Skip to content

Commit 87fa2ef

Browse files
authored
feat: De-globalize JSAPI in Chart package (#1258)
- De-globalize JSAPI in the Chart package. - Update `dashboard-core-plugins` to match the Chart package changes. BREAKING CHANGE: - `ChartUtils` class now needs to be instantiated with a JSAPI object, most of the methods converted from static to instance methods. - All `ChartModelFactory` methods require JSAPI object as the first argument. - `FigureChartModel` constructor requires JSAPI object as the first argument.
1 parent 7d56f97 commit 87fa2ef

26 files changed

Lines changed: 1172 additions & 1092 deletions

package-lock.json

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

packages/chart/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@deephaven/icons": "file:../icons",
26-
"@deephaven/jsapi-shim": "file:../jsapi-shim",
26+
"@deephaven/jsapi-types": "file:../jsapi-types",
2727
"@deephaven/jsapi-utils": "file:../jsapi-utils",
2828
"@deephaven/log": "file:../log",
2929
"@deephaven/utils": "file:../utils",
@@ -40,6 +40,7 @@
4040
"react": "^17.x"
4141
},
4242
"devDependencies": {
43+
"@deephaven/jsapi-shim": "file:../jsapi-shim",
4344
"@deephaven/mocks": "file:../mocks",
4445
"@deephaven/tsconfig": "file:../tsconfig",
4546
"@types/plotly.js": "^2.12.11"

packages/chart/src/ChartModelFactory.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('creating model from metadata', () => {
99
const table = new (dh as any).Table({ columns });
1010
const settings = { series: ['C'], xAxis: 'name', type: 'PIE' as const };
1111
const model = await ChartModelFactory.makeModelFromSettings(
12+
dh,
1213
settings,
1314
table
1415
);

packages/chart/src/ChartModelFactory.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dh, { Figure, Table } from '@deephaven/jsapi-shim';
1+
import type { dh as DhType, Figure, Table } from '@deephaven/jsapi-types';
22
import ChartUtils, { ChartModelSettings } from './ChartUtils';
33
import FigureChartModel from './FigureChartModel';
44
import ChartTheme from './ChartTheme';
@@ -8,6 +8,7 @@ class ChartModelFactory {
88
/**
99
* Creates a model from the settings provided.
1010
* Tries to create a Figure in the API with it.
11+
* @param dh JSAPI instance
1112
* @param settings The chart builder settings
1213
* @param settings.isLinked Whether the newly created chart should stay linked with the original table, update when filters are updated
1314
* @param settings.series The column names to use for creating the series of this chart
@@ -21,20 +22,23 @@ class ChartModelFactory {
2122
* This causes TS issues in 1 or 2 spots. Once this is TS it can be returned to just FigureChartModel
2223
*/
2324
static async makeModelFromSettings(
25+
dh: DhType,
2426
settings: ChartModelSettings,
2527
table: Table,
2628
theme = ChartTheme
2729
): Promise<ChartModel> {
2830
const figure = await ChartModelFactory.makeFigureFromSettings(
31+
dh,
2932
settings,
3033
table
3134
);
32-
return new FigureChartModel(figure, settings, theme);
35+
return new FigureChartModel(dh, figure, settings, theme);
3336
}
3437

3538
/**
3639
* Creates a model from the settings provided.
3740
* Tries to create a Figure in the API with it.
41+
* @param dh DH JSAPI instance
3842
* @param settings The chart builder settings
3943
* @param settings.isLinked Whether the newly created chart should stay linked with the original table, update when filters are updated
4044
* @param settings.series The column names to use for creating the series of this chart
@@ -45,11 +49,12 @@ class ChartModelFactory {
4549
* @returns The Figure created with the settings provided
4650
*/
4751
static async makeFigureFromSettings(
52+
dh: DhType,
4853
settings: ChartModelSettings,
4954
table: Table
5055
): Promise<Figure> {
5156
// Copy the table first and then re-apply the filters from the original table
52-
// When we add toable linking we'll want to listen to the original table and update
57+
// When we add table linking we'll want to listen to the original table and update
5358
// the copied table with any changes that occur.
5459
// The table gets owned by the Figure that gets created, which closes the table
5560
const tableCopy = await table.copy();
@@ -58,13 +63,14 @@ class ChartModelFactory {
5863
tableCopy.applySort(table.sort);
5964

6065
return dh.plot.Figure.create(
61-
ChartUtils.makeFigureSettings(settings, tableCopy)
66+
new ChartUtils(dh).makeFigureSettings(settings, tableCopy)
6267
);
6368
}
6469

6570
/**
6671
* Creates a model from the settings provided.
6772
* Tries to create a Figure in the API with it.
73+
* @param dh DH JSAPI instance
6874
* @param settings The chart builder settings
6975
* @param settings.isLinked Whether the newly created chart should stay linked with the original table, update when filters are updated
7076
* @param settings.series The column names to use for creating the series of this chart
@@ -78,11 +84,12 @@ class ChartModelFactory {
7884
* This causes TS issues in 1 or 2 spots. Once this is TS it can be returned to just FigureChartModel
7985
*/
8086
static async makeModel(
87+
dh: DhType,
8188
settings: ChartModelSettings | undefined,
8289
figure: Figure,
8390
theme = ChartTheme
8491
): Promise<ChartModel> {
85-
return new FigureChartModel(figure, settings, theme);
92+
return new FigureChartModel(dh, figure, settings, theme);
8693
}
8794
}
8895

0 commit comments

Comments
 (0)