@@ -25,7 +25,6 @@ var createGeoZoom = require('./zoom');
2525var createGeoZoomReset = require ( './zoom_reset' ) ;
2626var constants = require ( './constants' ) ;
2727
28- var xmlnsNamespaces = require ( '../../constants/xmlns_namespaces' ) ;
2928var topojsonUtils = require ( '../../lib/topojson_utils' ) ;
3029var topojsonFeature = require ( 'topojson-client' ) . feature ;
3130
@@ -39,8 +38,6 @@ function Geo(options, fullLayout) {
3938 this . container = options . container ;
4039 this . topojsonURL = options . topojsonURL ;
4140
42- this . hoverContainer = null ;
43-
4441 this . topojsonName = null ;
4542 this . topojson = null ;
4643
@@ -54,8 +51,6 @@ function Geo(options, fullLayout) {
5451 this . zoom = null ;
5552 this . zoomReset = null ;
5653
57- this . xaxis = null ;
58- this . yaxis = null ;
5954
6055 this . makeFramework ( ) ;
6156 this . updateFx ( fullLayout . hovermode ) ;
@@ -232,38 +227,30 @@ proto.makePath = function() {
232227 this . path = d3 . geo . path ( ) . projection ( this . projection ) ;
233228} ;
234229
235- /*
236- * <div this.container>
237- * <div this.geoDiv>
238- * <svg this.hoverContainer>
239- * <svg this.framework>
240- */
241230proto . 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+
259247 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 ) ;
265251
266- framework . append ( 'g' ) . attr ( 'class' , 'bglayer' )
252+ framework . append ( 'g' )
253+ . attr ( 'class' , 'bglayer' )
267254 . append ( 'rect' ) ;
268255
269256 framework . append ( 'g' ) . attr ( 'class' , 'baselayer' ) ;
@@ -274,8 +261,6 @@ proto.makeFramework = function() {
274261 // N.B. disable dblclick zoom default
275262 framework . on ( 'dblclick.zoom' , null ) ;
276263
277- // TODO use clip paths instead of nested SVG
278-
279264 this . xaxis = { _id : 'x' } ;
280265 this . yaxis = { _id : 'y' } ;
281266} ;
@@ -286,28 +271,20 @@ proto.adjustLayout = function(geoLayout, graphSize) {
286271 var left = graphSize . l + graphSize . w * domain . x [ 0 ] + geoLayout . _marginX ,
287272 top = graphSize . t + graphSize . h * ( 1 - domain . y [ 1 ] ) + geoLayout . _marginY ;
288273
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 ) ;
295275
296- this . hoverContainer . attr ( {
276+ var dimsAttrs = {
277+ x : 0 ,
278+ y : 0 ,
297279 width : geoLayout . _width ,
298280 height : geoLayout . _height
299- } ) ;
281+ } ;
300282
301- this . framework . attr ( {
302- width : geoLayout . _width ,
303- height : geoLayout . _height
304- } ) ;
283+ this . clipDef . select ( 'rect' )
284+ . attr ( dimsAttrs ) ;
305285
306286 this . framework . select ( '.bglayer' ) . select ( 'rect' )
307- . attr ( {
308- width : geoLayout . _width ,
309- height : geoLayout . _height
310- } )
287+ . attr ( dimsAttrs )
311288 . call ( Color . fill , geoLayout . bgcolor ) ;
312289
313290 this . xaxis . _offset = left ;
0 commit comments