@@ -17,6 +17,8 @@ var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
17
17
var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
18
18
var checkTextTemplate = require ( '../assets/check_texttemplate' ) ;
19
19
20
+ var SLICES_TEXT_SELECTOR = '.sunburstlayer text.slicetext' ;
21
+
20
22
function _mouseEvent ( type , gd , v ) {
21
23
return function ( ) {
22
24
if ( Array . isArray ( v ) ) {
@@ -1703,3 +1705,218 @@ describe('Test sunburst texttemplate with *remainder* `values` should work when
1703
1705
[ '%{percentParent} of %{parent}' , [ '20% of Eve' , '42% of Seth' , '8% of Seth' ] ] ,
1704
1706
] , /* skipEtra */ true ) ;
1705
1707
} ) ;
1708
+
1709
+ describe ( 'sunburst inside text orientation' , function ( ) {
1710
+ 'use strict' ;
1711
+
1712
+ var gd ;
1713
+
1714
+ beforeEach ( function ( ) {
1715
+ gd = createGraphDiv ( ) ;
1716
+ } ) ;
1717
+
1718
+ afterEach ( destroyGraphDiv ) ;
1719
+
1720
+ function assertTextRotations ( msg , opts ) {
1721
+ return function ( ) {
1722
+ var selection = d3 . selectAll ( SLICES_TEXT_SELECTOR ) ;
1723
+ var size = selection . size ( ) ;
1724
+ [ 'rotations' ] . forEach ( function ( e ) {
1725
+ expect ( size ) . toBe ( opts [ e ] . length , 'length for ' + e + ' does not match with the number of elements' ) ;
1726
+ } ) ;
1727
+
1728
+ for ( var i = 0 ; i < selection [ 0 ] . length ; i ++ ) {
1729
+ var transform = selection [ 0 ] [ i ] . getAttribute ( 'transform' ) ;
1730
+ var pos0 = transform . indexOf ( 'rotate(' ) ;
1731
+ var rotate = 0 ;
1732
+ if ( pos0 !== - 1 ) {
1733
+ pos0 += 'rotate' . length ;
1734
+ var pos1 = transform . indexOf ( ')' , pos0 ) ;
1735
+ rotate = + ( transform . substring ( pos0 + 1 , pos1 - 1 ) ) ;
1736
+ }
1737
+
1738
+ expect ( opts . rotations [ i ] ) . toBeCloseTo ( rotate , 1 , 'rotation for element ' + i , msg ) ;
1739
+ }
1740
+ } ;
1741
+ }
1742
+
1743
+ it ( 'should be able to react to new insidetextorientation option' , function ( done ) {
1744
+ var fig = {
1745
+ data : [ {
1746
+ type : 'sunburst' ,
1747
+ parents : [ '' , '' , '' , '' , '' , '' , '' ] ,
1748
+ labels : [ 64 , 32 , 16 , 8 , 4 , 2 , 1 ] ,
1749
+ values : [ 64 , 32 , 16 , 8 , 4 , 2 , 1 ] ,
1750
+
1751
+ text : [
1752
+ '666666' ,
1753
+ '55555' ,
1754
+ '4444' ,
1755
+ '333' ,
1756
+ '22' ,
1757
+ '1' ,
1758
+ ''
1759
+ ] ,
1760
+
1761
+ textinfo : 'text'
1762
+ } ] ,
1763
+ layout : {
1764
+ width : 300 ,
1765
+ height : 300
1766
+ }
1767
+ } ;
1768
+
1769
+ Plotly . plot ( gd , fig )
1770
+ . then ( assertTextRotations ( 'using default "auto"' , {
1771
+ rotations : [ - 0.71 , 0 , 0 , 31.18 , 14.17 , - 84.33 , 0 ]
1772
+ } ) )
1773
+ . then ( function ( ) {
1774
+ fig . data [ 0 ] . insidetextorientation = 'horizontal' ;
1775
+ return Plotly . react ( gd , fig ) ;
1776
+ } )
1777
+ . then ( assertTextRotations ( 'using "horizontal"' , {
1778
+ rotations : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
1779
+ } ) )
1780
+ . then ( function ( ) {
1781
+ fig . data [ 0 ] . insidetextorientation = 'radial' ;
1782
+ return Plotly . react ( gd , fig ) ;
1783
+ } )
1784
+ . then ( assertTextRotations ( 'using "radial"' , {
1785
+ rotations : [ 89.29 , - 46.77 , 65.20 , 31.18 , 14.17 , 5.67 , 1.42 ]
1786
+ } ) )
1787
+ . then ( function ( ) {
1788
+ fig . data [ 0 ] . insidetextorientation = 'tangential' ;
1789
+ return Plotly . react ( gd , fig ) ;
1790
+ } )
1791
+ . then ( assertTextRotations ( 'using "tangential"' , {
1792
+ rotations : [ 0 , 43.23 , - 24.80 , - 58.81 , - 75.83 , - 84.33 , - 88.58 ]
1793
+ } ) )
1794
+ . then ( function ( ) {
1795
+ fig . data [ 0 ] . insidetextorientation = 'auto' ;
1796
+ return Plotly . react ( gd , fig ) ;
1797
+ } )
1798
+ . then ( assertTextRotations ( 'back to "auto"' , {
1799
+ rotations : [ - 0.71 , 0 , 0 , 31.18 , 14.17 , - 84.33 , 0 ]
1800
+ } ) )
1801
+ . catch ( failTest )
1802
+ . then ( done ) ;
1803
+ } ) ;
1804
+ } ) ;
1805
+
1806
+ describe ( 'sunburst uniformtext' , function ( ) {
1807
+ 'use strict' ;
1808
+
1809
+ var gd ;
1810
+
1811
+ beforeEach ( function ( ) {
1812
+ gd = createGraphDiv ( ) ;
1813
+ } ) ;
1814
+
1815
+ afterEach ( destroyGraphDiv ) ;
1816
+
1817
+ function assertTextSizes ( msg , opts ) {
1818
+ return function ( ) {
1819
+ var selection = d3 . selectAll ( SLICES_TEXT_SELECTOR ) ;
1820
+ var size = selection . size ( ) ;
1821
+ [ 'fontsizes' , 'scales' ] . forEach ( function ( e ) {
1822
+ expect ( size ) . toBe ( opts [ e ] . length , 'length for ' + e + ' does not match with the number of elements' ) ;
1823
+ } ) ;
1824
+
1825
+ selection . each ( function ( d , i ) {
1826
+ var fontSize = this . style . fontSize ;
1827
+ expect ( fontSize ) . toBe ( opts . fontsizes [ i ] + 'px' , 'fontSize for element ' + i , msg ) ;
1828
+ } ) ;
1829
+
1830
+ for ( var i = 0 ; i < selection [ 0 ] . length ; i ++ ) {
1831
+ var transform = selection [ 0 ] [ i ] . getAttribute ( 'transform' ) ;
1832
+ var pos0 = transform . indexOf ( 'scale(' ) ;
1833
+ var scale = 1 ;
1834
+ if ( pos0 !== - 1 ) {
1835
+ pos0 += 'scale' . length ;
1836
+ var pos1 = transform . indexOf ( ')' , pos0 ) ;
1837
+ scale = + ( transform . substring ( pos0 + 1 , pos1 - 1 ) ) ;
1838
+ }
1839
+
1840
+ expect ( opts . scales [ i ] ) . toBeCloseTo ( scale , 1 , 'scale for element ' + i , msg ) ;
1841
+ }
1842
+ } ;
1843
+ }
1844
+
1845
+ it ( 'should be able to react with new uniform text options' , function ( done ) {
1846
+ var fig = {
1847
+ data : [ {
1848
+ type : 'sunburst' ,
1849
+ parents : [ '' , '' , '' , '' , '' , '' , '' , '' , '' , '' ] ,
1850
+ labels : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
1851
+ values : [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
1852
+
1853
+ text : [
1854
+ 0 ,
1855
+ '<br>' ,
1856
+ null ,
1857
+ '' ,
1858
+ ' ' ,
1859
+ '.' ,
1860
+ '|' ,
1861
+ '=' ,
1862
+ '$' ,
1863
+ 'very long lablel'
1864
+ ] ,
1865
+
1866
+ textinfo : 'text'
1867
+ } ] ,
1868
+ layout : {
1869
+ width : 300 ,
1870
+ height : 300
1871
+ }
1872
+ } ;
1873
+
1874
+ Plotly . plot ( gd , fig )
1875
+ . then ( assertTextSizes ( 'without uniformtext' , {
1876
+ fontsizes : [ 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 ] ,
1877
+ scales : [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0.58 ] ,
1878
+ } ) )
1879
+ . then ( function ( ) {
1880
+ fig . layout . uniformtext = { mode : 'hide' } ; // default with minsize=0
1881
+ return Plotly . react ( gd , fig ) ;
1882
+ } )
1883
+ . then ( assertTextSizes ( 'using mode: "hide"' , {
1884
+ fontsizes : [ 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 ] ,
1885
+ scales : [ 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 ] ,
1886
+ } ) )
1887
+ . then ( function ( ) {
1888
+ fig . layout . uniformtext . minsize = 9 ; // set a minsize less than trace font size
1889
+ return Plotly . react ( gd , fig ) ;
1890
+ } )
1891
+ . then ( assertTextSizes ( 'using minsize: 9' , {
1892
+ fontsizes : [ 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 ] ,
1893
+ scales : [ 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0.58 , 0 ] ,
1894
+ } ) )
1895
+ . then ( function ( ) {
1896
+ fig . layout . uniformtext . minsize = 32 ; // set a minsize greater than trace font size
1897
+ return Plotly . react ( gd , fig ) ;
1898
+ } )
1899
+ . then ( assertTextSizes ( 'using minsize: 32' , {
1900
+ fontsizes : [ 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 ] ,
1901
+ scales : [ 0 , 0.22 , 0.22 , 0.22 , 0.22 , 0.22 , 0.22 , 0 , 0 , 0 ] ,
1902
+ } ) )
1903
+ . then ( function ( ) {
1904
+ fig . layout . uniformtext . minsize = 16 ; // set a minsize greater than trace font size
1905
+ return Plotly . react ( gd , fig ) ;
1906
+ } )
1907
+ . then ( assertTextSizes ( 'using minsize: 16' , {
1908
+ fontsizes : [ 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 ] ,
1909
+ scales : [ 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0 ] ,
1910
+ } ) )
1911
+ . then ( function ( ) {
1912
+ fig . layout . uniformtext . mode = 'show' ;
1913
+ return Plotly . react ( gd , fig ) ;
1914
+ } )
1915
+ . then ( assertTextSizes ( 'using mode: "show"' , {
1916
+ fontsizes : [ 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 , 16 ] ,
1917
+ scales : [ 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 , 0.44 ] ,
1918
+ } ) )
1919
+ . catch ( failTest )
1920
+ . then ( done ) ;
1921
+ } ) ;
1922
+ } ) ;
0 commit comments