@fluentui/react-charts 9.0.2 → 9.0.4
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.md +64 -7
- package/dist/index.d.ts +829 -94
- package/lib/AreaChart.js +1 -0
- package/lib/AreaChart.js.map +1 -0
- package/lib/HeatMapChart.js +1 -0
- package/lib/HeatMapChart.js.map +1 -0
- package/lib/HorizontalBarChartWithAxis.js +1 -0
- package/lib/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib/SankeyChart.js +1 -0
- package/lib/SankeyChart.js.map +1 -0
- package/lib/VerticalStackedBarChart.js +1 -0
- package/lib/VerticalStackedBarChart.js.map +1 -0
- package/lib/components/AreaChart/AreaChart.js +775 -0
- package/lib/components/AreaChart/AreaChart.js.map +1 -0
- package/lib/components/AreaChart/AreaChart.types.js +4 -0
- package/lib/components/AreaChart/AreaChart.types.js.map +1 -0
- package/lib/components/AreaChart/index.js +3 -0
- package/lib/components/AreaChart/index.js.map +1 -0
- package/lib/components/AreaChart/useAreaChartStyles.styles.js +55 -0
- package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
- package/lib/components/CommonComponents/CartesianChart.js +30 -14
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/CommonComponents/ChartPopover.js +2 -2
- package/lib/components/CommonComponents/ChartPopover.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +7 -123
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib/components/CommonComponents/useChartPopoverStyles.styles.js +11 -22
- package/lib/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +112 -65
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +570 -159
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/Arc/Arc.js +1 -1
- package/lib/components/DonutChart/Arc/Arc.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +1 -1
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/DonutChart/Pie/usePieStyles.styles.js +2 -6
- package/lib/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.js +4 -1
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js +13 -9
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -9
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HeatMapChart/HeatMapChart.js +588 -0
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -0
- package/lib/components/HeatMapChart/HeatMapChart.types.js +4 -0
- package/lib/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
- package/lib/components/HeatMapChart/index.js +3 -0
- package/lib/components/HeatMapChart/index.js.map +1 -0
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +37 -0
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +2 -9
- package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +571 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +4 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/index.js +3 -0
- package/lib/components/HorizontalBarChartWithAxis/index.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +67 -0
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
- package/lib/components/Legends/Legends.js +38 -37
- package/lib/components/Legends/Legends.js.map +1 -1
- package/lib/components/Legends/useLegendsStyles.styles.js +2 -3
- package/lib/components/Legends/useLegendsStyles.styles.js.map +1 -1
- package/lib/components/LineChart/LineChart.js +43 -35
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/LineChart/useLineChartStyles.styles.js +1 -10
- package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js +1023 -0
- package/lib/components/SankeyChart/SankeyChart.js.map +1 -0
- package/lib/components/SankeyChart/SankeyChart.types.js +3 -0
- package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -0
- package/lib/components/SankeyChart/index.js +3 -0
- package/lib/components/SankeyChart/index.js.map +1 -0
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +109 -0
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
- package/lib/components/ScatterChart/ScatterChart.js +46 -59
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -10
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +165 -88
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +3 -11
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +904 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +1 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/index.js +3 -0
- package/lib/components/VerticalStackedBarChart/index.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +65 -0
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/types/DataPoint.js +1 -3
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/SVGTooltipText.js +49 -4
- package/lib/utilities/SVGTooltipText.js.map +1 -1
- package/lib/utilities/colors.js +20 -0
- package/lib/utilities/colors.js.map +1 -1
- package/lib/utilities/string.js +32 -0
- package/lib/utilities/string.js.map +1 -0
- package/lib/utilities/test-data.js +53 -0
- package/lib/utilities/test-data.js.map +1 -1
- package/lib/utilities/utilities.js +90 -18
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/AreaChart.js +6 -0
- package/lib-commonjs/AreaChart.js.map +1 -0
- package/lib-commonjs/HeatMapChart.js +6 -0
- package/lib-commonjs/HeatMapChart.js.map +1 -0
- package/lib-commonjs/HorizontalBarChartWithAxis.js +6 -0
- package/lib-commonjs/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib-commonjs/SankeyChart.js +6 -0
- package/lib-commonjs/SankeyChart.js.map +1 -0
- package/lib-commonjs/VerticalStackedBarChart.js +6 -0
- package/lib-commonjs/VerticalStackedBarChart.js.map +1 -0
- package/lib-commonjs/components/AreaChart/AreaChart.js +781 -0
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -0
- package/lib-commonjs/components/AreaChart/AreaChart.types.js +7 -0
- package/lib-commonjs/components/AreaChart/AreaChart.types.js.map +1 -0
- package/lib-commonjs/components/AreaChart/index.js +8 -0
- package/lib-commonjs/components/AreaChart/index.js.map +1 -0
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +95 -0
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +29 -14
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/ChartPopover.js +2 -2
- package/lib-commonjs/components/CommonComponents/ChartPopover.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +8 -198
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js +12 -37
- package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +120 -73
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +592 -178
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Arc/Arc.js +1 -1
- package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js +3 -10
- package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js +4 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js +14 -8
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -9
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +599 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js +7 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/index.js +8 -0
- package/lib-commonjs/components/HeatMapChart/index.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +59 -0
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +2 -16
- package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +580 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +7 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js +8 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +107 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
- package/lib-commonjs/components/Legends/Legends.js +37 -37
- package/lib-commonjs/components/Legends/Legends.js.map +1 -1
- package/lib-commonjs/components/Legends/useLegendsStyles.styles.js +2 -2
- package/lib-commonjs/components/Legends/useLegendsStyles.styles.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js +41 -33
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +1 -10
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js +1039 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.types.js +6 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/index.js +8 -0
- package/lib-commonjs/components/SankeyChart/index.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +179 -0
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +45 -58
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +1 -10
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +164 -87
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +4 -11
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +915 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +6 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/index.js +8 -0
- package/lib-commonjs/components/VerticalStackedBarChart/index.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +113 -0
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
- package/lib-commonjs/index.js +5 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js +1 -3
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/SVGTooltipText.js +49 -4
- package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
- package/lib-commonjs/utilities/colors.js +23 -0
- package/lib-commonjs/utilities/colors.js.map +1 -1
- package/lib-commonjs/utilities/string.js +29 -0
- package/lib-commonjs/utilities/string.js.map +1 -0
- package/lib-commonjs/utilities/test-data.js +59 -0
- package/lib-commonjs/utilities/test-data.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +94 -17
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +11 -8
- package/lib/components/DeclarativeChart/PlotlySchema.js +0 -7
- package/lib/components/DeclarativeChart/PlotlySchema.js.map +0 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +0 -10
- package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +0 -1
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { max as d3Max } from 'd3-array';
|
|
3
|
+
import { select as d3Select } from 'd3-selection';
|
|
4
|
+
import { scaleLinear as d3ScaleLinear, scaleBand as d3ScaleBand } from 'd3-scale';
|
|
5
|
+
import { Legends } from '../../components/Legends/Legends';
|
|
6
|
+
import { useId } from '@fluentui/react-utilities';
|
|
7
|
+
import { useHorizontalBarChartWithAxisStyles } from './useHorizontalBarChartWithAxisStyles.styles';
|
|
8
|
+
import { CartesianChart } from '../CommonComponents/CartesianChart';
|
|
9
|
+
import { ChartPopover } from '../CommonComponents/ChartPopover';
|
|
10
|
+
import { ChartTypes, getAccessibleDataObject, YAxisType, XAxisTypes, getTypeOfAxis, getNextColor, areArraysEqual, useRtl, DataVizPalette, getColorFromToken } from '../../utilities/index';
|
|
11
|
+
export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
12
|
+
var _props_legendProps, _props_legendProps1, _props_legendProps2, _props_legendProps3;
|
|
13
|
+
const _refArray = [];
|
|
14
|
+
const _calloutId = useId('callout');
|
|
15
|
+
const _isRtl = useRtl();
|
|
16
|
+
const _tooltipId = useId('HBCWATooltipID_');
|
|
17
|
+
const _xAxisType = props.data && props.data.length > 0 ? getTypeOfAxis(props.data[0].x, true) : XAxisTypes.NumericAxis;
|
|
18
|
+
const _yAxisType = props.data && props.data.length > 0 ? getTypeOfAxis(props.data[0].y, false) : YAxisType.StringAxis;
|
|
19
|
+
const _emptyChartId = useId('_HBCWithAxis_empty');
|
|
20
|
+
let _points = [];
|
|
21
|
+
let _barHeight = 0;
|
|
22
|
+
let _colors = [];
|
|
23
|
+
let _margins;
|
|
24
|
+
let _bars;
|
|
25
|
+
let _yAxisLabels;
|
|
26
|
+
let _xMax;
|
|
27
|
+
let _calloutAnchorPoint;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
let tooltipElement;
|
|
30
|
+
const cartesianChartRef = React.useRef(null);
|
|
31
|
+
const [color, setColor] = React.useState('');
|
|
32
|
+
const [dataForHoverCard, setDataForHoverCard] = React.useState(0);
|
|
33
|
+
const [isLegendSelected, setIsLegendSelected] = React.useState(((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends) && props.legendProps.selectedLegends.length > 0 || ((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.selectedLegend) !== undefined);
|
|
34
|
+
const [isLegendHovered, setIsLegendHovered] = React.useState(false);
|
|
35
|
+
var _props_legendProps_selectedLegend;
|
|
36
|
+
const [selectedLegendTitle, setSelectedLegendTitle] = React.useState((_props_legendProps_selectedLegend = (_props_legendProps2 = props.legendProps) === null || _props_legendProps2 === void 0 ? void 0 : _props_legendProps2.selectedLegend) !== null && _props_legendProps_selectedLegend !== void 0 ? _props_legendProps_selectedLegend : '');
|
|
37
|
+
const [xCalloutValue, setXCalloutValue] = React.useState('');
|
|
38
|
+
const [yCalloutValue, setYCalloutValue] = React.useState('');
|
|
39
|
+
const [selectedLegends, setSelectedLegends] = React.useState(((_props_legendProps3 = props.legendProps) === null || _props_legendProps3 === void 0 ? void 0 : _props_legendProps3.selectedLegends) || []);
|
|
40
|
+
const [dataPointCalloutProps, setDataPointCalloutProps] = React.useState();
|
|
41
|
+
const [callOutAccessibilityData, setCallOutAccessibilityData] = React.useState();
|
|
42
|
+
const [isPopoverOpen, setPopoverOpen] = React.useState(false);
|
|
43
|
+
const [clickPosition, setClickPosition] = React.useState({
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0
|
|
46
|
+
});
|
|
47
|
+
const prevPropsRef = React.useRef(null);
|
|
48
|
+
React.useEffect(()=>{
|
|
49
|
+
if (prevPropsRef.current) {
|
|
50
|
+
var _prevProps_legendProps, _props_legendProps;
|
|
51
|
+
const prevProps = prevPropsRef.current;
|
|
52
|
+
if (!areArraysEqual((_prevProps_legendProps = prevProps.legendProps) === null || _prevProps_legendProps === void 0 ? void 0 : _prevProps_legendProps.selectedLegends, (_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends)) {
|
|
53
|
+
var _props_legendProps1;
|
|
54
|
+
setSelectedLegends(((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.selectedLegends) || []);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
prevPropsRef.current = props;
|
|
58
|
+
}, [
|
|
59
|
+
props
|
|
60
|
+
]);
|
|
61
|
+
React.useImperativeHandle(props.componentRef, ()=>{
|
|
62
|
+
var _cartesianChartRef_current;
|
|
63
|
+
var _cartesianChartRef_current_chartContainer;
|
|
64
|
+
return {
|
|
65
|
+
chartContainer: (_cartesianChartRef_current_chartContainer = (_cartesianChartRef_current = cartesianChartRef.current) === null || _cartesianChartRef_current === void 0 ? void 0 : _cartesianChartRef_current.chartContainer) !== null && _cartesianChartRef_current_chartContainer !== void 0 ? _cartesianChartRef_current_chartContainer : null
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
const classes = useHorizontalBarChartWithAxisStyles(props);
|
|
69
|
+
function _adjustProps() {
|
|
70
|
+
_points = props.data || [];
|
|
71
|
+
_barHeight = props.barHeight || 32;
|
|
72
|
+
const defaultPalette = [
|
|
73
|
+
getColorFromToken(DataVizPalette.color6),
|
|
74
|
+
getColorFromToken(DataVizPalette.color1),
|
|
75
|
+
getColorFromToken(DataVizPalette.color5),
|
|
76
|
+
getColorFromToken(DataVizPalette.color7)
|
|
77
|
+
];
|
|
78
|
+
_colors = props.colors || defaultPalette;
|
|
79
|
+
}
|
|
80
|
+
function _getMargins(margins) {
|
|
81
|
+
_margins = margins;
|
|
82
|
+
}
|
|
83
|
+
function _renderContentForOnlyBars(point) {
|
|
84
|
+
const { useSingleColor = false } = props;
|
|
85
|
+
let selectedPointIndex = 0;
|
|
86
|
+
props.data.forEach((yDataPoint, index)=>{
|
|
87
|
+
if (yDataPoint.y === point.y) {
|
|
88
|
+
selectedPointIndex = index;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
92
|
+
let color;
|
|
93
|
+
if (useSingleColor) {
|
|
94
|
+
//if useSingle color , then check if user has given a palette or not
|
|
95
|
+
// and pick the first color from that or else from our paltette.
|
|
96
|
+
color = props.colors ? _createColors()(1) : getNextColor(1, 0);
|
|
97
|
+
} else {
|
|
98
|
+
color = point.color ? point.color : props.colors ? _createColors()(point.x) : getNextColor(selectedPointIndex, 0);
|
|
99
|
+
}
|
|
100
|
+
var _props_culture;
|
|
101
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ChartPopover, {
|
|
102
|
+
XValue: point.xAxisCalloutData || point.x.toString(),
|
|
103
|
+
legend: point.legend,
|
|
104
|
+
YValue: point.yAxisCalloutData || point.y,
|
|
105
|
+
color: color,
|
|
106
|
+
culture: (_props_culture = props.culture) !== null && _props_culture !== void 0 ? _props_culture : 'en-us',
|
|
107
|
+
clickPosition: clickPosition,
|
|
108
|
+
isPopoverOpen: isPopoverOpen
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
112
|
+
function _renderCallout(props) {
|
|
113
|
+
return props ? _renderContentForOnlyBars(props) : null;
|
|
114
|
+
}
|
|
115
|
+
function _getCustomizedCallout() {
|
|
116
|
+
return props.onRenderCalloutPerDataPoint ? props.onRenderCalloutPerDataPoint(dataPointCalloutProps, _renderCallout) : null;
|
|
117
|
+
}
|
|
118
|
+
function _getGraphData(xScale, yScale, containerHeight, containerWidth, xElement, yElement) {
|
|
119
|
+
return _bars = _yAxisType === YAxisType.NumericAxis ? _createNumericBars(containerHeight, containerWidth, xElement, yElement) : _createStringBars(containerHeight, containerWidth, xElement, yElement);
|
|
120
|
+
}
|
|
121
|
+
function _createColors() {
|
|
122
|
+
const increment = _colors.length <= 1 ? 1 : 1 / (_colors.length - 1);
|
|
123
|
+
const { useSingleColor = false } = props;
|
|
124
|
+
if (useSingleColor) {
|
|
125
|
+
return (_p)=>{
|
|
126
|
+
const { colors } = props;
|
|
127
|
+
return colors && colors.length > 0 ? colors[0] : getColorFromToken(DataVizPalette.color16);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const domainValues = [];
|
|
131
|
+
for(let i = 0; i < _colors.length; i++){
|
|
132
|
+
domainValues.push(increment * i * _xMax);
|
|
133
|
+
}
|
|
134
|
+
const colorScale = d3ScaleLinear().domain(domainValues).range(_colors);
|
|
135
|
+
return colorScale;
|
|
136
|
+
}
|
|
137
|
+
function _refCallback(element, legendTitle) {
|
|
138
|
+
_refArray.push({
|
|
139
|
+
index: legendTitle,
|
|
140
|
+
refElement: element
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function _onBarHover(point, // eslint-disable-next-line @typescript-eslint/no-shadow
|
|
144
|
+
color, mouseEvent) {
|
|
145
|
+
mouseEvent.persist();
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
147
|
+
if ((isLegendSelected === false || _isLegendHighlighted(point.legend)) && _calloutAnchorPoint !== point) {
|
|
148
|
+
_calloutAnchorPoint = point;
|
|
149
|
+
setPopoverOpen(true);
|
|
150
|
+
_updatePosition(mouseEvent.clientX, mouseEvent.clientY);
|
|
151
|
+
setDataForHoverCard(point.x);
|
|
152
|
+
setSelectedLegendTitle(point.legend);
|
|
153
|
+
setColor(props.useSingleColor || props.enableGradient ? color : point.color);
|
|
154
|
+
// To display callout value, if no callout value given, taking given point.x value as a string.
|
|
155
|
+
setXCalloutValue(point.yAxisCalloutData || point.y.toString());
|
|
156
|
+
setYCalloutValue(point.xAxisCalloutData || point.x.toString());
|
|
157
|
+
setDataPointCalloutProps(point);
|
|
158
|
+
setCallOutAccessibilityData(point.callOutAccessibilityData);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function _onBarLeave() {
|
|
162
|
+
setPopoverOpen(false);
|
|
163
|
+
}
|
|
164
|
+
function _handleChartMouseLeave() {
|
|
165
|
+
_calloutAnchorPoint = null;
|
|
166
|
+
setPopoverOpen(false);
|
|
167
|
+
}
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
169
|
+
function _onBarFocus(point, refArrayIndexNumber, color) {
|
|
170
|
+
if ((isLegendSelected === false || _isLegendHighlighted(point.legend)) && _calloutAnchorPoint !== point) {
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
172
|
+
_refArray.forEach((obj, index)=>{
|
|
173
|
+
if (refArrayIndexNumber === index) {
|
|
174
|
+
setPopoverOpen(true);
|
|
175
|
+
setSelectedLegendTitle(point.legend);
|
|
176
|
+
setDataForHoverCard(point.x);
|
|
177
|
+
setColor(props.useSingleColor ? color : point.color);
|
|
178
|
+
setXCalloutValue(point.yAxisCalloutData || point.y.toString());
|
|
179
|
+
setYCalloutValue(point.xAxisCalloutData || point.x.toString());
|
|
180
|
+
setDataPointCalloutProps(point);
|
|
181
|
+
setCallOutAccessibilityData(point.callOutAccessibilityData);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function _getScales(containerHeight, containerWidth, isNumericScale) {
|
|
187
|
+
if (isNumericScale) {
|
|
188
|
+
const xMax = d3Max(_points, (point)=>point.x);
|
|
189
|
+
const yMax = d3Max(_points, (point)=>point.y);
|
|
190
|
+
const xBarScale = d3ScaleLinear().domain(_isRtl ? [
|
|
191
|
+
xMax,
|
|
192
|
+
0
|
|
193
|
+
] : [
|
|
194
|
+
0,
|
|
195
|
+
xMax
|
|
196
|
+
]).nice().range([
|
|
197
|
+
_margins.left,
|
|
198
|
+
containerWidth - _margins.right
|
|
199
|
+
]);
|
|
200
|
+
const yBarScale = d3ScaleLinear().domain([
|
|
201
|
+
0,
|
|
202
|
+
yMax
|
|
203
|
+
]).range([
|
|
204
|
+
containerHeight - _margins.bottom,
|
|
205
|
+
_margins.top
|
|
206
|
+
]);
|
|
207
|
+
return {
|
|
208
|
+
xBarScale,
|
|
209
|
+
yBarScale
|
|
210
|
+
};
|
|
211
|
+
} else {
|
|
212
|
+
const xMax = d3Max(_points, (point)=>point.x);
|
|
213
|
+
// please note these padding default values must be consistent in here
|
|
214
|
+
// and CatrtesianChartBase w for more details refer example
|
|
215
|
+
// http://using-d3js.com/04_07_ordinal_scales.html
|
|
216
|
+
const yBarScale = d3ScaleBand().domain(_yAxisLabels).range([
|
|
217
|
+
containerHeight - _margins.bottom - _barHeight / 2,
|
|
218
|
+
_margins.top + _barHeight / 2
|
|
219
|
+
]).padding(props.yAxisPadding || 0);
|
|
220
|
+
const xBarScale = d3ScaleLinear().domain(_isRtl ? [
|
|
221
|
+
xMax,
|
|
222
|
+
0
|
|
223
|
+
] : [
|
|
224
|
+
0,
|
|
225
|
+
xMax
|
|
226
|
+
]).nice().range([
|
|
227
|
+
_margins.left,
|
|
228
|
+
containerWidth - _margins.right
|
|
229
|
+
]);
|
|
230
|
+
return {
|
|
231
|
+
xBarScale,
|
|
232
|
+
yBarScale
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function _createNumericBars(containerHeight, containerWidth, xElement, yElement) {
|
|
237
|
+
const { useSingleColor = false } = props;
|
|
238
|
+
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, true);
|
|
239
|
+
const sortedBars = [
|
|
240
|
+
..._points
|
|
241
|
+
];
|
|
242
|
+
sortedBars.sort((a, b)=>{
|
|
243
|
+
const aValue = typeof a.y === 'number' ? a.y : parseFloat(a.y);
|
|
244
|
+
const bValue = typeof b.y === 'number' ? b.y : parseFloat(b.y);
|
|
245
|
+
return bValue - aValue;
|
|
246
|
+
});
|
|
247
|
+
const bars = sortedBars.map((point, index)=>{
|
|
248
|
+
let shouldHighlight = true;
|
|
249
|
+
if (isLegendHovered || isLegendSelected) {
|
|
250
|
+
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
251
|
+
}
|
|
252
|
+
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
253
|
+
if (barHeight < 1) {
|
|
254
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
255
|
+
key: point.x
|
|
256
|
+
}, " ");
|
|
257
|
+
}
|
|
258
|
+
let startColor;
|
|
259
|
+
if (useSingleColor) {
|
|
260
|
+
//if useSingle color , then check if user has given a palette or not
|
|
261
|
+
// and pick the first color from that or else from our paltette.
|
|
262
|
+
startColor = props.colors ? _createColors()(1) : getNextColor(1, 0);
|
|
263
|
+
} else {
|
|
264
|
+
startColor = props.colors ? _createColors()(point.x) : getNextColor(index, 0);
|
|
265
|
+
}
|
|
266
|
+
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
267
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
268
|
+
key: `${index}_${point.x}`
|
|
269
|
+
}, /*#__PURE__*/ React.createElement("rect", {
|
|
270
|
+
key: point.y,
|
|
271
|
+
x: _isRtl ? xBarScale(point.x) : _margins.left,
|
|
272
|
+
y: yBarScale(point.y) - _barHeight / 2,
|
|
273
|
+
"data-is-focusable": shouldHighlight,
|
|
274
|
+
width: _isRtl ? containerWidth - _margins.right - Math.max(xBarScale(point.x), 0) : Math.max(xBarScale(point.x), 0) - _margins.left,
|
|
275
|
+
height: _barHeight,
|
|
276
|
+
ref: (e)=>{
|
|
277
|
+
_refCallback(e, point.legend);
|
|
278
|
+
},
|
|
279
|
+
rx: props.roundCorners ? 3 : 0,
|
|
280
|
+
onClick: point.onClick,
|
|
281
|
+
onMouseOver: (event)=>_onBarHover(point, startColor, event),
|
|
282
|
+
"aria-label": _getAriaLabel(point),
|
|
283
|
+
role: "img",
|
|
284
|
+
"aria-labelledby": `toolTip${_calloutId}`,
|
|
285
|
+
onMouseLeave: _onBarLeave,
|
|
286
|
+
onFocus: ()=>_onBarFocus(point, index, startColor),
|
|
287
|
+
onBlur: _onBarLeave,
|
|
288
|
+
fill: startColor,
|
|
289
|
+
opacity: shouldHighlight ? 1 : 0.1,
|
|
290
|
+
tabIndex: point.legend !== '' ? 0 : undefined
|
|
291
|
+
}));
|
|
292
|
+
});
|
|
293
|
+
return bars;
|
|
294
|
+
}
|
|
295
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
296
|
+
function _tooltipOfYAxislabels(ytooltipProps) {
|
|
297
|
+
const { tooltipCls, yAxis, id } = ytooltipProps;
|
|
298
|
+
if (yAxis === null) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
const div = d3Select('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
|
|
302
|
+
const aa = yAxis.selectAll('#BaseSpan')._groups[0];
|
|
303
|
+
const baseSpanLength = aa && Object.keys(aa).length;
|
|
304
|
+
const originalDataArray = [];
|
|
305
|
+
for(let i = 0; i < baseSpanLength; i++){
|
|
306
|
+
const originalData = aa[i].dataset && Object.values(aa[i].dataset)[0];
|
|
307
|
+
originalDataArray.push(originalData);
|
|
308
|
+
}
|
|
309
|
+
const tickObject = yAxis.selectAll('.tick')._groups[0];
|
|
310
|
+
const tickObjectLength = tickObject && Object.keys(tickObject).length;
|
|
311
|
+
for(let i = 0; i < tickObjectLength; i++){
|
|
312
|
+
const d1 = tickObject[i];
|
|
313
|
+
d3Select(d1)// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
314
|
+
.on('mouseover', (event, d)=>{
|
|
315
|
+
if (!tooltipElement) {
|
|
316
|
+
div.style('opacity', 0.9);
|
|
317
|
+
div.text(originalDataArray[i]).style('left', event.pageX + 'px').style('top', event.pageY - 28 + 'px');
|
|
318
|
+
}
|
|
319
|
+
}).on('mouseout', (d)=>{
|
|
320
|
+
div.style('opacity', 0);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function _createStringBars(containerHeight, containerWidth, xElement, yElement) {
|
|
325
|
+
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, false);
|
|
326
|
+
const { useSingleColor = false } = props;
|
|
327
|
+
const bars = _points.map((point, index)=>{
|
|
328
|
+
let shouldHighlight = true;
|
|
329
|
+
if (isLegendHovered || isLegendSelected) {
|
|
330
|
+
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
331
|
+
}
|
|
332
|
+
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
333
|
+
if (barHeight < 1) {
|
|
334
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
335
|
+
key: point.x
|
|
336
|
+
}, " ");
|
|
337
|
+
}
|
|
338
|
+
let startColor;
|
|
339
|
+
if (useSingleColor) {
|
|
340
|
+
//if useSingle color , then check if user has given a palette or not
|
|
341
|
+
// and pick the first color from that or else from our paltette.
|
|
342
|
+
startColor = props.colors ? _createColors()(1) : getNextColor(1, 0);
|
|
343
|
+
} else {
|
|
344
|
+
startColor = props.colors ? _createColors()(point.x) : getNextColor(index, 0);
|
|
345
|
+
}
|
|
346
|
+
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
347
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
348
|
+
key: `${index}_${point.x}`
|
|
349
|
+
}, /*#__PURE__*/ React.createElement("rect", {
|
|
350
|
+
transform: `translate(0,${0.5 * (yBarScale.bandwidth() - _barHeight)})`,
|
|
351
|
+
key: point.x,
|
|
352
|
+
x: _isRtl ? xBarScale(point.x) : _margins.left,
|
|
353
|
+
y: yBarScale(point.y),
|
|
354
|
+
rx: props.roundCorners ? 3 : 0,
|
|
355
|
+
width: _isRtl ? containerWidth - _margins.right - Math.max(xBarScale(point.x), 0) : Math.max(xBarScale(point.x), 0) - _margins.left,
|
|
356
|
+
height: _barHeight,
|
|
357
|
+
"aria-labelledby": `toolTip${_calloutId}`,
|
|
358
|
+
"aria-label": _getAriaLabel(point),
|
|
359
|
+
role: "img",
|
|
360
|
+
ref: (e)=>{
|
|
361
|
+
_refCallback(e, point.legend);
|
|
362
|
+
},
|
|
363
|
+
onClick: point.onClick,
|
|
364
|
+
onMouseOver: (event)=>_onBarHover(point, startColor, event),
|
|
365
|
+
onMouseLeave: _onBarLeave,
|
|
366
|
+
onBlur: _onBarLeave,
|
|
367
|
+
"data-is-focusable": shouldHighlight,
|
|
368
|
+
opacity: shouldHighlight ? 1 : 0.1,
|
|
369
|
+
onFocus: ()=>_onBarFocus(point, index, startColor),
|
|
370
|
+
fill: startColor,
|
|
371
|
+
tabIndex: point.legend !== '' ? 0 : undefined
|
|
372
|
+
}));
|
|
373
|
+
});
|
|
374
|
+
// Removing un wanted tooltip div from DOM, when prop not provided, for proper cleanup
|
|
375
|
+
// of unwanted DOM elements, to prevent flacky behaviour in tooltips , that might occur
|
|
376
|
+
// in creating tooltips when tooltips are enabled( as we try to recreate a tspan with _tooltipId)
|
|
377
|
+
if (!props.showYAxisLablesTooltip) {
|
|
378
|
+
try {
|
|
379
|
+
// eslint-disable-next-line @nx/workspace-no-restricted-globals
|
|
380
|
+
document.getElementById(_tooltipId) && document.getElementById(_tooltipId).remove();
|
|
381
|
+
//eslint-disable-next-line no-empty
|
|
382
|
+
} catch (e) {}
|
|
383
|
+
}
|
|
384
|
+
// Used to display tooltip at y axis labels.
|
|
385
|
+
if (props.showYAxisLablesTooltip) {
|
|
386
|
+
const yAxisElement = d3Select(yElement).call(yBarScale);
|
|
387
|
+
if (!tooltipElement) {
|
|
388
|
+
try {
|
|
389
|
+
// eslint-disable-next-line @nx/workspace-no-restricted-globals
|
|
390
|
+
document.getElementById(_tooltipId) && document.getElementById(_tooltipId).remove();
|
|
391
|
+
//eslint-disable-next-line no-empty
|
|
392
|
+
} catch (e) {}
|
|
393
|
+
}
|
|
394
|
+
const ytooltipProps = {
|
|
395
|
+
tooltipCls: classes.tooltip,
|
|
396
|
+
id: _tooltipId,
|
|
397
|
+
yAxis: yAxisElement
|
|
398
|
+
};
|
|
399
|
+
yAxisElement && _tooltipOfYAxislabels(ytooltipProps);
|
|
400
|
+
}
|
|
401
|
+
return bars;
|
|
402
|
+
}
|
|
403
|
+
function _onLegendHover(customMessage) {
|
|
404
|
+
if (!_isLegendSelected()) {
|
|
405
|
+
setIsLegendHovered(true);
|
|
406
|
+
setSelectedLegendTitle(customMessage);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function _onLegendLeave(isLegendFocused) {
|
|
410
|
+
if (!!isLegendFocused || !_isLegendSelected()) {
|
|
411
|
+
setIsLegendHovered(false);
|
|
412
|
+
setSelectedLegendTitle('');
|
|
413
|
+
setIsLegendSelected(isLegendFocused ? false : _isLegendSelected());
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function _getLegendData(data) {
|
|
417
|
+
const { useSingleColor } = props;
|
|
418
|
+
const actions = [];
|
|
419
|
+
data.forEach((point, _index)=>{
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
421
|
+
const color = useSingleColor ? props.colors ? _createColors()(1) : getNextColor(1, 0) : point.color;
|
|
422
|
+
// mapping data to the format Legends component needs
|
|
423
|
+
const legend = {
|
|
424
|
+
title: point.legend,
|
|
425
|
+
color,
|
|
426
|
+
hoverAction: ()=>{
|
|
427
|
+
_handleChartMouseLeave();
|
|
428
|
+
_onLegendHover(point.legend);
|
|
429
|
+
},
|
|
430
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
431
|
+
onMouseOutAction: (isLegendSelected)=>{
|
|
432
|
+
_onLegendLeave(isLegendSelected);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
actions.push(legend);
|
|
436
|
+
});
|
|
437
|
+
const legends = /*#__PURE__*/ React.createElement(Legends, {
|
|
438
|
+
legends: actions,
|
|
439
|
+
enabledWrapLines: props.enabledLegendsWrapLines,
|
|
440
|
+
overflowText: props.legendsOverflowText,
|
|
441
|
+
...props.legendProps,
|
|
442
|
+
onChange: _onLegendSelectionChange
|
|
443
|
+
});
|
|
444
|
+
return legends;
|
|
445
|
+
}
|
|
446
|
+
function _isLegendSelected() {
|
|
447
|
+
return isLegendSelected;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* This function checks if the given legend is highlighted or not.
|
|
451
|
+
* A legend can be highlighted in 2 ways:
|
|
452
|
+
* 1. selection: if the user clicks on it
|
|
453
|
+
* 2. hovering: if there is no selected legend and the user hovers over it
|
|
454
|
+
*/ function _isLegendHighlighted(legend) {
|
|
455
|
+
return _getHighlightedLegend().includes(legend);
|
|
456
|
+
}
|
|
457
|
+
function _getHighlightedLegend() {
|
|
458
|
+
return selectedLegends.length > 0 ? selectedLegends : selectedLegendTitle ? [
|
|
459
|
+
selectedLegendTitle
|
|
460
|
+
] : [];
|
|
461
|
+
}
|
|
462
|
+
function _onLegendSelectionChange(// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
463
|
+
selectedLegends, event, currentLegend) {
|
|
464
|
+
var _props_legendProps, _props_legendProps1;
|
|
465
|
+
if ((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.canSelectMultipleLegends) {
|
|
466
|
+
setSelectedLegends(selectedLegends);
|
|
467
|
+
setSelectedLegendTitle(currentLegend === null || currentLegend === void 0 ? void 0 : currentLegend.title);
|
|
468
|
+
} else {
|
|
469
|
+
setSelectedLegends(selectedLegends.slice(-1));
|
|
470
|
+
setSelectedLegendTitle(currentLegend === null || currentLegend === void 0 ? void 0 : currentLegend.title);
|
|
471
|
+
}
|
|
472
|
+
setIsLegendSelected(selectedLegends.length > 0);
|
|
473
|
+
if ((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.onChange) {
|
|
474
|
+
props.legendProps.onChange(selectedLegends, event, currentLegend);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function _getAxisData(yAxisData) {
|
|
478
|
+
if (yAxisData && yAxisData.yAxisDomainValues.length) {
|
|
479
|
+
// For HBCWA x and y Values are swapped
|
|
480
|
+
const { yAxisDomainValues: domainValue } = yAxisData;
|
|
481
|
+
_xMax = Math.max(domainValue[domainValue.length - 1], props.xMaxValue || 0);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function _getAriaLabel(point) {
|
|
485
|
+
var _point_callOutAccessibilityData;
|
|
486
|
+
const xValue = point.xAxisCalloutData || point.x;
|
|
487
|
+
const yValue = point.yAxisCalloutData || point.y;
|
|
488
|
+
return ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ` + `${yValue}.`;
|
|
489
|
+
}
|
|
490
|
+
function _getChartTitle() {
|
|
491
|
+
const { chartTitle, data } = props;
|
|
492
|
+
return (chartTitle ? `${chartTitle}. ` : '') + `Horizontal bar chart with ${(data === null || data === void 0 ? void 0 : data.length) || 0} bars. `;
|
|
493
|
+
}
|
|
494
|
+
function _isChartEmpty() {
|
|
495
|
+
return !(props.data && props.data.length > 0);
|
|
496
|
+
}
|
|
497
|
+
function _updatePosition(newX, newY) {
|
|
498
|
+
const threshold = 1; // Set a threshold for movement
|
|
499
|
+
const { x, y } = clickPosition;
|
|
500
|
+
// Calculate the distance moved
|
|
501
|
+
const distance = Math.sqrt(Math.pow(newX - x, 2) + Math.pow(newY - y, 2));
|
|
502
|
+
// Update the position only if the distance moved is greater than the threshold
|
|
503
|
+
if (distance > threshold) {
|
|
504
|
+
setClickPosition({
|
|
505
|
+
x: newX,
|
|
506
|
+
y: newY
|
|
507
|
+
});
|
|
508
|
+
setPopoverOpen(true);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (!_isChartEmpty()) {
|
|
512
|
+
_adjustProps();
|
|
513
|
+
const calloutProps = {
|
|
514
|
+
color: color,
|
|
515
|
+
legend: selectedLegendTitle,
|
|
516
|
+
XValue: xCalloutValue,
|
|
517
|
+
YValue: yCalloutValue ? yCalloutValue : dataForHoverCard,
|
|
518
|
+
...props.calloutProps,
|
|
519
|
+
...getAccessibleDataObject(callOutAccessibilityData),
|
|
520
|
+
customCallout: {
|
|
521
|
+
customizedCallout: _getCustomizedCallout() !== null ? _getCustomizedCallout() : undefined,
|
|
522
|
+
customCalloutProps: props.calloutPropsPerDataPoint ? props.calloutPropsPerDataPoint(dataPointCalloutProps) : undefined
|
|
523
|
+
},
|
|
524
|
+
isCartesian: true,
|
|
525
|
+
isPopoverOpen,
|
|
526
|
+
clickPosition
|
|
527
|
+
};
|
|
528
|
+
const tickParams = {
|
|
529
|
+
tickValues: props.tickValues,
|
|
530
|
+
tickFormat: props.tickFormat
|
|
531
|
+
};
|
|
532
|
+
const reversedBars = [
|
|
533
|
+
..._points
|
|
534
|
+
].reverse();
|
|
535
|
+
_yAxisLabels = reversedBars.map((point)=>point.y);
|
|
536
|
+
_xMax = Math.max(d3Max(_points, (point)=>point.x), props.xMaxValue || 0);
|
|
537
|
+
const legendBars = _getLegendData(_points);
|
|
538
|
+
return /*#__PURE__*/ React.createElement(CartesianChart, {
|
|
539
|
+
...props,
|
|
540
|
+
chartTitle: _getChartTitle(),
|
|
541
|
+
points: _points,
|
|
542
|
+
chartType: ChartTypes.HorizontalBarChartWithAxis,
|
|
543
|
+
xAxisType: _xAxisType,
|
|
544
|
+
yAxisType: _yAxisType,
|
|
545
|
+
stringDatasetForYAxisDomain: _yAxisLabels,
|
|
546
|
+
calloutProps: calloutProps,
|
|
547
|
+
tickParams: tickParams,
|
|
548
|
+
legendBars: legendBars,
|
|
549
|
+
barwidth: _barHeight,
|
|
550
|
+
getmargins: _getMargins,
|
|
551
|
+
getGraphData: _getGraphData,
|
|
552
|
+
getAxisData: _getAxisData,
|
|
553
|
+
onChartMouseLeave: _handleChartMouseLeave,
|
|
554
|
+
componentRef: cartesianChartRef,
|
|
555
|
+
/* eslint-disable react/jsx-no-bind */ // eslint-disable-next-line @typescript-eslint/no-shadow
|
|
556
|
+
children: (props)=>{
|
|
557
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("g", null, _bars));
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
} else {
|
|
561
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
562
|
+
id: _emptyChartId,
|
|
563
|
+
role: 'alert',
|
|
564
|
+
style: {
|
|
565
|
+
opacity: '0'
|
|
566
|
+
},
|
|
567
|
+
"aria-label": 'Graph has no data to display'
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
HorizontalBarChartWithAxis.displayName = 'HorizontalBarChartWithAxis';
|