@fluentui/react-charts 9.1.3 → 9.1.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 +20 -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
|
@@ -19,6 +19,7 @@ const _useHorizontalBarChartWithAxisStylesstyles = require("./useHorizontalBarCh
|
|
|
19
19
|
const _CartesianChart = require("../CommonComponents/CartesianChart");
|
|
20
20
|
const _ChartPopover = require("../CommonComponents/ChartPopover");
|
|
21
21
|
const _index = require("../../utilities/index");
|
|
22
|
+
const _vbcutils = require("../../utilities/vbc-utils");
|
|
22
23
|
const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwardedRef)=>{
|
|
23
24
|
var _props_legendProps, _props_legendProps1, _props_legendProps2, _props_legendProps3;
|
|
24
25
|
const _refArray = [];
|
|
@@ -38,7 +39,13 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
38
39
|
let _calloutAnchorPoint;
|
|
39
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
41
|
let tooltipElement;
|
|
42
|
+
let _longestBarPositiveTotalValue;
|
|
43
|
+
let _longestBarNegativeTotalValue;
|
|
44
|
+
let _domainMargin = _index.MIN_DOMAIN_MARGIN;
|
|
45
|
+
var _props_yAxisPadding;
|
|
46
|
+
let _yAxisPadding = (_props_yAxisPadding = props.yAxisPadding) !== null && _props_yAxisPadding !== void 0 ? _props_yAxisPadding : 0.5;
|
|
41
47
|
const cartesianChartRef = _react.useRef(null);
|
|
48
|
+
const X_ORIGIN = 0;
|
|
42
49
|
const [color, setColor] = _react.useState('');
|
|
43
50
|
const [dataForHoverCard, setDataForHoverCard] = _react.useState(0);
|
|
44
51
|
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);
|
|
@@ -127,7 +134,18 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
127
134
|
return props.onRenderCalloutPerDataPoint ? props.onRenderCalloutPerDataPoint(dataPointCalloutProps, _renderCallout) : null;
|
|
128
135
|
}
|
|
129
136
|
function _getGraphData(xScale, yScale, containerHeight, containerWidth, xElement, yElement) {
|
|
130
|
-
|
|
137
|
+
const stackedChartData = (0, _index.groupChartDataByYValue)(_points);
|
|
138
|
+
const longestBars = (0, _index.computeLongestBars)(stackedChartData, X_ORIGIN);
|
|
139
|
+
_longestBarPositiveTotalValue = longestBars.longestPositiveBar;
|
|
140
|
+
_longestBarNegativeTotalValue = longestBars.longestNegativeBar;
|
|
141
|
+
const { xBarScale, yBarScale } = _yAxisType === _index.YAxisType.NumericAxis ? _getScales(containerHeight, containerWidth, true) : _getScales(containerHeight, containerWidth, false);
|
|
142
|
+
const xRange = xBarScale.range();
|
|
143
|
+
let allBars = [];
|
|
144
|
+
// when the chart mounts, the xRange[1] is sometimes seen to be < 0 (like -40) while xRange[0] > 0.
|
|
145
|
+
if (xRange[0] < xRange[1]) {
|
|
146
|
+
allBars = stackedChartData.map((singleBarData)=>_yAxisType === _index.YAxisType.NumericAxis ? _createNumericBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale) : _createStringBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale)).flat();
|
|
147
|
+
}
|
|
148
|
+
return _bars = allBars;
|
|
131
149
|
}
|
|
132
150
|
function _createColors() {
|
|
133
151
|
const increment = _colors.length <= 1 ? 1 : 1 / (_colors.length - 1);
|
|
@@ -194,46 +212,43 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
194
212
|
}
|
|
195
213
|
}
|
|
196
214
|
function _getScales(containerHeight, containerWidth, isNumericScale) {
|
|
215
|
+
const xMax = _longestBarPositiveTotalValue;
|
|
216
|
+
const xMin = _longestBarNegativeTotalValue;
|
|
217
|
+
const xDomain = [
|
|
218
|
+
Math.min(X_ORIGIN, xMin),
|
|
219
|
+
Math.max(X_ORIGIN, xMax)
|
|
220
|
+
];
|
|
197
221
|
if (isNumericScale) {
|
|
198
|
-
const xMax = (0, _d3array.max)(_points, (point)=>point.x);
|
|
199
222
|
const yMax = (0, _d3array.max)(_points, (point)=>point.y);
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
]).nice().range([
|
|
223
|
+
const yMin = (0, _d3array.min)(_points, (point)=>point.y);
|
|
224
|
+
const yDomainMax = Math.max(yMax, props.yMaxValue || 0);
|
|
225
|
+
// Default to 0 if yMinValue is not provided.
|
|
226
|
+
const yMinProp = props.yMinValue || 0;
|
|
227
|
+
const yDomainMin = Math.min(yMin, yMinProp);
|
|
228
|
+
const xBarScale = (0, _d3scale.scaleLinear)().domain(xDomain).nice().range([
|
|
207
229
|
_margins.left,
|
|
208
230
|
containerWidth - _margins.right
|
|
209
231
|
]);
|
|
210
232
|
const yBarScale = (0, _d3scale.scaleLinear)().domain([
|
|
211
|
-
|
|
212
|
-
|
|
233
|
+
yDomainMin,
|
|
234
|
+
yDomainMax
|
|
213
235
|
]).range([
|
|
214
|
-
containerHeight - _margins.bottom,
|
|
215
|
-
_margins.top
|
|
236
|
+
containerHeight - (_margins.bottom + _domainMargin),
|
|
237
|
+
_margins.top + _domainMargin
|
|
216
238
|
]);
|
|
217
239
|
return {
|
|
218
240
|
xBarScale,
|
|
219
241
|
yBarScale
|
|
220
242
|
};
|
|
221
243
|
} else {
|
|
222
|
-
const xMax = (0, _d3array.max)(_points, (point)=>point.x);
|
|
223
244
|
// please note these padding default values must be consistent in here
|
|
224
245
|
// and CatrtesianChartBase w for more details refer example
|
|
225
246
|
// http://using-d3js.com/04_07_ordinal_scales.html
|
|
226
247
|
const yBarScale = (0, _d3scale.scaleBand)().domain(_yAxisLabels).range([
|
|
227
|
-
containerHeight - _margins.bottom
|
|
228
|
-
_margins.top +
|
|
229
|
-
]).padding(
|
|
230
|
-
const xBarScale = (0, _d3scale.scaleLinear)().domain(
|
|
231
|
-
xMax,
|
|
232
|
-
0
|
|
233
|
-
] : [
|
|
234
|
-
0,
|
|
235
|
-
xMax
|
|
236
|
-
]).nice().range([
|
|
248
|
+
containerHeight - (_margins.bottom + _domainMargin),
|
|
249
|
+
_margins.top + _domainMargin
|
|
250
|
+
]).padding(_yAxisPadding);
|
|
251
|
+
const xBarScale = (0, _d3scale.scaleLinear)().domain(xDomain).nice().range([
|
|
237
252
|
_margins.left,
|
|
238
253
|
containerWidth - _margins.right
|
|
239
254
|
]);
|
|
@@ -243,22 +258,35 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
243
258
|
};
|
|
244
259
|
}
|
|
245
260
|
}
|
|
246
|
-
function _createNumericBars(containerHeight, containerWidth, xElement, yElement) {
|
|
261
|
+
function _createNumericBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale) {
|
|
247
262
|
const { useSingleColor = false } = props;
|
|
248
|
-
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, true);
|
|
249
263
|
const sortedBars = [
|
|
250
|
-
...
|
|
264
|
+
...singleBarData
|
|
251
265
|
];
|
|
252
266
|
sortedBars.sort((a, b)=>{
|
|
253
267
|
const aValue = typeof a.y === 'number' ? a.y : parseFloat(a.y);
|
|
254
268
|
const bValue = typeof b.y === 'number' ? b.y : parseFloat(b.y);
|
|
255
269
|
return bValue - aValue;
|
|
256
270
|
});
|
|
271
|
+
let prevWidthPositive = 0;
|
|
272
|
+
let prevWidthNegative = 0;
|
|
273
|
+
let prevPoint = 0;
|
|
274
|
+
const totalPositiveBars = singleBarData.filter((point)=>point.x >= X_ORIGIN).length;
|
|
275
|
+
const totalNegativeBars = singleBarData.length - totalPositiveBars;
|
|
276
|
+
let currPositiveCounter = 0;
|
|
277
|
+
let currNegativeCounter = 0;
|
|
257
278
|
const bars = sortedBars.map((point, index)=>{
|
|
258
279
|
let shouldHighlight = true;
|
|
259
280
|
if (isLegendHovered || isLegendSelected) {
|
|
260
281
|
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
261
282
|
}
|
|
283
|
+
if (point.x >= X_ORIGIN) {
|
|
284
|
+
++currPositiveCounter;
|
|
285
|
+
}
|
|
286
|
+
if (point.x < X_ORIGIN) {
|
|
287
|
+
++currNegativeCounter;
|
|
288
|
+
}
|
|
289
|
+
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));
|
|
262
290
|
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
263
291
|
if (barHeight < 1) {
|
|
264
292
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, {
|
|
@@ -274,14 +302,26 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
274
302
|
startColor = props.colors ? _createColors()(point.x) : (0, _index.getNextColor)(index, 0);
|
|
275
303
|
}
|
|
276
304
|
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
305
|
+
const prevBarWidth = Math.abs(xBarScale(prevPoint + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
306
|
+
prevPoint > X_ORIGIN ? prevWidthPositive += prevBarWidth : prevWidthNegative += prevBarWidth;
|
|
307
|
+
const currentWidth = Math.abs(xBarScale(point.x + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
308
|
+
const gapWidthLTR = currentWidth > 2 && (point.x > X_ORIGIN && currPositiveCounter !== totalPositiveBars || point.x < X_ORIGIN && (totalPositiveBars !== 0 || currNegativeCounter > 1)) ? 2 : 0;
|
|
309
|
+
const gapWidthRTL = currentWidth > 2 && (point.x > X_ORIGIN && (totalNegativeBars !== 0 || currPositiveCounter > 1) || point.x < X_ORIGIN && currNegativeCounter !== totalNegativeBars) ? 2 : 0;
|
|
310
|
+
let xStart = X_ORIGIN;
|
|
311
|
+
if (_isRtl) {
|
|
312
|
+
xStart = point.x > X_ORIGIN ? barStartX - prevWidthPositive : barStartX + prevWidthNegative;
|
|
313
|
+
} else {
|
|
314
|
+
xStart = point.x > X_ORIGIN ? barStartX + prevWidthPositive : barStartX - prevWidthNegative;
|
|
315
|
+
}
|
|
316
|
+
prevPoint = point.x;
|
|
277
317
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, {
|
|
278
318
|
key: `${index}_${point.x}`
|
|
279
319
|
}, /*#__PURE__*/ _react.createElement("rect", {
|
|
280
320
|
key: point.y,
|
|
281
|
-
x:
|
|
321
|
+
x: xStart,
|
|
282
322
|
y: yBarScale(point.y) - _barHeight / 2,
|
|
283
323
|
"data-is-focusable": shouldHighlight,
|
|
284
|
-
width:
|
|
324
|
+
width: currentWidth - (_isRtl ? gapWidthRTL : gapWidthLTR),
|
|
285
325
|
height: _barHeight,
|
|
286
326
|
ref: (e)=>{
|
|
287
327
|
_refCallback(e, point.legend);
|
|
@@ -302,6 +342,59 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
302
342
|
});
|
|
303
343
|
return bars;
|
|
304
344
|
}
|
|
345
|
+
function _getUniqueYValues() {
|
|
346
|
+
var _props_data;
|
|
347
|
+
const mapY = {};
|
|
348
|
+
(_props_data = props.data) === null || _props_data === void 0 ? void 0 : _props_data.forEach((point)=>{
|
|
349
|
+
mapY[point.y] = point.y;
|
|
350
|
+
});
|
|
351
|
+
const uniqueY = Object.values(mapY);
|
|
352
|
+
return uniqueY;
|
|
353
|
+
}
|
|
354
|
+
function _calculateAppropriateBarHeight(data, totalWidth, innerPadding) {
|
|
355
|
+
const result = (0, _vbcutils.getClosestPairDiffAndRange)(data);
|
|
356
|
+
if (!result || result[1] === 0) {
|
|
357
|
+
return 16;
|
|
358
|
+
}
|
|
359
|
+
const closestPairDiff = result[0];
|
|
360
|
+
let range = result[1];
|
|
361
|
+
const yMax = (0, _d3array.max)(_points, (point)=>point.y);
|
|
362
|
+
// Since we are always rendering from 0 to yMax, we need to ensure that the range is at least yMax
|
|
363
|
+
// to calculate the bar height correctly.
|
|
364
|
+
range = Math.max(range, yMax);
|
|
365
|
+
// Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes
|
|
366
|
+
// for the derivation of the following formula.
|
|
367
|
+
const barWidth = Math.floor(totalWidth * closestPairDiff * (1 - innerPadding) / (range + closestPairDiff * (1 - innerPadding)));
|
|
368
|
+
return barWidth;
|
|
369
|
+
}
|
|
370
|
+
function _getDomainMarginsForHorizontalBarChart(containerHeight) {
|
|
371
|
+
_domainMargin = _index.MIN_DOMAIN_MARGIN;
|
|
372
|
+
const uniqueY = _getUniqueYValues();
|
|
373
|
+
/** Rate at which the space between the bars changes wrt the bar height */ _yAxisPadding = _yAxisPadding === 1 ? 0.99 : _yAxisPadding;
|
|
374
|
+
const barGapRate = _yAxisPadding / (1 - _yAxisPadding);
|
|
375
|
+
const numBars = uniqueY.length + (uniqueY.length - 1) * barGapRate;
|
|
376
|
+
// Total height available to render the bars
|
|
377
|
+
const totalHeight = containerHeight - (_margins.top + _index.MIN_DOMAIN_MARGIN) - (_margins.bottom + _index.MIN_DOMAIN_MARGIN);
|
|
378
|
+
if (_yAxisType !== _index.YAxisType.StringAxis) {
|
|
379
|
+
// Calculate bar height dynamically
|
|
380
|
+
_barHeight = props.barHeight || _calculateAppropriateBarHeight(uniqueY, totalHeight, _yAxisPadding);
|
|
381
|
+
_barHeight = Math.max(_barHeight, 1);
|
|
382
|
+
_domainMargin += _barHeight / 2;
|
|
383
|
+
} else {
|
|
384
|
+
// Calculate the appropriate bar height
|
|
385
|
+
_barHeight = props.barHeight || totalHeight / numBars;
|
|
386
|
+
/** Total height required to render the bars. Directly proportional to bar height */ const reqHeight = numBars * _barHeight;
|
|
387
|
+
if (totalHeight >= reqHeight) {
|
|
388
|
+
// Center align the chart by setting equal left and right margins for domain
|
|
389
|
+
_domainMargin = _index.MIN_DOMAIN_MARGIN + (totalHeight - reqHeight) / 2;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
..._margins,
|
|
394
|
+
top: _margins.top + _domainMargin,
|
|
395
|
+
bottom: _margins.bottom + _domainMargin
|
|
396
|
+
};
|
|
397
|
+
}
|
|
305
398
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
306
399
|
function _tooltipOfYAxislabels(ytooltipProps) {
|
|
307
400
|
const { tooltipCls, yAxis, id } = ytooltipProps;
|
|
@@ -331,14 +424,27 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
331
424
|
});
|
|
332
425
|
}
|
|
333
426
|
}
|
|
334
|
-
function _createStringBars(containerHeight, containerWidth, xElement, yElement) {
|
|
335
|
-
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, false);
|
|
427
|
+
function _createStringBars(containerHeight, containerWidth, xElement, yElement, singleBarData, xBarScale, yBarScale) {
|
|
336
428
|
const { useSingleColor = false } = props;
|
|
337
|
-
|
|
429
|
+
let prevWidthPositive = 0;
|
|
430
|
+
let prevWidthNegative = 0;
|
|
431
|
+
let prevPoint = 0;
|
|
432
|
+
const totalPositiveBars = singleBarData.filter((point)=>point.x >= X_ORIGIN).length;
|
|
433
|
+
const totalNegativeBars = singleBarData.length - totalPositiveBars;
|
|
434
|
+
let currPositiveCounter = 0;
|
|
435
|
+
let currNegativeCounter = 0;
|
|
436
|
+
const bars = singleBarData.map((point, index)=>{
|
|
338
437
|
let shouldHighlight = true;
|
|
339
438
|
if (isLegendHovered || isLegendSelected) {
|
|
340
439
|
shouldHighlight = _isLegendHighlighted(point.legend);
|
|
341
440
|
}
|
|
441
|
+
if (point.x >= X_ORIGIN) {
|
|
442
|
+
++currPositiveCounter;
|
|
443
|
+
}
|
|
444
|
+
if (point.x < X_ORIGIN) {
|
|
445
|
+
++currNegativeCounter;
|
|
446
|
+
}
|
|
447
|
+
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));
|
|
342
448
|
const barHeight = Math.max(yBarScale(point.y), 0);
|
|
343
449
|
if (barHeight < 1) {
|
|
344
450
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, {
|
|
@@ -354,15 +460,27 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
354
460
|
startColor = props.colors ? _createColors()(point.x) : (0, _index.getNextColor)(index, 0);
|
|
355
461
|
}
|
|
356
462
|
startColor = point.color && !useSingleColor ? point.color : startColor;
|
|
463
|
+
const prevBarWidth = Math.abs(xBarScale(prevPoint + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
464
|
+
prevPoint > 0 ? prevWidthPositive += prevBarWidth : prevWidthNegative += prevBarWidth;
|
|
465
|
+
const currentWidth = Math.abs(xBarScale(point.x + X_ORIGIN) - xBarScale(X_ORIGIN));
|
|
466
|
+
const gapWidthLTR = currentWidth > 2 && (point.x > X_ORIGIN && currPositiveCounter !== totalPositiveBars || point.x < X_ORIGIN && (totalPositiveBars !== 0 || currNegativeCounter > 1)) ? 2 : 0;
|
|
467
|
+
const gapWidthRTL = currentWidth > 2 && (point.x > X_ORIGIN && (totalNegativeBars !== 0 || currPositiveCounter > 1) || point.x < X_ORIGIN && currNegativeCounter !== totalNegativeBars) ? 2 : 0;
|
|
468
|
+
prevPoint = point.x;
|
|
469
|
+
let xStart = X_ORIGIN;
|
|
470
|
+
if (_isRtl) {
|
|
471
|
+
xStart = point.x > X_ORIGIN ? barStartX - prevWidthPositive : barStartX + prevWidthNegative;
|
|
472
|
+
} else {
|
|
473
|
+
xStart = point.x > X_ORIGIN ? barStartX + prevWidthPositive : barStartX - prevWidthNegative;
|
|
474
|
+
}
|
|
357
475
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, {
|
|
358
476
|
key: `${index}_${point.x}`
|
|
359
477
|
}, /*#__PURE__*/ _react.createElement("rect", {
|
|
360
478
|
transform: `translate(0,${0.5 * (yBarScale.bandwidth() - _barHeight)})`,
|
|
361
479
|
key: point.x,
|
|
362
|
-
x:
|
|
480
|
+
x: xStart,
|
|
363
481
|
y: yBarScale(point.y),
|
|
364
482
|
rx: props.roundCorners ? 3 : 0,
|
|
365
|
-
width:
|
|
483
|
+
width: currentWidth - (_isRtl ? gapWidthRTL : gapWidthLTR),
|
|
366
484
|
height: _barHeight,
|
|
367
485
|
"aria-labelledby": `toolTip${_calloutId}`,
|
|
368
486
|
"aria-label": _getAriaLabel(point),
|
|
@@ -426,16 +544,20 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
426
544
|
function _getLegendData(data) {
|
|
427
545
|
const { useSingleColor } = props;
|
|
428
546
|
const actions = [];
|
|
547
|
+
const mapLegendToColor = {};
|
|
429
548
|
data.forEach((point, _index1)=>{
|
|
430
549
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
431
550
|
const color = useSingleColor ? props.colors ? _createColors()(1) : (0, _index.getNextColor)(1, 0) : point.color;
|
|
551
|
+
mapLegendToColor[point.legend] = color;
|
|
552
|
+
});
|
|
553
|
+
Object.entries(mapLegendToColor).forEach(([legendTitle, color])=>{
|
|
432
554
|
// mapping data to the format Legends component needs
|
|
433
555
|
const legend = {
|
|
434
|
-
title:
|
|
556
|
+
title: legendTitle,
|
|
435
557
|
color,
|
|
436
558
|
hoverAction: ()=>{
|
|
437
559
|
_handleChartMouseLeave();
|
|
438
|
-
_onLegendHover(
|
|
560
|
+
_onLegendHover(legendTitle);
|
|
439
561
|
},
|
|
440
562
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
441
563
|
onMouseOutAction: (isLegendSelected)=>{
|
|
@@ -517,6 +639,20 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
517
639
|
setPopoverOpen(true);
|
|
518
640
|
}
|
|
519
641
|
}
|
|
642
|
+
function _getDomainNRangeValues(points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
|
|
643
|
+
let domainNRangeValue;
|
|
644
|
+
if (xAxisType === _index.XAxisTypes.NumericAxis) {
|
|
645
|
+
domainNRangeValue = (0, _index.domainRangeOfNumericForHorizontalBarChartWithAxis)(points, margins, width, isRTL, shiftX, X_ORIGIN);
|
|
646
|
+
} else {
|
|
647
|
+
domainNRangeValue = {
|
|
648
|
+
dStartValue: 0,
|
|
649
|
+
dEndValue: 0,
|
|
650
|
+
rStartValue: 0,
|
|
651
|
+
rEndValue: 0
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
return domainNRangeValue;
|
|
655
|
+
}
|
|
520
656
|
if (!_isChartEmpty()) {
|
|
521
657
|
_adjustProps();
|
|
522
658
|
const calloutProps = {
|
|
@@ -545,18 +681,21 @@ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwa
|
|
|
545
681
|
_xMax = Math.max((0, _d3array.max)(_points, (point)=>point.x), props.xMaxValue || 0);
|
|
546
682
|
const legendBars = _getLegendData(_points);
|
|
547
683
|
return /*#__PURE__*/ _react.createElement(_CartesianChart.CartesianChart, {
|
|
684
|
+
yAxisPadding: _yAxisPadding,
|
|
548
685
|
...props,
|
|
549
686
|
chartTitle: _getChartTitle(),
|
|
550
687
|
points: _points,
|
|
551
688
|
chartType: _index.ChartTypes.HorizontalBarChartWithAxis,
|
|
552
689
|
xAxisType: _xAxisType,
|
|
553
690
|
yAxisType: _yAxisType,
|
|
691
|
+
getDomainNRangeValues: _getDomainNRangeValues,
|
|
554
692
|
stringDatasetForYAxisDomain: _yAxisLabels,
|
|
555
693
|
calloutProps: calloutProps,
|
|
556
694
|
tickParams: tickParams,
|
|
557
695
|
legendBars: legendBars,
|
|
558
696
|
barwidth: _barHeight,
|
|
559
697
|
getmargins: _getMargins,
|
|
698
|
+
getYDomainMargins: _getDomainMarginsForHorizontalBarChart,
|
|
560
699
|
getGraphData: _getGraphData,
|
|
561
700
|
getAxisData: _getAxisData,
|
|
562
701
|
onChartMouseLeave: _handleChartMouseLeave,
|