diff --git a/types/react-plotly.js/index.d.ts b/types/react-plotly.js/index.d.ts new file mode 100644 index 0000000000..ac24016496 --- /dev/null +++ b/types/react-plotly.js/index.d.ts @@ -0,0 +1,104 @@ +// Type definitions for react-plotly.js 2.2 +// Project: https://github.com/plotly/react-plotly.js#readme +// Definitions by: Jon Freedman +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +import * as Plotly from 'plotly.js'; +import * as React from 'react'; + +export interface Frame { + name: string; + data: [{ x: Plotly.Datum, y: Plotly.Datum }]; + group: 'lower' | 'upper'; +} + +export interface Figure { + data: Plotly.Data[]; + layout: Partial; +} + +export interface PlotParams { + data: Plotly.Data[]; + layout: Partial; + frames?: Frame[]; + config?: Partial; + /** + * When provided, causes the plot to update only when the revision is incremented. + */ + revision?: number; + /** + * Callback executed after plot is initialized. + * @param figure Object with three keys corresponding to input props: data, layout and frames. + * @param graphDiv Reference to the DOM node into which the figure was rendered. + */ + onInitialized?: (figure: Readonly
, graphDiv: Readonly) => void; + /** + * Callback executed when when a plot is updated due to new data or layout, or when user interacts with a plot. + * @param figure Object with three keys corresponding to input props: data, layout and frames. + * @param graphDiv Reference to the DOM node into which the figure was rendered. + */ + onUpdate?: (figure: Readonly
, graphDiv: Readonly) => void; + /** + * Callback executed when component unmounts, before Plotly.purge strips the graphDiv of all private attributes. + * @param figure Object with three keys corresponding to input props: data, layout and frames. + * @param graphDiv Reference to the DOM node into which the figure was rendered. + */ + onPurge?: (figure: Readonly
, graphDiv: Readonly) => void; + /** + * Callback executed when a plotly.js API method rejects + * @param err Error + */ + onError?: (err: Readonly) => void; + /** + * id assigned to the
into which the plot is rendered. + */ + divId?: string; + /** + * applied to the
into which the plot is rendered + */ + className?: string; + /** + * used to style the
into which the plot is rendered + */ + style?: React.CSSProperties; + /** + * Assign the graph div to window.gd for debugging + */ + debug?: boolean; + /** + * When true, adds a call to Plotly.Plot.resize() as a window.resize event handler + */ + useResizeHandler?: boolean; + + onAfterExport?: () => void; + onAfterPlot?: () => void; + onAnimated?: () => void; + onAnimatingFrame?: (event: Readonly) => void; + onAnimationInterrupted?: () => void; + onAutoSize?: () => void; + onBeforeExport?: () => void; + onButtonClicked?: (event: Readonly) => void; + onClick?: (event: Readonly) => void; + onClickAnnotation?: (event: Readonly) => void; + onDeselect?: () => void; + onDoubleClick?: () => void; + onFramework?: () => void; + onHover?: (event: Readonly) => void; + onLegendClick?: (event: Readonly) => boolean; + onLegendDoubleClick?: (event: Readonly) => boolean; + onRelayout?: (event: Readonly) => void; + onRestyle?: (event: Readonly) => void; + onRedraw?: () => void; + onSelected?: (event: Readonly) => void; + onSelecting?: (event: Readonly) => void; + onSliderChange?: (event: Readonly) => void; + onSliderEnd?: (event: Readonly) => void; + onSliderStart?: (event: Readonly) => void; + onTransitioning?: () => void; + onTransitionInterrupted?: () => void; + onUnhover?: (event: Readonly) => void; +} + +export default class Plot extends React.PureComponent { +} diff --git a/types/react-plotly.js/react-plotly.js-tests.tsx b/types/react-plotly.js/react-plotly.js-tests.tsx new file mode 100644 index 0000000000..2ca0b7026d --- /dev/null +++ b/types/react-plotly.js/react-plotly.js-tests.tsx @@ -0,0 +1,24 @@ +import * as React from 'react'; +import Plot from 'react-plotly.js'; + +/** + * based on https://plot.ly/javascript/react/#quick-start + */ +export class SimpleChartComponent extends React.PureComponent { + render() { + return( + + ); + } +} diff --git a/types/react-plotly.js/tsconfig.json b/types/react-plotly.js/tsconfig.json new file mode 100644 index 0000000000..e0ec629a4c --- /dev/null +++ b/types/react-plotly.js/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-plotly.js-tests.tsx" + ] +} diff --git a/types/react-plotly.js/tslint.json b/types/react-plotly.js/tslint.json new file mode 100644 index 0000000000..6db713aff9 --- /dev/null +++ b/types/react-plotly.js/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "indent": [true, "spaces", 4] + } +}