@oliasoft-open-source/charts-library 5.1.0-beta-2 → 5.1.1-beta-1
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/dist/assets/{Color-YHDXOIA2-D9Cia5uO.js → Color-YHDXOIA2-5z3jgZVm.js} +1 -1
- package/dist/assets/{DocsRenderer-CFRXHY34-RPivBaWZ.js → DocsRenderer-CFRXHY34-kllrABNG.js} +3 -3
- package/dist/assets/{bar-chart.stories-DD1doofU.js → bar-chart.stories-C41de-ei.js} +1 -1
- package/dist/assets/{entry-preview-DrryAtE6.js → entry-preview-CRpTrA4o.js} +1 -1
- package/dist/assets/{get-draggableData-BDTcKxjB.js → get-draggableData-DPTQjrFS.js} +1 -1
- package/dist/assets/{iframe-CCbgehcE.js → iframe-C-Hu4-p_.js} +2 -2
- package/dist/assets/{legend-Of-Day88.js → legend-D-2OZtHn.js} +1 -1
- package/dist/assets/{legend-context-OK1TDQFW.js → legend-context-BDAlvkJS.js} +18 -18
- package/dist/assets/line-chart-DzPga9dx.js +1 -0
- package/dist/assets/{line-chart.stories-6YX4JB6B.js → line-chart.stories-CiRQ1HrN.js} +16 -13
- package/dist/assets/line-chart.test-case.stories-eW80_Tfk.js +430 -0
- package/dist/assets/{pie-chart.stories-D5_SOX3x.js → pie-chart.stories-CUYoikIz.js} +1 -1
- package/dist/assets/{preview-SqXleN6T.js → preview-BDL2yiRB.js} +2 -2
- package/dist/assets/{preview-CFlSBN9G.js → preview-D-26k3nY.js} +1 -1
- package/dist/assets/{scatter-chart.stories-_rMLva_h.js → scatter-chart.stories--WaN2oN8.js} +1 -1
- package/dist/bar-chart/utils/use-bar-chart-options.d.ts +1 -1
- package/dist/common/helpers/chart-utils.d.ts +1 -1
- package/dist/common/plugins/ellipsis-annotation-plugin/compute-ellipse-geometry.d.ts +9 -0
- package/dist/common/plugins/ellipsis-annotation-plugin/ellipsis-annotation-plugin.d.ts +14 -1
- package/dist/iframe.html +1 -1
- package/dist/index.js.js +202 -236
- package/dist/index.js.js.map +1 -1
- package/dist/index.json +1 -1
- package/dist/line-chart/hooks/use-chart-options.d.ts +2 -2
- package/dist/line-chart/hooks/use-chart-state.d.ts +1 -5
- package/dist/line-chart/utils/axis-scales/axis-scales.d.ts +1 -3
- package/dist/line-chart/utils/datalabels-alignment/get-alignment-data.d.ts +1 -1
- package/dist/line-chart/utils/get-axes-data-from-metasets.d.ts +1 -1
- package/dist/line-chart/utils/get-line-chart-data-labels.d.ts +0 -3
- package/dist/line-chart/utils/get-line-chart-tooltips.d.ts +14 -0
- package/dist/project.json +1 -1
- package/dist/scatter-chart/hooks/use-scatter-chart-config.d.ts +1 -1
- package/dist/src/components/bar-chart/utils/use-bar-chart-options.d.ts +1 -1
- package/dist/src/components/common/helpers/chart-utils.d.ts +1 -1
- package/dist/src/components/common/plugins/ellipsis-annotation-plugin/compute-ellipse-geometry.d.ts +9 -0
- package/dist/src/components/common/plugins/ellipsis-annotation-plugin/ellipsis-annotation-plugin.d.ts +14 -1
- package/dist/src/components/line-chart/hooks/use-chart-options.d.ts +2 -2
- package/dist/src/components/line-chart/hooks/use-chart-state.d.ts +1 -5
- package/dist/src/components/line-chart/utils/axis-scales/axis-scales.d.ts +1 -3
- package/dist/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.d.ts +1 -1
- package/dist/src/components/line-chart/utils/get-axes-data-from-metasets.d.ts +1 -1
- package/dist/src/components/line-chart/utils/get-line-chart-data-labels.d.ts +0 -3
- package/dist/src/components/line-chart/utils/get-line-chart-tooltips.d.ts +14 -0
- package/dist/src/components/scatter-chart/hooks/use-scatter-chart-config.d.ts +1 -1
- package/package.json +1 -1
- package/dist/assets/line-chart-BmREaqH4.js +0 -1
- package/dist/assets/line-chart.test-case.stories-BgFMDS-i.js +0 -428
package/dist/index.js.js
CHANGED
|
@@ -22426,17 +22426,17 @@ const HTML5Backend = function createBackend(manager, context, options) {
|
|
|
22426
22426
|
};
|
|
22427
22427
|
const MINOR_TICKS_PER_MAJOR = 10;
|
|
22428
22428
|
const getLargestMajorTickWidth = (majorTickPositions) => {
|
|
22429
|
-
return majorTickPositions.reduce(
|
|
22429
|
+
return majorTickPositions == null ? void 0 : majorTickPositions.reduce(
|
|
22430
22430
|
(acc, curr, index2) => {
|
|
22431
22431
|
if (index2 === 0) return acc;
|
|
22432
|
-
const gap = Math.abs(curr - majorTickPositions[index2 - 1]);
|
|
22432
|
+
const gap = Math.abs(curr - (majorTickPositions == null ? void 0 : majorTickPositions[index2 - 1]));
|
|
22433
22433
|
return Math.max(gap, acc);
|
|
22434
22434
|
},
|
|
22435
22435
|
0
|
|
22436
22436
|
);
|
|
22437
22437
|
};
|
|
22438
22438
|
const isValidPosition = (minorTickPosition, majorTickPositions, scale) => {
|
|
22439
|
-
const { axis, left: left2, top: top2, right: right2, bottom: bottom2 } = scale;
|
|
22439
|
+
const { axis, left: left2, top: top2, right: right2, bottom: bottom2 } = scale ?? {};
|
|
22440
22440
|
const isHorizontal = axis === "x";
|
|
22441
22441
|
const start = isHorizontal ? left2 : top2;
|
|
22442
22442
|
const end = isHorizontal ? right2 : bottom2;
|
|
@@ -22446,52 +22446,56 @@ const isValidPosition = (minorTickPosition, majorTickPositions, scale) => {
|
|
|
22446
22446
|
return isAfterStart && isBeforeEnd && !isDuplicate;
|
|
22447
22447
|
};
|
|
22448
22448
|
const getMinorTickPositions = (majorTickPositions, scale) => {
|
|
22449
|
-
|
|
22449
|
+
var _a2, _b2;
|
|
22450
|
+
const sortedMajorTickPositions = majorTickPositions == null ? void 0 : majorTickPositions.sort((a2, b2) => {
|
|
22450
22451
|
return a2 - b2;
|
|
22451
22452
|
});
|
|
22452
22453
|
const minorTickWidth = getLargestMajorTickWidth(majorTickPositions) / 10;
|
|
22453
22454
|
const startPosition = majorTickPositions[0];
|
|
22454
22455
|
const numMinorTicks = (majorTickPositions.length + 1) * MINOR_TICKS_PER_MAJOR;
|
|
22455
|
-
const positions2 = [...Array(numMinorTicks)].map((_2, index2) => {
|
|
22456
|
+
const positions2 = (_b2 = (_a2 = [...Array(numMinorTicks)]) == null ? void 0 : _a2.map((_2, index2) => {
|
|
22456
22457
|
const minorTickPosition = startPosition + (index2 - MINOR_TICKS_PER_MAJOR + 1) * minorTickWidth;
|
|
22457
|
-
return parseFloat(minorTickPosition.toFixed(1));
|
|
22458
|
-
}).filter(
|
|
22458
|
+
return parseFloat(minorTickPosition == null ? void 0 : minorTickPosition.toFixed(1));
|
|
22459
|
+
})) == null ? void 0 : _b2.filter(
|
|
22459
22460
|
(position) => isValidPosition(position, sortedMajorTickPositions, scale)
|
|
22460
22461
|
);
|
|
22461
22462
|
return positions2;
|
|
22462
22463
|
};
|
|
22463
22464
|
const drawMinorTicksForScale = (scale) => {
|
|
22464
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
|
|
22465
|
-
const { chart: chart2, ctx } = scale;
|
|
22466
|
-
|
|
22467
|
-
|
|
22468
|
-
if (config2.options.
|
|
22469
|
-
|
|
22470
|
-
const
|
|
22465
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
22466
|
+
const { chart: chart2, ctx } = scale ?? {};
|
|
22467
|
+
if (!ctx || (ctx == null ? void 0 : ctx.canvas) === null) return;
|
|
22468
|
+
const config2 = chart2 == null ? void 0 : chart2.config;
|
|
22469
|
+
if (!((_d2 = (_c2 = (_b2 = (_a2 = config2 == null ? void 0 : config2.options) == null ? void 0 : _a2.scales) == null ? void 0 : _b2[scale == null ? void 0 : scale.id]) == null ? void 0 : _c2.grid) == null ? void 0 : _d2.drawOnChartArea)) return;
|
|
22470
|
+
if (((_e2 = config2 == null ? void 0 : config2.options) == null ? void 0 : _e2.indexAxis) === (scale == null ? void 0 : scale.axis)) return;
|
|
22471
|
+
const isHorizontal = (scale == null ? void 0 : scale.axis) === "x";
|
|
22472
|
+
const majorTickPositions = (_g2 = (_f2 = scale == null ? void 0 : scale.ticks) == null ? void 0 : _f2.map((_2, index2) => scale == null ? void 0 : scale.getPixelForTick(index2))) == null ? void 0 : _g2.sort((a2, b2) => a2 - b2);
|
|
22471
22473
|
const minorTickPositions = getMinorTickPositions(majorTickPositions, scale);
|
|
22472
|
-
ctx.save();
|
|
22473
|
-
ctx.strokeStyle = ((
|
|
22474
|
+
(_h2 = ctx == null ? void 0 : ctx.save) == null ? void 0 : _h2.call(ctx);
|
|
22475
|
+
ctx.strokeStyle = ((_m2 = (_l2 = (_k2 = (_j2 = (_i2 = config2 == null ? void 0 : config2._config) == null ? void 0 : _i2.options) == null ? void 0 : _j2.scales) == null ? void 0 : _k2[scale.id]) == null ? void 0 : _l2.grid) == null ? void 0 : _m2.color) || "rgba(0,0,0,0.06)";
|
|
22474
22476
|
ctx.lineWidth = 0.5;
|
|
22475
|
-
minorTickPositions.forEach((minorTickPosition) => {
|
|
22477
|
+
minorTickPositions == null ? void 0 : minorTickPositions.forEach((minorTickPosition) => {
|
|
22478
|
+
var _a3, _b3, _c3, _d3, _e3;
|
|
22476
22479
|
ctx.beginPath();
|
|
22477
22480
|
if (isHorizontal) {
|
|
22478
|
-
const { top: top2, bottom: bottom2 } = chart2.chartArea;
|
|
22479
|
-
ctx.moveTo(minorTickPosition, top2);
|
|
22480
|
-
ctx.lineTo(minorTickPosition, bottom2);
|
|
22481
|
+
const { top: top2, bottom: bottom2 } = (chart2 == null ? void 0 : chart2.chartArea) ?? {};
|
|
22482
|
+
(_a3 = ctx == null ? void 0 : ctx.moveTo) == null ? void 0 : _a3.call(ctx, minorTickPosition, top2);
|
|
22483
|
+
(_b3 = ctx == null ? void 0 : ctx.lineTo) == null ? void 0 : _b3.call(ctx, minorTickPosition, bottom2);
|
|
22481
22484
|
} else {
|
|
22482
|
-
const { left: left2, right: right2 } = chart2.chartArea;
|
|
22483
|
-
ctx.moveTo(left2, minorTickPosition);
|
|
22484
|
-
ctx.lineTo(right2, minorTickPosition);
|
|
22485
|
+
const { left: left2, right: right2 } = (chart2 == null ? void 0 : chart2.chartArea) ?? {};
|
|
22486
|
+
(_c3 = ctx == null ? void 0 : ctx.moveTo) == null ? void 0 : _c3.call(ctx, left2, minorTickPosition);
|
|
22487
|
+
(_d3 = ctx == null ? void 0 : ctx.lineTo) == null ? void 0 : _d3.call(ctx, right2, minorTickPosition);
|
|
22485
22488
|
}
|
|
22486
|
-
ctx.stroke();
|
|
22489
|
+
(_e3 = ctx == null ? void 0 : ctx.stroke) == null ? void 0 : _e3.call(ctx);
|
|
22487
22490
|
});
|
|
22488
|
-
ctx.restore();
|
|
22491
|
+
(_n2 = ctx == null ? void 0 : ctx.restore) == null ? void 0 : _n2.call(ctx);
|
|
22489
22492
|
};
|
|
22490
22493
|
const chartMinorGridlinesPlugin = {
|
|
22491
22494
|
id: "minorGridlines",
|
|
22492
22495
|
beforeDatasetsDraw: (chart2) => {
|
|
22493
|
-
|
|
22494
|
-
|
|
22496
|
+
var _a2;
|
|
22497
|
+
const { scales } = chart2 ?? {};
|
|
22498
|
+
(_a2 = Object.keys(scales)) == null ? void 0 : _a2.forEach((id) => drawMinorTicksForScale(scales == null ? void 0 : scales[id]));
|
|
22495
22499
|
}
|
|
22496
22500
|
};
|
|
22497
22501
|
const BORDER_WIDTH = {
|
|
@@ -22649,23 +22653,23 @@ var Events = /* @__PURE__ */ ((Events2) => {
|
|
|
22649
22653
|
const chartAreaBorderPlugin = {
|
|
22650
22654
|
id: "chartAreaBorder",
|
|
22651
22655
|
beforeDraw(chart2, _2, options) {
|
|
22652
|
-
|
|
22653
|
-
|
|
22654
|
-
|
|
22655
|
-
} =
|
|
22656
|
-
ctx.save();
|
|
22657
|
-
ctx.strokeStyle = options.borderColor;
|
|
22658
|
-
ctx.lineWidth = options.borderWidth;
|
|
22659
|
-
ctx.setLineDash(options.borderDash || []);
|
|
22660
|
-
ctx.lineDashOffset = options.borderDashOffset ?? 0;
|
|
22661
|
-
ctx.strokeRect(left2, top2, width, height);
|
|
22662
|
-
ctx.restore();
|
|
22656
|
+
var _a2, _b2, _c2, _d2;
|
|
22657
|
+
if (!(chart2 == null ? void 0 : chart2.ctx) || !chart2.chartArea) return;
|
|
22658
|
+
const { ctx, chartArea } = chart2 ?? {};
|
|
22659
|
+
const { left: left2, top: top2, width, height } = chartArea ?? {};
|
|
22660
|
+
(_a2 = ctx == null ? void 0 : ctx.save) == null ? void 0 : _a2.call(ctx);
|
|
22661
|
+
ctx.strokeStyle = options == null ? void 0 : options.borderColor;
|
|
22662
|
+
ctx.lineWidth = options == null ? void 0 : options.borderWidth;
|
|
22663
|
+
(_b2 = ctx == null ? void 0 : ctx.setLineDash) == null ? void 0 : _b2.call(ctx, (options == null ? void 0 : options.borderDash) || []);
|
|
22664
|
+
ctx.lineDashOffset = (options == null ? void 0 : options.borderDashOffset) ?? 0;
|
|
22665
|
+
(_c2 = ctx == null ? void 0 : ctx.strokeRect) == null ? void 0 : _c2.call(ctx, left2, top2, width, height);
|
|
22666
|
+
(_d2 = ctx == null ? void 0 : ctx.restore) == null ? void 0 : _d2.call(ctx);
|
|
22663
22667
|
}
|
|
22664
22668
|
};
|
|
22665
22669
|
const getPlugins = (graph, legend2) => {
|
|
22666
22670
|
var _a2;
|
|
22667
22671
|
let plugins = [];
|
|
22668
|
-
if (graph.showMinorGridlines) {
|
|
22672
|
+
if (graph == null ? void 0 : graph.showMinorGridlines) {
|
|
22669
22673
|
plugins.push(chartMinorGridlinesPlugin);
|
|
22670
22674
|
}
|
|
22671
22675
|
const customLegend = legend2 == null ? void 0 : legend2.customLegend;
|
|
@@ -22692,7 +22696,7 @@ const generateRandomColor = (colors2) => {
|
|
|
22692
22696
|
const getTitle = (options) => {
|
|
22693
22697
|
return options.title !== "" ? {
|
|
22694
22698
|
display: true,
|
|
22695
|
-
text: options.title
|
|
22699
|
+
text: (options == null ? void 0 : options.title) ?? ""
|
|
22696
22700
|
} : {};
|
|
22697
22701
|
};
|
|
22698
22702
|
const isVertical = (direction) => {
|
|
@@ -22709,14 +22713,14 @@ const getClassName = (chartStyling, styles2) => {
|
|
|
22709
22713
|
staticChartHeight = false,
|
|
22710
22714
|
squareAspectRatio: squareAspectRatio2 = 0
|
|
22711
22715
|
} = chartStyling;
|
|
22712
|
-
const squareAspectRatioStyle = squareAspectRatio2 ? styles2.squareAspectRatio : "";
|
|
22716
|
+
const squareAspectRatioStyle = squareAspectRatio2 ? styles2 == null ? void 0 : styles2.squareAspectRatio : "";
|
|
22713
22717
|
let heightStyles = "";
|
|
22714
22718
|
if (width || height) {
|
|
22715
22719
|
heightStyles = "";
|
|
22716
22720
|
} else {
|
|
22717
22721
|
heightStyles = staticChartHeight ? styles2 == null ? void 0 : styles2.fixedHeight : styles2 == null ? void 0 : styles2.stretchHeight;
|
|
22718
22722
|
}
|
|
22719
|
-
return cx(styles2.chart, heightStyles, squareAspectRatioStyle);
|
|
22723
|
+
return cx(styles2 == null ? void 0 : styles2.chart, heightStyles, squareAspectRatioStyle);
|
|
22720
22724
|
};
|
|
22721
22725
|
const getLegend = (options, clickHandler) => {
|
|
22722
22726
|
const { legend: legend2 } = options || {};
|
|
@@ -22739,13 +22743,14 @@ const getLegend = (options, clickHandler) => {
|
|
|
22739
22743
|
};
|
|
22740
22744
|
};
|
|
22741
22745
|
const afterLabelCallback = (tooltipItem) => {
|
|
22742
|
-
|
|
22746
|
+
var _a2, _b2;
|
|
22747
|
+
const { error = null } = ((_b2 = (_a2 = tooltipItem == null ? void 0 : tooltipItem.dataset) == null ? void 0 : _a2.data) == null ? void 0 : _b2[tooltipItem == null ? void 0 : tooltipItem.dataIndex]) ?? {};
|
|
22743
22748
|
return error ? `Error: ${round$2(error, 4)}` : "";
|
|
22744
22749
|
};
|
|
22745
22750
|
const getTooltipLabel = (tooltipItem, showLabelsInTooltips) => {
|
|
22746
22751
|
var _a2, _b2, _c2;
|
|
22747
22752
|
const datasetDataLabel = (_c2 = (_b2 = (_a2 = tooltipItem == null ? void 0 : tooltipItem.dataset) == null ? void 0 : _a2.data) == null ? void 0 : _b2[tooltipItem == null ? void 0 : tooltipItem.dataIndex]) == null ? void 0 : _c2.label;
|
|
22748
|
-
const dataLabel = Array.isArray(datasetDataLabel) ? datasetDataLabel.join(" , ") : datasetDataLabel;
|
|
22753
|
+
const dataLabel = Array.isArray(datasetDataLabel) ? datasetDataLabel == null ? void 0 : datasetDataLabel.join(" , ") : datasetDataLabel ?? "";
|
|
22749
22754
|
return showLabelsInTooltips && (dataLabel == null ? void 0 : dataLabel.length) ? ` (${dataLabel})` : "";
|
|
22750
22755
|
};
|
|
22751
22756
|
const sanitize = (str) => str.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
@@ -22761,19 +22766,30 @@ const setDefaultTheme = () => {
|
|
|
22761
22766
|
defaults$2.color = DEFAULT_COLOR;
|
|
22762
22767
|
defaults$2.borderColor = BORDER_COLOR;
|
|
22763
22768
|
};
|
|
22764
|
-
const isNilOrEmpty = (value) => {
|
|
22765
|
-
if (value === null || value === void 0 || value === "") {
|
|
22766
|
-
return true;
|
|
22767
|
-
}
|
|
22768
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
22769
|
-
return true;
|
|
22770
|
-
}
|
|
22771
|
-
if (typeof value === "object" && Object.keys(value).length === 0) {
|
|
22772
|
-
return true;
|
|
22773
|
-
}
|
|
22774
|
-
return false;
|
|
22775
|
-
};
|
|
22776
22769
|
const isEmptyString = (value) => value === "";
|
|
22770
|
+
const computeEllipseGeometry = (ellipsePoints, xScale, yScale) => {
|
|
22771
|
+
const [p1, p2] = ellipsePoints.major;
|
|
22772
|
+
const [p3, p4] = ellipsePoints.minor;
|
|
22773
|
+
const centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
|
|
22774
|
+
const centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
|
|
22775
|
+
const dx = p2.x - p1.x;
|
|
22776
|
+
const dy = p2.y - p1.y;
|
|
22777
|
+
const angle = Math.atan2(
|
|
22778
|
+
yScale.getPixelForValue(centerY + dy / 2) - yScale.getPixelForValue(centerY - dy / 2),
|
|
22779
|
+
xScale.getPixelForValue(centerX + dx / 2) - xScale.getPixelForValue(centerX - dx / 2)
|
|
22780
|
+
);
|
|
22781
|
+
const radiusX = Math.hypot(
|
|
22782
|
+
xScale.getPixelForValue(p1.x) - xScale.getPixelForValue(p2.x),
|
|
22783
|
+
yScale.getPixelForValue(p1.y) - yScale.getPixelForValue(p2.y)
|
|
22784
|
+
) / 2;
|
|
22785
|
+
const radiusY = Math.hypot(
|
|
22786
|
+
xScale.getPixelForValue(p3.x) - xScale.getPixelForValue(p4.x),
|
|
22787
|
+
yScale.getPixelForValue(p3.y) - yScale.getPixelForValue(p4.y)
|
|
22788
|
+
) / 2;
|
|
22789
|
+
const cx2 = xScale.getPixelForValue(centerX);
|
|
22790
|
+
const cy = yScale.getPixelForValue(centerY);
|
|
22791
|
+
return { cx: cx2, cy, radiusX, radiusY, angle };
|
|
22792
|
+
};
|
|
22777
22793
|
const ellipsisAnnotationPlugin = {
|
|
22778
22794
|
id: "ellipsisAnnotationPlugin",
|
|
22779
22795
|
afterDatasetsDraw(chart2) {
|
|
@@ -22798,26 +22814,11 @@ const ellipsisAnnotationPlugin = {
|
|
|
22798
22814
|
customDataset.data.forEach((item) => {
|
|
22799
22815
|
const { ellipsePoints } = item;
|
|
22800
22816
|
if (!ellipsePoints) return;
|
|
22801
|
-
const
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
|
|
22805
|
-
const dx = p2.x - p1.x;
|
|
22806
|
-
const dy = p2.y - p1.y;
|
|
22807
|
-
const angle = Math.atan2(
|
|
22808
|
-
yScale.getPixelForValue(centerY + dy / 2) - yScale.getPixelForValue(centerY - dy / 2),
|
|
22809
|
-
xScale.getPixelForValue(centerX + dx / 2) - xScale.getPixelForValue(centerX - dx / 2)
|
|
22817
|
+
const { cx: cx2, cy, radiusX, radiusY, angle } = computeEllipseGeometry(
|
|
22818
|
+
ellipsePoints,
|
|
22819
|
+
xScale,
|
|
22820
|
+
yScale
|
|
22810
22821
|
);
|
|
22811
|
-
const radiusX = Math.hypot(
|
|
22812
|
-
xScale.getPixelForValue(p1.x) - xScale.getPixelForValue(p2.x),
|
|
22813
|
-
yScale.getPixelForValue(p1.y) - yScale.getPixelForValue(p2.y)
|
|
22814
|
-
) / 2;
|
|
22815
|
-
const radiusY = Math.hypot(
|
|
22816
|
-
xScale.getPixelForValue(p3.x) - xScale.getPixelForValue(p4.x),
|
|
22817
|
-
yScale.getPixelForValue(p3.y) - yScale.getPixelForValue(p4.y)
|
|
22818
|
-
) / 2;
|
|
22819
|
-
const cx2 = xScale.getPixelForValue(centerX);
|
|
22820
|
-
const cy = yScale.getPixelForValue(centerY);
|
|
22821
22822
|
ctx.save();
|
|
22822
22823
|
ctx.beginPath();
|
|
22823
22824
|
ctx.ellipse(cx2, cy, radiusX, radiusY, angle, 0, 2 * Math.PI);
|
|
@@ -24385,10 +24386,6 @@ const generateKey = (values) => {
|
|
|
24385
24386
|
return key;
|
|
24386
24387
|
};
|
|
24387
24388
|
const isPrimitiveValue = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
|
|
24388
|
-
const isRangeValid = (r2) => {
|
|
24389
|
-
if (!r2) return false;
|
|
24390
|
-
return Object.values(r2).some((value) => !isNilOrEmpty(value));
|
|
24391
|
-
};
|
|
24392
24389
|
const useChartFunctions = ({
|
|
24393
24390
|
chartRef,
|
|
24394
24391
|
state,
|
|
@@ -24561,7 +24558,7 @@ const validateAxes = (axes) => {
|
|
|
24561
24558
|
);
|
|
24562
24559
|
return { errors, valid };
|
|
24563
24560
|
};
|
|
24564
|
-
const RANGE_GAP
|
|
24561
|
+
const RANGE_GAP = 1;
|
|
24565
24562
|
const getInitAxes = ({ chartRef, state }) => {
|
|
24566
24563
|
const chart2 = chartRef == null ? void 0 : chartRef.current;
|
|
24567
24564
|
if (!chart2) return [];
|
|
@@ -24571,9 +24568,9 @@ const getInitAxes = ({ chartRef, state }) => {
|
|
|
24571
24568
|
let adjustedMin = Number(min);
|
|
24572
24569
|
let adjustedMax = Number(max);
|
|
24573
24570
|
if (isNaN(adjustedMin)) adjustedMin = 0;
|
|
24574
|
-
if (isNaN(adjustedMax)) adjustedMax = adjustedMin + RANGE_GAP
|
|
24571
|
+
if (isNaN(adjustedMax)) adjustedMax = adjustedMin + RANGE_GAP;
|
|
24575
24572
|
if (adjustedMin === adjustedMax) {
|
|
24576
|
-
adjustedMax += RANGE_GAP
|
|
24573
|
+
adjustedMax += RANGE_GAP;
|
|
24577
24574
|
}
|
|
24578
24575
|
const { unit } = ((_a2 = state == null ? void 0 : state.axes) == null ? void 0 : _a2.find((axis) => axis.id === id)) ?? {};
|
|
24579
24576
|
return {
|
|
@@ -25074,7 +25071,7 @@ const getDefaultProps$3 = (props) => {
|
|
|
25074
25071
|
persistenceId: (chart2 == null ? void 0 : chart2.persistenceId) ?? "",
|
|
25075
25072
|
controlsPortalId: (chart2 == null ? void 0 : chart2.controlsPortalId) ?? "",
|
|
25076
25073
|
testId: (chart2 == null ? void 0 : chart2.testId) ?? void 0,
|
|
25077
|
-
data: chart2 == null ? void 0 : chart2.data,
|
|
25074
|
+
data: (chart2 == null ? void 0 : chart2.data) ?? { datasets: [] },
|
|
25078
25075
|
options: {
|
|
25079
25076
|
title: (options == null ? void 0 : options.title) ?? "",
|
|
25080
25077
|
scales: (options == null ? void 0 : options.scales) ?? {},
|
|
@@ -25232,29 +25229,6 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25232
25229
|
};
|
|
25233
25230
|
});
|
|
25234
25231
|
};
|
|
25235
|
-
const getAnnotationsData = (data) => {
|
|
25236
|
-
return data == null ? void 0 : data.reduce((acc, obj) => {
|
|
25237
|
-
return {
|
|
25238
|
-
...acc,
|
|
25239
|
-
[obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
|
|
25240
|
-
};
|
|
25241
|
-
}, {});
|
|
25242
|
-
};
|
|
25243
|
-
const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
|
|
25244
|
-
if (!chartRef || !chartRef.current) return null;
|
|
25245
|
-
const metasets = chartRef.current.getSortedVisibleDatasetMetas();
|
|
25246
|
-
const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
|
|
25247
|
-
let allData = [];
|
|
25248
|
-
metasets.forEach((metaset) => {
|
|
25249
|
-
const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
|
|
25250
|
-
allData = allData.concat(data);
|
|
25251
|
-
});
|
|
25252
|
-
allData = allData.concat(annotDataByType);
|
|
25253
|
-
if (allData.length === 0) return null;
|
|
25254
|
-
const min = Math.min(...allData);
|
|
25255
|
-
const max = Math.max(...allData);
|
|
25256
|
-
return { min, max };
|
|
25257
|
-
};
|
|
25258
25232
|
const calculateDelta$1 = (tickValue, ticks) => {
|
|
25259
25233
|
let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
|
|
25260
25234
|
if (Math.abs(delta) >= 1 && tickValue !== Math.floor(Number(tickValue))) {
|
|
@@ -25368,8 +25342,8 @@ const estimateDataSeriesHaveCloseValues = (generatedDatasets) => {
|
|
|
25368
25342
|
}
|
|
25369
25343
|
const axesFirstLast = generatedDatasets == null ? void 0 : generatedDatasets.reduce((acc, dataset) => {
|
|
25370
25344
|
var _a3, _b2, _c2, _d2;
|
|
25371
|
-
const xAxisId = (dataset == null ? void 0 : dataset.xAxisID) ?? "
|
|
25372
|
-
const yAxisId = (dataset == null ? void 0 : dataset.yAxisID) ?? "
|
|
25345
|
+
const xAxisId = (dataset == null ? void 0 : dataset.xAxisID) ?? "x";
|
|
25346
|
+
const yAxisId = (dataset == null ? void 0 : dataset.yAxisID) ?? "y";
|
|
25373
25347
|
const data = (dataset == null ? void 0 : dataset.data) ?? [];
|
|
25374
25348
|
if (data && (data == null ? void 0 : data.length)) {
|
|
25375
25349
|
const { x: xFirstCurrent, y: yFirstCurrent } = (data == null ? void 0 : data[0]) ?? {};
|
|
@@ -25448,21 +25422,35 @@ const getSuggestedAxisRange = ({
|
|
|
25448
25422
|
max: round$2(maxAxisValue, DECIMAL_POINT_TOLERANCE)
|
|
25449
25423
|
};
|
|
25450
25424
|
};
|
|
25451
|
-
const
|
|
25452
|
-
|
|
25453
|
-
if (!chartRef || !scalesKeys) return {};
|
|
25454
|
-
const metasets = ((_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.getSortedVisibleDatasetMetas()) ?? [];
|
|
25455
|
-
const annotData = getAnnotationsData(annotationsData);
|
|
25456
|
-
return metasets && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
25457
|
-
const data = metasets.filter((dataset) => Object.values(dataset).includes(key)).flatMap((dataset) => dataset._parsed).map((parsedData) => parsedData[getAxisTypeFromKey(key)]).concat((annotData == null ? void 0 : annotData[key]) ?? []);
|
|
25425
|
+
const getAnnotationsData = (data) => {
|
|
25426
|
+
return data == null ? void 0 : data.reduce((acc, obj) => {
|
|
25458
25427
|
return {
|
|
25459
25428
|
...acc,
|
|
25460
|
-
[
|
|
25429
|
+
[obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
|
|
25461
25430
|
};
|
|
25462
|
-
}, {})
|
|
25431
|
+
}, {});
|
|
25432
|
+
};
|
|
25433
|
+
const getAxesDataFromMetasets = (generatedDatasets, scalesKeys, annotationsData) => {
|
|
25434
|
+
if (!Array.isArray(generatedDatasets) || !Array.isArray(scalesKeys)) {
|
|
25435
|
+
return {};
|
|
25436
|
+
}
|
|
25437
|
+
const annotations = getAnnotationsData(annotationsData);
|
|
25438
|
+
return scalesKeys.reduce((acc, axisKey) => {
|
|
25439
|
+
const axisType = getAxisTypeFromKey(axisKey);
|
|
25440
|
+
const datasetValues = generatedDatasets.filter((dataset) => {
|
|
25441
|
+
const axisId = dataset[`${axisType}AxisID`] ?? axisType;
|
|
25442
|
+
return axisId === axisKey;
|
|
25443
|
+
}).flatMap((dataset) => {
|
|
25444
|
+
const data = (dataset == null ? void 0 : dataset.data) ?? [];
|
|
25445
|
+
return data.map((point) => point[axisType]);
|
|
25446
|
+
});
|
|
25447
|
+
const annotationValues = (annotations == null ? void 0 : annotations[axisKey]) ?? [];
|
|
25448
|
+
acc[axisKey] = [.../* @__PURE__ */ new Set([...datasetValues, ...annotationValues])];
|
|
25449
|
+
return acc;
|
|
25450
|
+
}, {});
|
|
25463
25451
|
};
|
|
25464
25452
|
const shouldCalculate = (min, max) => !isNil(min) || !isNil(max);
|
|
25465
|
-
const autoScale = (options, state, generatedDatasets
|
|
25453
|
+
const autoScale = (options, state, generatedDatasets) => {
|
|
25466
25454
|
const {
|
|
25467
25455
|
additionalAxesOptions,
|
|
25468
25456
|
annotations: { annotationsData = [], controlAnnotation = false } = {}
|
|
@@ -25474,14 +25462,13 @@ const autoScale = (options, state, generatedDatasets, chartRef) => {
|
|
|
25474
25462
|
}
|
|
25475
25463
|
const scalesKeys = Object.keys(scales) ?? [];
|
|
25476
25464
|
const data = getAxesDataFromMetasets(
|
|
25477
|
-
|
|
25465
|
+
generatedDatasets,
|
|
25478
25466
|
scalesKeys,
|
|
25479
25467
|
annotationsData
|
|
25480
25468
|
);
|
|
25481
25469
|
const adjustedScales = data && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
25482
25470
|
const scale = scales[key];
|
|
25483
25471
|
const { min: propMin = void 0, max: propMax = void 0 } = scale;
|
|
25484
|
-
const { min: calcMin, max: calcMax } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
|
|
25485
25472
|
const { min: suggestedMin, max: suggestedMax } = getSuggestedAxisRange({
|
|
25486
25473
|
data: data[key],
|
|
25487
25474
|
beginAtZero: additionalAxesOptions == null ? void 0 : additionalAxesOptions.beginAtZero,
|
|
@@ -25490,8 +25477,8 @@ const autoScale = (options, state, generatedDatasets, chartRef) => {
|
|
|
25490
25477
|
const res = {
|
|
25491
25478
|
[key]: {
|
|
25492
25479
|
...scale,
|
|
25493
|
-
min: propMin ?? (shouldCalculate(propMin, propMax) ?
|
|
25494
|
-
max: propMax ?? (shouldCalculate(propMin, propMax) ?
|
|
25480
|
+
min: propMin ?? (shouldCalculate(propMin, propMax) ? void 0 : suggestedMin),
|
|
25481
|
+
max: propMax ?? (shouldCalculate(propMin, propMax) ? void 0 : suggestedMax)
|
|
25495
25482
|
}
|
|
25496
25483
|
};
|
|
25497
25484
|
return { ...acc, ...res };
|
|
@@ -25511,12 +25498,16 @@ const getCondition = (x2, y2, left2, right2, bottom2) => {
|
|
|
25511
25498
|
return { overLeftSide, overRightSide, overBottomSide };
|
|
25512
25499
|
};
|
|
25513
25500
|
const getAlignmentData = (context) => {
|
|
25514
|
-
var _a2;
|
|
25515
|
-
const
|
|
25516
|
-
const
|
|
25501
|
+
var _a2, _b2;
|
|
25502
|
+
const chart2 = context == null ? void 0 : context.chart;
|
|
25503
|
+
const dataIndex = (context == null ? void 0 : context.dataIndex) ?? 0;
|
|
25504
|
+
const datasetIndex = (context == null ? void 0 : context.datasetIndex) ?? 0;
|
|
25505
|
+
const chartArea = (chart2 == null ? void 0 : chart2.chartArea) ?? {};
|
|
25517
25506
|
const { left: left2 = null, right: right2 = null, bottom: bottom2 = null } = chartArea;
|
|
25518
|
-
const meta = chart2 == null ? void 0 : chart2.getDatasetMeta(datasetIndex);
|
|
25519
|
-
const
|
|
25507
|
+
const meta = (_a2 = chart2 == null ? void 0 : chart2.getDatasetMeta) == null ? void 0 : _a2.call(chart2, datasetIndex);
|
|
25508
|
+
const dataPoint = (_b2 = meta == null ? void 0 : meta.data) == null ? void 0 : _b2[dataIndex];
|
|
25509
|
+
const x2 = (dataPoint == null ? void 0 : dataPoint.x) ?? null;
|
|
25510
|
+
const y2 = (dataPoint == null ? void 0 : dataPoint.y) ?? null;
|
|
25520
25511
|
return {
|
|
25521
25512
|
x: x2,
|
|
25522
25513
|
y: y2,
|
|
@@ -25537,13 +25528,21 @@ const getPosition = () => {
|
|
|
25537
25528
|
};
|
|
25538
25529
|
};
|
|
25539
25530
|
const getLineChartDataLabels = (options) => {
|
|
25540
|
-
|
|
25531
|
+
var _a2;
|
|
25532
|
+
return ((_a2 = options == null ? void 0 : options.graph) == null ? void 0 : _a2.showDataLabels) ? {
|
|
25541
25533
|
display: AUTO,
|
|
25542
25534
|
align: getPosition(),
|
|
25543
25535
|
formatter: (_2, context) => {
|
|
25544
|
-
var
|
|
25545
|
-
const dataPoint = (_b2 = (
|
|
25546
|
-
|
|
25536
|
+
var _a3, _b2;
|
|
25537
|
+
const dataPoint = (_b2 = (_a3 = context == null ? void 0 : context.dataset) == null ? void 0 : _a3.data) == null ? void 0 : _b2[context.dataIndex];
|
|
25538
|
+
if (!dataPoint || dataPoint.label == null) return "";
|
|
25539
|
+
if (typeof dataPoint.label === "string") {
|
|
25540
|
+
return dataPoint.label;
|
|
25541
|
+
}
|
|
25542
|
+
if (Array.isArray(dataPoint.label)) {
|
|
25543
|
+
return dataPoint.label.map(String);
|
|
25544
|
+
}
|
|
25545
|
+
return String(dataPoint.label);
|
|
25547
25546
|
}
|
|
25548
25547
|
} : { display: false };
|
|
25549
25548
|
};
|
|
@@ -25562,17 +25561,25 @@ const customFormatNumber$1 = (labelNumber, scientificNotation) => {
|
|
|
25562
25561
|
return displayNumber(roundByMagnitude(labelNumber), roundOptions);
|
|
25563
25562
|
};
|
|
25564
25563
|
const getLineChartToolTips = (options) => {
|
|
25565
|
-
|
|
25564
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
25565
|
+
if (!((_b2 = (_a2 = options == null ? void 0 : options.axes) == null ? void 0 : _a2.x) == null ? void 0 : _b2.length) || !((_d2 = (_c2 = options == null ? void 0 : options.axes) == null ? void 0 : _c2.y) == null ? void 0 : _d2.length)) {
|
|
25566
|
+
console.warn("Tooltip config fallback: missing axes", options);
|
|
25567
|
+
return {
|
|
25568
|
+
enabled: false,
|
|
25569
|
+
callbacks: {}
|
|
25570
|
+
};
|
|
25571
|
+
}
|
|
25572
|
+
const { scientificNotation } = (options == null ? void 0 : options.tooltip) ?? {};
|
|
25566
25573
|
const getTooltipLabels = ({
|
|
25567
25574
|
xAxisID = "",
|
|
25568
25575
|
yAxisID = ""
|
|
25569
25576
|
}) => {
|
|
25570
|
-
var
|
|
25571
|
-
const xIndex = (xAxisID == null ? void 0 : xAxisID.length) > 1 ? Number(xAxisID[1]) - 1 : 0;
|
|
25572
|
-
const yIndex = (yAxisID == null ? void 0 : yAxisID.length) > 1 ? Number(yAxisID[1]) - 1 : 0;
|
|
25573
|
-
const xAxis = options.axes.x[xIndex];
|
|
25574
|
-
const yAxis = options.axes.y[yIndex];
|
|
25575
|
-
if (((
|
|
25577
|
+
var _a3, _b3, _c3, _d3, _e3, _f2, _g2;
|
|
25578
|
+
const xIndex = (xAxisID == null ? void 0 : xAxisID.length) > 1 ? Number(xAxisID == null ? void 0 : xAxisID[1]) - 1 : 0;
|
|
25579
|
+
const yIndex = (yAxisID == null ? void 0 : yAxisID.length) > 1 ? Number(yAxisID == null ? void 0 : yAxisID[1]) - 1 : 0;
|
|
25580
|
+
const xAxis = (_b3 = (_a3 = options == null ? void 0 : options.axes) == null ? void 0 : _a3.x) == null ? void 0 : _b3[xIndex];
|
|
25581
|
+
const yAxis = (_d3 = (_c3 = options == null ? void 0 : options.axes) == null ? void 0 : _c3.y) == null ? void 0 : _d3[yIndex];
|
|
25582
|
+
if (((_g2 = (_f2 = (_e3 = options == null ? void 0 : options.axes) == null ? void 0 : _e3.x) == null ? void 0 : _f2[0]) == null ? void 0 : _g2.position) === Position.Top) {
|
|
25576
25583
|
return {
|
|
25577
25584
|
titleAxisLabel: (yAxis == null ? void 0 : yAxis.label) || "",
|
|
25578
25585
|
valueAxisLabel: (xAxis == null ? void 0 : xAxis.label) || "",
|
|
@@ -25589,19 +25596,23 @@ const getLineChartToolTips = (options) => {
|
|
|
25589
25596
|
}
|
|
25590
25597
|
};
|
|
25591
25598
|
const titleCallback2 = (tooltipItem) => {
|
|
25599
|
+
var _a3, _b3, _c3, _d3;
|
|
25600
|
+
if (!(tooltipItem == null ? void 0 : tooltipItem[0])) return "";
|
|
25592
25601
|
const labels = getTooltipLabels(tooltipItem[0].dataset);
|
|
25593
|
-
const { titleLabel, titleAxisLabel } = labels ?? {};
|
|
25594
|
-
const formattedValue = titleLabel === TooltipLabel.Y ? tooltipItem[0].parsed.y : tooltipItem[0].parsed.x;
|
|
25602
|
+
const { titleLabel = "", titleAxisLabel = "" } = labels ?? {};
|
|
25603
|
+
const formattedValue = titleLabel === TooltipLabel.Y ? (_b3 = (_a3 = tooltipItem == null ? void 0 : tooltipItem[0]) == null ? void 0 : _a3.parsed) == null ? void 0 : _b3.y : (_d3 = (_c3 = tooltipItem == null ? void 0 : tooltipItem[0]) == null ? void 0 : _c3.parsed) == null ? void 0 : _d3.x;
|
|
25595
25604
|
const roundedValue = customFormatNumber$1(formattedValue, scientificNotation);
|
|
25596
25605
|
return `${roundedValue} ${titleAxisLabel}`;
|
|
25597
25606
|
};
|
|
25598
25607
|
const labelCallback2 = (tooltipItem) => {
|
|
25599
|
-
|
|
25600
|
-
|
|
25601
|
-
|
|
25608
|
+
var _a3;
|
|
25609
|
+
const { showLabelsInTooltips } = (options == null ? void 0 : options.tooltip) ?? {};
|
|
25610
|
+
let label = ((_a3 = tooltipItem == null ? void 0 : tooltipItem.dataset) == null ? void 0 : _a3.label) || "";
|
|
25611
|
+
const labels = getTooltipLabels(tooltipItem == null ? void 0 : tooltipItem.dataset);
|
|
25602
25612
|
const { valueLabel = "", valueAxisLabel = "" } = labels ?? {};
|
|
25603
25613
|
const getTooltipItemValue = () => {
|
|
25604
|
-
|
|
25614
|
+
var _a4, _b3;
|
|
25615
|
+
const labelNumber = valueLabel === TooltipLabel.X ? (_a4 = tooltipItem == null ? void 0 : tooltipItem.parsed) == null ? void 0 : _a4.x : (_b3 = tooltipItem == null ? void 0 : tooltipItem.parsed) == null ? void 0 : _b3.y;
|
|
25605
25616
|
return customFormatNumber$1(labelNumber, scientificNotation);
|
|
25606
25617
|
};
|
|
25607
25618
|
const tooltipItemValue = getTooltipItemValue();
|
|
@@ -25610,7 +25621,7 @@ const getLineChartToolTips = (options) => {
|
|
|
25610
25621
|
return `${label}: ${tooltipItemValue} ${units} ${tooltipLabel}`;
|
|
25611
25622
|
};
|
|
25612
25623
|
return {
|
|
25613
|
-
enabled: options.tooltip.tooltips,
|
|
25624
|
+
enabled: (_e2 = options == null ? void 0 : options.tooltip) == null ? void 0 : _e2.tooltips,
|
|
25614
25625
|
mode: ChartHoverMode.Nearest,
|
|
25615
25626
|
intersect: true,
|
|
25616
25627
|
padding: TOOLTIP_PADDING,
|
|
@@ -26052,10 +26063,10 @@ const useChartOptions = ({
|
|
|
26052
26063
|
const { legend: legend2, customLegendPlugin } = useLegendState({ chartRef, options }) ?? {};
|
|
26053
26064
|
const { state: legendState } = useLegend() ?? {};
|
|
26054
26065
|
const { annotation: annotation2 } = legendState ?? {};
|
|
26055
|
-
const datalabels = getLineChartDataLabels(options);
|
|
26056
|
-
const tooltip = getLineChartToolTips(options);
|
|
26066
|
+
const datalabels = getLineChartDataLabels(options) ?? {};
|
|
26067
|
+
const tooltip = getLineChartToolTips(options) ?? {};
|
|
26057
26068
|
const scales = useMemo(
|
|
26058
|
-
() => autoScale(options, state, generatedDatasets
|
|
26069
|
+
() => autoScale(options, state, generatedDatasets),
|
|
26059
26070
|
[options, state, generatedDatasets, chartRef]
|
|
26060
26071
|
);
|
|
26061
26072
|
const dragData = useMemo(
|
|
@@ -26158,6 +26169,7 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
|
26158
26169
|
resetZoom2();
|
|
26159
26170
|
return false;
|
|
26160
26171
|
}
|
|
26172
|
+
return true;
|
|
26161
26173
|
},
|
|
26162
26174
|
[resetZoom2]
|
|
26163
26175
|
);
|
|
@@ -26171,7 +26183,6 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
|
26171
26183
|
];
|
|
26172
26184
|
}, [handleDoubleClick]);
|
|
26173
26185
|
};
|
|
26174
|
-
const RANGE_GAP = 1;
|
|
26175
26186
|
const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
|
|
26176
26187
|
var _a2, _b2;
|
|
26177
26188
|
useEffect(() => {
|
|
@@ -26201,77 +26212,28 @@ const useStoreChartStateInStorage = (memoState, persistenceId) => {
|
|
|
26201
26212
|
memoState.zoomEnabled
|
|
26202
26213
|
]);
|
|
26203
26214
|
};
|
|
26204
|
-
const useUpdateAxesRanges = ({
|
|
26205
|
-
chartRef,
|
|
26206
|
-
range,
|
|
26207
|
-
state,
|
|
26208
|
-
dispatch,
|
|
26209
|
-
annotationsData
|
|
26210
|
-
}) => {
|
|
26211
|
-
const prevAxes = useRef(state.axes);
|
|
26212
|
-
useEffect(() => {
|
|
26213
|
-
if (range && isRangeValid(range)) {
|
|
26214
|
-
const newAxes = Object.entries(range).map(([key, { min, max }]) => {
|
|
26215
|
-
const { min: minFromData = void 0, max: maxFromData = void 0 } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
|
|
26216
|
-
let finalMin = min ?? minFromData;
|
|
26217
|
-
let finalMax = max ?? maxFromData;
|
|
26218
|
-
if (finalMin === finalMax) {
|
|
26219
|
-
finalMax += RANGE_GAP;
|
|
26220
|
-
}
|
|
26221
|
-
return {
|
|
26222
|
-
id: key,
|
|
26223
|
-
min: finalMin,
|
|
26224
|
-
max: finalMax
|
|
26225
|
-
};
|
|
26226
|
-
});
|
|
26227
|
-
const mergedAxes = [...prevAxes.current ?? []].map((axis) => {
|
|
26228
|
-
const newAxis = newAxes.find((a2) => a2.id === axis.id);
|
|
26229
|
-
return newAxis ? { ...axis, ...newAxis } : axis;
|
|
26230
|
-
});
|
|
26231
|
-
if (!isEqual(mergedAxes, prevAxes.current)) {
|
|
26232
|
-
dispatch({
|
|
26233
|
-
type: UPDATE_AXES_RANGES,
|
|
26234
|
-
payload: { axes: mergedAxes }
|
|
26235
|
-
});
|
|
26236
|
-
prevAxes.current = mergedAxes;
|
|
26237
|
-
}
|
|
26238
|
-
}
|
|
26239
|
-
}, [range]);
|
|
26240
|
-
};
|
|
26241
26215
|
const useChartState = ({
|
|
26242
|
-
chartRef,
|
|
26243
26216
|
options,
|
|
26244
26217
|
state,
|
|
26245
|
-
dispatch,
|
|
26246
26218
|
persistenceId
|
|
26247
26219
|
}) => {
|
|
26248
26220
|
const memoState = useMemo(() => state, [state]);
|
|
26249
26221
|
const memoOptions = useMemo(() => options, [options]);
|
|
26250
|
-
const {
|
|
26251
|
-
additionalAxesOptions: { range = void 0 },
|
|
26252
|
-
annotations: { annotationsData = [] } = {}
|
|
26253
|
-
} = memoOptions;
|
|
26254
26222
|
useStoreChartStateInStorage(memoState, persistenceId);
|
|
26255
26223
|
useToggleCustomLegendVisibility(memoState, memoOptions);
|
|
26256
|
-
useUpdateAxesRanges({
|
|
26257
|
-
range,
|
|
26258
|
-
state: memoState,
|
|
26259
|
-
dispatch,
|
|
26260
|
-
chartRef,
|
|
26261
|
-
annotationsData
|
|
26262
|
-
});
|
|
26263
26224
|
};
|
|
26264
26225
|
const WORD_SEPARATOR = " ";
|
|
26265
26226
|
const SEMI_TRANSPARENT = "rgba(0, 0, 0, 0.5)";
|
|
26266
26227
|
const getWords = (text) => {
|
|
26267
|
-
|
|
26228
|
+
var _a2;
|
|
26229
|
+
return (_a2 = Array.isArray(text) ? text.join(WORD_SEPARATOR) : text) == null ? void 0 : _a2.split(
|
|
26268
26230
|
WORD_SEPARATOR
|
|
26269
26231
|
);
|
|
26270
26232
|
};
|
|
26271
26233
|
const drawText = ({ ctx, lines, lineHeight, x: x2, y: y2, position }) => {
|
|
26272
|
-
lines.forEach((line, index2) => {
|
|
26273
|
-
const lineY = position.includes("top") ? y2 + lineHeight * (index2 + 1) - 5 : y2 - (lines.length - 1 - index2) * lineHeight;
|
|
26274
|
-
ctx.fillText(line, x2, lineY);
|
|
26234
|
+
lines == null ? void 0 : lines.forEach((line, index2) => {
|
|
26235
|
+
const lineY = (position == null ? void 0 : position.includes("top")) ? y2 + lineHeight * (index2 + 1) - 5 : y2 - (lines.length - 1 - index2) * lineHeight;
|
|
26236
|
+
ctx == null ? void 0 : ctx.fillText(line, x2, lineY);
|
|
26275
26237
|
});
|
|
26276
26238
|
};
|
|
26277
26239
|
const calculateMaxWidth = (initialMaxWidth, chartAreaWidth) => {
|
|
@@ -26281,71 +26243,72 @@ const calculateMaxWidth = (initialMaxWidth, chartAreaWidth) => {
|
|
|
26281
26243
|
return initialMaxWidth * maxWidthFactor;
|
|
26282
26244
|
};
|
|
26283
26245
|
const getLegendDimensions = (chart2) => {
|
|
26284
|
-
|
|
26285
|
-
const
|
|
26286
|
-
const
|
|
26246
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
|
|
26247
|
+
const { legend: legend2 } = chart2 ?? {};
|
|
26248
|
+
const legendWidth = legend2 && (legend2 == null ? void 0 : legend2.display) && ((_a2 = legend2 == null ? void 0 : legend2.options) == null ? void 0 : _a2.position) === "left" ? (legend2 == null ? void 0 : legend2.width) + ((_c2 = (_b2 = legend2 == null ? void 0 : legend2.options) == null ? void 0 : _b2.labels) == null ? void 0 : _c2.padding) * 2 : 0;
|
|
26249
|
+
const legendHeight = legend2 && legend2.display && (((_d2 = legend2 == null ? void 0 : legend2.options) == null ? void 0 : _d2.position) === "top" || ((_e2 = legend2 == null ? void 0 : legend2.options) == null ? void 0 : _e2.position) === "bottom") ? (legend2 == null ? void 0 : legend2.height) + ((_g2 = (_f2 = legend2 == null ? void 0 : legend2.options) == null ? void 0 : _f2.labels) == null ? void 0 : _g2.padding) * 2 : 0;
|
|
26287
26250
|
return { legendWidth, legendHeight };
|
|
26288
26251
|
};
|
|
26289
26252
|
const getPositionCoordinates = (position, chart2, xOffset, yOffset) => {
|
|
26290
|
-
const { chartArea, width } = chart2;
|
|
26253
|
+
const { chartArea, width } = chart2 ?? {};
|
|
26291
26254
|
const temporaryChartAreaRight = width - 8;
|
|
26292
|
-
const { legendWidth, legendHeight } = getLegendDimensions(chart2);
|
|
26255
|
+
const { legendWidth, legendHeight } = getLegendDimensions(chart2) ?? {};
|
|
26293
26256
|
switch (position) {
|
|
26294
26257
|
case TextLabelPosition.TOP_LEFT:
|
|
26295
26258
|
return [
|
|
26296
|
-
chartArea.left + xOffset + legendWidth,
|
|
26297
|
-
chartArea.top + yOffset + legendHeight
|
|
26259
|
+
(chartArea == null ? void 0 : chartArea.left) + xOffset + legendWidth,
|
|
26260
|
+
(chartArea == null ? void 0 : chartArea.top) + yOffset + legendHeight
|
|
26298
26261
|
];
|
|
26299
26262
|
case TextLabelPosition.TOP_CENTER:
|
|
26300
26263
|
return [
|
|
26301
|
-
chartArea.left + chartArea.width / 2,
|
|
26302
|
-
chartArea.top + yOffset + legendHeight
|
|
26264
|
+
(chartArea == null ? void 0 : chartArea.left) + (chartArea == null ? void 0 : chartArea.width) / 2,
|
|
26265
|
+
(chartArea == null ? void 0 : chartArea.top) + yOffset + legendHeight
|
|
26303
26266
|
];
|
|
26304
26267
|
case TextLabelPosition.TOP_RIGHT:
|
|
26305
26268
|
return [
|
|
26306
26269
|
temporaryChartAreaRight - xOffset,
|
|
26307
26270
|
//replace within chartArea.right when resize bug will be fixed
|
|
26308
|
-
chartArea.top + yOffset + legendHeight
|
|
26271
|
+
(chartArea == null ? void 0 : chartArea.top) + yOffset + legendHeight
|
|
26309
26272
|
];
|
|
26310
26273
|
case TextLabelPosition.MIDDLE_LEFT:
|
|
26311
26274
|
return [
|
|
26312
|
-
chartArea.left + xOffset + legendWidth,
|
|
26313
|
-
chartArea.top + chartArea.height / 2
|
|
26275
|
+
(chartArea == null ? void 0 : chartArea.left) + xOffset + legendWidth,
|
|
26276
|
+
(chartArea == null ? void 0 : chartArea.top) + (chartArea == null ? void 0 : chartArea.height) / 2
|
|
26314
26277
|
];
|
|
26315
26278
|
case TextLabelPosition.MIDDLE_CENTER:
|
|
26316
26279
|
return [
|
|
26317
|
-
chartArea.left + chartArea.width / 2,
|
|
26318
|
-
chartArea.top + chartArea.height / 2
|
|
26280
|
+
(chartArea == null ? void 0 : chartArea.left) + (chartArea == null ? void 0 : chartArea.width) / 2,
|
|
26281
|
+
(chartArea == null ? void 0 : chartArea.top) + (chartArea == null ? void 0 : chartArea.height) / 2
|
|
26319
26282
|
];
|
|
26320
26283
|
case TextLabelPosition.MIDDLE_RIGHT:
|
|
26321
26284
|
return [
|
|
26322
26285
|
temporaryChartAreaRight - xOffset - legendWidth,
|
|
26323
26286
|
//replace within chartArea.right when resize bug will be fixed
|
|
26324
|
-
chartArea.top + chartArea.height / 2
|
|
26287
|
+
(chartArea == null ? void 0 : chartArea.top) + (chartArea == null ? void 0 : chartArea.height) / 2
|
|
26325
26288
|
];
|
|
26326
26289
|
case TextLabelPosition.BOTTOM_LEFT:
|
|
26327
26290
|
return [
|
|
26328
|
-
chartArea.left + xOffset + legendWidth,
|
|
26329
|
-
chartArea.bottom - yOffset - legendHeight
|
|
26291
|
+
(chartArea == null ? void 0 : chartArea.left) + xOffset + legendWidth,
|
|
26292
|
+
(chartArea == null ? void 0 : chartArea.bottom) - yOffset - legendHeight
|
|
26330
26293
|
];
|
|
26331
26294
|
case TextLabelPosition.BOTTOM_CENTER:
|
|
26332
26295
|
return [
|
|
26333
|
-
chartArea.left + chartArea.width / 2,
|
|
26334
|
-
chartArea.bottom - yOffset - legendHeight
|
|
26296
|
+
(chartArea == null ? void 0 : chartArea.left) + (chartArea == null ? void 0 : chartArea.width) / 2,
|
|
26297
|
+
(chartArea == null ? void 0 : chartArea.bottom) - yOffset - legendHeight
|
|
26335
26298
|
];
|
|
26336
26299
|
case TextLabelPosition.BOTTOM_RIGHT:
|
|
26337
26300
|
default:
|
|
26338
26301
|
return [
|
|
26339
26302
|
temporaryChartAreaRight - xOffset - legendWidth,
|
|
26340
26303
|
//replace within chartArea.right when resize bug will be fixed
|
|
26341
|
-
chartArea.bottom - yOffset - legendHeight
|
|
26304
|
+
(chartArea == null ? void 0 : chartArea.bottom) - yOffset - legendHeight
|
|
26342
26305
|
];
|
|
26343
26306
|
}
|
|
26344
26307
|
};
|
|
26345
26308
|
const getTextAlign = (position) => {
|
|
26346
|
-
if (position.includes(AlignOptions.Center)) {
|
|
26309
|
+
if (position == null ? void 0 : position.includes(AlignOptions.Center)) {
|
|
26347
26310
|
return AlignOptions.Center;
|
|
26348
|
-
} else if (position.includes(AlignOptions.Left)) {
|
|
26311
|
+
} else if (position == null ? void 0 : position.includes(AlignOptions.Left)) {
|
|
26349
26312
|
return AlignOptions.Left;
|
|
26350
26313
|
} else {
|
|
26351
26314
|
return AlignOptions.Right;
|
|
@@ -26355,11 +26318,11 @@ const wrapText = (words, maxWidth, ctx) => {
|
|
|
26355
26318
|
let line = "";
|
|
26356
26319
|
let lines = [];
|
|
26357
26320
|
for (let i2 = 0; i2 < words.length; i2++) {
|
|
26358
|
-
const testLine = `${line}${words[i2]}${WORD_SEPARATOR}`;
|
|
26359
|
-
const { width: testWidth } = ctx.measureText(testLine);
|
|
26321
|
+
const testLine = `${line}${words == null ? void 0 : words[i2]}${WORD_SEPARATOR}`;
|
|
26322
|
+
const { width: testWidth } = (ctx == null ? void 0 : ctx.measureText(testLine)) ?? {};
|
|
26360
26323
|
if (testWidth > maxWidth) {
|
|
26361
|
-
lines.push(line.trim());
|
|
26362
|
-
line = `${words[i2]}${WORD_SEPARATOR}`;
|
|
26324
|
+
lines.push(line == null ? void 0 : line.trim());
|
|
26325
|
+
line = `${words == null ? void 0 : words[i2]}${WORD_SEPARATOR}`;
|
|
26363
26326
|
} else {
|
|
26364
26327
|
line = testLine;
|
|
26365
26328
|
}
|
|
@@ -26368,15 +26331,17 @@ const wrapText = (words, maxWidth, ctx) => {
|
|
|
26368
26331
|
return lines;
|
|
26369
26332
|
};
|
|
26370
26333
|
const renderWrappedText = (ctx, options) => {
|
|
26371
|
-
|
|
26334
|
+
var _a2, _b2;
|
|
26335
|
+
if (!ctx) return;
|
|
26336
|
+
const { text, maxWidth, fontSize, lineHeight, x: x2, y: y2, position } = options ?? {};
|
|
26372
26337
|
const words = getWords(text);
|
|
26373
26338
|
const wrappedLines = wrapText(words, maxWidth, ctx);
|
|
26374
|
-
ctx.save();
|
|
26339
|
+
(_a2 = ctx == null ? void 0 : ctx.save) == null ? void 0 : _a2.call(ctx);
|
|
26375
26340
|
ctx.font = `${fontSize}px Arial`;
|
|
26376
26341
|
ctx.fillStyle = SEMI_TRANSPARENT;
|
|
26377
26342
|
ctx.textAlign = getTextAlign(position);
|
|
26378
26343
|
drawText({ ctx, lines: wrappedLines, lineHeight, x: x2, y: y2, position });
|
|
26379
|
-
ctx.restore();
|
|
26344
|
+
(_b2 = ctx == null ? void 0 : ctx.restore) == null ? void 0 : _b2.call(ctx);
|
|
26380
26345
|
};
|
|
26381
26346
|
const chartAreaTextPlugin = {
|
|
26382
26347
|
id: "chartAreaText",
|
|
@@ -26390,9 +26355,9 @@ const chartAreaTextPlugin = {
|
|
|
26390
26355
|
lineHeight,
|
|
26391
26356
|
maxWidth: initialMaxWidth,
|
|
26392
26357
|
position
|
|
26393
|
-
} = options;
|
|
26358
|
+
} = options ?? {};
|
|
26394
26359
|
if (!showLabel || !text) return;
|
|
26395
|
-
const { ctx, chartArea } = chart2;
|
|
26360
|
+
const { ctx, chartArea } = chart2 ?? {};
|
|
26396
26361
|
if (!ctx || !chartArea) return;
|
|
26397
26362
|
const maxWidth = calculateMaxWidth(initialMaxWidth, chartArea.width);
|
|
26398
26363
|
const [x2, y2] = getPositionCoordinates(position, chart2, xOffset, yOffset);
|
|
@@ -26719,8 +26684,10 @@ const annotationDraggerPlugin = {
|
|
|
26719
26684
|
id: "annotationDraggerPlugin",
|
|
26720
26685
|
beforeDraw(chart2) {
|
|
26721
26686
|
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
26687
|
+
const ctx = chart2 == null ? void 0 : chart2.ctx;
|
|
26722
26688
|
let annotations = ((_b2 = (_a2 = chart2.options.plugins) == null ? void 0 : _a2.annotation) == null ? void 0 : _b2.annotations) ?? {};
|
|
26723
26689
|
if (!annotations) return;
|
|
26690
|
+
if (!ctx || !annotations) return;
|
|
26724
26691
|
annotationLabel(
|
|
26725
26692
|
chart2.ctx,
|
|
26726
26693
|
annotations,
|
|
@@ -26753,6 +26720,7 @@ const annotationDraggerPlugin = {
|
|
|
26753
26720
|
const pluginOptions = ((_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.annotationDraggerPlugin) || {
|
|
26754
26721
|
enabled: false
|
|
26755
26722
|
};
|
|
26723
|
+
if (!canvas2 || !scales || !pluginOptions) return;
|
|
26756
26724
|
const typedScales = { ...scales, x: scales.x, y: scales.y };
|
|
26757
26725
|
let annotations = ((_d2 = (_c2 = chart2.options.plugins) == null ? void 0 : _c2.annotation) == null ? void 0 : _d2.annotations) ?? {};
|
|
26758
26726
|
if (!chart2 && !annotations) return;
|
|
@@ -27357,10 +27325,8 @@ const LineChart = (props) => {
|
|
|
27357
27325
|
graph
|
|
27358
27326
|
]);
|
|
27359
27327
|
useChartState({
|
|
27360
|
-
chartRef,
|
|
27361
27328
|
options,
|
|
27362
27329
|
state,
|
|
27363
|
-
dispatch,
|
|
27364
27330
|
persistenceId
|
|
27365
27331
|
});
|
|
27366
27332
|
const { resetZoom: resetZoom2, handleKeyDown, handleKeyUp } = useChartFunctions({
|