@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.
- package/CHANGELOG.json +49 -1
- package/CHANGELOG.md +23 -2
- package/dist/react-charting.d.ts +55 -1
- package/dist/react-charting.js +1 -1
- package/dist/react-charting.min.js +1 -1
- package/etc/react-charting.api.md +9 -0
- package/lib/components/CommonComponents/CartesianChart.base.js +10 -5
- package/lib/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.d.ts +16 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +213 -47
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types/IDataPoint.d.ts +37 -0
- package/lib/types/IDataPoint.js.map +1 -1
- package/lib/utilities/utilities.d.ts +7 -3
- package/lib/utilities/utilities.js +131 -17
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-amd/components/CommonComponents/CartesianChart.base.js +10 -5
- package/lib-amd/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib-amd/components/CommonComponents/CartesianChart.types.d.ts +16 -1
- package/lib-amd/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +215 -50
- package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-amd/index.d.ts +1 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/types/IDataPoint.d.ts +37 -0
- package/lib-amd/types/IDataPoint.js.map +1 -1
- package/lib-amd/utilities/utilities.d.ts +7 -3
- package/lib-amd/utilities/utilities.js +132 -16
- package/lib-amd/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.base.js +10 -5
- package/lib-commonjs/components/CommonComponents/CartesianChart.base.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.d.ts +16 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +215 -49
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types/IDataPoint.d.ts +37 -0
- package/lib-commonjs/types/IDataPoint.js.map +1 -1
- package/lib-commonjs/utilities/utilities.d.ts +7 -3
- package/lib-commonjs/utilities/utilities.js +132 -16
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +4 -4
- package/src/components/CommonComponents/CartesianChart.types.ts +19 -0
|
@@ -4,11 +4,12 @@ import { scaleLinear as d3ScaleLinear } from 'd3-scale';
|
|
|
4
4
|
import { format as d3Format } from 'd3-format';
|
|
5
5
|
import { DataVizPalette, getColorFromToken } from '../../utilities/colors';
|
|
6
6
|
import { GaugeChartVariant } from '../GaugeChart/index';
|
|
7
|
-
import { findNumericMinMaxOfY, formatScientificLimitWidth, MIN_DONUT_RADIUS } from '../../utilities/utilities';
|
|
7
|
+
import { DEFAULT_DATE_STRING, findNumericMinMaxOfY, formatScientificLimitWidth, MIN_DONUT_RADIUS, } from '../../utilities/utilities';
|
|
8
8
|
import { isArrayOrTypedArray, isDate, isDateArray, isNumberArray, isStringArray, isYearArray, isInvalidValue, formatToLocaleString, isNumber, isObjectArray, getAxisIds, getAxisKey, } from '@fluentui/chart-utilities';
|
|
9
9
|
import { curveCardinal as d3CurveCardinal } from 'd3-shape';
|
|
10
10
|
import { getOpacity, extractColor, resolveColor, createColorScale } from './PlotlyColorAdapter';
|
|
11
11
|
import { rgb } from 'd3-color';
|
|
12
|
+
import { calculatePrecision, precisionRound } from '@fluentui/react';
|
|
12
13
|
export var NON_PLOT_KEY_PREFIX = 'nonplot_';
|
|
13
14
|
export var SINGLE_REPEAT = 'repeat(1, 1fr)';
|
|
14
15
|
var dashOptions = {
|
|
@@ -329,25 +330,55 @@ export var transformPlotlyJsonToDonutProps = function (input, isMultiPlot, color
|
|
|
329
330
|
// otherwise, default to colorway from template
|
|
330
331
|
var colors = 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);
|
|
331
332
|
var mapLegendToDataPoint = {};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
mapLegendToDataPoint[legend]
|
|
342
|
-
legend
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
333
|
+
if (colors) {
|
|
334
|
+
(_j = firstData.labels) === null || _j === void 0 ? void 0 : _j.forEach(function (label, index) {
|
|
335
|
+
var value = getNumberAtIndexOrDefault(firstData.values, index);
|
|
336
|
+
if (isInvalidValue(value) || value < 0) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
var legend = "".concat(label);
|
|
340
|
+
// resolve color for each legend from the extracted colors
|
|
341
|
+
var color = resolveColor(colors, index, legend, colorMap, isDarkTheme);
|
|
342
|
+
if (!mapLegendToDataPoint[legend]) {
|
|
343
|
+
mapLegendToDataPoint[legend] = {
|
|
344
|
+
legend: legend,
|
|
345
|
+
data: value,
|
|
346
|
+
color: color,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
mapLegendToDataPoint[legend].data += value;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
// Sort labels by value descending before mapping
|
|
356
|
+
if (firstData.labels && firstData.values) {
|
|
357
|
+
var labelValuePairs = firstData.labels.map(function (label, index) { return ({
|
|
358
|
+
label: label,
|
|
359
|
+
value: getNumberAtIndexOrDefault(firstData.values, index),
|
|
360
|
+
index: index,
|
|
361
|
+
}); });
|
|
362
|
+
// Filter out invalid values
|
|
363
|
+
var validPairs = labelValuePairs.filter(function (pair) { return !isInvalidValue(pair.value); });
|
|
364
|
+
// Sort descending by value
|
|
365
|
+
validPairs.sort(function (a, b) { return b.value - a.value; });
|
|
366
|
+
validPairs.forEach(function (pair, sortedIdx) {
|
|
367
|
+
var legend = "".concat(pair.label);
|
|
368
|
+
var color = resolveColor(colors, sortedIdx, legend, colorMap, isDarkTheme);
|
|
369
|
+
if (!mapLegendToDataPoint[legend]) {
|
|
370
|
+
mapLegendToDataPoint[legend] = {
|
|
371
|
+
legend: legend,
|
|
372
|
+
data: pair.value,
|
|
373
|
+
color: color,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
mapLegendToDataPoint[legend].data += pair.value;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
349
380
|
}
|
|
350
|
-
}
|
|
381
|
+
}
|
|
351
382
|
var width = (_l = (_k = input.layout) === null || _k === void 0 ? void 0 : _k.width) !== null && _l !== void 0 ? _l : 440;
|
|
352
383
|
var height = (_o = (_m = input.layout) === null || _m === void 0 ? void 0 : _m.height) !== null && _o !== void 0 ? _o : 220;
|
|
353
384
|
var hideLabels = firstData.textinfo
|
|
@@ -451,7 +482,7 @@ export var transformPlotlyJsonToVSBCProps = function (input, isMultiPlot, colorM
|
|
|
451
482
|
});
|
|
452
483
|
});
|
|
453
484
|
var vsbcData = Object.values(mapXToDataPoints);
|
|
454
|
-
return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__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));
|
|
485
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__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));
|
|
455
486
|
};
|
|
456
487
|
export var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
|
|
457
488
|
var _a, _b, _c, _d;
|
|
@@ -517,7 +548,7 @@ export var transformPlotlyJsonToGVBCProps = function (input, isMultiPlot, colorM
|
|
|
517
548
|
});
|
|
518
549
|
});
|
|
519
550
|
var gvbcData = Object.values(mapXToDataPoints);
|
|
520
|
-
return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__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));
|
|
551
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__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));
|
|
521
552
|
};
|
|
522
553
|
export var transformPlotlyJsonToVBCProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
|
|
523
554
|
var _a, _b, _c, _d;
|
|
@@ -677,7 +708,7 @@ var transformPlotlyJsonToScatterTraceProps = function (input, isMultiPlot, chart
|
|
|
677
708
|
var scatterChartProps = {
|
|
678
709
|
scatterChartData: chartData,
|
|
679
710
|
};
|
|
680
|
-
var commonProps = __assign(__assign(__assign(__assign(__assign(__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));
|
|
711
|
+
var commonProps = __assign(__assign(__assign(__assign(__assign(__assign(__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));
|
|
681
712
|
if (isAreaChart) {
|
|
682
713
|
return __assign({ data: chartProps, mode: mode }, commonProps);
|
|
683
714
|
}
|
|
@@ -728,9 +759,9 @@ export var transformPlotlyJsonToHorizontalBarWithAxisProps = function (input, is
|
|
|
728
759
|
var scalingFactor = 0.01;
|
|
729
760
|
var gapFactor = 1 / (1 + scalingFactor * numberOfRows);
|
|
730
761
|
var barHeight = availableHeight / (numberOfRows * (1 + gapFactor));
|
|
731
|
-
return __assign(__assign(__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'
|
|
762
|
+
return __assign(__assign(__assign(__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'
|
|
732
763
|
? (_m = (_l = input.layout) === null || _l === void 0 ? void 0 : _l.yaxis2) === null || _m === void 0 ? void 0 : _m.title
|
|
733
|
-
: ((_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));
|
|
764
|
+
: ((_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));
|
|
734
765
|
};
|
|
735
766
|
export var transformPlotlyJsonToGanttChartProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
|
|
736
767
|
var _a, _b, _c;
|
|
@@ -776,7 +807,7 @@ export var transformPlotlyJsonToGanttChartProps = function (input, isMultiPlot,
|
|
|
776
807
|
.filter(function (point) { return point !== null; });
|
|
777
808
|
})
|
|
778
809
|
.flat();
|
|
779
|
-
return __assign(__assign(__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));
|
|
810
|
+
return __assign(__assign(__assign(__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));
|
|
780
811
|
};
|
|
781
812
|
export var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
|
|
782
813
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
|
|
@@ -890,7 +921,7 @@ export var transformPlotlyJsonToHeatmapProps = function (input, isMultiPlot, col
|
|
|
890
921
|
var rangeValuesForColorScale = Array.isArray(colorscale)
|
|
891
922
|
? colorscale.map(function (arr) { return arr[1]; })
|
|
892
923
|
: defaultRange;
|
|
893
|
-
return __assign(__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));
|
|
924
|
+
return __assign(__assign(__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));
|
|
894
925
|
};
|
|
895
926
|
export var transformPlotlyJsonToSankeyProps = function (input, isMultiPlot, colorMap, colorwayType, isDarkTheme) {
|
|
896
927
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -1519,7 +1550,7 @@ var createBins = function (data, binStart, binEnd, binSize) {
|
|
|
1519
1550
|
var binGenerator = d3Bin().domain([minVal, maxVal]);
|
|
1520
1551
|
if (typeof binSize === 'number' && binSize > 0) {
|
|
1521
1552
|
var thresholds = [];
|
|
1522
|
-
var precision = Math.max(
|
|
1553
|
+
var precision = Math.max(calculatePrecision(minVal), calculatePrecision(binSize));
|
|
1523
1554
|
var th = precisionRound(minVal, precision);
|
|
1524
1555
|
while (th < precisionRound(maxVal + binSize, precision)) {
|
|
1525
1556
|
thresholds.push(th);
|
|
@@ -1566,14 +1597,6 @@ var calculateHistNorm = function (histnorm, value, total, dx, dy) {
|
|
|
1566
1597
|
return value;
|
|
1567
1598
|
}
|
|
1568
1599
|
};
|
|
1569
|
-
var getPrecision = function (value) {
|
|
1570
|
-
var _a, _b;
|
|
1571
|
-
return (_b = (_a = value.toString().split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
1572
|
-
};
|
|
1573
|
-
var precisionRound = function (value, precision) {
|
|
1574
|
-
var factor = Math.pow(10, precision);
|
|
1575
|
-
return Math.round(value * factor) / factor;
|
|
1576
|
-
};
|
|
1577
1600
|
var getLegendShape = function (series) {
|
|
1578
1601
|
var _a, _b;
|
|
1579
1602
|
var dashType = ((_a = series.line) === null || _a === void 0 ? void 0 : _a.dash) || 'solid';
|
|
@@ -1951,7 +1974,128 @@ var getBarProps = function (data, layout, isHorizontal) {
|
|
|
1951
1974
|
};
|
|
1952
1975
|
};
|
|
1953
1976
|
var getAxisScaleTypeProps = function (data, layout) {
|
|
1977
|
+
var _a, _b, _c;
|
|
1954
1978
|
var result = {};
|
|
1979
|
+
var axisObjects = getAxisObjects(data, layout);
|
|
1980
|
+
if (((_a = axisObjects.x) === null || _a === void 0 ? void 0 : _a.type) === 'log') {
|
|
1981
|
+
result.xScaleType = 'log';
|
|
1982
|
+
}
|
|
1983
|
+
if (((_b = axisObjects.y) === null || _b === void 0 ? void 0 : _b.type) === 'log') {
|
|
1984
|
+
result.yScaleType = 'log';
|
|
1985
|
+
}
|
|
1986
|
+
if (((_c = axisObjects.y2) === null || _c === void 0 ? void 0 : _c.type) === 'log') {
|
|
1987
|
+
result.secondaryYScaleType = 'log';
|
|
1988
|
+
}
|
|
1989
|
+
return result;
|
|
1990
|
+
};
|
|
1991
|
+
/**
|
|
1992
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/tick_value_defaults.js#L8}
|
|
1993
|
+
*/
|
|
1994
|
+
var getAxisTickProps = function (data, layout) {
|
|
1995
|
+
var props = {};
|
|
1996
|
+
var axisObjects = getAxisObjects(data, layout);
|
|
1997
|
+
Object.keys(axisObjects).forEach(function (axId) {
|
|
1998
|
+
var ax = axisObjects[axId];
|
|
1999
|
+
if (!ax) {
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
var axType = getAxisType(data, axId[0], ax);
|
|
2003
|
+
if ((!ax.tickmode || ax.tickmode === 'array') && isArrayOrTypedArray(ax.tickvals)) {
|
|
2004
|
+
var tickValues = axType === 'date' ? ax.tickvals.map(function (v) { return new Date(v); }) : ax.tickvals;
|
|
2005
|
+
if (axId === 'x') {
|
|
2006
|
+
props.tickValues = tickValues;
|
|
2007
|
+
}
|
|
2008
|
+
else if (axId === 'y') {
|
|
2009
|
+
props.yAxisTickValues = tickValues;
|
|
2010
|
+
}
|
|
2011
|
+
return;
|
|
2012
|
+
}
|
|
2013
|
+
if ((!ax.tickmode || ax.tickmode === 'linear') && ax.dtick) {
|
|
2014
|
+
var dtick = plotlyDtick(ax.dtick, axType);
|
|
2015
|
+
var tick0 = plotlyTick0(ax.tick0, axType, dtick);
|
|
2016
|
+
if (axId === 'x') {
|
|
2017
|
+
props.xAxis = {
|
|
2018
|
+
tickStep: dtick,
|
|
2019
|
+
tick0: tick0,
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
else if (axId === 'y') {
|
|
2023
|
+
props.yAxis = {
|
|
2024
|
+
tickStep: dtick,
|
|
2025
|
+
tick0: tick0,
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
return;
|
|
2029
|
+
}
|
|
2030
|
+
if ((!ax.tickmode || ax.tickmode === 'auto') && typeof ax.nticks === 'number' && ax.nticks >= 0) {
|
|
2031
|
+
if (axId === 'x') {
|
|
2032
|
+
props.xAxisTickCount = ax.nticks;
|
|
2033
|
+
}
|
|
2034
|
+
else if (axId === 'y') {
|
|
2035
|
+
props.yAxisTickCount = ax.nticks;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
return props;
|
|
2040
|
+
};
|
|
2041
|
+
/**
|
|
2042
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L16}
|
|
2043
|
+
*/
|
|
2044
|
+
var plotlyDtick = function (dtick, axType) {
|
|
2045
|
+
var isLogAx = axType === 'log';
|
|
2046
|
+
var isDateAx = axType === 'date';
|
|
2047
|
+
var isCatAx = axType === 'category';
|
|
2048
|
+
var dtickDflt = isDateAx ? 86400000 : 1;
|
|
2049
|
+
if (!dtick) {
|
|
2050
|
+
return dtickDflt;
|
|
2051
|
+
}
|
|
2052
|
+
if (isNumber(dtick)) {
|
|
2053
|
+
dtick = Number(dtick);
|
|
2054
|
+
if (dtick <= 0) {
|
|
2055
|
+
return dtickDflt;
|
|
2056
|
+
}
|
|
2057
|
+
if (isCatAx) {
|
|
2058
|
+
// category dtick must be positive integers
|
|
2059
|
+
return Math.max(1, Math.round(dtick));
|
|
2060
|
+
}
|
|
2061
|
+
if (isDateAx) {
|
|
2062
|
+
// date dtick must be at least 0.1ms (our current precision)
|
|
2063
|
+
return Math.max(0.1, dtick);
|
|
2064
|
+
}
|
|
2065
|
+
return dtick;
|
|
2066
|
+
}
|
|
2067
|
+
if (typeof dtick !== 'string' || !(isDateAx || isLogAx)) {
|
|
2068
|
+
return dtickDflt;
|
|
2069
|
+
}
|
|
2070
|
+
var prefix = dtick.charAt(0);
|
|
2071
|
+
var dtickNum = isNumber(dtick.slice(1)) ? Number(dtick.slice(1)) : 0;
|
|
2072
|
+
if (dtickNum <= 0 ||
|
|
2073
|
+
!(
|
|
2074
|
+
// "M<n>" gives ticks every (integer) n months
|
|
2075
|
+
((isDateAx && prefix === 'M' && dtickNum === Math.round(dtickNum)) ||
|
|
2076
|
+
// "L<f>" gives ticks linearly spaced in data (not in position) every (float) f
|
|
2077
|
+
(isLogAx && prefix === 'L') ||
|
|
2078
|
+
// "D1" gives powers of 10 with all small digits between, "D2" gives only 2 and 5
|
|
2079
|
+
(isLogAx && prefix === 'D' && (dtickNum === 1 || dtickNum === 2))))) {
|
|
2080
|
+
return dtickDflt;
|
|
2081
|
+
}
|
|
2082
|
+
return dtick;
|
|
2083
|
+
};
|
|
2084
|
+
/**
|
|
2085
|
+
* @see {@link https://github.com/plotly/plotly.js/blob/master/src/plots/cartesian/clean_ticks.js#L70}
|
|
2086
|
+
*/
|
|
2087
|
+
var plotlyTick0 = function (tick0, axType, dtick) {
|
|
2088
|
+
if (axType === 'date') {
|
|
2089
|
+
return isDate(tick0) ? new Date(tick0) : new Date(DEFAULT_DATE_STRING);
|
|
2090
|
+
}
|
|
2091
|
+
if (dtick === 'D1' || dtick === 'D2') {
|
|
2092
|
+
// D1 and D2 modes ignore tick0 entirely
|
|
2093
|
+
return undefined;
|
|
2094
|
+
}
|
|
2095
|
+
// Aside from date axes, tick0 must be numeric
|
|
2096
|
+
return isNumber(tick0) ? Number(tick0) : 0;
|
|
2097
|
+
};
|
|
2098
|
+
var getAxisObjects = function (data, layout) {
|
|
1955
2099
|
// Traces are grouped by their xaxis property, and for each group/subplot, the adapter functions
|
|
1956
2100
|
// are called with the corresponding filtered data. As a result, all traces passed to an adapter
|
|
1957
2101
|
// function share the same xaxis.
|
|
@@ -1962,21 +2106,43 @@ var getAxisScaleTypeProps = function (data, layout) {
|
|
|
1962
2106
|
xAxisId = axisIds.x;
|
|
1963
2107
|
yAxisIds.add(axisIds.y);
|
|
1964
2108
|
});
|
|
1965
|
-
var
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
return ((_a = layout === null || layout === void 0 ? void 0 : layout[axisKey]) === null || _a === void 0 ? void 0 : _a.type) === 'log';
|
|
1969
|
-
};
|
|
1970
|
-
if (typeof xAxisId === 'number' && isLogAxis('x', xAxisId)) {
|
|
1971
|
-
result.xScaleType = 'log';
|
|
2109
|
+
var axisObjects = {};
|
|
2110
|
+
if (typeof xAxisId === 'number') {
|
|
2111
|
+
axisObjects.x = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('x', xAxisId)];
|
|
1972
2112
|
}
|
|
1973
2113
|
var sortedYAxisIds = Array.from(yAxisIds).sort();
|
|
1974
|
-
if (sortedYAxisIds.length > 0
|
|
1975
|
-
|
|
2114
|
+
if (sortedYAxisIds.length > 0) {
|
|
2115
|
+
axisObjects.y = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('y', sortedYAxisIds[0])];
|
|
1976
2116
|
}
|
|
1977
|
-
if (sortedYAxisIds.length > 1
|
|
1978
|
-
|
|
2117
|
+
if (sortedYAxisIds.length > 1) {
|
|
2118
|
+
axisObjects.y2 = layout === null || layout === void 0 ? void 0 : layout[getAxisKey('y', sortedYAxisIds[1])];
|
|
2119
|
+
}
|
|
2120
|
+
return axisObjects;
|
|
2121
|
+
};
|
|
2122
|
+
var getAxisType = function (data, axLetter, ax) {
|
|
2123
|
+
var values = [];
|
|
2124
|
+
data.forEach(function (series) {
|
|
2125
|
+
var _a;
|
|
2126
|
+
(_a = series[axLetter]) === null || _a === void 0 ? void 0 : _a.forEach(function (val) {
|
|
2127
|
+
if (!isInvalidValue(val)) {
|
|
2128
|
+
values.push(val);
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2131
|
+
});
|
|
2132
|
+
// Note: When ax.type is explicitly specified, Plotly casts the values to match that type.
|
|
2133
|
+
// Therefore, simply checking the type of the values may not be sufficient. At the moment,
|
|
2134
|
+
// we don’t always perform this casting ourselves and instead use the values as provided.
|
|
2135
|
+
if (isNumberArray(values)) {
|
|
2136
|
+
if ((ax === null || ax === void 0 ? void 0 : ax.type) === 'log') {
|
|
2137
|
+
return 'log';
|
|
2138
|
+
}
|
|
2139
|
+
return 'linear';
|
|
2140
|
+
}
|
|
2141
|
+
if (isDateArray(values)) {
|
|
2142
|
+
return 'date';
|
|
2143
|
+
}
|
|
2144
|
+
if (isStringArray(values)) {
|
|
2145
|
+
return 'category';
|
|
1979
2146
|
}
|
|
1980
|
-
return result;
|
|
1981
2147
|
};
|
|
1982
2148
|
//# sourceMappingURL=PlotlySchemaAdapter.js.map
|