Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

feat(praparat): set config with @Input #11

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions projects/praparat/src/lib/pan-zoom-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export class PanZoomModel {
this.zoomToPoint(newScale, focal);
}

clone() {
return new PanZoomModel({
initialScale: this.initialScale,
initialPan: this.initialPan,
maxScale: this.maxScale,
minScale: this.minScale,
wheelZoomFactor: this.wheelZoomFactor,
});
}

private setScale(scale: number) {
if (this.scale !== scale) {
this._scale$.next(scale);
Expand Down
58 changes: 50 additions & 8 deletions projects/praparat/src/lib/praparat.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {
Component,
OnInit,
ChangeDetectionStrategy,
ViewChild,
ElementRef,
Renderer2,
NgZone,
AfterViewInit,
OnDestroy,
Inject
Inject,
Input,
} from '@angular/core';
import { PanZoomModel } from './pan-zoom-model';
import { Subject, combineLatest, animationFrameScheduler } from 'rxjs';
import { takeUntil, debounceTime, throttleTime, tap } from 'rxjs/operators';
import { takeUntil, debounceTime, throttleTime } from 'rxjs/operators';
import { DOCUMENT } from '@angular/common';
import { Point } from './point';
import { DEFAULT_PRAPARAT_CONFIG, PraparatConfig } from './praparat-config';

/**
* @dynamic
Expand All @@ -25,12 +26,54 @@ import { Point } from './point';
styleUrls: ['./praparat.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PraparatComponent implements OnInit, OnDestroy, AfterViewInit {
export class PraparatComponent implements OnDestroy, AfterViewInit {

@ViewChild('zoomElement', { static: true })
zoomElement!: ElementRef<HTMLElement>;

private model = new PanZoomModel();
@Input()
get initialScale() {
return this.model.initialScale;
}
set initialScale(value) {
this.model.initialScale = value;
}

@Input()
get initialPan() {
return this.model.initialPan;
}
set initialPan(value) {
this.model.initialPan = value;
}

@Input()
get wheelZoomFactor() {
return this.model.wheelZoomFactor;
}
set wheelZoomFactor(value) {
this.model.wheelZoomFactor = value;
}

@Input()
get maxScale() {
return this.model.maxScale;
}
set maxScale(value) {
this.model.maxScale = value;
}

@Input()
get minScale() {
return this.model.minScale;
}
set minScale(value) {
this.model.minScale = value;
}

private model = new PanZoomModel({
...this.defaultConfig,
});

private destroyed = new Subject<void>();
private removeListeners: (() => void)[] = [];
Expand All @@ -40,11 +83,9 @@ export class PraparatComponent implements OnInit, OnDestroy, AfterViewInit {
private renderer: Renderer2,
private ngZone: NgZone,
@Inject(DOCUMENT) private document: Document,
@Inject(DEFAULT_PRAPARAT_CONFIG) private defaultConfig: PraparatConfig,
) { }

ngOnInit() {
}

ngOnDestroy() {
this.destroyed.next();
this.destroyed.complete();
Expand All @@ -55,6 +96,7 @@ export class PraparatComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngAfterViewInit() {
this.model = this.model.clone();

this.ngZone.runOutsideAngular(() => {
// マウスホイールでのズーム
Expand Down