diff --git a/packages/charts/react-charting/etc/react-charting.api.md b/packages/charts/react-charting/etc/react-charting.api.md index f07cb027b9303..a9793c3c65d41 100644 --- a/packages/charts/react-charting/etc/react-charting.api.md +++ b/packages/charts/react-charting/etc/react-charting.api.md @@ -1228,6 +1228,7 @@ export interface ISankeyChartData { export interface ISankeyChartProps { accessibility?: ISankeyChartAccessibilityProps; borderColorsForNodes?: string[]; + calloutProps?: Partial; className?: string; colorsForNodes?: string[]; componentRef?: IRefObject; diff --git a/packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx b/packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx index 83480263bdfe2..d5972d32a7b11 100644 --- a/packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx +++ b/packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx @@ -14,7 +14,6 @@ import { transformPlotlyJsonToVSBCProps, transformPlotlyJsonToScatterChartProps, transformPlotlyJsonToHorizontalBarWithAxisProps, - transformPlotlyJsonToHeatmapProps, transformPlotlyJsonToSankeyProps, transformPlotlyJsonToGaugeProps, @@ -86,7 +85,8 @@ export const DeclarativeChart: React.FunctionComponent = DeclarativeChartProps >((props, forwardedRef) => { const { plotlySchema } = sanitizeJson(props.chartSchema); - let { data, layout, selectedLegends } = plotlySchema; + const { data, layout } = plotlySchema; + let { selectedLegends } = plotlySchema; const xValues = data[0].x; const isXDate = isDateArray(xValues); const isXNumber = isNumberArray(xValues); @@ -108,9 +108,9 @@ export const DeclarativeChart: React.FunctionComponent = }; React.useEffect(() => { - const { plotlySchema } = sanitizeJson(props.chartSchema); - const { selectedLegends } = plotlySchema; - setActiveLegends(selectedLegends ?? []); + const { updatedPlotlySchema } = sanitizeJson(props.chartSchema); + const { updatedSelectedLegends } = updatedPlotlySchema; + setActiveLegends(updatedSelectedLegends ?? []); }, [props.chartSchema]); const legendProps = { @@ -142,10 +142,10 @@ export const DeclarativeChart: React.FunctionComponent = return ( ); case 'bar': @@ -156,7 +156,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); } else { @@ -166,7 +166,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToGVBCProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); } @@ -175,7 +175,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); } @@ -188,16 +188,16 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToScatterChartProps({ data, layout }, true, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); } return ( ); } @@ -206,7 +206,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); case 'heatmap': @@ -215,7 +215,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToHeatmapProps(plotlySchema)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); case 'sankey': @@ -223,7 +223,7 @@ export const DeclarativeChart: React.FunctionComponent = ); case 'indicator': @@ -233,7 +233,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToGaugeProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); } @@ -244,7 +244,7 @@ export const DeclarativeChart: React.FunctionComponent = {...transformPlotlyJsonToVBCProps(plotlySchema, colorMap, isDarkTheme)} legendProps={legendProps} componentRef={chartRef} - calloutProps={{layerProps: {eventBubblingEnabled: true}}} + calloutProps={{ layerProps: { eventBubblingEnabled: true } }} /> ); default: diff --git a/packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts b/packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts index 8e0dab6dfab96..471db94b0c098 100644 --- a/packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts +++ b/packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts @@ -523,7 +523,7 @@ export const sanitizeJson = (jsonObject: any, depth: number = 0): any => { } return jsonObject; -} +}; function isTypedArray(a: any) { return ArrayBuffer.isView(a) && !(a instanceof DataView); diff --git a/packages/charts/react-charting/src/components/DonutChart/DonutChart.base.tsx b/packages/charts/react-charting/src/components/DonutChart/DonutChart.base.tsx index 99442c1523fa4..e1bdcc6cef078 100644 --- a/packages/charts/react-charting/src/components/DonutChart/DonutChart.base.tsx +++ b/packages/charts/react-charting/src/components/DonutChart/DonutChart.base.tsx @@ -100,7 +100,7 @@ export class DonutChartBase extends React.Component; - /** - * props for the callout in the chart - */ - calloutProps?: Partial; + /** + * props for the callout in the chart + */ + calloutProps?: Partial; } /** diff --git a/packages/charts/react-charting/src/components/VerticalBarChart/VerticalBarChart.base.tsx b/packages/charts/react-charting/src/components/VerticalBarChart/VerticalBarChart.base.tsx index 5ed9a8e8f4a95..5a01b1ac417d6 100644 --- a/packages/charts/react-charting/src/components/VerticalBarChart/VerticalBarChart.base.tsx +++ b/packages/charts/react-charting/src/components/VerticalBarChart/VerticalBarChart.base.tsx @@ -143,7 +143,7 @@ export class VerticalBarChartBase public componentDidUpdate(prevProps: IVerticalBarChartProps): void { if (prevProps.legendProps?.selectedLegend !== this.props.legendProps?.selectedLegend) { this.setState({ - selectedLegend: this.props.legendProps?.selectedLegend ?? '' + selectedLegend: this.props.legendProps?.selectedLegend ?? '', }); } } diff --git a/packages/charts/react-charting/src/components/VerticalStackedBarChart/VerticalStackedBarChart.base.tsx b/packages/charts/react-charting/src/components/VerticalStackedBarChart/VerticalStackedBarChart.base.tsx index af8c34515af52..06bcd655861c8 100644 --- a/packages/charts/react-charting/src/components/VerticalStackedBarChart/VerticalStackedBarChart.base.tsx +++ b/packages/charts/react-charting/src/components/VerticalStackedBarChart/VerticalStackedBarChart.base.tsx @@ -172,7 +172,7 @@ export class VerticalStackedBarChartBase public componentDidUpdate(prevProps: IVerticalStackedBarChartProps): void { if (prevProps.legendProps?.selectedLegend !== this.props.legendProps?.selectedLegend) { this.setState({ - selectedLegend: this.props.legendProps?.selectedLegend ?? '' + selectedLegend: this.props.legendProps?.selectedLegend ?? '', }); } diff --git a/packages/react-examples/src/react-charting/DeclarativeChart/DeclarativeChart.Basic.Example.tsx b/packages/react-examples/src/react-charting/DeclarativeChart/DeclarativeChart.Basic.Example.tsx index c3aa8e7c7a99f..8252669314127 100644 --- a/packages/react-examples/src/react-charting/DeclarativeChart/DeclarativeChart.Basic.Example.tsx +++ b/packages/react-examples/src/react-charting/DeclarativeChart/DeclarativeChart.Basic.Example.tsx @@ -37,7 +37,6 @@ const schemas: any[] = [ const dropdownStyles = { dropdown: { width: 200 } }; - const textFieldStyles: Partial = { root: { maxWidth: 300 } }; function fileSaver(url: string) { @@ -67,11 +66,11 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati this._lastKnownValidLegends = selectedLegends; } - componentDidMount() { - document.addEventListener('contextmenu', (e) => { + public componentDidMount() { + document.addEventListener('contextmenu', e => { e.preventDefault(); }); - }; + } public render(): JSX.Element { return
{this._createDeclarativeChart()}
; @@ -83,7 +82,10 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati this.setState({ selectedChoice: option.key as string, selectedLegends: JSON.stringify(selectedLegends) }); }; - private _onSelectedLegendsEdited = (event: React.FormEvent, newValue?: string): void => { + private _onSelectedLegendsEdited = ( + event: React.FormEvent, + newValue?: string, + ): void => { this.setState({ selectedLegends: newValue ?? '' }); }; @@ -104,13 +106,14 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati if (this.state.selectedLegends === '') { this._lastKnownValidLegends = undefined; } else { - try { - this._lastKnownValidLegends = JSON.parse(this.state.selectedLegends); - } catch (error) { + try { + this._lastKnownValidLegends = JSON.parse(this.state.selectedLegends); + } catch (error) { + // Nothing to do here } } const plotlySchema = { data, layout, selectedLegends: this._lastKnownValidLegends }; - let inputSchema: Schema = { plotlySchema: plotlySchema }; + const inputSchema: Schema = { plotlySchema }; return ( @@ -142,7 +145,12 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati componentRef={this._declarativeChartRef} />
- +
); } diff --git a/packages/react-examples/src/react-charting/DeclarativeChart/ErrorBoundary.tsx b/packages/react-examples/src/react-charting/DeclarativeChart/ErrorBoundary.tsx index 3e341236116a2..0817ce247502d 100644 --- a/packages/react-examples/src/react-charting/DeclarativeChart/ErrorBoundary.tsx +++ b/packages/react-examples/src/react-charting/DeclarativeChart/ErrorBoundary.tsx @@ -1,30 +1,26 @@ import * as React from 'react'; -interface ErrorBoundaryProps { +interface IErrorBoundaryProps { children: React.ReactNode; } -interface ErrorBoundaryState { +interface IErrorBoundaryState { hasError: boolean; error: string; } -class ErrorBoundary extends React.Component { - constructor(props: ErrorBoundaryProps) { - super(props); - this.state = { hasError: false, error: '' }; - } - - static getDerivedStateFromError(error: Error) { +class ErrorBoundary extends React.Component { + public static getDerivedStateFromError(error: Error) { // Update state so the next render will show the fallback UI. return { hasError: true, error: `${error.message} ${error.stack}` }; } - componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { - console.error("Error caught by ErrorBoundary:", error, errorInfo); + constructor(props: IErrorBoundaryProps) { + super(props); + this.state = { hasError: false, error: '' }; } - render() { + public render() { if (this.state.hasError) { return

${this.state.error}

; }