@@ -988,6 +988,31 @@ export function calculateNiceScale(minValue, maxValue, maxTicks, rough = false)
988
988
} ;
989
989
}
990
990
991
+ export function calculateNiceScaleWithExactExtremes ( minValue , maxValue , maxTicks , rough = false ) {
992
+ const range = rough ? ( maxValue - minValue ) : niceNum ( maxValue - minValue , false ) ;
993
+ const tickSpacing = rough ? ( range / ( maxTicks - 1 ) ) : niceNum ( range / ( maxTicks - 1 ) , true ) ;
994
+ const niceMin = Math . floor ( minValue / tickSpacing ) * tickSpacing ;
995
+ const niceMax = Math . ceil ( maxValue / tickSpacing ) * tickSpacing ;
996
+ let ticks = [ ] ;
997
+ let tick = niceMin ;
998
+
999
+ while ( tick <= niceMax ) {
1000
+ if ( tick >= minValue && tick <= maxValue ) {
1001
+ ticks . push ( tick ) ;
1002
+ }
1003
+ tick += tickSpacing ;
1004
+ }
1005
+
1006
+ if ( ticks [ 0 ] !== minValue ) ticks [ 0 ] = minValue ;
1007
+ if ( ticks [ ticks . length - 1 ] !== maxValue ) ticks [ ticks . length - 1 ] = maxValue ;
1008
+
1009
+ return {
1010
+ min : minValue ,
1011
+ max : maxValue ,
1012
+ tickSize : tickSpacing ,
1013
+ ticks
1014
+ } ;
1015
+ }
991
1016
export function interpolateColorHex ( minColor , maxColor , minValue , maxValue , value ) {
992
1017
const hexToRgb = ( hex ) => ( {
993
1018
r : parseInt ( hex . substring ( 1 , 3 ) , 16 ) ,
@@ -1730,6 +1755,7 @@ export function applyDataLabel(func, data, fallbackValue, config) {
1730
1755
}
1731
1756
1732
1757
const lib = {
1758
+ XMLNS ,
1733
1759
abbreviate,
1734
1760
adaptColorToBackground,
1735
1761
addVector,
@@ -1741,8 +1767,11 @@ const lib = {
1741
1767
calcMedian,
1742
1768
calcNutArrowPath,
1743
1769
calcTrend,
1770
+ calculateNiceScale,
1771
+ calculateNiceScaleWithExactExtremes,
1744
1772
canShowValue,
1745
1773
checkArray,
1774
+ checkFormatter,
1746
1775
checkNaN,
1747
1776
checkObj,
1748
1777
closestDecimal,
@@ -1752,18 +1781,18 @@ const lib = {
1752
1781
createCsvContent,
1753
1782
createPolygonPath,
1754
1783
createSmoothPath,
1755
- createStraightPath,
1756
1784
createSpiralPath,
1757
1785
createStar,
1786
+ createStraightPath,
1758
1787
createTSpans,
1759
1788
createUid,
1760
1789
createWordCloudDatasetFromPlainText,
1761
- checkFormatter,
1762
1790
darkenHexColor,
1763
1791
dataLabel,
1764
1792
degreesToRadians,
1765
1793
downloadCsv,
1766
1794
error,
1795
+ functionReturnsString,
1767
1796
generateSpiralCoordinates,
1768
1797
getMissingDatasetAttributes,
1769
1798
getPalette,
@@ -1772,7 +1801,6 @@ const lib = {
1772
1801
isFunction,
1773
1802
isSafeValue,
1774
1803
isValidUserValue,
1775
- functionReturnsString,
1776
1804
lightenHexColor,
1777
1805
makeDonut,
1778
1806
makePath,
@@ -1784,10 +1812,9 @@ const lib = {
1784
1812
rotateMatrix,
1785
1813
shiftHue,
1786
1814
sumByAttribute,
1815
+ sumSeries,
1787
1816
themePalettes,
1788
1817
translateSize,
1789
1818
treeShake,
1790
- XMLNS ,
1791
- sumSeries
1792
1819
} ;
1793
1820
export default lib ;
0 commit comments