@rfkit/charts 1.1.36 → 1.1.38
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/index.js +44 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10955,15 +10955,27 @@ const ToolsBar_SeriesDisplayControl_styles_module = SeriesDisplayControl_styles_
|
|
|
10955
10955
|
const SeriesDisplayControl_SeriesDisplayControl = ()=>{
|
|
10956
10956
|
const { state: { globalID, series }, dispatch } = useStore_useStore();
|
|
10957
10957
|
const { data, legendExternal, forceDisplay } = series;
|
|
10958
|
-
const
|
|
10958
|
+
const [updateCounter, setUpdateCounter] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
|
|
10959
|
+
const dataSnapshot = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
10960
|
+
const snapshot = {};
|
|
10961
|
+
data.forEach((value, key)=>{
|
|
10962
|
+
snapshot[key] = {
|
|
10963
|
+
...value
|
|
10964
|
+
};
|
|
10965
|
+
});
|
|
10966
|
+
return snapshot;
|
|
10967
|
+
}, [
|
|
10959
10968
|
data,
|
|
10969
|
+
updateCounter
|
|
10970
|
+
]);
|
|
10971
|
+
const seriesArray = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>Object.keys(dataSnapshot).filter((name)=>!legendExternal.includes(name)).filter((name)=>name !== constants_SeriesType.TemplateData), [
|
|
10972
|
+
dataSnapshot,
|
|
10960
10973
|
legendExternal
|
|
10961
10974
|
]);
|
|
10962
|
-
const [updateCounter, setUpdateCounter] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
|
|
10963
10975
|
const seriesDataSnapshot = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
10964
10976
|
const snapshot = {};
|
|
10965
10977
|
seriesArray.forEach((name)=>{
|
|
10966
|
-
const item =
|
|
10978
|
+
const item = dataSnapshot[name];
|
|
10967
10979
|
if (item) snapshot[name] = {
|
|
10968
10980
|
display: item.display,
|
|
10969
10981
|
label: item.label || name,
|
|
@@ -10973,8 +10985,7 @@ const SeriesDisplayControl_SeriesDisplayControl = ()=>{
|
|
|
10973
10985
|
return snapshot;
|
|
10974
10986
|
}, [
|
|
10975
10987
|
seriesArray,
|
|
10976
|
-
|
|
10977
|
-
updateCounter
|
|
10988
|
+
dataSnapshot
|
|
10978
10989
|
]);
|
|
10979
10990
|
const handleDropdownClick = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
10980
10991
|
setUpdateCounter((prev)=>prev + 1);
|
|
@@ -11506,6 +11517,8 @@ const TEXT_OFFSET = 8;
|
|
|
11506
11517
|
const MINOR_TICK_DIVISIONS = 4;
|
|
11507
11518
|
const MIN_TICK_SPACING = 4;
|
|
11508
11519
|
const MIN_CONTAINER_HEIGHT = 100;
|
|
11520
|
+
const IDEAL_TICK_COUNT = 7;
|
|
11521
|
+
const MIN_RANGE_SPAN = 0.5;
|
|
11509
11522
|
function useCanvasAxisY(options = {}) {
|
|
11510
11523
|
const { ranging } = options;
|
|
11511
11524
|
const { state: { axisY } } = useStore_useStore();
|
|
@@ -11546,22 +11559,29 @@ function useCanvasAxisY(options = {}) {
|
|
|
11546
11559
|
const formatTickLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
|
|
11547
11560
|
if (Math.abs(value) >= 1000) return `${(value / 1000).toFixed(1)}k`;
|
|
11548
11561
|
if (Math.abs(value) < 0.01 && 0 !== value) return value.toExponential(1);
|
|
11562
|
+
const rangeSpan = range.max - range.min;
|
|
11563
|
+
if (rangeSpan < 1) {
|
|
11564
|
+
const decimalPlaces = Math.max(2, Math.ceil(-Math.log10(rangeSpan)) + 1);
|
|
11565
|
+
return value.toFixed(Math.min(decimalPlaces, 4));
|
|
11566
|
+
}
|
|
11549
11567
|
return value.toFixed(Math.abs(value) < 1 ? 2 : 1);
|
|
11550
|
-
}, [
|
|
11568
|
+
}, [
|
|
11569
|
+
range
|
|
11570
|
+
]);
|
|
11551
11571
|
const ticksData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
11552
11572
|
if (0 === containerHeight) return {
|
|
11553
11573
|
majorTicks: [],
|
|
11554
11574
|
minorTicks: []
|
|
11555
11575
|
};
|
|
11556
11576
|
const rangeSpan = range.max - range.min;
|
|
11557
|
-
const
|
|
11558
|
-
const maxTicks = Math.floor(containerHeight / minTickSpacing);
|
|
11559
|
-
const idealTickCount = Math.max(5, Math.min(maxTicks, 20));
|
|
11577
|
+
const idealTickCount = IDEAL_TICK_COUNT;
|
|
11560
11578
|
const roughInterval = rangeSpan / idealTickCount;
|
|
11561
11579
|
const magnitude = 10 ** Math.floor(Math.log10(roughInterval));
|
|
11562
11580
|
const normalizedInterval = roughInterval / magnitude;
|
|
11563
11581
|
let interval;
|
|
11564
11582
|
interval = normalizedInterval <= 1 ? magnitude : normalizedInterval <= 2 ? 2 * magnitude : normalizedInterval <= 5 ? 5 * magnitude : 10 * magnitude;
|
|
11583
|
+
const minTickInterval = MIN_RANGE_SPAN / (2 * IDEAL_TICK_COUNT);
|
|
11584
|
+
interval = Math.max(interval, minTickInterval);
|
|
11565
11585
|
const majorTicks = [];
|
|
11566
11586
|
const startTick = Math.ceil(range.min / interval) * interval;
|
|
11567
11587
|
for(let value = startTick; value <= range.max; value += interval){
|
|
@@ -11593,7 +11613,9 @@ function useCanvasAxisY(options = {}) {
|
|
|
11593
11613
|
const minorTicks = [];
|
|
11594
11614
|
const minorInterval = interval / MINOR_TICK_DIVISIONS;
|
|
11595
11615
|
const minorTickSpacing = minorInterval / rangeSpan * containerHeight;
|
|
11596
|
-
|
|
11616
|
+
const isVerySmallRange = rangeSpan < 1;
|
|
11617
|
+
const minTickSpacingThreshold = isVerySmallRange ? 2 * MIN_TICK_SPACING : MIN_TICK_SPACING;
|
|
11618
|
+
if (minorTickSpacing >= minTickSpacingThreshold && containerHeight > MIN_CONTAINER_HEIGHT && !isVerySmallRange) {
|
|
11597
11619
|
const minorStart = Math.ceil(range.min / minorInterval) * minorInterval;
|
|
11598
11620
|
for(let value = minorStart; value <= range.max; value += minorInterval){
|
|
11599
11621
|
if (Math.abs(value % interval) < 0.1 * minorInterval) continue;
|
|
@@ -11681,15 +11703,23 @@ function useCanvasAxisY(options = {}) {
|
|
|
11681
11703
|
]);
|
|
11682
11704
|
const handleWheel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
|
|
11683
11705
|
if (disabled) return;
|
|
11706
|
+
if (e.deltaY < 0) {
|
|
11707
|
+
const currentRange = range.max - range.min;
|
|
11708
|
+
if (currentRange <= MIN_RANGE_SPAN) return;
|
|
11709
|
+
}
|
|
11684
11710
|
ranging.moveWheel?.(e);
|
|
11685
11711
|
}, [
|
|
11686
11712
|
ranging,
|
|
11687
|
-
disabled
|
|
11713
|
+
disabled,
|
|
11714
|
+
range
|
|
11688
11715
|
]);
|
|
11689
11716
|
const handleMouseMove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
|
|
11690
11717
|
if (disabled || !isDragging || !containerRef.current) return;
|
|
11691
11718
|
const offset = (e.clientY - dragStartY) / containerRef.current.offsetHeight;
|
|
11692
|
-
|
|
11719
|
+
const rangeSpan = range.max - range.min;
|
|
11720
|
+
const isVerySmallRange = rangeSpan < 1;
|
|
11721
|
+
const threshold = isVerySmallRange ? 0.005 : 0.01;
|
|
11722
|
+
if (Math.abs(offset) > threshold) {
|
|
11693
11723
|
ranging.move?.(offset);
|
|
11694
11724
|
setDragStartY(e.clientY);
|
|
11695
11725
|
}
|
|
@@ -11697,7 +11727,8 @@ function useCanvasAxisY(options = {}) {
|
|
|
11697
11727
|
disabled,
|
|
11698
11728
|
isDragging,
|
|
11699
11729
|
dragStartY,
|
|
11700
|
-
ranging
|
|
11730
|
+
ranging,
|
|
11731
|
+
range
|
|
11701
11732
|
]);
|
|
11702
11733
|
const handleMouseUp = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
11703
11734
|
if (disabled) return;
|