Skip to content

Commit 865476a

Browse files
committed
mv geo module to plots/geo :
- keep GeoLayout module (for now) - merge GeoAxes into GeoLayout
1 parent 2d40132 commit 865476a

File tree

11 files changed

+112
-115
lines changed

11 files changed

+112
-115
lines changed

src/geo/geo.js renamed to src/plots/geo/geo.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
/* global PlotlyGeoAssets:false */
44

5-
var Plotly = require('../plotly'),
6-
d3 = require('d3'),
7-
params = require('./lib/params'),
8-
addProjectionsToD3 = require('./lib/projections'),
9-
createGeoScale = require('./lib/set-scale'),
10-
createGeoZoom = require('./lib/zoom'),
11-
createGeoZoomReset = require('./lib/zoom-reset'),
12-
plotScatterGeo = require('./plot/scattergeo'),
13-
plotChoropleth = require('./plot/choropleth'),
14-
topojsonUtils = require('./lib/topojson-utils'),
15-
topojsonFeature = require('topojson').feature;
5+
var Plotly = require('../../plotly');
6+
var d3 = require('d3');
7+
8+
var addProjectionsToD3 = require('./projections');
9+
var createGeoScale = require('./set_scale');
10+
var createGeoZoom = require('./zoom');
11+
var createGeoZoomReset = require('./zoom_reset');
12+
13+
var plotScatterGeo = require('../../traces/scattergeo/plot');
14+
var plotChoropleth = require('../../traces/choropleth/plot');
15+
16+
var constants = require('../../constants/geo_constants');
17+
var topojsonUtils = require('../../lib/topojson_utils');
18+
var topojsonFeature = require('topojson').feature;
19+
1620

