Skip to content

Commit 3fa4a6a

Browse files
committed
Making insert and remove static methods in PlotlyService
1 parent ee86ccc commit 3fa4a6a

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/app/plotly/plot/plot.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class PlotComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
106106

107107
const figure = this.createFigure();
108108
this.purge.emit(figure);
109-
this.plotly.remove(this.plotlyInstance);
109+
PlotlyService.remove(this.plotlyInstance);
110110
}
111111

112112
ngOnChanges(changes: SimpleChanges) {

src/app/plotly/plotly.service.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,23 @@ export class PlotlyService {
3232
}
3333
}
3434

35+
public static insert(instance: Plotly.PlotlyHTMLElement) {
36+
const index = PlotlyService.instances.indexOf(instance);
37+
if (index === -1) {
38+
PlotlyService.instances.push(instance);
39+
}
40+
return instance;
41+
}
42+
43+
public static remove(div: Plotly.PlotlyHTMLElement) {
44+
const index = PlotlyService.instances.indexOf(div);
45+
if (index >= 0) {
46+
PlotlyService.instances.splice(index, 1);
47+
}
48+
}
49+
3550
public newPlot(div: HTMLDivElement, data: Plotly.Data[], layout?: Partial<Plotly.Layout>, config?: Partial<Plotly.Config>) {
36-
return this.plotly.newPlot(div, data, layout, config).then(this.insert.bind(this));
51+
return this.plotly.newPlot(div, data, layout, config).then(instance => PlotlyService.insert(instance));
3752
}
3853

3954
public plot(div: Plotly.PlotlyHTMLElement, data: Plotly.Data[], layout?: Partial<Plotly.Layout>, config?: Partial<Plotly.Config>) {
@@ -61,19 +76,4 @@ export class PlotlyService {
6176
return undefined;
6277
}
6378

64-
public insert(instance: Plotly.PlotlyHTMLElement) {
65-
const index = PlotlyService.instances.indexOf(instance);
66-
if (index === -1) {
67-
PlotlyService.instances.push(instance);
68-
}
69-
return instance;
70-
}
71-
72-
public remove(div: Plotly.PlotlyHTMLElement) {
73-
const index = PlotlyService.instances.indexOf(div);
74-
if (index >= 0) {
75-
PlotlyService.instances.splice(index, 1);
76-
}
77-
}
78-
7979
}

0 commit comments

Comments
 (0)