Skip to content

Commit

Permalink
Merge pull request #105 from rchiodo/rchiodo/use_new_plotly_api
Browse files Browse the repository at this point in the history
Support new plotly API
  • Loading branch information
rgbkrk authored Oct 29, 2023
2 parents ad34d6c + d356cf3 commit ab03b2e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/transform-plotly/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface FigureLayout extends ObjectType {
interface Figure extends ObjectType {
data: object;
layout: FigureLayout;
config: ObjectType | undefined;
frames: object[] | undefined;
}

declare class PlotlyHTMLElement extends HTMLDivElement {
Expand Down Expand Up @@ -52,7 +54,8 @@ export class PlotlyTransform extends React.Component<Props> {
newPlot: (
div: PlotlyHTMLElement | null | undefined,
data: object,
layout: FigureLayout
layout?: FigureLayout,
config?: object
) => void;
redraw: (div?: PlotlyHTMLElement) => void;
};
Expand All @@ -61,7 +64,11 @@ export class PlotlyTransform extends React.Component<Props> {
// Handle case of either string to be `JSON.parse`d or pure object
const figure = this.getFigure();
this.Plotly = require("plotly.js-dist");
this.Plotly.newPlot(this.plotDiv, figure.data, figure.layout);
if (figure.config || figure.frames) {
this.Plotly.newPlot(this.plotDiv, figure);
} else {
this.Plotly.newPlot(this.plotDiv, figure.data, figure.layout);
}
}

shouldComponentUpdate(nextProps: Props): boolean {
Expand Down Expand Up @@ -94,9 +101,9 @@ export class PlotlyTransform extends React.Component<Props> {
return cloneDeep(figure) as Figure;
}

const { data = {}, layout = {} } = figure as Figure;
const { data = {}, layout = {}, config = undefined, frames = undefined } = figure as Figure;

return { data, layout };
return { data, layout, config, frames };
};

render() {
Expand Down

0 comments on commit ab03b2e

Please sign in to comment.