8000 ZERO circular dependency by etpinard · Pull Request #2429 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

ZERO circular dependency #2429

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 17 commits into from
Mar 2, 2018
Merged
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
Prev Previous commit
Next Next commit
add apiMethodRegistry in src/registry
- export api methods in plot_api/index.js
- expose and register them in src/core.js
  • Loading branch information
etpinard committed Mar 1, 2018
commit 52b83b322a23374d7b35db032d723a00dc17a1ef
44 changes: 15 additions & 29 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

'use strict';

/*
* Export the plotly.js API methods.
*/

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

// package version injected by `npm run preprocess`
exports.version = '1.34.0';

Expand All @@ -30,33 +24,25 @@ require('./fonts/mathjax_config');
var Registry = require('./registry');
var register = exports.register = Registry.register;

// plot api
exports.plot = Plotly.plot;
exports.newPlot = Plotly.newPlot;
exports.restyle = Plotly.restyle;
exports.relayout = Plotly.relayout;
exports.redraw = Plotly.redraw;
exports.update = Plotly.update;
exports.react = Plotly.react;
exports.extendTraces = Plotly.extendTraces;
exports.prependTraces = Plotly.prependTraces;
exports.addTraces = Plotly.addTraces;
exports.deleteTraces = Plotly.deleteTraces;
exports.moveTraces = Plotly.moveTraces;
exports.purge = Plotly.purge;
exports.setPlotConfig = require('./plot_api/set_plot_config');
exports.toImage = require('./plot_api/to_image');
exports.downloadImage = require('./snapshot/download');
exports.validate = require('./plot_api/validate');
exports.addFrames = Plotly.addFrames;
exports.deleteFrames = Plotly.deleteFrames;
exports.animate = Plotly.animate;
// expose plot api methods
var plotApi = require('./plot_api');
var methodNames = Object.keys(plotApi);
for(var i = 0; i < methodNames.length; i++) {
var name = methodNames[i];
exports[name] = plotApi[name];
register({
moduleType: 'apiMethod',
name: name,
fn: plotApi[name]
});
}

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

