/
multi-line-chart.component.ts
71 lines (59 loc) · 1.63 KB
/
multi-line-chart.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Component, OnInit, OnChanges, ViewChild, ElementRef, Input } from '@angular/core';
import { ChartOptions, ChartData } from '../../core/models';
import { MultiLineChart } from '../../core/charts';
@Component({
selector: 'app-multi-line-chart',
templateUrl: './multi-line-chart.component.html',
styleUrls: ['./multi-line-chart.component.scss']
})
export class MultiLineChartComponent implements OnInit, OnChanges {
@ViewChild('chart') svgElement: ElementRef;
@Input() options: ChartOptions;
@Input() multiData: ChartData[];
private chart: MultiLineChart;
private touchMode = false;
private containerLeft = 0;
constructor() { }
press(event) {
this.changeTouchMode(true);
const posX = event.center.x - this.containerLeft;
this.chart.touch(posX);
}
pressup(event) {
this.changeTouchMode(false);
}
panmove(event) {
if (!this.touchMode) {
return;
}
const posX = event.center.x - this.containerLeft;
this.chart.touch(posX);
}
panstart(event) {
if (!this.touchMode) {
return;
}
}
panend(event) {
if (!this.touchMode) {
return;
}
this.changeTouchMode(false);
}
ngOnInit() {
this.chart = new MultiLineChart(this.svgElement.nativeElement, this.options, this.multiData);
// calculate container (svg) left position
this.containerLeft = +this.svgElement.nativeElement.getBoundingClientRect().left;
}
ngOnChanges() {
if (this.chart) {
this.chart.update(this.options, this.multiData);
}
}
private changeTouchMode(mode: boolean): void {
this.touchMode = mode;
if (!mode) {
this.chart.untouch();
}
}
}