Skip to content

Commit bfa07bd

Browse files
committed
Add @types/plotly.js-dist-mon
1 parent 5201d97 commit bfa07bd

File tree

8 files changed

+88
-72
lines changed

8 files changed

+88
-72
lines changed

package-lock.json

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
"@angular/platform-browser-dynamic": "^20.0.2",
2121
"@angular/router": "^20.0.2",
2222
"plotly.js-dist": "^2.20.0",
23+
"plotly.js-dist-min": "^3.1.1",
2324
"rxjs": "~7.8.0",
24-
"tslib": "^2.3.1",
25+
"tslib": "^2.8.1",
2526
"zone.js": "^0.15.1"
2627
},
2728
"devDependencies": {
@@ -36,8 +37,9 @@
3637
"@types/jasmine": "~4.3.1",
3738
"@types/jasminewd2": "~2.0.3",
3839
"@types/node": "^12.11.1",
39-
"@typescript-eslint/eslint-plugin": "^7.2.0",
40-
"@typescript-eslint/parser": "^7.2.0",
40+
"@types/plotly.js-dist-min": "^2.3.4",
41+
"@typescript-eslint/eslint-plugin": "^7.18.0",
42+
"@typescript-eslint/parser": "^7.18.0",
4143
"coveralls": "^3.1.1",
4244
"eslint": "^8.57.0",
4345
"jasmine-core": "~4.6.0",
@@ -51,4 +53,4 @@
5153
"ts-node": "~10.9.1",
5254
"typescript": "~5.8.3"
5355
}
54-
}
56+
}

projects/demo_app/src/app/app.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component } from '@angular/core';
2+
import {Data, Layout} from "plotly.js-dist-min";
23

34
@Component({
45
selector: 'app-root',
@@ -11,9 +12,9 @@ export class AppComponent {
1112

1213
public graph = {
1314
data: [
14-
{ x: [1, 2, 3], y: [2, 6, 3], type: 'scatter', mode: 'lines+points', marker: {color: 'red'} },
15+
{ x: [1, 2, 3], y: [2, 6, 3], type: 'scatter', mode: 'lines+markers', marker: {color: 'red'} },
1516
{ x: [1, 2, 3], y: [2, 5, 3], type: 'bar' },
16-
],
17-
layout: {width: 320, height: 240, title: 'A Fancy Plot'}
17+
] satisfies Data[],
18+
layout: {width: 320, height: 240, title: { text: 'A Fancy Plot'}} satisfies Partial<Layout>
1819
};
1920
}

projects/plotly/src/lib/plotly.component.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
44
import { PlotlyComponent } from './plotly.component';
55
import { PlotlyService } from './plotly.service';
66

7-
import PlotlyJS from 'plotly.js-dist';
7+
import PlotlyJS, { Plots } from 'plotly.js-dist-min';
88

99

1010
PlotlyService.setPlotly(PlotlyJS);
@@ -20,9 +20,7 @@ describe('PlotlyComponent', () => {
2020

2121
TestBed.configureTestingModule({
2222
imports: [PlotlyComponent],
23-
providers: [
24-
PlotlyService,
25-
],
23+
providers: [PlotlyService],
2624
}).compileComponents();
2725
});
2826

@@ -199,21 +197,21 @@ describe('PlotlyComponent', () => {
199197
await component.createPlot();
200198
await fixture.whenStable();
201199

202-
spyOn(PlotlyJS.Plots, 'resize').and.callThrough();
200+
spyOn(Plots, 'resize').and.callThrough();
203201

204202
window.dispatchEvent(new Event('resize'));
205203
await fixture.whenStable();
206204

207-
expect(PlotlyJS.Plots.resize).toHaveBeenCalled();
208-
PlotlyJS.Plots.resize.calls.reset();
205+
expect(Plots.resize).toHaveBeenCalled();
206+
Plots.resize.calls.reset();
209207

210208
fixture.destroy();
211209
await fixture.whenStable();
212210

213211
window.dispatchEvent(new Event('resize'));
214212
await fixture.whenStable();
215213

216-
expect(PlotlyJS.Plots.resize).not.toHaveBeenCalled();
214+
expect(Plots.resize).not.toHaveBeenCalled();
217215
});
218216

219217

projects/plotly/src/lib/plotly.component.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { CommonModule } from '@angular/common';
2222

2323
import { PlotlyService } from './plotly.service';
24-
import { Plotly } from './plotly.interface';
24+
import { PlotlyHTMLElement, Data, Layout, Config } from 'plotly.js-dist-min';
2525

2626
// @dynamic
2727
@Component({
@@ -36,17 +36,17 @@ import { Plotly } from './plotly.interface';
3636
export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
3737
protected defaultClassName = 'js-plotly-plot';
3838

39-
public plotlyInstance?: Plotly.PlotlyHTMLElement;
40-
public resizeHandler?: (instance: Plotly.PlotlyHTMLElement) => void;
39+
public plotlyInstance?: PlotlyHTMLElement;
40+
public resizeHandler?: (instance: PlotlyHTMLElement) => void;
4141
public layoutDiffer?: KeyValueDiffer<string, any>;
42-
public dataDiffer?: IterableDiffer<Plotly.Data>;
42+
public dataDiffer?: IterableDiffer<Data>;
4343

4444
@ViewChild('plot', { static: true }) plotEl!: ElementRef;
4545

46-
data = input<Plotly.Data[]>();
47-
layout = input<Partial<Plotly.Layout>>();
48-
config = input<Partial<Plotly.Config>>();
49-
frames = input<Partial<Plotly.Config>[]>();
46+
data = input<Data[]>();
47+
layout = input<Partial<Layout>>();
48+
config = input<Partial<Config>>();
49+
frames = input<Partial<Config>[]>();
5050
style = input<{ [key: string]: string }>();
5151

5252
divId = input<string>();
@@ -59,9 +59,21 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
5959
updateOnDataChange = input(true);
6060
updateOnlyWithRevision = input(false);
6161

62-
initialized = output<Plotly.Figure>();
63-
update = output<Plotly.Figure>();
64-
purge = output<Plotly.Figure>();
62+
initialized = output< {
63+
data: Data[];
64+
layout: Partial<Layout>;
65+
frames: Partial<Config>;
66+
}>();
67+
update = output< {
68+
data: Data[];
69+
layout: Partial<Layout>;
70+
frames: Partial<Config>;
71+
}>();
72+
purge = output< {
73+
data: Data[];
74+
layout: Partial<Layout>;
75+
frames: Partial<Config>;
76+
}>();
6577
error = output<Error>();
6678

6779
afterExport = output();
@@ -124,7 +136,7 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
124136
this.createPlot().then(() => {
125137
const figure = this.createFigure();
126138
this.initialized.emit(figure);
127-
});
139+
});
128140
}
129141

