@oliasoft-open-source/charts-library 4.8.0-beta-4 → 4.8.0-beta-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 CHANGED
@@ -22856,18 +22856,6 @@ const setDefaultTheme = () => {
22856
22856
  defaults$2.color = DEFAULT_COLOR;
22857
22857
  defaults$2.borderColor = BORDER_COLOR;
22858
22858
  };
22859
- const isNilOrEmpty = (value) => {
22860
- if (value === null || value === void 0 || value === "") {
22861
- return true;
22862
- }
22863
- if (Array.isArray(value) && value.length === 0) {
22864
- return true;
22865
- }
22866
- if (typeof value === "object" && Object.keys(value).length === 0) {
22867
- return true;
22868
- }
22869
- return false;
22870
- };
22871
22859
  const isLessThanMax = (value, max) => {
22872
22860
  return value === void 0 || max === void 0 || Number(value) < Number(max);
22873
22861
  };
@@ -22887,10 +22875,6 @@ const generateKey = (values) => {
22887
22875
  return key;
22888
22876
  };
22889
22877
  const isPrimitiveValue = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
22890
- const isRangeValid = (r2) => {
22891
- if (!r2) return false;
22892
- return Object.values(r2).some((value) => !isNilOrEmpty(value));
22893
- };
22894
22878
  const getChartStateFromStorage = (persistenceId) => {
22895
22879
  if (!persistenceId) return null;
22896
22880
  const chartStateKey = `line-chart-state-${persistenceId}`;
@@ -22901,37 +22885,6 @@ const getChartStateFromStorage = (persistenceId) => {
22901
22885
  }
22902
22886
  return null;
22903
22887
  };
