@@ -25,22 +25,19 @@ var createGeoZoom = require('./zoom');
25
25
var createGeoZoomReset = require ( './zoom_reset' ) ;
26
26
var constants = require ( './constants' ) ;
27
27
28
- var xmlnsNamespaces = require ( '../../constants/xmlns_namespaces' ) ;
29
28
var topojsonUtils = require ( '../../lib/topojson_utils' ) ;
30
29
var topojsonFeature = require ( 'topojson-client' ) . feature ;
31
30
32
31
// add a few projection types to d3.geo
33
32
addProjectionsToD3 ( d3 ) ;
34
33
35
34
36
- function Geo ( options , fullLayout ) {
35
+ function Geo ( options ) {
37
36
this . id = options . id ;
38
37
this . graphDiv = options . graphDiv ;
39
38
this . container = options . container ;
40
39
this . topojsonURL = options . topojsonURL ;
41
40
42
- this . hoverContainer = null ;
43
-
44
41
this . topojsonName = null ;
45
42
this . topojson = null ;
46
43
@@ -54,11 +51,7 @@ function Geo(options, fullLayout) {
54
51
this . zoom = null ;
55
52
this . zoomReset = null ;
56
53
57
- this . xaxis = null ;
58
- this . yaxis = null ;
59
-
60
54
this . makeFramework ( ) ;
61
- this . updateFx ( fullLayout . hovermode ) ;
62
55
63
56
this . traceHash = { } ;
64
57
}
@@ -178,15 +171,6 @@ proto.onceTopojsonIsLoaded = function(geoCalcData, geoLayout) {
178
171
this . render ( ) ;
179
172
} ;
180
173
181
- proto . updateFx = function ( hovermode ) {
182
- this . showHover = ( hovermode !== false ) ;
183
-
184
- // TODO should more strict, any layout.hovermode other
185
- // then false will make all geo subplot display hover text.
186
- // Instead each geo should have its own geo.hovermode
187
- // to control hover visibility independently of other subplots.
188
- } ;
189
-
190
174
proto . makeProjection = function ( geoLayout ) {
191
175
var projLayout = geoLayout . projection ,
192
176
projType = projLayout . type ,
@@ -232,38 +216,30 @@ proto.makePath = function() {
232
216
this . path = d3 . geo . path ( ) . projection ( this . projection ) ;
233
217
} ;
234
218
235
- /*
236
- * <div this.container>
237
- * <div this.geoDiv>
238
- * <svg this.hoverContainer>
239
- * <svg this.framework>
240
- */
241
219
proto . makeFramework = function ( ) {
242
- var geoDiv = this . geoDiv = d3 . select ( this . container ) . append ( 'div' ) ;
243
- geoDiv
244
- . attr ( 'id' , this . id )
245
- . style ( 'position' , 'absolute' ) ;
246
-
247
- // only choropleth traces use this,
248
- // scattergeo traces use Fx.hover and fullLayout._hoverlayer
249
- var hoverContainer = this . hoverContainer = geoDiv . append ( 'svg' ) ;
250
- hoverContainer
251
- . attr ( xmlnsNamespaces . svgAttrs )
252
- . style ( {
253
- 'position' : 'absolute' ,
254
- 'z-index' : 20 ,
255
- 'pointer-events' : 'none'
256
- } ) ;
257
-
258
- var framework = this . framework = geoDiv . append ( 'svg' ) ;
220
+ var fullLayout = this . graphDiv . _fullLayout ;
221
+ var clipId = 'clip' + fullLayout . _uid + this . id ;
222
+
223
+ var defGroup = fullLayout . _defs . selectAll ( 'g.clips' )
224
+ . data ( [ 0 ] ) ;
225
+ defGroup . enter ( ) . append ( 'g' )
226
+ . classed ( 'clips' , true ) ;
227
+
228
+ var clipDef = this . clipDef = defGroup . selectAll ( '#' + clipId )
229
+ . data ( [ 0 ] ) ;
230
+
231
+ clipDef . enter ( ) . append ( 'clipPath' ) . attr ( 'id' , clipId )
232
+ . append ( 'rect' ) ;
233
+
234
+ var framework = this . framework = d3 . select ( this . container ) . append ( 'g' ) ;
235
+
259
236
framework
260
- . attr ( xmlnsNamespaces . svgAttrs )
261
- . attr ( {
262
- 'position' : 'absolute' ,
263
- 'preserveAspectRatio' : 'none'
264
- } ) ;
237
+ . attr ( 'class' , 'geo ' + this . id )
238
+ . style ( 'pointer-events' , 'all' )
239
+ . call ( Drawing . setClipUrl , clipId ) ;
265
240
266
- framework . append ( 'g' ) . attr ( 'class' , 'bglayer' )
241
+ framework . append ( 'g' )
242
+ . attr ( 'class' , 'bglayer' )
267
243
. append ( 'rect' ) ;
268
244
269
245
framework . append ( 'g' ) . attr ( 'class' , 'baselayer' ) ;
@@ -274,8 +250,6 @@ proto.makeFramework = function() {
274
250
// N.B. disable dblclick zoom default
275
251
framework . on ( 'dblclick.zoom' , null ) ;
276
252
277
- // TODO use clip paths instead of nested SVG
278
-
279
253
this . xaxis = { _id : 'x' } ;
280
254
this . yaxis = { _id : 'y' } ;
281
255
} ;
@@ -286,28 +260,20 @@ proto.adjustLayout = function(geoLayout, graphSize) {
286
260
var left = graphSize . l + graphSize . w * domain . x [ 0 ] + geoLayout . _marginX ,
287
261
top = graphSize . t + graphSize . h * ( 1 - domain . y [ 1 ] ) + geoLayout . _marginY ;
288
262
289
- this . geoDiv . style ( {
290
- left : left + 'px' ,
291
- top : top + 'px' ,
292
- width : geoLayout . _width + 'px' ,
293
- height : geoLayout . _height + 'px'
294
- } ) ;
263
+ Drawing . setTranslate ( this . framework , left , top ) ;
295
264
296
- this . hoverContainer . attr ( {
265
+ var dimsAttrs = {
266
+ x : 0 ,
267
+ y : 0 ,
297
268
width : geoLayout . _width ,
298
269
height : geoLayout . _height
299
- } ) ;
270
+ } ;
300
271
301
- this . framework . attr ( {
302
- width : geoLayout . _width ,
303
- height : geoLayout . _height
304
- } ) ;
272
+ this . clipDef . select ( 'rect' )
273
+ . attr ( dimsAttrs ) ;
305
274
306
275
this . framework . select ( '.bglayer' ) . select ( 'rect' )
307
- . attr ( {
308
- width : geoLayout . _width ,
309
- height : geoLayout . _height
310
- } )
276
+ . attr ( dimsAttrs )
311
277
. call ( Color . fill , geoLayout . bgcolor ) ;
312
278
313
279
this . xaxis . _offset = left ;
0 commit comments