@@ -59,46 +59,49 @@ plotChoropleth.calcGeoJSON = function(trace, topojson) {
59
59
60
60
plotChoropleth . plot = function ( geo , choroplethData , geoLayout ) {
61
61
var framework = geo . framework ,
62
- topojson = geo . topojson ,
63
62
gChoropleth = framework . select ( 'g.choroplethlayer' ) ,
64
63
gBaseLayer = framework . select ( 'g.baselayer' ) ,
65
64
gBaseLayerOverChoropleth = framework . select ( 'g.baselayeroverchoropleth' ) ,
66
65
baseLayersOverChoropleth = constants . baseLayersOverChoropleth ,
67
66
layerName ;
68
67
69
- // TODO move to more d3-idiomatic pattern (that's work on replot)
70
- // N.B. html('') does not work in IE11
71
- gChoropleth . selectAll ( '*' ) . remove ( ) ;
72
- gBaseLayerOverChoropleth . selectAll ( '*' ) . remove ( ) ;
73
-
74
68
var gChoroplethTraces = gChoropleth
75
- . selectAll ( 'g.trace.scatter ' )
69
+ . selectAll ( 'g.trace.choropleth ' )
76
70
. data ( choroplethData ) ;
77
71
78
72
gChoroplethTraces . enter ( ) . append ( 'g' )
79
- . attr ( 'class' , 'trace choropleth' ) ;
73
+ . attr ( 'class' , 'trace choropleth' ) ;
74
+
75
+ gChoroplethTraces . exit ( ) . remove ( ) ;
80
76
81
77
gChoroplethTraces
82
78
. each ( function ( trace ) {
83
79
if ( trace . visible !== true ) return ;
84
80
85
- var cdi = plotChoropleth . calcGeoJSON ( trace , topojson ) ,
86
- cleanHoverLabelsFunc = makeCleanHoverLabelsFunc ( geo , trace ) ;
81
+ var cdi = plotChoropleth . calcGeoJSON ( trace , geo . topojson ) ,
82
+ cleanHoverLabelsFunc = makeCleanHoverLabelsFunc ( geo , trace ) ,
83
+ eventDataFunc = makeEventDataFunc ( trace ) ;
87
84
88
- function handleMouseOver ( d ) {
85
+ function handleMouseOver ( pt , ptIndex ) {
89
86
if ( ! geo . showHover ) return ;
90
87
91
- var xy = geo . projection ( d . properties . ct ) ;
92
- cleanHoverLabelsFunc ( d ) ;
88
+ var xy = geo . projection ( pt . properties . ct ) ;
89
+ cleanHoverLabelsFunc ( pt ) ;
93
90
94
91
Plotly . Fx . loneHover ( {
95
92
x : xy [ 0 ] ,
96
93
y : xy [ 1 ] ,
97
- name : d . nameLabel ,
98
- text : d . textLabel
94
+ name : pt . nameLabel ,
95
+ text : pt . textLabel
99
96
} , {
100
97
container : geo . hoverContainer . node ( )
101
98
} ) ;
99
+
100
+ geo . graphDiv . emit ( 'plotly_hover' , eventDataFunc ( pt , ptIndex ) ) ;
101
+ }
102
+
103
+ function handleClick ( pt , ptIndex ) {
104
+ geo . graphDiv . emit ( 'plotly_click' , eventDataFunc ( pt , ptIndex ) ) ;
102
105
}
103
106
104
107
d3 . select ( this )
@@ -107,6 +110,7 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
107
110
. enter ( ) . append ( 'path' )
108
111
. attr ( 'class' , 'choroplethlocation' )
109
112
. on ( 'mouseover' , handleMouseOver )
113
+ . on ( 'click' , handleClick )
110
114
. on ( 'mouseout' , function ( ) {
111
115
Plotly . Fx . loneUnhover ( geo . hoverContainer ) ;
112
116
} )
@@ -118,6 +122,8 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
118
122
} ) ;
119
123
120
124
// some baselayers are drawn over choropleth
125
+ gBaseLayerOverChoropleth . selectAll ( '*' ) . remove ( ) ;
126
+
121
127
for ( var i = 0 ; i < baseLayersOverChoropleth . length ; i ++ ) {
122
128
layerName = baseLayersOverChoropleth [ i ] ;
123
129
gBaseLayer . select ( 'g.' + layerName ) . remove ( ) ;
@@ -140,11 +146,11 @@ plotChoropleth.style = function(geo) {
140
146
sclFunc = makeScaleFunction ( scl , zmin , zmax ) ;
141
147
142
148
s . selectAll ( 'path.choroplethlocation' )
143
- . each ( function ( d ) {
149
+ . each ( function ( pt ) {
144
150
d3 . select ( this )
145
- . attr ( 'fill' , function ( d ) { return sclFunc ( d . z ) ; } )
146
- . call ( Color . stroke , d . mlc || markerLine . color )
147
- . call ( Drawing . dashLine , '' , d . mlw || markerLine . width ) ;
151
+ . attr ( 'fill' , function ( pt ) { return sclFunc ( pt . z ) ; } )
152
+ . call ( Color . stroke , pt . mlc || markerLine . color )
153
+ . call ( Drawing . dashLine , '' , pt . mlw || markerLine . width ) ;
148
154
} ) ;
149
155
} ) ;
150
156
} ;
@@ -153,9 +159,9 @@ function makeCleanHoverLabelsFunc(geo, trace) {
153
159
var hoverinfo = trace . hoverinfo ;
154
160
155
161
if ( hoverinfo === 'none' ) {
156
- return function cleanHoverLabelsFunc ( d ) {
157
- delete d . nameLabel ;
158
- delete d . textLabel ;
162
+ return function cleanHoverLabelsFunc ( pt ) {
163
+ delete pt . nameLabel ;
164
+ delete pt . textLabel ;
159
165
} ;
160
166
}
161
167
@@ -174,20 +180,33 @@ function makeCleanHoverLabelsFunc(geo, trace) {
174
180
return Plotly . Axes . tickText ( axis , axis . c2l ( val ) , 'hover' ) . text ;
175
181
}
176
182
177
- return function cleanHoverLabelsFunc ( d ) {
183
+ return function cleanHoverLabelsFunc ( pt ) {
178
184
// put location id in name label container
179
185
// if name isn't part of hoverinfo
180
186
var thisText = [ ] ;
181
187
182
- if ( hasIdAsNameLabel ) d . nameLabel = d . id ;
188
+ if ( hasIdAsNameLabel ) pt . nameLabel = pt . id ;
183
189
else {
184
- if ( hasName ) d . nameLabel = trace . name ;
185
- if ( hasLocation ) thisText . push ( d . id ) ;
190
+ if ( hasName ) pt . nameLabel = trace . name ;
191
+ if ( hasLocation ) thisText . push ( pt . id ) ;
186
192
}
187
193
188
- if ( hasZ ) thisText . push ( formatter ( d . z ) ) ;
189
- if ( hasText ) thisText . push ( d . tx ) ;
194
+ if ( hasZ ) thisText . push ( formatter ( pt . z ) ) ;
195
+ if ( hasText ) thisText . push ( pt . tx ) ;
196
+
197
+ pt . textLabel = thisText . join ( '<br>' ) ;
198
+ } ;
199
+ }
190
200
191
- d . textLabel = thisText . join ( '<br>' ) ;
201
+ function makeEventDataFunc ( trace ) {
202
+ return function ( pt , ptIndex ) {
203
+ return { points : [ {
204
+ data : trace . _input ,
205
+ fullData : trace ,
206
+ curveNumber : trace . index ,
207
+ pointNumber : ptIndex ,
208
+ location : pt . id ,
209
+ z : pt . z
210
+ } ] } ;
192
211
} ;
193
212
}
0 commit comments