Skip to content

Subplot registration #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/annotations/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

'use strict';

var Plotly = require('../../plotly');
var ARROWPATHS = require('./arrow_paths');
var Cartesian = require('../../plots/cartesian');
var fontAttrs = require('../../plots/font_attributes');
var extendFlat = require('../../lib/extend').extendFlat;

Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = {
valType: 'enumerated',
values: [
'paper',
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString()
Cartesian.idRegex.x.toString()
],
role: 'info',
description: [
Expand Down Expand Up @@ -199,7 +199,7 @@ module.exports = {
valType: 'enumerated',
values: [
'paper',
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
Cartesian.idRegex.y.toString()
],
role: 'info',
description: [
Expand Down
2 changes: 1 addition & 1 deletion src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function handleSubplotObjs(layoutAttributes) {
var subplotRegistry = subplotsRegistry[subplotType],
isSubplotObj;

if(subplotType === 'cartesian') {
if(subplotType === 'cartesian' || subplotType === 'gl2d') {
isSubplotObj = (
subplotRegistry.attrRegex.x.test(k) ||
subplotRegistry.attrRegex.y.test(k)
Expand Down
17 changes: 4 additions & 13 deletions src/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,10 @@ exports.defaultConfig = require('./plot_api/plot_config');
// plots
var Plots = exports.Plots = require('./plots/plots');

var Cartesian = require('./plots/cartesian');
Plots.registerSubplot(Cartesian);

var Geo = require('./plots/geo');
Plots.registerSubplot(Geo);

var Gl3d = require('./plots/gl3d');
Plots.registerSubplot(Gl3d);

var Gl2d = require('./plots/gl2d');
Plots.registerSubplot(Gl2d);

exports.Axes = require('./plots/cartesian/axes');
exports.Fx = require('./plots/cartesian/graph_interact');
exports.micropolar = require('./plots/polar/micropolar');


// components
exports.Color = require('./components/color');
exports.Drawing = require('./components/drawing');
Expand Down Expand Up @@ -80,6 +67,10 @@ exports.register = function register(_modules) {
throw new Error('Invalid module was attempted to be registered!');
} else {
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);

if(!Plots.subplotsRegistry[newModule.basePlotModule.name]){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard right here, we make the check to see if the plot was registered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha. Nice!

Plots.registerSubplot(newModule.basePlotModule);
}
}
}
};
Expand Down
10 changes: 10 additions & 0 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ exports.attr = ['xaxis', 'yaxis'];
exports.idRoot = ['x', 'y'];

exports.attributes = require('./attributes');

exports.idRegex = {
x: /^x([2-9]|[1-9][0-9]+)?$/,
y: /^y([2-9]|[1-9][0-9]+)?$/
};

exports.attrRegex = {
x: /^xaxis([2-9]|[1-9][0-9]+)?$/,
y: /^yaxis([2-9]|[1-9][0-9]+)?$/
};
12 changes: 5 additions & 7 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
*/

'use strict';

var Plotly = require('../../plotly');
var Cartesian = require('./index');
var fontAttrs = require('../font_attributes');
var colorAttrs = require('../../components/color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;


module.exports = {
title: {
valType: 'string',
Expand Down Expand Up @@ -385,8 +383,8 @@ module.exports = {
valType: 'enumerated',
values: [
'free',
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString(),
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
Cartesian.idRegex.x.toString(),
Cartesian.idRegex.y.toString()
],
role: 'info',
description: [
Expand Down Expand Up @@ -414,8 +412,8 @@ module.exports = {
valType: 'enumerated',
values: [
'free',
Plotly.Plots.subplotsRegistry.cartesian.idRegex.x.toString(),
Plotly.Plots.subplotsRegistry.cartesian.idRegex.y.toString()
Cartesian.idRegex.x.toString(),
Cartesian.idRegex.y.toString()
],
role: 'info',
description: [
Expand Down
19 changes: 11 additions & 8 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

/* global PlotlyGeoAssets:false */

var Plotly = require('../../plotly');
var d3 = require('d3');

var Color = require('../../components/color');
var Drawing = require('../../components/drawing');

var Plots = require('../../plots/plots');
var Axes = require('../../plots/cartesian/axes');

var addProjectionsToD3 = require('./projections');
var createGeoScale = require('./set_scale');
Expand Down Expand Up @@ -350,7 +353,7 @@ function styleFillLayer(selection, layerName, geoLayout) {
selection.select('.' + layerName)
.selectAll('path')
.attr('stroke', 'none')
.call(Plotly.Color.fill, geoLayout[layerAdj + 'color']);
.call(Color.fill, geoLayout[layerAdj + 'color']);
}

function styleLineLayer(selection, layerName, geoLayout) {
Expand All @@ -359,16 +362,16 @@ function styleLineLayer(selection, layerName, geoLayout) {
selection.select('.' + layerName)
.selectAll('path')
.attr('fill', 'none')
.call(Plotly.Color.stroke, geoLayout[layerAdj + 'color'])
.call(Plotly.Drawing.dashLine, '', geoLayout[layerAdj + 'width']);
.call(Color.stroke, geoLayout[layerAdj + 'color'])
.call(Drawing.dashLine, '', geoLayout[layerAdj + 'width']);
}

function styleGraticule(selection, axisName, geoLayout) {
selection.select('.' + axisName + 'graticule')
.selectAll('path')
.attr('fill', 'none')
.call(Plotly.Color.stroke, geoLayout[axisName].gridcolor)
.call(Plotly.Drawing.dashLine, '', geoLayout[axisName].gridwidth);
.call(Color.stroke, geoLayout[axisName].gridcolor)
.call(Drawing.dashLine, '', geoLayout[axisName].gridwidth);
}

proto.styleLayer = function(selection, layerName, geoLayout) {
Expand Down Expand Up @@ -451,10 +454,10 @@ function createMockAxis(fullLayout) {
var mockAxis = {
type: 'linear',
showexponent: 'all',
exponentformat: Plotly.Axes.layoutAttributes.exponentformat.dflt,
exponentformat: Axes.layoutAttributes.exponentformat.dflt,
_td: { _fullLayout: fullLayout }
};

Plotly.Axes.setConvert(mockAxis);
Axes.setConvert(mockAxis);
return mockAxis;
}
8 changes: 5 additions & 3 deletions src/plots/geo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

'use strict';

var Plotly = require('../../plotly');

var Geo = require('./geo');

var Plots = Plotly.Plots;
var Plots = require('../../plots/plots');


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

exports.idRoot = 'geo';

exports.idRegex = /^geo([2-9]|[1-9][0-9]+)?$/;

exports.attrRegex = /^geo([2-9]|[1-9][0-9]+)?$/;

exports.attributes = require('./layout/attributes');

exports.layoutAttributes = require('./layout/layout_attributes');
Expand Down
6 changes: 3 additions & 3 deletions src/plots/geo/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var Plotly = require('../../../plotly');
var Lib = require('../../../lib');
var constants = require('../../../constants/geo_constants');
var axisAttributes = require('./axis_attributes');

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

function coerce(attr, dflt) {
return Plotly.Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
return Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
}

function getRangeDflt(axisName) {
Expand Down Expand Up @@ -55,7 +55,7 @@ module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut)

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

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

coerce('tick0', range[0]);
coerce('dtick', axisName==='lonaxis' ? 30 : 10);
Expand Down
7 changes: 4 additions & 3 deletions src/plots/geo/layout/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@

'use strict';

var Plotly = require('../../../plotly');
var Lib = require('../../../lib');
var Plots = require('../../plots');
var constants = require('../../../constants/geo_constants');
var layoutAttributes = require('./layout_attributes');
var supplyGeoAxisLayoutDefaults = require('./axis_defaults');


module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var geos = Plotly.Plots.getSubplotIdsInData(fullData, 'geo'),
var geos = Plots.getSubplotIdsInData(fullData, 'geo'),
geosLength = geos.length;

var geoLayoutIn, geoLayoutOut;

function coerce(attr, dflt) {
return Plotly.Lib.coerce(geoLayoutIn, geoLayoutOut, layoutAttributes, attr, dflt);
return Lib.coerce(geoLayoutIn, geoLayoutOut, layoutAttributes, attr, dflt);
}

for(var i = 0; i < geosLength; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/plots/gl2d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ exports.attr = ['xaxis', 'yaxis'];

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

exports.idRegex = {
x: /^x([2-9]|[1-9][0-9]+)?$/,
y: /^y([2-9]|[1-9][0-9]+)?$/
};

exports.attrRegex = {
x: /^xaxis([2-9]|[1-9][0-9]+)?$/,
y: /^yaxis([2-9]|[1-9][0-9]+)?$/
};

exports.attributes = require('../cartesian/attributes');

exports.plot = function plotGl2d(gd) {
Expand Down
4 changes: 4 additions & 0 deletions src/plots/gl3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ exports.attr = 'scene';

exports.idRoot = 'scene';

exports.idRegex = /^scene([2-9]|[1-9][0-9]+)?$/;

exports.attrRegex = /^scene([2-9]|[1-9][0-9]+)?$/;

exports.attributes = require('./layout/attributes');

exports.layoutAttributes = require('./layout/layout_attributes');
Expand Down
26 changes: 3 additions & 23 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ plots.fontWeight = 'normal';
*/
plots.register = function(_module, thisType, categoriesIn, meta) {
if(modules[thisType]) {
console.warn('type ' + thisType + ' already registered');
console.log('type ' + thisType + ' already registered');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bringing in @bpostlethwaite and @alexcjohnson

Should we warn (or spit out a console.log) when users register the same plot module twice?

I'd vote for doing nothing at all.

@mdtusz If I'm no mistaken, every time a user registers two or more trace modules that rely on the same plot module e.g.

var PlotlyBar = require('plotly.js/lib/bar');
var PlotlyBox = require('plotly.js/lib/box');

Plotly.register([PlotlyBar, PlotlyBox]);

would split out a log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi I switched log --> warn out of (perhaps bad) habit, from when I had a project that needed to support ie8 😦

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy. No way plotly.js works in ie8

return;
}

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

if(subplotsRegistry[plotType]) {
throw new Error('plot type' + plotType + ' already registered');
}

var attr = _module.attr,
idRoot = _module.idRoot;

var regexStart = '^',
regexEnd = '([2-9]|[1-9][0-9]+)?$',
hasXY = (plotType === 'cartesian' || subplotsRegistry === 'gl2d');

function makeRegex(mid) {
return new RegExp(regexStart + mid + regexEnd);
console.log('plot type ' + plotType + ' already registered');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops the above comment (https://github.com/plotly/plotly.js/pull/193/files#r50156440) was supposed to be placed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, but there's a check in the Plotly.register function that will avoid calling subplotsRegistry if the module has already been loaded.

return;
}

// not sure what's best for the 'cartesian' type at this point
subplotsRegistry[plotType] = _module;

// register the regex representing the set of all valid attribute names
subplotsRegistry[plotType].attrRegex = hasXY ?
{ x: makeRegex(attr[0]), y: makeRegex(attr[1]) } :
makeRegex(attr);

// register the regex representing the set of all valid attribute ids
subplotsRegistry[plotType].idRegex = hasXY ?
{ x: makeRegex(idRoot[0]), y: makeRegex(idRoot[1]) } :
makeRegex(idRoot);
};

// TODO separate the 'find subplot' step (which looks in layout)
Expand Down
1 change: 1 addition & 0 deletions src/traces/bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Bar.hoverPoints = require('./hover');

Bar.moduleType = 'trace';
Bar.name = 'bar';
Bar.basePlotModule = require('../../plots/cartesian');
Bar.categories = ['cartesian', 'bar', 'oriented', 'markerColorscale', 'errorBarsOK', 'showLegend'];
Bar.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Box.hoverPoints = require('./hover');

Box.moduleType = 'trace';
Box.name = 'box';
Box.basePlotModule = require('../../plots/cartesian');
Box.categories = ['cartesian', 'symbols', 'oriented', 'box', 'showLegend'];
Box.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/choropleth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Choropleth.plot = require('./plot').plot;

Choropleth.moduleType = 'trace';
Choropleth.name = 'choropleth';
Choropleth.basePlotModule = require('../../plots/geo');
Choropleth.categories = ['geo', 'noOpacity'];
Choropleth.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/contour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Contour.hoverPoints = require('./hover');

Contour.moduleType = 'trace';
Contour.name = 'contour';
Contour.basePlotModule = require('../../plots/cartesian');
Contour.categories = ['cartesian', '2dMap', 'contour'];
Contour.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Heatmap.hoverPoints = require('./hover');

Heatmap.moduleType = 'trace';
Heatmap.name = 'heatmap';
Heatmap.basePlotModule = require('../../plots/cartesian');
Heatmap.categories = ['cartesian', '2dMap'];
Heatmap.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/histogram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Histogram.hoverPoints = require('../bar/hover');

Histogram.moduleType = 'trace';
Histogram.name = 'histogram';
Histogram.basePlotModule = require('../../plots/cartesian');
Histogram.categories = ['cartesian', 'bar', 'histogram', 'oriented', 'errorBarsOK', 'showLegend'];
Histogram.meta = {
description: [
Expand Down
1 change: 1 addition & 0 deletions src/traces/histogram2d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Histogram2D.hoverPoints = require('../heatmap/hover');

Histogram2D.moduleType = 'trace';
Histogram2D.name = 'histogram2d';
Histogram2D.basePlotModule = require('../../plots/cartesian');
Histogram2D.categories = ['cartesian', '2dMap', 'histogram'];
Histogram2D.meta = {
hrName: 'histogram_2d',
Expand Down
1 change: 1 addition & 0 deletions src/traces/histogram2dcontour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Histogram2dContour.hoverPoints = require('../contour/hover');

Histogram2dContour.moduleType = 'trace';
Histogram2dContour.name = 'histogram2dcontour';
Histogram2dContour.basePlotModule = require('../../plots/cartesian');
Histogram2dContour.categories = ['cartesian', '2dMap', 'contour', 'histogram'];
Histogram2dContour.meta = {
hrName: 'histogram_2d_contour',
Expand Down
Loading