@fluentui/react-charts 0.0.0-nightly-20250814-0406.1 → 0.0.0-nightly-20250818-0407.1
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 +15 -15
- package/dist/index.d.ts +15 -6
- package/lib/components/CommonComponents/CartesianChart.js +12 -16
- 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 +3 -2
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +55 -38
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +126 -33
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/utilities.js +10 -4
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +12 -15
- 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 +2 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +57 -38
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +125 -32
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +10 -4
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +13 -13
|
@@ -47,6 +47,8 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
47
47
|
const cartesianChartRef = _react.useRef(null);
|
|
48
48
|
const Y_ORIGIN = 0;
|
|
49
49
|
const _legendsRef = _react.useRef(null);
|
|
50
|
+
let _yAxisType;
|
|
51
|
+
let _yAxisLabels = [];
|
|
50
52
|
const [selectedLegends, setSelectedLegends] = _react.useState(((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends) || []);
|
|
51
53
|
const [activeLegend, setActiveLegend] = _react.useState(undefined);
|
|
52
54
|
const [dataForHoverCard, setDataForHoverCard] = _react.useState(0);
|
|
@@ -247,15 +249,22 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
247
249
|
_lineObject = _getFormattedLineData(props.data);
|
|
248
250
|
_xAxisInnerPadding = (0, _index1.getScalePadding)(props.xAxisInnerPadding, props.xAxisPadding, _xAxisType === _index1.XAxisTypes.StringAxis ? 2 / 3 : 1 / 2);
|
|
249
251
|
_xAxisOuterPadding = (0, _index1.getScalePadding)(props.xAxisOuterPadding, props.xAxisPadding, 0);
|
|
252
|
+
_initYAxisParams();
|
|
250
253
|
}
|
|
251
254
|
function _createDataSetLayer() {
|
|
252
255
|
const tempArr = [];
|
|
253
256
|
const dataset = _points.map((singlePointData)=>{
|
|
257
|
+
tempArr.push(singlePointData.xAxisPoint);
|
|
258
|
+
if (_yAxisType === _index1.YAxisType.StringAxis) {
|
|
259
|
+
return {
|
|
260
|
+
x: singlePointData.xAxisPoint,
|
|
261
|
+
y: 0
|
|
262
|
+
};
|
|
263
|
+
}
|
|
254
264
|
let total = 0;
|
|
255
265
|
singlePointData.chartData.forEach((point)=>{
|
|
256
266
|
total = total + point.data;
|
|
257
267
|
});
|
|
258
|
-
tempArr.push(singlePointData.xAxisPoint);
|
|
259
268
|
return {
|
|
260
269
|
x: singlePointData.xAxisPoint,
|
|
261
270
|
y: total
|
|
@@ -286,7 +295,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
286
295
|
}
|
|
287
296
|
function _getGraphData(xScale, yScale, containerHeight, containerWidth, xElement) {
|
|
288
297
|
const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth);
|
|
289
|
-
return _bars = _createBar(xBarScale, yBarScale, containerHeight, xElement);
|
|
298
|
+
return _bars = _createBar(xBarScale, _yAxisType === _index1.YAxisType.StringAxis ? yScale : yBarScale, containerHeight, xElement);
|
|
290
299
|
}
|
|
291
300
|
function _getAxisData(yAxisData) {
|
|
292
301
|
if (yAxisData && yAxisData.yAxisDomainValues.length) {
|
|
@@ -413,6 +422,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
413
422
|
const y1 = useSecondaryYScale ? yScaleSecondary(lineObject[item][i - 1].y) : yScalePrimary(lineObject[item][i - 1].y);
|
|
414
423
|
const x2 = xScale(lineObject[item][i].xItem.xAxisPoint);
|
|
415
424
|
const y2 = useSecondaryYScale ? yScaleSecondary(lineObject[item][i].y) : yScalePrimary(lineObject[item][i].y);
|
|
425
|
+
const yScaleBandwidthTranslate = !useSecondaryYScale && _yAxisType === _index1.YAxisType.StringAxis ? yScalePrimary.bandwidth() / 2 : 0;
|
|
416
426
|
if (lineBorderWidth > 0) {
|
|
417
427
|
borderForLines.push(/*#__PURE__*/ _react.createElement("line", {
|
|
418
428
|
key: `${index}-${i}-BorderLine`,
|
|
@@ -425,7 +435,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
425
435
|
fill: "transparent",
|
|
426
436
|
strokeLinecap: "round",
|
|
427
437
|
stroke: _reacttheme.tokens.colorNeutralBackground1,
|
|
428
|
-
transform: `translate(${xScaleBandwidthTranslate},
|
|
438
|
+
transform: `translate(${xScaleBandwidthTranslate}, ${yScaleBandwidthTranslate})`
|
|
429
439
|
}));
|
|
430
440
|
}
|
|
431
441
|
var _lineObject_item__lineOptions_strokeWidth, _lineObject_item__lineOptions_strokeLinecap;
|
|
@@ -440,7 +450,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
440
450
|
strokeLinecap: (_lineObject_item__lineOptions_strokeLinecap = (_lineObject_item__lineOptions1 = lineObject[item][0].lineOptions) === null || _lineObject_item__lineOptions1 === void 0 ? void 0 : _lineObject_item__lineOptions1.strokeLinecap) !== null && _lineObject_item__lineOptions_strokeLinecap !== void 0 ? _lineObject_item__lineOptions_strokeLinecap : 'round',
|
|
441
451
|
strokeDasharray: (_lineObject_item__lineOptions2 = lineObject[item][0].lineOptions) === null || _lineObject_item__lineOptions2 === void 0 ? void 0 : _lineObject_item__lineOptions2.strokeDasharray,
|
|
442
452
|
stroke: lineObject[item][i].color,
|
|
443
|
-
transform: `translate(${xScaleBandwidthTranslate},
|
|
453
|
+
transform: `translate(${xScaleBandwidthTranslate}, ${yScaleBandwidthTranslate})`,
|
|
444
454
|
onMouseOver: (event)=>_lineHover(lineObject[item][i - 1], event),
|
|
445
455
|
onMouseLeave: _handleMouseOut
|
|
446
456
|
}));
|
|
@@ -452,6 +462,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
452
462
|
refElement: null
|
|
453
463
|
};
|
|
454
464
|
const noBarsAndLinesActive = circlePoint.xItem.chartData.filter((dataPoint)=>_noLegendHighlighted() || _isLegendHighlighted(dataPoint.legend)).length === 0;
|
|
465
|
+
const yScaleBandwidthTranslate = !circlePoint.useSecondaryYScale && _yAxisType === _index1.YAxisType.StringAxis ? yScalePrimary.bandwidth() / 2 : 0;
|
|
455
466
|
dots.push(/*#__PURE__*/ _react.createElement("circle", {
|
|
456
467
|
key: `${index}-${subIndex}-dot`,
|
|
457
468
|
cx: xScale(circlePoint.xItem.xAxisPoint),
|
|
@@ -465,7 +476,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
465
476
|
// Elements with visibility: hidden cannot receive focus, so use opacity: 0 instead to hide them.
|
|
466
477
|
// For more information, see https://fuzzbomb.github.io/accessibility-demos/visually-hidden-focus-test.html
|
|
467
478
|
opacity: _getCircleOpacityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).opacity,
|
|
468
|
-
transform: `translate(${xScaleBandwidthTranslate},
|
|
479
|
+
transform: `translate(${xScaleBandwidthTranslate}, ${yScaleBandwidthTranslate})`,
|
|
469
480
|
ref: (e)=>circleRef.refElement = e,
|
|
470
481
|
...noBarsAndLinesActive ? {
|
|
471
482
|
tabIndex: !props.hideTooltip ? 0 : undefined,
|
|
@@ -579,22 +590,29 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
579
590
|
}
|
|
580
591
|
function _getBarGapAndScale(bars, yBarScale, defaultTotalHeight) {
|
|
581
592
|
const { barGapMax = 0 } = props;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
const totalData = bars.reduce((iter, value)=>iter + Math.abs(value.data), 0);
|
|
585
|
-
const totalHeight = defaultTotalHeight !== null && defaultTotalHeight !== void 0 ? defaultTotalHeight : Math.abs(yBarScale(totalData) - yBarScale(Y_ORIGIN));
|
|
593
|
+
let totalData = 0;
|
|
594
|
+
let totalHeight;
|
|
586
595
|
let sumOfPercent = 0;
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
596
|
+
let scalingRatio;
|
|
597
|
+
if (_yAxisType === _index1.YAxisType.StringAxis) {
|
|
598
|
+
totalHeight = defaultTotalHeight !== null && defaultTotalHeight !== void 0 ? defaultTotalHeight : bars.reduce((total, bar)=>total + yBarScale(bar.data), 0);
|
|
599
|
+
} else {
|
|
600
|
+
// When displaying gaps between the bars, the height of each bar is
|
|
601
|
+
// adjusted so that the total of all bars is not changed by the gaps
|
|
602
|
+
totalData = bars.reduce((iter, value)=>iter + Math.abs(value.data), 0);
|
|
603
|
+
totalHeight = defaultTotalHeight !== null && defaultTotalHeight !== void 0 ? defaultTotalHeight : Math.abs(yBarScale(totalData) - yBarScale(Y_ORIGIN));
|
|
604
|
+
bars.forEach((point)=>{
|
|
605
|
+
let value = Math.abs(point.data) / totalData * 100;
|
|
606
|
+
if (value < 1 && value !== 0) {
|
|
607
|
+
value = 1;
|
|
608
|
+
}
|
|
609
|
+
sumOfPercent += value;
|
|
610
|
+
});
|
|
611
|
+
scalingRatio = sumOfPercent !== 0 ? sumOfPercent / 100 : 1;
|
|
612
|
+
}
|
|
595
613
|
const gaps = barGapMax && bars.length - 1;
|
|
596
614
|
const gapHeight = gaps && Math.max(barGapMin, Math.min(barGapMax, totalHeight * barGapMultiplier / gaps));
|
|
597
|
-
const heightValueScale = (totalHeight - gapHeight * gaps) / (totalData * scalingRatio);
|
|
615
|
+
const heightValueScale = _yAxisType === _index1.YAxisType.StringAxis ? 0 : (totalHeight - gapHeight * gaps) / (totalData * scalingRatio);
|
|
598
616
|
return {
|
|
599
617
|
gapHeight,
|
|
600
618
|
heightValueScale,
|
|
@@ -744,7 +762,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
744
762
|
const xPoint = xBarScale(_xAxisType === _index1.XAxisTypes.NumericAxis ? singleChartData.xAxisPoint : _xAxisType === _index1.XAxisTypes.DateAxis ? singleChartData.xAxisPoint : singleChartData.xAxisPoint);
|
|
745
763
|
const xScaleBandwidthTranslate = _xAxisType !== _index1.XAxisTypes.StringAxis ? -_barWidth / 2 : (xBarScale.bandwidth() - _barWidth) / 2;
|
|
746
764
|
let barTotalValue = 0;
|
|
747
|
-
const barsToDisplay = singleChartData.chartData.filter((point)=>point.data !== 0);
|
|
765
|
+
const barsToDisplay = singleChartData.chartData.filter((point)=>point.data !== 0 && point.data !== '' && !(_yAxisType === _index1.YAxisType.StringAxis && typeof yBarScale(point.data) === 'undefined'));
|
|
748
766
|
if (!barsToDisplay.length) {
|
|
749
767
|
return undefined;
|
|
750
768
|
}
|
|
@@ -752,7 +770,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
752
770
|
if (heightValueScale < 0) {
|
|
753
771
|
return undefined;
|
|
754
772
|
}
|
|
755
|
-
const yBaseline = containerHeight - _margins.bottom - yBarScale(Y_ORIGIN);
|
|
773
|
+
const yBaseline = containerHeight - _margins.bottom - (_yAxisType === _index1.YAxisType.StringAxis ? 0 : yBarScale(Y_ORIGIN));
|
|
756
774
|
let yPositiveStart = yBaseline;
|
|
757
775
|
let yNegativeStart = yBaseline;
|
|
758
776
|
let yPoint = 0;
|
|
@@ -772,22 +790,29 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
772
790
|
role: 'img',
|
|
773
791
|
tabIndex: !props.hideTooltip && shouldHighlight ? 0 : undefined
|
|
774
792
|
};
|
|
775
|
-
let barHeight
|
|
776
|
-
// FIXME: The current scaling logic may produce different min and gap heights for each bar stack.
|
|
777
|
-
const minHeight = Math.max(heightValueScale * absStackTotal / 100.0, barMinimumHeight);
|
|
778
|
-
if (barHeight < minHeight) {
|
|
779
|
-
barHeight = minHeight;
|
|
780
|
-
}
|
|
793
|
+
let barHeight;
|
|
781
794
|
const gapOffset = index ? gapHeight : 0;
|
|
782
|
-
if (
|
|
795
|
+
if (_yAxisType === _index1.YAxisType.StringAxis) {
|
|
796
|
+
barHeight = Math.max(containerHeight - _margins.bottom - (yBarScale(point.data) + yBarScale.bandwidth() / 2) - gapOffset, barMinimumHeight, 1);
|
|
783
797
|
yPositiveStart -= barHeight + gapOffset;
|
|
784
798
|
yPoint = yPositiveStart;
|
|
785
799
|
} else {
|
|
786
|
-
|
|
787
|
-
|
|
800
|
+
barHeight = Math.abs(heightValueScale * point.data);
|
|
801
|
+
// FIXME: The current scaling logic may produce different min and gap heights for each bar stack.
|
|
802
|
+
const minHeight = Math.max(heightValueScale * absStackTotal / 100.0, barMinimumHeight);
|
|
803
|
+
if (barHeight < minHeight) {
|
|
804
|
+
barHeight = minHeight;
|
|
805
|
+
}
|
|
806
|
+
if (point.data >= Y_ORIGIN) {
|
|
807
|
+
yPositiveStart -= barHeight + gapOffset;
|
|
808
|
+
yPoint = yPositiveStart;
|
|
809
|
+
} else {
|
|
810
|
+
yPoint = yNegativeStart + gapOffset;
|
|
811
|
+
yNegativeStart = yPoint + barHeight;
|
|
812
|
+
}
|
|
813
|
+
barTotalValue += point.data;
|
|
814
|
+
heightOfLastBar = index === barsToDisplay.length - 1 ? barHeight : 0;
|
|
788
815
|
}
|
|
789
|
-
barTotalValue += point.data;
|
|
790
|
-
heightOfLastBar = index === barsToDisplay.length - 1 ? barHeight : 0;
|
|
791
816
|
if (barCornerRadius && barHeight > barCornerRadius && index === barsToDisplay.length - 1) {
|
|
792
817
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, {
|
|
793
818
|
key: index + indexNumber + `${shouldFocusWholeStack}`
|
|
@@ -850,7 +875,7 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
850
875
|
};
|
|
851
876
|
let showLabel = false;
|
|
852
877
|
let barLabel = 0;
|
|
853
|
-
if (!props.hideLabels) {
|
|
878
|
+
if (!props.hideLabels && _yAxisType !== _index1.YAxisType.StringAxis) {
|
|
854
879
|
if (_noLegendHighlighted()) {
|
|
855
880
|
showLabel = true;
|
|
856
881
|
barLabel = barTotalValue;
|
|
@@ -920,6 +945,68 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
920
945
|
endValue: (0, _d3array.max)(values)
|
|
921
946
|
};
|
|
922
947
|
}
|
|
948
|
+
function _initYAxisParams() {
|
|
949
|
+
if (_points[0].chartData.length > 0) {
|
|
950
|
+
_yAxisType = (0, _index1.getTypeOfAxis)(_points[0].chartData[0].data, false);
|
|
951
|
+
} else {
|
|
952
|
+
Object.keys(_lineObject).forEach((lineLegend)=>{
|
|
953
|
+
if (!_lineObject[lineLegend][0].useSecondaryYScale) {
|
|
954
|
+
_yAxisType = (0, _index1.getTypeOfAxis)(_lineObject[lineLegend][0].y, false);
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
if (_yAxisType === _index1.YAxisType.StringAxis) {
|
|
959
|
+
const legendToYValues = {};
|
|
960
|
+
_points.forEach((xPoint)=>{
|
|
961
|
+
xPoint.chartData.forEach((bar)=>{
|
|
962
|
+
if (!legendToYValues[bar.legend]) {
|
|
963
|
+
legendToYValues[bar.legend] = [
|
|
964
|
+
`${bar.data}`
|
|
965
|
+
];
|
|
966
|
+
} else {
|
|
967
|
+
legendToYValues[bar.legend].push(`${bar.data}`);
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
const yAxisLabels = new Set();
|
|
972
|
+
Object.values(legendToYValues).forEach((yValues)=>{
|
|
973
|
+
yValues.forEach((yVal)=>{
|
|
974
|
+
yAxisLabels.add(yVal);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
Object.values(_lineObject).forEach((linePoints)=>{
|
|
978
|
+
linePoints.forEach((linePoint)=>{
|
|
979
|
+
if (!linePoint.useSecondaryYScale) {
|
|
980
|
+
yAxisLabels.add(`${linePoint.y}`);
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
_yAxisLabels = Array.from(yAxisLabels);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function _getYDomainMargins(containerHeight) {
|
|
988
|
+
/**
|
|
989
|
+
* Specifies the extra top margin to apply above the highest y-axis tick label.
|
|
990
|
+
* Useful when stacked bars extend beyond the combined height of all y-axis labels (or categories).
|
|
991
|
+
*/ let yAxisTickMarginTop = 0;
|
|
992
|
+
/** Total height available to render the bars */ const totalHeight = containerHeight - _margins.bottom - _margins.top;
|
|
993
|
+
if (_yAxisType === _index1.YAxisType.StringAxis) {
|
|
994
|
+
/** Maximum height of the stacked bars, expressed in multiples of the height of a y-axis label (or category) */ let maxBarHeightInLabels = 0;
|
|
995
|
+
_points.forEach((xPoint)=>{
|
|
996
|
+
/** Height of the stacked bar, expressed in multiples of the height of a y-axis label (or category) */ let barHeightInLabels = 0;
|
|
997
|
+
xPoint.chartData.forEach((bar)=>{
|
|
998
|
+
barHeightInLabels += _yAxisLabels.indexOf(`${bar.data}`) + 1;
|
|
999
|
+
});
|
|
1000
|
+
maxBarHeightInLabels = Math.max(maxBarHeightInLabels, barHeightInLabels);
|
|
1001
|
+
});
|
|
1002
|
+
/** Height of a y-axis label (or category) */ const yAxisLabelHeight = maxBarHeightInLabels === 0 ? 0 : totalHeight / maxBarHeightInLabels;
|
|
1003
|
+
yAxisTickMarginTop += yAxisLabelHeight * (maxBarHeightInLabels - _yAxisLabels.length);
|
|
1004
|
+
}
|
|
1005
|
+
return {
|
|
1006
|
+
..._margins,
|
|
1007
|
+
top: _margins.top + yAxisTickMarginTop
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
923
1010
|
if (!_isChartEmpty()) {
|
|
924
1011
|
_adjustProps();
|
|
925
1012
|
const _isHavingLines = props.data.some((item)=>item.lineData && item.lineData.length > 0);
|
|
@@ -975,6 +1062,12 @@ const VerticalStackedBarChart = (props)=>{
|
|
|
975
1062
|
},
|
|
976
1063
|
componentRef: cartesianChartRef,
|
|
977
1064
|
showRoundOffXTickValues: !(0, _index1.isScalePaddingDefined)(props.xAxisInnerPadding, props.xAxisPadding),
|
|
1065
|
+
yAxisType: _yAxisType,
|
|
1066
|
+
stringDatasetForYAxisDomain: [
|
|
1067
|
+
'',
|
|
1068
|
+
..._yAxisLabels
|
|
1069
|
+
],
|
|
1070
|
+
getYDomainMargins: _getYDomainMargins,
|
|
978
1071
|
/* eslint-disable react/jsx-no-bind */ children: (props)=>{
|
|
979
1072
|
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, /*#__PURE__*/ _react.createElement("g", null, _bars), /*#__PURE__*/ _react.createElement("g", null, _isHavingLines && _createLines(props.xScale, props.yScalePrimary, props.containerHeight, props.containerWidth, props.yScaleSecondary)));
|
|
980
1073
|
}
|