@fluentui/react-charting 5.24.24 → 5.24.26

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 (47) hide show
  1. package/CHANGELOG.json +49 -1
  2. package/CHANGELOG.md +23 -2
  3. package/dist/react-charting.d.ts +55 -1
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +9 -0
  7. package/lib/components/CommonComponents/CartesianChart.base.js +10 -5
  8. package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
  9. package/lib/components/CommonComponents/CartesianChart.types.d.ts +16 -1
  10. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +213 -47
  12. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  13. package/lib/index.d.ts +1 -1
  14. package/lib/index.js.map +1 -1
  15. package/lib/types/IDataPoint.d.ts +37 -0
  16. package/lib/types/IDataPoint.js.map +1 -1
  17. package/lib/utilities/utilities.d.ts +7 -3
  18. package/lib/utilities/utilities.js +131 -17
  19. package/lib/utilities/utilities.js.map +1 -1
  20. package/lib-amd/components/CommonComponents/CartesianChart.base.js +10 -5
  21. package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
  22. package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +16 -1
  23. package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
  24. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +215 -50
  25. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  26. package/lib-amd/index.d.ts +1 -1
  27. package/lib-amd/index.js.map +1 -1
  28. package/lib-amd/types/IDataPoint.d.ts +37 -0
  29. package/lib-amd/types/IDataPoint.js.map +1 -1
  30. package/lib-amd/utilities/utilities.d.ts +7 -3
  31. package/lib-amd/utilities/utilities.js +132 -16
  32. package/lib-amd/utilities/utilities.js.map +1 -1
  33. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +10 -5
  34. package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
  35. package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +16 -1
  36. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  37. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +215 -49
  38. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  39. package/lib-commonjs/index.d.ts +1 -1
  40. package/lib-commonjs/index.js.map +1 -1
  41. package/lib-commonjs/types/IDataPoint.d.ts +37 -0
  42. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  43. package/lib-commonjs/utilities/utilities.d.ts +7 -3
  44. package/lib-commonjs/utilities/utilities.js +132 -16
  45. package/lib-commonjs/utilities/utilities.js.map +1 -1
  46. package/package.json +4 -4
  47. package/src/components/CommonComponents/CartesianChart.types.ts +19 -0
@@ -13,6 +13,7 @@ var chart_utilities_1 = require("@fluentui/chart-utilities");
13
13
  var d3_shape_1 = require("d3-shape");
14
14
  var PlotlyColorAdapter_1 = require("./PlotlyColorAdapter");
15
15
  var d3_color_1 = require("d3-color");
16
+ var react_1 = require("@fluentui/react");
16
17
  exports.NON_PLOT_KEY_PREFIX = 'nonplot_';
17
18
  exports.SINGLE_REPEAT = 'repeat(1, 1fr)';
