@fluentui/react-charts 9.0.2 → 9.0.3
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 +48 -7
- package/dist/index.d.ts +767 -0
- 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 +64 -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/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/GaugeChart/GaugeChart.js +3 -0
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.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 +46 -0
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- 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 +76 -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/LineChart/LineChart.js +43 -35
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js +1022 -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/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/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 +73 -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 +104 -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/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/GaugeChart/GaugeChart.js +3 -0
- 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/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.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 +68 -0
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- 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 +116 -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/LineChart/LineChart.js +41 -33
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js +1038 -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/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/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 +120 -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
|
@@ -7,7 +7,7 @@ import { scaleLinear as d3ScaleLinear, scaleBand as d3ScaleBand, scaleUtc as d3S
|
|
|
7
7
|
import { useId } from '@fluentui/react-utilities';
|
|
8
8
|
import { tokens } from '@fluentui/react-theme';
|
|
9
9
|
import { CartesianChart, Legends, ChartPopover } from '../../index';
|
|
10
|
-
import { ChartTypes, getAccessibleDataObject, XAxisTypes, getTypeOfAxis, tooltipOfXAxislabels, formatValueWithSIPrefix, getBarWidth, getScalePadding, isScalePaddingDefined, calculateAppropriateBarWidth, useRtl } from '../../utilities/index';
|
|
10
|
+
import { ChartTypes, getAccessibleDataObject, XAxisTypes, getTypeOfAxis, tooltipOfXAxislabels, formatValueWithSIPrefix, getBarWidth, getScalePadding, isScalePaddingDefined, calculateAppropriateBarWidth, useRtl, areArraysEqual, calculateLongestLabelWidth } from '../../utilities/index';
|
|
11
11
|
var CircleVisbility;
|
|
12
12
|
(function(CircleVisbility) {
|
|
13
13
|
CircleVisbility["show"] = "visibility";
|
|
@@ -19,6 +19,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
19
19
|
* VerticalBarchart component
|
|
20
20
|
* {@docCategory VerticalBarChart}
|
|
21
21
|
*/ export const VerticalBarChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
22
|
+
var _props_legendProps;
|
|
22
23
|
let _points = [];
|
|
23
24
|
let _barWidth = 0;
|
|
24
25
|
let _colors;
|
|
@@ -28,6 +29,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
28
29
|
let _bars;
|
|
29
30
|
let _xAxisLabels;
|
|
30
31
|
let _yMax;
|
|
32
|
+
let _yMin;
|
|
31
33
|
let _isHavingLine = _checkForLine();
|
|
32
34
|
const _tooltipId = useId('VCTooltipID_');
|
|
33
35
|
const _xAxisType = props.data && props.data.length > 0 ? getTypeOfAxis(props.data[0].x, true) : XAxisTypes.StringAxis;
|
|
@@ -42,12 +44,11 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
42
44
|
const cartesianChartRef = React.useRef(null);
|
|
43
45
|
const [color, setColor] = React.useState('');
|
|
44
46
|
const [dataForHoverCard, setDataForHoverCard] = React.useState(0);
|
|
45
|
-
const [
|
|
46
|
-
const [activeLegend, setActiveLegend] = React.useState('');
|
|
47
|
+
const [activeLegend, setActiveLegend] = React.useState(undefined);
|
|
47
48
|
const [xCalloutValue, setXCalloutValue] = React.useState('');
|
|
48
49
|
const [yCalloutValue, setYCalloutValue] = React.useState('');
|
|
49
50
|
const [activeXdataPoint, setActiveXDatapoint] = React.useState(null);
|
|
50
|
-
const [
|
|
51
|
+
const [hoveredYValues, setYValueHover] = React.useState();
|
|
51
52
|
const [hoverXValue, setHoverXValue] = React.useState('');
|
|
52
53
|
const [calloutLegend, setCalloutLegend] = React.useState('');
|
|
53
54
|
const [callOutAccessibilityData, setCalloutAccessibilityData] = React.useState();
|
|
@@ -57,6 +58,8 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
57
58
|
y: 0
|
|
58
59
|
});
|
|
59
60
|
const [isPopoverOpen, setPopoverOpen] = React.useState(false);
|
|
61
|
+
const [selectedLegends, setSelectedLegends] = React.useState(((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends) || []);
|
|
62
|
+
const prevPropsRef = React.useRef(null);
|
|
60
63
|
React.useImperativeHandle(props.componentRef, ()=>{
|
|
61
64
|
var _cartesianChartRef_current;
|
|
62
65
|
var _cartesianChartRef_current_chartContainer;
|
|
@@ -64,6 +67,24 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
64
67
|
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
|
|
65
68
|
};
|
|
66
69
|
}, []);
|
|
70
|
+
React.useEffect(()=>{
|
|
71
|
+
if (prevPropsRef.current) {
|
|
72
|
+
var _prevProps_legendProps, _props_legendProps;
|
|
73
|
+
const prevProps = prevPropsRef.current;
|
|
74
|
+
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)) {
|
|
75
|
+
var _props_legendProps1;
|
|
76
|
+
setSelectedLegends(((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.selectedLegends) || []);
|
|
77
|
+
}
|
|
78
|
+
if (prevProps.height !== props.height || prevProps.width !== props.width) {
|
|
79
|
+
_adjustProps();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
prevPropsRef.current = props;
|
|
83
|
+
}, [
|
|
84
|
+
props,
|
|
85
|
+
prevPropsRef,
|
|
86
|
+
_adjustProps
|
|
87
|
+
]);
|
|
67
88
|
function _createLine(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
89
|
xScale, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
90
|
yScale, containerHeight = 0, containerWidth = 0, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -125,7 +146,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
125
146
|
id: `${_vbcPointId}-${index}`,
|
|
126
147
|
cx: isStringAxis ? xScale(item.x) + 0.5 * xScale.bandwidth() : xScale(item.x),
|
|
127
148
|
cy: item.useSecondaryYScale && yScaleSecondary ? yScaleSecondary(item.y) : yScale(item.y),
|
|
128
|
-
onMouseOver: _legendHighlighted(lineLegendText) ? _lineHover
|
|
149
|
+
onMouseOver: (event)=>_legendHighlighted(lineLegendText) ? _lineHover(item.point, event) : _onBarHover(item.point, colorScale(item.y), event),
|
|
129
150
|
onMouseOut: _onBarLeave,
|
|
130
151
|
r: _getCircleVisibilityAndRadius(item.x, lineLegendText).radius,
|
|
131
152
|
stroke: lineLegendColor,
|
|
@@ -145,13 +166,13 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
145
166
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, line, dots);
|
|
146
167
|
}
|
|
147
168
|
function _getCircleVisibilityAndRadius(xAxisPoint, legend) {
|
|
148
|
-
if (
|
|
149
|
-
if (xAxisPoint === activeXdataPoint &&
|
|
169
|
+
if (!_noLegendHighlighted()) {
|
|
170
|
+
if (xAxisPoint === activeXdataPoint && _legendHighlighted(legend)) {
|
|
150
171
|
return {
|
|
151
172
|
visibility: "visibility",
|
|
152
173
|
radius: 8
|
|
153
174
|
};
|
|
154
|
-
} else if (
|
|
175
|
+
} else if (_legendHighlighted(legend)) {
|
|
155
176
|
// Don't hide the circle to keep it focusable. For more information,
|
|
156
177
|
// see https://fuzzbomb.github.io/accessibility-demos/visually-hidden-focus-test.html
|
|
157
178
|
return {
|
|
@@ -271,10 +292,10 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
271
292
|
const { useSingleColor = false } = props;
|
|
272
293
|
const { data, lineLegendText, lineLegendColor = tokens.colorPaletteYellowBackground1 } = props;
|
|
273
294
|
const selectedPoint = data.filter((xDataPoint)=>xDataPoint.x === point.x);
|
|
274
|
-
//
|
|
275
|
-
if (_isHavingLine && ((_selectedPoint__lineData = selectedPoint[0].lineData) === null || _selectedPoint__lineData === void 0 ? void 0 : _selectedPoint__lineData.y) !== undefined) {
|
|
295
|
+
// Check if the line legend is highlighted or no legend is highlighted
|
|
296
|
+
if (_isHavingLine && ((_selectedPoint__lineData = selectedPoint[0].lineData) === null || _selectedPoint__lineData === void 0 ? void 0 : _selectedPoint__lineData.y) !== undefined && (_legendHighlighted(lineLegendText) || _noLegendHighlighted())) {
|
|
276
297
|
var _selectedPoint__lineData1, _selectedPoint__lineData2, _selectedPoint__lineData3;
|
|
277
|
-
// callout data for the
|
|
298
|
+
// Add callout data for the line
|
|
278
299
|
YValueHover.push({
|
|
279
300
|
legend: lineLegendText,
|
|
280
301
|
color: lineLegendColor,
|
|
@@ -283,14 +304,17 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
283
304
|
yAxisCalloutData: (_selectedPoint__lineData3 = selectedPoint[0].lineData) === null || _selectedPoint__lineData3 === void 0 ? void 0 : _selectedPoint__lineData3.yAxisCalloutData
|
|
284
305
|
});
|
|
285
306
|
}
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
307
|
+
// Check if the bar legend is highlighted or no legend is highlighted
|
|
308
|
+
if (selectedPoint[0].legend && (selectedLegends.includes(selectedPoint[0].legend) || _noLegendHighlighted())) {
|
|
309
|
+
// Add callout data for the bar
|
|
310
|
+
YValueHover.push({
|
|
311
|
+
legend: selectedPoint[0].legend,
|
|
312
|
+
y: selectedPoint[0].y,
|
|
313
|
+
color: !useSingleColor ? selectedPoint[0].color ? selectedPoint[0].color : _createColors()(selectedPoint[0].y) : _createColors()(1),
|
|
314
|
+
data: selectedPoint[0].yAxisCalloutData,
|
|
315
|
+
yAxisCalloutData: selectedPoint[0].yAxisCalloutData
|
|
316
|
+
});
|
|
317
|
+
}
|
|
294
318
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
295
319
|
const hoverXValue = point.x instanceof Date ? point.x.toLocaleString() : point.x.toString();
|
|
296
320
|
return {
|
|
@@ -306,7 +330,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
306
330
|
if (_calloutAnchorPoint !== point) {
|
|
307
331
|
_calloutAnchorPoint = point;
|
|
308
332
|
/** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */ updatePosition(mouseEvent.clientX, mouseEvent.clientY);
|
|
309
|
-
setPopoverOpen(
|
|
333
|
+
setPopoverOpen(_noLegendHighlighted() || _legendHighlighted(point.legend));
|
|
310
334
|
setDataForHoverCard(point.y);
|
|
311
335
|
setCalloutLegend(point.legend);
|
|
312
336
|
setColor(point.color || color);
|
|
@@ -335,7 +359,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
335
359
|
const { YValueHover, hoverXValue } = _getCalloutContentForLineAndBar(point);
|
|
336
360
|
_refArray.forEach((obj, index)=>{
|
|
337
361
|
if (obj.index === point.legend && refArrayIndexNumber === index) {
|
|
338
|
-
/** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */ setPopoverOpen(
|
|
362
|
+
/** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */ setPopoverOpen(_noLegendHighlighted() || _legendHighlighted(point.legend));
|
|
339
363
|
setDataForHoverCard(point.y);
|
|
340
364
|
setCalloutLegend(point.legend);
|
|
341
365
|
setColor(point.color || color);
|
|
@@ -362,7 +386,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
362
386
|
}
|
|
363
387
|
function _lineHoverFocus(point, _refSelected) {
|
|
364
388
|
const { lineLegendText = '', lineLegendColor = tokens.colorPaletteYellowBackground1 } = props;
|
|
365
|
-
setPopoverOpen(
|
|
389
|
+
setPopoverOpen(_noLegendHighlighted() || _legendHighlighted(lineLegendText));
|
|
366
390
|
setCalloutLegend(lineLegendText);
|
|
367
391
|
setDataForHoverCard(point.lineData.y);
|
|
368
392
|
setColor(lineLegendColor);
|
|
@@ -376,7 +400,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
376
400
|
let xBarScale;
|
|
377
401
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
402
|
const yBarScale = d3ScaleLinear().domain([
|
|
379
|
-
|
|
403
|
+
_yMin,
|
|
380
404
|
_yMax
|
|
381
405
|
]).range([
|
|
382
406
|
0,
|
|
@@ -423,31 +447,40 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
423
447
|
};
|
|
424
448
|
}
|
|
425
449
|
const classes = useVerticalBarChartStyles(props);
|
|
450
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
451
|
+
function _calculateMinBarHeight(yMin, yMax, yReferencePoint, yBarScale) {
|
|
452
|
+
const maxHeightFromBaseline = yMax < 0 ? Math.abs(yMin - yReferencePoint) : Math.max(Math.abs(yMax - yReferencePoint), Math.abs(yMin - yReferencePoint));
|
|
453
|
+
return Math.ceil(yBarScale(maxHeightFromBaseline) / 100.0);
|
|
454
|
+
}
|
|
426
455
|
function _createNumericBars(containerHeight, containerWidth, xElement) {
|
|
427
456
|
const { useSingleColor = false } = props;
|
|
428
457
|
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth);
|
|
429
458
|
const colorScale = _createColors();
|
|
459
|
+
const yReferencePoint = _yMax < 0 ? _yMax : 0;
|
|
430
460
|
const bars = _points.map((point, index)=>{
|
|
431
461
|
const shouldHighlight = _legendHighlighted(point.legend) || _noLegendHighlighted() ? true : false;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
462
|
+
let barHeight = yBarScale(point.y) - yBarScale(yReferencePoint);
|
|
463
|
+
const isHeightNegative = barHeight < 0;
|
|
464
|
+
barHeight = Math.abs(barHeight);
|
|
465
|
+
// Calculate threshold for minimum visible bar height
|
|
466
|
+
const minBarHeight = _calculateMinBarHeight(_yMin, _yMax, yReferencePoint, yBarScale);
|
|
467
|
+
let adjustedBarHeight = barHeight;
|
|
468
|
+
if (barHeight === 0) {
|
|
435
469
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
436
470
|
key: point.x
|
|
437
471
|
}, " ");
|
|
438
|
-
} else if (barHeight <=
|
|
439
|
-
adjustedBarHeight =
|
|
440
|
-
} else {
|
|
441
|
-
adjustedBarHeight = barHeight;
|
|
472
|
+
} else if (barHeight <= minBarHeight) {
|
|
473
|
+
adjustedBarHeight = minBarHeight;
|
|
442
474
|
}
|
|
443
475
|
const xPoint = xBarScale(point.x) - _barWidth / 2;
|
|
444
|
-
const yPoint = containerHeight - margins.bottom - adjustedBarHeight;
|
|
476
|
+
const yPoint = containerHeight - margins.bottom - (isHeightNegative ? -1 * adjustedBarHeight : adjustedBarHeight) - yBarScale(yReferencePoint);
|
|
477
|
+
const baselineHeight = containerHeight - margins.bottom - yBarScale(yReferencePoint);
|
|
445
478
|
return /*#__PURE__*/ React.createElement("g", {
|
|
446
|
-
key: point.x
|
|
479
|
+
key: `${point.x}_${index}`
|
|
447
480
|
}, /*#__PURE__*/ React.createElement("rect", {
|
|
448
481
|
id: `${_vbcBarId}-${index}`,
|
|
449
482
|
x: xPoint,
|
|
450
|
-
y: yPoint,
|
|
483
|
+
y: !isHeightNegative ? yPoint : baselineHeight,
|
|
451
484
|
width: _barWidth,
|
|
452
485
|
"data-is-focusable": !props.hideTooltip && shouldHighlight,
|
|
453
486
|
height: adjustedBarHeight,
|
|
@@ -463,8 +496,9 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
463
496
|
onBlur: _onBarLeave,
|
|
464
497
|
fill: point.color && !useSingleColor ? point.color : colorScale(point.y),
|
|
465
498
|
tabIndex: point.legend !== '' ? 0 : undefined,
|
|
466
|
-
opacity: shouldHighlight ?
|
|
467
|
-
|
|
499
|
+
opacity: shouldHighlight ? 1 : 0.1,
|
|
500
|
+
rx: props.roundCorners ? 3 : 0
|
|
501
|
+
}), _renderBarLabel(xPoint, yPoint, point.y, point.legend, isHeightNegative));
|
|
468
502
|
});
|
|
469
503
|
// Removing un wanted tooltip div from DOM, when prop not provided.
|
|
470
504
|
if (!props.showXAxisLablesTooltip) {
|
|
@@ -494,30 +528,35 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
494
528
|
function _createStringBars(containerHeight, containerWidth, xElement) {
|
|
495
529
|
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth);
|
|
496
530
|
const colorScale = _createColors();
|
|
531
|
+
const yReferencePoint = _yMax < 0 ? _yMax : 0;
|
|
497
532
|
const bars = _points.map((point, index)=>{
|
|
498
|
-
const
|
|
499
|
-
let
|
|
500
|
-
|
|
533
|
+
const shouldHighlight = _legendHighlighted(point.legend) || _noLegendHighlighted() ? true : false;
|
|
534
|
+
let barHeight = yBarScale(point.y) - yBarScale(yReferencePoint);
|
|
535
|
+
const isHeightNegative = barHeight < 0;
|
|
536
|
+
barHeight = Math.abs(barHeight);
|
|
537
|
+
// Calculate threshold for minimum visible bar height
|
|
538
|
+
const minBarHeight = _calculateMinBarHeight(_yMin, _yMax, yReferencePoint, yBarScale);
|
|
539
|
+
let adjustedBarHeight = barHeight;
|
|
540
|
+
if (barHeight === 0) {
|
|
501
541
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
502
|
-
key: point.x
|
|
542
|
+
key: point.x
|
|
503
543
|
}, " ");
|
|
504
|
-
} else if (barHeight <=
|
|
505
|
-
adjustedBarHeight =
|
|
506
|
-
} else {
|
|
507
|
-
adjustedBarHeight = barHeight;
|
|
544
|
+
} else if (barHeight <= minBarHeight) {
|
|
545
|
+
adjustedBarHeight = minBarHeight;
|
|
508
546
|
}
|
|
509
547
|
const xPoint = xBarScale(point.x);
|
|
510
|
-
const yPoint = containerHeight - margins.bottom - adjustedBarHeight;
|
|
548
|
+
const yPoint = containerHeight - margins.bottom - (isHeightNegative ? -1 * adjustedBarHeight : adjustedBarHeight) - yBarScale(yReferencePoint);
|
|
549
|
+
const baselineHeight = containerHeight - margins.bottom - yBarScale(yReferencePoint);
|
|
511
550
|
// Setting the bar width here is safe because there are no dependencies earlier in the code
|
|
512
551
|
// that rely on the width of bars in vertical bar charts with string x-axis.
|
|
513
552
|
_barWidth = getBarWidth(props.barWidth, props.maxBarWidth, xBarScale.bandwidth());
|
|
514
553
|
return /*#__PURE__*/ React.createElement("g", {
|
|
515
|
-
key: point.x instanceof Date ? point.x.getTime() : point.x
|
|
554
|
+
key: point.x instanceof Date ? `${point.x.getTime()}_${index}` : `${point.x}_${index}`,
|
|
516
555
|
transform: `translate(${0.5 * (xBarScale.bandwidth() - _barWidth)}, 0)`
|
|
517
556
|
}, /*#__PURE__*/ React.createElement("rect", {
|
|
518
557
|
id: `${_vbcBarId}-${index}`,
|
|
519
558
|
x: xPoint,
|
|
520
|
-
y: yPoint,
|
|
559
|
+
y: !isHeightNegative ? yPoint : baselineHeight,
|
|
521
560
|
width: _barWidth,
|
|
522
561
|
height: adjustedBarHeight,
|
|
523
562
|
"aria-label": _getAriaLabel(point),
|
|
@@ -529,11 +568,13 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
529
568
|
onMouseOver: (event)=>_onBarHover(point, colorScale(point.y), event),
|
|
530
569
|
onMouseLeave: _onBarLeave,
|
|
531
570
|
onBlur: _onBarLeave,
|
|
532
|
-
"data-is-focusable": !props.hideTooltip,
|
|
571
|
+
"data-is-focusable": !props.hideTooltip && shouldHighlight,
|
|
533
572
|
onFocus: _onBarFocus.bind(point, index, colorScale(point.y)),
|
|
534
573
|
fill: point.color ? point.color : colorScale(point.y),
|
|
535
|
-
tabIndex: point.legend !== '' ? 0 : undefined
|
|
536
|
-
|
|
574
|
+
tabIndex: point.legend !== '' ? 0 : undefined,
|
|
575
|
+
rx: props.roundCorners ? 3 : 0,
|
|
576
|
+
opacity: shouldHighlight ? 1 : 0.1
|
|
577
|
+
}), _renderBarLabel(xPoint, yPoint, point.y, point.legend, isHeightNegative));
|
|
537
578
|
});
|
|
538
579
|
// Removing un wanted tooltip div from DOM, when prop not provided.
|
|
539
580
|
if (!props.showXAxisLablesTooltip) {
|
|
@@ -565,28 +606,32 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
565
606
|
const { useSingleColor = false } = props;
|
|
566
607
|
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth);
|
|
567
608
|
const colorScale = _createColors();
|
|
609
|
+
const yReferencePoint = _yMax < 0 ? _yMax : 0;
|
|
568
610
|
const bars = _points.map((point, index)=>{
|
|
569
611
|
const shouldHighlight = _legendHighlighted(point.legend) || _noLegendHighlighted() ? true : false;
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
612
|
+
let barHeight = yBarScale(point.y) - yBarScale(yReferencePoint);
|
|
613
|
+
const isHeightNegative = barHeight < 0;
|
|
614
|
+
barHeight = Math.abs(barHeight);
|
|
615
|
+
// Calculate threshold for minimum visible bar height
|
|
616
|
+
const minBarHeight = _calculateMinBarHeight(_yMin, _yMax, yReferencePoint, yBarScale);
|
|
617
|
+
let adjustedBarHeight = barHeight;
|
|
618
|
+
if (barHeight === 0) {
|
|
573
619
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
574
|
-
key: point.x
|
|
620
|
+
key: point.x
|
|
575
621
|
}, " ");
|
|
576
|
-
} else if (barHeight <=
|
|
577
|
-
adjustedBarHeight =
|
|
578
|
-
} else {
|
|
579
|
-
adjustedBarHeight = barHeight;
|
|
622
|
+
} else if (barHeight <= minBarHeight) {
|
|
623
|
+
adjustedBarHeight = minBarHeight;
|
|
580
624
|
}
|
|
581
625
|
const xPoint = xBarScale(point.x) - _barWidth / 2;
|
|
582
|
-
const yPoint = containerHeight - margins.bottom - adjustedBarHeight;
|
|
626
|
+
const yPoint = containerHeight - margins.bottom - (isHeightNegative ? -1 * adjustedBarHeight : adjustedBarHeight) - yBarScale(yReferencePoint);
|
|
627
|
+
const baselineHeight = containerHeight - margins.bottom - yBarScale(yReferencePoint);
|
|
583
628
|
return /*#__PURE__*/ React.createElement("g", {
|
|
584
|
-
key: point.x instanceof Date ? point.x.getTime() : point.x
|
|
629
|
+
key: point.x instanceof Date ? `${point.x.getTime()}_${index}` : `${point.x}_${index}`
|
|
585
630
|
}, /*#__PURE__*/ React.createElement("rect", {
|
|
586
631
|
id: `${_vbcBarId}-${index}`,
|
|
587
632
|
x: xPoint,
|
|
588
633
|
className: classes.opacityChangeOnHover,
|
|
589
|
-
y: yPoint,
|
|
634
|
+
y: !isHeightNegative ? yPoint : baselineHeight,
|
|
590
635
|
width: _barWidth,
|
|
591
636
|
"data-is-focusable": !props.hideTooltip && shouldHighlight,
|
|
592
637
|
height: adjustedBarHeight,
|
|
@@ -601,8 +646,10 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
601
646
|
onFocus: _onBarFocus.bind(point, index, colorScale(point.y)),
|
|
602
647
|
onBlur: _onBarLeave,
|
|
603
648
|
fill: point.color && !useSingleColor ? point.color : colorScale(point.y),
|
|
604
|
-
tabIndex: point.legend !== '' ? 0 : undefined
|
|
605
|
-
|
|
649
|
+
tabIndex: point.legend !== '' ? 0 : undefined,
|
|
650
|
+
rx: props.roundCorners ? 3 : 0,
|
|
651
|
+
opacity: shouldHighlight ? 1 : 0.1
|
|
652
|
+
}), _renderBarLabel(xPoint, yPoint, point.y, point.legend, isHeightNegative));
|
|
606
653
|
});
|
|
607
654
|
// Removing un wanted tooltip div from DOM, when prop not provided.
|
|
608
655
|
if (!props.showXAxisLablesTooltip) {
|
|
@@ -629,36 +676,30 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
629
676
|
}
|
|
630
677
|
return bars;
|
|
631
678
|
}
|
|
632
|
-
function _onLegendClick(legendTitle) {
|
|
633
|
-
if (selectedLegend === legendTitle) {
|
|
634
|
-
setSelectedLegend('');
|
|
635
|
-
} else {
|
|
636
|
-
setSelectedLegend(legendTitle);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
679
|
function _onLegendHover(legendTitle) {
|
|
640
680
|
setActiveLegend(legendTitle);
|
|
641
681
|
}
|
|
642
682
|
function _onLegendLeave() {
|
|
643
|
-
setActiveLegend(
|
|
683
|
+
setActiveLegend(undefined);
|
|
644
684
|
}
|
|
645
685
|
function _getLegendData(data) {
|
|
646
686
|
const { useSingleColor } = props;
|
|
647
687
|
const { lineLegendText, lineLegendColor = tokens.colorPaletteYellowForeground1 } = props;
|
|
648
688
|
const actions = [];
|
|
689
|
+
const mapLegendToColor = {};
|
|
649
690
|
data.forEach((point, _index)=>{
|
|
650
691
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
651
692
|
const color = !useSingleColor ? point.color : _createColors()(1);
|
|
693
|
+
mapLegendToColor[point.legend] = color;
|
|
694
|
+
});
|
|
695
|
+
Object.entries(mapLegendToColor).forEach(([legendTitle, color])=>{
|
|
652
696
|
// mapping data to the format Legends component needs
|
|
653
697
|
const legend = {
|
|
654
|
-
title:
|
|
698
|
+
title: legendTitle,
|
|
655
699
|
color,
|
|
656
|
-
action: ()=>{
|
|
657
|
-
_onLegendClick(point.legend);
|
|
658
|
-
},
|
|
659
700
|
hoverAction: ()=>{
|
|
660
701
|
_handleChartMouseLeave();
|
|
661
|
-
_onLegendHover(
|
|
702
|
+
_onLegendHover(legendTitle);
|
|
662
703
|
},
|
|
663
704
|
onMouseOutAction: ()=>{
|
|
664
705
|
_onLegendLeave();
|
|
@@ -670,9 +711,6 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
670
711
|
const lineLegend = {
|
|
671
712
|
title: lineLegendText,
|
|
672
713
|
color: lineLegendColor,
|
|
673
|
-
action: ()=>{
|
|
674
|
-
_onLegendClick(lineLegendText);
|
|
675
|
-
},
|
|
676
714
|
hoverAction: ()=>{
|
|
677
715
|
_handleChartMouseLeave();
|
|
678
716
|
_onLegendHover(lineLegendText);
|
|
@@ -688,14 +726,28 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
688
726
|
legends: actions,
|
|
689
727
|
enabledWrapLines: props.enabledLegendsWrapLines,
|
|
690
728
|
overflowText: props.legendsOverflowText,
|
|
691
|
-
...props.legendProps
|
|
729
|
+
...props.legendProps,
|
|
730
|
+
selectedLegends: selectedLegends,
|
|
731
|
+
onChange: _onLegendSelectionChange
|
|
692
732
|
});
|
|
693
733
|
return legends;
|
|
694
734
|
}
|
|
735
|
+
function _onLegendSelectionChange(legendsSelected, event, currentLegend) {
|
|
736
|
+
var _props_legendProps, _props_legendProps1;
|
|
737
|
+
if ((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.canSelectMultipleLegends) {
|
|
738
|
+
setSelectedLegends(legendsSelected);
|
|
739
|
+
} else {
|
|
740
|
+
setSelectedLegends(legendsSelected.slice(-1));
|
|
741
|
+
}
|
|
742
|
+
if ((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.onChange) {
|
|
743
|
+
props.legendProps.onChange(legendsSelected, event, currentLegend);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
695
746
|
function _getAxisData(yAxisData) {
|
|
696
747
|
if (yAxisData && yAxisData.yAxisDomainValues.length) {
|
|
697
748
|
const { yAxisDomainValues: domainValue } = yAxisData;
|
|
698
749
|
_yMax = Math.max(domainValue[domainValue.length - 1], props.yMaxValue || 0);
|
|
750
|
+
_yMin = Math.min(domainValue[0], props.yMinValue || 0);
|
|
699
751
|
}
|
|
700
752
|
}
|
|
701
753
|
/**
|
|
@@ -704,12 +756,17 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
704
756
|
* 1. selection: if the user clicks on it
|
|
705
757
|
* 2. hovering: if there is no selected legend and the user hovers over it
|
|
706
758
|
*/ function _legendHighlighted(legendTitle) {
|
|
707
|
-
return
|
|
759
|
+
return _getHighlightedLegend().includes(legendTitle);
|
|
708
760
|
}
|
|
709
761
|
/**
|
|
710
762
|
* This function checks if none of the legends is selected or hovered.
|
|
711
763
|
*/ function _noLegendHighlighted() {
|
|
712
|
-
return
|
|
764
|
+
return _getHighlightedLegend().length === 0;
|
|
765
|
+
}
|
|
766
|
+
function _getHighlightedLegend() {
|
|
767
|
+
return selectedLegends.length > 0 ? selectedLegends : activeLegend ? [
|
|
768
|
+
activeLegend
|
|
769
|
+
] : [];
|
|
713
770
|
}
|
|
714
771
|
function _getAriaLabel(point) {
|
|
715
772
|
var _point_lineData, _point_lineData1, _point_callOutAccessibilityData;
|
|
@@ -720,13 +777,13 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
720
777
|
const lineYValue = ((_point_lineData = point.lineData) === null || _point_lineData === void 0 ? void 0 : _point_lineData.yAxisCalloutData) || ((_point_lineData1 = point.lineData) === null || _point_lineData1 === void 0 ? void 0 : _point_lineData1.y);
|
|
721
778
|
return ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ` + (legend ? `${legend}, ` : '') + `${yValue}.` + (typeof lineYValue !== 'undefined' ? ` ${lineLegend}, ${lineYValue}.` : '');
|
|
722
779
|
}
|
|
723
|
-
function _renderBarLabel(xPoint, yPoint, barValue, legend) {
|
|
780
|
+
function _renderBarLabel(xPoint, yPoint, barValue, legend, isNegativeBar) {
|
|
724
781
|
if (props.hideLabels || _barWidth < 16 || !(_legendHighlighted(legend) || _noLegendHighlighted())) {
|
|
725
782
|
return null;
|
|
726
783
|
}
|
|
727
784
|
return /*#__PURE__*/ React.createElement("text", {
|
|
728
785
|
x: xPoint + _barWidth / 2,
|
|
729
|
-
y: yPoint - 6,
|
|
786
|
+
y: isNegativeBar ? yPoint + 12 : yPoint - 6,
|
|
730
787
|
textAnchor: "middle",
|
|
731
788
|
className: classes.barLabel,
|
|
732
789
|
"aria-hidden": true
|
|
@@ -735,13 +792,13 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
735
792
|
function _getDomainMargins(containerWidth) {
|
|
736
793
|
_domainMargin = MIN_DOMAIN_MARGIN;
|
|
737
794
|
/** Total width available to render the bars */ const totalWidth = containerWidth - (margins.left + MIN_DOMAIN_MARGIN) - (margins.right + MIN_DOMAIN_MARGIN);
|
|
795
|
+
/** Rate at which the space between the bars changes wrt the bar width */ const barGapRate = _xAxisInnerPadding / (1 - _xAxisInnerPadding);
|
|
738
796
|
if (_xAxisType === XAxisTypes.StringAxis) {
|
|
739
797
|
if (isScalePaddingDefined(props.xAxisOuterPadding, props.xAxisPadding)) {
|
|
740
798
|
// Setting the domain margin for string x-axis to 0 because the xAxisOuterPadding prop is now available
|
|
741
799
|
// to adjust the space before the first bar and after the last bar.
|
|
742
800
|
_domainMargin = 0;
|
|
743
801
|
} else if (props.barWidth !== 'auto') {
|
|
744
|
-
/** Rate at which the space between the bars changes wrt the bar width */ const barGapRate = _xAxisInnerPadding / (1 - _xAxisInnerPadding);
|
|
745
802
|
// Update the bar width so that when CartesianChart rerenders,
|
|
746
803
|
// the following calculations don't use the previous bar width.
|
|
747
804
|
_barWidth = getBarWidth(props.barWidth, props.maxBarWidth);
|
|
@@ -750,10 +807,29 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
750
807
|
// Center align the chart by setting equal left and right margins for domain
|
|
751
808
|
_domainMargin = MIN_DOMAIN_MARGIN + (totalWidth - reqWidth) / 2;
|
|
752
809
|
}
|
|
810
|
+
} else if (props.mode === 'plotly' && _xAxisLabels.length > 1) {
|
|
811
|
+
// Calculate the remaining width after rendering bars at their maximum allowable width
|
|
812
|
+
const bandwidth = totalWidth / (_xAxisLabels.length + (_xAxisLabels.length - 1) * barGapRate);
|
|
813
|
+
const barWidth = getBarWidth(props.barWidth, props.maxBarWidth, bandwidth);
|
|
814
|
+
let reqWidth = (_xAxisLabels.length + (_xAxisLabels.length - 1) * barGapRate) * barWidth;
|
|
815
|
+
const margin1 = (totalWidth - reqWidth) / 2;
|
|
816
|
+
// Calculate the remaining width after accounting for the space required to render x-axis labels
|
|
817
|
+
const step = calculateLongestLabelWidth(_xAxisLabels) + 20;
|
|
818
|
+
reqWidth = (_xAxisLabels.length - _xAxisInnerPadding) * step;
|
|
819
|
+
const margin2 = (totalWidth - reqWidth) / 2;
|
|
820
|
+
_domainMargin = MIN_DOMAIN_MARGIN + Math.max(0, Math.min(margin1, margin2));
|
|
753
821
|
}
|
|
754
822
|
} else {
|
|
755
823
|
var _props_data;
|
|
756
|
-
const
|
|
824
|
+
const uniqueX = {};
|
|
825
|
+
(_props_data = props.data) === null || _props_data === void 0 ? void 0 : _props_data.forEach((point)=>{
|
|
826
|
+
if (point.x instanceof Date) {
|
|
827
|
+
uniqueX[point.x.getTime()] = point.x;
|
|
828
|
+
} else {
|
|
829
|
+
uniqueX[point.x] = point.x;
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
const data = Object.values(uniqueX);
|
|
757
833
|
_barWidth = getBarWidth(props.barWidth, props.maxBarWidth, calculateAppropriateBarWidth(data, totalWidth));
|
|
758
834
|
_domainMargin = MIN_DOMAIN_MARGIN + _barWidth / 2;
|
|
759
835
|
}
|
|
@@ -764,7 +840,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
764
840
|
};
|
|
765
841
|
}
|
|
766
842
|
function _isChartEmpty() {
|
|
767
|
-
return _points.length === 0 ||
|
|
843
|
+
return _points.length === 0 || _points.every((point)=>point.y === 0) && !_isHavingLine;
|
|
768
844
|
}
|
|
769
845
|
function updatePosition(newX, newY) {
|
|
770
846
|
const threshold = 1; // Set a threshold for movement
|
|
@@ -783,11 +859,12 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
783
859
|
_adjustProps();
|
|
784
860
|
_xAxisLabels = _points.map((point)=>point.x);
|
|
785
861
|
_yMax = Math.max(d3Max(_points, (point)=>point.y), props.yMaxValue || 0);
|
|
862
|
+
_yMin = Math.min(d3Min(_points, (point)=>point.y), props.yMinValue || 0);
|
|
786
863
|
const legendBars = _getLegendData(_points);
|
|
787
864
|
var _props_culture;
|
|
788
865
|
const calloutProps = {
|
|
789
866
|
..._isHavingLine && {
|
|
790
|
-
YValueHover:
|
|
867
|
+
YValueHover: hoveredYValues,
|
|
791
868
|
hoverXValue: hoverXValue
|
|
792
869
|
},
|
|
793
870
|
color: color,
|
|
@@ -798,7 +875,7 @@ const MIN_DOMAIN_MARGIN = 8;
|
|
|
798
875
|
...getAccessibleDataObject(callOutAccessibilityData),
|
|
799
876
|
clickPosition: clickPosition,
|
|
800
877
|
isPopoverOpen: isPopoverOpen,
|
|
801
|
-
isCalloutForStack: _isHavingLine && _noLegendHighlighted(),
|
|
878
|
+
isCalloutForStack: _isHavingLine && (_noLegendHighlighted() || _getHighlightedLegend().length > 1),
|
|
802
879
|
culture: (_props_culture = props.culture) !== null && _props_culture !== void 0 ? _props_culture : 'en-us',
|
|
803
880
|
isCartesian: true,
|
|
804
881
|
customCallout: {
|