@oliasoft-open-source/charts-library 8.0.2 → 8.0.4-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 +55 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35817,13 +35817,13 @@ var isCalloutAnchorInChartArea = (ctx, refAnnotation, margin = 0) => {
|
|
|
35817
35817
|
};
|
|
35818
35818
|
//#endregion
|
|
35819
35819
|
//#region src/components/common/plugins/annotation-dragger-plugin/annotation-position-storage.ts
|
|
35820
|
-
var STORAGE_PREFIX = "chart_annotations";
|
|
35821
|
-
var getStorageKey = (persistenceId) => {
|
|
35822
|
-
return `${STORAGE_PREFIX}:${persistenceId}`;
|
|
35820
|
+
var STORAGE_PREFIX$1 = "chart_annotations";
|
|
35821
|
+
var getStorageKey$1 = (persistenceId) => {
|
|
35822
|
+
return `${STORAGE_PREFIX$1}:${persistenceId}`;
|
|
35823
35823
|
};
|
|
35824
|
-
var readStorage = (persistenceId) => {
|
|
35824
|
+
var readStorage$1 = (persistenceId) => {
|
|
35825
35825
|
try {
|
|
35826
|
-
const raw = window.localStorage.getItem(getStorageKey(persistenceId));
|
|
35826
|
+
const raw = window.localStorage.getItem(getStorageKey$1(persistenceId));
|
|
35827
35827
|
if (!raw) return {};
|
|
35828
35828
|
const json = JSON.parse(raw);
|
|
35829
35829
|
return typeof json === "object" && json !== null ? json : {};
|
|
@@ -35831,15 +35831,15 @@ var readStorage = (persistenceId) => {
|
|
|
35831
35831
|
return {};
|
|
35832
35832
|
}
|
|
35833
35833
|
};
|
|
35834
|
-
var writeStorage = (persistenceId, data) => {
|
|
35834
|
+
var writeStorage$1 = (persistenceId, data) => {
|
|
35835
35835
|
try {
|
|
35836
|
-
window.localStorage.setItem(getStorageKey(persistenceId), JSON.stringify(data));
|
|
35836
|
+
window.localStorage.setItem(getStorageKey$1(persistenceId), JSON.stringify(data));
|
|
35837
35837
|
} catch {}
|
|
35838
35838
|
};
|
|
35839
35839
|
var setAnnotationPosition = (persistenceId, annotationId, pos) => {
|
|
35840
35840
|
if (!persistenceId) return;
|
|
35841
|
-
const current = readStorage(persistenceId);
|
|
35842
|
-
writeStorage(persistenceId, {
|
|
35841
|
+
const current = readStorage$1(persistenceId);
|
|
35842
|
+
writeStorage$1(persistenceId, {
|
|
35843
35843
|
...current,
|
|
35844
35844
|
[annotationId]: {
|
|
35845
35845
|
...current[annotationId] ?? {},
|
|
@@ -35849,7 +35849,7 @@ var setAnnotationPosition = (persistenceId, annotationId, pos) => {
|
|
|
35849
35849
|
};
|
|
35850
35850
|
var getAnnotationPosition = (persistenceId, annotationId) => {
|
|
35851
35851
|
if (!persistenceId) return void 0;
|
|
35852
|
-
return readStorage(persistenceId)[annotationId];
|
|
35852
|
+
return readStorage$1(persistenceId)[annotationId];
|
|
35853
35853
|
};
|
|
35854
35854
|
//#endregion
|
|
35855
35855
|
//#region src/components/common/helpers/get-chart-from-ctx.ts
|
|
@@ -38436,15 +38436,48 @@ var LegendDropZones = (legendDropZonesProps) => {
|
|
|
38436
38436
|
});
|
|
38437
38437
|
};
|
|
38438
38438
|
//#endregion
|
|
38439
|
+
//#region src/components/common/legend-component/legend-position-storage.ts
|
|
38440
|
+
var STORAGE_PREFIX = "chart_legend_position";
|
|
38441
|
+
var getStorageKey = (persistenceId) => {
|
|
38442
|
+
return `${STORAGE_PREFIX}:${persistenceId}`;
|
|
38443
|
+
};
|
|
38444
|
+
var isPosition = (value) => {
|
|
38445
|
+
return Object.values(Position).includes(String(value));
|
|
38446
|
+
};
|
|
38447
|
+
var readStorage = (persistenceId) => {
|
|
38448
|
+
try {
|
|
38449
|
+
const raw = window.localStorage.getItem(getStorageKey(persistenceId));
|
|
38450
|
+
if (!raw) return void 0;
|
|
38451
|
+
const parsed = JSON.parse(raw);
|
|
38452
|
+
return isPosition(parsed) ? parsed : void 0;
|
|
38453
|
+
} catch {
|
|
38454
|
+
return;
|
|
38455
|
+
}
|
|
38456
|
+
};
|
|
38457
|
+
var writeStorage = (persistenceId, position) => {
|
|
38458
|
+
try {
|
|
38459
|
+
window.localStorage.setItem(getStorageKey(persistenceId), JSON.stringify(position));
|
|
38460
|
+
} catch {}
|
|
38461
|
+
};
|
|
38462
|
+
var setLegendPosition = (persistenceId, position) => {
|
|
38463
|
+
if (!persistenceId) return;
|
|
38464
|
+
writeStorage(persistenceId, position);
|
|
38465
|
+
};
|
|
38466
|
+
var getLegendPosition = (persistenceId) => {
|
|
38467
|
+
if (!persistenceId) return void 0;
|
|
38468
|
+
return readStorage(persistenceId);
|
|
38469
|
+
};
|
|
38470
|
+
//#endregion
|
|
38439
38471
|
//#region src/components/common/legend-component/legend.tsx
|
|
38440
|
-
var Legend = ({ chartRef, legendConfig }) => {
|
|
38472
|
+
var Legend = ({ chartRef, legendConfig, persistenceId }) => {
|
|
38441
38473
|
const chart = chartRef?.current;
|
|
38442
38474
|
const [chartArea, setChartArea] = useState(chart?.chartArea);
|
|
38443
38475
|
const { options: { legend } } = legendConfig ?? {};
|
|
38444
38476
|
const [measureRef, measureRect] = useMeasure();
|
|
38445
38477
|
const resizeRef = measureRef;
|
|
38446
38478
|
const panelRef = useRef(null);
|
|
38447
|
-
const [legendPosition, setLegendPosition] = useState(legend?.position || Position.BottomLeft);
|
|
38479
|
+
const [legendPosition, setLegendPosition$1] = useState(() => getLegendPosition(persistenceId) || legend?.position || Position.BottomLeft);
|
|
38480
|
+
const [prevLegendPositionProp, setPrevLegendPositionProp] = useState(legend?.position);
|
|
38448
38481
|
const panelRect = panelRef?.current ? panelRef.current.getBoundingClientRect() : null;
|
|
38449
38482
|
const panelSize = {
|
|
38450
38483
|
width: panelRect?.width,
|
|
@@ -38460,6 +38493,14 @@ var Legend = ({ chartRef, legendConfig }) => {
|
|
|
38460
38493
|
}, 20);
|
|
38461
38494
|
return () => clearTimeout(timeout);
|
|
38462
38495
|
}, [chart?.chartArea, measureRect]);
|
|
38496
|
+
if (legend?.position && legend.position !== prevLegendPositionProp) {
|
|
38497
|
+
setPrevLegendPositionProp(legend.position);
|
|
38498
|
+
setLegendPosition$1(legend.position);
|
|
38499
|
+
}
|
|
38500
|
+
const handleLegendPositionChange = (position) => {
|
|
38501
|
+
setLegendPosition$1(position);
|
|
38502
|
+
setLegendPosition(persistenceId, position);
|
|
38503
|
+
};
|
|
38463
38504
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
38464
38505
|
/* @__PURE__ */ jsx("div", {
|
|
38465
38506
|
ref: resizeRef,
|
|
@@ -38477,7 +38518,7 @@ var Legend = ({ chartRef, legendConfig }) => {
|
|
|
38477
38518
|
}),
|
|
38478
38519
|
/* @__PURE__ */ jsx(LegendDropZones, {
|
|
38479
38520
|
chartArea,
|
|
38480
|
-
setLegendPosition:
|
|
38521
|
+
setLegendPosition: handleLegendPositionChange,
|
|
38481
38522
|
isDragging,
|
|
38482
38523
|
placeholderSize: panelSize
|
|
38483
38524
|
}, measureRect.width)
|
|
@@ -38568,6 +38609,7 @@ var LineChart = (props) => {
|
|
|
38568
38609
|
plugins: usePlugins
|
|
38569
38610
|
}), showCustomLegend && !!generatedDatasets.length && /* @__PURE__ */ jsx(Legend, {
|
|
38570
38611
|
chartRef,
|
|
38612
|
+
persistenceId,
|
|
38571
38613
|
legendConfig: {
|
|
38572
38614
|
options,
|
|
38573
38615
|
generatedDatasets,
|
package/package.json
CHANGED