@@ -1738,4 +1738,95 @@ describe('Test axes', function() {
1738
1738
] ) ;
1739
1739
} ) ;
1740
1740
} ) ;
1741
+
1742
+ describe ( 'autoBin' , function ( ) {
1743
+
1744
+ function _autoBin ( x , ax , nbins ) {
1745
+ ax . _categories = [ ] ;
1746
+ Axes . setConvert ( ax ) ;
1747
+
1748
+ var d = ax . makeCalcdata ( { x : x } , 'x' ) ;
1749
+
1750
+ return Axes . autoBin ( d , ax , nbins , false , 'gregorian' ) ;
1751
+ }
1752
+
1753
+ it ( 'should auto bin categories' , function ( ) {
1754
+ var out = _autoBin (
1755
+ [ 'apples' , 'oranges' , 'bananas' ] ,
1756
+ { type : 'category' }
1757
+ ) ;
1758
+
1759
+ expect ( out ) . toEqual ( {
1760
+ start : - 0.5 ,
1761
+ end : 2.5 ,
1762
+ size : 1
1763
+ } ) ;
1764
+ } ) ;
1765
+
1766
+ it ( 'should not error out for categories on linear axis' , function ( ) {
1767
+ var out = _autoBin (
1768
+ [ 'apples' , 'oranges' , 'bananas' ] ,
1769
+ { type : 'linear' }
1770
+ ) ;
1771
+
1772
+ expect ( out ) . toEqual ( {
1773
+ start : undefined ,
1774
+ end : undefined ,
1775
+ size : 2
1776
+ } ) ;
1777
+ } ) ;
1778
+
1779
+ it ( 'should not error out for categories on log axis' , function ( ) {
1780
+ var out = _autoBin (
1781
+ [ 'apples' , 'oranges' , 'bananas' ] ,
1782
+ { type : 'log' }
1783
+ ) ;
1784
+
1785
+ expect ( out ) . toEqual ( {
1786
+ start : undefined ,
1787
+ end : undefined ,
1788
+ size : 2
1789
+ } ) ;
1790
+ } ) ;
1791
+
1792
+ it ( 'should not error out for categories on date axis' , function ( ) {
1793
+ var out = _autoBin (
1794
+ [ 'apples' , 'oranges' , 'bananas' ] ,
1795
+ { type : 'date' }
1796
+ ) ;
1797
+
1798
+ expect ( out ) . toEqual ( {
1799
+ start : undefined ,
1800
+ end : undefined ,
1801
+ size : 2
1802
+ } ) ;
1803
+ } ) ;
1804
+
1805
+ it ( 'should auto bin linear data' , function ( ) {
1806
+ var out = _autoBin (
1807
+ [ 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ] ,
1808
+ { type : 'linear' }
1809
+ ) ;
1810
+
1811
+ expect ( out ) . toEqual ( {
1812
+ start : - 0.5 ,
1813
+ end : 4.5 ,
1814
+ size : 1
1815
+ } ) ;
1816
+ } ) ;
1817
+
1818
+ it ( 'should auto bin linear data with nbins constraint' , function ( ) {
1819
+ var out = _autoBin (
1820
+ [ 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ] ,
1821
+ { type : 'linear' } ,
1822
+ 2
1823
+ ) ;
1824
+
1825
+ expect ( out ) . toEqual ( {
1826
+ start : - 0.5 ,
1827
+ end : 5.5 ,
1828
+ size : 2
1829
+ } ) ;
1830
+ } ) ;
1831
+ } ) ;
1741
1832
} ) ;
0 commit comments