22904
- const removeExpiredChartStates = (maxAgeInHours = 72) => {
22905
- const currentTime = (/* @__PURE__ */ new Date()).getTime();
22906
- const maxAgeInMilliseconds = maxAgeInHours * 60 * 60 * 1e3;
22907
- for (let i2 = 0; i2 < localStorage.length; i2++) {
22908
- const key = localStorage.key(i2);
22909
- if (key == null ? void 0 : key.includes("line-chart-state-")) {
22910
- const chartStateObjectJSON = localStorage.getItem(key);
22911
- if (chartStateObjectJSON) {
22912
- const chartStateObject = JSON.parse(chartStateObjectJSON);
22913
- const storedTime = chartStateObject.timestamp;
22914
- if (storedTime) {
22915
- const ageInMilliseconds = currentTime - storedTime;
22916
- if (ageInMilliseconds > maxAgeInMilliseconds) {
22917
- localStorage.removeItem(key);
22918
- }
22919
- }
22920
- }
22921
- }
22922
- }
22923
- };
22924
- const storeChartStateInStorage = (state, persistenceId) => {
22925
- if (!persistenceId) return;
22926
- const currentTime = (/* @__PURE__ */ new Date()).getTime();
22927
- const chartStateKey = `line-chart-state-${persistenceId}`;
22928
- const chartStateObject = {
22929
- state,
22930
- timestamp: currentTime
22931
- };
22932
- localStorage.setItem(chartStateKey, JSON.stringify(chartStateObject));
22933
- removeExpiredChartStates();
22934
- };
22935
22888
  const initialState = ({ options, persistenceId }) => {
22936
22889
  const {
22937
22890
  additionalAxesOptions: { range: customAxesRange = {} },
@@ -25074,8 +25027,7 @@ var CUSTOM_OPTION = /* @__PURE__ */ ((CUSTOM_OPTION2) => {
25074
25027
  return CUSTOM_OPTION2;
25075
25028
  })(CUSTOM_OPTION || {});
25076
25029
  const generateLineChartDatasets = (datasets, state, options, { label }) => {
25077
- var _a2, _b2;
25078
- const copyDataset = datasets ?? [];
25030
+ const copyDataset = [...datasets ?? []];
25079
25031
  const { annotations, graph } = options ?? {};
25080
25032
  const {
25081
25033
  controlAnnotation,
@@ -25083,14 +25035,12 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25083
25035
  annotationsData = []
25084
25036
  } = annotations ?? {};
25085
25037
  if (controlAnnotation && showAnnotations) {
25086
- let index2 = 0;
25087
- while (index2 < annotationsData.length) {
25088
- const ann = annotationsData[index2];
25038
+ const annotationDatasets = annotationsData.map((ann, index2) => {
25089
25039
  const { type, ...annotation2 } = ann;
25090
25040
  const color2 = annotation2.color ?? COLORS[index2];
25091
25041
  const borderDash = ANNOTATION_DASH;
25092
25042
  const borderWidth = BORDER_WIDTH.INITIAL;
25093
- copyDataset.push({
25043
+ return {
25094
25044
  ...annotation2,
25095
25045
  isAnnotation: true,
25096
25046
  annotationType: type,
@@ -25102,14 +25052,12 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25102
25052
  borderDash,
25103
25053
  borderWidth,
25104
25054
  data: [{}]
25105
- });
25106
- index2++;
25107
- }
25055
+ };
25056
+ });
25057
+ copyDataset.push(...annotationDatasets);
25108
25058
  }
25109
- const result = new Array(copyDataset.length);
25110
- let i2 = 0;
25111
- while (i2 < copyDataset.length) {
25112
- const line = copyDataset[i2];
25059
+ return copyDataset == null ? void 0 : copyDataset.map((line, i2) => {
25060
+ var _a2, _b2;
25113
25061
  const {
25114
25062
  formation,
25115
25063
  data = [],
@@ -25136,9 +25084,9 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25136
25084
  data[2].x = Math.min(axesMax, endPoint.x);
25137
25085
  }
25138
25086
  }
25139
- const filteredData = (data == null ? void 0 : data.length) ? data == null ? void 0 : data.filter(Boolean) : [];
25140
25087
  const hasCustomOpt = checkCustomOption(line, CUSTOM_OPTION);
25141
- const isSinglePoint = filteredData.length === 1;
25088
+ const filteredData = data.filter(Boolean) || [];
25089
+ const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
25142
25090
  let pointState, lineState;
25143
25091
  if (customShowPoints !== void 0) {
25144
25092
  pointState = customShowPoints;
@@ -25154,19 +25102,17 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25154
25102
  } else {
25155
25103
  lineState = lineEnabled;
25156
25104
  }
25157
- const parsedPointRadius = typeof pointRadiusProp === "string" ? parseFloat(pointRadiusProp) : pointRadiusProp;
25158
- const linePointRadius = parsedPointRadius || DEFAULT_POINT_RADIUS;
25159
- const parsedHoverRadius = typeof pointHoverRadius === "string" ? parseFloat(pointHoverRadius) : pointHoverRadius;
25160
- const hoverRadius = parsedHoverRadius || DEFAULT_HOVER_RADIUS;
25105
+ const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
25106
+ const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
25161
25107
  const indexedColor = COLORS[i2];
25162
- result[i2] = {
25108
+ return {
25163
25109
  ...line,
25164
25110
  label: (line == null ? void 0 : line.label) ?? `${label} ${i2 + 1}`,
25165
25111
  data: filteredData,
25166
25112
  showLine: lineState,
25167
25113
  lineTension: (line == null ? void 0 : line.lineTension) ?? lineTension,
25168
25114
  spanGaps,
25169
- borderWidth: (typeof borderWidth === "string" ? parseFloat(borderWidth) : borderWidth) || DEFAULT_BORDER_WIDTH,
25115
+ borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
25170
25116
  borderDash: borderDash || [],
25171
25117
  borderJoinStyle: BORDER_JOIN_STYLE,
25172
25118
  borderColor: borderColor ?? indexedColor ?? generateRandomColor(COLORS),
@@ -25177,9 +25123,7 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25177
25123
  pointHitRadius: (line == null ? void 0 : line.pointHitRadius) ?? hoverRadius,
25178
25124
  ...hasCustomOpt ? { hasCustomOpt } : {}
25179
25125
  };
25180
- i2++;
25181
- }
25182
- return result;
25126
+ });
25183
25127
  };
25184
25128
  const getAnnotationsData = (data) => {
25185
25129
  return data == null ? void 0 : data.reduce((acc, obj) => {
@@ -26042,6 +25986,11 @@ const useChartOptions = ({
26042
25986
  chartAreaBorder: {
26043
25987
  borderColor: BORDER_COLOR
26044
25988
  },
25989
+ decimation: {
25990
+ enabled: true,
25991
+ algorithm: "lttb",
25992
+ samples: 200
25993
+ },
26045
25994
  chartAreaText: {
26046
25995
  showLabel,
26047
25996
  text,
@@ -26115,122 +26064,6 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
26115
26064
  ];
26116
26065
  }, [handleDoubleClick]);
26117
26066
  };
26118
- const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
26119
- var _a2, _b2;
26120
- useEffect(() => {
26121
- var _a3, _b3;
26122
- if ((_b3 = (_a3 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a3.customLegend) == null ? void 0 : _b3.customLegendPlugin) {
26123
- const parent = document.getElementById(
26124
- memoOptions.legend.customLegend.customLegendContainerID
26125
- );
26126
- if (parent !== null) {
26127
- parent.style.visibility = memoState.legendEnabled ? "visible" : "hidden";
26128
- }
26129
- }
26130
- }, [
26131
- (_b2 = (_a2 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendPlugin,
26132
- memoState.legendEnabled
26133
- ]);
26134
- };
26135
- const useStoreChartStateInStorage = (memoState, persistenceId) => {
26136
- useEffect(() => {
26137
- storeChartStateInStorage(memoState, persistenceId);
26138
- }, [
26139
- memoState.panEnabled,
26140
- memoState.lineEnabled,
26141
- memoState.pointsEnabled,
26142
- memoState.legendEnabled,
26143
- memoState.enableDragPoints,
26144
- memoState.zoomEnabled
26145
- ]);
26146
- };
26147
- const useUpdateAxesRanges = ({
26148
- chartRef,
26149
- range,
26150
- state,
26151
- dispatch,
26152
- annotationsData
26153
- }) => {
26154
- const prevAxes = useRef(state.axes);
26155
- useEffect(() => {
26156
- if (range && isRangeValid(range)) {
26157
- const newAxes = Object.entries(range).map(([key, { min, max }]) => {
26158
- const { min: minFromData = 0, max: maxFromData = 0 } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
26159
- return {
26160
- id: key,
26161
- min: min ?? minFromData,
26162
- max: max ?? maxFromData
26163
- };
26164
- });
26165
- const mergedAxes = [...prevAxes.current ?? []].map((axis) => {
26166
- const newAxis = newAxes.find((a2) => a2.id === axis.id);
26167
- return newAxis ? { ...axis, ...newAxis } : axis;
26168
- });
26169
- if (!isEqual(mergedAxes, prevAxes.current)) {
26170
- dispatch({
26171
- type: UPDATE_AXES_RANGES,
26172
- payload: { axes: mergedAxes }
26173
- });
26174
- prevAxes.current = mergedAxes;
26175
- }
26176
- }
26177
- }, [range]);
26178
- };
26179
- const useSaveInitialAxesRanges = (chartRef, dispatch, generatedDatasets) => {
26180
- var _a2;
26181
- const prevDatasets = useRef(null);
26182
- useEffect(() => {
26183
- var _a3, _b2;
26184
- if (((_a3 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a3.scales) && !isEqual(prevDatasets.current, generatedDatasets)) {
26185
- const scales = ((_b2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _b2.scales) ?? {};
26186
- const initialAxesRanges = Object.entries(scales).map(
26187
- ([id, { min, max, _range: range }]) => ({
26188
- id,
26189
- min: (range == null ? void 0 : range.min) ?? min,
26190
- max: (range == null ? void 0 : range.max) ?? max
26191
- })
26192
- );
26193
- dispatch({
26194
- type: SAVE_INITIAL_AXES_RANGES,
26195
- payload: { initialAxesRanges }
26196
- });
26197
- prevDatasets.current = generatedDatasets;
26198
- }
26199
- }, [(_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.scales, generatedDatasets]);
26200
- };
26201
- const useChartState = ({
26202
- chartRef,
26203
- options,
26204
- state,
26205
- dispatch,
26206
- persistenceId,
26207
- generatedDatasets
26208
- }) => {
26209
- useEffect(() => {
26210
- return () => {
26211
- if (chartRef == null ? void 0 : chartRef.current) {
26212
- const chart2 = chartRef == null ? void 0 : chartRef.current;
26213
- chart2 == null ? void 0 : chart2.destroy();
26214
- }
26215
- };
26216
- }, []);
26217
- const memoState = useMemo(() => state, [state]);
26218
- const memoOptions = useMemo(() => options, [options]);
26219
- const {
26220
- additionalAxesOptions: { range = void 0 },
26221
- annotations: { annotationsData = [] } = {}
26222
- } = memoOptions;
26223
- useStoreChartStateInStorage(memoState, persistenceId);
26224
- useToggleCustomLegendVisibility(memoState, memoOptions);
26225
- useUpdateAxesRanges({
26226
- range,
26227
- state: memoState,
26228
- dispatch,
26229
- chartRef,
26230
- annotationsData
26231
- });
26232
- useSaveInitialAxesRanges(chartRef, dispatch, generatedDatasets);
26233
- };
26234
26067
  const WORD_SEPARATOR = " ";
26235
26068
  const SEMI_TRANSPARENT = "rgba(0, 0, 0, 0.5)";
26236
26069
  const getWords = (text) => {
@@ -27325,14 +27158,6 @@ const LineChart = (props) => {
27325
27158
  );
27326
27159
  return result;
27327
27160
  }, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
27328
- useChartState({
27329
- chartRef,
27330
- options,
27331
- state,
27332
- dispatch,
27333
- persistenceId,
27334
- generatedDatasets
27335
- });
27336
27161
  const { resetZoom: resetZoom2, handleKeyDown, handleKeyUp } = useChartFunctions({
27337
27162
  chartRef,
27338
27163
  state,