Skip to content

Commit 970abc2

Browse files
committed
Update plots to work as standalone modules
1 parent ba8cbab commit 970abc2

File tree

9 files changed

+55
-47
lines changed

9 files changed

+55
-47
lines changed

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: /^x([2-9]|[1-9][0-9]+)?$/,
28+
y: /^y([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' || plotType === '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)

0 commit comments

Comments
 (0)