@@ -1674,6 +1674,67 @@ describe('legend interaction', function() {
1674
1674
} ) ;
1675
1675
} ) ;
1676
1676
1677
+ describe ( 'editable mode interactions for shape legends' , function ( ) {
1678
+ var gd ;
1679
+
1680
+ var mock = {
1681
+ data : [ ] ,
1682
+ layout : {
1683
+ shapes : [
1684
+ { showlegend : true , type : 'line' , xref : 'paper' , yref : 'paper' , x0 : 0.1 , y0 : 0.2 , x1 : 0.2 , y1 : 0.1 } ,
1685
+ { showlegend : true , type : 'line' , xref : 'paper' , yref : 'paper' , x0 : 0.3 , y0 : 0.4 , x1 : 0.4 , y1 : 0.3 } ,
1686
+ { showlegend : true , type : 'line' , xref : 'paper' , yref : 'paper' , x0 : 0.5 , y0 : 0.6 , x1 : 0.6 , y1 : 0.5 } ,
1687
+ { showlegend : true , type : 'line' , xref : 'paper' , yref : 'paper' , x0 : 0.7 , y0 : 0.8 , x1 : 0.8 , y1 : 0.7 } ,
1688
+ { showlegend : true , type : 'line' , xref : 'paper' , yref : 'paper' , x0 : 0.9 , y0 : 1.0 , x1 : 1.0 , y1 : 0.9 }
1689
+ ]
1690
+ } ,
1691
+ config : { editable : true }
1692
+ } ;
1693
+
1694
+ beforeEach ( function ( done ) {
1695
+ gd = createGraphDiv ( ) ;
1696
+ Plotly . newPlot ( gd , Lib . extendDeep ( { } , mock ) ) . then ( done ) ;
1697
+ } ) ;
1698
+
1699
+ afterEach ( destroyGraphDiv ) ;
1700
+
1701
+ function _setValue ( index , str ) {
1702
+ var item = d3SelectAll ( 'text.legendtext' ) [ 0 ] [ index || 0 ] ;
1703
+ item . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
1704
+ return delay ( 20 ) ( ) . then ( function ( ) {
1705
+ var input = d3Select ( '.plugin-editable.editable' ) ;
1706
+ input . text ( str ) ;
1707
+ input . node ( ) . dispatchEvent ( new KeyboardEvent ( 'blur' ) ) ;
1708
+ } ) . then ( delay ( 20 ) ) ;
1709
+ }
1710
+
1711
+ function assertLabels ( expected ) {
1712
+ var labels = [ ] ;
1713
+ d3SelectAll ( 'text.legendtext' ) . each ( function ( ) {
1714
+ labels . push ( this . textContent ) ;
1715
+ } ) ;
1716
+ expect ( labels ) . toEqual ( expected ) ;
1717
+ }
1718
+
1719
+ it ( 'sets and unsets shape group names' , function ( done ) {
1720
+ assertLabels ( [ 'shape 0' , 'shape 1' , 'shape 2' , 'shape 3' , 'shape 4' ] ) ;
1721
+ // Set the name of the first shape:
1722
+ _setValue ( 0 , 'foo' ) . then ( function ( ) {
1723
+ expect ( gd . layout . shapes [ 0 ] . name ) . toEqual ( 'foo' ) ;
1724
+ // labels shorter than half the longest get padded with spaces to match the longest length
1725
+ assertLabels ( [ 'foo ' , 'shape 1' , 'shape 2' , 'shape 3' , 'shape 4' ] ) ;
1726
+
1727
+ // Set the name of the third legend item:
1728
+ return _setValue ( 3 , 'barbar' ) ;
1729
+ } ) . then ( function ( ) {
1730
+ expect ( gd . layout . shapes [ 3 ] . name ) . toEqual ( 'barbar' ) ;
1731
+ assertLabels ( [ 'foo ' , 'shape 1' , 'shape 2' , 'barbar' , 'shape 4' ] ) ;
1732
+
1733
+ return _setValue ( 2 , 'asdf' ) ;
1734
+ } ) . then ( done , done . fail ) ;
1735
+ } ) ;
1736
+ } ) ;
1737
+
1677
1738
describe ( 'staticPlot' , function ( ) {
1678
1739
var gd ;
1679
1740
@@ -1953,7 +2014,7 @@ describe('legend interaction', function() {
1953
2014
. then ( done , done . fail ) ;
1954
2015
} ) ;
1955
2016
1956
- it ( 'double-clicking isolates a visible trace ' , function ( done ) {
2017
+ it ( 'double-clicking isolates a visible shape ' , function ( done ) {
1957
2018
Promise . resolve ( )
1958
2019
. then ( click ( 0 ) )
1959
2020
. then ( assertVisibleShapes ( [ false , true , true ] ) )
@@ -1962,7 +2023,7 @@ describe('legend interaction', function() {
1962
2023
. then ( done , done . fail ) ;
1963
2024
} ) ;
1964
2025
1965
- it ( 'double-clicking an isolated trace shows all non-hidden traces ' , function ( done ) {
2026
+ it ( 'double-clicking an isolated trace shows all non-hidden shapes ' , function ( done ) {
1966
2027
Promise . resolve ( )
1967
2028
. then ( click ( 0 , 2 ) )
1968
2029
. then ( assertVisibleShapes ( [ false , true , true ] ) )
0 commit comments