@@ -1652,15 +1652,12 @@ describe('Test axes', function() {
1652
1652
} ) ;
1653
1653
} ) ;
1654
1654
1655
- describe ( 'expand ' , function ( ) {
1656
- var expand = Axes . expand ;
1657
- var ax , data , options ;
1655
+ describe ( 'findExtremes ' , function ( ) {
1656
+ var findExtremes = Axes . findExtremes ;
1657
+ var ax , data , options , out ;
1658
1658
1659
- // Axes.expand modifies ax, so this provides a simple
1660
- // way of getting a new clean copy each time.
1661
1659
function getDefaultAx ( ) {
1662
1660
return {
1663
- autorange : true ,
1664
1661
c2l : Number ,
1665
1662
type : 'linear' ,
1666
1663
_m : 1
@@ -1671,55 +1668,42 @@ describe('Test axes', function() {
1671
1668
ax = getDefaultAx ( ) ;
1672
1669
data = [ 1 , 4 , 7 , 2 ] ;
1673
1670
1674
- expand ( ax , data ) ;
1675
-
1676
- expect ( ax . _min ) . toEqual ( [ { val : 1 , pad : 0 , extrapad : false } ] ) ;
1677
- expect ( ax . _max ) . toEqual ( [ { val : 7 , pad : 0 , extrapad : false } ] ) ;
1671
+ out = findExtremes ( ax , data ) ;
1672
+ expect ( out . min ) . toEqual ( [ { val : 1 , pad : 0 , extrapad : false } ] ) ;
1673
+ expect ( out . max ) . toEqual ( [ { val : 7 , pad : 0 , extrapad : false } ] ) ;
1678
1674
} ) ;
1679
1675
1680
1676
it ( 'calls ax.setScale if necessary' , function ( ) {
1681
- ax = {
1682
- autorange : true ,
1683
- c2l : Number ,
1684
- type : 'linear' ,
1685
- setScale : function ( ) { }
1686
- } ;
1677
+ ax = getDefaultAx ( ) ;
1678
+ delete ax . _m ;
1679
+ ax . setScale = function ( ) { } ;
1687
1680
spyOn ( ax , 'setScale' ) ;
1688
1681
1689
- expand ( ax , [ 1 ] ) ;
1690
-
1682
+ findExtremes ( ax , [ 1 ] ) ;
1691
1683
expect ( ax . setScale ) . toHaveBeenCalled ( ) ;
1692
1684
} ) ;
1693
1685
1694
1686
it ( 'handles symmetric pads as numbers' , function ( ) {
1695
1687
ax = getDefaultAx ( ) ;
1696
1688
data = [ 1 , 4 , 2 , 7 ] ;
1697
- options = {
1698
- vpad : 2 ,
1699
- ppad : 10
1700
- } ;
1689
+ options = { vpad : 2 , ppad : 10 } ;
1701
1690
1702
- expand ( ax , data , options ) ;
1703
-
1704
- expect ( ax . _min ) . toEqual ( [ { val : - 1 , pad : 10 , extrapad : false } ] ) ;
1705
- expect ( ax . _max ) . toEqual ( [ { val : 9 , pad : 10 , extrapad : false } ] ) ;
1691
+ out = findExtremes ( ax , data , options ) ;
1692
+ expect ( out . min ) . toEqual ( [ { val : - 1 , pad : 10 , extrapad : false } ] ) ;
1693
+ expect ( out . max ) . toEqual ( [ { val : 9 , pad : 10 , extrapad : false } ] ) ;
1706
1694
} ) ;
1707
1695
1708
1696
it ( 'handles symmetric pads as number arrays' , function ( ) {
1709
1697
ax = getDefaultAx ( ) ;
1710
1698
data = [ 1 , 4 , 2 , 7 ] ;
1711
- options = {
1712
- vpad : [ 1 , 10 , 6 , 3 ] ,
1713
- ppad : [ 0 , 15 , 20 , 10 ]
1714
- } ;
1715
-
1716
- expand ( ax , data , options ) ;
1699
+ options = { vpad : [ 1 , 10 , 6 , 3 ] , ppad : [ 0 , 15 , 20 , 10 ] } ;
1717
1700
1718
- expect ( ax . _min ) . toEqual ( [
1701
+ out = findExtremes ( ax , data , options ) ;
1702
+ expect ( out . min ) . toEqual ( [
1719
1703
{ val : - 6 , pad : 15 , extrapad : false } ,
1720
1704
{ val : - 4 , pad : 20 , extrapad : false }
1721
1705
] ) ;
1722
- expect ( ax . _max ) . toEqual ( [
1706
+ expect ( out . max ) . toEqual ( [
1723
1707
{ val : 14 , pad : 15 , extrapad : false } ,
1724
1708
{ val : 8 , pad : 20 , extrapad : false }
1725
1709
] ) ;
@@ -1735,10 +1719,9 @@ describe('Test axes', function() {
1735
1719
ppadplus : 20
1736
1720
} ;
1737
1721
1738
- expand ( ax , data , options ) ;
1739
-
1740
- expect ( ax . _min ) . toEqual ( [ { val : - 4 , pad : 10 , extrapad : false } ] ) ;
1741
- expect ( ax . _max ) . toEqual ( [ { val : 11 , pad : 20 , extrapad : false } ] ) ;
1722
+ out = findExtremes ( ax , data , options ) ;
1723
+ expect ( out . min ) . toEqual ( [ { val : - 4 , pad : 10 , extrapad : false } ] ) ;
1724
+ expect ( out . max ) . toEqual ( [ { val : 11 , pad : 20 , extrapad : false } ] ) ;
1742
1725
} ) ;
1743
1726
1744
1727
it ( 'handles separate pads as number arrays' , function ( ) {
@@ -1751,13 +1734,12 @@ describe('Test axes', function() {
1751
1734
ppadplus : [ 0 , 0 , 40 , 20 ]
1752
1735
} ;
1753
1736
1754
- expand ( ax , data , options ) ;
1755
-
1756
- expect ( ax . _min ) . toEqual ( [
1737
+ out = findExtremes ( ax , data , options ) ;
1738
+ expect ( out . min ) . toEqual ( [
1757
1739
{ val : 1 , pad : 30 , extrapad : false } ,
1758
1740
{ val : - 3 , pad : 10 , extrapad : false }
1759
1741
] ) ;
1760
- expect ( ax . _max ) . toEqual ( [
1742
+ expect ( out . max ) . toEqual ( [
1761
1743
{ val : 9 , pad : 0 , extrapad : false } ,
1762
1744
{ val : 3 , pad : 40 , extrapad : false } ,
1763
1745
{ val : 8 , pad : 20 , extrapad : false }
@@ -1776,70 +1758,49 @@ describe('Test axes', function() {
1776
1758
ppadplus : 40
1777
1759
} ;
1778
1760
1779
- expand ( ax , data , options ) ;
1780
-
1781
- expect ( ax . _min ) . toEqual ( [ { val : - 1 , pad : 20 , extrapad : false } ] ) ;
1782
- expect ( ax . _max ) . toEqual ( [ { val : 9 , pad : 40 , extrapad : false } ] ) ;
1761
+ out = findExtremes ( ax , data , options ) ;
1762
+ expect ( out . min ) . toEqual ( [ { val : - 1 , pad : 20 , extrapad : false } ] ) ;
1763
+ expect ( out . max ) . toEqual ( [ { val : 9 , pad : 40 , extrapad : false } ] ) ;
1783
1764
} ) ;
1784
1765
1785
1766
it ( 'adds 5% padding if specified by flag' , function ( ) {
1786
1767
ax = getDefaultAx ( ) ;
1787
1768
data = [ 1 , 5 ] ;
1788
- options = {
1789
- vpad : 1 ,
1790
- ppad : 10 ,
1791
- padded : true
1792
- } ;
1769
+ options = { vpad : 1 , ppad : 10 , padded : true } ;
1793
1770
1794
- expand ( ax , data , options ) ;
1795
-
1796
- expect ( ax . _min ) . toEqual ( [ { val : 0 , pad : 10 , extrapad : true } ] ) ;
1797
- expect ( ax . _max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : true } ] ) ;
1771
+ out = findExtremes ( ax , data , options ) ;
1772
+ expect ( out . min ) . toEqual ( [ { val : 0 , pad : 10 , extrapad : true } ] ) ;
1773
+ expect ( out . max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : true } ] ) ;
1798
1774
} ) ;
1799
1775
1800
1776
it ( 'has lower bound zero with all positive data if tozero is sset' , function ( ) {
1801
1777
ax = getDefaultAx ( ) ;
1802
1778
data = [ 2 , 5 ] ;
1803
- options = {
1804
- vpad : 1 ,
1805
- ppad : 10 ,
1806
- tozero : true
1807
- } ;
1779
+ options = { vpad : 1 , ppad : 10 , tozero : true } ;
1808
1780
1809
- expand ( ax , data , options ) ;
1810
-
1811
- expect ( ax . _min ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1812
- expect ( ax . _max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : false } ] ) ;
1781
+ out = findExtremes ( ax , data , options ) ;
1782
+ expect ( out . min ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1783
+ expect ( out . max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : false } ] ) ;
1813
1784
} ) ;
1814
1785
1815
1786
it ( 'has upper bound zero with all negative data if tozero is set' , function ( ) {
1816
1787
ax = getDefaultAx ( ) ;
1817
1788
data = [ - 7 , - 4 ] ;
1818
- options = {
1819
- vpad : 1 ,
1820
- ppad : 10 ,
1821
- tozero : true
1822
- } ;
1789
+ options = { vpad : 1 , ppad : 10 , tozero : true } ;
1823
1790
1824
- expand ( ax , data , options ) ;
1825
-
1826
- expect ( ax . _min ) . toEqual ( [ { val : - 8 , pad : 10 , extrapad : false } ] ) ;
1827
- expect ( ax . _max ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1791
+ out = findExtremes ( ax , data , options ) ;
1792
+ expect ( out . min ) . toEqual ( [ { val : - 8 , pad : 10 , extrapad : false } ] ) ;
1793
+ expect ( out . max ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1828
1794
} ) ;
1829
1795
1830
1796
it ( 'sets neither bound to zero with positive and negative data if tozero is set' , function ( ) {
1831
1797
ax = getDefaultAx ( ) ;
1832
1798
data = [ - 7 , 4 ] ;
1833
- options = {
1834
- vpad : 1 ,
1835
- ppad : 10 ,
1836
- tozero : true
1837
- } ;
1799
+ options = { vpad : 1 , ppad : 10 , tozero : true } ;
1838
1800
1839
- expand ( ax , data , options ) ;
1840
-
1841
- expect ( ax . _min ) . toEqual ( [ { val : - 8 , pad : 10 , extrapad : false } ] ) ;
1842
- expect ( ax . _max ) . toEqual ( [ { val : 5 , pad : 10 , extrapad : false } ] ) ;
1801
+ out = findExtremes ( ax , data , options ) ;
1802
+ expect ( out . min ) . toEqual ( [ { val : - 8 , pad : 10 , extrapad : false } ] ) ;
1803
+ expect ( out . max ) . toEqual ( [ { val : 5 , pad : 10 , extrapad : false } ] ) ;
1843
1804
} ) ;
1844
1805
1845
1806
it ( 'overrides padded with tozero' , function ( ) {
@@ -1852,27 +1813,25 @@ describe('Test axes', function() {
1852
1813
padded : true
1853
1814
} ;
1854
1815
1855
- expand ( ax , data , options ) ;
1856
-
1857
- expect ( ax . _min ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1858
- expect ( ax . _max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : true } ] ) ;
1816
+ out = findExtremes ( ax , data , options ) ;
1817
+ expect ( out . min ) . toEqual ( [ { val : 0 , pad : 0 , extrapad : false } ] ) ;
1818
+ expect ( out . max ) . toEqual ( [ { val : 6 , pad : 10 , extrapad : true } ] ) ;
1859
1819
} ) ;
1860
1820
1861
1821
it ( 'should fail if no data is given' , function ( ) {
1862
1822
ax = getDefaultAx ( ) ;
1863
- expect ( function ( ) { expand ( ax ) ; } ) . toThrow ( ) ;
1823
+ expect ( function ( ) { findExtremes ( ax ) ; } ) . toThrow ( ) ;
1864
1824
} ) ;
1865
1825
1866
1826
it ( 'should return even if `autorange` is false' , function ( ) {
1867
1827
ax = getDefaultAx ( ) ;
1868
- data = [ 2 , 5 ] ;
1869
-
1870
1828
ax . autorange = false ;
1871
1829
ax . rangeslider = { autorange : false } ;
1830
+ data = [ 2 , 5 ] ;
1872
1831
1873
- expand ( ax , data , { } ) ;
1874
- expect ( ax . _min ) . toEqual ( [ { val : 2 , pad : 0 , extrapad : false } ] ) ;
1875
- expect ( ax . _max ) . toEqual ( [ { val : 5 , pad : 0 , extrapad : false } ] ) ;
1832
+ out = findExtremes ( ax , data , { } ) ;
1833
+ expect ( out . min ) . toEqual ( [ { val : 2 , pad : 0 , extrapad : false } ] ) ;
1834
+ expect ( out . max ) . toEqual ( [ { val : 5 , pad : 0 , extrapad : false } ] ) ;
1876
1835
} ) ;
1877
1836
} ) ;
1878
1837
0 commit comments