Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee86ccc

Browse files
committed
Creating methods getPlotly and getInstanceByDivId on PlotlyService
1 parente9ae792 commitee86ccc

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

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

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

107107
constfigure=this.createFigure();
108108
this.purge.emit(figure);
109+
this.plotly.remove(this.plotlyInstance);
109110
}
110111

111112
ngOnChanges(changes:SimpleChanges){
@@ -229,7 +230,7 @@ export class PlotComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
229230
}
230231
}
231232

232-
dataDifferTrackBy(index:number,item:any):any{
233+
dataDifferTrackBy(_:number,item:any):any{
233234
constobj=Object.assign({},item,{uid:''});
234235
returnJSON.stringify(obj);
235236
}

‎src/app/plotly/plotly.service.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{TestBed,inject}from'@angular/core/testing';
2+
import*asPlotlyjsfrom'plotly.js/dist/plotly.min.js';
23

34
import{PlotlyService}from'./plotly.service';
45

@@ -12,4 +13,8 @@ describe('PlotlyService', () => {
1213
it('should be created',inject([PlotlyService],(service:PlotlyService)=>{
1314
expect(service).toBeTruthy();
1415
}));
16+
17+
it('should return the plotly object',inject([PlotlyService],(service:PlotlyService)=>{
18+
expect(service.getPlotly()).toBe(Plotlyjs);
19+
}));
1520
});

‎src/app/plotly/plotly.service.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export namespace Plotly {
2323

2424
@Injectable()
2525
exportclassPlotlyService{
26+
protectedstaticinstances:Plotly.PlotlyHTMLElement[]=[];
2627
protectedplotly=Plotlyjs;
2728

2829
constructor(){
@@ -32,7 +33,7 @@ export class PlotlyService {
3233
}
3334

3435
publicnewPlot(div:HTMLDivElement,data:Plotly.Data[],layout?:Partial<Plotly.Layout>,config?:Partial<Plotly.Config>){
35-
returnthis.plotly.newPlot(div,data,layout,config);
36+
returnthis.plotly.newPlot(div,data,layout,config).then(this.insert.bind(this));
3637
}
3738

3839
publicplot(div:Plotly.PlotlyHTMLElement,data:Plotly.Data[],layout?:Partial<Plotly.Layout>,config?:Partial<Plotly.Config>){
@@ -47,4 +48,32 @@ export class PlotlyService {
4748
returnthis.plotly.Plots.resize(div);
4849
}
4950

51+
publicgetPlotly(){
52+
returnthis.plotly;
53+
}
54+
55+
publicgetInstanceByDivId(id:string):Plotly.PlotlyHTMLElement|undefined{
56+
for(constinstanceofPlotlyService.instances){
57+
if(instance.id===id){
58+
returninstance;
59+
}
60+
}
61+
returnundefined;
62+
}
63+
64+
publicinsert(instance:Plotly.PlotlyHTMLElement){
65+
constindex=PlotlyService.instances.indexOf(instance);
66+
if(index===-1){
67+
PlotlyService.instances.push(instance);
68+
}
69+
returninstance;
70+
}
71+
72+
publicremove(div:Plotly.PlotlyHTMLElement){
73+
constindex=PlotlyService.instances.indexOf(div);
74+
if(index>=0){
75+
PlotlyService.instances.splice(index,1);
76+
}
77+
}
78+
5079
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp