Skip to content

Commit bf28ad9

Browse files
committed
move Plotly.register in plot_api/register.js
1 parent fffddcb commit bf28ad9

File tree

3 files changed

+71
-59
lines changed

3 files changed

+71
-59
lines changed

src/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ exports.deleteTraces = Plotly.deleteTraces;
3030
exports.moveTraces = Plotly.moveTraces;
3131
exports.purge = Plotly.purge;
3232
exports.setPlotConfig = require('./plot_api/set_plot_config');
33-
exports.register = Plotly.register;
33+
exports.register = require('./plot_api/register');
3434
exports.toImage = require('./plot_api/to_image');
3535
exports.downloadImage = require('./snapshot/download');
3636
exports.validate = require('./plot_api/validate');
3737

38+
// scatter is the only trace included by default
39+
exports.register(require('./traces/scatter'));
40+
3841
// plot icons
3942
exports.Icons = require('../build/ploticon');
4043

src/plot_api/register.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Plots = require('../plots/plots');
12+
var Lib = require('../lib');
13+
14+
15+
module.exports = function register(_modules) {
16+
if(!_modules) {
17+
throw new Error('No argument passed to Plotly.register.');
18+
}
19+
else if(_modules && !Array.isArray(_modules)) {
20+
_modules = [_modules];
21+
}
22+
23+
for(var i = 0; i < _modules.length; i++) {
24+
var newModule = _modules[i];
25+
26+
if(!newModule) {
27+
throw new Error('Invalid module was attempted to be registered!');
28+
}
29+
30+
switch(newModule.moduleType) {
31+
case 'trace':
32+
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);
33+
34+
if(!Plots.subplotsRegistry[newModule.basePlotModule.name]) {
35+
Plots.registerSubplot(newModule.basePlotModule);
36+
}
37+
38+
break;
39+
40+
case 'transform':
41+
if(typeof newModule.name !== 'string') {
42+
throw new Error('Transform module *name* must be a string.');
43+
}
44+
45+
var prefix = 'Transform module ' + newModule.name;
46+
47+
if(typeof newModule.transform !== 'function') {
48+
throw new Error(prefix + ' is missing a *transform* function.');
49+
}
50+
if(!Lib.isPlainObject(newModule.attributes)) {
51+
Lib.log(prefix + ' registered without an *attributes* object.');
52+
}
53+
if(typeof newModule.supplyDefaults !== 'function') {
54+
Lib.log(prefix + ' registered without a *supplyDefaults* function.');
55+
}
56+
57+
Plots.transformsRegistry[newModule.name] = newModule;
58+
59+
break;
60+
61+
default:
62+
throw new Error('Invalid module was attempted to be registered!');
63+
}
64+
}
65+
};

src/plotly.js

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
require('es6-promise').polyfill();
2323

2424
// lib functions
25-
var Lib = exports.Lib = require('./lib');
25+
exports.Lib = require('./lib');
2626
exports.util = require('./lib/svg_text_utils');
2727
exports.Queue = require('./lib/queue');
2828

@@ -34,8 +34,7 @@ exports.MathJaxConfig = require('./fonts/mathjax_config');
3434
exports.defaultConfig = require('./plot_api/plot_config');
3535

3636
// plots
37-
var Plots = exports.Plots = require('./plots/plots');
38-
37+
exports.Plots = require('./plots/plots');
3938
exports.Axes = require('./plots/cartesian/axes');
4039
exports.Fx = require('./plots/cartesian/graph_interact');
4140

@@ -52,61 +51,6 @@ exports.Images = require('./components/images');
5251
exports.UpdateMenus = require('./components/updatemenus');
5352
exports.ModeBar = require('./components/modebar');
5453

55-
exports.register = function register(_modules) {
56-
if(!_modules) {
57-
throw new Error('No argument passed to Plotly.register.');
58-
}
59-
else if(_modules && !Array.isArray(_modules)) {
60-
_modules = [_modules];
61-
}
62-
63-
for(var i = 0; i < _modules.length; i++) {
64-
var newModule = _modules[i];
65-
66-
if(!newModule) {
67-
throw new Error('Invalid module was attempted to be registered!');
68-
}
69-
70-
switch(newModule.moduleType) {
71-
case 'trace':
72-
Plots.register(newModule, newModule.name, newModule.categories, newModule.meta);
73-
74-
if(!Plots.subplotsRegistry[newModule.basePlotModule.name]) {
75-
Plots.registerSubplot(newModule.basePlotModule);
76-
}
77-
78-
break;
79-
80-
case 'transform':
81-
if(typeof newModule.name !== 'string') {
82-
throw new Error('Transform module *name* must be a string.');
83-
}
84-
85-
var prefix = 'Transform module ' + newModule.name;
86-
87-
if(typeof newModule.transform !== 'function') {
88-
throw new Error(prefix + ' is missing a *transform* function.');
89-
}
90-
if(!Lib.isPlainObject(newModule.attributes)) {
91-
Lib.log(prefix + ' registered without an *attributes* object.');
92-
}
93-
if(typeof newModule.supplyDefaults !== 'function') {
94-
Lib.log(prefix + ' registered without a *supplyDefaults* function.');
95-
}
96-
97-
Plots.transformsRegistry[newModule.name] = newModule;
98-
99-
break;
100-
101-
default:
102-
throw new Error('Invalid module was attempted to be registered!');
103-
}
104-
}
105-
};
106-
107-
// Scatter is the only trace included by default
108-
exports.register(require('./traces/scatter'));
109-
11054
// plot api
11155
require('./plot_api/plot_api');
11256
exports.PlotSchema = require('./plot_api/plot_schema');

0 commit comments

Comments
 (0)