18
19
  var dashOptions = {
@@ -337,25 +338,55 @@ var transformPlotlyJsonToDonutProps = function (input, isMultiPlot, colorMap, co
337
338
  // otherwise, default to colorway from template
338
339
  var colors = (0, PlotlyColorAdapter_1.extractColor)((_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.piecolorway) !== null && _b !== void 0 ? _b : (_e = (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.template) === null || _d === void 0 ? void 0 : _d.layout) === null || _e === void 0 ? void 0 : _e.colorway, colorwayType, (_g = (_f = input.layout) === null || _f === void 0 ? void 0 : _f.piecolorway) !== null && _g !== void 0 ? _g : (_h = firstData === null || firstData === void 0 ? void 0 : firstData.marker) === null || _h === void 0 ? void 0 : _h.colors, colorMap, isDarkTheme);
339
340
  var mapLegendToDataPoint = {};
340
- (_j = firstData.labels) === null || _j === void 0 ? void 0 : _j.forEach(function (label, index) {
341
- var value = (0, exports.getNumberAtIndexOrDefault)(firstData.values, index);
342
- if ((0, chart_utilities_1.isInvalidValue)(value) || value < 0) {
343
- return;
344
- }
345
- var legend = "".concat(label);
346
- // resolve color for each legend from the extracted colors
347
- var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, legend, colorMap, isDarkTheme);
348
- if (!mapLegendToDataPoint[legend]) {
349
- mapLegendToDataPoint[legend] = {
350
- legend: legend,
351
- data: value,
352
- color: color,
353
- };
354
- }
355
- else {
356
- mapLegendToDataPoint[legend].data += value;
341
+ if (colors) {
342
+ (_j = firstData.labels) === null || _j === void 0 ? void 0 : _j.forEach(function (label, index) {
343
+ var value = (0, exports.getNumberAtIndexOrDefault)(firstData.values, index);
344
+ if ((0, chart_utilities_1.isInvalidValue)(value) || value < 0) {
345
+ return;
346
+ }
347
+ var legend = "".concat(label);
348
+ // resolve color for each legend from the extracted colors
349
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, index, legend, colorMap, isDarkTheme);
350
+ if (!mapLegendToDataPoint[legend]) {
351
+ mapLegendToDataPoint[legend] = {
352
+ legend: legend,
353
+ data: value,
354
+ color: color,
355
+ };
356
+ }
357
+ else {
358
+ mapLegendToDataPoint[legend].data += value;
359
+ }
360
+ });
361
+ }
362
+ else {
363
+ // Sort labels by value descending before mapping
364
+ if (firstData.labels && firstData.values) {
365
+ var labelValuePairs = firstData.labels.map(function (label, index) { return ({
366
+ label: label,
367
+ value: (0, exports.getNumberAtIndexOrDefault)(firstData.values, index),
368
+ index: index,
369
+ }); });
370
+ // Filter out invalid values
371
+ var validPairs = labelValuePairs.filter(function (pair) { return !(0, chart_utilities_1.isInvalidValue)(pair.value); });
372
+ // Sort descending by value
373
+ validPairs.sort(function (a, b) { return b.value - a.value; });
374
+ validPairs.forEach(function (pair, sortedIdx) {
375
+ var legend = "".concat(pair.label);
376
+ var color = (0, PlotlyColorAdapter_1.resolveColor)(colors, sortedIdx, legend, colorMap, isDarkTheme);
377
+ if (!mapLegendToDataPoint[legend]) {
378
+ mapLegendToDataPoint[legend] = {
379
+ legend: legend,
380
+ data: pair.value,
381
+ color: color,
382
+ };
383
+ }
384
+ else {
385
+ mapLegendToDataPoint[legend].data += pair.value;
386
+ }
387
+ });
357
388
  }
358
- });
389
+ }
359
390
  var width = (_l = (_k = input.layout) === null || _k === void 0 ? void 0 : _k.width) !== null && _l !== void 0 ? _l : 440;
360
391
  var height = (_o = (_m = input.layout) === null || _m === void 0 ? void 0 : _m.height) !== null && _o !== void 0 ? _o : 220;
361
392
  var hideLabels = firstData.textinfo
@@ -460,7 +491,7 @@ var transformPlotlyJsonToVSBCProps = function (input, isMultiPlot, colorMap, col
460
491
  });
461
492
  });
462
493
  var vsbcData = Object.values(mapXToDataPoints);
463
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: vsbcData, width: (_a = input.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barWidth: 'auto', yMaxValue: yMaxValue, yMinValue: yMinValue, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true, supportNegativeData: true, barGapMax: 2, showYAxisLables: true, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, wrapXAxisLables: typeof ((_d = vsbcData[0]) === null || _d === void 0 ? void 0 : _d.xAxisPoint) === 'string' }), getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getYMinMaxValues(input.data[0], input.layout)), getXAxisTickFormat(input.data[0], input.layout)), yAxisTickFormat), getBarProps(input.data, input.layout));
494
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: vsbcData, width: (_a = input.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = input.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barWidth: 'auto', yMaxValue: yMaxValue, yMinValue: yMinValue, mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true, supportNegativeData: true, barGapMax: 2, showYAxisLables: true, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, wrapXAxisLables: typeof ((_d = vsbcData[0]) === null || _d === void 0 ? void 0 : _d.xAxisPoint) === 'string' }), getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getYMinMaxValues(input.data[0], input.layout)), getXAxisTickFormat(input.data[0], input.layout)), yAxisTickFormat), getBarProps(input.data, input.layout)), getAxisTickProps(input.data, input.layout));
464
495
  };
