@oliasoft-open-source/charts-library 4.1.1 → 4.1.3-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 +28 -7
- package/dist/index.js.map +1 -1
- package/dist/src/components/bar-chart/bar-chart-const.d.ts +2 -0
- package/dist/src/components/common/hooks/use-reset.d.ts +3 -0
- package/dist/src/components/common/legend-component/state/legend-action-types.d.ts +1 -0
- package/dist/src/components/common/legend-component/state/legend-state-reducer.d.ts +4 -1
- package/dist/src/components/line-chart/line-chart.stories.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -25099,6 +25099,7 @@ const getDraggableData = (options) => {
|
|
|
25099
25099
|
};
|
|
25100
25100
|
const UPSERT_HIDDEN_STATE = "UPSERT_HIDDEN_STATE";
|
|
25101
25101
|
const TOGGLE_ANNOTATION_VISIBILITY = "TOGGLE_ANNOTATION_VISIBILITY";
|
|
25102
|
+
const RESET_STATE = "RESET_STATE";
|
|
25102
25103
|
const legendInitialState = {
|
|
25103
25104
|
hiddenStates: [],
|
|
25104
25105
|
annotation: [],
|
|
@@ -25106,6 +25107,9 @@ const legendInitialState = {
|
|
|
25106
25107
|
};
|
|
25107
25108
|
const legendReducer = (state, action) => {
|
|
25108
25109
|
switch (action.type) {
|
|
25110
|
+
case RESET_STATE: {
|
|
25111
|
+
return action.payload;
|
|
25112
|
+
}
|
|
25109
25113
|
case UPSERT_HIDDEN_STATE: {
|
|
25110
25114
|
const { label, hidden, datasetIndex } = action.payload;
|
|
25111
25115
|
const existingIndex = state.hiddenStates.findIndex(
|
|
@@ -25229,6 +25233,15 @@ const getAnnotation = ({
|
|
|
25229
25233
|
const shouldGenerateAnnotations = showAnnotations && annotationsData && (annotationsData == null ? void 0 : annotationsData.length);
|
|
25230
25234
|
return shouldGenerateAnnotations ? generateAnnotations(annotationsData, visibleAnnotationsIndexes) ?? [] : [];
|
|
25231
25235
|
};
|
|
25236
|
+
const useReset = (state, dispatch, dependencies) => {
|
|
25237
|
+
const prevState = useRef(state);
|
|
25238
|
+
useEffect(() => {
|
|
25239
|
+
if (!isEqual(state, prevState == null ? void 0 : prevState.current)) {
|
|
25240
|
+
dispatch({ type: "RESET_STATE", payload: state });
|
|
25241
|
+
prevState.current = state;
|
|
25242
|
+
}
|
|
25243
|
+
}, [...dependencies]);
|
|
25244
|
+
};
|
|
25232
25245
|
const LegendContext = createContext$2(void 0);
|
|
25233
25246
|
const LegendProvider = ({ children, options }) => {
|
|
25234
25247
|
const { showAnnotations = true, annotationsData = [] } = (options == null ? void 0 : options.annotations) ?? {};
|
|
@@ -25247,7 +25260,11 @@ const LegendProvider = ({ children, options }) => {
|
|
|
25247
25260
|
legendReducer,
|
|
25248
25261
|
initialState2
|
|
25249
25262
|
);
|
|
25250
|
-
const contextValue = useMemo(
|
|
25263
|
+
const contextValue = useMemo(
|
|
25264
|
+
() => ({ state, dispatch }),
|
|
25265
|
+
[state, options, dispatch]
|
|
25266
|
+
);
|
|
25267
|
+
useReset(initialState2, dispatch, [options]);
|
|
25251
25268
|
return /* @__PURE__ */ jsx(LegendContext.Provider, { value: contextValue, children });
|
|
25252
25269
|
};
|
|
25253
25270
|
const useLegend = () => {
|
|
@@ -39259,6 +39276,8 @@ const getBarChartDataLabels = (options) => {
|
|
|
39259
39276
|
formatter: formatterCallback
|
|
39260
39277
|
} : { display: false };
|
|
39261
39278
|
};
|
|
39279
|
+
const DISPLAY_SCIENTIFIC_LOWER_BOUND = 1e-4;
|
|
39280
|
+
const DISPLAY_SCIENTIFIC_UPPER_BOUND = 1e7;
|
|
39262
39281
|
const getBarChartToolTips = (options) => {
|
|
39263
39282
|
var _a2;
|
|
39264
39283
|
const getTooltipLabels = (dataset) => {
|
|
@@ -39293,6 +39312,13 @@ const getBarChartToolTips = (options) => {
|
|
|
39293
39312
|
const axisLabel = !titleAxisLabel && !titleUnit ? "" : `${titleAxisLabel || titleUnit}: `;
|
|
39294
39313
|
return axisLabel + barLabel;
|
|
39295
39314
|
};
|
|
39315
|
+
const customFormatNumber2 = (labelNumber) => {
|
|
39316
|
+
let roundOptions = {};
|
|
39317
|
+
if (Math.abs(labelNumber) < DISPLAY_SCIENTIFIC_LOWER_BOUND || Math.abs(labelNumber) > DISPLAY_SCIENTIFIC_UPPER_BOUND) {
|
|
39318
|
+
roundOptions = { roundScientificCoefficient: 3 };
|
|
39319
|
+
}
|
|
39320
|
+
return displayNumber(roundByMagnitude(labelNumber), roundOptions);
|
|
39321
|
+
};
|
|
39296
39322
|
const labelCallback = (tooltipItem) => {
|
|
39297
39323
|
var _a3;
|
|
39298
39324
|
const { showLabelsInTooltips = false } = (options == null ? void 0 : options.tooltip) || {};
|
|
@@ -39303,12 +39329,7 @@ const getBarChartToolTips = (options) => {
|
|
|
39303
39329
|
const { formattedValue } = tooltipItem;
|
|
39304
39330
|
const formattedValueWithDotSeparator = formattedValue.replace(",", ".");
|
|
39305
39331
|
const labelNumber = toNum(formattedValueWithDotSeparator);
|
|
39306
|
-
|
|
39307
|
-
if (Math.abs(labelNumber) < 1) {
|
|
39308
|
-
labelNumberFormatted = labelNumber.toPrecision(3);
|
|
39309
|
-
} else {
|
|
39310
|
-
labelNumberFormatted = Number.isInteger(labelNumber) ? labelNumber : labelNumber.toFixed(3);
|
|
39311
|
-
}
|
|
39332
|
+
const labelNumberFormatted = customFormatNumber2(labelNumber);
|
|
39312
39333
|
let tooltipItemValue2 = "";
|
|
39313
39334
|
if (typeof tooltipItem.raw === "number") {
|
|
39314
39335
|
tooltipItemValue2 = labelNumberFormatted;
|