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

+3-3
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

+1-1
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

+4-13
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

+10
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

+5-7
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

+11-8
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

+5-3
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

+3-3
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

+4-3
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

+10
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) {

src/plots/gl3d/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ exports.attr = 'scene';
2121

2222
exports.idRoot = 'scene';
2323

24+
exports.idRegex = /^scene([2-9]|[1-9][0-9]+)?$/;
25+
26+
exports.attrRegex = /^scene([2-9]|[1-9][0-9]+)?$/;
27+
2428
exports.attributes = require('./layout/attributes');
2529

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

src/plots/plots.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ plots.fontWeight = 'normal';
4141
*/
4242
plots.register = function(_module, thisType, categoriesIn, meta) {
4343
if(modules[thisType]) {
44-
console.warn('type ' + thisType + ' already registered');
44+
console.log('type ' + thisType + ' already registered');
4545
return;
4646
}
4747

@@ -132,32 +132,12 @@ plots.registerSubplot = function(_module) {
132132
var plotType = _module.name;
133133

134134
if(subplotsRegistry[plotType]) {
135-
throw new Error('plot type' + plotType + ' already registered');
136-
}
137-
138-
var attr = _module.attr,
139-
idRoot = _module.idRoot;
140-
141-
var regexStart = '^',
142-
regexEnd = '([2-9]|[1-9][0-9]+)?$',
143-
hasXY = (plotType === 'cartesian' || subplotsRegistry === 'gl2d');
144-
145-
function makeRegex(mid) {
146-
return new RegExp(regexStart + mid + regexEnd);
135+
console.log('plot type ' + plotType + ' already registered');
136+
return;
147137
}
148138

149139
// not sure what's best for the 'cartesian' type at this point
150140
subplotsRegistry[plotType] = _module;
151-
152-
// register the regex representing the set of all valid attribute names
153-
subplotsRegistry[plotType].attrRegex = hasXY ?
154-
{ x: makeRegex(attr[0]), y: makeRegex(attr[1]) } :
155-
makeRegex(attr);
156-
157-
// register the regex representing the set of all valid attribute ids
158-
subplotsRegistry[plotType].idRegex = hasXY ?
159-
{ x: makeRegex(idRoot[0]), y: makeRegex(idRoot[1]) } :
160-
makeRegex(idRoot);
161141
};
162142

163143
// TODO separate the 'find subplot' step (which looks in layout)

src/traces/bar/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bar.hoverPoints = require('./hover');
2525

2626
Bar.moduleType = 'trace';
2727
Bar.name = 'bar';
28+
Bar.basePlotModule = require('../../plots/cartesian');
2829
Bar.categories = ['cartesian', 'bar', 'oriented', 'markerColorscale', 'errorBarsOK', 'showLegend'];
2930
Bar.meta = {
3031
description: [

src/traces/box/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Box.hoverPoints = require('./hover');
2222

2323
Box.moduleType = 'trace';
2424
Box.name = 'box';
25+
Box.basePlotModule = require('../../plots/cartesian');
2526
Box.categories = ['cartesian', 'symbols', 'oriented', 'box', 'showLegend'];
2627
Box.meta = {
2728
description: [

src/traces/choropleth/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Choropleth.plot = require('./plot').plot;
1919

2020
Choropleth.moduleType = 'trace';
2121
Choropleth.name = 'choropleth';
22+
Choropleth.basePlotModule = require('../../plots/geo');
2223
Choropleth.categories = ['geo', 'noOpacity'];
2324
Choropleth.meta = {
2425
description: [

src/traces/contour/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Contour.hoverPoints = require('./hover');
2121

2222
Contour.moduleType = 'trace';
2323
Contour.name = 'contour';
24+
Contour.basePlotModule = require('../../plots/cartesian');
2425
Contour.categories = ['cartesian', '2dMap', 'contour'];
2526
Contour.meta = {
2627
description: [

src/traces/heatmap/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Heatmap.hoverPoints = require('./hover');
2121

2222
Heatmap.moduleType = 'trace';
2323
Heatmap.name = 'heatmap';
24+
Heatmap.basePlotModule = require('../../plots/cartesian');
2425
Heatmap.categories = ['cartesian', '2dMap'];
2526
Heatmap.meta = {
2627
description: [

src/traces/histogram/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Histogram.hoverPoints = require('../bar/hover');
3838

3939
Histogram.moduleType = 'trace';
4040
Histogram.name = 'histogram';
41+
Histogram.basePlotModule = require('../../plots/cartesian');
4142
Histogram.categories = ['cartesian', 'bar', 'histogram', 'oriented', 'errorBarsOK', 'showLegend'];
4243
Histogram.meta = {
4344
description: [

src/traces/histogram2d/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Histogram2D.hoverPoints = require('../heatmap/hover');
2121

2222
Histogram2D.moduleType = 'trace';
2323
Histogram2D.name = 'histogram2d';
24+
Histogram2D.basePlotModule = require('../../plots/cartesian');
2425
Histogram2D.categories = ['cartesian', '2dMap', 'histogram'];
2526
Histogram2D.meta = {
2627
hrName: 'histogram_2d',

src/traces/histogram2dcontour/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Histogram2dContour.hoverPoints = require('../contour/hover');
2121

2222
Histogram2dContour.moduleType = 'trace';
2323
Histogram2dContour.name = 'histogram2dcontour';
24+
Histogram2dContour.basePlotModule = require('../../plots/cartesian');
2425
Histogram2dContour.categories = ['cartesian', '2dMap', 'contour', 'histogram'];
2526
Histogram2dContour.meta = {
2627
hrName: 'histogram_2d_contour',

0 commit comments

Comments
 (0)