@@ -9,28 +9,28 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
9
9
10
10
describe ( 'hover info' , function ( ) {
11
11
'use strict' ;
12
-
12
+
13
13
var mock = require ( '@mocks/14.json' ) ,
14
14
evt = {
15
15
clientX : mock . layout . width / 2 ,
16
16
clientY : mock . layout . height / 2
17
17
} ;
18
-
18
+
19
19
afterEach ( destroyGraphDiv ) ;
20
20
21
21
describe ( 'hover info' , function ( ) {
22
22
var mockCopy = Lib . extendDeep ( { } , mock ) ;
23
23
24
24
beforeEach ( function ( done ) {
25
25
Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
26
- } ) ;
26
+ } ) ;
27
27
28
28
it ( 'responds to hover' , function ( ) {
29
29
var gd = document . getElementById ( 'graph' ) ;
30
30
Fx . hover ( 'graph' , evt , 'xy' ) ;
31
-
31
+
32
32
var hoverTrace = gd . _hoverdata [ 0 ] ;
33
-
33
+
34
34
expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
35
35
expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
36
36
expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -50,14 +50,14 @@ describe('hover info', function() {
50
50
51
51
beforeEach ( function ( done ) {
52
52
Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
53
- } ) ;
53
+ } ) ;
54
54
55
55
it ( 'responds to hover x' , function ( ) {
56
56
var gd = document . getElementById ( 'graph' ) ;
57
57
Fx . hover ( 'graph' , evt , 'xy' ) ;
58
-
58
+
59
59
var hoverTrace = gd . _hoverdata [ 0 ] ;
60
-
60
+
61
61
expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
62
62
expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
63
63
expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -76,14 +76,14 @@ describe('hover info', function() {
76
76
77
77
beforeEach ( function ( done ) {
78
78
Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
79
- } ) ;
79
+ } ) ;
80
80
81
81
it ( 'responds to hover y' , function ( ) {
82
82
var gd = document . getElementById ( 'graph' ) ;
83
83
Fx . hover ( 'graph' , evt , 'xy' ) ;
84
-
84
+
85
85
var hoverTrace = gd . _hoverdata [ 0 ] ;
86
-
86
+
87
87
expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
88
88
expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
89
89
expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
@@ -94,4 +94,146 @@ describe('hover info', function() {
94
94
expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '1' ) ;
95
95
} ) ;
96
96
} ) ;
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
+ } ) ;
97
239
} ) ;
0 commit comments