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

Revise scatter register to allow custom partial bundles without scatter included by default #5535

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/index-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Plotly = require('./core');

Plotly.register([
// traces
require('./scatter'),
require('./bar'),
require('./pie'),

Expand Down
1 change: 1 addition & 0 deletions lib/index-cartesian.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Plotly = require('./core');

Plotly.register([
// traces
require('./scatter'),
require('./bar'),
require('./box'),
require('./heatmap'),
Expand Down
1 change: 1 addition & 0 deletions lib/index-strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Plotly = require('./core');

Plotly.register([
// traces
require('./scatter'),
require('./bar'),
require('./box'),
require('./heatmap'),
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Plotly = require('./core');

Plotly.register([
// traces
require('./scatter'),
require('./bar'),
require('./box'),
require('./heatmap'),
Expand Down
3 changes: 0 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ for(var i = 0; i < methodNames.length; i++) {
});
}

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

// register all registrable components modules
register([
require('./components/legend'),
Expand Down
8 changes: 7 additions & 1 deletion src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ exports.getTraceValObject = function(trace, parts) {
// first look in the module for this trace
// components have already merged their trace attributes in here
var _module = trace._module;
if(!_module) _module = (Registry.modules[trace.type || baseAttributes.type.dflt] || {})._module;
if(!_module) _module = (Registry.modules[trace.type] || {})._module;
if(!_module) {
var scatter = Registry.modules[baseAttributes.type.dflt];
if(scatter) {
_module = scatter._module;
}
}
if(!_module) return false;

moduleAttrs = _module.attributes;
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function expandRange(range) {
*/
axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption) {
var axLetter = attr.charAt(attr.length - 1);
var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
var axlist = gd._fullLayout._subplots[axLetter + 'axis'] || [];
var refAttr = attr + 'ref';
var attrDef = {};

Expand Down
6 changes: 3 additions & 3 deletions src/plots/cartesian/axis_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ exports.listIds = function(gd, axLetter) {
var fullLayout = gd._fullLayout;
if(!fullLayout) return [];

var subplotLists = fullLayout._subplots;
if(axLetter) return subplotLists[axLetter + 'axis'];
return subplotLists.xaxis.concat(subplotLists.yaxis);
var subplotLists = fullLayout._subplots || {};
if(axLetter) return subplotLists[axLetter + 'axis'] || [];
return (subplotLists.xaxis || []).concat(subplotLists.yaxis || []);
};

// get an axis object from its id 'x','x2' etc
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/include_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var Registry = require('../../registry');
var Lib = require('../../lib');
var axisIds = require('./axis_ids');
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;

/**
* Factory function for checking component arrays for subplot references.
Expand All @@ -21,7 +22,7 @@ module.exports = function makeIncludeComponents(containerArrayName) {
if(!Array.isArray(array)) return;

var Cartesian = Registry.subplotsRegistry.cartesian;
var idRegex = Cartesian.idRegex;
var idRegex = cartesianIdRegex;
var subplots = layoutOut._subplots;
var xaList = subplots.xaxis;
var yaList = subplots.yaxis;
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
_fullLayout: newFullLayout
};

var ids = newSubplotList.cartesian.concat(newSubplotList.gl2d || []);
var ids = (newSubplotList.cartesian || []).concat(newSubplotList.gl2d || []);

for(i = 0; i < ids.length; i++) {
var id = ids[i];
Expand Down
10 changes: 8 additions & 2 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var isPlainObject = require('./lib/is_plain_object');
var addStyleRule = require('./lib/dom').addStyleRule;
var ExtendModule = require('./lib/extend');

var basePlotAttributes = require('./plots/attributes');
var dfltTrace = require('./plots/attributes').type.dflt;
var baseLayoutAttributes = require('./plots/layout_attributes');

var extendFlat = ExtendModule.extendFlat;
Expand Down Expand Up @@ -140,7 +140,13 @@ exports.traceIs = function(traceType, category) {
Loggers.log('Unrecognized trace type ' + traceType + '.');
}

_module = exports.modules[basePlotAttributes.type.dflt];
_module = exports.modules[dfltTrace];
if(!_module) {
Loggers.log('The default trace type ' + dfltTrace + ' is not registered.');

// in case the category starts with no return true otherwise false
return category.indexOf('no') === 0 ? true : false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it important to return true here for the no categories? In what situation would this occur?

}
}

return !!_module.categories[category];
Expand Down
16 changes: 5 additions & 11 deletions test/jasmine/assets/check_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
* but the test is that they may have been registered in any order
*/
module.exports = function checkComponent(Plotly) {
describe('core (svg 2d, scatter) and registered (bar) traces and transforms', function() {
describe('core and registered (bar) traces and transforms', function() {
var gd;

var mock = {
data: [
{
type: 'bar',
// x data is date so we coerce a calendar
x: ['2001-01-01', '2002-01-01', '2003-01-01'],
y: [1, 3, 5]
Expand Down Expand Up @@ -43,21 +44,14 @@ module.exports = function checkComponent(Plotly) {

afterEach(destroyGraphDiv);

it('should graph scatter traces with calendar attributes', function() {
var nodes = d3SelectAll('g.trace.scatter');

expect(nodes.size()).toEqual(1);
it('should graph bar traces with calendar attributes', function() {
var nodes = d3SelectAll('g.trace.bars');

// compare to core_test
expect(gd._fullLayout.calendar).toBe('gregorian');
expect(gd._fullLayout.xaxis.calendar).toBe('gregorian');
expect(gd._fullData[0].xcalendar).toBe('gregorian');
});

it('should graph bar traces with calendar attributes', function() {
var nodes = d3SelectAll('g.trace.bars');

expect(nodes.size()).toEqual(1);
expect(nodes.size()).toEqual(2);
expect(gd._fullData[1].xcalendar).toBe('gregorian');
expect(gd._fullData[1].transforms[0].valuecalendar).toBe('nepali');
});
Expand Down
18 changes: 5 additions & 13 deletions test/jasmine/bundle_tests/bar_test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
var d3SelectAll = require('../../strict-d3').selectAll;

var Plotly = require('@lib/core');
var PlotlyBar = require('@lib/bar');
var Bar = require('@lib/bar');

var d3SelectAll = require('../../strict-d3').selectAll;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Bundle with bar', function() {
'use strict';

Plotly.register(PlotlyBar);
Plotly.register(Bar);

var mock = require('@mocks/bar_line.json');
var mock = require('@mocks/0.json');

beforeEach(function(done) {
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);

it('should graph scatter traces', function() {
var nodes = d3SelectAll('g.trace.scatter');

expect(nodes.size()).toEqual(1);
});

it('should graph bar traces', function() {
var nodes = d3SelectAll('g.trace.bars');

expect(nodes.size()).toEqual(1);
expect(nodes.size()).toEqual(3);
});
});
9 changes: 3 additions & 6 deletions test/jasmine/bundle_tests/choropleth_test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
var d3SelectAll = require('../../strict-d3').selectAll;

var Plotly = require('@lib/core');
var PlotlyChoropleth = require('@lib/choropleth');
var Choropleth = require('@lib/choropleth');

var d3SelectAll = require('../../strict-d3').selectAll;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


var LONG_TIMEOUT_INTERVAL = 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL;


describe('Bundle with choropleth', function() {
'use strict';

Plotly.register(PlotlyChoropleth);
Plotly.register(Choropleth);

var gd;

Expand Down
18 changes: 5 additions & 13 deletions test/jasmine/bundle_tests/contour_test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
var d3SelectAll = require('../../strict-d3').selectAll;

var Plotly = require('@lib/core');
var PlotlyContour = require('@lib/contour');
var Contour = require('@lib/contour');

var d3SelectAll = require('../../strict-d3').selectAll;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Bundle with contour', function() {
'use strict';

Plotly.register(PlotlyContour);
Plotly.register(Contour);

var mock = require('@mocks/contour_scatter.json');
var mock = require('@mocks/contour_log.json');

beforeEach(function(done) {
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
});

afterEach(destroyGraphDiv);

it('should graph scatter traces', function() {
var nodes = d3SelectAll('g.trace.scatter');

expect(nodes.size()).toEqual(1);
});

it('should graph contour traces', function() {
var nodes = d3SelectAll('g.contour');

expect(nodes.size()).toEqual(1);
expect(nodes.size()).toEqual(4);
});
});
10 changes: 6 additions & 4 deletions test/jasmine/bundle_tests/core_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
var d3SelectAll = require('../../strict-d3').selectAll;

var Plotly = require('@lib/core');
var Scatter = require('@lib/scatter');

var d3SelectAll = require('../../strict-d3').selectAll;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Bundle with core only', function() {
describe('Bundle with core and scatter only', function() {
'use strict';

Plotly.register(Scatter);

var gd;

var mock = require('@mocks/bar_line.json');
Expand Down
6 changes: 5 additions & 1 deletion test/jasmine/bundle_tests/dynamic_import_test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
var Plotly = require('@lib/core');
var Scatter = require('@lib/scatter');

var d3Select = require('../../strict-d3').select;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Dynamic @lib/ module imports', function() {
'use strict';

Plotly.register(Scatter);

var gd;

afterEach(destroyGraphDiv);
Expand Down
8 changes: 4 additions & 4 deletions test/jasmine/bundle_tests/finance_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Plots = require('@src/plots/plots');
var Plotly = require('@lib/core');
var ohlc = require('@lib/ohlc');
var candlestick = require('@lib/candlestick');
var Ohlc = require('@lib/ohlc');
var Candlestick = require('@lib/candlestick');

var d3Select = require('../../strict-d3').select;
var createGraphDiv = require('../assets/create_graph_div');
Expand All @@ -10,7 +10,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('Bundle with finance trace type', function() {
'use strict';

Plotly.register([ohlc, candlestick]);
Plotly.register([Ohlc, Candlestick]);

var mock = require('@mocks/finance_style.json');

Expand All @@ -25,7 +25,7 @@ describe('Bundle with finance trace type', function() {

// scatter is registered no matter what
// ohlc uses some parts of box by direct require but does not need to register it.
expect(traceModules).toEqual(['scatter', 'ohlc', 'candlestick']);
expect(traceModules).toEqual(['ohlc', 'candlestick']);
});

it('should graph ohlc and candlestick traces', function(done) {
Expand Down
18 changes: 5 additions & 13 deletions test/jasmine/bundle_tests/histogram2dcontour_test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
var d3SelectAll = require('../../strict-d3').selectAll;

var Plotly = require('@lib/core');
var PlotlyHistogram2dContour = require('@lib/histogram2dcontour');
var PlotlyHistogram = require('@lib/histogram');
var Histogram2dContour = require('@lib/histogram2dcontour');
var Histogram = require('@lib/histogram');

var d3SelectAll = require('../../strict-d3').selectAll;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Bundle with histogram2dcontour and histogram', function() {
'use strict';

Plotly.register([PlotlyHistogram2dContour, PlotlyHistogram]);
Plotly.register([Histogram2dContour, Histogram]);

var mock = require('@mocks/2dhistogram_contour_subplots.json');

beforeEach(function(done) {
Plotly.newPlot(createGraphDiv(), mock.data, mock.layout).then(done);
Plotly.newPlot(createGraphDiv(), mock.data.slice(1), mock.layout).then(done);
});

afterEach(destroyGraphDiv);

it('should graph scatter traces', function() {
var nodes = d3SelectAll('g.trace.scatter');

expect(nodes.size()).toEqual(1);
});

it('should graph contour traces', function() {
var nodes = d3SelectAll('g.contour');

Expand Down
5 changes: 3 additions & 2 deletions test/jasmine/bundle_tests/mathjax_test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var Plotly = require('@lib/index');
var d3Select = require('../../strict-d3').select;

var d3Select = require('../../strict-d3').select;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');


describe('Test MathJax:', function() {
'use strict';

var mathJaxScriptTag;

// N.B. we have to load MathJax "dynamically" as Karam
Expand Down
Loading