465
496
  exports.transformPlotlyJsonToVSBCProps = transformPlotlyJsonToVSBCProps;
466
497
  var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
@@ -527,7 +558,7 @@ var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorMap, col
527
558
  });
528
559
  });
529
560
  var gvbcData = Object.values(mapXToDataPoints);
530
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: gvbcData, width: (_a = processedInput.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = processedInput.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barwidth: 'auto', mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true, wrapXAxisLables: typeof ((_d = gvbcData[0]) === null || _d === void 0 ? void 0 : _d.name) === 'string' }), getTitles(processedInput.layout)), getAxisCategoryOrderProps(processedInput.data, processedInput.layout)), getYMinMaxValues(processedInput.data[0], processedInput.layout)), getXAxisTickFormat(processedInput.data[0], processedInput.layout)), yAxisTickFormat), getBarProps(processedInput.data, processedInput.layout));
561
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: gvbcData, width: (_a = processedInput.layout) === null || _a === void 0 ? void 0 : _a.width, height: (_c = (_b = processedInput.layout) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 350, barwidth: 'auto', mode: 'plotly' }, secondaryYAxisValues), { hideTickOverlap: true, hideLegend: hideLegend, roundCorners: true, wrapXAxisLables: typeof ((_d = gvbcData[0]) === null || _d === void 0 ? void 0 : _d.name) === 'string' }), getTitles(processedInput.layout)), getAxisCategoryOrderProps(processedInput.data, processedInput.layout)), getYMinMaxValues(processedInput.data[0], processedInput.layout)), getXAxisTickFormat(processedInput.data[0], processedInput.layout)), yAxisTickFormat), getBarProps(processedInput.data, processedInput.layout)), getAxisTickProps(processedInput.data, processedInput.layout));
531
562
  };
532
563
  exports.transformPlotlyJsonToGVBCProps = transformPlotlyJsonToGVBCProps;
533
564
  var transformPlotlyJsonToVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
@@ -692,7 +723,7 @@ var transformPlotlyJsonToScatterTraceProps = function (input, isMultiPlot, chart
692
723
  var scatterChartProps = {
693
724
  scatterChartData: chartData,
694
725
  };
695
- var commonProps = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ supportNegativeData: true }, secondaryYAxisValues), { width: (_b = input.layout) === null || _b === void 0 ? void 0 : _b.width, height: (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 350, hideTickOverlap: true, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 }), getTitles(input.layout)), getXAxisTickFormat(input.data[0], input.layout)), yAxisTickFormat), getAxisScaleTypeProps(input.data, input.layout));
726
+ var commonProps = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ supportNegativeData: true }, secondaryYAxisValues), { width: (_b = input.layout) === null || _b === void 0 ? void 0 : _b.width, height: (_d = (_c = input.layout) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 350, hideTickOverlap: true, hideLegend: hideLegend, useUTC: false, optimizeLargeData: numDataPoints > 1000 }), getTitles(input.layout)), getXAxisTickFormat(input.data[0], input.layout)), yAxisTickFormat), getAxisScaleTypeProps(input.data, input.layout)), getAxisTickProps(input.data, input.layout));
696
727
  if (isAreaChart) {
697
728
  return tslib_1.__assign({ data: chartProps, mode: mode }, commonProps);
698
729
  }
@@ -743,9 +774,9 @@ var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, isMultiPl
743
774
  var scalingFactor = 0.01;
744
775
  var gapFactor = 1 / (1 + scalingFactor * numberOfRows);
745
776
  var barHeight = availableHeight / (numberOfRows * (1 + gapFactor));
