@fluentui/react-charts 9.1.2 → 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.
Files changed (65) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/dist/index.d.ts +36 -1
  3. package/lib/components/AreaChart/AreaChart.js +18 -8
  4. package/lib/components/AreaChart/AreaChart.js.map +1 -1
  5. package/lib/components/CommonComponents/CartesianChart.js +20 -15
  6. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  7. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  8. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +57 -43
  9. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  10. package/lib/components/GaugeChart/useGaugeChartStyles.styles.js +4 -2
  11. package/lib/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
  12. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +44 -18
  13. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  14. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -1
  15. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +3 -2
  16. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  17. package/lib/components/HeatMapChart/HeatMapChart.js +1 -1
  18. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
  19. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +181 -38
  20. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  21. package/lib/components/LineChart/LineChart.js +40 -36
  22. package/lib/components/LineChart/LineChart.js.map +1 -1
  23. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +8 -8
  24. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  25. package/lib/components/ScatterChart/ScatterChart.js +1 -1
  26. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  27. package/lib/components/VerticalBarChart/VerticalBarChart.js +4 -4
  28. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  29. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +61 -23
  30. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  31. package/lib/types/DataPoint.js.map +1 -1
  32. package/lib/utilities/utilities.js +77 -46
  33. package/lib/utilities/utilities.js.map +1 -1
  34. package/lib-commonjs/components/AreaChart/AreaChart.js +16 -7
  35. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  36. package/lib-commonjs/components/CommonComponents/CartesianChart.js +19 -15
  37. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  38. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  39. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +57 -43
  40. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  41. package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js +4 -2
  42. package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
  43. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +43 -17
  44. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  45. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -1
  46. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +4 -2
  47. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  48. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +1 -1
  49. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
  50. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +175 -36
  51. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  52. package/lib-commonjs/components/LineChart/LineChart.js +40 -36
  53. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  54. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +7 -7
  55. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  56. package/lib-commonjs/components/ScatterChart/ScatterChart.js +1 -1
  57. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  58. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +4 -4
  59. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  60. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +60 -22
  61. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  62. package/lib-commonjs/types/DataPoint.js.map +1 -1
  63. package/lib-commonjs/utilities/utilities.js +76 -46
  64. package/lib-commonjs/utilities/utilities.js.map +1 -1
  65. package/package.json +8 -8