// register all registrable components modules
exports.register([
register([
require('./components/fx'),
require('./components/legend'),
require('./components/annotations'),
Expand All @@ -72,7 +58,7 @@ exports.register([
]);

// locales en and en-US are required for default behavior
exports.register([
register([
require('./locale-en'),
require('./locale-en-us')
]);
Expand Down
32 changes: 32 additions & 0 deletions src/plot_api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var main = require('./plot_api');

exports.plot = main.plot;
exports.newPlot = main.newPlot;
exports.restyle = main.restyle;
exports.relayout = main.relayout;
exports.redraw = main.redraw;
exports.update = main.update;
exports.react = main.react;
exports.extendTraces = main.extendTraces;
exports.prependTraces = main.prependTraces;
exports.addTraces = main.addTraces;
exports.deleteTraces = main.deleteTraces;
exports.moveTraces = main.moveTraces;
exports.purge = main.purge;
exports.addFrames = main.addFrames;
exports.deleteFrames = main.deleteFrames;
exports.animate = main.animate;

exports.toImage = require('./to_image');
exports.validate = require('./validate');
exports.downloadImage = require('../snapshot/download');
68 changes: 34 additions & 34 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var numericNameWarningCountLimit = 5;
* object containing `data`, `layout`, `config`, and `frames` members
*
*/
Plotly.plot = function(gd, data, layout, config) {
exports.plot = function(gd, data, layout, config) {
var frames;

gd = Lib.getGraphDiv(gd);
Expand Down Expand Up @@ -93,7 +93,7 @@ Plotly.plot = function(gd, data, layout, config) {

function addFrames() {
if(frames) {
return Plotly.addFrames(gd, frames);
return exports.addFrames(gd, frames);
}
}

Expand Down Expand Up @@ -627,7 +627,7 @@ function plotPolar(gd, data, layout) {
}

// convenience function to force a full redraw, mostly for use by plotly.js
Plotly.redraw = function(gd) {
exports.redraw = function(gd) {
gd = Lib.getGraphDiv(gd);

if(!Lib.isPlotDiv(gd)) {
Expand All @@ -638,7 +638,7 @@ Plotly.redraw = function(gd) {
helpers.cleanLayout(gd.layout);

gd.calcdata = undefined;
return Plotly.plot(gd).then(function() {
return exports.plot(gd).then(function() {
gd.emit('plotly_redraw');
return gd;
});
Expand All @@ -652,14 +652,14 @@ Plotly.redraw = function(gd) {
* @param {Object} layout
* @param {Object} config
*/
Plotly.newPlot = function(gd, data, layout, config) {
exports.newPlot = function(gd, data, layout, config) {
gd = Lib.getGraphDiv(gd);

// remove gl contexts
Plots.cleanPlot([], {}, gd._fullData || {}, gd._fullLayout || {});

Plots.purge(gd);
return Plotly.plot(gd, data, layout, config);
return exports.plot(gd, data, layout, config);
};

/**
Expand Down Expand Up @@ -987,7 +987,7 @@ function concatTypedArray(arr0, arr1) {
* @param {Number|Object} [maxPoints] Number of points for trace window after lengthening.
*
*/
Plotly.extendTraces = function extendTraces(gd, update, indices, maxPoints) {
exports.extendTraces = function extendTraces(gd, update, indices, maxPoints) {
gd = Lib.getGraphDiv(gd);

function updateArray(target, insert, maxp) {
Expand Down Expand Up @@ -1038,14 +1038,14 @@ Plotly.extendTraces = function extendTraces(gd, update, indices, maxPoints) {
}

var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);
var promise = Plotly.redraw(gd);
var promise = exports.redraw(gd);
var undoArgs = [gd, undo.update, indices, undo.maxPoints];
Queue.add(gd, Plotly.prependTraces, undoArgs, extendTraces, arguments);
Queue.add(gd, exports.prependTraces, undoArgs, extendTraces, arguments);

return promise;
};

Plotly.prependTraces = function prependTraces(gd, update, indices, maxPoints) {
exports.prependTraces = function prependTraces(gd, update, indices, maxPoints) {
gd = Lib.getGraphDiv(gd);

function updateArray(target, insert, maxp) {
Expand Down Expand Up @@ -1095,9 +1095,9 @@ Plotly.prependTraces = function prependTraces(gd, update, indices, maxPoints) {
}

var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);
var promise = Plotly.redraw(gd);
var promise = exports.redraw(gd);
var undoArgs = [gd, undo.update, indices, undo.maxPoints];
10000 Queue.add(gd, Plotly.extendTraces, undoArgs, prependTraces, arguments);
Queue.add(gd, exports.extendTraces, undoArgs, prependTraces, arguments);

return promise;
};
Expand All @@ -1111,11 +1111,11 @@ Plotly.prependTraces = function prependTraces(gd, update, indices, maxPoints) {
* @param {Number[]|Number} [newIndices=[gd.data.length]] Locations to add traces
*
*/
Plotly.addTraces = function addTraces(gd, traces, newIndices) {
exports.addTraces = function addTraces(gd, traces, newIndices) {
gd = Lib.getGraphDiv(gd);

var currentIndices = [],
undoFunc = Plotly.deleteTraces,
undoFunc = exports.deleteTraces,
redoFunc = addTraces,
undoArgs = [gd, currentIndices],
redoArgs = [gd, traces], // no newIndices here
Expand Down Expand Up @@ -1150,7 +1150,7 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) {
// if the user didn't define newIndices, they just want the traces appended
// i.e., we can simply redraw and be done
if(typeof newIndices === 'undefined') {
promise = Plotly.redraw(gd);
promise = exports.redraw(gd);
Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
return promise;
}
Expand All @@ -1176,7 +1176,7 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) {
// this requires some extra work that moveTraces will do
Queue.startSequence(gd);
Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
promise = Plotly.moveTraces(gd, currentIndices, newIndices);
promise = exports.moveTraces(gd, currentIndices, newIndices);
Queue.stopSequence(gd);
return promise;
};
Expand All @@ -1188,11 +1188,11 @@ Plotly.addTraces = function addTraces(gd, traces, newIndices) {
* @param {Object[]} gd.data The array of traces we're removing from
* @param {Number|Number[]} indices The indices
*/
Plotly.deleteTraces = function deleteTraces(gd, indices) {
exports.deleteTraces = function deleteTraces(gd, indices) {
gd = Lib.getGraphDiv(gd);

var traces = [],
undoFunc = Plotly.addTraces,
undoFunc = exports.addTraces,
redoFunc = deleteTraces,
undoArgs = [gd, traces, indices],
redoArgs = [gd, indices],
Expand All @@ -1217,7 +1217,7 @@ Plotly.deleteTraces = function deleteTraces(gd, indices) {
traces.push(deletedTrace);
}

var promise = Plotly.redraw(gd);
var promise = exports.redraw(gd);
Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);

return promise;
Expand Down Expand Up @@ -1254,7 +1254,7 @@ Plotly.deleteTraces = function deleteTraces(gd, indices) {
* // reorder all traces (assume there are 5--a, b, c, d, e)
* Plotly.moveTraces(gd, [b, d, e, a, c]) // same as 'move to end'
*/
Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
exports.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
gd = Lib.getGraphDiv(gd);

var newData = [],
Expand Down Expand Up @@ -1315,7 +1315,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) {

gd.data = newData;

var promise = Plotly.redraw(gd);
var promise = exports.redraw(gd);
Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);

return promise;
Expand Down Expand Up @@ -1351,7 +1351,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
* If the array is too short, it will wrap around (useful for
* style files that want to specify cyclical default values).
*/
Plotly.restyle = function restyle(gd, astr, val, _traces) {
exports.restyle = function restyle(gd, astr, val, _traces) {
gd = Lib.getGraphDiv(gd);
helpers.clearPromiseQueue(gd);

Expand Down Expand Up @@ -1382,7 +1382,7 @@ Plotly.restyle = function restyle(gd, astr, val, _traces) {
var seq = [];

if(flags.fullReplot) {
seq.push(Plotly.plot);
seq.push(exports.plot);
} else {
seq.push(Plots.previousPromises);

Expand Down Expand Up @@ -2156,7 +2156,7 @@ function refAutorange(gd, obj, axLetter) {
* integer or array of integers for the traces to alter (all if omitted)
*
*/
Plotly.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
gd = Lib.getGraphDiv(gd);
helpers.clearPromiseQueue(gd);

Expand Down Expand Up @@ -2194,10 +2194,10 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
gd.data = undefined;
gd.layout = undefined;

seq.push(function() { return Plotly.plot(gd, data, layout); });
seq.push(function() { return exports.plot(gd, data, layout); });
}
else if(restyleFlags.fullReplot) {
seq.push(Plotly.plot);
seq.push(exports.plot);
}
else if(relayoutFlags.layoutReplot) {
seq.push(subroutines.layoutReplot);
Expand Down Expand Up @@ -2258,10 +2258,10 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
* object containing `data`, `layout`, `config`, and `frames` members
*
*/
Plotly.react = function(gd, data, layout, config) {
exports.react = function(gd, data, layout, config) {
var frames, plotDone;

function addFrames() { return Plotly.addFrames(gd, frames); }
function addFrames() { return exports.addFrames(gd, frames); }

gd = Lib.getGraphDiv(gd);

Expand All @@ -2270,7 +2270,7 @@ Plotly.react = function(gd, data, layout, config) {

// you can use this as the initial draw as well as to update
if(!Lib.isPlotDiv(gd) || !oldFullData || !oldFullLayout) {
plotDone = Plotly.newPlot(gd, data, layout, config);
plotDone = exports.newPlot(gd, data, layout, config);
}
else {

Expand Down Expand Up @@ -2323,7 +2323,7 @@ Plotly.react = function(gd, data, layout, config) {

if(restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {
gd._fullLayout._skipDefaults = true;
seq.push(Plotly.plot);
seq.push(exports.plot);
}
else {
for(var componentType in relayoutFlags.arrays) {
Expand Down Expand Up @@ -2660,7 +2660,7 @@ function diffConfig(oldConfig, newConfig) {
* @param {object} animationOpts
* configuration for the animation
*/
Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
exports.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
gd = Lib.getGraphDiv(gd);

if(!Lib.isPlotDiv(gd)) {
Expand Down Expand Up @@ -3024,7 +3024,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
* provided, an index will be provided in serial order. If already used, the frame
* will be overwritten.
*/
Plotly.addFrames = function(gd, frameList, indices) {
exports.addFrames = function(gd, frameList, indices) {
gd = Lib.getGraphDiv(gd);

if(frameList === null || frameList === undefined) {
Expand Down Expand Up @@ -3153,7 +3153,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
* @param {array of integers} frameList
* list of integer indices of frames to be deleted
*/
Plotly.deleteFrames = function(gd, frameList) {
exports.deleteFrames = function(gd, frameList) {
gd = Lib.getGraphDiv(gd);

if(!Lib.isPlotDiv(gd)) {
Expand Down Expand Up @@ -3197,7 +3197,7 @@ Plotly.deleteFrames = function(gd, frameList) {
* @param {string id or DOM element} gd
* the id or DOM element of the graph container div
*/
Plotly.purge = function purge(gd) {
exports.purge = function purge(gd) {
gd = Lib.getGraphDiv(gd);

var fullLayout = gd._fullLayout || {},
Expand Down
Loading
0