@@ -6896,6 +6896,64 @@ describe('more react tests', function() {
6896
6896
} ) ;
6897
6897
} ) ;
6898
6898
6899
+ describe ( 'category preservation tests on gd passed to Plotly.react()' , function ( ) {
6900
+ var gd ;
6901
+
6902
+ beforeEach ( function ( ) {
6903
+ gd = createGraphDiv ( ) ;
6904
+ } ) ;
6905
+
6906
+ afterEach ( destroyGraphDiv ) ;
6907
+
6908
+ function _hover ( gd , opts ) {
6909
+ Fx . hover ( gd , opts ) ;
6910
+ // needed for successive hover events
6911
+ Lib . clearThrottle ( ) ;
6912
+ }
6913
+
6914
+ it ( 'should preserve categories and axis ticklabels' , function ( done ) {
6915
+ var fig = {
6916
+ data : [ {
6917
+ type : 'bar' ,
6918
+ y : [ 3 , 5 , 3 , 2 ] ,
6919
+ x : [ 'a' , 'b' , 'c' , 'd' ]
6920
+ } ] ,
6921
+ layout : {
6922
+ width : 500 ,
6923
+ height : 500
6924
+ }
6925
+ } ;
6926
+
6927
+ Plotly . newPlot ( gd , fig )
6928
+ . then ( function ( gd ) {
6929
+ return Plotly . react ( gd , fig ) ;
6930
+ } )
6931
+ . then ( function ( ) {
6932
+ expect ( gd . _fullLayout . xaxis . _categories ) . toEqual ( [ 'a' , 'b' , 'c' , 'd' ] ) ;
6933
+ expect ( gd . _fullLayout . xaxis . _categoriesMap ) . toEqual ( { a : 0 , b : 1 , c : 2 , d : 3 } ) ;
6934
+ } )
6935
+ . then ( function ( ) {
6936
+ _hover ( gd , { xval : fig . data [ 0 ] . x . indexOf ( 'a' ) } ) ;
6937
+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'a' ) ;
6938
+ } )
6939
+ . then ( function ( ) {
6940
+ _hover ( gd , { xval : fig . data [ 0 ] . x . indexOf ( 'b' ) } ) ;
6941
+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'b' ) ;
6942
+ } )
6943
+ . then ( function ( ) {
6944
+ _hover ( gd , { xval : fig . data [ 0 ] . x . indexOf ( 'c' ) } ) ;
6945
+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'c' ) ;
6946
+ } )
6947
+ . then ( function ( ) {
6948
+ _hover ( gd , { xval : fig . data [ 0 ] . x . indexOf ( 'd' ) } ) ;
6949
+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'd' ) ;
6950
+ } )
6951
+
6952
+ . catch ( failTest )
6953
+ . then ( done ) ;
6954
+ } ) ;
6955
+ } ) ;
6956
+
6899
6957
describe ( 'more matching axes tests' , function ( ) {
6900
6958
var gd ;
6901
6959
0 commit comments