746
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: chartData, secondaryYAxistitle: typeof ((_k = (_j = input.layout) === null || _j === void 0 ? void 0 : _j.yaxis2) === null || _k === void 0 ? void 0 : _k.title) === 'string'
777
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: chartData, secondaryYAxistitle: typeof ((_k = (_j = input.layout) === null || _j === void 0 ? void 0 : _j.yaxis2) === null || _k === void 0 ? void 0 : _k.title) === 'string'
747
778
  ? (_m = (_l = input.layout) === null || _l === void 0 ? void 0 : _l.yaxis2) === null || _m === void 0 ? void 0 : _m.title
748
- : ((_q = (_p = (_o = input.layout) === null || _o === void 0 ? void 0 : _o.yaxis2) === null || _p === void 0 ? void 0 : _p.title) === null || _q === void 0 ? void 0 : _q.text) || '', barHeight: barHeight, showYAxisLables: true, height: chartHeight, width: (_r = input.layout) === null || _r === void 0 ? void 0 : _r.width, hideTickOverlap: true, hideLegend: hideLegend, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, roundCorners: true }, getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getBarProps(input.data, input.layout, true));
779
+ : ((_q = (_p = (_o = input.layout) === null || _o === void 0 ? void 0 : _o.yaxis2) === null || _p === void 0 ? void 0 : _p.title) === null || _q === void 0 ? void 0 : _q.text) || '', barHeight: barHeight, showYAxisLables: true, height: chartHeight, width: (_r = input.layout) === null || _r === void 0 ? void 0 : _r.width, hideTickOverlap: true, hideLegend: hideLegend, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, roundCorners: true }, getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getBarProps(input.data, input.layout, true)), getAxisTickProps(input.data, input.layout));
749
780
  };
750
781
  exports.transformPlotlyJsonToHorizontalBarWithAxisProps = transformPlotlyJsonToHorizontalBarWithAxisProps;
751
782
  var transformPlotlyJsonToGanttChartProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
@@ -792,7 +823,7 @@ var transformPlotlyJsonToGanttChartProps = function (input, isMultiPlot, colorMa
792
823
  .filter(function (point) { return point !== null; });
793
824
  })
794
825
  .flat();
795
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: chartData, showYAxisLables: true, height: (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 350, width: (_c = input.layout) === null || _c === void 0 ? void 0 : _c.width, hideTickOverlap: true, hideLegend: hideLegend, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, roundCorners: true, useUTC: false }, getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getBarProps(input.data, input.layout, true));
826
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: chartData, showYAxisLables: true, height: (_b = (_a = input.layout) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 350, width: (_c = input.layout) === null || _c === void 0 ? void 0 : _c.width, hideTickOverlap: true, hideLegend: hideLegend, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, roundCorners: true, useUTC: false }, getTitles(input.layout)), getAxisCategoryOrderProps(input.data, input.layout)), getBarProps(input.data, input.layout, true)), getAxisTickProps(input.data, input.layout));
796
827
  };
797
828
  exports.transformPlotlyJsonToGanttChartProps = transformPlotlyJsonToGanttChartProps;
798
829
  var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
@@ -907,7 +938,7 @@ var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, colorMap,
907
938
  var rangeValuesForColorScale = Array.isArray(colorscale)
908
939
  ? colorscale.map(function (arr) { return arr[1]; })
909
940
  : defaultRange;
910
- return tslib_1.__assign(tslib_1.__assign({ data: [heatmapData], domainValuesForColorScale: domainValuesForColorScale, rangeValuesForColorScale: rangeValuesForColorScale, hideLegend: true, showYAxisLables: true, sortOrder: 'none', width: (_6 = input.layout) === null || _6 === void 0 ? void 0 : _6.width, height: (_8 = (_7 = input.layout) === null || _7 === void 0 ? void 0 : _7.height) !== null && _8 !== void 0 ? _8 : 350, hideTickOverlap: true, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, wrapXAxisLables: true }, getTitles(input.layout)), getAxisCategoryOrderProps([firstData], input.layout));
941
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ data: [heatmapData], domainValuesForColorScale: domainValuesForColorScale, rangeValuesForColorScale: rangeValuesForColorScale, hideLegend: true, showYAxisLables: true, sortOrder: 'none', width: (_6 = input.layout) === null || _6 === void 0 ? void 0 : _6.width, height: (_8 = (_7 = input.layout) === null || _7 === void 0 ? void 0 : _7.height) !== null && _8 !== void 0 ? _8 : 350, hideTickOverlap: true, noOfCharsToTruncate: 20, showYAxisLablesTooltip: true, wrapXAxisLables: true }, getTitles(input.layout)), getAxisCategoryOrderProps([firstData], input.layout)), getAxisTickProps(input.data, input.layout));
911
942
  };
