@fluentui/react-charts 9.3.6 → 9.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/dist/index.d.ts +70 -17
- package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.js +2 -16
- package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.js.map +1 -1
- package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.types.js.map +1 -1
- package/lib/components/AreaChart/AreaChart.js +3 -43
- package/lib/components/AreaChart/AreaChart.js.map +1 -1
- package/lib/components/AreaChart/useAreaChartStyles.styles.js +1 -2
- package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib/components/ChartTable/ChartTable.js +8 -11
- package/lib/components/ChartTable/ChartTable.js.map +1 -1
- package/lib/components/ChartTable/ChartTable.types.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
- package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
- package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.js +52 -32
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/CommonComponents/ChartPopover.js +1 -2
- package/lib/components/CommonComponents/ChartPopover.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +9 -7
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +8 -5
- package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
- package/lib/components/CommonComponents/useChartPopoverStyles.styles.raw.js +0 -2
- package/lib/components/CommonComponents/useChartPopoverStyles.styles.raw.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +48 -25
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +309 -209
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +9 -15
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib/components/DonutChart/Pie/Pie.js +4 -2
- package/lib/components/DonutChart/Pie/Pie.js.map +1 -1
- package/lib/components/FunnelChart/FunnelChart.js +8 -13
- package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib/components/FunnelChart/FunnelChart.types.js.map +1 -1
- package/lib/components/GanttChart/GanttChart.js +4 -17
- package/lib/components/GanttChart/GanttChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.js +8 -13
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +24 -36
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +1 -2
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/HeatMapChart/HeatMapChart.js +3 -16
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +5 -25
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/Legends/Legends.js +3 -4
- package/lib/components/Legends/Legends.js.map +1 -1
- package/lib/components/Legends/Legends.types.js.map +1 -1
- package/lib/components/Legends/OverflowMenu.js.map +1 -1
- package/lib/components/Legends/useLegendsStyles.styles.raw.js.map +1 -1
- package/lib/components/LineChart/LineChart.js +68 -75
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/LineChart/LineChart.types.js +1 -1
- package/lib/components/LineChart/LineChart.types.js.map +1 -1
- package/lib/components/LineChart/eventAnnotation/EventAnnotation.js +3 -4
- package/lib/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -1
- package/lib/components/LineChart/useLineChartStyles.styles.js +1 -2
- package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js +4 -10
- package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -1
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +1 -2
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.js +41 -49
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -2
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib/components/Sparkline/Sparkline.js +11 -7
- package/lib/components/Sparkline/Sparkline.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +15 -92
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +1 -2
- package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +28 -49
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +1 -2
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib/types/ChartAnnotation.js.map +1 -1
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/Common.styles.js +0 -1
- package/lib/utilities/Common.styles.js.map +1 -1
- package/lib/utilities/Common.styles.raw.js +0 -1
- package/lib/utilities/Common.styles.raw.js.map +1 -1
- package/lib/utilities/FocusableTooltipText.js +1 -1
- package/lib/utilities/FocusableTooltipText.js.map +1 -1
- package/lib/utilities/getWindow.js +0 -1
- package/lib/utilities/getWindow.js.map +1 -1
- package/lib/utilities/hooks.js +34 -0
- package/lib/utilities/hooks.js.map +1 -0
- package/lib/utilities/image-export-utils.js +118 -78
- package/lib/utilities/image-export-utils.js.map +1 -1
- package/lib/utilities/utilities.js +243 -102
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.js +2 -16
- package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.js.map +1 -1
- package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.types.js.map +1 -1
- package/lib-commonjs/components/AreaChart/AreaChart.js +2 -41
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +0 -2
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ChartTable/ChartTable.js +9 -11
- package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -1
- package/lib-commonjs/components/ChartTable/ChartTable.types.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
- package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
- package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +51 -31
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/ChartPopover.js +1 -2
- package/lib-commonjs/components/CommonComponents/ChartPopover.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +7 -6
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +7 -4
- package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.raw.js +0 -2
- package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +48 -25
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +309 -208
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +7 -13
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Pie/Pie.js +4 -2
- package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/FunnelChart.js +7 -12
- package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/FunnelChart.types.js.map +1 -1
- package/lib-commonjs/components/GanttChart/GanttChart.js +3 -16
- package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js +7 -12
- package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +22 -34
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +2 -15
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +4 -23
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.js +3 -4
- package/lib-commonjs/components/Legends/Legends.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.types.js.map +1 -1
- package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -1
- package/lib-commonjs/components/Legends/useLegendsStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js +67 -74
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.types.js +1 -1
- package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
- package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js +2 -2
- package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -1
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +0 -2
- package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js +4 -10
- package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +0 -2
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +38 -46
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +0 -2
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/Sparkline/Sparkline.js +11 -7
- package/lib-commonjs/components/Sparkline/Sparkline.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +14 -91
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +26 -47
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +0 -2
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
- package/lib-commonjs/types/ChartAnnotation.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/Common.styles.js +0 -1
- package/lib-commonjs/utilities/Common.styles.js.map +1 -1
- package/lib-commonjs/utilities/Common.styles.raw.js +0 -1
- package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -1
- package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -1
- package/lib-commonjs/utilities/getWindow.js +0 -1
- package/lib-commonjs/utilities/getWindow.js.map +1 -1
- package/lib-commonjs/utilities/hooks.js +45 -0
- package/lib-commonjs/utilities/hooks.js.map +1 -0
- package/lib-commonjs/utilities/image-export-utils.js +119 -79
- package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +253 -101
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +9 -9
- package/lib/components/DeclarativeChart/imageExporter.js +0 -223
- package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
- package/lib-commonjs/components/DeclarativeChart/imageExporter.js +0 -233
- package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +0 -1
|
@@ -10,6 +10,9 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
+
CARTESIAN_XAXIS_CLASSNAME: function() {
|
|
14
|
+
return CARTESIAN_XAXIS_CLASSNAME;
|
|
15
|
+
},
|
|
13
16
|
ChartTypes: function() {
|
|
14
17
|
return ChartTypes;
|
|
15
18
|
},
|
|
@@ -49,6 +52,9 @@ _export(exports, {
|
|
|
49
52
|
areArraysEqual: function() {
|
|
50
53
|
return areArraysEqual;
|
|
51
54
|
},
|
|
55
|
+
autoLayoutXAxisLabels: function() {
|
|
56
|
+
return autoLayoutXAxisLabels;
|
|
57
|
+
},
|
|
52
58
|
calculateLongestLabelWidth: function() {
|
|
53
59
|
return calculateLongestLabelWidth;
|
|
54
60
|
},
|
|
@@ -67,9 +73,6 @@ _export(exports, {
|
|
|
67
73
|
createDateXAxis: function() {
|
|
68
74
|
return createDateXAxis;
|
|
69
75
|
},
|
|
70
|
-
createMeasurementSpan: function() {
|
|
71
|
-
return createMeasurementSpan;
|
|
72
|
-
},
|
|
73
76
|
createNumericXAxis: function() {
|
|
74
77
|
return createNumericXAxis;
|
|
75
78
|
},
|
|
@@ -175,6 +178,9 @@ _export(exports, {
|
|
|
175
178
|
getSecureProps: function() {
|
|
176
179
|
return getSecureProps;
|
|
177
180
|
},
|
|
181
|
+
getTextSize: function() {
|
|
182
|
+
return getTextSize;
|
|
183
|
+
},
|
|
178
184
|
getTypeOfAxis: function() {
|
|
179
185
|
return getTypeOfAxis;
|
|
180
186
|
},
|
|
@@ -202,6 +208,9 @@ _export(exports, {
|
|
|
202
208
|
isValidDomainValue: function() {
|
|
203
209
|
return isValidDomainValue;
|
|
204
210
|
},
|
|
211
|
+
measureTextWithDOM: function() {
|
|
212
|
+
return measureTextWithDOM;
|
|
213
|
+
},
|
|
205
214
|
pointTypes: function() {
|
|
206
215
|
return pointTypes;
|
|
207
216
|
},
|
|
@@ -252,6 +261,8 @@ const _chartutilities = require("@fluentui/chart-utilities");
|
|
|
252
261
|
const MIN_DOMAIN_MARGIN = 8;
|
|
253
262
|
const MIN_DONUT_RADIUS = 1;
|
|
254
263
|
const DEFAULT_DATE_STRING = '2000-01-01';
|
|
264
|
+
const CARTESIAN_XAXIS_CLASSNAME = 'fui-cart__xAxis';
|
|
265
|
+
const CARTESIAN_XAXIS_TEXT_SELECTOR = `.${CARTESIAN_XAXIS_CLASSNAME} text`;
|
|
255
266
|
var ChartTypes = /*#__PURE__*/ function(ChartTypes) {
|
|
256
267
|
ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
|
|
257
268
|
ChartTypes[ChartTypes["LineChart"] = 1] = "LineChart";
|
|
@@ -298,9 +309,13 @@ function defaultYAxisTickFormatter(value) {
|
|
|
298
309
|
}
|
|
299
310
|
function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleType, _useRtl) {
|
|
300
311
|
const { domainNRangeValues, showRoundOffXTickValues = false, xAxistickSize = 6, tickPadding = 10, xAxisCount, xAxisElement, hideTickOverlap, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
|
|
312
|
+
const dStartValue = domainNRangeValues.dStartValue;
|
|
313
|
+
const dEndValue = domainNRangeValues.dEndValue;
|
|
314
|
+
const finalXmin = xAxisParams.xMinValue !== undefined ? Math.min(dStartValue, xAxisParams.xMinValue) : dStartValue;
|
|
315
|
+
const finalXmax = xAxisParams.xMaxValue !== undefined ? Math.max(dEndValue, xAxisParams.xMaxValue) : dEndValue;
|
|
301
316
|
const xAxisScale = createNumericScale(scaleType).domain([
|
|
302
|
-
|
|
303
|
-
|
|
317
|
+
finalXmin,
|
|
318
|
+
finalXmax
|
|
304
319
|
]).range([
|
|
305
320
|
domainNRangeValues.rStartValue,
|
|
306
321
|
domainNRangeValues.rEndValue
|
|
@@ -317,7 +332,7 @@ function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleTy
|
|
|
317
332
|
const xAxisValue = typeof domainValue === 'number' ? domainValue : domainValue.valueOf();
|
|
318
333
|
return (defaultFormat === null || defaultFormat === void 0 ? void 0 : defaultFormat(xAxisValue)) === '' ? '' : (0, _chartutilities.formatToLocaleString)(xAxisValue, culture);
|
|
319
334
|
};
|
|
320
|
-
if (hideTickOverlap
|
|
335
|
+
if (hideTickOverlap) {
|
|
321
336
|
const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map((v, i)=>tickFormat(v, i))) + 20;
|
|
322
337
|
const [start, end] = xAxisScale.range();
|
|
323
338
|
tickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
|
|
@@ -341,10 +356,12 @@ function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleTy
|
|
|
341
356
|
if (xAxisElement) {
|
|
342
357
|
(0, _d3selection.select)(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true').style('direction', 'ltr').style('unicode-bidi', 'isolate');
|
|
343
358
|
}
|
|
344
|
-
const tickValues =
|
|
359
|
+
const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
|
|
360
|
+
const tickLabels = tickValues.map(xAxis.tickFormat());
|
|
345
361
|
return {
|
|
346
362
|
xScale: xAxisScale,
|
|
347
|
-
tickValues
|
|
363
|
+
tickValues,
|
|
364
|
+
tickLabels
|
|
348
365
|
};
|
|
349
366
|
}
|
|
350
367
|
/**
|
|
@@ -532,7 +549,7 @@ function getDateFormatLevel(date, useUTC) {
|
|
|
532
549
|
return (_matchedFormat_formatLevel = matchedFormat === null || matchedFormat === void 0 ? void 0 : matchedFormat.formatLevel) !== null && _matchedFormat_formatLevel !== void 0 ? _matchedFormat_formatLevel : 7;
|
|
533
550
|
}
|
|
534
551
|
function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLocale, customDateTimeFormatter, useUTC, chartType) {
|
|
535
|
-
const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
|
|
552
|
+
const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, hideTickOverlap, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
|
|
536
553
|
const isUtcSet = useUTC === true || useUTC === 'utc';
|
|
537
554
|
const xAxisScale = isUtcSet ? (0, _d3scale.scaleUtc)() : (0, _d3scale.scaleTime)();
|
|
538
555
|
xAxisScale.domain([
|
|
@@ -576,10 +593,11 @@ function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLo
|
|
|
576
593
|
}
|
|
577
594
|
return (0, _chartutilities.formatDateToLocaleString)(domainValue, culture, useUTC ? true : false, false, formatOptions);
|
|
578
595
|
};
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
596
|
+
if (hideTickOverlap) {
|
|
597
|
+
const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map(tickFormat)) + 40;
|
|
598
|
+
const [start, end] = xAxisScale.range();
|
|
599
|
+
tickCount = Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth));
|
|
600
|
+
}
|
|
583
601
|
const xAxis = (0, _d3axis.axisBottom)(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).ticks(tickCount).tickFormat(tickFormat);
|
|
584
602
|
if ([
|
|
585
603
|
8
|
|
@@ -598,10 +616,12 @@ function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLo
|
|
|
598
616
|
if (xAxisElement) {
|
|
599
617
|
(0, _d3selection.select)(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
|
|
600
618
|
}
|
|
601
|
-
const tickValues =
|
|
619
|
+
const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
|
|
620
|
+
const tickLabels = tickValues.map(xAxis.tickFormat());
|
|
602
621
|
return {
|
|
603
622
|
xScale: xAxisScale,
|
|
604
|
-
tickValues
|
|
623
|
+
tickValues,
|
|
624
|
+
tickLabels
|
|
605
625
|
};
|
|
606
626
|
}
|
|
607
627
|
function createStringXAxis(xAxisParams, tickParams, dataset, culture, _useRtl) {
|
|
@@ -650,7 +670,8 @@ function createStringXAxis(xAxisParams, tickParams, dataset, culture, _useRtl) {
|
|
|
650
670
|
}
|
|
651
671
|
return {
|
|
652
672
|
xScale: xAxisScale,
|
|
653
|
-
tickValues
|
|
673
|
+
tickValues,
|
|
674
|
+
tickLabels: tickValues.map(xAxis.tickFormat())
|
|
654
675
|
};
|
|
655
676
|
}
|
|
656
677
|
function useRtl() {
|
|
@@ -902,27 +923,24 @@ function calloutData(values) {
|
|
|
902
923
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
903
924
|
combinedResult.forEach((ele)=>{
|
|
904
925
|
const xValue = ele.x instanceof Date ? ele.x.getTime() : ele.x;
|
|
926
|
+
const newPoint = {
|
|
927
|
+
legend: ele.legend,
|
|
928
|
+
y: ele.y,
|
|
929
|
+
color: ele.color,
|
|
930
|
+
xAxisCalloutData: ele.xAxisCalloutData,
|
|
931
|
+
yAxisCalloutData: ele.yAxisCalloutData,
|
|
932
|
+
callOutAccessibilityData: ele.callOutAccessibilityData,
|
|
933
|
+
index: ele.index
|
|
934
|
+
};
|
|
905
935
|
if (xValue in xValToDataPoints) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
yAxisCalloutData: ele.yAxisCalloutData,
|
|
912
|
-
callOutAccessibilityData: ele.callOutAccessibilityData,
|
|
913
|
-
index: ele.index
|
|
914
|
-
});
|
|
936
|
+
// Check if a point with the same legend and y-value already exists
|
|
937
|
+
const existingPoint = xValToDataPoints[xValue].find((p)=>p.legend === newPoint.legend && p.y === newPoint.y);
|
|
938
|
+
if (!existingPoint) {
|
|
939
|
+
xValToDataPoints[xValue].push(newPoint);
|
|
940
|
+
}
|
|
915
941
|
} else {
|
|
916
942
|
xValToDataPoints[xValue] = [
|
|
917
|
-
|
|
918
|
-
legend: ele.legend,
|
|
919
|
-
y: ele.y,
|
|
920
|
-
color: ele.color,
|
|
921
|
-
xAxisCalloutData: ele.xAxisCalloutData,
|
|
922
|
-
yAxisCalloutData: ele.yAxisCalloutData,
|
|
923
|
-
callOutAccessibilityData: ele.callOutAccessibilityData,
|
|
924
|
-
index: ele.index
|
|
925
|
-
}
|
|
943
|
+
newPoint
|
|
926
944
|
];
|
|
927
945
|
}
|
|
928
946
|
});
|
|
@@ -948,14 +966,14 @@ function silceOrAppendToArray(array, value) {
|
|
|
948
966
|
}
|
|
949
967
|
const DEFAULT_WRAP_WIDTH = 10;
|
|
950
968
|
function createWrapOfXLabels(wrapLabelProps) {
|
|
951
|
-
const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH } = wrapLabelProps;
|
|
969
|
+
const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH, container } = wrapLabelProps;
|
|
952
970
|
if (node === null) {
|
|
953
971
|
return;
|
|
954
972
|
}
|
|
955
973
|
const axisNode = (0, _d3selection.select)(node).call(xAxis);
|
|
956
974
|
let removeVal = 0;
|
|
957
975
|
let maxLines = 1;
|
|
958
|
-
axisNode.selectAll('.tick text').each(function() {
|
|
976
|
+
axisNode.selectAll('.tick text').each(function(_, tickIndex) {
|
|
959
977
|
const text = (0, _d3selection.select)(this);
|
|
960
978
|
const totalWord = text.text();
|
|
961
979
|
const truncatedWord = `${text.text().slice(0, noOfCharsToTruncate)}...`;
|
|
@@ -967,33 +985,33 @@ function createWrapOfXLabels(wrapLabelProps) {
|
|
|
967
985
|
const lineHeight = 1.1; // ems
|
|
968
986
|
const y = text.attr('y');
|
|
969
987
|
const dy = parseFloat(text.attr('dy'));
|
|
970
|
-
let tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('
|
|
971
|
-
if (showXAxisLablesTooltip
|
|
972
|
-
tspan
|
|
973
|
-
} else if (showXAxisLablesTooltip && totalWordLength <= noOfCharsToTruncate) {
|
|
974
|
-
tspan = text.append('tspan').attr('id', 'LessLength').attr('x', 0).attr('y', y).attr('dy', dy + 'em').text(totalWord);
|
|
988
|
+
let tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', 0).attr('y', y).attr('dy', dy + 'em');
|
|
989
|
+
if (showXAxisLablesTooltip) {
|
|
990
|
+
tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
|
|
975
991
|
} else {
|
|
992
|
+
const maxWidth = Array.isArray(width) ? width[tickIndex] : width;
|
|
976
993
|
while(word = words.pop()){
|
|
977
994
|
line.push(word);
|
|
978
|
-
|
|
979
|
-
|
|
995
|
+
const label = line.join(' ');
|
|
996
|
+
tspan.text(label);
|
|
997
|
+
const labelWidth = getTextSize(label, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
|
|
998
|
+
if (labelWidth > maxWidth && line.length > 1) {
|
|
980
999
|
line.pop();
|
|
981
1000
|
tspan.text(line.join(' '));
|
|
982
1001
|
line = [
|
|
983
1002
|
word
|
|
984
1003
|
];
|
|
985
|
-
tspan = text.append('tspan').attr('
|
|
1004
|
+
tspan = text.append('tspan').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
|
|
986
1005
|
}
|
|
987
1006
|
}
|
|
988
1007
|
}
|
|
989
1008
|
maxLines = Math.max(maxLines, lineNumber + 1);
|
|
990
1009
|
});
|
|
991
1010
|
if (!showXAxisLablesTooltip) {
|
|
1011
|
+
var _querySelector;
|
|
992
1012
|
let maxHeight = 12; // intial value to render corretly first time
|
|
993
|
-
|
|
994
|
-
const
|
|
995
|
-
const BoxCordinates = outerHTMLElement && outerHTMLElement.getBoundingClientRect();
|
|
996
|
-
const boxHeight = BoxCordinates && BoxCordinates.height;
|
|
1013
|
+
var _querySelector_getBoundingClientRect_height;
|
|
1014
|
+
const boxHeight = (_querySelector_getBoundingClientRect_height = (_querySelector = (container !== null && container !== void 0 ? container : document).querySelector(`.${CARTESIAN_XAXIS_CLASSNAME} tspan`)) === null || _querySelector === void 0 ? void 0 : _querySelector.getBoundingClientRect().height) !== null && _querySelector_getBoundingClientRect_height !== void 0 ? _querySelector_getBoundingClientRect_height : 0;
|
|
997
1015
|
if (boxHeight > maxHeight) {
|
|
998
1016
|
maxHeight = boxHeight;
|
|
999
1017
|
}
|
|
@@ -1005,24 +1023,18 @@ function createYAxisLabels(node, yAxis, noOfCharsToTruncate, truncateLabel, isRt
|
|
|
1005
1023
|
if (node === null) {
|
|
1006
1024
|
return;
|
|
1007
1025
|
}
|
|
1008
|
-
let tickIndex = 0;
|
|
1009
1026
|
const axisNode = (0, _d3selection.select)(node).call(yAxis);
|
|
1010
1027
|
axisNode.selectAll('.tick text').each(function() {
|
|
1011
1028
|
const text = (0, _d3selection.select)(this);
|
|
1012
1029
|
const totalWord = text.text();
|
|
1013
1030
|
const truncatedWord = isRtl ? `...${text.text().slice(0, noOfCharsToTruncate)}` : `${text.text().slice(0, noOfCharsToTruncate)}...`;
|
|
1014
1031
|
const totalWordLength = text.text().length;
|
|
1015
|
-
const padding = 0; // ems
|
|
1016
1032
|
const y = text.attr('y');
|
|
1017
1033
|
const x = text.attr('x');
|
|
1018
1034
|
const dy = parseFloat(text.attr('dy'));
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
if (truncateLabel && totalWordLength > noOfCharsToTruncate) {
|
|
1023
|
-
text.append('tspan').attr('id', `showDots-${uid}`).attr('x', x).attr('y', y).attr('dy', dy + 'em').attr('dx', padding + dx + 'em').text(truncatedWord);
|
|
1024
|
-
} else {
|
|
1025
|
-
text.append('tspan').attr('id', `LessLength-${uid}`).attr('x', x).attr('y', y).attr('dx', padding + dx + 'em').text(totalWord);
|
|
1035
|
+
const tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', x).attr('y', y).attr('dy', dy + 'em');
|
|
1036
|
+
if (truncateLabel) {
|
|
1037
|
+
tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
|
|
1026
1038
|
}
|
|
1027
1039
|
});
|
|
1028
1040
|
}
|
|
@@ -1064,30 +1076,30 @@ const calculateLongestLabelWidth = (labels, query = 'none')=>{
|
|
|
1064
1076
|
return maxLabelWidth;
|
|
1065
1077
|
};
|
|
1066
1078
|
function tooltipOfAxislabels(axistooltipProps) {
|
|
1067
|
-
const { tooltipCls, axis, id } = axistooltipProps;
|
|
1079
|
+
const { tooltipCls, axis, id, container } = axistooltipProps;
|
|
1068
1080
|
if (axis === null) {
|
|
1069
1081
|
return null;
|
|
1070
1082
|
}
|
|
1071
|
-
const div = (0, _d3selection.select)('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
const tickObjectLength = tickObject && Object.keys(tickObject).length;
|
|
1081
|
-
for(let i = 0; i < tickObjectLength; i++){
|
|
1082
|
-
const d1 = tickObject[i];
|
|
1083
|
-
(0, _d3selection.select)(d1) // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1083
|
+
const div = (container ? (0, _d3selection.select)(container) : (0, _d3selection.select)('body')).append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
|
|
1084
|
+
axis.selectAll('.tick text').each(function() {
|
|
1085
|
+
const tickSelection = (0, _d3selection.select)(this);
|
|
1086
|
+
const fullLabel = tickSelection.attr('data-full');
|
|
1087
|
+
if (tickSelection.text() === fullLabel) {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
const tickEl = this;
|
|
1091
|
+
tickSelection // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1084
1092
|
.on('mouseover', (event, d)=>{
|
|
1085
|
-
|
|
1086
|
-
|
|
1093
|
+
const containerBounds = container === null || container === void 0 ? void 0 : container.getBoundingClientRect();
|
|
1094
|
+
const tickBounds = tickEl.getBoundingClientRect();
|
|
1095
|
+
const tooltipBottom = containerBounds ? containerBounds.bottom - (tickBounds.top - 4) : tickBounds.top - 4;
|
|
1096
|
+
var _containerBounds_left;
|
|
1097
|
+
const tooltipLeft = (tickBounds.left + tickBounds.right) / 2 - ((_containerBounds_left = containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.left) !== null && _containerBounds_left !== void 0 ? _containerBounds_left : 0);
|
|
1098
|
+
div.text(fullLabel).style('bottom', `${tooltipBottom}px`).style('left', `${tooltipLeft}px`).style('transform', 'translateX(-50%)').style('opacity', 0.9);
|
|
1087
1099
|
}).on('mouseout', (d)=>{
|
|
1088
1100
|
div.style('opacity', 0);
|
|
1089
1101
|
});
|
|
1090
|
-
}
|
|
1102
|
+
});
|
|
1091
1103
|
}
|
|
1092
1104
|
function getXAxisType(points) {
|
|
1093
1105
|
let isXAxisDateType = false;
|
|
@@ -1101,11 +1113,11 @@ function getXAxisType(points) {
|
|
|
1101
1113
|
}
|
|
1102
1114
|
return isXAxisDateType;
|
|
1103
1115
|
}
|
|
1104
|
-
function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode) {
|
|
1116
|
+
function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode, xMinVal, xMaxVal) {
|
|
1105
1117
|
const isScatterPolar = isScatterPolarSeries(points);
|
|
1106
1118
|
let [xMin, xMax] = getScatterXDomainExtent(points, scaleType);
|
|
1107
1119
|
if (hasMarkersMode) {
|
|
1108
|
-
const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType);
|
|
1120
|
+
const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType, xMinVal, xMaxVal);
|
|
1109
1121
|
xMin = xMin - xPadding.start;
|
|
1110
1122
|
xMax = xMax + xPadding.end;
|
|
1111
1123
|
}
|
|
@@ -1512,8 +1524,8 @@ function areArraysEqual(arr1, arr2) {
|
|
|
1512
1524
|
return true;
|
|
1513
1525
|
}
|
|
1514
1526
|
const cssVarRegExp = /var\((--[a-zA-Z0-9\-]+)\)/g;
|
|
1515
|
-
function resolveCSSVariables(
|
|
1516
|
-
const containerStyles = getComputedStyle(
|
|
1527
|
+
function resolveCSSVariables(container, styleRules) {
|
|
1528
|
+
const containerStyles = getComputedStyle(container);
|
|
1517
1529
|
return styleRules.replace(cssVarRegExp, (match, group1)=>{
|
|
1518
1530
|
return containerStyles.getPropertyValue(group1);
|
|
1519
1531
|
});
|
|
@@ -1613,11 +1625,6 @@ function copyStyle(properties, fromEl, toEl) {
|
|
|
1613
1625
|
});
|
|
1614
1626
|
}
|
|
1615
1627
|
}
|
|
1616
|
-
let measurementSpanCounter = 0;
|
|
1617
|
-
function getUniqueMeasurementSpanId() {
|
|
1618
|
-
measurementSpanCounter++;
|
|
1619
|
-
return `measurement_span_${measurementSpanCounter}`;
|
|
1620
|
-
}
|
|
1621
1628
|
const MEASUREMENT_SPAN_STYLE = {
|
|
1622
1629
|
position: 'absolute',
|
|
1623
1630
|
visibility: 'hidden',
|
|
@@ -1628,23 +1635,60 @@ const MEASUREMENT_SPAN_STYLE = {
|
|
|
1628
1635
|
border: 'none',
|
|
1629
1636
|
whiteSpace: 'pre'
|
|
1630
1637
|
};
|
|
1631
|
-
const
|
|
1632
|
-
|
|
1638
|
+
const MEASUREMENT_SPAN_ID = 'fui_measurement_span';
|
|
1639
|
+
const TEXT_STYLE_PROPERTIES = [
|
|
1640
|
+
'font-size',
|
|
1641
|
+
'font-family',
|
|
1642
|
+
'font-weight',
|
|
1643
|
+
'font-style',
|
|
1644
|
+
'letter-spacing',
|
|
1645
|
+
'text-transform'
|
|
1646
|
+
];
|
|
1647
|
+
const measureTextWithDOM = (text, cssSelector, container)=>{
|
|
1633
1648
|
let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
|
|
1634
1649
|
if (!measurementSpan) {
|
|
1635
1650
|
measurementSpan = document.createElement('span');
|
|
1636
1651
|
measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
|
|
1637
1652
|
measurementSpan.setAttribute('aria-hidden', 'true');
|
|
1638
|
-
|
|
1639
|
-
parentElement.appendChild(measurementSpan);
|
|
1640
|
-
} else {
|
|
1641
|
-
document.body.appendChild(measurementSpan);
|
|
1642
|
-
}
|
|
1653
|
+
(container !== null && container !== void 0 ? container : document.body).appendChild(measurementSpan);
|
|
1643
1654
|
}
|
|
1644
|
-
measurementSpan.setAttribute('class', className);
|
|
1645
1655
|
Object.assign(measurementSpan.style, MEASUREMENT_SPAN_STYLE);
|
|
1656
|
+
const refEl = (container !== null && container !== void 0 ? container : document).querySelector(cssSelector);
|
|
1657
|
+
if (refEl) {
|
|
1658
|
+
copyStyle(TEXT_STYLE_PROPERTIES, refEl, measurementSpan);
|
|
1659
|
+
}
|
|
1646
1660
|
measurementSpan.textContent = `${text}`;
|
|
1647
|
-
|
|
1661
|
+
const rect = measurementSpan.getBoundingClientRect();
|
|
1662
|
+
return {
|
|
1663
|
+
node: measurementSpan,
|
|
1664
|
+
width: rect.width,
|
|
1665
|
+
height: rect.height
|
|
1666
|
+
};
|
|
1667
|
+
};
|
|
1668
|
+
const CACHE_SIZE = 2000;
|
|
1669
|
+
const textSizeCache = new Map();
|
|
1670
|
+
const getTextSize = (text, cssSelector, container)=>{
|
|
1671
|
+
const cacheKey = `${text}|${cssSelector}`;
|
|
1672
|
+
const cachedResult = textSizeCache.get(cacheKey);
|
|
1673
|
+
if (cachedResult) {
|
|
1674
|
+
return cachedResult;
|
|
1675
|
+
}
|
|
1676
|
+
const { width, height } = measureTextWithDOM(text, cssSelector, container);
|
|
1677
|
+
// TODO: Improve cache eviction strategy if needed (e.g., LRU)
|
|
1678
|
+
if (textSizeCache.size >= CACHE_SIZE) {
|
|
1679
|
+
const firstKey = textSizeCache.keys().next().value;
|
|
1680
|
+
if (!(0, _chartutilities.isInvalidValue)(firstKey)) {
|
|
1681
|
+
textSizeCache.delete(firstKey);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
textSizeCache.set(cacheKey, {
|
|
1685
|
+
width,
|
|
1686
|
+
height
|
|
1687
|
+
});
|
|
1688
|
+
return {
|
|
1689
|
+
width,
|
|
1690
|
+
height
|
|
1691
|
+
};
|
|
1648
1692
|
};
|
|
1649
1693
|
function isScatterPolarSeries(points) {
|
|
1650
1694
|
return points.some((item)=>{
|
|
@@ -1666,17 +1710,26 @@ const createNumericScale = (scaleType)=>{
|
|
|
1666
1710
|
return (0, _d3scale.scaleLinear)();
|
|
1667
1711
|
}
|
|
1668
1712
|
};
|
|
1669
|
-
const getDomainPaddingForMarkers = (minVal, maxVal, scaleType)=>{
|
|
1713
|
+
const getDomainPaddingForMarkers = (minVal, maxVal, scaleType, userMinVal, userMaxVal)=>{
|
|
1670
1714
|
if (scaleType === 'log') {
|
|
1671
1715
|
return {
|
|
1672
1716
|
start: minVal * 0.5,
|
|
1673
1717
|
end: maxVal
|
|
1674
1718
|
};
|
|
1675
1719
|
}
|
|
1676
|
-
|
|
1720
|
+
/* if user explicitly sets userMinVal or userMaxVal, we will check that to avoid excessive padding on either side.
|
|
1721
|
+
If the difference between minVal and userMinVal is more than 10% of the data range, we set padding to 0 on that side.
|
|
1722
|
+
this is to avoid cases where userMinVal is significantly smaller than minVal or userMaxVal is significantly larger than
|
|
1723
|
+
maxVal, which would lead to excessive padding. In other cases, we apply the default 10% padding on both sides.
|
|
1724
|
+
*/ const rangePadding = (maxVal - minVal) * 0.1;
|
|
1725
|
+
// If explicit bounds are set and they're far from the data range, don't add extra padding
|
|
1726
|
+
const paddingAlreadySatisfiedAtMin = userMinVal !== undefined && rangePadding > Math.abs(minVal - Math.min(minVal, userMinVal));
|
|
1727
|
+
const paddingAlreadySatisfiedAtMax = userMaxVal !== undefined && rangePadding > Math.abs(maxVal - Math.max(maxVal, userMaxVal));
|
|
1728
|
+
const startPadding = paddingAlreadySatisfiedAtMin ? 0 : rangePadding;
|
|
1729
|
+
const endPadding = paddingAlreadySatisfiedAtMax ? 0 : rangePadding;
|
|
1677
1730
|
return {
|
|
1678
|
-
start:
|
|
1679
|
-
end:
|
|
1731
|
+
start: startPadding,
|
|
1732
|
+
end: endPadding
|
|
1680
1733
|
};
|
|
1681
1734
|
};
|
|
1682
1735
|
const isValidDomainValue = (value, scaleType)=>{
|
|
@@ -1700,7 +1753,7 @@ const getScatterXDomainExtent = (points, scaleType)=>{
|
|
|
1700
1753
|
xMax
|
|
1701
1754
|
];
|
|
1702
1755
|
};
|
|
1703
|
-
const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType })=>{
|
|
1756
|
+
const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType, xMinValue, xMaxValue, yMinValue, yMaxValue })=>{
|
|
1704
1757
|
// Note: This function is executed after the scale is created, so the actual padding can be
|
|
1705
1758
|
// obtained by calculating the difference between the respective minimums or maximums of the
|
|
1706
1759
|
// scale domain and the data. However, doing so often causes the marker size to scale up
|
|
@@ -1711,13 +1764,13 @@ const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecon
|
|
|
1711
1764
|
// it the other way around (i.e., adjusting the scale domain first with padding and then scaling
|
|
1712
1765
|
// the markers to fit inside the plot area).
|
|
1713
1766
|
const [xMin, xMax] = getScatterXDomainExtent(data, xScaleType);
|
|
1714
|
-
const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType);
|
|
1767
|
+
const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType, xMinValue, xMaxValue);
|
|
1715
1768
|
const scaleXMin = xMin instanceof Date ? new Date(+xMin - xPadding.start) : xMin - xPadding.start;
|
|
1716
1769
|
const scaleXMax = xMax instanceof Date ? new Date(+xMax + xPadding.end) : xMax + xPadding.end;
|
|
1717
1770
|
const extraXPixels = Math.min(Math.abs(xScale(xMin) - xScale(scaleXMin)), Math.abs(xScale(scaleXMax) - xScale(xMax)));
|
|
1718
1771
|
const yScaleType = useSecondaryYScale ? secondaryYScaleType : primaryYScaleType;
|
|
1719
1772
|
const { startValue: yMin, endValue: yMax } = findNumericMinMaxOfY(data, undefined, useSecondaryYScale, yScaleType);
|
|
1720
|
-
const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType);
|
|
1773
|
+
const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType, yMinValue, yMaxValue);
|
|
1721
1774
|
const scaleYMin = yMin - yPadding.start;
|
|
1722
1775
|
const scaleYMax = yMax + yPadding.end;
|
|
1723
1776
|
const yScale = useSecondaryYScale ? yScaleSecondary : yScalePrimary;
|
|
@@ -1769,7 +1822,7 @@ const generateNumericTicks = (scaleType, tickStep, tick0, scaleDomain)=>{
|
|
|
1769
1822
|
const refTick = typeof tick0 === 'number' ? tick0 : 0;
|
|
1770
1823
|
if (scaleType === 'log') {
|
|
1771
1824
|
if (typeof tickStep === 'number' && tickStep > 0) {
|
|
1772
|
-
return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>
|
|
1825
|
+
return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>10 ** t);
|
|
1773
1826
|
}
|
|
1774
1827
|
if (typeof tickStep === 'string') {
|
|
1775
1828
|
const prefix = tickStep[0];
|
|
@@ -1816,7 +1869,7 @@ function calculatePrecision(value) {
|
|
|
1816
1869
|
return 0;
|
|
1817
1870
|
}
|
|
1818
1871
|
function precisionRound(value, precision, base = 10) {
|
|
1819
|
-
const exp =
|
|
1872
|
+
const exp = base ** precision;
|
|
1820
1873
|
return Math.round(value * exp) / exp;
|
|
1821
1874
|
}
|
|
1822
1875
|
const findCalloutPoints = (calloutPointsByX, x)=>{
|
|
@@ -1832,3 +1885,102 @@ const findCalloutPoints = (calloutPointsByX, x)=>{
|
|
|
1832
1885
|
values: calloutPointsByX[key]
|
|
1833
1886
|
};
|
|
1834
1887
|
};
|
|
1888
|
+
const autoLayoutXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
|
|
1889
|
+
let requiresWrap = false;
|
|
1890
|
+
let requiresTruncate = false;
|
|
1891
|
+
const maxWidths = [];
|
|
1892
|
+
const [rangeStart, rangeEnd] = scale.range();
|
|
1893
|
+
const isRTL = rangeEnd - rangeStart < 0;
|
|
1894
|
+
const start = isRTL ? containerWidth : 0;
|
|
1895
|
+
const end = isRTL ? 0 : containerWidth;
|
|
1896
|
+
const getTickPosition = (index)=>{
|
|
1897
|
+
var _scale;
|
|
1898
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1899
|
+
return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
|
|
1900
|
+
};
|
|
1901
|
+
const getLabelWidth = (text)=>{
|
|
1902
|
+
return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
|
|
1903
|
+
};
|
|
1904
|
+
for(let i = 0; i < tickValues.length; i++){
|
|
1905
|
+
const position = getTickPosition(i);
|
|
1906
|
+
const leftSpace = Math.abs(i > 0 ? (position - getTickPosition(i - 1)) / 2 : position - start);
|
|
1907
|
+
const rightSpace = Math.abs(i + 1 < tickValues.length ? (getTickPosition(i + 1) - position) / 2 : end - position);
|
|
1908
|
+
const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
|
|
1909
|
+
const label = tickLabels[i];
|
|
1910
|
+
const labelWidth = getLabelWidth(label);
|
|
1911
|
+
maxWidths.push(maxAvailableWidth);
|
|
1912
|
+
if (labelWidth > maxAvailableWidth) {
|
|
1913
|
+
const longestWordWidth = Math.max(...label.split(/\s+/).map((word)=>getLabelWidth(word)));
|
|
1914
|
+
if (longestWordWidth <= maxAvailableWidth) {
|
|
1915
|
+
requiresWrap = true;
|
|
1916
|
+
} else {
|
|
1917
|
+
requiresTruncate = true;
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
if (requiresTruncate) {
|
|
1922
|
+
return truncateAndStaggerXAxisLabels(tickValues, tickLabels, scale, axisNode, containerWidth, container);
|
|
1923
|
+
}
|
|
1924
|
+
if (requiresWrap) {
|
|
1925
|
+
var _createWrapOfXLabels;
|
|
1926
|
+
return (_createWrapOfXLabels = createWrapOfXLabels({
|
|
1927
|
+
node: axisNode,
|
|
1928
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1929
|
+
xAxis: scale,
|
|
1930
|
+
noOfCharsToTruncate: 100,
|
|
1931
|
+
showXAxisLablesTooltip: false,
|
|
1932
|
+
width: maxWidths,
|
|
1933
|
+
container
|
|
1934
|
+
})) !== null && _createWrapOfXLabels !== void 0 ? _createWrapOfXLabels : 0;
|
|
1935
|
+
}
|
|
1936
|
+
return 0;
|
|
1937
|
+
};
|
|
1938
|
+
const truncateAndStaggerXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
|
|
1939
|
+
if (!axisNode) {
|
|
1940
|
+
return 0;
|
|
1941
|
+
}
|
|
1942
|
+
let maxHeight = 12;
|
|
1943
|
+
const [rangeStart, rangeEnd] = scale.range();
|
|
1944
|
+
const isRTL = rangeEnd - rangeStart < 0;
|
|
1945
|
+
const start = isRTL ? containerWidth : 0;
|
|
1946
|
+
const end = isRTL ? 0 : containerWidth;
|
|
1947
|
+
const getTickPosition = (index)=>{
|
|
1948
|
+
var _scale;
|
|
1949
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1950
|
+
return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
|
|
1951
|
+
};
|
|
1952
|
+
const getLabelSize = (text)=>{
|
|
1953
|
+
return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container);
|
|
1954
|
+
};
|
|
1955
|
+
(0, _d3selection.select)(axisNode).selectAll('.tick text').each(function(_, i) {
|
|
1956
|
+
const position = getTickPosition(i);
|
|
1957
|
+
const leftSpace = Math.abs(i > 0 ? position - getTickPosition(i - 1) : position - start);
|
|
1958
|
+
const rightSpace = Math.abs(i + 1 < tickValues.length ? getTickPosition(i + 1) - position : end - position);
|
|
1959
|
+
const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
|
|
1960
|
+
const label = tickLabels[i];
|
|
1961
|
+
const textNode = (0, _d3selection.select)(this).text(null).attr('data-full', label);
|
|
1962
|
+
const lineHeight = 1.1; // ems
|
|
1963
|
+
const y = textNode.attr('y');
|
|
1964
|
+
const dy = parseFloat(textNode.attr('dy'));
|
|
1965
|
+
textNode.append('tspan').attr('x', 0).attr('y', y).attr('dy', (i % 2 === 1 ? lineHeight : 0) + dy + 'em').text(truncateTextToFitWidth(label, maxAvailableWidth, (s)=>getLabelSize(s).width));
|
|
1966
|
+
maxHeight = Math.max(maxHeight, getLabelSize(label).height);
|
|
1967
|
+
});
|
|
1968
|
+
return tickValues.length > 1 ? maxHeight : 0;
|
|
1969
|
+
};
|
|
1970
|
+
const truncateTextToFitWidth = (text, maxWidth, measure)=>{
|
|
1971
|
+
if (measure(text) <= maxWidth) {
|
|
1972
|
+
return text;
|
|
1973
|
+
}
|
|
1974
|
+
let lo = 1;
|
|
1975
|
+
let hi = text.length;
|
|
1976
|
+
while(lo < hi){
|
|
1977
|
+
const mid = Math.floor((lo + hi + 1) / 2);
|
|
1978
|
+
const candidate = text.slice(0, mid) + '...';
|
|
1979
|
+
if (measure(candidate) <= maxWidth) {
|
|
1980
|
+
lo = mid;
|
|
1981
|
+
} else {
|
|
1982
|
+
hi = mid - 1;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
return text.slice(0, lo) + '...';
|
|
1986
|
+
};
|