@rfkit/charts 1.1.36 → 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.
Files changed (2) hide show
  1. package/index.js +28 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11506,6 +11506,8 @@ const TEXT_OFFSET = 8;
11506
11506
  const MINOR_TICK_DIVISIONS = 4;
11507
11507
  const MIN_TICK_SPACING = 4;
11508
11508
  const MIN_CONTAINER_HEIGHT = 100;
11509
+ const IDEAL_TICK_COUNT = 7;
11510
+ const MIN_RANGE_SPAN = 0.5;
11509
11511
  function useCanvasAxisY(options = {}) {
11510
11512
  const { ranging } = options;
11511
11513
  const { state: { axisY } } = useStore_useStore();
@@ -11546,22 +11548,29 @@ function useCanvasAxisY(options = {}) {
11546
11548
  const formatTickLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
11547
11549
  if (Math.abs(value) >= 1000) return `${(value / 1000).toFixed(1)}k`;
11548
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
+ }
11549
11556
  return value.toFixed(Math.abs(value) < 1 ? 2 : 1);
11550
- }, []);
11557
+ }, [
11558
+ range
11559
+ ]);
11551
11560
  const ticksData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
11552
11561
  if (0 === containerHeight) return {
11553
11562
  majorTicks: [],
11554
11563
  minorTicks: []
11555
11564
  };
11556
11565
  const rangeSpan = range.max - range.min;
11557
- const minTickSpacing = 25;
11558
- const maxTicks = Math.floor(containerHeight / minTickSpacing);
11559
- const idealTickCount = Math.max(5, Math.min(maxTicks, 20));
11566
+ const idealTickCount = IDEAL_TICK_COUNT;
11560
11567
  const roughInterval = rangeSpan / idealTickCount;
11561
11568
  const magnitude = 10 ** Math.floor(Math.log10(roughInterval));
11562
11569
  const normalizedInterval = roughInterval / magnitude;
11563
11570
  let interval;
11564
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);
11565
11574
  const majorTicks = [];
11566
11575
  const startTick = Math.ceil(range.min / interval) * interval;
11567
11576
  for(let value = startTick; value <= range.max; value += interval){
@@ -11593,7 +11602,9 @@ function useCanvasAxisY(options = {}) {
11593
11602
  const minorTicks = [];
11594
11603
  const minorInterval = interval / MINOR_TICK_DIVISIONS;
11595
11604
  const minorTickSpacing = minorInterval / rangeSpan * containerHeight;
11596
- if (minorTickSpacing >= MIN_TICK_SPACING && containerHeight > MIN_CONTAINER_HEIGHT) {
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) {
11597
11608
  const minorStart = Math.ceil(range.min / minorInterval) * minorInterval;
11598
11609
  for(let value = minorStart; value <= range.max; value += minorInterval){
11599
11610
  if (Math.abs(value % interval) < 0.1 * minorInterval) continue;
@@ -11681,15 +11692,23 @@ function useCanvasAxisY(options = {}) {
11681
11692
  ]);
11682
11693
  const handleWheel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
11683
11694
  if (disabled) return;
11695
+ if (e.deltaY < 0) {
11696
+ const currentRange = range.max - range.min;
11697
+ if (currentRange <= MIN_RANGE_SPAN) return;
11698
+ }
11684
11699
  ranging.moveWheel?.(e);
11685
11700
  }, [
11686
11701
  ranging,
11687
- disabled
11702
+ disabled,
11703
+ range
11688
11704
  ]);
11689
11705
  const handleMouseMove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
11690
11706
  if (disabled || !isDragging || !containerRef.current) return;
11691
11707
  const offset = (e.clientY - dragStartY) / containerRef.current.offsetHeight;
11692
- if (Math.abs(offset) > 0.01) {
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) {
11693
11712
  ranging.move?.(offset);
11694
11713
  setDragStartY(e.clientY);
11695
11714
  }
@@ -11697,7 +11716,8 @@ function useCanvasAxisY(options = {}) {
11697
11716
  disabled,
11698
11717
  isDragging,
11699
11718
  dragStartY,
11700
- ranging
11719
+ ranging,
11720
+ range
11701
11721
  ]);
11702
11722
  const handleMouseUp = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
11703
11723
  if (disabled) return;
package/package.json CHANGED
@@ -5,6 +5,6 @@
5
5
  "types": "index.d.ts",
6
6
  "author": "Hxgh",
7
7
  "license": "MIT",
8
- "version": "1.1.36",
8
+ "version": "1.1.37",
9
9
  "private": false
10
10
  }