@@ -25,22 +25,19 @@ 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
3231// add a few projection types to d3.geo
3332addProjectionsToD3 ( d3 ) ;
3433
3534
36- function Geo ( options , fullLayout ) {
35+ function Geo ( options ) {
3736 this . id = options . id ;
3837 this . graphDiv = options . graphDiv ;
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,11 +51,7 @@ function Geo(options, fullLayout) {
5451 this . zoom = null ;
5552 this . zoomReset = null ;
5653
57- this . xaxis = null ;
58- this . yaxis = null ;
59-
6054 this . makeFramework ( ) ;
61- this . updateFx ( fullLayout . hovermode ) ;
6255
6356 this . traceHash = { } ;
6457}
@@ -178,15 +171,6 @@ proto.onceTopojsonIsLoaded = function(geoCalcData, geoLayout) {
178171 this . render ( ) ;
179172} ;
180173
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-
190174proto . makeProjection = function ( geoLayout ) {
191175 var projLayout = geoLayout . projection ,
192176 projType = projLayout . type ,
@@ -232,38 +216,30 @@ proto.makePath = function() {
232216 this . path = d3 . geo . path ( ) . projection ( this . projection ) ;
233217} ;
234218
235- /*
236- * <div this.container>
237- * <div this.geoDiv>
238- * <svg this.hoverContainer>
239- * <svg this.framework>
240- */
241219proto . 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+
259236 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 ) ;
265240
266- framework . append ( 'g' ) . attr ( 'class' , 'bglayer' )
241+ framework . append ( 'g' )
242+ . attr ( 'class' , 'bglayer' )
267243 . append ( 'rect' ) ;
268244
269245 framework . append ( 'g' ) . attr ( 'class' , 'baselayer' ) ;
@@ -274,8 +250,6 @@ proto.makeFramework = function() {
274250 // N.B. disable dblclick zoom default
275251 framework . on ( 'dblclick.zoom' , null ) ;
276252
277- // TODO use clip paths instead of nested SVG
278-
279253 this . xaxis = { _id : 'x' } ;
280254 this . yaxis = { _id : 'y' } ;
281255} ;
@@ -286,28 +260,20 @@ proto.adjustLayout = function(geoLayout, graphSize) {
286260 var left = graphSize . l + graphSize . w * domain . x [ 0 ] + geoLayout . _marginX ,
287261 top = graphSize . t + graphSize . h * ( 1 - domain . y [ 1 ] ) + geoLayout . _marginY ;
288262
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 ) ;
295264
296- this . hoverContainer . attr ( {
265+ var dimsAttrs = {
266+ x : 0 ,
267+ y : 0 ,
297268 width : geoLayout . _width ,
298269 height : geoLayout . _height
299- } ) ;
270+ } ;
300271
301- this . framework . attr ( {
302- width : geoLayout . _width ,
303- height : geoLayout . _height
304- } ) ;
272+ this . clipDef . select ( 'rect' )
273+ . attr ( dimsAttrs ) ;
305274
306275 this . framework . select ( '.bglayer' ) . select ( 'rect' )
307- . attr ( {
308- width : geoLayout . _width ,
309- height : geoLayout . _height
310- } )
276+ . attr ( dimsAttrs )
311277 . call ( Color . fill , geoLayout . bgcolor ) ;
312278
313279 this . xaxis . _offset = left ;
0 commit comments