24
24
svg = null ,
25
25
point = null ,
26
26
target = null
27
-
27
+
28
28
function tip ( vis ) {
29
29
svg = getSVGNode ( vis )
30
30
point = svg . createSVGPoint ( )
31
31
document . body . appendChild ( node )
32
32
}
33
-
33
+
34
34
// Public - show the tooltip on the screen
35
35
//
36
36
// Returns a tip
37
37
tip . show = function ( ) {
38
38
var args = Array . prototype . slice . call ( arguments )
39
39
if ( args [ args . length - 1 ] instanceof SVGElement ) target = args . pop ( )
40
-
40
+
41
41
var content = html . apply ( this , args ) ,
42
42
poffset = offset . apply ( this , args ) ,
43
43
dir = direction . apply ( this , args ) ,
46
46
coords ,
47
47
scrollTop = document . documentElement . scrollTop || document . body . scrollTop ,
48
48
scrollLeft = document . documentElement . scrollLeft || document . body . scrollLeft
49
-
49
+
50
50
nodel . html ( content )
51
51
. style ( { opacity : 1 , 'pointer-events' : 'all' } )
52
-
52
+
53
53
while ( i -- ) nodel . classed ( directions [ i ] , false )
54
54
coords = direction_callbacks . get ( dir ) . apply ( this )
55
55
nodel . classed ( dir , true ) . style ( {
56
56
top : ( coords . top + poffset [ 0 ] ) + scrollTop + 'px' ,
57
57
left : ( coords . left + poffset [ 1 ] ) + scrollLeft + 'px'
58
58
} )
59
-
59
+
60
60
return tip
61
61
}
62
-
62
+
63
63
// Public - hide the tooltip
64
64
//
65
65
// Returns a tip
68
68
nodel . style ( { opacity : 0 , 'pointer-events' : 'none' } )
69
69
return tip
70
70
}
71
-
71
+
72
72
// Public: Proxy attr calls to the d3 tip container. Sets or gets attribute value.
73
73
//
74
74
// n - name of the attribute
82
82
var args = Array . prototype . slice . call ( arguments )
83
83
d3 . selection . prototype . attr . apply ( d3 . select ( node ) , args )
84
84
}
85
-
85
+
86
86
return tip
87
87
}
88
-
88
+
89
89
// Public: Proxy style calls to the d3 tip container. Sets or gets a style value.
90
90
//
91
91
// n - name of the property
99
99
var args = Array . prototype . slice . call ( arguments )
100
100
d3 . selection . prototype . style . apply ( d3 . select ( node ) , args )
101
101
}
102
-
102
+
103
103
return tip
104
104
}
105
-
105
+
106
106
// Public: Set or get the direction of the tooltip
107
107
//
108
108
// v - One of n(north), s(south), e(east), or w(west), nw(northwest),
112
112
tip . direction = function ( v ) {
113
113
if ( ! arguments . length ) return direction
114
114
direction = v == null ? v : d3 . functor ( v )
115
-
115
+
116
116
return tip
117
117
}
118
-
118
+
119
119
// Public: Sets or gets the offset of the tip
120
120
//
121
121
// v - Array of [x, y] offset
124
124
tip . offset = function ( v ) {
125
125
if ( ! arguments . length ) return offset
126
126
offset = v == null ? v : d3 . functor ( v )
127
-
127
+
128
128
return tip
129
129
}
130
-
130
+
131
131
// Public: sets or gets the html value of the tooltip
132
132
//
133
133
// v - String value of the tip
136
136
tip . html = function ( v ) {
137
137
if ( ! arguments . length ) return html
138
138
html = v == null ? v : d3 . functor ( v )
139
-
139
+
140
140
return tip
141
141
}
142
-
142
+
143
143
function d3_tip_direction ( ) { return 'n' }
144
144
function d3_tip_offset ( ) { return [ 0 , 0 ] }
145
145
function d3_tip_html ( ) { return ' ' }
146
-
146
+
147
147
var direction_callbacks = d3 . map ( {
148
148
n : direction_n ,
149
149
s : direction_s ,
154
154
sw : direction_sw ,
155
155
se : direction_se
156
156
} ) ,
157
-
157
+
158
158
directions = direction_callbacks . keys ( )
159
-
159
+
160
160
function direction_n ( ) {
161
161
var bbox = getScreenBBox ( )
162
162
return {
163
163
top : bbox . n . y - node . offsetHeight ,
164
164
left : bbox . n . x - node . offsetWidth / 2
165
165
}
166
166
}
167
-
167
+
168
168
function direction_s ( ) {
169
169
var bbox = getScreenBBox ( )
170
170
return {
171
171
top : bbox . s . y ,
172
172
left : bbox . s . x - node . offsetWidth / 2
173
173
}
174
174
}
175
-
175
+
176
176
function direction_e ( ) {
177
177
var bbox = getScreenBBox ( )
178
178
return {
179
179
top : bbox . e . y - node . offsetHeight / 2 ,
180
180
left : bbox . e . x
181
181
}
182
182
}
183
-
183
+
184
184
function direction_w ( ) {
185
185
var bbox = getScreenBBox ( )
186
186
return {
187
187
top : bbox . w . y - node . offsetHeight / 2 ,
188
188
left : bbox . w . x - node . offsetWidth
189
189
}
190
190
}
191
-
191
+
192
192
function direction_nw ( ) {
193
193
var bbox = getScreenBBox ( )
194
194
return {
195
195
top : bbox . nw . y - node . offsetHeight ,
196
196
left : bbox . nw . x - node . offsetWidth
197
197
}
198
198
}
199
-
199
+
200
200
function direction_ne ( ) {
201
201
var bbox = getScreenBBox ( )
202
202
return {
203
203
top : bbox . ne . y - node . offsetHeight ,
204
204
left : bbox . ne . x
205
205
}
206
206
}
207
-
207
+
208
208
function direction_sw ( ) {
209
209
var bbox = getScreenBBox ( )
210
210
return {
211
211
top : bbox . sw . y ,
212
212
left : bbox . sw . x - node . offsetWidth
213
213
}
214
214
}
215
-
215
+
216
216
function direction_se ( ) {
217
217
var bbox = getScreenBBox ( )
218
218
return {
219
219
top : bbox . se . y ,
220
220
left : bbox . e . x
221
221
}
222
222
}
223
-
223
+
224
224
function initNode ( ) {
225
225
var node = d3 . select ( document . createElement ( 'div' ) )
226
226
node . style ( {
230
230
'pointer-events' : 'none' ,
231
231
'box-sizing' : 'border-box'
232
232
} )
233
-
233
+
234
234
return node . node ( )
235
235
}
236
-
236
+
237
237
function getSVGNode ( el ) {
238
238
el = el . node ( )
239
239
if ( el . tagName . toLowerCase ( ) == 'svg' )
240
240
return el
241
-
241
+
242
242
return el . ownerSVGElement
243
243
}
244
-
244
+
245
245
// Private - gets the screen coordinates of a shape
246
246
//
247
247
// Given a shape on the screen, will return an SVGPoint for the directions
264
264
height = tbbox . height ,
265
265
x = tbbox . x ,
266
266
y = tbbox . y
267
-
267
+
268
268
point . x = x
269
269
point . y = y
270
270
bbox . nw = point . matrixTransform ( matrix )
283
283
bbox . n = point . matrixTransform ( matrix )
284
284
point . y += height
285
285
bbox . s = point . matrixTransform ( matrix )
286
-
286
+
287
287
return bbox
288
288
}
289
-
289
+
290
290
return tip
291
291
} ;
292
292
293
- } ) ) ;
293
+ } ) ) ;
0 commit comments