@oliasoft-open-source/charts-library 3.0.3 → 3.1.0-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/index.js +72 -49
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
8
8
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
9
9
|
import React, { forwardRef, useRef, useEffect, useMemo, useCallback, useState, useReducer } from "react";
|
|
10
|
-
import { round as round$2, toNum, isCloseTo } from "@oliasoft-open-source/units";
|
|
10
|
+
import { round as round$2, toNum, displayNumber, isCloseTo } from "@oliasoft-open-source/units";
|
|
11
11
|
import cx from "classnames";
|
|
12
12
|
import { produce } from "immer";
|
|
13
13
|
import { Icon, Tooltip as Tooltip$2, Button, Flex, Text, Menu, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer } from "@oliasoft-open-source/react-ui-library";
|
|
@@ -1284,7 +1284,7 @@ const formatters$1 = {
|
|
|
1284
1284
|
if (maxTick < 1e-4 || maxTick > 1e15) {
|
|
1285
1285
|
notation = "scientific";
|
|
1286
1286
|
}
|
|
1287
|
-
delta = calculateDelta$
|
|
1287
|
+
delta = calculateDelta$2(tickValue, ticks);
|
|
1288
1288
|
}
|
|
1289
1289
|
const logDelta = log10$1(Math.abs(delta));
|
|
1290
1290
|
const numDecimal = Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0);
|
|
@@ -1314,7 +1314,7 @@ const formatters$1 = {
|
|
|
1314
1314
|
return "";
|
|
1315
1315
|
}
|
|
1316
1316
|
};
|
|
1317
|
-
function calculateDelta$
|
|
1317
|
+
function calculateDelta$2(tickValue, ticks) {
|
|
1318
1318
|
let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
|
|
1319
1319
|
if (Math.abs(delta) >= 1 && tickValue !== Math.floor(tickValue)) {
|
|
1320
1320
|
delta = tickValue - Math.floor(tickValue);
|
|
@@ -23677,7 +23677,7 @@ const formatters = {
|
|
|
23677
23677
|
if (maxTick < 1e-4 || maxTick > 1e15) {
|
|
23678
23678
|
notation = "scientific";
|
|
23679
23679
|
}
|
|
23680
|
-
delta = calculateDelta(tickValue, ticks);
|
|
23680
|
+
delta = calculateDelta$1(tickValue, ticks);
|
|
23681
23681
|
}
|
|
23682
23682
|
const logDelta = log10(Math.abs(delta));
|
|
23683
23683
|
const numDecimal = Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0);
|
|
@@ -23696,7 +23696,7 @@ const formatters = {
|
|
|
23696
23696
|
return "";
|
|
23697
23697
|
}
|
|
23698
23698
|
};
|
|
23699
|
-
function calculateDelta(tickValue, ticks) {
|
|
23699
|
+
function calculateDelta$1(tickValue, ticks) {
|
|
23700
23700
|
let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
|
|
23701
23701
|
if (Math.abs(delta) >= 1 && tickValue !== Math.floor(tickValue)) {
|
|
23702
23702
|
delta = tickValue - Math.floor(tickValue);
|
|
@@ -31207,12 +31207,6 @@ const isLessThanMax = (value, max) => {
|
|
|
31207
31207
|
const isGreaterThanMin = (value, min) => {
|
|
31208
31208
|
return value === void 0 || min === void 0 || Number(value) > Number(min);
|
|
31209
31209
|
};
|
|
31210
|
-
const truncateDecimals = (number, digits) => {
|
|
31211
|
-
const multiplier = 10 ** digits;
|
|
31212
|
-
const adjustedNum = number * multiplier;
|
|
31213
|
-
const truncatedNum = Math[adjustedNum < 0 ? "ceil" : "floor"](adjustedNum);
|
|
31214
|
-
return truncatedNum / multiplier;
|
|
31215
|
-
};
|
|
31216
31210
|
const generateAxisId = (axisType, index2 = 0, hasMultiAxes = false) => {
|
|
31217
31211
|
const i2 = hasMultiAxes ? index2 + 1 : "";
|
|
31218
31212
|
return `${axisType}${i2}`;
|
|
@@ -32494,6 +32488,7 @@ const LineChartPropTypes = {
|
|
|
32494
32488
|
testId: PropTypes.string,
|
|
32495
32489
|
data: PropTypes.object.isRequired,
|
|
32496
32490
|
options: PropTypes.shape({
|
|
32491
|
+
scales: PropTypes.object,
|
|
32497
32492
|
title: PropTypes.oneOfType([
|
|
32498
32493
|
PropTypes.string,
|
|
32499
32494
|
PropTypes.arrayOf(PropTypes.string)
|
|
@@ -32524,7 +32519,6 @@ const LineChartPropTypes = {
|
|
|
32524
32519
|
reverse: PropTypes.bool,
|
|
32525
32520
|
beginAtZero: PropTypes.bool,
|
|
32526
32521
|
stepSize: PropTypes.number,
|
|
32527
|
-
truncateAxisNumbersToDigitsCallback: PropTypes.number,
|
|
32528
32522
|
suggestedMin: PropTypes.number,
|
|
32529
32523
|
suggestedMax: PropTypes.number,
|
|
32530
32524
|
range: PropTypes.shape({
|
|
@@ -32658,6 +32652,7 @@ const getDefaultProps$2 = (props) => {
|
|
|
32658
32652
|
data: props.chart.data,
|
|
32659
32653
|
options: {
|
|
32660
32654
|
title: props.chart.options.title || "",
|
|
32655
|
+
scales: props.chart.options.scales || {},
|
|
32661
32656
|
axes: {
|
|
32662
32657
|
x: props.chart.options.axes.x || [{}],
|
|
32663
32658
|
y: props.chart.options.axes.y || [{}]
|
|
@@ -32667,7 +32662,6 @@ const getDefaultProps$2 = (props) => {
|
|
|
32667
32662
|
reverse: props.chart.options.additionalAxesOptions.reverse || false,
|
|
32668
32663
|
beginAtZero: props.chart.options.additionalAxesOptions.beginAtZero || false,
|
|
32669
32664
|
stepSize: props.chart.options.additionalAxesOptions.stepSize,
|
|
32670
|
-
truncateAxisNumbersToDigitsCallback: props.chart.options.additionalAxesOptions.truncateAxisNumbersToDigitsCallback,
|
|
32671
32665
|
suggestedMin: props.chart.options.additionalAxesOptions.suggestedMin,
|
|
32672
32666
|
suggestedMax: props.chart.options.additionalAxesOptions.suggestedMax,
|
|
32673
32667
|
range: props.chart.options.additionalAxesOptions.range,
|
|
@@ -32832,33 +32826,57 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
32832
32826
|
};
|
|
32833
32827
|
});
|
|
32834
32828
|
};
|
|
32829
|
+
const calculateDelta = (tickValue, ticks) => {
|
|
32830
|
+
let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
|
|
32831
|
+
if (Math.abs(delta) >= 1 && tickValue !== Math.floor(tickValue)) {
|
|
32832
|
+
delta = tickValue - Math.floor(tickValue);
|
|
32833
|
+
}
|
|
32834
|
+
return delta;
|
|
32835
|
+
};
|
|
32836
|
+
const formatAxisLabelNumbers = (tickValue, ticks, locale = "en-gb") => {
|
|
32837
|
+
if (tickValue === 0 || tickValue === null) {
|
|
32838
|
+
return "0";
|
|
32839
|
+
}
|
|
32840
|
+
let notation;
|
|
32841
|
+
let delta = tickValue;
|
|
32842
|
+
if (ticks.length > 1) {
|
|
32843
|
+
const maxTick = Math.max(
|
|
32844
|
+
Math.abs(ticks[0].value),
|
|
32845
|
+
Math.abs(ticks[ticks.length - 1].value)
|
|
32846
|
+
);
|
|
32847
|
+
if (maxTick < 1e-4 || maxTick > 1e15) {
|
|
32848
|
+
notation = "scientific";
|
|
32849
|
+
}
|
|
32850
|
+
delta = calculateDelta(tickValue, ticks);
|
|
32851
|
+
}
|
|
32852
|
+
const logDelta = Math.log10(Math.abs(delta));
|
|
32853
|
+
const numDecimal = isNaN(logDelta) ? 1 : Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0);
|
|
32854
|
+
return displayNumber(round$2(tickValue, numDecimal), {
|
|
32855
|
+
scientific: notation === "scientific",
|
|
32856
|
+
roundScientificCoefficientToNDecimals: numDecimal
|
|
32857
|
+
});
|
|
32858
|
+
};
|
|
32835
32859
|
const getLineChartAxis = (options, axisType, state, currentScales, i2 = 0) => {
|
|
32836
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
32860
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
|
|
32837
32861
|
const axisData = currentScales || options.axes[axisType][0];
|
|
32838
32862
|
const stateAxis = state.axes.filter((axis) => axis.id.startsWith(axisType))[i2];
|
|
32863
|
+
const ticksConfigFromProps = (_b2 = (_a2 = options == null ? void 0 : options.scales) == null ? void 0 : _a2[`${i2 === 0 ? axisType : axisType + i2}`]) == null ? void 0 : _b2.ticks;
|
|
32839
32864
|
const { additionalAxesOptions } = options;
|
|
32840
32865
|
const getTicks = () => {
|
|
32841
|
-
const
|
|
32842
|
-
|
|
32843
|
-
|
|
32844
|
-
callback: (tick) => truncateDecimals(
|
|
32845
|
-
tick,
|
|
32846
|
-
additionalAxesOptions.truncateAxisNumbersToDigitsCallback
|
|
32847
|
-
)
|
|
32848
|
-
} : {};
|
|
32849
|
-
const ticks = additionalAxesOptions.chartScaleType === ScaleType.Logarithmic ? {
|
|
32850
|
-
callback: (tick) => {
|
|
32851
|
-
return LOGARITHMIC_STEPS.includes(tick) ? tick.toLocaleString() : "";
|
|
32852
|
-
}
|
|
32853
|
-
} : {
|
|
32854
|
-
stepSize: axisData.stepSize || (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null),
|
|
32855
|
-
...truncateAxisNumbersToDigitsCallback
|
|
32866
|
+
const isLogarithmic = additionalAxesOptions.chartScaleType === ScaleType.Logarithmic;
|
|
32867
|
+
const ticksFormattingCallback = (tick, _index, ticks2) => {
|
|
32868
|
+
return isLogarithmic ? LOGARITHMIC_STEPS.includes(tick) ? formatAxisLabelNumbers(tick, ticks2) : "" : formatAxisLabelNumbers(tick, ticks2);
|
|
32856
32869
|
};
|
|
32857
|
-
|
|
32858
|
-
|
|
32859
|
-
|
|
32870
|
+
const ticks = {
|
|
32871
|
+
...!isLogarithmic ? {
|
|
32872
|
+
stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null)
|
|
32873
|
+
} : {},
|
|
32874
|
+
callback: ticksFormattingCallback,
|
|
32875
|
+
includeBounds: false,
|
|
32860
32876
|
//OW-10088 disable irregular axis ticks
|
|
32877
|
+
...ticksConfigFromProps
|
|
32861
32878
|
};
|
|
32879
|
+
return ticks;
|
|
32862
32880
|
};
|
|
32863
32881
|
return {
|
|
32864
32882
|
type: additionalAxesOptions.chartScaleType,
|
|
@@ -32867,10 +32885,10 @@ const getLineChartAxis = (options, axisType, state, currentScales, i2 = 0) => {
|
|
|
32867
32885
|
reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
|
|
32868
32886
|
suggestedMax: additionalAxesOptions.suggestedMax,
|
|
32869
32887
|
suggestedMin: additionalAxesOptions.suggestedMin,
|
|
32870
|
-
min: (stateAxis == null ? void 0 : stateAxis.min) ?? ((
|
|
32871
|
-
max: (stateAxis == null ? void 0 : stateAxis.max) ?? ((
|
|
32888
|
+
min: (stateAxis == null ? void 0 : stateAxis.min) ?? ((_d2 = (_c2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _c2[axisType]) == null ? void 0 : _d2.min),
|
|
32889
|
+
max: (stateAxis == null ? void 0 : stateAxis.max) ?? ((_f2 = (_e2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _e2[axisType]) == null ? void 0 : _f2.max),
|
|
32872
32890
|
title: {
|
|
32873
|
-
display: (
|
|
32891
|
+
display: (_g2 = axisData.label) == null ? void 0 : _g2.length,
|
|
32874
32892
|
text: axisData.label,
|
|
32875
32893
|
padding: 0
|
|
32876
32894
|
},
|
|
@@ -34520,7 +34538,7 @@ const getDefaultProps = (props) => {
|
|
|
34520
34538
|
};
|
|
34521
34539
|
return chart2;
|
|
34522
34540
|
};
|
|
34523
|
-
const getBarChartAxis = (chart2, axisType, currentScales) => {
|
|
34541
|
+
const getBarChartAxis = (chart2, axisType, currentScales, i2) => {
|
|
34524
34542
|
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2;
|
|
34525
34543
|
const isDirectionVertical = isVertical(chart2.options.direction);
|
|
34526
34544
|
const axisData = currentScales || chart2.options.axes[axisType][0];
|
|
@@ -34536,18 +34554,23 @@ const getBarChartAxis = (chart2, axisType, currentScales) => {
|
|
|
34536
34554
|
return axisType === axisWithReverse ? chart2.options.additionalAxesOptions.reverse : false;
|
|
34537
34555
|
};
|
|
34538
34556
|
const getTicks = () => {
|
|
34539
|
-
|
|
34540
|
-
|
|
34541
|
-
|
|
34542
|
-
|
|
34543
|
-
|
|
34544
|
-
|
|
34545
|
-
|
|
34546
|
-
|
|
34547
|
-
|
|
34548
|
-
stepSize: axisData.stepSize
|
|
34549
|
-
}
|
|
34550
|
-
|
|
34557
|
+
var _a3, _b3, _c3, _d3;
|
|
34558
|
+
const additionalAxesOptions = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.additionalAxesOptions;
|
|
34559
|
+
const ticksConfigFromProps = (_d3 = (_c3 = (_b3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _b3.scales) == null ? void 0 : _c3[`${i2 === 0 ? axisType : axisType + i2}`]) == null ? void 0 : _d3.ticks;
|
|
34560
|
+
const isLogarithmic = isDirectionCompatibleWithAxisType && additionalAxesOptions.chartScaleType === ScaleType.Logarithmic;
|
|
34561
|
+
const ticksFormattingCallback = (tick, _index, ticks2) => {
|
|
34562
|
+
return isLogarithmic ? LOGARITHMIC_STEPS.includes(tick) ? formatAxisLabelNumbers(tick, ticks2) : "" : formatAxisLabelNumbers(tick, ticks2);
|
|
34563
|
+
};
|
|
34564
|
+
const ticks = {
|
|
34565
|
+
...!isLogarithmic ? {
|
|
34566
|
+
stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null)
|
|
34567
|
+
} : {},
|
|
34568
|
+
callback: ticksFormattingCallback,
|
|
34569
|
+
includeBounds: false,
|
|
34570
|
+
//OW-10088 disable irregular axis ticks
|
|
34571
|
+
...ticksConfigFromProps
|
|
34572
|
+
};
|
|
34573
|
+
return ticks;
|
|
34551
34574
|
};
|
|
34552
34575
|
return {
|
|
34553
34576
|
type: getScaleType(),
|
|
@@ -34577,7 +34600,7 @@ const getBarChartAxes = (chart2, axisType) => {
|
|
|
34577
34600
|
const color2 = curr.color || COLORS[i2] || generateRandomColor$1(COLORS);
|
|
34578
34601
|
axisData.color = color2;
|
|
34579
34602
|
axisData.position = curr.position || getAxisPosition(axisType, i2);
|
|
34580
|
-
const axis = getBarChartAxis(chart2, axisType, axisData);
|
|
34603
|
+
const axis = getBarChartAxis(chart2, axisType, axisData, i2);
|
|
34581
34604
|
return { ...acc, [axisType + (i2 + 1)]: axis };
|
|
34582
34605
|
}, {});
|
|
34583
34606
|
return axes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-beta-1",
|
|
4
4
|
"description": "React Chart Library (based on Chart.js and react-chart-js-2)",
|
|
5
5
|
"homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
|
|
6
6
|
"bugs": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"react-icons": "^4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@oliasoft-open-source/react-ui-library": "^3.6.
|
|
53
|
-
"@oliasoft-open-source/units": "^
|
|
52
|
+
"@oliasoft-open-source/react-ui-library": "^3.6.5",
|
|
53
|
+
"@oliasoft-open-source/units": "^3.1.1",
|
|
54
54
|
"@storybook/addon-actions": "^7.0.18",
|
|
55
55
|
"@storybook/addon-docs": "^7.0.18",
|
|
56
56
|
"@storybook/react": "^7.0.18",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"vitest": "^0.32.0"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"@oliasoft-open-source/react-ui-library": "^3.6.
|
|
96
|
-
"@oliasoft-open-source/units": "^
|
|
95
|
+
"@oliasoft-open-source/react-ui-library": "^3.6.5",
|
|
96
|
+
"@oliasoft-open-source/units": "^3.1.1",
|
|
97
97
|
"classnames": "^2.3.2",
|
|
98
98
|
"immer": "^10.0.2",
|
|
99
99
|
"lodash": "^4.17.21",
|