1721
function Geo(options, fullLayout) {
1822

@@ -129,13 +133,13 @@ proto.makeProjection = function(geoLayout) {
129133

130134
if(isNew) {
131135
this.projectionType = projType;
132-
projection = this.projection = d3.geo[params.projNames[projType]]();
136+
projection = this.projection = d3.geo[constants.projNames[projType]]();
133137
}
134138
else projection = this.projection;
135139

136140
projection
137141
.translate(projLayout._translate0)
138-
.precision(params.precision);
142+
.precision(constants.precision);
139143

140144
if(!geoLayout._isAlbersUsa) {
141145
projection
@@ -146,7 +150,7 @@ proto.makeProjection = function(geoLayout) {
146150
if(geoLayout._clipAngle) {
147151
this.clipAngle = geoLayout._clipAngle; // needed in proto.render
148152
projection
149-
.clipAngle(geoLayout._clipAngle - params.clipPad);
153+
.clipAngle(geoLayout._clipAngle - constants.clipPad);
150154
}
151155
else this.clipAngle = null; // for graph edits
152156

@@ -249,7 +253,7 @@ proto.drawTopo = function(selection, layerName, geoLayout) {
249253

250254
var topojson = this.topojson,
251255
datum = layerName==='frame' ?
252-
params.sphereSVG :
256+
constants.sphereSVG :
253257
topojsonFeature(topojson, topojson.objects[layerName]);
254258

255259
selection.append('g')
@@ -273,7 +277,7 @@ proto.drawGraticule = function(selection, axisName, geoLayout) {
273277

274278
if(axisLayout.showgrid !== true) return;
275279

276-
var scopeDefaults = params.scopeDefaults[geoLayout.scope],
280+
var scopeDefaults = constants.scopeDefaults[geoLayout.scope],
277281
lonaxisRange = scopeDefaults.lonaxisRange,
278282
lataxisRange = scopeDefaults.lataxisRange,
279283
step = axisName==='lonaxis' ?
@@ -290,8 +294,8 @@ proto.drawGraticule = function(selection, axisName, geoLayout) {
290294

291295
proto.drawLayout = function(geoLayout) {
292296
var gBaseLayer = this.framework.select('g.baselayer'),
293-
baseLayers = params.baseLayers,
294-
axesNames = params.axesNames,
297+
baseLayers = constants.baseLayers,
298+
axesNames = constants.axesNames,
295299
layerName;
296300

297301
// TODO move to more d3-idiomatic pattern (that's work on replot)
@@ -311,7 +315,7 @@ proto.drawLayout = function(geoLayout) {
311315
};
312316

313317
function styleFillLayer(selection, layerName, geoLayout) {
314-
var layerAdj = params.layerNameToAdjective[layerName];
318+
var layerAdj = constants.layerNameToAdjective[layerName];
315319

316320
selection.select('.' + layerName)
317321
.selectAll('path')
@@ -320,7 +324,7 @@ function styleFillLayer(selection, layerName, geoLayout) {
320324
}
321325

322326
function styleLineLayer(selection, layerName, geoLayout) {
323-
var layerAdj = params.layerNameToAdjective[layerName];
327+
var layerAdj = constants.layerNameToAdjective[layerName];
324328

325329
selection.select('.' + layerName)
326330
.selectAll('path')
@@ -338,8 +342,8 @@ function styleGraticule(selection, axisName, geoLayout) {
338342
}
339343

340344
proto.styleLayer = function(selection, layerName, geoLayout) {
341-
var fillLayers = params.fillLayers,
342-
lineLayers = params.lineLayers;
345+
var fillLayers = constants.fillLayers,
346+
lineLayers = constants.lineLayers;
343347

344348
if(fillLayers.indexOf(layerName)!==-1) {
345349
styleFillLayer(selection, layerName, geoLayout);
@@ -351,8 +355,8 @@ proto.styleLayer = function(selection, layerName, geoLayout) {
351355

352356
proto.styleLayout = function(geoLayout) {
353357
var gBaseLayer = this.framework.select('g.baselayer'),
354-
baseLayers = params.baseLayers,
355-
axesNames = params.axesNames,
358+
baseLayers = constants.baseLayers,
359+
axesNames = constants.axesNames,
356360
layerName;
357361

358362
for(var i = 0; i < baseLayers.length; i++) {

src/geo/attributes/geolayout.js renamed to src/plots/geo/layout/attributes.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
var Plotly = require('../../plotly'),
2-
params = require('../lib/params');
1+
var colorAttrs = require('../../../components/color/attributes');
2+
var constants = require('../../../constants/geo_constants');
3+
var geoAxesAttrs = require('./axis_attributes');
4+
35

46
module.exports = {
57
domain: {
@@ -45,15 +47,15 @@ module.exports = {
4547
scope: {
4648
valType: 'enumerated',
4749
role: 'info',
48-
values: Object.keys(params.scopeDefaults),
50+
values: Object.keys(constants.scopeDefaults),
4951
dflt: 'world',
5052
description: 'Set the scope of the map.'
5153
},
5254
projection: {
5355
type: {
5456
valType: 'enumerated',
5557
role: 'info',
56-
values: Object.keys(params.projNames),
58+
values: Object.keys(constants.projNames),
5759
description: 'Sets the projection type.'
5860
},
5961
rotation: {
@@ -112,7 +114,7 @@ module.exports = {
112114
coastlinecolor: {
113115
valType: 'color',
114116
role: 'style',
115-
dflt: Plotly.Color.defaultLine,
117+
dflt: colorAttrs.defaultLine,
116118
description: 'Sets the coastline color.'
117119
},
118120
coastlinewidth: {
@@ -131,7 +133,7 @@ module.exports = {
131133
landcolor: {
132134
valType: 'color',
133135
role: 'style',
134-
dflt: params.landColor,
136+
dflt: constants.landColor,
135137
description: 'Sets the land mass color.'
136138
},
137139
showocean: {
@@ -143,7 +145,7 @@ module.exports = {
143145
oceancolor: {
144146
valType: 'color',
145147
role: 'style',
146-
dflt: params.waterColor,
148+
dflt: constants.waterColor,
147149
description: 'Sets the ocean color'
148150
},
149151
showlakes: {
@@ -155,7 +157,7 @@ module.exports = {
155157
lakecolor: {
156158
valType: 'color',
157159
role: 'style',
158-
dflt: params.waterColor,
160+
dflt: constants.waterColor,
159161
description: 'Sets the color of the lakes.'
160162
},
161163
showrivers: {
@@ -167,7 +169,7 @@ module.exports = {
167169
rivercolor: {
168170
valType: 'color',
169171
role: 'style',
170-
dflt: params.waterColor,
172+
dflt: constants.waterColor,
171173
description: 'Sets color of the rivers.'
172174
},
173175
riverwidth: {
@@ -185,7 +187,7 @@ module.exports = {
185187
countrycolor: {
186188
valType: 'color',
187189
role: 'style',
188-
dflt: Plotly.Color.defaultLine,
190+
dflt: colorAttrs.defaultLine,
189191
description: 'Sets line color of the country boundaries.'
190192
},
191193
countrywidth: {
@@ -206,7 +208,7 @@ module.exports = {
206208
subunitcolor: {
207209
valType: 'color',
208210
role: 'style',
209-
dflt: Plotly.Color.defaultLine,
211+
dflt: colorAttrs.defaultLine,
210212
description: 'Sets the color of the subunits boundaries.'
211213
},
212214
subunitwidth: {
@@ -224,7 +226,7 @@ module.exports = {
224226
framecolor: {
225227
valType: 'color',
226228
role: 'style',
227-
dflt: Plotly.Color.defaultLine,
229+
dflt: colorAttrs.defaultLine,
228230
description: 'Sets the color the frame.'
229231
},
230232
framewidth: {
@@ -237,11 +239,9 @@ module.exports = {
237239
bgcolor: {
238240
valType: 'color',
239241
role: 'style',
240-
dflt: Plotly.Color.background,
242+
dflt: colorAttrs.background,
241243
description: 'Set the background color of the map'
242244
},
243-
_nestedModules: {
244-
'lonaxis': 'GeoAxes',
245-
'lataxis': 'GeoAxes'
246-
}
245+
lonaxis: geoAxesAttrs,
246+
lataxis: geoAxesAttrs
247247
};

src/geo/attributes/geoaxes.js renamed to src/plots/geo/layout/axis_attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Plotly = require('../../plotly');
1+
var colorAttrs = require('../../../components/color/attributes');
22

33
module.exports = {
44
range: {
@@ -33,7 +33,7 @@ module.exports = {
3333
gridcolor: {
3434
valType: 'color',
3535
role: 'style',
36-
dflt: Plotly.Color.lightLine,
36+
dflt: colorAttrs.lightLine,
3737
description: [
3838
'Sets the graticule\'s stroke color.'
3939
].join(' ')

src/geo/defaults/geoaxes.js renamed to src/plots/geo/layout/axis_defaults.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
'use strict';
22

3-
var Plotly = require('../../plotly'),
4-
params = require('../lib/params');
3+
var Plotly = require('../../../plotly');
4+
var constants = require('../../../constants/geo_constants');
5+
var axisAttributes = require('./axis_attributes');
56

6-
var GeoAxes = module.exports = {};
77

8-
GeoAxes.layoutAttributes = require('../attributes/geoaxes');
9-
10-
GeoAxes.supplyLayoutDefaults = function(geoLayoutIn, geoLayoutOut) {
11-
var axesNames = params.axesNames;
12-
13-
var axisIn, axisOut, axisName, rangeDflt, range, show;
8+
module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut) {
9+
var axesNames = constants.axesNames;
1410

1511
function coerce(attr, dflt) {
16-
return Plotly.Lib.coerce(axisIn, axisOut,
17-
GeoAxes.layoutAttributes, attr, dflt);
12+
return Plotly.Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
1813
}
1914

2015
function getRangeDflt(axisName) {
@@ -26,7 +21,7 @@ GeoAxes.supplyLayoutDefaults = function(geoLayoutIn, geoLayoutOut) {
2621
projLayout = geoLayoutOut.projection;
2722
projType = projLayout.type;
2823
projRotation = projLayout.rotation;
29-
dfltSpans = params[axisName + 'Span'];
24+
dfltSpans = constants[axisName + 'Span'];
3025

3126
halfSpan = dfltSpans[projType]!==undefined ?
3227
dfltSpans[projType] / 2 :
@@ -37,24 +32,24 @@ GeoAxes.supplyLayoutDefaults = function(geoLayoutIn, geoLayoutOut) {
3732

3833
return [rotateAngle - halfSpan, rotateAngle + halfSpan];
3934
}
40-
else return params.scopeDefaults[scope][axisName + 'Range'];
35+
else return constants.scopeDefaults[scope][axisName + 'Range'];
4136
}
4237

4338
for(var i = 0; i < axesNames.length; i++) {
44-
axisName = axesNames[i];
45-
axisIn = geoLayoutIn[axisName] || {};
46-
axisOut = {};
39+
var axisName = axesNames[i];
40+
var axisIn = geoLayoutIn[axisName] || {};
41+
var axisOut = {};
4742

48-
rangeDflt = getRangeDflt(axisName);
43+
var rangeDflt = getRangeDflt(axisName);
4944

50-
range = coerce('range', rangeDflt);
45+
var range = coerce('range', rangeDflt);
5146

5247
Plotly.Lib.noneOrAll(axisIn.range, axisOut.range, [0, 1]);
5348

5449
coerce('tick0', range[0]);
5550
coerce('dtick', axisName==='lonaxis' ? 30 : 10);
5651

57-
show = coerce('showgrid');
52+
var show = coerce('showgrid');
5853
if(show) {
5954
coerce('gridcolor');
6055
coerce('gridwidth');

0 commit comments

Comments
 (0)