@@ -9,6 +9,7 @@ import { curveLinear as d3CurveLinear, curveNatural as d3CurveNatural, curveStep
9
9
  import { formatPrefix as d3FormatPrefix } from 'd3-format';
10
10
  import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
11
11
  import { formatDateToLocaleString, formatToLocaleString, getMultiLevelDateTimeFormatOptions } from '@fluentui/chart-utilities';
12
+ export const MIN_DOMAIN_MARGIN = 8;
12
13
  export var ChartTypes;
13
14
  (function(ChartTypes) {
14
15
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
@@ -487,10 +488,10 @@ export function createYAxisForHorizontalBarChartWithAxis(yAxisParams, isRtl, axi
487
488
  startValue: 0,
488
489
  endValue: 0
489
490
  }, yAxisElement = null, yMaxValue = 0, yMinValue = 0, containerHeight, margins, tickPadding = 12, maxOfYVal = 0, yAxisTickFormat, yAxisTickCount = 4 } = yAxisParams;
490
- // maxOfYVal coming from only area chart and Grouped vertical bar chart(Calculation done at base file)
491
+ // maxOfYVal coming from horizontal bar chart with axis (Calculation done at base file)
491
492
  const tempVal = maxOfYVal || yMinMaxValues.endValue;
492
493
  const finalYmax = tempVal > yMaxValue ? tempVal : yMaxValue;
493
- const finalYmin = yMinMaxValues.startValue < yMinValue ? 0 : yMinValue;
494
+ const finalYmin = yMinMaxValues.startValue < yMinValue ? Math.min(0, yMinMaxValues.startValue) : yMinValue;
494
495
  const yAxisScale = d3ScaleLinear().domain([
495
496
  finalYmin,
496
497
  finalYmax
@@ -510,9 +511,9 @@ export function createNumericYAxisForOtherCharts(yAxisParams, isRtl, axisData, i
510
511
  endValue: 0
511
512
  }, yAxisElement = null, yMaxValue = 0, yMinValue = 0, containerHeight, containerWidth, margins, tickPadding = 12, maxOfYVal = 0, yAxisTickFormat, yAxisTickCount = 4, eventAnnotationProps, eventLabelHeight } = yAxisParams;
512
513
  // maxOfYVal coming from only area chart and Grouped vertical bar chart(Calculation done at base file)
513
- const tempVal = maxOfYVal || yMinMaxValues.endValue;
514
+ const tempVal = maxOfYVal || yMinMaxValues.endValue || 0;
514
515
  const finalYmax = tempVal > yMaxValue ? tempVal : yMaxValue;
515
- const finalYmin = Math.min(yMinMaxValues.startValue, yMinValue || 0);
516
+ const finalYmin = Math.min(yMinMaxValues.startValue || 0, yMinValue || 0);
516
517
  const domainValues = prepareDatapoints(finalYmax, finalYmin, yAxisTickCount, isIntegralDataset, roundedTicks);
517
518
  let yMin = finalYmin;
518
519
  let yMax = domainValues[domainValues.length - 1];
@@ -549,11 +550,13 @@ export const createStringYAxis = (yAxisParams, dataPoints, isRtl, chartType, bar
549
550
  * @param dataPoints
550
551
  * @param isRtl
551
552
  */ export const createStringYAxisForHorizontalBarChartWithAxis = (yAxisParams, dataPoints, isRtl, barWidth, culture)=>{
552
- const { containerHeight, tickPadding = 12, margins, yAxisTickFormat, yAxisElement } = yAxisParams;
553
+ const { containerHeight, tickPadding = 12, margins, yAxisTickFormat, yAxisElement, yAxisPadding } = yAxisParams;
554
+ let yAxisPaddingValue = yAxisPadding !== null && yAxisPadding !== void 0 ? yAxisPadding : 0.5;
555
+ yAxisPaddingValue = yAxisPaddingValue === 1 ? 0.99 : yAxisPaddingValue;
553
556
  const yAxisScale = d3ScaleBand().domain(dataPoints).range([
554
- containerHeight - margins.bottom - barWidth / 2,
555
- margins.top + barWidth / 2
556
- ]);
557
+ containerHeight - margins.bottom,
558
+ margins.top
559
+ ]).padding(yAxisPaddingValue);
557
560
  const axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
558
561
  const yAxis = axis.tickPadding(tickPadding).ticks(dataPoints);
559
562
  if (yAxisTickFormat) {
@@ -917,6 +920,41 @@ export function tooltipOfXAxislabels(xAxistooltipProps) {
917
920
  rEndValue
918
921
  };
919
922
  }
923
+ /**
924
+ * Groups HorizontalBarChart With Axis data based on YValue
925
+ * Used for stacked case
926
+ * @param {IHorizontalBarChartWithAxisDataPoint[]} chartData
927
+ * @returns {IHorizontalBarChartWithAxisDataPoint[][]}
928
+ */ export function groupChartDataByYValue(chartData) {
929
+ const map = {};
930
+ chartData.forEach((dataPoint)=>{
931
+ const key = dataPoint.y;
932
+ if (!map[key]) {
933
+ map[key] = [];
934
+ }
935
+ map[key].push(dataPoint);
936
+ });
937
+ return Object.values(map);
938
+ }
939
+ /**
940
+ * Calculates maximum domain values for Numeric x axis for both positive and negative values
941
+ * works for Horizontal Bar Chart With axis
942
+ * @param {HorizontalBarChartWithAxisDataPoint[][]} stackedChartData
943
+ * @returns {number}
944
+ */ export function computeLongestBars(stackedChartData, X_ORIGIN) {
945
+ let longestPositiveBar = 0;
946
+ let longestNegativeBar = 0;
947
+ stackedChartData.forEach((group)=>{
948
+ const positiveBarTotal = group.reduce((acc, point)=>acc + (point.x > 0 ? point.x : 0), X_ORIGIN);
949
+ const negativeBarTotal = group.reduce((acc, point)=>acc + (point.x < 0 ? point.x : 0), X_ORIGIN);
950
+ longestPositiveBar = Math.max(longestPositiveBar, positiveBarTotal);
951
+ longestNegativeBar = Math.min(longestNegativeBar, negativeBarTotal);
952
+ });
953
+ return {
954
+ longestPositiveBar,
955
+ longestNegativeBar
956
+ };
957
+ }
920
958
  /**
921
959
  * Calculates Domain and range values for Numeric X axis.
922
960
  * This method calculates Horizontal Chart with Axis
@@ -926,17 +964,19 @@ export function tooltipOfXAxislabels(xAxistooltipProps) {
926
964
  * @param {number} width
927
965
  * @param {boolean} isRTL
928
966
  * @returns {IDomainNRange}
929
- */ export function domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, containerWidth, isRTL, shiftX) {
930
- const xMax = d3Max(points, (point)=>point.x);
967
+ */ export function domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, containerWidth, isRTL, shiftX, X_ORIGIN) {
968
+ const longestBars = computeLongestBars(groupChartDataByYValue(points), X_ORIGIN);
969
+ const xMax = longestBars.longestPositiveBar;
970
+ const xMin = longestBars.longestNegativeBar;
931
971
  const rMin = isRTL ? margins.left : margins.left + shiftX;
932
972
  const rMax = isRTL ? containerWidth - margins.right - shiftX : containerWidth - margins.right;
933
973
  return isRTL ? {
934
974
  dStartValue: xMax,
935
- dEndValue: 0,
975
+ dEndValue: Math.min(xMin, X_ORIGIN),
936
976
  rStartValue: rMin,
937
977
  rEndValue: rMax
938
978
  } : {
939
- dStartValue: 0,
979
+ dStartValue: Math.min(xMin, X_ORIGIN),
940
980
  dEndValue: xMax,
941
981
  rStartValue: rMin,
942
982
  rEndValue: rMax
@@ -1144,7 +1184,7 @@ export function tooltipOfXAxislabels(xAxistooltipProps) {
1144
1184
  * @param {number} [barWidth]
1145
1185
  * @returns {IDomainNRange}
1146
1186
  */ export function getDomainNRangeValues(// eslint-disable-next-line @typescript-eslint/no-explicit-any
1147
- points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
1187
+ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX, X_ORIGIN) {
1148
1188
  let domainNRangeValue;
1149
1189
  if (xAxisType === 0) {
1150
1190
  switch(chartType){
@@ -1159,7 +1199,7 @@ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shift
1159
1199
  domainNRangeValue = domainRageOfVerticalNumeric(points, margins, width, isRTL, barWidth);
1160
1200
  break;
1161
1201
  case 6:
1162
- domainNRangeValue = domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, width, isRTL, shiftX);
1202
+ domainNRangeValue = domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, width, isRTL, shiftX, X_ORIGIN);
1163
1203
  break;
1164
1204
  case 7:
1165
1205
  domainNRangeValue = domainRangeOfNumericForScatterChart(points, margins, width, isRTL);
@@ -1217,16 +1257,18 @@ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shift
1217
1257
  * @export
1218
1258
  * @param {LineChartPoints[]} points
1219
1259
  * @returns {{ startValue: number; endValue: number }}
1220
- */ export function findNumericMinMaxOfY(points) {
1221
- const yMax = d3Max(points, (point)=>{
1222
- return d3Max(point.data, (item)=>item.y);
1223
- });
1224
- const yMin = d3Min(points, (point)=>{
1225
- return d3Min(point.data, (item)=>item.y);
1260
+ */ export function findNumericMinMaxOfY(points, yAxisType, useSecondaryYScale) {
1261
+ const values = [];
1262
+ points.forEach((point)=>{
1263
+ if (!useSecondaryYScale === !point.useSecondaryYScale) {
1264
+ point.data.forEach((data)=>{
1265
+ values.push(data.y);
1266
+ });
1267
+ }
1226
1268
  });
1227
1269
  return {
1228
- startValue: yMin,
1229
- endValue: yMax
1270
+ startValue: d3Min(values),
1271
+ endValue: d3Max(values)
1230
1272
  };
1231
1273
  }
1232
1274
  /**
@@ -1247,32 +1289,21 @@ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shift
1247
1289
  * @export
1248
1290
  * @param {VerticalBarChartDataPoint[]} points
1249
1291
  * @returns {{ startValue: number; endValue: number }}
1250
- */ export function findVerticalNumericMinMaxOfY(points) {
1251
- const yMax = d3Max(points, (point)=>{
1252
- if (point.lineData !== undefined) {
1253
- if (point.y > point.lineData.y) {
1254
- return point.y;
1255
- } else {
1256
- return point.lineData.y;
1257
- }
1258
- } else {
1259
- return point.y;
1292
+ */ export function findVerticalNumericMinMaxOfY(points, yAxisType, useSecondaryYScale) {
1293
+ const values = [];
1294
+ points.forEach((point)=>{
1295
+ if (!useSecondaryYScale) {
1296
+ values.push(point.y);
1260
1297
  }
1261
- });
1262
- const yMin = d3Min(points, (point)=>{
1263
- if (point.lineData !== undefined) {
1264
- if (point.y < point.lineData.y) {
1265
- return point.y;
1266
- } else {
1267
- return point.lineData.y;
1298
+ if (typeof point.lineData !== 'undefined') {
1299
+ if (!useSecondaryYScale === !point.lineData.useSecondaryYScale) {
1300
+ values.push(point.lineData.y);
1268
1301
  }
1269
- } else {
1270
- return point.y;
1271
1302
  }
1272
1303
  });
1273
1304
  return {
1274
- startValue: yMin,
1275
- endValue: yMax
1305
+ startValue: d3Min(values),
1306
+ endValue: d3Max(values)
1276
1307
  };
1277
1308
  }
1278
1309
  /**
@@ -1304,19 +1335,19 @@ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shift
1304
1335
  * @returns {{ startValue: number; endValue: number }}
1305
1336
  */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1306
1337
  export function getMinMaxOfYAxis(// eslint-disable-next-line @typescript-eslint/no-explicit-any
1307
- points, chartType, yAxisType = 0) {
1338
+ points, chartType, yAxisType = 0, useSecondaryYScale) {
1308
1339
  let minMaxValues;
1309
1340
  switch(chartType){
1310
1341
  case 0:
1311
1342
  case 1:
1312
1343
  case 7:
1313
- minMaxValues = findNumericMinMaxOfY(points);
1344
+ minMaxValues = findNumericMinMaxOfY(points, yAxisType, useSecondaryYScale);
1314
1345
  break;
1315
1346
  case 3:
1316
1347
  minMaxValues = findVSBCNumericMinMaxOfY(points);
1317
1348
  break;
1318
1349
  case 2:
1319
- minMaxValues = findVerticalNumericMinMaxOfY(points);
1350
+ minMaxValues = findVerticalNumericMinMaxOfY(points, yAxisType, useSecondaryYScale);
1320
1351
  break;
1321
1352
  case 6:
1322
1353
  minMaxValues = findHBCWANumericMinMaxOfY(points, yAxisType);