Skip to content

Commit

Permalink
Adding back getInstanceByDivId method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefarzat committed Jan 17, 2019
1 parent 49fda0f commit e0c2f2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app/shared/plotly.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TestBed, inject } from '@angular/core/testing';
import * as PlotlyJS from 'plotly.js/dist/plotly.js';

import { PlotlyService } from './plotly.service';
import { Plotly } from './plotly.interface';

describe('PlotlyService', () => {
beforeEach(() => {
Expand Down Expand Up @@ -63,4 +64,15 @@ describe('PlotlyService', () => {
service.resize('one' as any);
expect(plotly.Plots.resize).toHaveBeenCalledWith('one');
}));


it('should get a plotly instance by id', inject([PlotlyService], (service: PlotlyService) => {
const instance = { id: 'aidi' } as Plotly.PlotlyHTMLElement;

PlotlyService.insert(instance);
expect(service.getInstanceByDivId('aidi')).toBe(instance);

PlotlyService.remove(instance);
expect(service.getInstanceByDivId('aidi')).toBeUndefined();
}));
});
9 changes: 9 additions & 0 deletions src/app/shared/plotly.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export class PlotlyService {
}
}

public getInstanceByDivId(id: string): Plotly.PlotlyHTMLElement | undefined {
for (const instance of PlotlyService.instances) {
if (instance.id === id) {
return instance;
}
}
return undefined;
}

public getPlotly() {
if (typeof PlotlyService._plotly === 'undefined') {
throw new Error(`Peer dependency plotly.js isn't installed`);
Expand Down

0 comments on commit e0c2f2a

Please sign in to comment.