@fluentui/react-charting 5.23.32 → 5.23.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +34 -1
- package/CHANGELOG.md +14 -2
- package/dist/react-charting.js +1 -1
- package/dist/react-charting.min.js +1 -1
- package/lib/components/AreaChart/AreaChart.base.d.ts +4 -1
- package/lib/components/AreaChart/AreaChart.base.js +56 -35
- package/lib/components/AreaChart/AreaChart.base.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +7 -6
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.base.js +56 -51
- package/lib/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/lib-amd/components/AreaChart/AreaChart.base.d.ts +4 -1
- package/lib-amd/components/AreaChart/AreaChart.base.js +55 -34
- package/lib-amd/components/AreaChart/AreaChart.base.js.map +1 -1
- package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +7 -6
- package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
- package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js +55 -50
- package/lib-amd/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/lib-commonjs/components/AreaChart/AreaChart.base.d.ts +4 -1
- package/lib-commonjs/components/AreaChart/AreaChart.base.js +55 -34
- package/lib-commonjs/components/AreaChart/AreaChart.base.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +7 -6
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.d.ts +3 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js +55 -50
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.base.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclarativeChart.js","sourceRoot":"../src/","sources":["components/DeclarativeChart/DeclarativeChart.tsx"],"names":[],"mappings":";;;;IA2EA,IAAM,eAAe,GAAG;QACtB,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAkB,CAAC,CAAC;QACzD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF;;;OAGG;IACU,QAAA,gBAAgB,GAAmD,KAAK,CAAC,UAAU,CAG9F,UAAC,KAAK,EAAE,YAAY;;QACZ,IAAA,YAAY,GAAK,IAAA,kCAAY,EAAC,KAAK,CAAC,WAAW,CAAC,aAApC,CAAqC;QACjD,IAAA,IAAI,GAAa,YAAY,KAAzB,EAAE,MAAM,GAAK,YAAY,OAAjB,CAAkB;QAChC,IAAA,eAAe,GAAK,YAAY,gBAAjB,CAAkB;QACvC,IAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAM,OAAO,GAAG,IAAA,iCAAW,EAAC,OAAO,CAAC,CAAC;QACrC,IAAM,SAAS,GAAG,IAAA,mCAAa,EAAC,OAAO,CAAC,CAAC;QACzC,IAAM,QAAQ,GAAG,IAAA,kCAAY,EAAC,OAAO,CAAC,CAAC;QACvC,IAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;QACnC,IAAM,KAAK,GAAG,IAAA,gBAAQ,GAAE,CAAC;QACzB,IAAM,WAAW,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,mCAAI,KAAK,CAAC;QAC/C,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAS,IAAI,CAAC,CAAC;QAE5C,IAAI,CAAC,IAAA,yCAAmB,EAAC,eAAe,CAAC,EAAE,CAAC;YAC1C,eAAe,GAAG,EAAE,CAAC;QACvB,CAAC;QAEK,IAAA,KAA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AAE,IAAI,EAAE,EAAE,IAC5D,CACH,CAAC;YACJ,KAAK,WAAW;gBACd,IAAI,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;oBACvC,OAAO,CACL,oBAAC,kBAAU,uBACL,IAAA,qDAA+B,EAAC,YAAY,EAAE,QAAQ,EAAE,WAAW,CAAC,IACxE,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,QAAQ,EACtB,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,IAC5D,CACH,CAAC;gBACJ,CAAC;gBACD,OAAO,sDAA6B,CAAC;YACvC,KAAK,WAAW;gBACd,OAAO,CACL,oBAAC,wBAAgB,uBACX,IAAA,mDAA6B,EAAC,YAAY,EAAE,QAAQ,EAAE,WAAW,CAAC,IACtE,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,QAAQ,EACtB,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,IAC5D,CACH,CAAC;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,wBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from 'react';\nimport { useTheme } from '@fluentui/react';\nimport { IRefObject } from '@fluentui/react/lib/Utilities';\nimport { DonutChart } from '../DonutChart/index';\nimport { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';\nimport {\n isArrayOrTypedArray,\n isDateArray,\n isNumberArray,\n isMonthArray,\n sanitizeJson,\n updateXValues,\n transformPlotlyJsonToDonutProps,\n transformPlotlyJsonToVSBCProps,\n transformPlotlyJsonToScatterChartProps,\n transformPlotlyJsonToHorizontalBarWithAxisProps,\n transformPlotlyJsonToHeatmapProps,\n transformPlotlyJsonToSankeyProps,\n transformPlotlyJsonToGaugeProps,\n transformPlotlyJsonToGVBCProps,\n transformPlotlyJsonToVBCProps,\n} from './PlotlySchemaAdapter';\nimport { LineChart } from '../LineChart/index';\nimport { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';\nimport { AreaChart } from '../AreaChart/index';\nimport { HeatMapChart } from '../HeatMapChart/index';\nimport { SankeyChart } from '../SankeyChart/SankeyChart';\nimport { GaugeChart } from '../GaugeChart/index';\nimport { GroupedVerticalBarChart } from '../GroupedVerticalBarChart/index';\nimport { VerticalBarChart } from '../VerticalBarChart/index';\nimport { IImageExportOptions, toImage } from './imageExporter';\nimport { IChart } from '../../types/index';\n\n/**\n * DeclarativeChart schema.\n * {@docCategory DeclarativeChart}\n */\nexport interface Schema {\n /**\n * Plotly schema represented as JSON object\n */\n plotlySchema: any;\n}\n\n/**\n * DeclarativeChart props.\n * {@docCategory DeclarativeChart}\n */\nexport interface DeclarativeChartProps extends React.RefAttributes<HTMLDivElement> {\n /**\n * The schema representing the chart data, layout and configuration\n */\n chartSchema: Schema;\n\n /**\n * Callback when an event occurs\n */\n onSchemaChange?: (eventData: Schema) => void;\n\n /**\n * Optional callback to access the IDeclarativeChart interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<IDeclarativeChart>;\n}\n\n/**\n * {@docCategory DeclarativeChart}\n */\nexport interface IDeclarativeChart {\n exportAsImage: (opts?: IImageExportOptions) => Promise<string>;\n}\n\nconst useColorMapping = () => {\n const colorMap = React.useRef(new Map<string, string>());\n return colorMap;\n};\n\n/**\n * DeclarativeChart component.\n * {@docCategory DeclarativeChart}\n */\nexport const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> = React.forwardRef<\n HTMLDivElement,\n DeclarativeChartProps\n>((props, forwardedRef) => {\n const { plotlySchema } = sanitizeJson(props.chartSchema);\n const { data, layout } = plotlySchema;\n let { selectedLegends } = plotlySchema;\n const xValues = data[0].x;\n const isXDate = isDateArray(xValues);\n const isXNumber = isNumberArray(xValues);\n const isXMonth = isMonthArray(xValues);\n const colorMap = useColorMapping();\n const theme = useTheme();\n const isDarkTheme = theme?.isInverted ?? false;\n const chartRef = React.useRef<IChart>(null);\n\n if (!isArrayOrTypedArray(selectedLegends)) {\n selectedLegends = [];\n }\n\n const [activeLegends, setActiveLegends] = React.useState<string[]>(selectedLegends);\n const onActiveLegendsChange = (keys: string[]) => {\n setActiveLegends(keys);\n if (props.onSchemaChange) {\n props.onSchemaChange({ plotlySchema: { data, layout, selectedLegends: keys } });\n }\n };\n\n React.useEffect(() => {\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const { plotlySchema } = sanitizeJson(props.chartSchema);\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const { selectedLegends } = plotlySchema;\n setActiveLegends(selectedLegends ?? []);\n }, [props.chartSchema]);\n\n const legendProps = {\n canSelectMultipleLegends: false,\n onChange: onActiveLegendsChange,\n selectedLegend: activeLegends.slice(0, 1)[0],\n };\n\n const exportAsImage = React.useCallback(\n (opts?: IImageExportOptions) => {\n return toImage(chartRef.current?.chartContainer, {\n background: theme.palette.white,\n ...opts,\n });\n },\n [theme],\n );\n\n React.useImperativeHandle(\n props.componentRef,\n () => ({\n exportAsImage,\n }),\n [exportAsImage],\n );\n\n switch (data[0].type) {\n case 'pie':\n return (\n <DonutChart\n {...transformPlotlyJsonToDonutProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends }}\n componentRef={chartRef}\n // Bubble event to prevent right click to open menu on the callout\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'bar':\n const orientation = data[0].orientation;\n if (orientation === 'h') {\n return (\n <HorizontalBarChartWithAxis\n {...transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n } else {\n if (['group', 'overlay'].includes(plotlySchema?.layout?.barmode)) {\n return (\n <GroupedVerticalBarChart\n {...transformPlotlyJsonToGVBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends }}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n return (\n <VerticalStackedBarChart\n {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends }}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n case 'scatter':\n const isAreaChart = data.some((series: any) => series.fill === 'tonexty' || series.fill === 'tozeroy');\n const renderChart = (chartProps: any) => {\n if (isAreaChart) {\n return <AreaChart {...chartProps} />;\n }\n return (\n <LineChart\n {...{\n ...chartProps,\n legendProps: {\n onChange: onActiveLegendsChange,\n canSelectMultipleLegends: true,\n selectedLegends: activeLegends,\n },\n }}\n />\n );\n };\n if (isXDate || isXNumber) {\n const chartProps = {\n ...transformPlotlyJsonToScatterChartProps({ data, layout }, isAreaChart, colorMap, isDarkTheme),\n legendProps,\n componentRef: chartRef,\n calloutProps: { layerProps: { eventBubblingEnabled: true } },\n };\n return renderChart(chartProps);\n } else if (isXMonth) {\n const updatedData = data.map((dataPoint: any) => ({\n ...dataPoint,\n x: updateXValues(dataPoint.x),\n }));\n const chartProps = {\n ...transformPlotlyJsonToScatterChartProps({ data: updatedData, layout }, isAreaChart, colorMap, isDarkTheme),\n legendProps,\n componentRef: chartRef,\n calloutProps: { layerProps: { eventBubblingEnabled: true } },\n };\n return renderChart(chartProps);\n }\n return (\n <VerticalStackedBarChart\n {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends }}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'heatmap':\n return (\n <HeatMapChart\n {...transformPlotlyJsonToHeatmapProps(plotlySchema)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'sankey':\n return (\n <SankeyChart\n {...transformPlotlyJsonToSankeyProps(plotlySchema, colorMap, isDarkTheme)}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'indicator':\n if (data?.[0]?.mode?.includes('gauge')) {\n return (\n <GaugeChart\n {...transformPlotlyJsonToGaugeProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n return <div>Unsupported Schema</div>;\n case 'histogram':\n return (\n <VerticalBarChart\n {...transformPlotlyJsonToVBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n default:\n throw new Error('Unsupported chart schema');\n }\n});\nDeclarativeChart.displayName = 'DeclarativeChart';\n"]}
|
|
1
|
+
{"version":3,"file":"DeclarativeChart.js","sourceRoot":"../src/","sources":["components/DeclarativeChart/DeclarativeChart.tsx"],"names":[],"mappings":";;;;IA2EA,IAAM,eAAe,GAAG;QACtB,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAkB,CAAC,CAAC;QACzD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF;;;OAGG;IACU,QAAA,gBAAgB,GAAmD,KAAK,CAAC,UAAU,CAG9F,UAAC,KAAK,EAAE,YAAY;;QACZ,IAAA,YAAY,GAAK,IAAA,kCAAY,EAAC,KAAK,CAAC,WAAW,CAAC,aAApC,CAAqC;QACjD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,oBAAC,wBAAgB,uBACX,IAAA,mDAA6B,EAAC,YAAY,EAAE,QAAQ,EAAE,WAAW,CAAC,IACtE,WAAW,EAAE,sBAAsB,EACnC,YAAY,EAAE,QAAQ,EACtB,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,IAC5D,CACH,CAAC;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,wBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from 'react';\nimport { useTheme } from '@fluentui/react';\nimport { IRefObject } from '@fluentui/react/lib/Utilities';\nimport { DonutChart } from '../DonutChart/index';\nimport { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';\nimport {\n isArrayOrTypedArray,\n isDateArray,\n isNumberArray,\n isMonthArray,\n sanitizeJson,\n updateXValues,\n transformPlotlyJsonToDonutProps,\n transformPlotlyJsonToVSBCProps,\n transformPlotlyJsonToScatterChartProps,\n transformPlotlyJsonToHorizontalBarWithAxisProps,\n transformPlotlyJsonToHeatmapProps,\n transformPlotlyJsonToSankeyProps,\n transformPlotlyJsonToGaugeProps,\n transformPlotlyJsonToGVBCProps,\n transformPlotlyJsonToVBCProps,\n} from './PlotlySchemaAdapter';\nimport { LineChart } from '../LineChart/index';\nimport { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';\nimport { AreaChart } from '../AreaChart/index';\nimport { HeatMapChart } from '../HeatMapChart/index';\nimport { SankeyChart } from '../SankeyChart/SankeyChart';\nimport { GaugeChart } from '../GaugeChart/index';\nimport { GroupedVerticalBarChart } from '../GroupedVerticalBarChart/index';\nimport { VerticalBarChart } from '../VerticalBarChart/index';\nimport { IImageExportOptions, toImage } from './imageExporter';\nimport { IChart } from '../../types/index';\n\n/**\n * DeclarativeChart schema.\n * {@docCategory DeclarativeChart}\n */\nexport interface Schema {\n /**\n * Plotly schema represented as JSON object\n */\n plotlySchema: any;\n}\n\n/**\n * DeclarativeChart props.\n * {@docCategory DeclarativeChart}\n */\nexport interface DeclarativeChartProps extends React.RefAttributes<HTMLDivElement> {\n /**\n * The schema representing the chart data, layout and configuration\n */\n chartSchema: Schema;\n\n /**\n * Callback when an event occurs\n */\n onSchemaChange?: (eventData: Schema) => void;\n\n /**\n * Optional callback to access the IDeclarativeChart interface. Use this instead of ref for accessing\n * the public methods and properties of the component.\n */\n componentRef?: IRefObject<IDeclarativeChart>;\n}\n\n/**\n * {@docCategory DeclarativeChart}\n */\nexport interface IDeclarativeChart {\n exportAsImage: (opts?: IImageExportOptions) => Promise<string>;\n}\n\nconst useColorMapping = () => {\n const colorMap = React.useRef(new Map<string, string>());\n return colorMap;\n};\n\n/**\n * DeclarativeChart component.\n * {@docCategory DeclarativeChart}\n */\nexport const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> = React.forwardRef<\n HTMLDivElement,\n DeclarativeChartProps\n>((props, forwardedRef) => {\n const { plotlySchema } = sanitizeJson(props.chartSchema);\n const { data, layout } = plotlySchema;\n let { selectedLegends } = plotlySchema;\n const xValues = data[0].x;\n const isXDate = isDateArray(xValues);\n const isXNumber = isNumberArray(xValues);\n const isXMonth = isMonthArray(xValues);\n const colorMap = useColorMapping();\n const theme = useTheme();\n const isDarkTheme = theme?.isInverted ?? false;\n const chartRef = React.useRef<IChart>(null);\n\n if (!isArrayOrTypedArray(selectedLegends)) {\n selectedLegends = [];\n }\n\n const [activeLegends, setActiveLegends] = React.useState<string[]>(selectedLegends);\n const onActiveLegendsChange = (keys: string[]) => {\n setActiveLegends(keys);\n if (props.onSchemaChange) {\n props.onSchemaChange({ plotlySchema: { data, layout, selectedLegends: keys } });\n }\n };\n\n React.useEffect(() => {\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const { plotlySchema } = sanitizeJson(props.chartSchema);\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const { selectedLegends } = plotlySchema;\n setActiveLegends(selectedLegends ?? []);\n }, [props.chartSchema]);\n\n const legendProps = {\n canSelectMultipleLegends: false,\n onChange: onActiveLegendsChange,\n selectedLegend: activeLegends.slice(0, 1)[0],\n };\n\n const exportAsImage = React.useCallback(\n (opts?: IImageExportOptions) => {\n return toImage(chartRef.current?.chartContainer, {\n background: theme.palette.white,\n ...opts,\n });\n },\n [theme],\n );\n\n React.useImperativeHandle(\n props.componentRef,\n () => ({\n exportAsImage,\n }),\n [exportAsImage],\n );\n\n const multiSelectLegendProps = {\n ...legendProps,\n canSelectMultipleLegends: true,\n selectedLegends: activeLegends,\n };\n\n switch (data[0].type) {\n case 'pie':\n return (\n <DonutChart\n {...transformPlotlyJsonToDonutProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={multiSelectLegendProps}\n componentRef={chartRef}\n // Bubble event to prevent right click to open menu on the callout\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'bar':\n const orientation = data[0].orientation;\n if (orientation === 'h') {\n return (\n <HorizontalBarChartWithAxis\n {...transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n } else {\n if (['group', 'overlay'].includes(plotlySchema?.layout?.barmode)) {\n return (\n <GroupedVerticalBarChart\n {...transformPlotlyJsonToGVBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={multiSelectLegendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n return (\n <VerticalStackedBarChart\n {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={multiSelectLegendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n case 'scatter':\n const isAreaChart = data.some((series: any) => series.fill === 'tonexty' || series.fill === 'tozeroy');\n const renderChart = (chartProps: any) => {\n if (isAreaChart) {\n return (\n <AreaChart\n {...chartProps}\n legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends }}\n />\n );\n }\n return (\n <LineChart\n {...{\n ...chartProps,\n legendProps: {\n onChange: onActiveLegendsChange,\n canSelectMultipleLegends: true,\n selectedLegends: activeLegends,\n },\n }}\n />\n );\n };\n if (isXDate || isXNumber) {\n const chartProps = {\n ...transformPlotlyJsonToScatterChartProps({ data, layout }, isAreaChart, colorMap, isDarkTheme),\n legendProps,\n componentRef: chartRef,\n calloutProps: { layerProps: { eventBubblingEnabled: true } },\n };\n return renderChart(chartProps);\n } else if (isXMonth) {\n const updatedData = data.map((dataPoint: any) => ({\n ...dataPoint,\n x: updateXValues(dataPoint.x),\n }));\n const chartProps = {\n ...transformPlotlyJsonToScatterChartProps({ data: updatedData, layout }, isAreaChart, colorMap, isDarkTheme),\n legendProps,\n componentRef: chartRef,\n calloutProps: { layerProps: { eventBubblingEnabled: true } },\n };\n return renderChart(chartProps);\n }\n return (\n <VerticalStackedBarChart\n {...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={multiSelectLegendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'heatmap':\n return (\n <HeatMapChart\n {...transformPlotlyJsonToHeatmapProps(plotlySchema)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'sankey':\n return (\n <SankeyChart\n {...transformPlotlyJsonToSankeyProps(plotlySchema, colorMap, isDarkTheme)}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n case 'indicator':\n if (data?.[0]?.mode?.includes('gauge')) {\n return (\n <GaugeChart\n {...transformPlotlyJsonToGaugeProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={legendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n }\n return <div>Unsupported Schema</div>;\n case 'histogram':\n return (\n <VerticalBarChart\n {...transformPlotlyJsonToVBCProps(plotlySchema, colorMap, isDarkTheme)}\n legendProps={multiSelectLegendProps}\n componentRef={chartRef}\n calloutProps={{ layerProps: { eventBubblingEnabled: true } }}\n />\n );\n default:\n throw new Error('Unsupported chart schema');\n }\n});\nDeclarativeChart.displayName = 'DeclarativeChart';\n"]}
|
|
@@ -11,6 +11,7 @@ export interface IVerticalBarChartState extends IBasestate {
|
|
|
11
11
|
hoverXValue?: string | number | null;
|
|
12
12
|
callOutAccessibilityData?: IAccessibilityProps;
|
|
13
13
|
calloutLegend: string;
|
|
14
|
+
selectedLegends: string[];
|
|
14
15
|
}
|
|
15
16
|
export declare class VerticalBarChartBase extends React.Component<IVerticalBarChartProps, IVerticalBarChartState> implements IChart {
|
|
16
17
|
static defaultProps: Partial<IVerticalBarChartProps>;
|
|
@@ -66,10 +67,10 @@ export declare class VerticalBarChartBase extends React.Component<IVerticalBarCh
|
|
|
66
67
|
private _createStringBars;
|
|
67
68
|
private _createDateBars;
|
|
68
69
|
private _closeCallout;
|
|
69
|
-
private _onLegendClick;
|
|
70
70
|
private _onLegendHover;
|
|
71
71
|
private _onLegendLeave;
|
|
72
72
|
private _getLegendData;
|
|
73
|
+
private _onLegendSelectionChange;
|
|
73
74
|
private _getAxisData;
|
|
74
75
|
/**
|
|
75
76
|
* This function checks if the given legend is highlighted or not.
|
|
@@ -82,6 +83,7 @@ export declare class VerticalBarChartBase extends React.Component<IVerticalBarCh
|
|
|
82
83
|
* This function checks if none of the legends is selected or hovered.
|
|
83
84
|
*/
|
|
84
85
|
private _noLegendHighlighted;
|
|
86
|
+
private _getHighlightedLegend;
|
|
85
87
|
private _getAriaLabel;
|
|
86
88
|
private _renderBarLabel;
|
|
87
89
|
private _getDomainMargins;
|
|
@@ -12,7 +12,7 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
12
12
|
var VerticalBarChartBase = /** @class */ (function (_super) {
|
|
13
13
|
tslib_1.__extends(VerticalBarChartBase, _super);
|
|
14
14
|
function VerticalBarChartBase(props) {
|
|
15
|
-
var _a
|
|
15
|
+
var _a;
|
|
16
16
|
var _this = _super.call(this, props) || this;
|
|
17
17
|
_this._isRtl = (0, Utilities_1.getRTL)();
|
|
18
18
|
_this._getDomainNRangeValues = function (points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
|
|
@@ -85,12 +85,12 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
85
85
|
dots));
|
|
86
86
|
};
|
|
87
87
|
_this._getCircleVisibilityAndRadius = function (xAxisPoint, legend) {
|
|
88
|
-
var
|
|
89
|
-
if (
|
|
90
|
-
if (xAxisPoint === activeXdataPoint &&
|
|
88
|
+
var activeXdataPoint = _this.state.activeXdataPoint;
|
|
89
|
+
if (!_this._noLegendHighlighted()) {
|
|
90
|
+
if (xAxisPoint === activeXdataPoint && _this._legendHighlighted(legend)) {
|
|
91
91
|
return { visibility: CircleVisbility.show, radius: 8 };
|
|
92
92
|
}
|
|
93
|
-
else if (
|
|
93
|
+
else if (_this._legendHighlighted(legend)) {
|
|
94
94
|
// Don't hide the circle to keep it focusable. For more information,
|
|
95
95
|
// see https://fuzzbomb.github.io/accessibility-demos/visually-hidden-focus-test.html
|
|
96
96
|
return { visibility: CircleVisbility.show, radius: 0.3 };
|
|
@@ -163,7 +163,9 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
163
163
|
: _this._createColors()(selectedPoint[0].y)
|
|
164
164
|
: _this._createColors()(1);
|
|
165
165
|
// there might be no y value of the line for the hovered bar. so we need to check this condition
|
|
166
|
-
if (_this._isHavingLine &&
|
|
166
|
+
if (_this._isHavingLine &&
|
|
167
|
+
((_a = selectedPoint[0].lineData) === null || _a === void 0 ? void 0 : _a.y) !== undefined &&
|
|
168
|
+
(_this._legendHighlighted(lineLegendText) || _this._noLegendHighlighted())) {
|
|
167
169
|
// callout data for the line
|
|
168
170
|
YValueHover.push({
|
|
169
171
|
legend: lineLegendText,
|
|
@@ -173,18 +175,20 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
173
175
|
yAxisCalloutData: (_d = selectedPoint[0].lineData) === null || _d === void 0 ? void 0 : _d.yAxisCalloutData,
|
|
174
176
|
});
|
|
175
177
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
?
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
if (_this._legendHighlighted(selectedPoint[0].legend) || _this._noLegendHighlighted()) {
|
|
179
|
+
// callout data for the bar
|
|
180
|
+
YValueHover.push({
|
|
181
|
+
legend: selectedPoint[0].legend,
|
|
182
|
+
y: selectedPoint[0].y,
|
|
183
|
+
color: enableGradient
|
|
184
|
+
? useSingleColor
|
|
185
|
+
? (0, index_2.getNextGradient)(0, 0)[0]
|
|
186
|
+
: ((_e = selectedPoint[0].gradient) === null || _e === void 0 ? void 0 : _e[0]) || (0, index_2.getNextGradient)(pointIndex, 0)[0]
|
|
187
|
+
: calloutColor,
|
|
188
|
+
data: selectedPoint[0].yAxisCalloutData,
|
|
189
|
+
yAxisCalloutData: selectedPoint[0].yAxisCalloutData,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
188
192
|
var hoverXValue = point.x instanceof Date ? (0, index_2.formatDate)(point.x, _this.props.useUTC) : point.x.toString();
|
|
189
193
|
return {
|
|
190
194
|
YValueHover: YValueHover,
|
|
@@ -210,7 +214,7 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
210
214
|
_this.setState({
|
|
211
215
|
refSelected: obj.refElement,
|
|
212
216
|
/** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */
|
|
213
|
-
isCalloutVisible: _this.
|
|
217
|
+
isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(point.legend),
|
|
214
218
|
calloutLegend: point.legend,
|
|
215
219
|
dataForHoverCard: point.y,
|
|
216
220
|
color: point.color || color,
|
|
@@ -315,9 +319,6 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
315
319
|
var legend = {
|
|
316
320
|
title: legendTitle,
|
|
317
321
|
color: color,
|
|
318
|
-
action: function () {
|
|
319
|
-
_this._onLegendClick(legendTitle);
|
|
320
|
-
},
|
|
321
322
|
hoverAction: function () {
|
|
322
323
|
_this._handleChartMouseLeave();
|
|
323
324
|
_this._onLegendHover(legendTitle);
|
|
@@ -332,9 +333,6 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
332
333
|
var lineLegend = {
|
|
333
334
|
title: lineLegendText,
|
|
334
335
|
color: lineLegendColor,
|
|
335
|
-
action: function () {
|
|
336
|
-
_this._onLegendClick(lineLegendText);
|
|
337
|
-
},
|
|
338
336
|
hoverAction: function () {
|
|
339
337
|
_this._handleChartMouseLeave();
|
|
340
338
|
_this._onLegendHover(lineLegendText);
|
|
@@ -346,7 +344,7 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
346
344
|
};
|
|
347
345
|
actions.unshift(lineLegend);
|
|
348
346
|
}
|
|
349
|
-
var legends = (React.createElement(index_1.Legends, tslib_1.__assign({ legends: actions, enabledWrapLines: _this.props.enabledLegendsWrapLines, overflowProps: _this.props.legendsOverflowProps, focusZonePropsInHoverCard: _this.props.focusZonePropsForLegendsInHoverCard, overflowText: _this.props.legendsOverflowText }, _this.props.legendProps)));
|
|
347
|
+
var legends = (React.createElement(index_1.Legends, tslib_1.__assign({ legends: actions, enabledWrapLines: _this.props.enabledLegendsWrapLines, overflowProps: _this.props.legendsOverflowProps, focusZonePropsInHoverCard: _this.props.focusZonePropsForLegendsInHoverCard, overflowText: _this.props.legendsOverflowText }, _this.props.legendProps, { onChange: _this._onLegendSelectionChange.bind(_this) })));
|
|
350
348
|
return legends;
|
|
351
349
|
};
|
|
352
350
|
_this._getAxisData = function (yAxisData) {
|
|
@@ -363,14 +361,13 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
363
361
|
* 2. hovering: if there is no selected legend and the user hovers over it
|
|
364
362
|
*/
|
|
365
363
|
_this._legendHighlighted = function (legendTitle) {
|
|
366
|
-
return
|
|
367
|
-
(_this.state.selectedLegend === '' && _this.state.activeLegend === legendTitle));
|
|
364
|
+
return _this._getHighlightedLegend().includes(legendTitle);
|
|
368
365
|
};
|
|
369
366
|
/**
|
|
370
367
|
* This function checks if none of the legends is selected or hovered.
|
|
371
368
|
*/
|
|
372
369
|
_this._noLegendHighlighted = function () {
|
|
373
|
-
return _this.
|
|
370
|
+
return _this._getHighlightedLegend().length === 0;
|
|
374
371
|
};
|
|
375
372
|
_this._getAriaLabel = function (point) {
|
|
376
373
|
var _a, _b, _c;
|
|
@@ -434,8 +431,8 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
434
431
|
dataForHoverCard: 0,
|
|
435
432
|
isCalloutVisible: false,
|
|
436
433
|
refSelected: null,
|
|
437
|
-
|
|
438
|
-
activeLegend:
|
|
434
|
+
selectedLegends: ((_a = props.legendProps) === null || _a === void 0 ? void 0 : _a.selectedLegends) || [],
|
|
435
|
+
activeLegend: undefined,
|
|
439
436
|
xCalloutValue: '',
|
|
440
437
|
yCalloutValue: '',
|
|
441
438
|
activeXdataPoint: null,
|
|
@@ -457,10 +454,10 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
457
454
|
return _this;
|
|
458
455
|
}
|
|
459
456
|
VerticalBarChartBase.prototype.componentDidUpdate = function (prevProps) {
|
|
460
|
-
var _a, _b, _c
|
|
461
|
-
if (((_a = prevProps.legendProps) === null || _a === void 0 ? void 0 : _a.
|
|
457
|
+
var _a, _b, _c;
|
|
458
|
+
if (!(0, index_2.areArraysEqual)((_a = prevProps.legendProps) === null || _a === void 0 ? void 0 : _a.selectedLegends, (_b = this.props.legendProps) === null || _b === void 0 ? void 0 : _b.selectedLegends)) {
|
|
462
459
|
this.setState({
|
|
463
|
-
|
|
460
|
+
selectedLegends: ((_c = this.props.legendProps) === null || _c === void 0 ? void 0 : _c.selectedLegends) || [],
|
|
464
461
|
});
|
|
465
462
|
}
|
|
466
463
|
};
|
|
@@ -483,7 +480,8 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
483
480
|
tickValues: this.props.tickValues,
|
|
484
481
|
tickFormat: this.props.tickFormat,
|
|
485
482
|
};
|
|
486
|
-
return !this._isChartEmpty() ? (React.createElement(index_1.CartesianChart, tslib_1.__assign({}, this.props, { chartTitle: this._getChartTitle(), points: this._points, supportNegativeData: this.props.supportNegativeData, chartType: index_2.ChartTypes.VerticalBarChart, xAxisType: this._xAxisType, createYAxis: index_2.createNumericYAxis, calloutProps: calloutProps, tickParams: tickParams }, (this._isHavingLine &&
|
|
483
|
+
return !this._isChartEmpty() ? (React.createElement(index_1.CartesianChart, tslib_1.__assign({}, this.props, { chartTitle: this._getChartTitle(), points: this._points, supportNegativeData: this.props.supportNegativeData, chartType: index_2.ChartTypes.VerticalBarChart, xAxisType: this._xAxisType, createYAxis: index_2.createNumericYAxis, calloutProps: calloutProps, tickParams: tickParams }, (this._isHavingLine &&
|
|
484
|
+
(this._noLegendHighlighted() || this._getHighlightedLegend().length > 1) && { isCalloutForStack: true }), { legendBars: legendBars, datasetForXAxisDomain: this._xAxisLabels, barwidth: this._barWidth, focusZoneDirection: react_focus_1.FocusZoneDirection.horizontal, customizedCallout: this._getCustomizedCallout(), createStringYAxis: index_2.createStringYAxis, getmargins: this._getMargins, getMinMaxOfYAxis: index_2.findVerticalNumericMinMaxOfY, getGraphData: this._getGraphData, getDomainNRangeValues: this._getDomainNRangeValues, getAxisData: this._getAxisData, onChartMouseLeave: this._handleChartMouseLeave, getDomainMargins: this._getDomainMargins }, (this._xAxisType === index_2.XAxisTypes.StringAxis && {
|
|
487
485
|
xAxisInnerPadding: this._xAxisInnerPadding,
|
|
488
486
|
xAxisOuterPadding: this._xAxisOuterPadding,
|
|
489
487
|
}), { ref: this._cartesianChartRef,
|
|
@@ -536,7 +534,7 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
536
534
|
this.setState({
|
|
537
535
|
refSelected: mouseEvent,
|
|
538
536
|
/** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */
|
|
539
|
-
isCalloutVisible: this.
|
|
537
|
+
isCalloutVisible: this._noLegendHighlighted() || this._legendHighlighted(point.legend),
|
|
540
538
|
dataForHoverCard: point.y,
|
|
541
539
|
calloutLegend: point.legend,
|
|
542
540
|
color: point.color || color,
|
|
@@ -546,7 +544,7 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
546
544
|
yCalloutValue: point.yAxisCalloutData,
|
|
547
545
|
dataPointCalloutProps: point,
|
|
548
546
|
// Hovering over a bar should highlight corresponding line points only when no legend is selected
|
|
549
|
-
activeXdataPoint: this._noLegendHighlighted() ? point.x : null,
|
|
547
|
+
activeXdataPoint: this._noLegendHighlighted() || this._legendHighlighted(point.legend) ? point.x : null,
|
|
550
548
|
YValueHover: YValueHover,
|
|
551
549
|
hoverXValue: hoverXValue,
|
|
552
550
|
callOutAccessibilityData: point.callOutAccessibilityData,
|
|
@@ -798,18 +796,6 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
798
796
|
}
|
|
799
797
|
return bars;
|
|
800
798
|
};
|
|
801
|
-
VerticalBarChartBase.prototype._onLegendClick = function (legendTitle) {
|
|
802
|
-
if (this.state.selectedLegend === legendTitle) {
|
|
803
|
-
this.setState({
|
|
804
|
-
selectedLegend: '',
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
else {
|
|
808
|
-
this.setState({
|
|
809
|
-
selectedLegend: legendTitle,
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
799
|
VerticalBarChartBase.prototype._onLegendHover = function (legendTitle) {
|
|
814
800
|
this.setState({
|
|
815
801
|
activeLegend: legendTitle,
|
|
@@ -817,9 +803,28 @@ define(["require", "exports", "tslib", "react", "d3-array", "d3-shape", "d3-sele
|
|
|
817
803
|
};
|
|
818
804
|
VerticalBarChartBase.prototype._onLegendLeave = function () {
|
|
819
805
|
this.setState({
|
|
820
|
-
activeLegend:
|
|
806
|
+
activeLegend: undefined,
|
|
821
807
|
});
|
|
822
808
|
};
|
|
809
|
+
VerticalBarChartBase.prototype._onLegendSelectionChange = function (selectedLegends, event, currentLegend) {
|
|
810
|
+
var _a, _b;
|
|
811
|
+
if ((_a = this.props.legendProps) === null || _a === void 0 ? void 0 : _a.canSelectMultipleLegends) {
|
|
812
|
+
this.setState({ selectedLegends: selectedLegends });
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
this.setState({ selectedLegends: selectedLegends.slice(-1) });
|
|
816
|
+
}
|
|
817
|
+
if ((_b = this.props.legendProps) === null || _b === void 0 ? void 0 : _b.onChange) {
|
|
818
|
+
this.props.legendProps.onChange(selectedLegends, event, currentLegend);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
VerticalBarChartBase.prototype._getHighlightedLegend = function () {
|
|
822
|
+
return this.state.selectedLegends.length > 0
|
|
823
|
+
? this.state.selectedLegends
|
|
824
|
+
: this.state.activeLegend
|
|
825
|
+
? [this.state.activeLegend]
|
|
826
|
+
: [];
|
|
827
|
+
};
|
|
823
828
|
VerticalBarChartBase.prototype._renderBarLabel = function (xPoint, yPoint, barValue, legend, isNegativeBar) {
|
|
824
829
|
if (this.props.hideLabels ||
|
|
825
830
|
this._barWidth < 16 ||
|