Skip to content
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

Add registry of component modules #845

Merged
merged 18 commits into from
Aug 19, 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
3 changes: 3 additions & 0 deletions src/components/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

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

exports.moduleType = 'component';

exports.name = 'annotations';

exports.ARROWPATHS = require('./arrow_paths');

Expand Down
3 changes: 2 additions & 1 deletion src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var tinycolor = require('tinycolor2');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var dragElement = require('../dragelement');
var Lib = require('../../lib');
Expand Down Expand Up @@ -437,7 +438,7 @@ module.exports = function draw(gd, id) {
function drawTitle(titleClass, titleOpts) {
var trace = getTrace(),
propName;
if(Plots.traceIs(trace, 'markerColorscale')) {
if(Registry.traceIs(trace, 'markerColorscale')) {
propName = 'marker.colorbar.title';
}
else propName = 'colorbar.title';
Expand Down
4 changes: 2 additions & 2 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Color = require('../color');
var Colorscale = require('../colorscale');
var Lib = require('../../lib');
Expand Down Expand Up @@ -183,7 +183,7 @@ drawing.pointStyle = function(s, trace) {

// only scatter & box plots get marker path and opacity
// bars, histograms don't
if(Plots.traceIs(trace, 'symbols')) {
if(Registry.traceIs(trace, 'symbols')) {
var sizeFn = makeBubbleSizeFn(trace);

s.attr('d', function(d) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/errorbars/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

var isNumeric = require('fast-isnumeric');

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

var makeComputeError = require('./compute_error');
Expand All @@ -24,7 +24,7 @@ module.exports = function calc(gd) {
var calcTrace = calcdata[i],
trace = calcTrace[0].trace;

if(!Plots.traceIs(trace, 'errorBarsOK')) continue;
if(!Registry.traceIs(trace, 'errorBarsOK')) continue;

var xa = Axes.getFromId(gd, trace.xaxis),
ya = Axes.getFromId(gd, trace.yaxis);
Expand Down
4 changes: 2 additions & 2 deletions src/components/errorbars/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

var isNumeric = require('fast-isnumeric');

var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Lib = require('../../lib');

var attributes = require('./attributes');
Expand Down Expand Up @@ -70,6 +70,6 @@ module.exports = function(traceIn, traceOut, defaultColor, opts) {
if(!opts.inherit || !containerOut[copyAttr]) {
coerce('color', defaultColor);
coerce('thickness');
coerce('width', Plots.traceIs(traceOut, 'gl3d') ? 0 : 4);
coerce('width', Registry.traceIs(traceOut, 'gl3d') ? 0 : 4);
}
};
2 changes: 2 additions & 0 deletions src/components/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var attributes = require('./attributes');


module.exports = {
moduleType: 'component',
name: 'images',
draw: draw,
layoutAttributes: attributes,
supplyLayoutDefaults: supplyLayoutDefaults
Expand Down
9 changes: 5 additions & 4 deletions src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

'use strict';

var Registry = require('../../registry');
var Lib = require('../../lib');
var Plots = require('../../plots/plots');

var attributes = require('./attributes');
var basePlotLayoutAttributes = require('../../plots/layout_attributes');
var helpers = require('./helpers');


Expand All @@ -33,10 +34,10 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
if(helpers.legendGetsTrace(trace)) {
visibleTraces++;
// always show the legend by default if there's a pie
if(Plots.traceIs(trace, 'pie')) visibleTraces++;
if(Registry.traceIs(trace, 'pie')) visibleTraces++;
}

if((Plots.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') ||
if((Registry.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') ||
['tonextx', 'tonexty'].indexOf(trace.fill) !== -1) {
defaultOrder = helpers.isGrouped({traceorder: defaultOrder}) ?
'grouped+reversed' : 'reversed';
Expand All @@ -53,7 +54,7 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
}

var showLegend = Lib.coerce(layoutIn, layoutOut,
Plots.layoutAttributes, 'showlegend', visibleTraces > 1);
basePlotLayoutAttributes, 'showlegend', visibleTraces > 1);

if(showLegend === false) return;

Expand Down
7 changes: 4 additions & 3 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var d3 = require('d3');
var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var dragElement = require('../dragelement');
var Drawing = require('../drawing');
var Color = require('../color');
Expand Down Expand Up @@ -108,7 +109,7 @@ module.exports = function draw(gd) {
traces.call(style)
.style('opacity', function(d) {
var trace = d[0].trace;
if(Plots.traceIs(trace, 'pie')) {
if(Registry.traceIs(trace, 'pie')) {
return hiddenSlices.indexOf(d[0].label) !== -1 ? 0.5 : 1;
} else {
return trace.visible === 'legendonly' ? 0.5 : 1;
Expand Down Expand Up @@ -337,7 +338,7 @@ function drawTexts(g, gd) {
var legendItem = g.data()[0][0],
fullLayout = gd._fullLayout,
trace = legendItem.trace,
isPie = Plots.traceIs(trace, 'pie'),
isPie = Registry.traceIs(trace, 'pie'),
traceIndex = trace.index,
name = isPie ? legendItem.label : trace.name;

Expand Down Expand Up @@ -400,7 +401,7 @@ function setupTraceToggle(g, gd) {
tracei,
newVisible;

if(Plots.traceIs(trace, 'pie')) {
if(Registry.traceIs(trace, 'pie')) {
var thisLabel = legendItem.label,
thisLabelIndex = hiddenSlices.indexOf(thisLabel);

Expand Down
5 changes: 2 additions & 3 deletions src/components/legend/get_legend_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

'use strict';

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

var Registry = require('../../registry');
var helpers = require('./helpers');


Expand Down Expand Up @@ -49,7 +48,7 @@ module.exports = function getLegendData(calcdata, opts) {

if(!helpers.legendGetsTrace(trace) || !trace.showlegend) continue;

if(Plots.traceIs(trace, 'pie')) {
if(Registry.traceIs(trace, 'pie')) {
if(!slicesShown[lgroup]) slicesShown[lgroup] = {};

for(j = 0; j < cd.length; j++) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/legend/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

'use strict';

var Plots = require('../../plots/plots');
var Registry = require('../../registry');


exports.legendGetsTrace = function legendGetsTrace(trace) {
return trace.visible && Plots.traceIs(trace, 'showLegend');
return trace.visible && Registry.traceIs(trace, 'showLegend');
};

exports.isGrouped = function isGrouped(legendLayout) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/legend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

var legend = module.exports = {};


legend.moduleType = 'component';

legend.name = 'legend';

legend.layoutAttributes = require('./attributes');

legend.supplyLayoutDefaults = require('./defaults');
Expand Down
8 changes: 4 additions & 4 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

var d3 = require('d3');

var Registry = require('../../registry');
var Lib = require('../../lib');
var Plots = require('../../plots/plots');
var Drawing = require('../drawing');
var Color = require('../color');

Expand Down Expand Up @@ -165,7 +165,7 @@ function styleBars(d) {
markerLine = marker.line || {},
barpath = d3.select(this).select('g.legendpoints')
.selectAll('path.legendbar')
.data(Plots.traceIs(trace, 'bar') ? [d] : []);
.data(Registry.traceIs(trace, 'bar') ? [d] : []);
barpath.enter().append('path').classed('legendbar', true)
.attr('d', 'M6,6H-6V-6H6Z')
.attr('transform', 'translate(20,0)');
Expand All @@ -187,7 +187,7 @@ function styleBoxes(d) {
var trace = d[0].trace,
pts = d3.select(this).select('g.legendpoints')
.selectAll('path.legendbox')
.data(Plots.traceIs(trace, 'box') && trace.visible ? [d] : []);
.data(Registry.traceIs(trace, 'box') && trace.visible ? [d] : []);
pts.enter().append('path').classed('legendbox', true)
// if we want the median bar, prepend M6,0H-6
.attr('d', 'M6,6H-6V-6H6Z')
Expand All @@ -210,7 +210,7 @@ function stylePies(d) {
var trace = d[0].trace,
pts = d3.select(this).select('g.legendpoints')
.selectAll('path.legendpie')
.data(Plots.traceIs(trace, 'pie') && trace.visible ? [d] : []);
.data(Registry.traceIs(trace, 'pie') && trace.visible ? [d] : []);
pts.enter().append('path').classed('legendpie', true)
.attr('d', 'M6,6H-6V-6H6Z')
.attr('transform', 'translate(20,0)');
Expand Down
2 changes: 1 addition & 1 deletion src/components/rangeselector/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var buttonAttrs = require('./button_attributes');
var constants = require('./constants');


module.exports = function rangeSelectorDefaults(containerIn, containerOut, layout, counterAxes) {
module.exports = function handleDefaults(containerIn, containerOut, layout, counterAxes) {
var selectorIn = containerIn.rangeselector || {},
selectorOut = containerOut.rangeselector = {};

Expand Down
8 changes: 6 additions & 2 deletions src/components/rangeselector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
'use strict';


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

exports.supplyLayoutDefaults = require('./defaults');
exports.name = 'rangeselector';

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

exports.handleDefaults = require('./defaults');

exports.draw = require('./draw');
2 changes: 1 addition & 1 deletion src/components/rangeslider/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Lib = require('../../lib');
var attributes = require('./attributes');


module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, axName, counterAxes) {
module.exports = function handleDefaults(layoutIn, layoutOut, axName, counterAxes) {
if(!layoutIn[axName].rangeslider) return;

var containerIn = Lib.isPlainObject(layoutIn[axName].rangeslider) ?
Expand Down
10 changes: 7 additions & 3 deletions src/components/rangeslider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
var Plots = require('../../plots/plots');

var createSlider = require('./create_slider');
var supplyLayoutDefaults = require('./defaults');
var layoutAttributes = require('./attributes');
var handleDefaults = require('./defaults');


module.exports = {
draw: draw,
supplyLayoutDefaults: supplyLayoutDefaults
moduleType: 'component',
name: 'rangeslider',
layoutAttributes: layoutAttributes,
handleDefaults: handleDefaults,
draw: draw
};

function draw(gd) {
Expand Down
3 changes: 3 additions & 0 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

'use strict';

exports.moduleType = 'component';

exports.name = 'shapes';

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

Expand Down
4 changes: 4 additions & 0 deletions src/components/updatemenus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
'use strict';


exports.moduleType = 'component';

exports.name = 'updatemenus';

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

exports.supplyLayoutDefaults = require('./defaults');
Expand Down
31 changes: 27 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ var Plotly = require('./plotly');
// package version injected by `npm run preprocess`
exports.version = '1.16.2';

// inject promise polyfill
require('es6-promise').polyfill();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be gone in v2 #420 (comment)


// inject plot css
require('../build/plotcss');

// inject default MathJax config
require('./fonts/mathjax_config');

// plot api
exports.plot = Plotly.plot;
exports.newPlot = Plotly.newPlot;
Expand All @@ -30,20 +39,34 @@ exports.deleteTraces = Plotly.deleteTraces;
exports.moveTraces = Plotly.moveTraces;
exports.purge = Plotly.purge;
exports.setPlotConfig = require('./plot_api/set_plot_config');
exports.register = Plotly.register;
exports.register = require('./plot_api/register');
exports.toImage = require('./plot_api/to_image');
exports.downloadImage = require('./snapshot/download');
exports.validate = require('./plot_api/validate');

// scatter is the only trace included by default
exports.register(require('./traces/scatter'));

// register all registrable components modules
exports.register([
require('./components/legend'),
require('./components/annotations'),
require('./components/shapes'),
require('./components/images'),
require('./components/updatemenus'),
require('./components/rangeslider'),
require('./components/rangeselector')
]);

// plot icons
exports.Icons = require('../build/ploticon');

// unofficial 'beta' plot methods, use at your own risk
exports.Plots = Plotly.Plots;
exports.Fx = Plotly.Fx;
exports.Snapshot = Plotly.Snapshot;
exports.PlotSchema = Plotly.PlotSchema;
exports.Queue = Plotly.Queue;
exports.Snapshot = require('./snapshot');
exports.PlotSchema = require('./plot_api/plot_schema');
exports.Queue = require('./lib/queue');

// export d3 used in the bundle
exports.d3 = require('d3');
3 changes: 3 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ lib.bBoxIntersect = function(a, b, pad) {
// minor convenience/performance booster for d3...
lib.identity = function(d) { return d; };

// minor convenience helper
lib.noop = function() {};

// random string generator
lib.randstr = function randstr(existing, bits, base) {
/*
Expand Down
Loading