@fluentui/react-charting 5.23.84 → 5.23.85

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 (50) hide show
  1. package/CHANGELOG.json +34 -1
  2. package/CHANGELOG.md +14 -2
  3. package/dist/react-charting.d.ts +7 -0
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +2 -0
  7. package/lib/components/CommonComponents/CartesianChart.base.js +1 -1
  8. package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
  9. package/lib/components/CommonComponents/CartesianChart.types.d.ts +2 -0
  10. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +8 -3
  12. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  13. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +5 -0
  14. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +78 -16
  15. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  16. package/lib/types/IDataPoint.d.ts +5 -0
  17. package/lib/types/IDataPoint.js.map +1 -1
  18. package/lib/utilities/utilities.d.ts +1 -0
  19. package/lib/utilities/utilities.js +114 -40
  20. package/lib/utilities/utilities.js.map +1 -1
  21. package/lib-amd/components/CommonComponents/CartesianChart.base.js +1 -1
  22. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  23. package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +2 -0
  24. package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
  25. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +8 -3
  26. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  27. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +5 -0
  28. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +77 -16
  29. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  30. package/lib-amd/types/IDataPoint.d.ts +5 -0
  31. package/lib-amd/types/IDataPoint.js.map +1 -1
  32. package/lib-amd/utilities/utilities.d.ts +1 -0
  33. package/lib-amd/utilities/utilities.js +115 -41
  34. package/lib-amd/utilities/utilities.js.map +1 -1
  35. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +1 -1
  36. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  37. package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +2 -0
  38. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  39. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +8 -3
  40. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  41. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +5 -0
  42. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +77 -15
  43. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  44. package/lib-commonjs/types/IDataPoint.d.ts +5 -0
  45. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  46. package/lib-commonjs/utilities/utilities.d.ts +1 -0
  47. package/lib-commonjs/utilities/utilities.js +116 -42
  48. package/lib-commonjs/utilities/utilities.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/components/CommonComponents/CartesianChart.types.ts +3 -0
