Skip to content

Commit b0c8448

Browse files
committed
geo: make geo trace module use calcData instead of fullData
1 parent fce36fa commit b0c8448

File tree

4 files changed

+75
-34
lines changed

4 files changed

+75
-34
lines changed

src/plots/geo/geo.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ var Color = require('../../components/color');
1717
var Drawing = require('../../components/drawing');
1818
var Axes = require('../../plots/cartesian/axes');
1919

20-
var filterVisible = require('../../lib/filter_visible');
21-
2220
var addProjectionsToD3 = require('./projections');
2321
var createGeoScale = require('./set_scale');
2422
var createGeoZoom = require('./zoom');
@@ -29,6 +27,9 @@ var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
2927
var topojsonUtils = require('../../lib/topojson_utils');
3028
var topojsonFeature = require('topojson').feature;
3129

30+
// add a few projection types to d3.geo
31+
addProjectionsToD3(d3);
32+
3233

3334
function Geo(options, fullLayout) {
3435

@@ -37,9 +38,6 @@ function Geo(options, fullLayout) {
3738
this.container = options.container;
3839
this.topojsonURL = options.topojsonURL;
3940

40-
// add a few projection types to d3.geo
41-
addProjectionsToD3(d3);
42-
4341
this.hoverContainer = null;
4442

4543
this.topojsonName = null;
@@ -65,7 +63,7 @@ module.exports = Geo;
6563

6664
var proto = Geo.prototype;
6765

68-
proto.plot = function(geoData, fullLayout, promises) {
66+
proto.plot = function(geoCalcData, fullLayout, promises) {
6967
var _this = this,
7068
geoLayout = fullLayout[_this.id],
7169
graphSize = fullLayout._size;
@@ -97,7 +95,7 @@ proto.plot = function(geoData, fullLayout, promises) {
9795

9896
if(PlotlyGeoAssets.topojson[_this.topojsonName] !== undefined) {
9997
_this.topojson = PlotlyGeoAssets.topojson[_this.topojsonName];
100-
_this.onceTopojsonIsLoaded(geoData, geoLayout);
98+
_this.onceTopojsonIsLoaded(geoCalcData, geoLayout);
10199
}
102100
else {
103101
topojsonPath = topojsonUtils.getTopojsonPath(
@@ -128,31 +126,32 @@ proto.plot = function(geoData, fullLayout, promises) {
128126
_this.topojson = topojson;
129127
PlotlyGeoAssets.topojson[_this.topojsonName] = topojson;
130128

131-
_this.onceTopojsonIsLoaded(geoData, geoLayout);
129+
_this.onceTopojsonIsLoaded(geoCalcData, geoLayout);
132130
resolve();
133131
});
134132
}));
135133
}
136134
}
137-
else _this.onceTopojsonIsLoaded(geoData, geoLayout);
135+
else _this.onceTopojsonIsLoaded(geoCalcData, geoLayout);
138136

139137
// TODO handle topojson-is-loading case
140138
// to avoid making multiple request while streaming
141139
};
142140

143-
proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
141+
proto.onceTopojsonIsLoaded = function(geoCalcData, geoLayout) {
144142
var i;
145143

146144
this.drawLayout(geoLayout);
147145

148146
var traceHashOld = this.traceHash;
149147
var traceHash = {};
150148

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;
153152

154153
traceHash[trace.type] = traceHash[trace.type] || [];
155-
traceHash[trace.type].push(trace);
154+
traceHash[trace.type].push(calcData);
156155
}
157156

158157
var moduleNamesOld = Object.keys(traceHashOld);
@@ -165,26 +164,41 @@ proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
165164
var moduleName = moduleNamesOld[i];
166165

167166
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];
171172
}
172173
}
173174

174175
moduleNames = Object.keys(traceHash);
175176

176177
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;
179180

180-
_module.plot(this, filterVisible(moduleData), geoLayout);
181+
_module.plot(this, filterVisible(moduleCalcData), geoLayout);
181182
}
182183

183184
this.traceHash = traceHash;
184185

