@rfkit/charts 1.1.35 → 1.1.37
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 +37 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6895,8 +6895,13 @@ const GuageBox = ({ children, padding, limit, step, setLimit, onChange })=>{
|
|
|
6895
6895
|
toLimit
|
|
6896
6896
|
]);
|
|
6897
6897
|
const handleMouseUpOrLeave = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
6898
|
+
if (down) onChange?.(limit);
|
|
6898
6899
|
setDown(false);
|
|
6899
|
-
}, [
|
|
6900
|
+
}, [
|
|
6901
|
+
down,
|
|
6902
|
+
limit,
|
|
6903
|
+
onChange
|
|
6904
|
+
]);
|
|
6900
6905
|
const handleMouseMove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
|
|
6901
6906
|
if (down) toLimit(e);
|
|
6902
6907
|
}, [
|
|
@@ -6907,17 +6912,14 @@ const GuageBox = ({ children, padding, limit, step, setLimit, onChange })=>{
|
|
|
6907
6912
|
let newLimit = limit + (e.deltaY > 0 ? -step : step);
|
|
6908
6913
|
newLimit = Math.max(min, Math.min(max, newLimit));
|
|
6909
6914
|
setLimit(newLimit);
|
|
6915
|
+
onChange?.(newLimit);
|
|
6910
6916
|
}, [
|
|
6911
6917
|
step,
|
|
6912
6918
|
limit,
|
|
6913
6919
|
min,
|
|
6914
6920
|
max,
|
|
6915
|
-
setLimit
|
|
6916
|
-
|
|
6917
|
-
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
6918
|
-
onChange?.(limit);
|
|
6919
|
-
}, [
|
|
6920
|
-
limit
|
|
6921
|
+
setLimit,
|
|
6922
|
+
onChange
|
|
6921
6923
|
]);
|
|
6922
6924
|
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
|
|
6923
6925
|
className: components_GuageBox_styles_module.GuageBox,
|
|
@@ -11504,6 +11506,8 @@ const TEXT_OFFSET = 8;
|
|
|
11504
11506
|
const MINOR_TICK_DIVISIONS = 4;
|
|
11505
11507
|
const MIN_TICK_SPACING = 4;
|
|
11506
11508
|
const MIN_CONTAINER_HEIGHT = 100;
|
|
11509
|
+
const IDEAL_TICK_COUNT = 7;
|
|
11510
|
+
const MIN_RANGE_SPAN = 0.5;
|
|
11507
11511
|
function useCanvasAxisY(options = {}) {
|
|
11508
11512
|
const { ranging } = options;
|
|
11509
11513
|
const { state: { axisY } } = useStore_useStore();
|
|
@@ -11544,22 +11548,29 @@ function useCanvasAxisY(options = {}) {
|
|
|
11544
11548
|
const formatTickLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
|
|
11545
11549
|
if (Math.abs(value) >= 1000) return `${(value / 1000).toFixed(1)}k`;
|
|
11546
11550
|
if (Math.abs(value) < 0.01 && 0 !== value) return value.toExponential(1);
|
|
11551
|
+
const rangeSpan = range.max - range.min;
|
|
11552
|
+
if (rangeSpan < 1) {
|
|
11553
|
+
const decimalPlaces = Math.max(2, Math.ceil(-Math.log10(rangeSpan)) + 1);
|
|
11554
|
+
return value.toFixed(Math.min(decimalPlaces, 4));
|
|
11555
|
+
}
|
|
11547
11556
|
return value.toFixed(Math.abs(value) < 1 ? 2 : 1);
|
|
11548
|
-
}, [
|
|
11557
|
+
}, [
|
|
11558
|
+
range
|
|
11559
|
+
]);
|
|
11549
11560
|
const ticksData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
11550
11561
|
if (0 === containerHeight) return {
|
|
11551
11562
|
majorTicks: [],
|
|
11552
11563
|
minorTicks: []
|
|
11553
11564
|
};
|
|
11554
11565
|
const rangeSpan = range.max - range.min;
|
|
11555
|
-
const
|
|
11556
|
-
const maxTicks = Math.floor(containerHeight / minTickSpacing);
|
|
11557
|
-
const idealTickCount = Math.max(5, Math.min(maxTicks, 20));
|
|
11566
|
+
const idealTickCount = IDEAL_TICK_COUNT;
|
|
11558
11567
|
const roughInterval = rangeSpan / idealTickCount;
|
|
11559
11568
|
const magnitude = 10 ** Math.floor(Math.log10(roughInterval));
|
|
11560
11569
|
const normalizedInterval = roughInterval / magnitude;
|
|
11561
11570
|
let interval;
|
|
11562
11571
|
interval = normalizedInterval <= 1 ? magnitude : normalizedInterval <= 2 ? 2 * magnitude : normalizedInterval <= 5 ? 5 * magnitude : 10 * magnitude;
|
|
11572
|
+
const minTickInterval = MIN_RANGE_SPAN / (2 * IDEAL_TICK_COUNT);
|
|
11573
|
+
interval = Math.max(interval, minTickInterval);
|
|
11563
11574
|
const majorTicks = [];
|
|
11564
11575
|
const startTick = Math.ceil(range.min / interval) * interval;
|
|
11565
11576
|
for(let value = startTick; value <= range.max; value += interval){
|
|
@@ -11591,7 +11602,9 @@ function useCanvasAxisY(options = {}) {
|
|
|
11591
11602
|
const minorTicks = [];
|
|
11592
11603
|
const minorInterval = interval / MINOR_TICK_DIVISIONS;
|
|
11593
11604
|
const minorTickSpacing = minorInterval / rangeSpan * containerHeight;
|
|
11594
|
-
|
|
11605
|
+
const isVerySmallRange = rangeSpan < 1;
|
|
11606
|
+
const minTickSpacingThreshold = isVerySmallRange ? 2 * MIN_TICK_SPACING : MIN_TICK_SPACING;
|
|
11607
|
+
if (minorTickSpacing >= minTickSpacingThreshold && containerHeight > MIN_CONTAINER_HEIGHT && !isVerySmallRange) {
|
|
11595
11608
|
const minorStart = Math.ceil(range.min / minorInterval) * minorInterval;
|
|
11596
11609
|
for(let value = minorStart; value <= range.max; value += minorInterval){
|
|
11597
11610
|
if (Math.abs(value % interval) < 0.1 * minorInterval) continue;
|
|
@@ -11679,15 +11692,23 @@ function useCanvasAxisY(options = {}) {
|
|
|
11679
11692
|
]);
|
|
11680
11693
|
const handleWheel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
|
|
11681
11694
|
if (disabled) return;
|
|
11695
|
+
if (e.deltaY < 0) {
|
|
11696
|
+
const currentRange = range.max - range.min;
|
|
11697
|
+
if (currentRange <= MIN_RANGE_SPAN) return;
|
|
11698
|
+
}
|
|
11682
11699
|
ranging.moveWheel?.(e);
|
|
11683
11700
|
}, [
|
|
11684
11701
|
ranging,
|
|
11685
|
-
disabled
|
|
11702
|
+
disabled,
|
|
11703
|
+
range
|
|
11686
11704
|
]);
|
|
11687
11705
|
const handleMouseMove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
|
|
11688
11706
|
if (disabled || !isDragging || !containerRef.current) return;
|
|
11689
11707
|
const offset = (e.clientY - dragStartY) / containerRef.current.offsetHeight;
|
|
11690
|
-
|
|
11708
|
+
const rangeSpan = range.max - range.min;
|
|
11709
|
+
const isVerySmallRange = rangeSpan < 1;
|
|
11710
|
+
const threshold = isVerySmallRange ? 0.005 : 0.01;
|
|
11711
|
+
if (Math.abs(offset) > threshold) {
|
|
11691
11712
|
ranging.move?.(offset);
|
|
11692
11713
|
setDragStartY(e.clientY);
|
|
11693
11714
|
}
|
|
@@ -11695,7 +11716,8 @@ function useCanvasAxisY(options = {}) {
|
|
|
11695
11716
|
disabled,
|
|
11696
11717
|
isDragging,
|
|
11697
11718
|
dragStartY,
|
|
11698
|
-
ranging
|
|
11719
|
+
ranging,
|
|
11720
|
+
range
|
|
11699
11721
|
]);
|
|
11700
11722
|
const handleMouseUp = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
11701
11723
|
if (disabled) return;
|