912
943
  exports.transformPlotlyJsonToHeatmapProps = transformPlotlyJsonToHeatmapProps;
913
944
  var transformPlotlyJsonToSankeyProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
@@ -1542,11 +1573,11 @@ var createBins = function (data, binStart, binEnd, binSize) {
1542
1573
  var binGenerator = (0, d3_array_1.bin)().domain([minVal, maxVal]);
1543
1574
  if (typeof binSize === 'number' && binSize > 0) {
1544
1575
  var thresholds = [];
1545
- var precision = Math.max(getPrecision(minVal), getPrecision(binSize));
1546
- var th = precisionRound(minVal, precision);
1547
- while (th < precisionRound(maxVal + binSize, precision)) {
1576
+ var precision = Math.max((0, react_1.calculatePrecision)(minVal), (0, react_1.calculatePrecision)(binSize));
1577
+ var th = (0, react_1.precisionRound)(minVal, precision);
1578
+ while (th < (0, react_1.precisionRound)(maxVal + binSize, precision)) {
1548
1579
  thresholds.push(th);
1549
- th = precisionRound(th + binSize, precision);
1580
+ th = (0, react_1.precisionRound)(th + binSize, precision);
1550
1581
  }
1551
1582
  minVal = thresholds[0];
1552
1583
  maxVal = thresholds[thresholds.length - 1];
@@ -1589,14 +1620,6 @@ var calculateHistNorm = function (histnorm, value, total, dx, dy) {
1589
1620
  return value;
1590
1621
  }
1591
1622
  };
1592
- var getPrecision = function (value) {
1593
- var _a, _b;
1594
- return (_b = (_a = value.toString().split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
1595
- };
1596
- var precisionRound = function (value, precision) {
1597
- var factor = Math.pow(10, precision);
1598
- return Math.round(value * factor) / factor;
1599
- };
1600
1623
  var getLegendShape = function (series) {
1601
1624
  var _a, _b;
1602
1625
  var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
@@ -1979,7 +2002,128 @@ var getBarProps = function (data, layout, isHorizontal) {
1979
2002
  };
1980
2003
  };
1981
2004
  var getAxisScaleTypeProps = function (data, layout) {
2005
+ var _a, _b, _c;
1982
2006
  var result = {};
2007
+ var axisObjects = getAxisObjects(data, layout);
2008
+ if (((_a = axisObjects.x) === null || _a === void 0 ? void 0 : _a.type) === 'log') {
2009
+ result.xScaleType = 'log';
2010
+ }
2011
+ if (((_b = axisObjects.y) === null || _b === void 0 ? void 0 : _b.type) === 'log') {
2012
+ result.yScaleType = 'log';
2013
+ }
2014
+ if (((_c = axisObjects.y2) === null || _c === void 0 ? void 0 : _c.type) === 'log') {
2015
+ result.secondaryYScaleType = 'log';
2016
+ }
2017
+ return result;
2018
+ };
2019
+ /**
2020
+ * @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/tick_value_defaults.js#L8}
2021
+ */
2022
+ var getAxisTickProps = function (data, layout) {
2023
+ var props = {};
2024
+ var axisObjects = getAxisObjects(data, layout);
2025
+ Object.keys(axisObjects).forEach(function (axId) {
2026
+ var ax = axisObjects[axId];
2027
+ if (!ax) {
2028
+ return;
2029
+ }
2030
+ var axType = getAxisType(data, axId[0], ax);
2031
+ if ((!ax.tickmode || ax.tickmode === 'array') && (0, chart_utilities_1.isArrayOrTypedArray)(ax.tickvals)) {
2032
+ var tickValues = axType === 'date' ? ax.tickvals.map(function (v) { return new Date(v); }) : ax.tickvals;
2033
+ if (axId === 'x') {
2034
+ props.tickValues = tickValues;
2035
+ }
2036
+ else if (axId === 'y') {
2037
+ props.yAxisTickValues = tickValues;
2038
+ }
2039
+ return;
2040
+ }
2041
+ if ((!ax.tickmode || ax.tickmode === 'linear') && ax.dtick) {
2042
+ var dtick = plotlyDtick(ax.dtick, axType);
2043
+ var tick0 = plotlyTick0(ax.tick0, axType, dtick);
2044
+ if (axId === 'x') {
2045
+ props.xAxis = {
2046
+ tickStep: dtick,
2047
+ tick0: tick0,
2048
+ };
2049
+ }
2050
+ else if (axId === 'y') {
2051
+ props.yAxis = {
2052
+ tickStep: dtick,
2053
+ tick0: tick0,
2054
+ };
2055
+ }
2056
+ return;
2057
+ }
2058
+ if ((!ax.tickmode || ax.tickmode === 'auto') && typeof ax.nticks === 'number' && ax.nticks >= 0) {
2059
+ if (axId === 'x') {
2060
+ props.xAxisTickCount = ax.nticks;
2061
+ }
2062
+ else if (axId === 'y') {
2063
+ props.yAxisTickCount = ax.nticks;
2064
+ }
2065
+ }
2066
+ });
2067
+ return props;
2068
+ };
2069
+ /**
2070
+ * @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L16}
2071
+ */
2072
+ var plotlyDtick = function (dtick, axType) {
2073
+ var isLogAx = axType === 'log';
2074
+ var isDateAx = axType === 'date';
2075
+ var isCatAx = axType === 'category';
2076
+ var dtickDflt = isDateAx ? 86400000 : 1;
2077
+ if (!dtick) {
2078
+ return dtickDflt;
2079
+ }
2080
+ if ((0, chart_utilities_1.isNumber)(dtick)) {
2081
+ dtick = Number(dtick);
2082
+ if (dtick <= 0) {
2083
+ return dtickDflt;
2084
+ }
2085
+ if (isCatAx) {
2086
+ // category dtick must be positive integers
2087
+ return Math.max(1, Math.round(dtick));
2088
+ }
2089
+ if (isDateAx) {
2090
+ // date dtick must be at least 0.1ms (our current precision)
2091
+ return Math.max(0.1, dtick);
2092
+ }
2093
+ return dtick;
2094
+ }
2095
+ if (typeof dtick !== 'string' || !(isDateAx || isLogAx)) {
2096
+ return dtickDflt;
2097
+ }
2098
+ var prefix = dtick.charAt(0);
2099
+ var dtickNum = (0, chart_utilities_1.isNumber)(dtick.slice(1)) ? Number(dtick.slice(1)) : 0;
2100
+ if (dtickNum <= 0 ||
2101
+ !(
2102
+ // "M<n>" gives ticks every (integer) n months
2103
+ ((isDateAx && prefix === 'M' && dtickNum === Math.round(dtickNum)) ||
2104
+ // "L<f>" gives ticks linearly spaced in data (not in position) every (float) f
2105
+ (isLogAx && prefix === 'L') ||
2106
+ // "D1" gives powers of 10 with all small digits between, "D2" gives only 2 and 5
2107
+ (isLogAx && prefix === 'D' && (dtickNum === 1 || dtickNum === 2))))) {
2108
+ return dtickDflt;
2109
+ }
2110
+ return dtick;
2111
+ };
2112
+ /**
2113
+ * @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L70}
2114
+ */
2115
+ var plotlyTick0 = function (tick0, axType, dtick) {
2116
+ if (axType === 'date') {
2117
+ return (0, chart_utilities_1.isDate)(tick0) ? new Date(tick0) : new Date(utilities_1.DEFAULT_DATE_STRING);
2118
+ }
2119
+ if (dtick === 'D1' || dtick === 'D2') {
2120
+ // D1 and D2 modes ignore tick0 entirely
2121
+ return undefined;
2122
+ }
2123
+ // Aside from date axes, tick0 must be numeric
2124
+ return (0, chart_utilities_1.isNumber)(tick0) ? Number(tick0) : 0;
2125
+ };
2126
+ var getAxisObjects = function (data, layout) {
1983
2127
  // Traces are grouped by their xaxis property, and for each group/subplot, the adapter functions
1984
2128
  // are called with the corresponding filtered data. As a result, all traces passed to an adapter
1985
2129
  // function share the same xaxis.
@@ -1990,21 +2134,43 @@ var getAxisScaleTypeProps = function (data, layout) {
1990
2134
  xAxisId = axisIds.x;
1991
2135
  yAxisIds.add(axisIds.y);
1992
2136
  });
1993
- var isLogAxis = function (axLetter, axId) {
1994
- var _a;
1995
- var axisKey = (0, chart_utilities_1.getAxisKey)(axLetter, axId);
1996
- return ((_a = layout === null || layout === void 0 ? void 0 : layout[axisKey]) === null || _a === void 0 ? void 0 : _a.type) === 'log';
1997
- };
1998
- if (typeof xAxisId === 'number' && isLogAxis('x', xAxisId)) {
1999
- result.xScaleType = 'log';
2137
+ var axisObjects = {};
2138
+ if (typeof xAxisId === 'number') {
2139
+ axisObjects.x = layout === null || layout === void 0 ? void 0 : layout[(0, chart_utilities_1.getAxisKey)('x', xAxisId)];
2000
2140
  }
2001
2141
  var sortedYAxisIds = Array.from(yAxisIds).sort();
2002
- if (sortedYAxisIds.length > 0 && isLogAxis('y', sortedYAxisIds[0])) {
2003
- result.yScaleType = 'log';
2142
+ if (sortedYAxisIds.length > 0) {
2143
+ axisObjects.y = layout === null || layout === void 0 ? void 0 : layout[(0, chart_utilities_1.getAxisKey)('y', sortedYAxisIds[0])];
2004
2144
  }
2005
- if (sortedYAxisIds.length > 1 && isLogAxis('y', sortedYAxisIds[1])) {
2006
- result.secondaryYScaleType = 'log';
2145
+ if (sortedYAxisIds.length > 1) {
2146
+ axisObjects.y2 = layout === null || layout === void 0 ? void 0 : layout[(0, chart_utilities_1.getAxisKey)('y', sortedYAxisIds[1])];
2147
+ }
2148
+ return axisObjects;
2149
+ };
2150
+ var getAxisType = function (data, axLetter, ax) {
2151
+ var values = [];
2152
+ data.forEach(function (series) {
2153
+ var _a;
2154
+ (_a = series[axLetter]) === null || _a === void 0 ? void 0 : _a.forEach(function (val) {
2155
+ if (!(0, chart_utilities_1.isInvalidValue)(val)) {
2156
+ values.push(val);
2157
+ }
2158
+ });
2159
+ });
2160
+ // Note: When ax.type is explicitly specified, Plotly casts the values to match that type.
2161
+ // Therefore, simply checking the type of the values may not be sufficient. At the moment,
2162
+ // we don’t always perform this casting ourselves and instead use the values as provided.
2163
+ if ((0, chart_utilities_1.isNumberArray)(values)) {
2164
+ if ((ax === null || ax === void 0 ? void 0 : ax.type) === 'log') {
2165
+ return 'log';
2166
+ }
2167
+ return 'linear';
2168
+ }
2169
+ if ((0, chart_utilities_1.isDateArray)(values)) {
2170
+ return 'date';
2171
+ }
2172
+ if ((0, chart_utilities_1.isStringArray)(values)) {
2173
+ return 'category';
2007
2174
  }
2008
- return result;
2009
2175
  };
2010
2176
  //# sourceMappingURL=PlotlySchemaAdapter.js.map