Skip to content

Commit 7f2342f

Browse files
committed
Closes #70 . Adding HugeMemoryUsageComponent to test
1 parent e3dfb8d commit 7f2342f

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

src/app/demo/demo.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ <h5>Angular Plotly</h5>
1515
<li><a [routerLink]="['/memory-leak']">Memory Leak</a></li>
1616
<li><a [routerLink]="['/frames']">Frames</a></li>
1717
<li><a [routerLink]="['/timeout-update']">Timeout Update</a></li>
18+
<li><a [routerLink]="['/huge-memory-usage']">Huge Memory Usage</a></li>
1819
</ul>
1920
</div>
2021
</div>

src/app/demo/demo.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { FancyplotComponent } from './fancyplot/fancyplot.component';
2121
import { MemoryLeakComponent } from './memory-leak/memory-leak.component';
2222
import { FramesComponent } from './frames/frames.component';
2323
import { TimeoutUpdateComponent } from './timeout-update/timeout-update.component';
24+
import { HugeMemoryUsageComponent } from './huge-memory-usage/huge-memory-usage.component';
2425

2526

2627
const demoRoutes: Routes = [
@@ -33,6 +34,7 @@ const demoRoutes: Routes = [
3334
{ path: 'memory-leak', component: MemoryLeakComponent, data: { title: 'Memory leak' } },
3435
{ path: 'frames', component: FramesComponent, data: { title: 'Frames' } },
3536
{ path: 'timeout-update', component: TimeoutUpdateComponent, data: { title: 'Timeout Update' } },
37+
{ path: 'huge-memory-usage', component: HugeMemoryUsageComponent, data: { title: 'Huge Memory Usage' } },
3638

3739
{ path: '', redirectTo: '/home', pathMatch: 'full' },
3840
];
@@ -61,7 +63,8 @@ PlotlyViaCDNModule.plotlyVersion = '1.5.0';
6163
FancyplotComponent,
6264
MemoryLeakComponent,
6365
FramesComponent,
64-
TimeoutUpdateComponent
66+
TimeoutUpdateComponent,
67+
HugeMemoryUsageComponent,
6568
],
6669
exports: [DemoComponent],
6770
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div>
2+
<p>&nbsp;</p>
3+
<button *ngIf="status === 'init'" (click)="loadData()" class="button">Load a 15MiB data</button>
4+
<span *ngIf="status === 'loading'" style="font-style: italic">Loading...</span>
5+
<span *ngIf="status === 'loaded'">
6+
Lodaded! <br />
7+
<button (click)="changeRandomData()" class="button">Change Random Data</button>
8+
</span>
9+
<span *ngIf="status === 'fail'">Something went wrong!</span>
10+
<p>&nbsp;</p>
11+
12+
<plotly-plot [data]="data" [layout]="layout" [revision]="revision" [debug]="debug" [useResizeHandler]="useResizeHandler"></plotly-plot>
13+
</div>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'plotly-huge-memory-usage',
5+
templateUrl: './huge-memory-usage.component.html',
6+
})
7+
export class HugeMemoryUsageComponent {
8+
public debug = true;
9+
public useResizeHandler = true;
10+
public status = 'init';
11+
public revision = 0;
12+
13+
public data: any[] = [];
14+
15+
public layout = {
16+
autoexpand: 'true',
17+
autosie: 'true',
18+
uirevision: "true",
19+
margin: {
20+
autoexpand: true,
21+
margin: 5
22+
},
23+
offset: 100,
24+
type: "scattergl",
25+
title: "huge Graph",
26+
hovermode: "closest",
27+
xaxis: {
28+
linecolor: "black",
29+
linewidth: 2,
30+
mirror: true,
31+
title: "Time (s)",
32+
automargin: true
33+
},
34+
yaxis: {
35+
linecolor: "black",
36+
linewidth: 2,
37+
mirror: true,
38+
automargin: true,
39+
type: "log",
40+
exponentformat: "power",
41+
title: "PSD (g²/Hz)"
42+
}
43+
};
44+
45+
public callback(data: any[]) {
46+
for (const item of data) {
47+
this.data.push({
48+
x: item.f,
49+
y: item.PSD,
50+
name: item.name,
51+
hoverlabel: { namelength: 50 },
52+
type: "scattergl",
53+
mode: "line"
54+
});
55+
}
56+
57+
this.status = 'loaded';
58+
this.revision += 1;
59+
}
60+
61+
public loadData() {
62+
(window as any).callback = this.callback.bind(this);
63+
64+
const script: HTMLScriptElement = document.createElement('script');
65+
script.type = 'text/javascript';
66+
script.src = 'https://d3xt.com/plotly/angular-plotly-huge-memory-usage.json';
67+
script.onerror = () => {
68+
this.status = 'failed';
69+
console.error(`Error loading from angular-plotly-huge-memory-usage.json`);
70+
};
71+
72+
const head: HTMLHeadElement = document.getElementsByTagName('head')[0];
73+
head.appendChild(script);
74+
this.status = 'loading';
75+
}
76+
77+
public changeRandomData() {
78+
let i = Math.floor((Math.random() * this.data.length) + 1);
79+
const item = this.data[i];
80+
81+
i = Math.floor((Math.random() * 2) + 1);
82+
if (i === 1) {
83+
const x = item.x;
84+
i = Math.floor((Math.random() * x.length) + 1);
85+
x[i] = Math.floor((Math.random() * 50) + 1);
86+
} else {
87+
const y = item.y;
88+
i = Math.floor((Math.random() * y.length) + 1);
89+
y[i] = Math.floor((Math.random() * 10) + 1);
90+
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)