@@ -13,6 +13,10 @@ var fail = require('../assets/fail_test');
1313var checkTicks = require ( '../assets/custom_assertions' ) . checkTicks ;
1414var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
1515
16+ var customAssertions = require ( '../assets/custom_assertions' ) ;
17+ var assertClip = customAssertions . assertClip ;
18+ var assertNodeDisplay = customAssertions . assertNodeDisplay ;
19+
1620var d3 = require ( 'd3' ) ;
1721
1822describe ( 'Bar.supplyDefaults' , function ( ) {
@@ -1509,6 +1513,96 @@ describe('bar hover', function() {
15091513 . then ( done ) ;
15101514 } ) ;
15111515 } ) ;
1516+
1517+ it ( 'should show/hide text in clipped and non-clipped layers' , function ( done ) {
1518+ var fig = Lib . extendDeep ( { } , require ( '@mocks/bar_cliponaxis-false.json' ) ) ;
1519+ gd = createGraphDiv ( ) ;
1520+
1521+ // only show one trace
1522+ fig . data = [ fig . data [ 0 ] ] ;
1523+
1524+ function _assert ( layerClips , barDisplays , barTextDisplays , barClips ) {
1525+ var subplotLayer = d3 . select ( '.plot' ) ;
1526+ var barLayer = subplotLayer . select ( '.barlayer' ) ;
1527+
1528+ assertClip ( subplotLayer , layerClips [ 0 ] , 1 , 'subplot layer' ) ;
1529+ assertClip ( subplotLayer . select ( '.maplayer' ) , layerClips [ 1 ] , 1 , 'some other trace layer' ) ;
1530+ assertClip ( barLayer , layerClips [ 2 ] , 1 , 'bar layer' ) ;
1531+
1532+ assertNodeDisplay (
1533+ barLayer . selectAll ( '.point' ) ,
1534+ barDisplays ,
1535+ 'bar points (never hidden by display attr)'
1536+ ) ;
1537+ assertNodeDisplay (
1538+ barLayer . selectAll ( '.bartext' ) ,
1539+ barTextDisplays ,
1540+ 'bar text'
1541+ ) ;
1542+
1543+ assertClip (
1544+ barLayer . selectAll ( '.point > path' ) ,
1545+ barClips [ 0 ] , barClips [ 1 ] ,
1546+ 'bar clips'
1547+ ) ;
1548+ }
1549+
1550+ Plotly . newPlot ( gd , fig ) . then ( function ( ) {
1551+ _assert (
1552+ [ false , true , false ] ,
1553+ [ null , null , null ] ,
1554+ [ null , null , 'none' ] ,
1555+ [ true , 3 ]
1556+ ) ;
1557+ return Plotly . restyle ( gd , 'visible' , false ) ;
1558+ } )
1559+ . then ( function ( ) {
1560+ _assert (
1561+ [ true , false , false ] ,
1562+ [ ] ,
1563+ [ ] ,
1564+ [ false , 0 ]
1565+ ) ;
1566+ return Plotly . restyle ( gd , { visible : true , cliponaxis : null } ) ;
1567+ } )
1568+ . then ( function ( ) {
1569+ _assert (
1570+ [ true , false , false ] ,
1571+ [ null , null , null ] ,
1572+ [ null , null , null ] ,
1573+ [ false , 3 ]
1574+ ) ;
1575+ return Plotly . restyle ( gd , 'cliponaxis' , false ) ;
1576+ } )
1577+ . then ( function ( ) {
1578+ _assert (
1579+ [ false , true , false ] ,
1580+ [ null , null , null ] ,
1581+ [ null , null , 'none' ] ,
1582+ [ true , 3 ]
1583+ ) ;
1584+ return Plotly . relayout ( gd , 'yaxis.range' , [ 0 , 1 ] ) ;
1585+ } )
1586+ . then ( function ( ) {
1587+ _assert (
1588+ [ false , true , false ] ,
1589+ [ null , null , null ] ,
1590+ [ 'none' , 'none' , 'none' ] ,
1591+ [ true , 3 ]
1592+ ) ;
1593+ return Plotly . relayout ( gd , 'yaxis.range' , [ 0 , 4 ] ) ;
1594+ } )
1595+ . then ( function ( ) {
1596+ _assert (
1597+ [ false , true , false ] ,
1598+ [ null , null , null ] ,
1599+ [ null , null , null ] ,
1600+ [ true , 3 ]
1601+ ) ;
1602+ } )
1603+ . catch ( fail )
1604+ . then ( done ) ;
1605+ } ) ;
15121606} ) ;
15131607
15141608function mockBarPlot ( dataWithoutTraceType , layout ) {
0 commit comments