@@ -559,6 +559,176 @@ describe('ternary plots', function() {
559559 }
560560} ) ;
561561
562+ describe ( 'ternary plots when css transform is present' , function ( ) {
563+ 'use strict' ;
564+
565+ afterEach ( destroyGraphDiv ) ;
566+
567+ var mock = require ( '@mocks/ternary_simple.json' ) ;
568+ var gd ;
569+
570+ function transformPlot ( gd , transformString ) {
571+ gd . style . webkitTransform = transformString ;
572+ gd . style . MozTransform = transformString ;
573+ gd . style . msTransform = transformString ;
574+ gd . style . OTransform = transformString ;
575+ gd . style . transform = transformString ;
576+ }
577+
578+ var cssTransform = 'translate(-25%, -25%) scale(0.5)' ;
579+ var scale = 0.5 ;
580+ var pointPos = [ scale * 391 , scale * 219 ] ;
581+ var blankPos = [ scale * 200 , scale * 200 ] ;
582+
583+ beforeEach ( function ( done ) {
584+ gd = createGraphDiv ( ) ;
585+
586+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
587+
588+ transformPlot ( gd , cssTransform ) ;
589+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
590+ } ) ;
591+
592+ it ( 'should respond zoom drag interactions' , function ( done ) {
593+ function assertRange ( gd , expected ) {
594+ var ternary = gd . _fullLayout . ternary ;
595+ var actual = [
596+ ternary . aaxis . min ,
597+ ternary . baxis . min ,
598+ ternary . caxis . min
599+ ] ;
600+ expect ( actual ) . toBeCloseToArray ( expected ) ;
601+ }
602+
603+ assertRange ( gd , [ 0.231 , 0.2 , 0.11 ] ) ;
604+
605+ drag ( { path : [ [ scale * 383 , scale * 213 ] , [ scale * 293 , scale * 243 ] ] } )
606+ . then ( function ( ) { assertRange ( gd , [ 0.4486 , 0.2480 , 0.1453 ] ) ; } )
607+ . then ( function ( ) { return doubleClick ( pointPos [ 0 ] , pointPos [ 1 ] ) ; } )
608+ . then ( function ( ) { assertRange ( gd , [ 0 , 0 , 0 ] ) ; } )
609+ . catch ( failTest )
610+ . then ( done ) ;
611+ } ) ;
612+
613+ it ( 'should display to hover labels' , function ( done ) {
614+ mouseEvent ( 'mousemove' , blankPos [ 0 ] , blankPos [ 1 ] ) ;
615+ assertHoverLabelContent ( [ null , null ] , 'only on data points' ) ;
616+
617+ function check ( content , style , msg ) {
618+ Lib . clearThrottle ( ) ;
619+ mouseEvent ( 'mousemove' , pointPos [ 0 ] , pointPos [ 1 ] ) ;
620+
621+ assertHoverLabelContent ( { nums : content } , msg ) ;
622+ assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , style , msg ) ;
623+ }
624+
625+ check ( [
626+ 'Component A: 0.5' ,
627+ 'B: 0.25' ,
628+ 'Component C: 0.25'
629+ ] . join ( '\n' ) , {
630+ bgcolor : 'rgb(31, 119, 180)' ,
631+ bordercolor : 'rgb(255, 255, 255)' ,
632+ fontColor : 'rgb(255, 255, 255)' ,
633+ fontSize : 13 ,
634+ fontFamily : 'Arial'
635+ } , 'one label per data pt' ) ;
636+
637+ Plotly . restyle ( gd , {
638+ 'hoverlabel.bordercolor' : 'blue' ,
639+ 'hoverlabel.font.family' : [ [ 'Gravitas' , 'Arial' , 'Roboto' ] ]
640+ } )
641+ . then ( function ( ) {
642+ check ( [
643+ 'Component A: 0.5' ,
644+ 'B: 0.25' ,
645+ 'Component C: 0.25'
646+ ] . join ( '\n' ) , {
647+ bgcolor : 'rgb(31, 119, 180)' ,
648+ bordercolor : 'rgb(0, 0, 255)' ,
649+ fontColor : 'rgb(0, 0, 255)' ,
650+ fontSize : 13 ,
651+ fontFamily : 'Gravitas'
652+ } , 'after hoverlabel styling restyle call' ) ;
653+
654+ return Plotly . restyle ( gd , 'hoverinfo' , [ [ 'a' , 'b+c' , 'b' ] ] ) ;
655+ } )
656+ . then ( function ( ) {
657+ check ( 'Component A: 0.5' , {
658+ bgcolor : 'rgb(31, 119, 180)' ,
659+ bordercolor : 'rgb(0, 0, 255)' ,
660+ fontColor : 'rgb(0, 0, 255)' ,
661+ fontSize : 13 ,
662+ fontFamily : 'Gravitas'
663+ } , 'after hoverlabel styling restyle call' ) ;
664+ } )
665+ . catch ( failTest )
666+ . then ( done ) ;
667+ } ) ;
668+
669+ it ( 'should respond to hover interactions by' , function ( ) {
670+ var hoverCnt = 0 ;
671+ var unhoverCnt = 0 ;
672+
673+ var hoverData , unhoverData ;
674+
675+ gd . on ( 'plotly_hover' , function ( eventData ) {
676+ hoverCnt ++ ;
677+ hoverData = eventData . points [ 0 ] ;
678+ } ) ;
679+
680+ gd . on ( 'plotly_unhover' , function ( eventData ) {
681+ unhoverCnt ++ ;
682+ unhoverData = eventData . points [ 0 ] ;
683+ } ) ;
684+
685+ mouseEvent ( 'mousemove' , blankPos [ 0 ] , blankPos [ 1 ] ) ;
686+ expect ( hoverData ) . toBe ( undefined , 'not firing on blank points' ) ;
687+ expect ( unhoverData ) . toBe ( undefined , 'not firing on blank points' ) ;
688+
689+ mouseEvent ( 'mousemove' , pointPos [ 0 ] , pointPos [ 1 ] ) ;
690+ expect ( hoverData ) . not . toBe ( undefined , 'firing on data points' ) ;
691+ expect ( Object . keys ( hoverData ) ) . toEqual ( [
692+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' , 'pointIndex' ,
693+ 'xaxis' , 'yaxis' , 'a' , 'b' , 'c'
694+ ] , 'returning the correct event data keys' ) ;
695+ expect ( hoverData . curveNumber ) . toEqual ( 0 , 'returning the correct curve number' ) ;
696+ expect ( hoverData . pointNumber ) . toEqual ( 0 , 'returning the correct point number' ) ;
697+
698+ mouseEvent ( 'mouseout' , pointPos [ 0 ] , pointPos [ 1 ] ) ;
699+ expect ( unhoverData ) . not . toBe ( undefined , 'firing on data points' ) ;
700+ expect ( Object . keys ( unhoverData ) ) . toEqual ( [
701+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' , 'pointIndex' ,
702+ 'xaxis' , 'yaxis' , 'a' , 'b' , 'c'
703+ ] , 'returning the correct event data keys' ) ;
704+ expect ( unhoverData . curveNumber ) . toEqual ( 0 , 'returning the correct curve number' ) ;
705+ expect ( unhoverData . pointNumber ) . toEqual ( 0 , 'returning the correct point number' ) ;
706+
707+ expect ( hoverCnt ) . toEqual ( 1 ) ;
708+ expect ( unhoverCnt ) . toEqual ( 1 ) ;
709+ } ) ;
710+
711+ it ( 'should respond to click interactions by' , function ( ) {
712+ var ptData ;
713+
714+ gd . on ( 'plotly_click' , function ( eventData ) {
715+ ptData = eventData . points [ 0 ] ;
716+ } ) ;
717+
718+ click ( blankPos [ 0 ] , blankPos [ 1 ] ) ;
719+ expect ( ptData ) . toBe ( undefined , 'not firing on blank points' ) ;
720+
721+ click ( pointPos [ 0 ] , pointPos [ 1 ] ) ;
722+ expect ( ptData ) . not . toBe ( undefined , 'firing on data points' ) ;
723+ expect ( Object . keys ( ptData ) ) . toEqual ( [
724+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' , 'pointIndex' ,
725+ 'xaxis' , 'yaxis' , 'a' , 'b' , 'c'
726+ ] , 'returning the correct event data keys' ) ;
727+ expect ( ptData . curveNumber ) . toEqual ( 0 , 'returning the correct curve number' ) ;
728+ expect ( ptData . pointNumber ) . toEqual ( 0 , 'returning the correct point number' ) ;
729+ } ) ;
730+ } ) ;
731+
562732describe ( 'ternary defaults' , function ( ) {
563733 'use strict' ;
564734
0 commit comments