@oliasoft-open-source/charts-library 3.4.5-beta-2 → 3.4.6
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 +98 -99
- package/dist/index.js.map +1 -1
- package/dist/src/components/bar-chart/get-bar-chart-tooltips.d.ts +3 -0
- package/dist/src/components/controls/axes-options/axes-options.d.ts +6 -0
- package/dist/src/components/line-chart/utils/axis-scales/axis-scales.d.ts +1 -1
- package/dist/src/components/line-chart/utils/get-annotations-data.d.ts +1 -0
- package/dist/src/components/line-chart/utils/get-axes-data-from-metasets.d.ts +1 -0
- package/dist/src/components/line-chart/utils/get-line-chart-tooltips.d.ts +5 -0
- package/dist/src/helpers/chart-consts.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13161,7 +13161,9 @@ const ANNOTATION_DASH = [10, 2];
|
|
|
13161
13161
|
const DEFAULT_FONT_SIZE = 13;
|
|
13162
13162
|
const DEFAULT_FONT_FAMILY = '"Lato", sans-serif';
|
|
13163
13163
|
const DEFAULT_COLOR = "rgba(0,0,0,.87)";
|
|
13164
|
-
const LEGEND_LABEL_BOX_SIZE =
|
|
13164
|
+
const LEGEND_LABEL_BOX_SIZE = 12;
|
|
13165
|
+
const TOOLTIP_PADDING = 8;
|
|
13166
|
+
const TOOLTIP_BOX_PADDING = 4;
|
|
13165
13167
|
const LOGARITHMIC_STEPS = [1, 10, 100, 1e3, 1e4];
|
|
13166
13168
|
const COLORS = [
|
|
13167
13169
|
"#3366cc",
|
|
@@ -22168,7 +22170,8 @@ const generateAxisId = (axisType, index2 = 0, hasMultiAxes = false) => {
|
|
|
22168
22170
|
return `${axisType}${i2}`;
|
|
22169
22171
|
};
|
|
22170
22172
|
const getAxisTypeFromKey = (string) => {
|
|
22171
|
-
|
|
22173
|
+
var _a2;
|
|
22174
|
+
return ((_a2 = string.match(/[^0-9/]+/gi)) == null ? void 0 : _a2[0]) || "";
|
|
22172
22175
|
};
|
|
22173
22176
|
const generateKey = (values) => {
|
|
22174
22177
|
const key = values.join("");
|
|
@@ -23734,17 +23737,18 @@ const reducer = (state, action) => {
|
|
|
23734
23737
|
return state;
|
|
23735
23738
|
}
|
|
23736
23739
|
};
|
|
23737
|
-
const AxesOptionsPopover = ({
|
|
23738
|
-
initialAxesRanges,
|
|
23739
|
-
axes,
|
|
23740
|
-
controlsAxesLabels,
|
|
23741
|
-
onUpdateAxes,
|
|
23742
|
-
onResetAxes,
|
|
23743
|
-
close,
|
|
23744
|
-
depthType,
|
|
23745
|
-
translations
|
|
23746
|
-
}) => {
|
|
23740
|
+
const AxesOptionsPopover = (optionsPopover) => {
|
|
23747
23741
|
var _a2;
|
|
23742
|
+
const {
|
|
23743
|
+
initialAxesRanges,
|
|
23744
|
+
axes,
|
|
23745
|
+
controlsAxesLabels,
|
|
23746
|
+
onUpdateAxes,
|
|
23747
|
+
onResetAxes,
|
|
23748
|
+
close,
|
|
23749
|
+
depthType,
|
|
23750
|
+
translations
|
|
23751
|
+
} = optionsPopover;
|
|
23748
23752
|
const [depthTypeState, setDepthTypeState] = useState(
|
|
23749
23753
|
depthType == null ? void 0 : depthType.selectedDepthType
|
|
23750
23754
|
);
|
|
@@ -23759,14 +23763,20 @@ const AxesOptionsPopover = ({
|
|
|
23759
23763
|
const { errors, valid } = validateAxes(formState);
|
|
23760
23764
|
const onEditValue = ({ name: name2, value, id }) => {
|
|
23761
23765
|
dispatch({
|
|
23762
|
-
type: actionTypes.
|
|
23766
|
+
type: actionTypes.ValueUpdated,
|
|
23767
|
+
payload: { name: name2, value, id }
|
|
23768
|
+
});
|
|
23769
|
+
};
|
|
23770
|
+
const onEditUnit = ({ name: name2, value, id }) => {
|
|
23771
|
+
dispatch({
|
|
23772
|
+
type: actionTypes.UnitUpdated,
|
|
23763
23773
|
payload: { name: name2, value, id }
|
|
23764
23774
|
});
|
|
23765
23775
|
};
|
|
23766
23776
|
const onDone = (e2) => {
|
|
23767
23777
|
e2.preventDefault();
|
|
23768
23778
|
if (valid) {
|
|
23769
|
-
const sanitizedFormState = formState.map((axis
|
|
23779
|
+
const sanitizedFormState = formState.map((axis) => ({
|
|
23770
23780
|
...axis,
|
|
23771
23781
|
min: toNum(axis.min),
|
|
23772
23782
|
max: toNum(axis.max)
|
|
@@ -23774,6 +23784,13 @@ const AxesOptionsPopover = ({
|
|
|
23774
23784
|
onUpdateAxes({
|
|
23775
23785
|
axes: sanitizedFormState
|
|
23776
23786
|
});
|
|
23787
|
+
sanitizedFormState.forEach((el, i2) => {
|
|
23788
|
+
var _a3, _b2, _c2;
|
|
23789
|
+
const selectedUnit = (_a3 = el.unit) == null ? void 0 : _a3.selectedUnit;
|
|
23790
|
+
if (selectedUnit) {
|
|
23791
|
+
(_c2 = (_b2 = axes == null ? void 0 : axes[i2]) == null ? void 0 : _b2.unit) == null ? void 0 : _c2.setSelectedUnit(selectedUnit);
|
|
23792
|
+
}
|
|
23793
|
+
});
|
|
23777
23794
|
if (depthType) {
|
|
23778
23795
|
depthType.setSelectedDepthType(depthTypeState);
|
|
23779
23796
|
}
|
|
@@ -23782,13 +23799,14 @@ const AxesOptionsPopover = ({
|
|
|
23782
23799
|
};
|
|
23783
23800
|
const onReset = () => {
|
|
23784
23801
|
dispatch({
|
|
23785
|
-
type: actionTypes.
|
|
23802
|
+
type: actionTypes.Reset,
|
|
23786
23803
|
payload: { axes, initialAxesRanges }
|
|
23787
23804
|
});
|
|
23788
|
-
initialAxesRanges.
|
|
23789
|
-
var _a3;
|
|
23790
|
-
|
|
23791
|
-
|
|
23805
|
+
initialAxesRanges.forEach((el, i2) => {
|
|
23806
|
+
var _a3, _b2, _c2;
|
|
23807
|
+
const selectedUnit = (_a3 = el == null ? void 0 : el.unit) == null ? void 0 : _a3.selectedUnit;
|
|
23808
|
+
if (selectedUnit) {
|
|
23809
|
+
(_c2 = (_b2 = axes == null ? void 0 : axes[i2]) == null ? void 0 : _b2.unit) == null ? void 0 : _c2.setSelectedUnit(selectedUnit);
|
|
23792
23810
|
}
|
|
23793
23811
|
});
|
|
23794
23812
|
onResetAxes();
|
|
@@ -23847,10 +23865,15 @@ const AxesOptionsPopover = ({
|
|
|
23847
23865
|
name: "selectedUnit",
|
|
23848
23866
|
options: (_i2 = axis == null ? void 0 : axis.unit) == null ? void 0 : _i2.options,
|
|
23849
23867
|
value: unit == null ? void 0 : unit.selectedUnit,
|
|
23850
|
-
onChange:
|
|
23868
|
+
onChange: (e2) => {
|
|
23869
|
+
onEditUnit({
|
|
23870
|
+
name: e2.target.name,
|
|
23871
|
+
value: e2.target.value,
|
|
23872
|
+
id: axis.id
|
|
23873
|
+
});
|
|
23874
|
+
},
|
|
23851
23875
|
autoLayerWidth: true,
|
|
23852
|
-
width: "15%"
|
|
23853
|
-
native: true
|
|
23876
|
+
width: "15%"
|
|
23854
23877
|
}
|
|
23855
23878
|
) : null
|
|
23856
23879
|
] }) }, i2);
|
|
@@ -23897,15 +23920,16 @@ const AxesOptionsPopover = ({
|
|
|
23897
23920
|
] })
|
|
23898
23921
|
] });
|
|
23899
23922
|
};
|
|
23900
|
-
const AxesOptions = ({
|
|
23901
|
-
|
|
23902
|
-
|
|
23903
|
-
|
|
23904
|
-
|
|
23905
|
-
|
|
23906
|
-
|
|
23907
|
-
|
|
23908
|
-
|
|
23923
|
+
const AxesOptions = (optionsPopover) => {
|
|
23924
|
+
const {
|
|
23925
|
+
initialAxesRanges,
|
|
23926
|
+
axes,
|
|
23927
|
+
controlsAxesLabels,
|
|
23928
|
+
onUpdateAxes,
|
|
23929
|
+
onResetAxes,
|
|
23930
|
+
depthType,
|
|
23931
|
+
translations
|
|
23932
|
+
} = optionsPopover;
|
|
23909
23933
|
return /* @__PURE__ */ jsx(
|
|
23910
23934
|
Popover,
|
|
23911
23935
|
{
|
|
@@ -24833,77 +24857,37 @@ const getSuggestedAxisRange = ({
|
|
|
24833
24857
|
max: round$2(maxAxisValue, DECIMAL_POINT_TOLERANCE)
|
|
24834
24858
|
};
|
|
24835
24859
|
};
|
|
24836
|
-
const checkMultiAxis = (scalesKeys) => {
|
|
24837
|
-
let counts = {
|
|
24838
|
-
x: 0,
|
|
24839
|
-
y: 0
|
|
24840
|
-
};
|
|
24841
|
-
scalesKeys.forEach((axeKey) => {
|
|
24842
|
-
const key = getAxisTypeFromKey(axeKey);
|
|
24843
|
-
counts[key]++;
|
|
24844
|
-
});
|
|
24845
|
-
const res = counts.x > counts.y && AxisType.X || counts.y > counts.x && AxisType.Y || counts.x === counts.y && null;
|
|
24846
|
-
return res;
|
|
24847
|
-
};
|
|
24848
24860
|
const getAnnotationsData = (data) => {
|
|
24849
|
-
return data.reduce((acc, obj) => {
|
|
24861
|
+
return data == null ? void 0 : data.reduce((acc, obj) => {
|
|
24850
24862
|
return {
|
|
24851
24863
|
...acc,
|
|
24852
24864
|
[obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
|
|
24853
24865
|
};
|
|
24854
24866
|
}, {});
|
|
24855
24867
|
};
|
|
24856
|
-
const
|
|
24857
|
-
|
|
24858
|
-
|
|
24859
|
-
return
|
|
24860
|
-
|
|
24861
|
-
|
|
24862
|
-
|
|
24863
|
-
|
|
24864
|
-
|
|
24865
|
-
|
|
24866
|
-
|
|
24867
|
-
}
|
|
24868
|
-
};
|
|
24869
|
-
const getDataForMultiAxes = () => {
|
|
24870
|
-
const multiAxesKey = checkMultiAxis(scalesKeys);
|
|
24871
|
-
const axes = (scalesKeys == null ? void 0 : scalesKeys.filter((key) => key == null ? void 0 : key.includes(multiAxesKey))) ?? [];
|
|
24872
|
-
const data = getAnnotationsData(annotationsData);
|
|
24873
|
-
const [first, second] = axes;
|
|
24874
|
-
const reduceData = (arr, key) => arr.reduce((acc, { [key]: value }) => [...acc, value], []);
|
|
24875
|
-
return datasets.reduce(
|
|
24876
|
-
(acc, obj) => {
|
|
24877
|
-
const key = Object.values(obj).find((val) => axes.includes(val)) ?? multiAxesKey;
|
|
24878
|
-
return key ? {
|
|
24879
|
-
...acc,
|
|
24880
|
-
[key]: [
|
|
24881
|
-
.../* @__PURE__ */ new Set([
|
|
24882
|
-
...acc[key],
|
|
24883
|
-
...reduceData(obj == null ? void 0 : obj.data, multiAxesKey),
|
|
24884
|
-
...key === multiAxesKey && (data == null ? void 0 : data[multiAxesKey]) || []
|
|
24885
|
-
])
|
|
24886
|
-
]
|
|
24887
|
-
} : acc;
|
|
24888
|
-
},
|
|
24889
|
-
{ [first]: [], [second]: [] }
|
|
24890
|
-
);
|
|
24891
|
-
};
|
|
24892
|
-
return {
|
|
24893
|
-
...getData(),
|
|
24894
|
-
...getDataForMultiAxes()
|
|
24895
|
-
};
|
|
24868
|
+
const getAxesDataFromMetasets = (chartRef, scalesKeys, annotationsData) => {
|
|
24869
|
+
var _a2;
|
|
24870
|
+
if (!chartRef || !scalesKeys)
|
|
24871
|
+
return {};
|
|
24872
|
+
const metasets = ((_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.getSortedVisibleDatasetMetas()) ?? [];
|
|
24873
|
+
const annotData = getAnnotationsData(annotationsData);
|
|
24874
|
+
return metasets && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
24875
|
+
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]) ?? []);
|
|
24876
|
+
return {
|
|
24877
|
+
...acc,
|
|
24878
|
+
[key]: [...new Set(data)]
|
|
24879
|
+
};
|
|
24880
|
+
}, {}));
|
|
24896
24881
|
};
|
|
24897
|
-
const autoScale = (options, state, generatedDatasets) => {
|
|
24898
|
-
const { additionalAxesOptions = {}, annotations = {} } = options || {};
|
|
24899
|
-
const { annotationsData = [] } = annotations || {};
|
|
24882
|
+
const autoScale = (options, state, generatedDatasets, chartRef) => {
|
|
24883
|
+
const { additionalAxesOptions = {}, annotations: { annotationsData } = {} } = options || {};
|
|
24900
24884
|
const scales = getLineChartScales(options, state) || {};
|
|
24901
24885
|
if (!(additionalAxesOptions == null ? void 0 : additionalAxesOptions.autoAxisPadding) && !estimateDataSeriesHaveCloseValues(generatedDatasets)) {
|
|
24902
24886
|
return scales;
|
|
24903
24887
|
}
|
|
24904
24888
|
const scalesKeys = Object.keys(scales) ?? [];
|
|
24905
|
-
const data =
|
|
24906
|
-
const adjustedScales = scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
24889
|
+
const data = getAxesDataFromMetasets(chartRef, scalesKeys, annotationsData);
|
|
24890
|
+
const adjustedScales = data && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
24907
24891
|
const { min: propMin = void 0, max: propMax = void 0 } = scales[key];
|
|
24908
24892
|
const { min, max } = getSuggestedAxisRange({
|
|
24909
24893
|
data: data[key],
|
|
@@ -24918,7 +24902,7 @@ const autoScale = (options, state, generatedDatasets) => {
|
|
|
24918
24902
|
}
|
|
24919
24903
|
};
|
|
24920
24904
|
return { ...acc, ...res };
|
|
24921
|
-
}, {});
|
|
24905
|
+
}, {}));
|
|
24922
24906
|
return adjustedScales ?? scales;
|
|
24923
24907
|
};
|
|
24924
24908
|
const getCondition = (x2, y2, left2, right2, bottom2) => {
|
|
@@ -25037,6 +25021,11 @@ const getAnnotation = (options, state) => {
|
|
|
25037
25021
|
const annotations = shouldGenerateAnnotations ? generateAnnotations(options, state) : null;
|
|
25038
25022
|
return { annotations };
|
|
25039
25023
|
};
|
|
25024
|
+
const getUnitsFromLabel = (label) => {
|
|
25025
|
+
const matches = label.match(/\[(.*)\]/g);
|
|
25026
|
+
const units = matches && matches.length > 0 ? matches[0] : "";
|
|
25027
|
+
return units;
|
|
25028
|
+
};
|
|
25040
25029
|
const getLineChartToolTips = (options) => {
|
|
25041
25030
|
const getTooltipLabels = (dataset) => {
|
|
25042
25031
|
var _a2, _b2;
|
|
@@ -25071,7 +25060,7 @@ const getLineChartToolTips = (options) => {
|
|
|
25071
25060
|
return `${roundedValue} ${titleAxisLabel}`;
|
|
25072
25061
|
};
|
|
25073
25062
|
const labelCallback = (tooltipItem) => {
|
|
25074
|
-
const { showLabelsInTooltips
|
|
25063
|
+
const { showLabelsInTooltips } = options.tooltip;
|
|
25075
25064
|
let label = tooltipItem.dataset.label || "";
|
|
25076
25065
|
const labels = getTooltipLabels(tooltipItem.dataset);
|
|
25077
25066
|
const { valueLabel, valueAxisLabel } = labels;
|
|
@@ -25082,18 +25071,20 @@ const getLineChartToolTips = (options) => {
|
|
|
25082
25071
|
roundScientificCoefficient: 4
|
|
25083
25072
|
}) : displayNumber(labelNumber);
|
|
25084
25073
|
};
|
|
25085
|
-
const splitValueAxisLabel = valueAxisLabel.split(" ");
|
|
25086
|
-
const newValueAxisLabel = hideSimulationName ? splitValueAxisLabel[splitValueAxisLabel.length - 1] : valueAxisLabel;
|
|
25087
25074
|
const tooltipItemValue = getTooltipItemValue();
|
|
25088
|
-
const
|
|
25075
|
+
const units = getUnitsFromLabel(valueAxisLabel);
|
|
25089
25076
|
const tooltipLabel = getTooltipLabel(tooltipItem, showLabelsInTooltips);
|
|
25090
|
-
return `${label}: ${tooltipItemValue} ${
|
|
25077
|
+
return `${label}: ${tooltipItemValue} ${units} ${tooltipLabel}`;
|
|
25091
25078
|
};
|
|
25092
25079
|
return {
|
|
25093
25080
|
enabled: options.tooltip.tooltips,
|
|
25094
25081
|
mode: ChartHoverMode.Nearest,
|
|
25095
25082
|
intersect: true,
|
|
25096
|
-
padding:
|
|
25083
|
+
padding: TOOLTIP_PADDING,
|
|
25084
|
+
usePointStyle: true,
|
|
25085
|
+
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
25086
|
+
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
25087
|
+
boxPadding: TOOLTIP_BOX_PADDING,
|
|
25097
25088
|
callbacks: {
|
|
25098
25089
|
title: titleCallback,
|
|
25099
25090
|
label: labelCallback,
|
|
@@ -25180,7 +25171,7 @@ const useChartOptions = ({
|
|
|
25180
25171
|
[legendEnabled]
|
|
25181
25172
|
);
|
|
25182
25173
|
const scales = useMemo(
|
|
25183
|
-
() => autoScale(options, state, generatedDatasets),
|
|
25174
|
+
() => autoScale(options, state, generatedDatasets, chartRef),
|
|
25184
25175
|
[options, state, generatedDatasets]
|
|
25185
25176
|
);
|
|
25186
25177
|
const dragData = useMemo(
|
|
@@ -26075,7 +26066,12 @@ const PieChart = (props) => {
|
|
|
26075
26066
|
const formattedValue = Math.abs(labelValue) < 1 ? roundNumberToPrecision(labelValue, { n: 3 }) : round$2(labelValue, 3);
|
|
26076
26067
|
return `${dataLabel} ${formattedValue} ${unit}`;
|
|
26077
26068
|
}
|
|
26078
|
-
}
|
|
26069
|
+
},
|
|
26070
|
+
padding: TOOLTIP_PADDING,
|
|
26071
|
+
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
26072
|
+
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
26073
|
+
boxPadding: TOOLTIP_BOX_PADDING,
|
|
26074
|
+
usePointStyle: true
|
|
26079
26075
|
};
|
|
26080
26076
|
};
|
|
26081
26077
|
return /* @__PURE__ */ jsx(
|
|
@@ -38753,7 +38749,10 @@ const getBarChartToolTips = (options) => {
|
|
|
38753
38749
|
enabled: options.tooltip.tooltips,
|
|
38754
38750
|
mode: ChartHoverMode.Nearest,
|
|
38755
38751
|
intersect: true,
|
|
38756
|
-
padding:
|
|
38752
|
+
padding: TOOLTIP_PADDING,
|
|
38753
|
+
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
38754
|
+
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
38755
|
+
boxPadding: TOOLTIP_BOX_PADDING,
|
|
38757
38756
|
callbacks: {
|
|
38758
38757
|
title: titleCallback,
|
|
38759
38758
|
label: labelCallback,
|