@@ -4,14 +4,19 @@ enyo.kind({
4
4
kind : enyo . Control ,
5
5
6
6
published : {
7
- data : undefined ,
8
- tooltipListener : undefined ,
7
+ data : undefined
9
8
} ,
10
9
11
10
components : [
12
11
{ tag : "div" , name : "context" } ,
13
12
{ tag : "div" , name : "focus" }
14
13
] ,
14
+ tooltipView : undefined ,
15
+
16
+ create : function ( ) {
17
+ this . inherited ( arguments ) ;
18
+ this . tooltipView = new edvent . InfoView ( ) ;
19
+ } ,
15
20
16
21
plot : function ( ) {
17
22
@@ -48,6 +53,24 @@ enyo.kind({
48
53
. call ( axis ) ;
49
54
} ;
50
55
56
+ tip = d3 . tip ( ) . attr ( 'class' , 'd3-tip' )
57
+ . render ( enyo . bind ( this , function ( node , d ) {
58
+ this . tooltipView . setTo ( d ) ;
59
+ this . tooltipView . renderInto ( node ) ;
60
+ } )
61
+ ) ;
62
+
63
+ tip . offset ( function ( width ) {
64
+ return function ( d ) {
65
+ return this . getBoundingClientRect ( ) . left > width / 2 ? [ 0 , - 10 ] : [ 0 , 10 ] ;
66
+ }
67
+ } ( width ) )
68
+ . direction ( function ( width ) {
69
+ return function ( d ) {
70
+ return this . getBoundingClientRect ( ) . left > width / 2 ? "w" : "e" ;
71
+ }
72
+ } ( width ) ) ;
73
+
51
74
brushed = function ( ) {
52
75
x . domain ( brush . empty ( ) ? x2 . domain ( ) : brush . extent ( ) ) ;
53
76
svg . selectAll ( ".line" )
@@ -142,6 +165,7 @@ enyo.kind({
142
165
. append ( "g" )
143
166
. attr ( "transform" , "translate(" + margin . left + "," + margin . top + ")" ) ;
144
167
168
+ svg . call ( tip ) ;
145
169
svg . append ( "defs" ) . append ( "clipPath" )
146
170
. attr ( "transform" , "translate(" + 0 + "," + - 7 + ")" )
147
171
. attr ( "id" , "clip" )
@@ -174,6 +198,37 @@ enyo.kind({
174
198
. style ( "text-anchor" , "end" )
175
199
. text ( function ( d , index ) { return class_list [ index ] . key ; } ) ;
176
200
201
+ // lines
202
+ var line = d3 . svg . line ( )
203
+ . interpolate ( "step-after" )
204
+ . x ( function ( d ) { return x ( d . index ) ; } )
205
+ . y ( function ( d ) { return yList [ d . class_index ] ( d . method ) ; } ) ;
206
+
207
+ var objects = function ( d , index ) {
208
+ return colorList [ index ] . domain ( ) . map ( function ( obj ) {
209
+ return {
210
+ obj : obj ,
211
+ class_index : index ,
212
+ values : d . values . filter ( function ( e ) {
213
+ return e . obj == obj ;
214
+ } )
215
+ } ;
216
+ } ) ;
217
+ } ;
218
+
219
+ var object = svg . selectAll ( ".object" )
220
+ . data ( objects )
221
+ . enter ( ) . append ( "g" )
222
+ . attr ( "class" , "object" ) ;
223
+
224
+ object . append ( "path" )
225
+ . attr ( "clip-path" , "url(#clip)" )
226
+ . attr ( "class" , "line" )
227
+ . attr ( "d" , function ( d ) { return line ( d . values ) ; } )
228
+ . style ( "stroke" , function ( d ) {
229
+ return colorList [ d . class_index ] ( d . obj ) ;
230
+ } ) ;
231
+
177
232
// scatter plot
178
233
var shapes = svg . append ( "g" )
179
234
. attr ( "clip-path" , "url(#clip)" )
@@ -189,12 +244,8 @@ enyo.kind({
189
244
. attr ( "cx" , function ( d ) { return x ( d . index ) ; } )
190
245
. attr ( "cy" , function ( d ) { return yList [ d . class_index ] ( d . method ) ; } )
191
246
. style ( "fill" , function ( d ) { return colorList [ d . class_index ] ( d . obj ) ; } )
192
-
193
- . on ( "mouseover" , enyo . bind ( this , function ( d ) {
194
- if ( this . tooltipListener != undefined )
195
- this . tooltipListener ( d ) ;
196
- } ) ) ;
197
-
247
+ . on ( 'mouseover' , tip . show )
248
+ . on ( 'mouseout' , tip . hide ) ;
198
249
199
250
// entry
200
251
shapes . append ( "rect" )
@@ -205,11 +256,8 @@ enyo.kind({
205
256
. attr ( "width" , 10 )
206
257
. attr ( "height" , 10 )
207
258
. style ( "fill" , function ( d ) { return colorList [ d . class_index ] ( d . obj ) ; } )
208
-
209
- . on ( "mouseover" , enyo . bind ( this , function ( d ) {
210
- if ( this . tooltipListener != undefined )
211
- this . tooltipListener ( d ) ;
212
- } ) ) ;
259
+ . on ( 'mouseover' , tip . show )
260
+ . on ( 'mouseout' , tip . hide ) ;
213
261
214
262
// exit
215
263
shapes . append ( "rect" )
@@ -223,43 +271,8 @@ enyo.kind({
223
271
. attr ( "width" , 10 )
224
272
. attr ( "height" , 10 )
225
273
. style ( "fill" , function ( d ) { return colorList [ d . class_index ] ( d . obj ) ; } )
226
-
227
- . on ( "mouseover" , enyo . bind ( this , function ( d ) {
228
- if ( this . tooltipListener != undefined )
229
- this . tooltipListener ( d ) ;
230
- } ) ) ;
231
-
232
- // lines
233
- var line = d3 . svg . line ( )
234
- . interpolate ( "step-after" )
235
- . x ( function ( d ) { return x ( d . index ) ; } )
236
- . y ( function ( d ) { return yList [ d . class_index ] ( d . method ) ; } ) ;
237
-
238
- var objects = function ( d , index ) {
239
- return colorList [ index ] . domain ( ) . map ( function ( obj ) {
240
- return {
241
- obj : obj ,
242
- class_index : index ,
243
- values : d . values . filter ( function ( e ) {
244
- return e . obj == obj ;
245
- } )
246
- } ;
247
- } ) ;
248
- } ;
249
-
250
- var object = svg . selectAll ( ".object" )
251
- . data ( objects )
252
- . enter ( ) . append ( "g" )
253
- . attr ( "class" , "object" ) ;
254
-
255
- object . append ( "path" )
256
- . attr ( "clip-path" , "url(#clip)" )
257
- . attr ( "class" , "line" )
258
- . attr ( "d" , function ( d ) { return line ( d . values ) ; } )
259
- . style ( "stroke" , function ( d ) {
260
- return colorList [ d . class_index ] ( d . obj ) ;
261
- } ) ;
262
-
274
+ . on ( 'mouseover' , tip . show )
275
+ . on ( 'mouseout' , tip . hide ) ;
263
276
}
264
277
265
278
0 commit comments