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

ZERO circular dependency #2429

Merged
merged 17 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from 10 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: 2 additions & 4 deletions src/components/annotations/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

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

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

module.exports = {
hasClickToShow: hasClickToShow,
Expand Down Expand Up @@ -59,7 +57,7 @@ function onClick(gd, hoverData) {
update['annotations[' + offSet[i] + '].visible'] = false;
}

return Plotly.update(gd, {}, update);
return Registry.call('update', [gd, {}, update]);
}

/*
Expand Down
11 changes: 4 additions & 7 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var d3 = require('d3');

var Plotly = require('../../plotly');
var Registry = require('../../registry');
var Plots = require('../../plots/plots');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
Expand All @@ -21,10 +20,8 @@ var Fx = require('../fx');
var svgTextUtils = require('../../lib/svg_text_utils');
var setCursor = require('../../lib/setcursor');
var dragElement = require('../dragelement');

var drawArrowHead = require('./draw_arrow_head');


// Annotations are stored in gd.layout.annotations, an array of objects
// index can point to one item in this array,
// or non-numeric to simply add a new one
Expand Down Expand Up @@ -594,7 +591,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
});
},
doneFn: function() {
Plotly.relayout(gd, update);
Registry.call('relayout', [gd, update]);
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand Down Expand Up @@ -676,7 +673,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
},
doneFn: function() {
setCursor(annTextGroupInner);
Plotly.relayout(gd, update);
Registry.call('relayout', [gd, update]);
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand All @@ -701,7 +698,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
update[ya._name + '.autorange'] = true;
}

Plotly.relayout(gd, update);
Registry.call('relayout', [gd, update]);
});
}
else annText.call(textLayout);
Expand Down
7 changes: 4 additions & 3 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
var d3 = require('d3');
var tinycolor = require('tinycolor2');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
Expand Down Expand Up @@ -588,9 +587,11 @@ module.exports = function draw(gd, id) {
setCursor(container);

if(xf !== undefined && yf !== undefined) {
Plotly.restyle(gd,
Registry.call('restyle', [
gd,
{'colorbar.x': xf, 'colorbar.y': yf},
getTrace().index);
getTrace().index
]);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var mouseOffset = require('mouse-event-offset');
var hasHover = require('has-hover');
var supportsPassive = require('has-passive-events');

var Plotly = require('../../plotly');
var Registry = require('../../registry');
var Lib = require('../../lib');

var constants = require('../../plots/cartesian/constants');
Expand Down Expand Up @@ -278,7 +278,7 @@ dragElement.coverSlip = coverSlip;

function finishDrag(gd) {
gd._dragging = false;
if(gd._replotPending) Plotly.plot(gd);
if(gd._replotPending) Registry.call('plot', [gd]);
}

function pointerOffset(e) {
Expand Down
63 changes: 49 additions & 14 deletions src/components/errorbars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,57 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var errorBars = module.exports = {};
var Lib = require('../../lib');
var overrideAll = require('../../plot_api/edit_types').overrideAll;

var attributes = require('./attributes');
var calc = require('./calc');

var xyAttrs = {
error_x: Lib.extendFlat({}, attributes),
error_y: Lib.extendFlat({}, attributes)
};
delete xyAttrs.error_x.copy_zstyle;
delete xyAttrs.error_y.copy_zstyle;
delete xyAttrs.error_y.copy_ystyle;

var xyzAttrs = {
error_x: Lib.extendFlat({}, attributes),
error_y: Lib.extendFlat({}, attributes),
error_z: Lib.extendFlat({}, attributes)
};
delete xyzAttrs.error_x.copy_ystyle;
delete xyzAttrs.error_y.copy_ystyle;
delete xyzAttrs.error_z.copy_ystyle;
delete xyzAttrs.error_z.copy_zstyle;

module.exports = {
moduleType: 'component',
name: 'errorbars',

errorBars.attributes = require('./attributes');
schema: {
traces: {
scatter: xyAttrs,
bar: xyAttrs,
histogram: xyAttrs,
scatter3d: overrideAll(xyzAttrs, 'calc', 'nested'),
scattergl: overrideAll(xyAttrs, 'calc', 'nested')
}
},

errorBars.supplyDefaults = require('./defaults');
supplyDefaults: require('./defaults'),

errorBars.calc = require('./calc');
calc: calc,
calcFromTrace: calcFromTrace,

errorBars.calcFromTrace = function(trace, layout) {
plot: require('./plot'),
style: require('./style'),
hoverInfo: hoverInfo
};

function calcFromTrace(trace, layout) {
var x = trace.x || [],
y = trace.y || [],
len = x.length || y.length;
Expand All @@ -33,19 +72,15 @@ errorBars.calcFromTrace = function(trace, layout) {

calcdataMock[0].trace = trace;

errorBars.calc({
calc({
calcdata: [calcdataMock],
_fullLayout: layout
});

return calcdataMock;
};
}

errorBars.plot = require('./plot');

errorBars.style = require('./style');

errorBars.hoverInfo = function(calcPoint, trace, hoverPoint) {
function hoverInfo(calcPoint, trace, hoverPoint) {
if((trace.error_y || {}).visible) {
hoverPoint.yerr = calcPoint.yh - calcPoint.y;
if(!trace.error_y.symmetric) hoverPoint.yerrneg = calcPoint.y - calcPoint.ys;
Expand All @@ -54,4 +89,4 @@ errorBars.hoverInfo = function(calcPoint, trace, hoverPoint) {
hoverPoint.xerr = calcPoint.xh - calcPoint.x;
if(!trace.error_x.symmetric) hoverPoint.xerrneg = calcPoint.x - calcPoint.xs;
}
};
}
32 changes: 22 additions & 10 deletions src/plots/grid.js → src/components/grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

'use strict';

var Lib = require('../lib');
var domainAttrs = require('./domain').attributes;
var counterRegex = require('../lib/regex').counter;
var cartesianIdRegex = require('./cartesian/constants').idRegex;
var Lib = require('../../lib');
var counterRegex = require('../../lib/regex').counter;
var domainAttrs = require('../../plots/domain').attributes;
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;


var gridAttrs = exports.attributes = {
var gridAttrs = {
rows: {
valType: 'integer',
min: 1,
Expand Down Expand Up @@ -168,7 +167,7 @@ var gridAttrs = exports.attributes = {

// the shape of the grid - this needs to be done BEFORE supplyDataDefaults
// so that non-subplot traces can place themselves in the grid
exports.sizeDefaults = function(layoutIn, layoutOut) {
function sizeDefaults(layoutIn, layoutOut) {
var gridIn = layoutIn.grid;
if(!gridIn) return;

Expand Down Expand Up @@ -211,7 +210,7 @@ exports.sizeDefaults = function(layoutIn, layoutOut) {
x: fillGridPositions('x', coerce, hasSubplotGrid ? 0.2 : 0.1, columns),
y: fillGridPositions('y', coerce, hasSubplotGrid ? 0.3 : 0.1, rows, reversed)
};
};
}

// coerce x or y sizing attributes and return an array of domains for this direction
function fillGridPositions(axLetter, coerce, dfltGap, len, reversed) {
Expand All @@ -232,7 +231,7 @@ function fillGridPositions(axLetter, coerce, dfltGap, len, reversed) {

// the (cartesian) contents of the grid - this needs to happen AFTER supplyDataDefaults
// so that we know what cartesian subplots are available
exports.contentDefaults = function(layoutIn, layoutOut) {
function contentDefaults(layoutIn, layoutOut) {
var gridOut = layoutOut.grid;
// make sure we got to the end of handleGridSizing
if(!gridOut || !gridOut._domains) return;
Expand Down Expand Up @@ -368,7 +367,7 @@ exports.contentDefaults = function(layoutIn, layoutOut) {
}
}
}
};
}

function fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {
var out = new Array(len);
Expand Down Expand Up @@ -397,3 +396,16 @@ function fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {

return out;
}

module.exports = {
moduleType: 'component',
name: 'grid',

schema: {
layout: {grid: gridAttrs}
},

layoutAttributes: gridAttrs,
sizeDefaults: sizeDefaults,
contentDefaults: contentDefaults
};
5 changes: 2 additions & 3 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
Expand Down Expand Up @@ -339,7 +338,7 @@ module.exports = function draw(gd) {
},
doneFn: function() {
if(xf !== undefined && yf !== undefined) {
Plotly.relayout(gd, {'legend.x': xf, 'legend.y': yf});
Registry.call('relayout', [gd, {'legend.x': xf, 'legend.y': yf}]);
}
},
clickFn: function(numClicks, e) {
Expand Down Expand Up @@ -431,7 +430,7 @@ function drawTexts(g, gd) {
update.name = text;
}

return Plotly.restyle(gd, update, traceIndex);
return Registry.call('restyle', [gd, update, traceIndex]);
});
} else {
text.call(textLayout);
Expand Down
5 changes: 2 additions & 3 deletions src/components/legend/handle_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

'use strict';

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Registry = require('../../registry');

Expand Down Expand Up @@ -112,7 +111,7 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Plotly.relayout(gd, 'hiddenlabels', hiddenSlices);
Registry.call('relayout', [gd, 'hiddenlabels', hiddenSlices]);
} else {
var hasLegendgroup = legendgroup && legendgroup.length;
var traceIndicesInGroup = [];
Expand Down Expand Up @@ -218,6 +217,6 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Plotly.restyle(gd, attrUpdate, attrIndices);
Registry.call('restyle', [gd, attrUpdate, attrIndices]);
}
};
Loading