@@ -10,6 +10,7 @@ import { timeSecond as d3TimeSecond, timeMinute as d3TimeMinute, timeHour as d3T
10
10
  import { formatPrefix as d3FormatPrefix } from 'd3-format';
11
11
  import { getId } from '@fluentui/react';
12
12
  import { curveLinear as d3CurveLinear, curveNatural as d3CurveNatural, curveStep as d3CurveStep, curveStepAfter as d3CurveStepAfter, curveStepBefore as d3CurveStepBefore, } from 'd3-shape';
13
+ export var MIN_DOMAIN_MARGIN = 8;
13
14
  export var ChartTypes;
14
15
  (function (ChartTypes) {
15
16
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
@@ -66,7 +67,7 @@ export function defaultYAxisTickFormatter(value) {
66
67
  */
67
68
  export function createNumericXAxis(xAxisParams, tickParams, chartType, culture) {
68
69
  var _a;
69
- var domainNRangeValues = xAxisParams.domainNRangeValues, _b = xAxisParams.showRoundOffXTickValues, showRoundOffXTickValues = _b === void 0 ? false : _b, _c = xAxisParams.xAxistickSize, xAxistickSize = _c === void 0 ? 6 : _c, _d = xAxisParams.tickPadding, tickPadding = _d === void 0 ? 10 : _d, xAxisCount = xAxisParams.xAxisCount, xAxisElement = xAxisParams.xAxisElement, hideTickOverlap = xAxisParams.hideTickOverlap;
70
+ var domainNRangeValues = xAxisParams.domainNRangeValues, _b = xAxisParams.showRoundOffXTickValues, showRoundOffXTickValues = _b === void 0 ? true : _b, _c = xAxisParams.xAxistickSize, xAxistickSize = _c === void 0 ? 6 : _c, _d = xAxisParams.tickPadding, tickPadding = _d === void 0 ? 10 : _d, xAxisCount = xAxisParams.xAxisCount, xAxisElement = xAxisParams.xAxisElement, hideTickOverlap = xAxisParams.hideTickOverlap;
70
71
  var xAxisScale = d3ScaleLinear()
71
72
  .domain([domainNRangeValues.dStartValue, domainNRangeValues.dEndValue])
72
73
  .range([domainNRangeValues.rStartValue, domainNRangeValues.rEndValue]);
@@ -101,16 +102,75 @@ export function createNumericXAxis(xAxisParams, tickParams, chartType, culture)
101
102
  var tickValues = ((_a = tickParams.tickValues) !== null && _a !== void 0 ? _a : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
102
103
  return { xScale: xAxisScale, tickValues: tickValues };
103
104
  }
104
- function multiFormat(date, locale, useUTC) {
105
+ /**
106
+ * This function returns a multilevel formatter for a given date range.
107
+ * It determines the appropriate date format to accommodate each tick value.
108
+ * The goal is to represent the date label in the smallest possible format without loss of information.
109
+ * The challenge here is to adhere to locale specific formats while ensuring the complete label is shown.
110
+ * There is an exhaustive map of all possible date/time units and their respective formats.
111
+ * Based on the range of formatting granularity levels, a format spanning the range is returned.
112
+ * @param startLevel - The starting level of the date format.
113
+ * @param endLevel - The ending level of the date format.
114
+ * @param locale - The locale object for formatting.
115
+ * @param useUTC
116
+ * @returns
117
+ */
118
+ function getMultiLevelDateFormatter(startLevel, endLevel, locale, useUTC) {
105
119
  var timeFormat = locale ? (useUTC ? locale.utcFormat : locale.format) : useUTC ? d3UtcFormat : d3TimeFormat;
106
- var formatMillisecond = timeFormat('.%L');
107
- var formatSecond = timeFormat(':%S');
108
- var formatMinute = timeFormat('%I:%M');
109
- var formatHour = timeFormat('%I %p');
110
- var formatDay = timeFormat('%a %d');
111
- var formatWeek = timeFormat('%b %d');
112
- var formatMonth = timeFormat('%B');
113
- var formatYear = timeFormat('%Y');
120
+ // Refer to https://d3js.org/d3-time-format#locale_format to see explanation about each format specifier
121
+ var DEFAULT = '%c';
122
+ var MS = '.%L';
123
+ var MS_S = ':%S.%L';
124
+ var MS_S_MIN = '%M:%S.%L';
125
+ var MS_S_MIN_H = '%-I:%M:%S.%L %p';
126
+ var MS_S_MIN_H_D = '%a %d, %X';
127
+ var MS_S_MIN_H_D_W = '%b %d, %X';
128
+ var MS_S_MIN_H_D_W_M = MS_S_MIN_H_D_W;
129
+ var MS_S_MIN_H_D_W_M_Y = DEFAULT;
130
+ var S = ':%S';
131
+ var S_MIN = '%-I:%M:%S';
132
+ var S_MIN_H = '%X';
133
+ var S_MIN_H_D = MS_S_MIN_H_D;
134
+ var S_MIN_H_D_W = MS_S_MIN_H_D_W;
135
+ var S_MIN_H_D_W_M = MS_S_MIN_H_D_W_M;
136
+ var S_MIN_H_D_W_M_Y = DEFAULT;
137
+ var MIN = '%-I:%M %p';
138
+ var MIN_H = MIN;
139
+ var MIN_H_D = '%a %d, %-I:%M %p';
140
+ var MIN_H_D_W = '%b %d, %-I:%M %p';
141
+ var MIN_H_D_W_M = MIN_H_D_W;
142
+ var MIN_H_D_W_M_Y = '%x, %-I:%M %p';
143
+ var H = '%-I %p';
144
+ var H_D = '%a %d, %-I %p';
145
+ var H_D_W = '%b %d, %-I %p';
146
+ var H_D_W_M = H_D_W;
147
+ var H_D_W_M_Y = '%x, %-I %p';
148
+ var D = '%a %d';
149
+ var D_W = '%b %d';
150
+ var D_W_M = D_W;
151
+ var D_W_M_Y = '%x';
152
+ var W = D_W;
153
+ var W_M = W;
154
+ var W_M_Y = D_W_M_Y;
155
+ var M = '%B';
156
+ var M_Y = '%b %Y';
157
+ var Y = '%Y';
158
+ var MULTI_LEVEL_DATE_TIME_FORMATS = [
159
+ // ms, s, min, h, d, w, m, y
160
+ [MS, MS_S, MS_S_MIN, MS_S_MIN_H, MS_S_MIN_H_D, MS_S_MIN_H_D_W, MS_S_MIN_H_D_W_M, MS_S_MIN_H_D_W_M_Y], // ms
161
+ [DEFAULT, S, S_MIN, S_MIN_H, S_MIN_H_D, S_MIN_H_D_W, S_MIN_H_D_W_M, S_MIN_H_D_W_M_Y], // s
162
+ [DEFAULT, DEFAULT, MIN, MIN_H, MIN_H_D, MIN_H_D_W, MIN_H_D_W_M, MIN_H_D_W_M_Y], // min
163
+ [DEFAULT, DEFAULT, DEFAULT, H, H_D, H_D_W, H_D_W_M, H_D_W_M_Y], // h
164
+ [DEFAULT, DEFAULT, DEFAULT, DEFAULT, D, D_W, D_W_M, D_W_M_Y], // d
165
+ [DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, W, W_M, W_M_Y], // w
166
+ [DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, M, M_Y], // m
167
+ [DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, Y], // y
168
+ ];
169
+ var formatter = timeFormat(MULTI_LEVEL_DATE_TIME_FORMATS[startLevel][endLevel]);
170
+ return formatter;
171
+ }
172
+ function getDateFormatLevel(date, useUTC) {
173
+ var _a;
114
174
  var timeSecond = useUTC ? d3UtcSecond : d3TimeSecond;
115
175
  var timeMinute = useUTC ? d3UtcMinute : d3TimeMinute;
116
176
  var timeHour = useUTC ? d3UtcHour : d3TimeHour;
@@ -118,21 +178,21 @@ function multiFormat(date, locale, useUTC) {
118
178
  var timeMonth = useUTC ? d3UtcMonth : d3TimeMonth;
119
179
  var timeWeek = useUTC ? d3UtcWeek : d3TimeWeek;
120
180
  var timeYear = useUTC ? d3UtcYear : d3TimeYear;
121
- return (timeSecond(date) < date
122
- ? formatMillisecond
123
- : timeMinute(date) < date
124
- ? formatSecond
125
- : timeHour(date) < date
126
- ? formatMinute
127
- : timeDay(date) < date
128
- ? formatHour
129
- : timeMonth(date) < date
130
- ? timeWeek(date) < date
131
- ? formatDay
132
- : formatWeek
133
- : timeYear(date) < date
134
- ? formatMonth
135
- : formatYear)(date);
181
+ var formats = [
182
+ { formatLevel: 0, condition: function (d) { return timeSecond(d) < d; } }, // Milliseconds
183
+ { formatLevel: 1, condition: function (d) { return timeMinute(d) < d; } }, // Seconds
184
+ { formatLevel: 2, condition: function (d) { return timeHour(d) < d; } }, // Minutes
185
+ { formatLevel: 3, condition: function (d) { return timeDay(d) < d; } }, // Hours
186
+ { formatLevel: 4, condition: function (d) { return timeMonth(d) < d && timeWeek(d) < d; } }, // Days
187
+ { formatLevel: 5, condition: function (d) { return timeMonth(d) < d; } }, // Weeks
188
+ { formatLevel: 6, condition: function (d) { return timeYear(d) < d; } }, // Months
189
+ { formatLevel: 7, condition: function () { return true; } }, // Years (default)
190
+ ];
191
+ var matchedFormat = formats.find(function (_a) {
192
+ var condition = _a.condition;
193
+ return condition(date);
194
+ });
195
+ return (_a = matchedFormat === null || matchedFormat === void 0 ? void 0 : matchedFormat.formatLevel) !== null && _a !== void 0 ? _a : 7;
136
196
  }
137
197
  function isPowerOf10(num) {
138
198
  var roundedfinalYMax = handleFloatingPointPrecisionError(num);
@@ -151,12 +211,26 @@ function handleFloatingPointPrecisionError(num) {
151
211
  */
152
212
  export function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLocale, customDateTimeFormatter, useUTC) {
153
213
  var _a;
154
- var domainNRangeValues = xAxisParams.domainNRangeValues, xAxisElement = xAxisParams.xAxisElement, _b = xAxisParams.tickPadding, tickPadding = _b === void 0 ? 6 : _b, _c = xAxisParams.xAxistickSize, xAxistickSize = _c === void 0 ? 6 : _c, xAxisCount = xAxisParams.xAxisCount, hideTickOverlap = xAxisParams.hideTickOverlap;
214
+ var domainNRangeValues = xAxisParams.domainNRangeValues, xAxisElement = xAxisParams.xAxisElement, _b = xAxisParams.tickPadding, tickPadding = _b === void 0 ? 6 : _b, _c = xAxisParams.xAxistickSize, xAxistickSize = _c === void 0 ? 6 : _c, xAxisCount = xAxisParams.xAxisCount;
155
215
  var xAxisScale = useUTC ? d3ScaleUtc() : d3ScaleTime();
156
216
  xAxisScale
157
217
  .domain([domainNRangeValues.dStartValue, domainNRangeValues.dEndValue])
158
- .range([domainNRangeValues.rStartValue, domainNRangeValues.rEndValue]);
218
+ .range([domainNRangeValues.rStartValue, domainNRangeValues.rEndValue])
219
+ .nice();
159
220
  var tickCount = xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : 6;
221
+ var lowestFormatLevel = 100;
222
+ var highestFormatLevel = -1;
223
+ var locale = timeFormatLocale ? d3TimeFormatLocale(timeFormatLocale) : undefined;
224
+ xAxisScale.ticks().forEach(function (domainValue) {
225
+ var formatLevel = getDateFormatLevel(domainValue, useUTC);
226
+ if (formatLevel > highestFormatLevel) {
227
+ highestFormatLevel = formatLevel;
228
+ }
229
+ if (formatLevel < lowestFormatLevel) {
230
+ lowestFormatLevel = formatLevel;
231
+ }
232
+ });
233
+ var formatFn = getMultiLevelDateFormatter(lowestFormatLevel, highestFormatLevel, locale, useUTC);
160
234
  var tickFormat = function (domainValue, _index) {
161
235
  if (customDateTimeFormatter) {
162
236
  return customDateTimeFormatter(domainValue);
@@ -165,8 +239,7 @@ export function createDateXAxis(xAxisParams, tickParams, culture, options, timeF
165
239
  return domainValue.toLocaleString(culture, options);
166
240
  }
167
241
  if (timeFormatLocale) {
168
- var locale = d3TimeFormatLocale(timeFormatLocale);
169
- return multiFormat(domainValue, locale, useUTC);
242
+ return formatFn(domainValue);
170
243
  }
171
244
  if (culture === undefined && tickParams.tickFormat) {
172
245
  if (useUTC) {
@@ -176,13 +249,12 @@ export function createDateXAxis(xAxisParams, tickParams, culture, options, timeF
176
249
  return d3TimeFormat(tickParams.tickFormat)(domainValue);
177
250
  }
178
251
  }
179
- return multiFormat(domainValue, undefined, useUTC);
252
+ return formatFn(domainValue);
180
253
  };
181
- if (hideTickOverlap && typeof xAxisCount === 'undefined') {
182
- var longestLabelWidth = calculateLongestLabelWidth(xAxisScale.ticks().map(tickFormat), '[class^="xAxis-"] text') + 40;
183
- var _d = xAxisScale.range(), start = _d[0], end = _d[1];
184
- tickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
185
- }
254
+ var longestLabelWidth = calculateLongestLabelWidth(xAxisScale.ticks().map(tickFormat), '[class^="xAxis-"] text') + 40;
255
+ var _d = xAxisScale.range(), start = _d[0], end = _d[1];
256
+ tickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
257
+ tickCount = Math.min(tickCount, xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : tickCount);
186
258
  var xAxis = d3AxisBottom(xAxisScale)
187
259
  .tickSize(xAxistickSize)
188
260
  .tickPadding(tickPadding)
@@ -310,13 +382,12 @@ export function prepareDatapoints(maxVal, minVal, splitInto, isIntegralDataset,
310
382
  }
311
383
  export function createYAxisForHorizontalBarChartWithAxis(yAxisParams, isRtl) {
312
384
  var _a = yAxisParams.yMinMaxValues, yMinMaxValues = _a === void 0 ? { startValue: 0, endValue: 0 } : _a, _b = yAxisParams.yAxisElement, yAxisElement = _b === void 0 ? null : _b, _c = yAxisParams.yMaxValue, yMaxValue = _c === void 0 ? 0 : _c, _d = yAxisParams.yMinValue, yMinValue = _d === void 0 ? 0 : _d, containerHeight = yAxisParams.containerHeight, margins = yAxisParams.margins, _e = yAxisParams.tickPadding, tickPadding = _e === void 0 ? 12 : _e, _f = yAxisParams.maxOfYVal, maxOfYVal = _f === void 0 ? 0 : _f, yAxisTickFormat = yAxisParams.yAxisTickFormat, _g = yAxisParams.yAxisTickCount, yAxisTickCount = _g === void 0 ? 4 : _g;
313
- // maxOfYVal coming from only area chart and Grouped vertical bar chart(Calculation done at base file)
385
+ // maxOfYVal coming from horizontal bar chart with axis (Calculation done at base file)
314
386
  var tempVal = maxOfYVal || yMinMaxValues.endValue;
315
387
  var finalYmax = tempVal > yMaxValue ? tempVal : yMaxValue;
316
388
  var finalYmin = yMinMaxValues.startValue < yMinValue ? Math.min(0, yMinMaxValues.startValue) : yMinValue;
317
- var yDomainPadding = Math.abs(finalYmax - finalYmin) * 0.1;
318
389
  var yAxisScale = d3ScaleLinear()
319
- .domain([finalYmin - yDomainPadding, finalYmax + yDomainPadding])
390
+ .domain([finalYmin, finalYmax])
320
391
  .range([containerHeight - margins.bottom, margins.top]);
321
392
  var axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
322
393
  var yAxis = axis.tickPadding(tickPadding).ticks(yAxisTickCount);
@@ -358,10 +429,13 @@ export function createNumericYAxis(yAxisParams, isRtl, axisData, isIntegralDatas
358
429
  * @param isRtl
359
430
  */
360
431
  export var createStringYAxisForHorizontalBarChartWithAxis = function (yAxisParams, dataPoints, isRtl, barWidth) {
361
- var containerHeight = yAxisParams.containerHeight, _a = yAxisParams.tickPadding, tickPadding = _a === void 0 ? 12 : _a, margins = yAxisParams.margins, yAxisTickFormat = yAxisParams.yAxisTickFormat, yAxisElement = yAxisParams.yAxisElement;
432
+ var containerHeight = yAxisParams.containerHeight, _a = yAxisParams.tickPadding, tickPadding = _a === void 0 ? 12 : _a, margins = yAxisParams.margins, yAxisTickFormat = yAxisParams.yAxisTickFormat, yAxisElement = yAxisParams.yAxisElement, yAxisPadding = yAxisParams.yAxisPadding;
433
+ var yAxisPaddingValue = yAxisPadding !== null && yAxisPadding !== void 0 ? yAxisPadding : 0.5;
434
+ yAxisPaddingValue = yAxisPaddingValue === 1 ? 0.99 : yAxisPaddingValue;
362
435
  var yAxisScale = d3ScaleBand()
363
436
  .domain(dataPoints)
364
- .range([containerHeight - margins.bottom - barWidth / 2, margins.top + barWidth / 2]);
437
+ .range([containerHeight - margins.bottom, margins.top])
438
+ .padding(yAxisPaddingValue);
365
439
  var axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
366
440
  var yAxis = axis.tickPadding(tickPadding).ticks(dataPoints);
367
441
  if (yAxisTickFormat) {