@@ -25,7 +25,6 @@ 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
@@ -39,8 +38,6 @@ function Geo(options, fullLayout) {
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,8 +51,6 @@ 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
54
60
55
this . makeFramework ( ) ;
61
56
this . updateFx ( fullLayout . hovermode ) ;
@@ -232,38 +227,30 @@ proto.makePath = function() {
232
227
this . path = d3 . geo . path ( ) . projection ( this . projection ) ;
233
228
} ;
234
229
235
- /*
236
- * <div this.container>
237
- * <div this.geoDiv>
238
- * <svg this.hoverContainer>
239
- * <svg this.framework>
240
- */
241
230
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' ) ;
231
+ var fullLayout = this . graphDiv . _fullLayout ;
232
+ var clipId = 'clip' + fullLayout . _uid + this . id ;
233
+
234
+ var defGroup = fullLayout . _defs . selectAll ( 'g.clips' )
235
+ . data ( [ 0 ] ) ;
236
+ defGroup . enter ( ) . append ( 'g' )
237
+ . classed ( 'clips' , true ) ;
238
+
239
+ var clipDef = this . clipDef = defGroup . selectAll ( '#' + clipId )
240
+ . data ( [ 0 ] ) ;
241
+
242
+ clipDef . enter ( ) . append ( 'clipPath' ) . attr ( 'id' , clipId )
243
+ . append ( 'rect' ) ;
244
+
245
+ var framework = this . framework = d3 . select ( this . container ) . append ( 'g' ) ;
246
+
259
247
framework
260
- . attr ( xmlnsNamespaces . svgAttrs )
261
- . attr ( {
262
- 'position' : 'absolute' ,
263
- 'preserveAspectRatio' : 'none'
264
- } ) ;
248
+ . attr ( 'class' , 'geo ' + this . id )
249
+ . style ( 'pointer-events' , 'all' )
250
+ . call ( Drawing . setClipUrl , clipId ) ;
265
251
266
- framework . append ( 'g' ) . attr ( 'class' , 'bglayer' )
252
+ framework . append ( 'g' )
253
+ . attr ( 'class' , 'bglayer' )
267
254
. append ( 'rect' ) ;
268
255
269
256
framework . append ( 'g' ) . attr ( 'class' , 'baselayer' ) ;
@@ -274,8 +261,6 @@ proto.makeFramework = function() {
274
261
// N.B. disable dblclick zoom default
275
262
framework . on ( 'dblclick.zoom' , null ) ;
276
263
277
- // TODO use clip paths instead of nested SVG
278
-
279
264
this . xaxis = { _id : 'x' } ;
280
265
this . yaxis = { _id : 'y' } ;
281
266
} ;
@@ -286,28 +271,20 @@ proto.adjustLayout = function(geoLayout, graphSize) {
286
271
var left = graphSize . l + graphSize . w * domain . x [ 0 ] + geoLayout . _marginX ,
287
272
top = graphSize . t + graphSize . h * ( 1 - domain . y [ 1 ] ) + geoLayout . _marginY ;
288
273
289
- this . geoDiv . style ( {
290
- left : left + 'px' ,
291
- top : top + 'px' ,
292
- width : geoLayout . _width + 'px' ,
293
- height : geoLayout . _height + 'px'
294
- } ) ;
274
+ Drawing . setTranslate ( this . framework , left , top ) ;
295
275
296
- this . hoverContainer . attr ( {
276
+ var dimsAttrs = {
277
+ x : 0 ,
278
+ y : 0 ,
297
279
width : geoLayout . _width ,
298
280
height : geoLayout . _height
299
- } ) ;
281
+ } ;
300
282
301
- this . framework . attr ( {
302
- width : geoLayout . _width ,
303
- height : geoLayout . _height
304
- } ) ;
283
+ this . clipDef . select ( 'rect' )
284
+ . attr ( dimsAttrs ) ;
305
285
306
286
this . framework . select ( '.bglayer' ) . select ( 'rect' )
307
- . attr ( {
308
- width : geoLayout . _width ,
309
- height : geoLayout . _height
310
- } )
287
+ . attr ( dimsAttrs )
311
288
. call ( Color . fill , geoLayout . bgcolor ) ;
312
289
313
290
this . xaxis . _offset = left ;
0 commit comments