Skip to content

Commit 58e86d9

Browse files
committed
Merge pull request #193 from plotly/subplot-registration
Subplot registration
2 parents 0366caa + 1007c8a commit 58e86d9

File tree

30 files changed

+90
-70
lines changed

30 files changed

+90
-70
lines changed

src/components/annotations/attributes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
'use strict';
1010

11-
var Plotly = require('../../plotly');
1211
var ARROWPATHS = require('./arrow_paths');
12+
var Cartesian = require('../../plots/cartesian');
1313
var fontAttrs = require('../../plots/font_attributes');
1414
var extendFlat = require('../../lib/extend').extendFlat;
1515

@@ -156,7 +156,7 @@ module.exports = {
156156
valType: 'enumerated',
157157
values: [
158158
'paper',
159-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString()
159+
Cartesian.idRegex.x.toString()
160160
],
161161
role: 'info',
162162
description: [
@@ -199,7 +199,7 @@ module.exports = {
199199
valType: 'enumerated',
200200
values: [
201201
'paper',
202-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
202+
Cartesian.idRegex.y.toString()
203203
],
204204
role: 'info',
205205
description: [

src/plot_api/plot_schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function handleSubplotObjs(layoutAttributes) {
286286
var subplotRegistry = subplotsRegistry[subplotType],
287287
isSubplotObj;
288288

289-
if(subplotType === 'cartesian') {
289+
if(subplotType === 'cartesian' || subplotType === 'gl2d') {
290290
isSubplotObj = (
291291
subplotRegistry.attrRegex.x.test(k) ||
292292
subplotRegistry.attrRegex.y.test(k)

src/plotly.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,10 @@ exports.defaultConfig = require('./plot_api/plot_config');
3636
// plots
3737
var Plots = exports.Plots = require('./plots/plots');
3838

39-
var Cartesian = require('./plots/cartesian');
40-
Plots.registerSubplot(Cartesian);
41-
42-
var Geo = require('./plots/geo');
43-
Plots.registerSubplot(Geo);
44-
45-
var Gl3d = require('./plots/gl3d');
46-
Plots.registerSubplot(Gl3d);
47-
48-
var Gl2d = require('./plots/gl2d');
49-
Plots.registerSubplot(Gl2d);
50-
5139
exports.Axes = require('./plots/cartesian/axes');
5240
exports.Fx = require('./plots/cartesian/graph_interact');
5341
exports.micropolar = require('./plots/polar/micropolar');
5442

55-
5643
// components
5744
exports.Color = require('./components/color');
5845
exports.Drawing = require('./components/drawing');
@@ -80,6 +67,10 @@ exports.register = function register(_modules) {
8067
throw new Error('Invalid module was attempted to be registered!');
8168
} else {
8269
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);
70+
71+
if(!Plots.subplotsRegistry[newModule.basePlotModule.name]){
72+
Plots.registerSubplot(newModule.basePlotModule);
73+
}
8374
}
8475
}
8576
};

src/plots/cartesian/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ exports.attr = ['xaxis', 'yaxis'];
1717
exports.idRoot = ['x', 'y'];
1818

1919
exports.attributes = require('./attributes');
20+
21+
exports.idRegex = {
22+
x: /^x([2-9]|[1-9][0-9]+)?$/,
23+
y: /^y([2-9]|[1-9][0-9]+)?$/
24+
};
25+
26+
exports.attrRegex = {
27+
x: /^xaxis([2-9]|[1-9][0-9]+)?$/,
28+
y: /^yaxis([2-9]|[1-9][0-9]+)?$/
29+
};

src/plots/cartesian/layout_attributes.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
*/
88

99
'use strict';
10-
11-
var Plotly = require('../../plotly');
10+
var Cartesian = require('./index');
1211
var fontAttrs = require('../font_attributes');
1312
var colorAttrs = require('../../components/color/attributes');
1413
var extendFlat = require('../../lib/extend').extendFlat;
1514

16-
1715
module.exports = {
1816
title: {
1917
valType: 'string',
@@ -385,8 +383,8 @@ module.exports = {
385383
valType: 'enumerated',
386384
values: [
387385
'free',
388-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString(),
389-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
386+
Cartesian.idRegex.x.toString(),
387+
Cartesian.idRegex.y.toString()
390388
],
391389
role: 'info',
392390
description: [
@@ -414,8 +412,8 @@ module.exports = {
414412
valType: 'enumerated',
415413
values: [
416414
'free',
417-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString(),
418-
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
415+
Cartesian.idRegex.x.toString(),
416+
Cartesian.idRegex.y.toString()
419417
],
420418
role: 'info',
421419
description: [

src/plots/geo/geo.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
/* global PlotlyGeoAssets:false */
1313

14-
var Plotly = require('../../plotly');
1514
var d3 = require('d3');
1615

16+
var Color = require('../../components/color');
17+
var Drawing = require('../../components/drawing');
18+
1719
var Plots = require('../../plots/plots');
20+
var Axes = require('../../plots/cartesian/axes');
1821

1922
var addProjectionsToD3 = require('./projections');
2023
var createGeoScale = require('./set_scale');
@@ -350,7 +353,7 @@ function styleFillLayer(selection, layerName, geoLayout) {
350353
selection.select('.' + layerName)
351354
.selectAll('path')
352355
.attr('stroke', 'none')
353-
.call(Plotly.Color.fill, geoLayout[layerAdj + 'color']);
356+
.call(Color.fill, geoLayout[layerAdj + 'color']);
354357
}
355358

356359
function styleLineLayer(selection, layerName, geoLayout) {
@@ -359,16 +362,16 @@ function styleLineLayer(selection, layerName, geoLayout) {
359362
selection.select('.' + layerName)
360363
.selectAll('path')
361364
.attr('fill', 'none')
362-
.call(Plotly.Color.stroke, geoLayout[layerAdj + 'color'])
363-
.call(Plotly.Drawing.dashLine, '', geoLayout[layerAdj + 'width']);
365+
.call(Color.stroke, geoLayout[layerAdj + 'color'])
366+
.call(Drawing.dashLine, '', geoLayout[layerAdj + 'width']);
364367
}
365368

366369
function styleGraticule(selection, axisName, geoLayout) {
367370
selection.select('.' + axisName + 'graticule')
368371
.selectAll('path')
369372
.attr('fill', 'none')
370-
.call(Plotly.Color.stroke, geoLayout[axisName].gridcolor)
371-
.call(Plotly.Drawing.dashLine, '', geoLayout[axisName].gridwidth);
373+
.call(Color.stroke, geoLayout[axisName].gridcolor)
374+
.call(Drawing.dashLine, '', geoLayout[axisName].gridwidth);
372375
}
373376

374377
proto.styleLayer = function(selection, layerName, geoLayout) {
@@ -451,10 +454,10 @@ function createMockAxis(fullLayout) {
451454
var mockAxis = {
452455
type: 'linear',
453456
showexponent: 'all',
454-
exponentformat: Plotly.Axes.layoutAttributes.exponentformat.dflt,
457+
exponentformat: Axes.layoutAttributes.exponentformat.dflt,
455458
_td: { _fullLayout: fullLayout }
456459
};
457460

458-
Plotly.Axes.setConvert(mockAxis);
461+
Axes.setConvert(mockAxis);
459462
return mockAxis;
460463
}

src/plots/geo/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
13-
1412
var Geo = require('./geo');
1513

16-
var Plots = Plotly.Plots;
14+
var Plots = require('../../plots/plots');
1715

1816

1917
exports.name = 'geo';
@@ -22,6 +20,10 @@ exports.attr = 'geo';
2220

2321
exports.idRoot = 'geo';
2422

23+
exports.idRegex = /^geo([2-9]|[1-9][0-9]+)?$/;
24+
25+
exports.attrRegex = /^geo([2-9]|[1-9][0-9]+)?$/;
26+
2527
exports.attributes = require('./layout/attributes');
2628

2729
exports.layoutAttributes = require('./layout/layout_attributes');

src/plots/geo/layout/axis_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../../plotly');
12+
var Lib = require('../../../lib');
1313
var constants = require('../../../constants/geo_constants');
1414
var axisAttributes = require('./axis_attributes');
1515

@@ -20,7 +20,7 @@ module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut)
2020
var axisIn, axisOut;
2121

2222
function coerce(attr, dflt) {
23-
return Plotly.Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
23+
return Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
2424
}
2525

2626
function getRangeDflt(axisName) {
@@ -55,7 +55,7 @@ module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut)
5555

5656
var range = coerce('range', rangeDflt);
5757

58-
Plotly.Lib.noneOrAll(axisIn.range, axisOut.range, [0, 1]);
58+
Lib.noneOrAll(axisIn.range, axisOut.range, [0, 1]);
5959

6060
coerce('tick0', range[0]);
6161
coerce('dtick', axisName==='lonaxis' ? 30 : 10);

src/plots/geo/layout/defaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../../plotly');
12+
var Lib = require('../../../lib');
13+
var Plots = require('../../plots');
1314
var constants = require('../../../constants/geo_constants');
1415
var layoutAttributes = require('./layout_attributes');
1516
var supplyGeoAxisLayoutDefaults = require('./axis_defaults');
1617

1718

1819
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
19-
var geos = Plotly.Plots.getSubplotIdsInData(fullData, 'geo'),
20+
var geos = Plots.getSubplotIdsInData(fullData, 'geo'),
2021
geosLength = geos.length;
2122

2223
var geoLayoutIn, geoLayoutOut;
2324

2425
function coerce(attr, dflt) {
25-
return Plotly.Lib.coerce(geoLayoutIn, geoLayoutOut, layoutAttributes, attr, dflt);
26+
return Lib.coerce(geoLayoutIn, geoLayoutOut, layoutAttributes, attr, dflt);
2627
}
2728

2829
for(var i = 0; i < geosLength; i++) {

src/plots/gl2d/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ exports.attr = ['xaxis', 'yaxis'];
2222

2323
exports.idRoot = ['x', 'y'];
2424

25+
exports.idRegex = {
26+
x: /^x([2-9]|[1-9][0-9]+)?$/,
27+
y: /^y([2-9]|[1-9][0-9]+)?$/
28+
};
29+
30+
exports.attrRegex = {
31+
x: /^xaxis([2-9]|[1-9][0-9]+)?$/,
32+
y: /^yaxis([2-9]|[1-9][0-9]+)?$/
33+
};
34+
2535
exports.attributes = require('../cartesian/attributes');
2636

2737
exports.plot = function plotGl2d(gd) {

0 commit comments

Comments
 (0)