Skip to content
  • Sponsor plotly/angular-plotly.js

  • Notifications You must be signed in to change notification settings
  • Fork 78
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: plotly/angular-plotly.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 889917b
Choose a base ref
...
head repository: plotly/angular-plotly.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fc34f6f
Choose a head ref
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Feb 22, 2020

  1. Copy the full SHA
    fc34f6f View commit details
1 change: 1 addition & 0 deletions src/app/demo/demo.component.html
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ <h5>Angular Plotly</h5>
<li><a [routerLink]="['/timeout-update']">Timeout Update</a></li>
<li><a [routerLink]="['/huge-memory-usage']">Huge Memory Usage</a></li>
<li><a [routerLink]="['/slow-example']">Slow Example</a></li>
<li><a [routerLink]="['/performance']">Performance</a></li>
</ul>
</div>
</div>
3 changes: 3 additions & 0 deletions src/app/demo/demo.module.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import { FramesComponent } from './frames/frames.component';
import { TimeoutUpdateComponent } from './timeout-update/timeout-update.component';
import { HugeMemoryUsageComponent } from './huge-memory-usage/huge-memory-usage.component';
import { SlowExampleComponent } from './slow-example/slow-example.component';
import { PerformanceComponent } from './performance/performance.component';


const demoRoutes: Routes = [
@@ -37,6 +38,7 @@ const demoRoutes: Routes = [
{ path: 'timeout-update', component: TimeoutUpdateComponent, data: { title: 'Timeout Update' } },
{ path: 'huge-memory-usage', component: HugeMemoryUsageComponent, data: { title: 'Huge Memory Usage' } },
{ path: 'slow-example', component: SlowExampleComponent, data: { title: 'Slow example' } },
{ path: 'performance', component: PerformanceComponent, data: { title: 'Performance' } },

{ path: '', redirectTo: '/home', pathMatch: 'full' },
];
@@ -68,6 +70,7 @@ PlotlyViaCDNModule.plotlyVersion = '1.49.4';
TimeoutUpdateComponent,
HugeMemoryUsageComponent,
SlowExampleComponent,
PerformanceComponent,
],
exports: [DemoComponent],
})
10 changes: 10 additions & 0 deletions src/app/demo/performance/performance.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-auto-rows: 225px;
gap: 4px;

max-width: 1200px;
margin: 0 auto;
}

12 changes: 12 additions & 0 deletions src/app/demo/performance/performance.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<h4>Total time: {{ getTotalTime() }}ms</h4>

<div class="grid">

<div class="item" *ngFor="let data of chartData; let i = index; trackBy: trackByIndex">
<div>Time: {{ getTime(i) }}ms</div>
<plotly-plot [data]="data" [layout]="layout" [style]="style" [config]="config" (ngInited)="onNgInited(i)" (initialized)="onInitialized(i)"></plotly-plot>
</div>


</div>
25 changes: 25 additions & 0 deletions src/app/demo/performance/performance.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PerformanceComponent } from './performance.component';

describe('PerformanceComponent', () => {
let component: PerformanceComponent;
let fixture: ComponentFixture<PerformanceComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PerformanceComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PerformanceComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
83 changes: 83 additions & 0 deletions src/app/demo/performance/performance.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'plotly-performance',
templateUrl: './performance.component.html',
styleUrls: ['./performance.component.css']
})
export class PerformanceComponent implements OnInit {
numberOfCharts = 100;
indexNumberOfCharts = this.numberOfCharts - 1;

chartData = [];
layout: any;
style: any;
config: any;

public mainStartTime: number;
public mainEndTime: number;
public startTime: number[] = [];
public endTime: number[] = [];

constructor() { }

ngOnInit(): void {
this.initChartSetup();
this.initChartData();

this.mainStartTime = (new Date()).getTime();
}

trackByIndex(i) {
return i;
}

initChartSetup() {
this.layout = {
xaxis: { title: { text: "X" }, automargin: true },
yaxis: { title: { text: "Y" }, automargin: true },
margin: {
t: 12,
r: 12,
b: 12,
l: 12
}
};

this.style = { position: "relative", width: "100%", height: '200px' };

this.config = { staticPlot: true };
}

initChartData() {
for (let i = 1; i <= this.numberOfCharts; i++) {
const data = [
{ type: "bar", name: `Chart ${i}`, x: [1, 2, 3], y: [100, 300, 200] }
];
this.chartData.push(data);
}
}

onNgInited(i: number) {
this.startTime[i] = (new Date()).getTime();
}

onInitialized(i: number) {
this.endTime[i] = (new Date()).getTime();

if (i === this.indexNumberOfCharts) {
this.mainEndTime = (new Date()).getTime();
}
}

getTime(i: number): number {
if (i in this.endTime) return this.endTime[i] - this.startTime[i];
return 0;
}

getTotalTime(): number {
if (this.mainEndTime) return this.mainEndTime - this.mainStartTime;
return 0;
}

}
7 changes: 6 additions & 1 deletion src/app/shared/plot/plot.component.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import {
IterableDiffers,
KeyValueDiffer,
KeyValueDiffers,
ChangeDetectionStrategy,
} from '@angular/core';

import { PlotlyService } from '../plotly.service';
@@ -25,6 +26,7 @@ import { Plotly } from '../plotly.interface';
selector: 'plotly-plot',
template: `<div #plot [attr.id]="divId" [className]="getClassName()" [ngStyle]="style"></div>`,
providers: [PlotlyService],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PlotComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
protected defaultClassName = 'js-plotly-plot';
@@ -52,6 +54,7 @@ export class PlotComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
@Input() updateOnDataChange = true;
@Input() updateOnlyWithRevision = false;

@Output() ngInited = new EventEmitter();
@Output() initialized = new EventEmitter<Plotly.Figure>();
@Output() update = new EventEmitter<Plotly.Figure>();
@Output() purge = new EventEmitter<Plotly.Figure>();
@@ -99,7 +102,9 @@ export class PlotComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
) { }

ngOnInit() {
this.createPlot().then(() => {
this.ngInited.emit();
setTimeout(async () => {
await this.createPlot();
const figure = this.createFigure();
this.initialized.emit(figure);
});