@@ -17,8 +17,6 @@ var Color = require('../../components/color');
17
17
var Drawing = require ( '../../components/drawing' ) ;
18
18
var Axes = require ( '../../plots/cartesian/axes' ) ;
19
19
20
- var filterVisible = require ( '../../lib/filter_visible' ) ;
21
-
22
20
var addProjectionsToD3 = require ( './projections' ) ;
23
21
var createGeoScale = require ( './set_scale' ) ;
24
22
var createGeoZoom = require ( './zoom' ) ;
@@ -29,6 +27,9 @@ var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
29
27
var topojsonUtils = require ( '../../lib/topojson_utils' ) ;
30
28
var topojsonFeature = require ( 'topojson' ) . feature ;
31
29
30
+ // add a few projection types to d3.geo
31
+ addProjectionsToD3 ( d3 ) ;
32
+
32
33
33
34
function Geo ( options , fullLayout ) {
34
35
@@ -37,9 +38,6 @@ function Geo(options, fullLayout) {
37
38
this . container = options . container ;
38
39
this . topojsonURL = options . topojsonURL ;
39
40
40
- // add a few projection types to d3.geo
41
- addProjectionsToD3 ( d3 ) ;
42
-
43
41
this . hoverContainer = null ;
44
42
45
43
this . topojsonName = null ;
@@ -65,7 +63,7 @@ module.exports = Geo;
65
63
66
64
var proto = Geo . prototype ;
67
65
68
- proto . plot = function ( geoData , fullLayout , promises ) {
66
+ proto . plot = function ( geoCalcData , fullLayout , promises ) {
69
67
var _this = this ,
70
68
geoLayout = fullLayout [ _this . id ] ,
71
69
graphSize = fullLayout . _size ;
@@ -97,7 +95,7 @@ proto.plot = function(geoData, fullLayout, promises) {
97
95
98
96
if ( PlotlyGeoAssets . topojson [ _this . topojsonName ] !== undefined ) {
99
97
_this . topojson = PlotlyGeoAssets . topojson [ _this . topojsonName ] ;
100
- _this . onceTopojsonIsLoaded ( geoData , geoLayout ) ;
98
+ _this . onceTopojsonIsLoaded ( geoCalcData , geoLayout ) ;
101
99
}
102
100
else {
103
101
topojsonPath = topojsonUtils . getTopojsonPath (
@@ -128,31 +126,32 @@ proto.plot = function(geoData, fullLayout, promises) {
128
126
_this . topojson = topojson ;
129
127
PlotlyGeoAssets . topojson [ _this . topojsonName ] = topojson ;
130
128
131
- _this . onceTopojsonIsLoaded ( geoData , geoLayout ) ;
129
+ _this . onceTopojsonIsLoaded ( geoCalcData , geoLayout ) ;
132
130
resolve ( ) ;
133
131
} ) ;
134
132
} ) ) ;
135
133
}
136
134
}
137
- else _this . onceTopojsonIsLoaded ( geoData , geoLayout ) ;
135
+ else _this . onceTopojsonIsLoaded ( geoCalcData , geoLayout ) ;
138
136
139
137
// TODO handle topojson-is-loading case
140
138
// to avoid making multiple request while streaming
141
139
} ;
142
140
143
- proto . onceTopojsonIsLoaded = function ( geoData , geoLayout ) {
141
+ proto . onceTopojsonIsLoaded = function ( geoCalcData , geoLayout ) {
144
142
var i ;
145
143
146
144
this . drawLayout ( geoLayout ) ;
147
145
148
146
var traceHashOld = this . traceHash ;
149
147
var traceHash = { } ;
150
148
151
- for ( i = 0 ; i < geoData . length ; i ++ ) {
152
- var trace = geoData [ i ] ;
149
+ for ( i = 0 ; i < geoCalcData . length ; i ++ ) {
150
+ var calcData = geoCalcData [ i ] ,
151
+ trace = calcData [ 0 ] . trace ;
153
152
154
153
traceHash [ trace . type ] = traceHash [ trace . type ] || [ ] ;
155
- traceHash [ trace . type ] . push ( trace ) ;
154
+ traceHash [ trace . type ] . push ( calcData ) ;
156
155
}
157
156
158
157
var moduleNamesOld = Object . keys ( traceHashOld ) ;
@@ -165,26 +164,41 @@ proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
165
164
var moduleName = moduleNamesOld [ i ] ;
166
165
167
166
if ( moduleNames . indexOf ( moduleName ) === - 1 ) {
168
- var fakeModule = traceHashOld [ moduleName ] [ 0 ] ;
169
- fakeModule . visible = false ;
170
- traceHash [ moduleName ] = [ fakeModule ] ;
167
+ var fakeCalcTrace = traceHashOld [ moduleName ] [ 0 ] ,
168
+ fakeTrace = fakeCalcTrace [ 0 ] . trace ;
169
+
170
+ fakeTrace . visible = false ;
171
+ traceHash [ moduleName ] = [ fakeCalcTrace ] ;
171
172
}
172
173
}
173
174
174
175
moduleNames = Object . keys ( traceHash ) ;
175
176
176
177
for ( i = 0 ; i < moduleNames . length ; i ++ ) {
177
- var moduleData = traceHash [ moduleNames [ i ] ] ;
178
- var _module = moduleData [ 0 ] . _module ;
178
+ var moduleCalcData = traceHash [ moduleNames [ i ] ] ,
179
+ _module = moduleCalcData [ 0 ] [ 0 ] . trace . _module ;
179
180
180
- _module . plot ( this , filterVisible ( moduleData ) , geoLayout ) ;
181
+ _module . plot ( this , filterVisible ( moduleCalcData ) , geoLayout ) ;
181
182
}
182
183
183
184
this . traceHash = traceHash ;
184
185
185
186
this . render ( ) ;
186
187
} ;
187
188
189
+ function filterVisible ( calcDataIn ) {
190
+ var calcDataOut = [ ] ;
191
+
192
+ for ( var i = 0 ; i < calcDataIn . length ; i ++ ) {
193
+ var calcTrace = calcDataIn [ i ] ,
194
+ trace = calcTrace [ 0 ] . trace ;
195
+
196
+ if ( trace . visible === true ) calcDataOut . push ( calcTrace ) ;
197
+ }
198
+
199
+ return calcDataOut ;
200
+ }
201
+
188
202
proto . updateFx = function ( hovermode ) {
189
203
this . showHover = ( hovermode !== false ) ;
190
204
0 commit comments