Skip to content
Merged
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@deephaven/icons": "file:../icons",
"@deephaven/jsapi-shim": "file:../jsapi-shim",
"@deephaven/jsapi-types": "file:../jsapi-types",
"@deephaven/jsapi-utils": "file:../jsapi-utils",
"@deephaven/log": "file:../log",
"@deephaven/utils": "file:../utils",
Expand All @@ -40,6 +40,7 @@
"react": "^17.x"
},
"devDependencies": {
"@deephaven/jsapi-shim": "file:../jsapi-shim",
"@deephaven/mocks": "file:../mocks",
"@deephaven/tsconfig": "file:../tsconfig",
"@types/plotly.js": "^2.12.11"
Expand Down
1 change: 1 addition & 0 deletions packages/chart/src/ChartModelFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('creating model from metadata', () => {
const table = new (dh as any).Table({ columns });
const settings = { series: ['C'], xAxis: 'name', type: 'PIE' as const };
const model = await ChartModelFactory.makeModelFromSettings(
dh,
settings,
table
);
Expand Down
17 changes: 12 additions & 5 deletions packages/chart/src/ChartModelFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dh, { Figure, Table } from '@deephaven/jsapi-shim';
import type { dh as DhType, Figure, Table } from '@deephaven/jsapi-types';
import ChartUtils, { ChartModelSettings } from './ChartUtils';
import FigureChartModel from './FigureChartModel';
import ChartTheme from './ChartTheme';
Expand All @@ -8,6 +8,7 @@ class ChartModelFactory {
/**
* Creates a model from the settings provided.
* Tries to create a Figure in the API with it.
* @param dh JSAPI instance
* @param settings The chart builder settings
* @param settings.isLinked Whether the newly created chart should stay linked with the original table, update when filters are updated
* @param settings.series The column names to use for creating the series of this chart
Expand All @@ -21,20 +22,23 @@ class ChartModelFactory {
* This causes TS issues in 1 or 2 spots. Once this is TS it can be returned to just FigureChartModel
*/
static async makeModelFromSettings(
dh: DhType,
settings: ChartModelSettings,
table: Table,
theme = ChartTheme
): Promise<ChartModel> {
const figure = await ChartModelFactory.makeFigureFromSettings(
dh,
settings,
table
);
return new FigureChartModel(figure, settings, theme);
return new FigureChartModel(dh, figure, settings, theme);
}

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

return dh.plot.Figure.create(
ChartUtils.makeFigureSettings(settings, tableCopy)
new ChartUtils(dh).makeFigureSettings(settings, tableCopy)
);
}

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

Expand Down
Loading