|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | + |
| 3 | +@Component({ |
| 4 | + selector: 'plotly-performance', |
| 5 | + templateUrl: './performance.component.html', |
| 6 | + styleUrls: ['./performance.component.css'] |
| 7 | +}) |
| 8 | +export class PerformanceComponent implements OnInit { |
| 9 | + numberOfCharts = 100; |
| 10 | + indexNumberOfCharts = this.numberOfCharts - 1; |
| 11 | + |
| 12 | + chartData = []; |
| 13 | + layout: any; |
| 14 | + style: any; |
| 15 | + config: any; |
| 16 | + |
| 17 | + public mainStartTime: number; |
| 18 | + public mainEndTime: number; |
| 19 | + public startTime: number[] = []; |
| 20 | + public endTime: number[] = []; |
| 21 | + |
| 22 | + constructor() { } |
| 23 | + |
| 24 | + ngOnInit(): void { |
| 25 | + this.initChartSetup(); |
| 26 | + this.initChartData(); |
| 27 | + |
| 28 | + this.mainStartTime = (new Date()).getTime(); |
| 29 | + } |
| 30 | + |
| 31 | + trackByIndex(i) { |
| 32 | + return i; |
| 33 | + } |
| 34 | + |
| 35 | + initChartSetup() { |
| 36 | + this.layout = { |
| 37 | + xaxis: { title: { text: "X" }, automargin: true }, |
| 38 | + yaxis: { title: { text: "Y" }, automargin: true }, |
| 39 | + margin: { |
| 40 | + t: 12, |
| 41 | + r: 12, |
| 42 | + b: 12, |
| 43 | + l: 12 |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + this.style = { position: "relative", width: "100%", height: '200px' }; |
| 48 | + |
| 49 | + this.config = { staticPlot: true }; |
| 50 | + } |
| 51 | + |
| 52 | + initChartData() { |
| 53 | + for (let i = 1; i <= this.numberOfCharts; i++) { |
| 54 | + const data = [ |
| 55 | + { type: "bar", name: `Chart ${i}`, x: [1, 2, 3], y: [100, 300, 200] } |
| 56 | + ]; |
| 57 | + this.chartData.push(data); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + onNgInited(i: number) { |
| 62 | + this.startTime[i] = (new Date()).getTime(); |
| 63 | + } |
| 64 | + |
| 65 | + onInitialized(i: number) { |
| 66 | + this.endTime[i] = (new Date()).getTime(); |
| 67 | + |
| 68 | + if (i === this.indexNumberOfCharts) { |
| 69 | + this.mainEndTime = (new Date()).getTime(); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + getTime(i: number): number { |
| 74 | + if (i in this.endTime) return this.endTime[i] - this.startTime[i]; |
| 75 | + return 0; |
| 76 | + } |
| 77 | + |
| 78 | + getTotalTime(): number { |
| 79 | + if (this.mainEndTime) return this.mainEndTime - this.mainStartTime; |
| 80 | + return 0; |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments