@oliasoft-open-source/charts-library 3.0.5-beta-1 → 3.1.0-beta-2
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 +86 -54
- package/package.json +3 -3
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,14 +31207,8 @@ 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
|
-
const i2 = hasMultiAxes
|
|
31211
|
+
const i2 = hasMultiAxes ? index2 + 1 : "";
|
|
31218
31212
|
return `${axisType}${i2}`;
|
|
31219
31213
|
};
|
|
31220
31214
|
const getAxisTypeFromKey = (string) => {
|
|
@@ -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,60 @@ 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,
|
|
32878
|
+
font: {
|
|
32879
|
+
size: 14
|
|
32880
|
+
}
|
|
32861
32881
|
};
|
|
32882
|
+
return ticks;
|
|
32862
32883
|
};
|
|
32863
32884
|
return {
|
|
32864
32885
|
type: additionalAxesOptions.chartScaleType,
|
|
@@ -32867,10 +32888,10 @@ const getLineChartAxis = (options, axisType, state, currentScales, i2 = 0) => {
|
|
|
32867
32888
|
reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
|
|
32868
32889
|
suggestedMax: additionalAxesOptions.suggestedMax,
|
|
32869
32890
|
suggestedMin: additionalAxesOptions.suggestedMin,
|
|
32870
|
-
min: (stateAxis == null ? void 0 : stateAxis.min) ?? ((
|
|
32871
|
-
max: (stateAxis == null ? void 0 : stateAxis.max) ?? ((
|
|
32891
|
+
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),
|
|
32892
|
+
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
32893
|
title: {
|
|
32873
|
-
display: (
|
|
32894
|
+
display: (_g2 = axisData.label) == null ? void 0 : _g2.length,
|
|
32874
32895
|
text: axisData.label,
|
|
32875
32896
|
padding: 0
|
|
32876
32897
|
},
|
|
@@ -33145,7 +33166,11 @@ const generateAnnotations = (options, state) => {
|
|
|
33145
33166
|
if (!((_a2 = state == null ? void 0 : state.showAnnotationLineIndex) == null ? void 0 : _a2.includes(i2))) {
|
|
33146
33167
|
return { ...acc };
|
|
33147
33168
|
}
|
|
33148
|
-
const
|
|
33169
|
+
const getScaleId = () => {
|
|
33170
|
+
var _a3;
|
|
33171
|
+
const axisType = curr.annotationAxis;
|
|
33172
|
+
return ((_a3 = options.axes[axisType]) == null ? void 0 : _a3.length) > 1 ? `${axisType}1` : axisType;
|
|
33173
|
+
};
|
|
33149
33174
|
const color2 = (curr == null ? void 0 : curr.color) || COLORS[i2];
|
|
33150
33175
|
const type = (curr == null ? void 0 : curr.type) || "line";
|
|
33151
33176
|
const adjustScaleRange2 = curr == null ? void 0 : curr.adjustScaleRange;
|
|
@@ -33175,7 +33200,7 @@ const generateAnnotations = (options, state) => {
|
|
|
33175
33200
|
const annotation2 = {
|
|
33176
33201
|
...curr,
|
|
33177
33202
|
id: `${curr == null ? void 0 : curr.label}-${curr == null ? void 0 : curr.value}-${i2}`,
|
|
33178
|
-
scaleID,
|
|
33203
|
+
scaleID: getScaleId(),
|
|
33179
33204
|
label,
|
|
33180
33205
|
backgroundColor: color2,
|
|
33181
33206
|
borderColor,
|
|
@@ -34516,7 +34541,7 @@ const getDefaultProps = (props) => {
|
|
|
34516
34541
|
};
|
|
34517
34542
|
return chart2;
|
|
34518
34543
|
};
|
|
34519
|
-
const getBarChartAxis = (chart2, axisType, currentScales) => {
|
|
34544
|
+
const getBarChartAxis = (chart2, axisType, currentScales, i2) => {
|
|
34520
34545
|
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2;
|
|
34521
34546
|
const isDirectionVertical = isVertical(chart2.options.direction);
|
|
34522
34547
|
const axisData = currentScales || chart2.options.axes[axisType][0];
|
|
@@ -34532,18 +34557,26 @@ const getBarChartAxis = (chart2, axisType, currentScales) => {
|
|
|
34532
34557
|
return axisType === axisWithReverse ? chart2.options.additionalAxesOptions.reverse : false;
|
|
34533
34558
|
};
|
|
34534
34559
|
const getTicks = () => {
|
|
34535
|
-
|
|
34536
|
-
|
|
34537
|
-
|
|
34538
|
-
|
|
34539
|
-
|
|
34540
|
-
|
|
34541
|
-
|
|
34542
|
-
|
|
34543
|
-
|
|
34544
|
-
stepSize: axisData.stepSize
|
|
34545
|
-
}
|
|
34546
|
-
|
|
34560
|
+
var _a3, _b3, _c3, _d3;
|
|
34561
|
+
const additionalAxesOptions = (_a3 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a3.additionalAxesOptions;
|
|
34562
|
+
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;
|
|
34563
|
+
const isLogarithmic = isDirectionCompatibleWithAxisType && additionalAxesOptions.chartScaleType === ScaleType.Logarithmic;
|
|
34564
|
+
const ticksFormattingCallback = (tick, _index, ticks2) => {
|
|
34565
|
+
return isLogarithmic ? LOGARITHMIC_STEPS.includes(tick) ? formatAxisLabelNumbers(tick, ticks2) : "" : formatAxisLabelNumbers(tick, ticks2);
|
|
34566
|
+
};
|
|
34567
|
+
const ticks = {
|
|
34568
|
+
...!isLogarithmic ? {
|
|
34569
|
+
stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null)
|
|
34570
|
+
} : {},
|
|
34571
|
+
callback: ticksFormattingCallback,
|
|
34572
|
+
includeBounds: false,
|
|
34573
|
+
//OW-10088 disable irregular axis ticks
|
|
34574
|
+
...ticksConfigFromProps,
|
|
34575
|
+
font: {
|
|
34576
|
+
size: 14
|
|
34577
|
+
}
|
|
34578
|
+
};
|
|
34579
|
+
return ticks;
|
|
34547
34580
|
};
|
|
34548
34581
|
return {
|
|
34549
34582
|
type: getScaleType(),
|
|
@@ -34573,9 +34606,8 @@ const getBarChartAxes = (chart2, axisType) => {
|
|
|
34573
34606
|
const color2 = curr.color || COLORS[i2] || generateRandomColor$1(COLORS);
|
|
34574
34607
|
axisData.color = color2;
|
|
34575
34608
|
axisData.position = curr.position || getAxisPosition(axisType, i2);
|
|
34576
|
-
const axis = getBarChartAxis(chart2, axisType, axisData);
|
|
34577
|
-
|
|
34578
|
-
return { ...acc, [axisId]: axis };
|
|
34609
|
+
const axis = getBarChartAxis(chart2, axisType, axisData, i2);
|
|
34610
|
+
return { ...acc, [axisType + (i2 + 1)]: axis };
|
|
34579
34611
|
}, {});
|
|
34580
34612
|
return axes;
|
|
34581
34613
|
};
|
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-2",
|
|
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": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@oliasoft-open-source/react-ui-library": "^3.6.5",
|
|
53
|
-
"@oliasoft-open-source/units": "^
|
|
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",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@oliasoft-open-source/react-ui-library": "^3.6.5",
|
|
96
|
-
"@oliasoft-open-source/units": "^
|
|
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",
|