Skip to content

Commit d5e894d

Browse files
committed
add geo plot index + register it in plotly.js + rm GeoLayout module
1 parent 8126914 commit d5e894d

File tree

5 files changed

+83
-37
lines changed

5 files changed

+83
-37
lines changed

src/plotly.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ var Cartesian = require('./plots/cartesian');
3939
Plots.registerSubplot(Cartesian);
4040
exports.Axes = require('./plots/cartesian/axes');
4141
exports.Fx = require('./plots/cartesian/graph_interact');
42+
43+
var Geo = require('./plots/geo');
44+
Plots.registerSubplot(Geo);
4245
exports.Scene = require('./plots/gl3d/scene');
4346
exports.Gl3dLayout = require('./plots/gl3d/layout');
44-
exports.Geo = require('./plots/geo/geo');
45-
exports.GeoLayout = require('./plots/geo/layout');
4647
exports.Scene2D = require('./plots/gl2d/scene2d');
4748
exports.micropolar = require('./plots/polar/micropolar');
4849

src/plots/geo/index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
var Plotly = require('../../plotly');
13+
14+
var Geo = require('./geo');
15+
16+
var Plots = Plotly.Plots;
17+
18+
19+
exports.type = 'geo';
20+
21+
exports.attr = 'geo';
22+
23+
exports.idRoot = 'geo';
24+
25+
exports.attributes = require('./layout/attributes');
26+
27+
exports.layoutAttributes = require('./layout/layout_attributes');
28+
29+
exports.supplyLayoutDefaults = require('./layout/defaults');
30+
31+
exports.plot = function plotGeo(gd) {
32+
var fullLayout = gd._fullLayout,
33+
fullData = gd._fullData,
34+
geoIds = Plots.getSubplotIds(fullLayout, 'geo');
35+
36+
/**
37+
* If 'plotly-geo-assets.js' is not included,
38+
* initialize object to keep reference to every loaded topojson
39+
*/
40+
if(window.PlotlyGeoAssets === undefined) {
41+
window.PlotlyGeoAssets = { topojson : {} };
42+
}
43+
44+
for(var i = 0; i < geoIds.length; i++) {
45+
var geoId = geoIds[i],
46+
fullGeoData = Plots.getSubplotData(fullData, 'geo', geoId),
47+
geo = fullLayout[geoId]._geo;
48+
49+
// If geo is not instantiated, create one!
50+
if(geo === undefined) {
51+
geo = new Geo({
52+
id: geoId,
53+
container: fullLayout._geocontainer.node(),
54+
topojsonURL: gd._context.topojsonURL
55+
}, fullLayout);
56+
57+
fullLayout[geoId]._geo = geo;
58+
}
59+
60+
geo.plot(fullGeoData, fullLayout, gd._promises);
61+
}
62+
};

src/plots/geo/layout/index.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/plots/layout_attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ module.exports = {
196196
'xaxis': 'Axes',
197197
'yaxis': 'Axes',
198198
'scene': 'Gl3dLayout',
199-
'geo': 'GeoLayout',
199+
'geo': 'geo',
200200
'legend': 'Legend',
201201
'annotations': 'Annotations',
202202
'shapes': 'Shapes'

test/jasmine/tests/geolayout_test.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
var Plotly = require('@src/plotly');
1+
var Geo = require('@src/plots/geo');
22

3-
describe('Test geolayout', function () {
3+
describe('Test Geo layout defaults', function () {
44
'use strict';
55

6-
var GeoLayout = Plotly.GeoLayout;
6+
var layoutAttributes = Geo.layoutAttributes;
7+
var supplyLayoutDefaults = Geo.supplyLayoutDefaults;
78

89
describe('supplyLayoutDefaults', function() {
910
var layoutIn, layoutOut;
@@ -30,12 +31,12 @@ describe('Test geolayout', function () {
3031
}
3132
};
3233

33-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
34+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
3435
expect(layoutOut.geo.projection.rotation).toBeUndefined();
3536

3637
delete layoutIn.geo.projection.type;
3738
layoutOut = {};
38-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
39+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
3940
expect(layoutOut.geo.projection.rotation).toBeDefined();
4041
});
4142

@@ -55,21 +56,21 @@ describe('Test geolayout', function () {
5556
}
5657
};
5758

58-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
59+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
5960
fields.forEach(function(field) {
6061
expect(layoutOut.geo[field]).toBeUndefined();
6162
});
6263

6364
delete layoutIn.geo.projection.type;
6465
layoutOut = {};
65-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
66+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
6667
fields.forEach(function(field) {
6768
expect(layoutOut.geo[field]).toBeDefined();
6869
});
6970
});
7071

7172
it('should not coerce projection.parallels if type is conic', function() {
72-
var projTypes = GeoLayout.layoutAttributes.projection.type.values;
73+
var projTypes = layoutAttributes.projection.type.values;
7374

7475
function testOne(projType) {
7576
layoutIn = {
@@ -81,7 +82,7 @@ describe('Test geolayout', function () {
8182
}
8283
};
8384
layoutOut = {};
84-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
85+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
8586
}
8687

8788
projTypes.forEach(function(projType) {
@@ -103,14 +104,14 @@ describe('Test geolayout', function () {
103104
geo: { scope: 'usa' }
104105
};
105106
layoutOut = {};
106-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
107+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
107108
fields.forEach(function(field) {
108109
expect(layoutOut.geo[field]).toBeDefined();
109110
});
110111

111112
delete layoutIn.geo.scope;
112113
layoutOut = {};
113-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
114+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
114115
fields.forEach(function(field) {
115116
expect(layoutOut.geo[field]).toBeUndefined();
116117
});
@@ -122,7 +123,7 @@ describe('Test geolayout', function () {
122123
}
123124
};
124125
layoutOut = {};
125-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
126+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
126127
fields.forEach(function(field) {
127128
expect(layoutOut.geo[field]).toBeDefined();
128129
});
@@ -134,14 +135,14 @@ describe('Test geolayout', function () {
134135
}
135136
};
136137
layoutOut = {};
137-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
138+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
138139
fields.forEach(function(field) {
139140
expect(layoutOut.geo[field]).toBeDefined();
140141
});
141142

142143
delete layoutIn.geo.resolution;
143144
layoutOut = {};
144-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
145+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
145146
fields.forEach(function(field) {
146147
expect(layoutOut.geo[field]).toBeUndefined();
147148
});
@@ -151,14 +152,14 @@ describe('Test geolayout', function () {
151152
var fields = [
152153
'showframe', 'framecolor', 'framewidth'
153154
],
154-
scopes = GeoLayout.layoutAttributes.scope.values;
155+
scopes = layoutAttributes.scope.values;
155156

156157
function testOne(scope) {
157158
layoutIn = {
158159
geo: { scope: scope }
159160
};
160161
layoutOut = {};
161-
GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
162+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
162163
}
163164

164165
scopes.forEach(function(scope) {

0 commit comments

Comments
 (0)