@fluentui/react-charts 9.1.3 → 9.1.5
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 +33 -2
- package/dist/index.d.ts +13 -0
- package/lib/components/CommonComponents/CartesianChart.js +3 -2
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +7 -8
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js +4 -2
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +3 -2
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +181 -38
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +8 -8
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib/utilities/utilities.js +52 -12
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +2 -2
- 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/PlotlySchemaAdapter.js +7 -8
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js +4 -2
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +4 -2
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +175 -36
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +7 -7
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +51 -12
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { max as d3Max } from 'd3-array';
|
|
2
|
+
import { max as d3Max, min as d3Min } from 'd3-array';
|
|
3
3
|
import { select as d3Select } from 'd3-selection';
|
|
4
4
|
import { scaleLinear as d3ScaleLinear, scaleBand as d3ScaleBand } from 'd3-scale';
|
|
5
5
|
import { Legends } from '../../components/Legends/Legends';
|
|
@@ -7,7 +7,8 @@ import { useId } from '@fluentui/react-utilities';
|
|
|
7
7
|
import { useHorizontalBarChartWithAxisStyles } from './useHorizontalBarChartWithAxisStyles.styles';
|
|
8
8
|
import { CartesianChart } from '../CommonComponents/CartesianChart';
|
|
9
9
|
import { ChartPopover } from '../CommonComponents/ChartPopover';
|
|
10
|
-
import { ChartTypes, getAccessibleDataObject, YAxisType, XAxisTypes, getTypeOfAxis, getNextColor, areArraysEqual, useRtl, DataVizPalette, getColorFromToken } from '../../utilities/index';
|
|
10
|
+
import { ChartTypes, getAccessibleDataObject, YAxisType, XAxisTypes, getTypeOfAxis, getNextColor, areArraysEqual, useRtl, DataVizPalette, getColorFromToken, computeLongestBars, domainRangeOfNumericForHorizontalBarChartWithAxis, groupChartDataByYValue, MIN_DOMAIN_MARGIN } from '../../utilities/index';
|
|
11
|
+
import { getClosestPairDiffAndRange } from '../../utilities/vbc-utils';
|
|
11
12
|
export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
12
13
|
var _props_legendProps, _props_legendProps1, _props_legendProps2, _props_legendProps3;
|
|
13
14
|
const _refArray = [];
|
|
@@ -27,7 +28,13 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
27
28
|
let _calloutAnchorPoint;
|
|
28
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
30
|
let tooltipElement;
|
|
31
|
+
let _longestBarPositiveTotalValue;
|
|
32
|
+
let _longestBarNegativeTotalValue;
|
|
33
|
+
let _domainMargin = MIN_DOMAIN_MARGIN;
|
|
34
|
+
var _props_yAxisPadding;
|
|
35
|
+
let _yAxisPadding = (_props_yAxisPadding = props.yAxisPadding) !== null && _props_yAxisPadding !== void 0 ? _props_yAxisPadding : 0.5;
|
|
30
36
|
const cartesianChartRef = React.useRef(null);
|
|
37
|
+
const X_ORIGIN = 0;
|
|
31
38
|
const [color, setColor] = React.useState('');
|
|
32
39
|
const [dataForHoverCard, setDataForHoverCard] = React.useState(0);
|
|
33
40
|
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);
|
|
@@ -116,7 +123,18 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
116
123
|
return props.onRenderCalloutPerDataPoint ? props.onRenderCalloutPerDataPoint(dataPointCalloutProps, _renderCallout) : null;
|
|
117
124
|
}
|
|
118
125
|
function _getGraphData(xScale, yScale, containerHeight, containerWidth, xElement, yElement) {
|
|
119
|
-
|
|
126
|
+
const stackedChartData = groupChartDataByYValue(_points);
|
|
127
|
+
const longestBars = computeLongestBars(stackedChartData, X_ORIGIN);
|
|
128
|
+
_longestBarPositiveTotalValue = longestBars.longestPositiveBar;
|
|
129
|
+
_longestBarNegativeTotalValue = longestBars.longestNegativeBar;
|
|
130
|
+
const { xBarScale, yBarScale } = _yAxisType === YAxisType.NumericAxis ? _getScales(containerHeight, containerWidth, true) : _getScales(containerHeight, containerWidth, false);
|
|
131
|
+
const xRange = xBarScale.range();
|
|
132
|
+
let allBars = [];
|
|
133
|
+
// when the chart mounts, the xRange[1] is sometimes seen to be < 0 (like -40) while xRange[0] > 0.
|
|
134
|
+
if (xRange[0] < xRange[1]) {
|
|
135
|
+
allBars = stackedChartData.map((singleBarData)=>_yAxisType === YAxisType.NumericAxis ? _createNumericBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale) : _createStringBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale)).flat();
|
|
136
|
+
}
|
|
137
|
+
return _bars = allBars;
|
|
120
138
|
}
|
|
121
139
|
function _createColors() {
|
|
122
140
|
const increment = _colors.length <= 1 ? 1 : 1 / (_colors.length - 1);
|
|
@@ -184,46 +202,43 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
184
202
|
}
|
|
185
203
|
}
|
|
186
204
|
function _getScales(containerHeight, containerWidth, isNumericScale) {
|
|
205
|
+
const xMax = _longestBarPositiveTotalValue;
|
|
206
|
+
const xMin = _longestBarNegativeTotalValue;
|
|
207
|
+
const xDomain = [
|
|
208
|
+
Math.min(X_ORIGIN, xMin),
|
|
209
|
+
Math.max(X_ORIGIN, xMax)
|
|
210
|
+
];
|
|
187
211
|
if (isNumericScale) {
|
|
188
|
-
const xMax = d3Max(_points, (point)=>point.x);
|
|
189
212
|
const yMax = d3Max(_points, (point)=>point.y);
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
]).nice().range([
|
|
213
|
+
const yMin = d3Min(_points, (point)=>point.y);
|
|
214
|
+
const yDomainMax = Math.max(yMax, props.yMaxValue || 0);
|
|
215
|
+
// Default to 0 if yMinValue is not provided.
|
|
216
|
+
const yMinProp = props.yMinValue || 0;
|
|
217
|
+
const yDomainMin = Math.min(yMin, yMinProp);
|
|
218
|
+
const xBarScale = d3ScaleLinear().domain(xDomain).nice().range([
|
|
197
219
|
_margins.left,
|
|
198
220
|
containerWidth - _margins.right
|
|
199
221
|
]);
|
|
200
222
|
const yBarScale = d3ScaleLinear().domain([
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
yDomainMin,
|
|
224
|
+
yDomainMax
|
|
203
225
|
]).range([
|
|
204
|
-
containerHeight - _margins.bottom,
|
|
205
|
-
_margins.top
|
|
226
|
+
containerHeight - (_margins.bottom + _domainMargin),
|
|
227
|
+
_margins.top + _domainMargin
|
|
206
228
|
]);
|
|
207
229
|
return {
|
|
208
230
|
xBarScale,
|
|
209
231
|
yBarScale
|
|
210
232
|
};
|
|
211
233
|
} else {
|
|
212
|
-
const xMax = d3Max(_points, (point)=>point.x);
|
|
213
234
|
// please note these padding default values must be consistent in here
|
|
214
235
|
// and CatrtesianChartBase w for more details refer example
|
|
215
236
|
// http://using-d3js.com/04_07_ordinal_scales.html
|
|
216
237
|
const yBarScale = d3ScaleBand().domain(_yAxisLabels).range([
|
|
217
|
-
containerHeight - _margins.bottom
|
|
218
|
-
_margins.top +
|
|
219
|
-
]).padding(
|
|
220
|
-
const xBarScale = d3ScaleLinear().domain(
|
|
221
|
-
xMax,
|
|
222
|
-
0
|
|
223
|
-
] : [
|
|
224
|
-
0,
|
|
225
|
-
xMax
|
|
226
|
-
]).nice().range([
|
|
238
|
+
containerHeight - (_margins.bottom + _domainMargin),
|
|
239
|
+
_margins.top + _domainMargin
|
|
240
|
+
]).padding(_yAxisPadding);
|
|
241
|
+
const xBarScale = d3ScaleLinear().domain(xDomain).nice().range([
|
|
227
242
|
_margins.left,
|
|
228
243
|
containerWidth - _margins.right
|
|
229
244
|
]);
|
|
@@ -233,22 +248,37 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
233
248
|
};
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
|
-
function _createNumericBars(containerHeight, containerWidth, xElement, yElement
|
|
251
|
+
function _createNumericBars(containerHeight, containerWidth, xElement, yElement, singleBarData, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
252
|
+
xBarScale, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
yBarScale) {
|
|
237
254
|
const { useSingleColor = false } = props;
|
|
238
|
-
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, true);
|
|
239
255
|
const sortedBars = [
|
|
240
|
-
...
|
|
256
|
+
...singleBarData
|
|
241
257
|
];
|
|
242
258
|
sortedBars.sort((a, b)=>{
|
|
243
259
|
const aValue = typeof a.y === 'number' ? a.y : parseFloat(a.y);
|
|
244
260
|
const bValue = typeof b.y === 'number' ? b.y : parseFloat(b.y);
|
|
245
261
|
return bValue - aValue;
|
|
246
262
|
});
|
|
263
|
+
let prevWidthPositive = 0;
|
|
264
|
+
let prevWidthNegative = 0;
|
|
265
|
+
let prevPoint = 0;
|
|
266
|
+
const totalPositiveBars = singleBarData.filter((point)=>point.x >= X_ORIGIN).length;
|
|
267
|
+
const totalNegativeBars = singleBarData.length - totalPositiveBars;
|
|
268
|
+
let currPositiveCounter = 0;
|
|
269
|
+
let currNegativeCounter = 0;
|
|
247
270
|
const bars = sortedBars.map((point, index)=>{
|
|
248
271
|
let shouldHighlight = true;
|
|
249
272
|
if (isLegendHovered || isLegendSelected) {
|
|
250
273
|
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
251
274
|
}
|
|
275
|
+
if (point.x >= X_ORIGIN) {
|
|
276
|
+
++currPositiveCounter;
|
|
277
|
+
}
|
|
278
|
+
if (point.x < X_ORIGIN) {
|
|
279
|
+
++currNegativeCounter;
|
|
280
|
+
}
|
|
281
|
+
const barStartX = _isRtl ? containerWidth - (_margins.right + Math.max(xBarScale(point.x + X_ORIGIN), xBarScale(X_ORIGIN)) - _margins.left) : Math.min(xBarScale(point.x + X_ORIGIN), xBarScale(X_ORIGIN));
|
|
252
282
|
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
253
283
|
if (barHeight < 1) {
|
|
254
284
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
@@ -264,14 +294,26 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
264
294
|
startColor = props.colors ? _createColors()(point.x) : getNextColor(index, 0);
|
|
265
295
|
}
|
|
266
296
|
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
297
|
+
const prevBarWidth = Math.abs(xBarScale(prevPoint + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
298
|
+
prevPoint > X_ORIGIN ? prevWidthPositive += prevBarWidth : prevWidthNegative += prevBarWidth;
|
|
299
|
+
const currentWidth = Math.abs(xBarScale(point.x + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
300
|
+
const gapWidthLTR = currentWidth > 2 && (point.x > X_ORIGIN && currPositiveCounter !== totalPositiveBars || point.x < X_ORIGIN && (totalPositiveBars !== 0 || currNegativeCounter > 1)) ? 2 : 0;
|
|
301
|
+
const gapWidthRTL = currentWidth > 2 && (point.x > X_ORIGIN && (totalNegativeBars !== 0 || currPositiveCounter > 1) || point.x < X_ORIGIN && currNegativeCounter !== totalNegativeBars) ? 2 : 0;
|
|
302
|
+
let xStart = X_ORIGIN;
|
|
303
|
+
if (_isRtl) {
|
|
304
|
+
xStart = point.x > X_ORIGIN ? barStartX - prevWidthPositive : barStartX + prevWidthNegative;
|
|
305
|
+
} else {
|
|
306
|
+
xStart = point.x > X_ORIGIN ? barStartX + prevWidthPositive : barStartX - prevWidthNegative;
|
|
307
|
+
}
|
|
308
|
+
prevPoint = point.x;
|
|
267
309
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
268
310
|
key: `${index}_${point.x}`
|
|
269
311
|
}, /*#__PURE__*/ React.createElement("rect", {
|
|
270
312
|
key: point.y,
|
|
271
|
-
x:
|
|
313
|
+
x: xStart,
|
|
272
314
|
y: yBarScale(point.y) - _barHeight / 2,
|
|
273
315
|
"data-is-focusable": shouldHighlight,
|
|
274
|
-
width:
|
|
316
|
+
width: currentWidth - (_isRtl ? gapWidthRTL : gapWidthLTR),
|
|
275
317
|
height: _barHeight,
|
|
276
318
|
ref: (e)=>{
|
|
277
319
|
_refCallback(e, point.legend);
|
|
@@ -292,6 +334,59 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
292
334
|
});
|
|
293
335
|
return bars;
|
|
294
336
|
}
|
|
337
|
+
function _getUniqueYValues() {
|
|
338
|
+
var _props_data;
|
|
339
|
+
const mapY = {};
|
|
340
|
+
(_props_data = props.data) === null || _props_data === void 0 ? void 0 : _props_data.forEach((point)=>{
|
|
341
|
+
mapY[point.y] = point.y;
|
|
342
|
+
});
|
|
343
|
+
const uniqueY = Object.values(mapY);
|
|
344
|
+
return uniqueY;
|
|
345
|
+
}
|
|
346
|
+
function _calculateAppropriateBarHeight(data, totalWidth, innerPadding) {
|
|
347
|
+
const result = getClosestPairDiffAndRange(data);
|
|
348
|
+
if (!result || result[1] === 0) {
|
|
349
|
+
return 16;
|
|
350
|
+
}
|
|
351
|
+
const closestPairDiff = result[0];
|
|
352
|
+
let range = result[1];
|
|
353
|
+
const yMax = d3Max(_points, (point)=>point.y);
|
|
354
|
+
// Since we are always rendering from 0 to yMax, we need to ensure that the range is at least yMax
|
|
355
|
+
// to calculate the bar height correctly.
|
|
356
|
+
range = Math.max(range, yMax);
|
|
357
|
+
// Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes
|
|
358
|
+
// for the derivation of the following formula.
|
|
359
|
+
const barWidth = Math.floor(totalWidth * closestPairDiff * (1 - innerPadding) / (range + closestPairDiff * (1 - innerPadding)));
|
|
360
|
+
return barWidth;
|
|
361
|
+
}
|
|
362
|
+
function _getDomainMarginsForHorizontalBarChart(containerHeight) {
|
|
363
|
+
_domainMargin = MIN_DOMAIN_MARGIN;
|
|
364
|
+
const uniqueY = _getUniqueYValues();
|
|
365
|
+
/** Rate at which the space between the bars changes wrt the bar height */ _yAxisPadding = _yAxisPadding === 1 ? 0.99 : _yAxisPadding;
|
|
366
|
+
const barGapRate = _yAxisPadding / (1 - _yAxisPadding);
|
|
367
|
+
const numBars = uniqueY.length + (uniqueY.length - 1) * barGapRate;
|
|
368
|
+
// Total height available to render the bars
|
|
369
|
+
const totalHeight = containerHeight - (_margins.top + MIN_DOMAIN_MARGIN) - (_margins.bottom + MIN_DOMAIN_MARGIN);
|
|
370
|
+
if (_yAxisType !== YAxisType.StringAxis) {
|
|
371
|
+
// Calculate bar height dynamically
|
|
372
|
+
_barHeight = props.barHeight || _calculateAppropriateBarHeight(uniqueY, totalHeight, _yAxisPadding);
|
|
373
|
+
_barHeight = Math.max(_barHeight, 1);
|
|
374
|
+
_domainMargin += _barHeight / 2;
|
|
375
|
+
} else {
|
|
376
|
+
// Calculate the appropriate bar height
|
|
377
|
+
_barHeight = props.barHeight || totalHeight / numBars;
|
|
378
|
+
/** Total height required to render the bars. Directly proportional to bar height */ const reqHeight = numBars * _barHeight;
|
|
379
|
+
if (totalHeight >= reqHeight) {
|
|
380
|
+
// Center align the chart by setting equal left and right margins for domain
|
|
381
|
+
_domainMargin = MIN_DOMAIN_MARGIN + (totalHeight - reqHeight) / 2;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
..._margins,
|
|
386
|
+
top: _margins.top + _domainMargin,
|
|
387
|
+
bottom: _margins.bottom + _domainMargin
|
|
388
|
+
};
|
|
389
|
+
}
|
|
295
390
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
296
391
|
function _tooltipOfYAxislabels(ytooltipProps) {
|
|
297
392
|
const { tooltipCls, yAxis, id } = ytooltipProps;
|
|
@@ -321,14 +416,29 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
321
416
|
});
|
|
322
417
|
}
|
|
323
418
|
}
|
|
324
|
-
function _createStringBars(containerHeight, containerWidth, xElement, yElement
|
|
325
|
-
|
|
419
|
+
function _createStringBars(containerHeight, containerWidth, xElement, yElement, singleBarData, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
420
|
+
xBarScale, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
421
|
+
yBarScale) {
|
|
326
422
|
const { useSingleColor = false } = props;
|
|
327
|
-
|
|
423
|
+
let prevWidthPositive = 0;
|
|
424
|
+
let prevWidthNegative = 0;
|
|
425
|
+
let prevPoint = 0;
|
|
426
|
+
const totalPositiveBars = singleBarData.filter((point)=>point.x >= X_ORIGIN).length;
|
|
427
|
+
const totalNegativeBars = singleBarData.length - totalPositiveBars;
|
|
428
|
+
let currPositiveCounter = 0;
|
|
429
|
+
let currNegativeCounter = 0;
|
|
430
|
+
const bars = singleBarData.map((point, index)=>{
|
|
328
431
|
let shouldHighlight = true;
|
|
329
432
|
if (isLegendHovered || isLegendSelected) {
|
|
330
433
|
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
331
434
|
}
|
|
435
|
+
if (point.x >= X_ORIGIN) {
|
|
436
|
+
++currPositiveCounter;
|
|
437
|
+
}
|
|
438
|
+
if (point.x < X_ORIGIN) {
|
|
439
|
+
++currNegativeCounter;
|
|
440
|
+
}
|
|
441
|
+
const barStartX = _isRtl ? containerWidth - (_margins.right + Math.max(xBarScale(point.x + X_ORIGIN), xBarScale(X_ORIGIN)) - _margins.left) : Math.min(xBarScale(point.x + X_ORIGIN), xBarScale(X_ORIGIN));
|
|
332
442
|
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
333
443
|
if (barHeight < 1) {
|
|
334
444
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
@@ -344,15 +454,27 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
344
454
|
startColor = props.colors ? _createColors()(point.x) : getNextColor(index, 0);
|
|
345
455
|
}
|
|
346
456
|
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
457
|
+
const prevBarWidth = Math.abs(xBarScale(prevPoint + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
458
|
+
prevPoint > 0 ? prevWidthPositive += prevBarWidth : prevWidthNegative += prevBarWidth;
|
|
459
|
+
const currentWidth = Math.abs(xBarScale(point.x + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
460
|
+
const gapWidthLTR = currentWidth > 2 && (point.x > X_ORIGIN && currPositiveCounter !== totalPositiveBars || point.x < X_ORIGIN && (totalPositiveBars !== 0 || currNegativeCounter > 1)) ? 2 : 0;
|
|
461
|
+
const gapWidthRTL = currentWidth > 2 && (point.x > X_ORIGIN && (totalNegativeBars !== 0 || currPositiveCounter > 1) || point.x < X_ORIGIN && currNegativeCounter !== totalNegativeBars) ? 2 : 0;
|
|
462
|
+
prevPoint = point.x;
|
|
463
|
+
let xStart = X_ORIGIN;
|
|
464
|
+
if (_isRtl) {
|
|
465
|
+
xStart = point.x > X_ORIGIN ? barStartX - prevWidthPositive : barStartX + prevWidthNegative;
|
|
466
|
+
} else {
|
|
467
|
+
xStart = point.x > X_ORIGIN ? barStartX + prevWidthPositive : barStartX - prevWidthNegative;
|
|
468
|
+
}
|
|
347
469
|
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
348
470
|
key: `${index}_${point.x}`
|
|
349
471
|
}, /*#__PURE__*/ React.createElement("rect", {
|
|
350
472
|
transform: `translate(0,${0.5 * (yBarScale.bandwidth() - _barHeight)})`,
|
|
351
473
|
key: point.x,
|
|
352
|
-
x:
|
|
474
|
+
x: xStart,
|
|
353
475
|
y: yBarScale(point.y),
|
|
354
476
|
rx: props.roundCorners ? 3 : 0,
|
|
355
|
-
width:
|
|
477
|
+
width: currentWidth - (_isRtl ? gapWidthRTL : gapWidthLTR),
|
|
356
478
|
height: _barHeight,
|
|
357
479
|
"aria-labelledby": `toolTip${_calloutId}`,
|
|
358
480
|
"aria-label": _getAriaLabel(point),
|
|
@@ -416,16 +538,20 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
416
538
|
function _getLegendData(data) {
|
|
417
539
|
const { useSingleColor } = props;
|
|
418
540
|
const actions = [];
|
|
541
|
+
const mapLegendToColor = {};
|
|
419
542
|
data.forEach((point, _index)=>{
|
|
420
543
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
421
544
|
const color = useSingleColor ? props.colors ? _createColors()(1) : getNextColor(1, 0) : point.color;
|
|
545
|
+
mapLegendToColor[point.legend] = color;
|
|
546
|
+
});
|
|
547
|
+
Object.entries(mapLegendToColor).forEach(([legendTitle, color])=>{
|
|
422
548
|
// mapping data to the format Legends component needs
|
|
423
549
|
const legend = {
|
|
424
|
-
title:
|
|
550
|
+
title: legendTitle,
|
|
425
551
|
color,
|
|
426
552
|
hoverAction: ()=>{
|
|
427
553
|
_handleChartMouseLeave();
|
|
428
|
-
_onLegendHover(
|
|
554
|
+
_onLegendHover(legendTitle);
|
|
429
555
|
},
|
|
430
556
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
431
557
|
onMouseOutAction: (isLegendSelected)=>{
|
|
@@ -508,6 +634,20 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
508
634
|
setPopoverOpen(true);
|
|
509
635
|
}
|
|
510
636
|
}
|
|
637
|
+
function _getDomainNRangeValues(points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
|
|
638
|
+
let domainNRangeValue;
|
|
639
|
+
if (xAxisType === XAxisTypes.NumericAxis) {
|
|
640
|
+
domainNRangeValue = domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, width, isRTL, shiftX, X_ORIGIN);
|
|
641
|
+
} else {
|
|
642
|
+
domainNRangeValue = {
|
|
643
|
+
dStartValue: 0,
|
|
644
|
+
dEndValue: 0,
|
|
645
|
+
rStartValue: 0,
|
|
646
|
+
rEndValue: 0
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
return domainNRangeValue;
|
|
650
|
+
}
|
|
511
651
|
if (!_isChartEmpty()) {
|
|
512
652
|
_adjustProps();
|
|
513
653
|
const calloutProps = {
|
|
@@ -536,18 +676,21 @@ export const HorizontalBarChartWithAxis = /*#__PURE__*/ React.forwardRef((props,
|
|
|
536
676
|
_xMax = Math.max(d3Max(_points, (point)=>point.x), props.xMaxValue || 0);
|
|
537
677
|
const legendBars = _getLegendData(_points);
|
|
538
678
|
return /*#__PURE__*/ React.createElement(CartesianChart, {
|
|
679
|
+
yAxisPadding: _yAxisPadding,
|
|
539
680
|
...props,
|
|
540
681
|
chartTitle: _getChartTitle(),
|
|
541
682
|
points: _points,
|
|
542
683
|
chartType: ChartTypes.HorizontalBarChartWithAxis,
|
|
543
684
|
xAxisType: _xAxisType,
|
|
544
685
|
yAxisType: _yAxisType,
|
|
686
|
+
getDomainNRangeValues: _getDomainNRangeValues,
|
|
545
687
|
stringDatasetForYAxisDomain: _yAxisLabels,
|
|
546
688
|
calloutProps: calloutProps,
|
|
547
689
|
tickParams: tickParams,
|
|
548
690
|
legendBars: legendBars,
|
|
549
691
|
barwidth: _barHeight,
|
|
550
692
|
getmargins: _getMargins,
|
|
693
|
+
getYDomainMargins: _getDomainMarginsForHorizontalBarChart,
|
|
551
694
|
getGraphData: _getGraphData,
|
|
552
695
|
getAxisData: _getAxisData,
|
|
553
696
|
onChartMouseLeave: _handleChartMouseLeave,
|