@rfkit/charts 1.1.40 → 1.1.41
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 +20 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11651,7 +11651,7 @@ const LINE_WIDTH_BASE = 0.5;
|
|
|
11651
11651
|
const MAJOR_TICK_LENGTH = 6;
|
|
11652
11652
|
const MINOR_TICK_LENGTH = 4;
|
|
11653
11653
|
const TEXT_OFFSET = 8;
|
|
11654
|
-
const MINOR_TICK_DIVISIONS =
|
|
11654
|
+
const MINOR_TICK_DIVISIONS = 2;
|
|
11655
11655
|
const MIN_TICK_SPACING = 4;
|
|
11656
11656
|
const MIN_CONTAINER_HEIGHT = 100;
|
|
11657
11657
|
const IDEAL_TICK_COUNT = 7;
|
|
@@ -11693,18 +11693,14 @@ function useCanvasAxisY(options = {}) {
|
|
|
11693
11693
|
resizeObserver.observe(container);
|
|
11694
11694
|
return ()=>resizeObserver.disconnect();
|
|
11695
11695
|
}, []);
|
|
11696
|
-
const formatTickLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
|
|
11697
|
-
if (
|
|
11698
|
-
if (
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
const decimalPlaces = Math.max(2, Math.ceil(-Math.log10(rangeSpan)) + 1);
|
|
11702
|
-
return value.toFixed(Math.min(decimalPlaces, 4));
|
|
11696
|
+
const formatTickLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value, formatStrategy)=>{
|
|
11697
|
+
if (formatStrategy.useScientific) return value.toExponential(1);
|
|
11698
|
+
if (formatStrategy.useKFormat) {
|
|
11699
|
+
const kValue = value / 1000;
|
|
11700
|
+
return formatStrategy.useDecimals ? `${kValue.toFixed(1)}k` : `${Math.round(kValue)}k`;
|
|
11703
11701
|
}
|
|
11704
|
-
return value.toFixed(Math.
|
|
11705
|
-
}, [
|
|
11706
|
-
range
|
|
11707
|
-
]);
|
|
11702
|
+
return formatStrategy.useDecimals ? value.toFixed(1) : Math.round(value).toString();
|
|
11703
|
+
}, []);
|
|
11708
11704
|
const ticksData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
11709
11705
|
if (0 === containerHeight) return {
|
|
11710
11706
|
majorTicks: [],
|
|
@@ -11719,8 +11715,18 @@ function useCanvasAxisY(options = {}) {
|
|
|
11719
11715
|
interval = normalizedInterval <= 1 ? magnitude : normalizedInterval <= 2 ? 2 * magnitude : normalizedInterval <= 5 ? 5 * magnitude : 10 * magnitude;
|
|
11720
11716
|
const minTickInterval = MIN_RANGE_SPAN / (2 * IDEAL_TICK_COUNT);
|
|
11721
11717
|
interval = Math.max(interval, minTickInterval);
|
|
11722
|
-
const
|
|
11718
|
+
const majorTickValues = [];
|
|
11723
11719
|
const startTick = Math.ceil(range.min / interval) * interval;
|
|
11720
|
+
for(let value = startTick; value <= range.max; value += interval)majorTickValues.push(value);
|
|
11721
|
+
const hasLargeValues = majorTickValues.some((v)=>Math.abs(v) >= 1000);
|
|
11722
|
+
const hasSmallValues = majorTickValues.some((v)=>Math.abs(v) < 0.01 && 0 !== v);
|
|
11723
|
+
const hasDecimals = majorTickValues.some((v)=>v % 1 !== 0);
|
|
11724
|
+
const formatStrategy = {
|
|
11725
|
+
useScientific: hasSmallValues,
|
|
11726
|
+
useKFormat: hasLargeValues && !hasSmallValues,
|
|
11727
|
+
useDecimals: hasDecimals
|
|
11728
|
+
};
|
|
11729
|
+
const majorTicks = [];
|
|
11724
11730
|
for(let value = startTick; value <= range.max; value += interval){
|
|
11725
11731
|
const position = (range.max - value) / rangeSpan * containerHeight;
|
|
11726
11732
|
let textPosition = position;
|
|
@@ -11743,7 +11749,7 @@ function useCanvasAxisY(options = {}) {
|
|
|
11743
11749
|
value,
|
|
11744
11750
|
position,
|
|
11745
11751
|
textPosition,
|
|
11746
|
-
label: formatTickLabel(value),
|
|
11752
|
+
label: formatTickLabel(value, formatStrategy),
|
|
11747
11753
|
isAdjusted
|
|
11748
11754
|
});
|
|
11749
11755
|
}
|