@@ -9,28 +9,28 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
99
1010describe ( 'hover info' , function ( ) {
1111 'use strict' ;
12-
12+
1313 var mock = require ( '@mocks/14.json' ) ,
1414 evt = {
1515 clientX : mock . layout . width / 2 ,
1616 clientY : mock . layout . height / 2
1717 } ;
18-
18+
1919 afterEach ( destroyGraphDiv ) ;
2020
2121 describe ( 'hover info' , function ( ) {
2222 var mockCopy = Lib . extendDeep ( { } , mock ) ;
2323
2424 beforeEach ( function ( done ) {
2525 Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
26- } ) ;
26+ } ) ;
2727
2828 it ( 'responds to hover' , function ( ) {
2929 var gd = document . getElementById ( 'graph' ) ;
3030 Fx . hover ( 'graph' , evt , 'xy' ) ;
31-
31+
3232 var hoverTrace = gd . _hoverdata [ 0 ] ;
33-
33+
3434 expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
3535 expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
3636 expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -50,14 +50,14 @@ describe('hover info', function() {
5050
5151 beforeEach ( function ( done ) {
5252 Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
53- } ) ;
53+ } ) ;
5454
5555 it ( 'responds to hover x' , function ( ) {
5656 var gd = document . getElementById ( 'graph' ) ;
5757 Fx . hover ( 'graph' , evt , 'xy' ) ;
58-
58+
5959 var hoverTrace = gd . _hoverdata [ 0 ] ;
60-
60+
6161 expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
6262 expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
6363 expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -76,14 +76,14 @@ describe('hover info', function() {
7676
7777 beforeEach ( function ( done ) {
7878 Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
79- } ) ;
79+ } ) ;
8080
8181 it ( 'responds to hover y' , function ( ) {
8282 var gd = document . getElementById ( 'graph' ) ;
8383 Fx . hover ( 'graph' , evt , 'xy' ) ;
84-
84+
8585 var hoverTrace = gd . _hoverdata [ 0 ] ;
86-
86+
8787 expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
8888 expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
8989 expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -94,4 +94,146 @@ describe('hover info', function() {
9494 expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '1' ) ;
9595 } ) ;
9696 } ) ;
97+
98+ describe ( 'hover info text' , function ( ) {
99+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
100+
101+ mockCopy . data [ 0 ] . text = [ ]
102+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover text'
103+ mockCopy . data [ 0 ] . hoverinfo = 'text' ;
104+
105+ beforeEach ( function ( done ) {
106+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
107+ } ) ;
108+
109+ it ( 'responds to hover text' , function ( ) {
110+ var gd = document . getElementById ( 'graph' ) ;
111+ Fx . hover ( 'graph' , evt , 'xy' ) ;
112+
113+ var hoverTrace = gd . _hoverdata [ 0 ] ;
114+
115+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
116+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
117+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
118+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
119+
120+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 0 ) ;
121+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
122+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'hover text' ) ;
123+ } ) ;
124+ } ) ;
125+
126+ describe ( 'hover info all' , function ( ) {
127+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
128+
129+ mockCopy . data [ 0 ] . text = [ ]
130+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover text'
131+ mockCopy . data [ 0 ] . hoverinfo = 'all' ;
132+
133+ beforeEach ( function ( done ) {
134+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
135+ } ) ;
136+
137+ it ( 'responds to hover all' , function ( ) {
138+ var gd = document . getElementById ( 'graph' ) ;
139+ Fx . hover ( 'graph' , evt , 'xy' ) ;
140+
141+ var hoverTrace = gd . _hoverdata [ 0 ] ;
142+
143+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
144+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
145+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
146+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
147+
148+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 1 ) ;
149+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
150+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '0.388' ) ;
151+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '<tspan class="line" dy="0em" x="9" y="-3.9453125">1</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">hover text</tspan>' ) ;
152+ } ) ;
153+ } ) ;
154+
155+ describe ( 'hover info y+text' , function ( ) {
156+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
157+
158+ mockCopy . data [ 0 ] . text = [ ]
159+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover text'
160+ mockCopy . data [ 0 ] . hoverinfo = 'y+text' ;
161+
162+ beforeEach ( function ( done ) {
163+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
164+ } ) ;
165+
166+ it ( 'responds to hover y+text' , function ( ) {
167+ var gd = document . getElementById ( 'graph' ) ;
168+ Fx . hover ( 'graph' , evt , 'xy' ) ;
169+
170+ var hoverTrace = gd . _hoverdata [ 0 ] ;
171+
172+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
173+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
174+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
175+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
176+
177+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 0 ) ;
178+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
179+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '<tspan class="line" dy="0em" x="9" y="-3.9453125">1</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">hover text</tspan>' ) ;
180+ } ) ;
181+ } ) ;
182+
183+ describe ( 'hover info x+text' , function ( ) {
184+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
185+
186+ mockCopy . data [ 0 ] . text = [ ]
187+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover text'
188+ mockCopy . data [ 0 ] . hoverinfo = 'x+text' ;
189+
190+ beforeEach ( function ( done ) {
191+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
192+ } ) ;
193+
194+ it ( 'responds to hover x+text' , function ( ) {
195+ var gd = document . getElementById ( 'graph' ) ;
196+ Fx . hover ( 'graph' , evt , 'xy' ) ;
197+
198+ var hoverTrace = gd . _hoverdata [ 0 ] ;
199+
200+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
201+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
202+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
203+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
204+
205+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 1 ) ;
206+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
207+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '0.388' ) ;
208+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( 'hover text' ) ;
209+ } ) ;
210+ } ) ;
211+
212+ describe ( 'hover info text with html' , function ( ) {
213+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
214+
215+ mockCopy . data [ 0 ] . text = [ ]
216+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover<br>text'
217+ mockCopy . data [ 0 ] . hoverinfo = 'text' ;
218+
219+ beforeEach ( function ( done ) {
220+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
221+ } ) ;
222+
223+ it ( 'responds to hover text with html' , function ( ) {
224+ var gd = document . getElementById ( 'graph' ) ;
225+ Fx . hover ( 'graph' , evt , 'xy' ) ;
226+
227+ var hoverTrace = gd . _hoverdata [ 0 ] ;
228+
229+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
230+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
231+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
232+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
233+
234+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 0 ) ;
235+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
236+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '<tspan class="line" dy="0em" x="9" y="-3.9453125">hover</tspan><tspan class="line" dy="1.3em" x="9" y="-3.9453125">text</tspan>' ) ;
237+ } ) ;
238+ } ) ;
97239} ) ;
0 commit comments