185186
this.render();
186187
};
187188

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+
188202
proto.updateFx = function(hovermode) {
189203
this.showHover = (hovermode !== false);
190204

src/plots/geo/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports.supplyLayoutDefaults = require('./layout/defaults');
3232

3333
exports.plot = function plotGeo(gd) {
3434
var fullLayout = gd._fullLayout,
35-
fullData = gd._fullData,
35+
calcData = gd.calcdata,
3636
geoIds = Plots.getSubplotIds(fullLayout, 'geo');
3737

3838
/**
@@ -45,7 +45,7 @@ exports.plot = function plotGeo(gd) {
4545

4646
for(var i = 0; i < geoIds.length; i++) {
4747
var geoId = geoIds[i],
48-
fullGeoData = Plots.getSubplotData(fullData, 'geo', geoId),
48+
geoCalcData = getSubplotCalcData(calcData, geoId),
4949
geo = fullLayout[geoId]._geo;
5050

5151
// If geo is not instantiated, create one!
@@ -62,7 +62,7 @@ exports.plot = function plotGeo(gd) {
6262
fullLayout[geoId]._geo = geo;
6363
}
6464

65-
geo.plot(fullGeoData, fullLayout, gd._promises);
65+
geo.plot(geoCalcData, fullLayout, gd._promises);
6666
}
6767
};
6868

@@ -102,3 +102,16 @@ exports.toSVG = function(gd) {
102102
.appendChild(geoFramework.node());
103103
}
104104
};
105+
106+
function getSubplotCalcData(calcData, id) {
107+
var subplotCalcData = [];
108+
109+
for(var i = 0; i < calcData.length; i++) {
110+
var calcTrace = calcData[i],
111+
trace = calcTrace[0].trace;
112+
113+
if(trace.geo === id) subplotCalcData.push(calcTrace);
114+
}
115+
116+
return subplotCalcData;
117+
}

src/traces/choropleth/plot.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ plotChoropleth.calcGeoJSON = function(trace, topojson) {
5858
return cdi;
5959
};
6060

61-
plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
61+
plotChoropleth.plot = function(geo, calcData, geoLayout) {
62+
function keyFunc(d) {
63+
return d[0].trace.uid;
64+
}
65+
6266
var framework = geo.framework,
6367
gChoropleth = framework.select('g.choroplethlayer'),
6468
gBaseLayer = framework.select('g.baselayer'),
@@ -68,15 +72,16 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
6872

6973
var gChoroplethTraces = gChoropleth
7074
.selectAll('g.trace.choropleth')
71-
.data(choroplethData, function(trace) { return trace.uid; });
75+
.data(calcData, keyFunc);
7276

7377
gChoroplethTraces.enter().append('g')
7478
.attr('class', 'trace choropleth');
7579

7680
gChoroplethTraces.exit().remove();
7781

78-
gChoroplethTraces.each(function(trace) {
79-
var cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
82+
gChoroplethTraces.each(function(calcTrace) {
83+
var trace = calcTrace[0].trace,
84+
cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
8085
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
8186
eventDataFunc = makeEventDataFunc(trace);
8287

@@ -143,8 +148,9 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
143148

144149
plotChoropleth.style = function(geo) {
145150
geo.framework.selectAll('g.trace.choropleth')
146-
.each(function(trace) {
147-
var s = d3.select(this),
151+
.each(function(calcTrace) {
152+
var trace = calcTrace[0].trace,
153+
s = d3.select(this),
148154
marker = trace.marker || {},
149155
markerLine = marker.line || {},
150156
zmin = trace.zmin,

src/traces/scattergeo/plot.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,14 @@ function makeLineGeoJSON(trace) {
115115
};
116116
}
117117

118-
plotScatterGeo.plot = function(geo, scattergeoData) {
118+
plotScatterGeo.plot = function(geo, calcData) {
119+
function keyFunc(d) {
120+
return d[0].trace.uid;
121+
}
122+
119123
var gScatterGeoTraces = geo.framework.select('.scattergeolayer')
120124
.selectAll('g.trace.scattergeo')
121-
.data(scattergeoData, function(trace) { return trace.uid; });
125+
.data(calcData, keyFunc);
122126

123127
gScatterGeoTraces.enter().append('g')
124128
.attr('class', 'trace scattergeo');
@@ -128,8 +132,9 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
128132
// TODO find a way to order the inner nodes on update
129133
gScatterGeoTraces.selectAll('*').remove();
130134

131-
gScatterGeoTraces.each(function(trace) {
132-
var s = d3.select(this);
135+
gScatterGeoTraces.each(function(calcTrace) {
136+
var s = d3.select(this),
137+
trace = calcTrace[0].trace;
133138

134139
if(!subTypes.hasLines(trace)) return;
135140

@@ -141,8 +146,9 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
141146
// TODO add hover - how?
142147
});
143148

144-
gScatterGeoTraces.each(function(trace) {
149+
gScatterGeoTraces.each(function(calcTrace) {
145150
var s = d3.select(this),
151+
trace = calcTrace[0].trace,
146152
showMarkers = subTypes.hasMarkers(trace),
147153
showText = subTypes.hasText(trace);
148154

@@ -221,7 +227,9 @@ plotScatterGeo.style = function(geo) {
221227
return trace.opacity;
222228
});
223229

224-
selection.each(function(trace) {
230+
selection.each(function(calcTrace) {
231+
var trace = calcTrace[0].trace;
232+
225233
d3.select(this).selectAll('path.point')
226234
.call(Drawing.pointStyle, trace);
227235
d3.select(this).selectAll('text')

0 commit comments

Comments
 (0)