130142
ngOnDestroy(): void {
@@ -198,7 +210,7 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
198210
}
199211
}
200212

201-
getData(): Plotly.Data[] {
213+
getData(): Data[] {
202214
return this.data() ?? [];
203215
}
204216

@@ -248,15 +260,17 @@ export class PlotlyComponent implements OnInit, OnChanges, OnDestroy, DoCheck {
248260
});
249261
}
250262

251-
createFigure(): Plotly.Figure {
263+
createFigure(): {
264+
data: Data[];
265+
layout: Partial<Layout>;
266+
frames: Partial<Config>;
267+
} {
252268
const p: any = this.plotlyInstance;
253-
const figure: Plotly.Figure = {
269+
return {
254270
data: p.data,
255271
layout: p.layout,
256272
frames: p._transitionData ? p._transitionData._frames : null
257273
};
258-
259-
return figure;
260274
}
261275

262276
updatePlot(): Promise<any> {

projects/plotly/src/lib/plotly.interface.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

projects/plotly/src/lib/plotly.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TestBed, inject } from '@angular/core/testing';
22
import PlotlyJS from 'plotly.js-dist';
33

44
import { PlotlyService } from './plotly.service';
5-
import { Plotly } from './plotly.interface';
5+
import {PlotlyHTMLElement} from "plotly.js-dist-min";
66

77
describe('PlotlyService', () => {
88
beforeEach(() => {
@@ -13,7 +13,7 @@ describe('PlotlyService', () => {
1313
});
1414

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

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

projects/plotly/src/lib/plotly.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { Plotly } from './plotly.interface';
2+
import {Config, Data, Layout, PlotlyHTMLElement} from "plotly.js-dist-min";
33

44
type PlotlyName = 'PlotlyJS' | 'ViaCDN' | 'ViaWindow' | undefined;
55

@@ -8,7 +8,7 @@ type PlotlyName = 'PlotlyJS' | 'ViaCDN' | 'ViaWindow' | undefined;
88
providedIn: 'root'
99
})
1010
export class PlotlyService {
11-
protected static instances: Plotly.PlotlyHTMLElement[] = [];
11+
protected static instances: PlotlyHTMLElement[] = [];
1212
public static plotly?: any = undefined;
1313
protected static moduleName?: PlotlyName = undefined;
1414

@@ -29,23 +29,23 @@ export class PlotlyService {
2929
PlotlyService.plotly = plotly;
3030
}
3131

32-
public static insert(instance: Plotly.PlotlyHTMLElement): Plotly.PlotlyHTMLElement {
32+
public static insert(instance: PlotlyHTMLElement): PlotlyHTMLElement {
3333
const index = PlotlyService.instances.indexOf(instance);
3434
if (index === -1) {
3535
PlotlyService.instances.push(instance);
3636
}
3737
return instance;
3838
}
3939

40-
public static remove(div: Plotly.PlotlyHTMLElement): void {
40+
public static remove(div: PlotlyHTMLElement): void {
4141
const index = PlotlyService.instances.indexOf(div);
4242
if (index >= 0) {
4343
PlotlyService.instances.splice(index, 1);
4444
PlotlyService.plotly.purge(div);
4545
}
4646
}
4747

48-
public getInstanceByDivId(id: string): Plotly.PlotlyHTMLElement | undefined {
48+
public getInstanceByDivId(id: string): PlotlyHTMLElement | undefined {
4949
for (const instance of PlotlyService.instances) {
5050
if (instance && instance.id === id) {
5151
return instance;
@@ -81,7 +81,7 @@ export class PlotlyService {
8181
});
8282
}
8383

84-
public async newPlot(div: HTMLDivElement, data: Plotly.Data[], layout?: Partial<Plotly.Layout>, config?: Partial<Plotly.Config>, frames?: Partial<Plotly.Config>[]): Promise<any> {
84+
public async newPlot(div: HTMLDivElement, data: Data[], layout?: Partial<Layout>, config?: Partial<Config>, frames?: Partial<Config>[]): Promise<any> {
8585
await this.waitFor(() => this._getPlotly() !== 'waiting');
8686

8787
if (frames) {
@@ -92,7 +92,7 @@ export class PlotlyService {
9292
return this._getPlotly().newPlot(div, data, layout, config).then(() => PlotlyService.insert(div as any)) as Promise<any>;
9393
}
9494

95-
public plot(div: Plotly.PlotlyHTMLElement, data: Plotly.Data[], layout?: Partial<Plotly.Layout>, config?: Partial<Plotly.Config>, frames?: Partial<Plotly.Config>[]): Promise<any> {
95+
public plot(div: PlotlyHTMLElement, data: Data[], layout?: Partial<Layout>, config?: Partial<Config>, frames?: Partial<Config>[]): Promise<any> {
9696
if (frames) {
9797
const obj = { data, layout, config, frames };
9898
return this._getPlotly().newPlot(div, obj) as Promise<any>;
@@ -101,7 +101,7 @@ export class PlotlyService {
101101
return this._getPlotly().newPlot(div, data, layout, config) as Promise<any>;
102102
}
103103

104-
public update(div: Plotly.PlotlyHTMLElement, data: Plotly.Data[], layout?: Partial<Plotly.Layout>, config?: Partial<Plotly.Config>, frames?: Partial<Plotly.Config>[]): Promise<any> {
104+
public update(div: PlotlyHTMLElement, data: Data[], layout?: Partial<Layout>, config?: Partial<Config>, frames?: Partial<Config>[]): Promise<any> {
105105
if (frames) {
106106
const obj = { data, layout, config, frames };
107107
return this._getPlotly().react(div, obj) as Promise<any>;
@@ -110,7 +110,7 @@ export class PlotlyService {
110110
return this._getPlotly().react(div, data, layout, config) as Promise<any>;
111111
}
112112

113-
public resize(div: Plotly.PlotlyHTMLElement): void {
113+
public resize(div: PlotlyHTMLElement): void {
114114
return this._getPlotly().Plots.resize(div);
115115
}
116116
}

0 commit comments

Comments
 (0)