Skip to content

Commit 9fc8832

Browse files
committed
add Registry.call method + use it to 🔪 circular deps !!!
1 parent 52b83b3 commit 9fc8832

File tree

24 files changed

+80
-90
lines changed

24 files changed

+80
-90
lines changed

src/components/annotations/click.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

12-
var Plotly = require('../../plotly');
13-
11+
var Registry = require('../../registry');
1412

1513
module.exports = {
1614
hasClickToShow: hasClickToShow,
@@ -59,7 +57,7 @@ function onClick(gd, hoverData) {
5957
update['annotations[' + offSet[i] + '].visible'] = false;
6058
}
6159

62-
return Plotly.update(gd, {}, update);
60+
return Registry.call('update', [gd, {}, update]);
6361
}
6462

6563
/*

src/components/annotations/draw.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var d3 = require('d3');
1312

14-
var Plotly = require('../../plotly');
13+
var Registry = require('../../registry');
1514
var Plots = require('../../plots/plots');
1615
var Lib = require('../../lib');
1716
var Axes = require('../../plots/cartesian/axes');
@@ -21,10 +20,8 @@ var Fx = require('../fx');
2120
var svgTextUtils = require('../../lib/svg_text_utils');
2221
var setCursor = require('../../lib/setcursor');
2322
var dragElement = require('../dragelement');
24-
2523
var drawArrowHead = require('./draw_arrow_head');
2624

27-
2825
// Annotations are stored in gd.layout.annotations, an array of objects
2926
// index can point to one item in this array,
3027
// or non-numeric to simply add a new one
@@ -594,7 +591,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
594591
});
595592
},
596593
doneFn: function() {
597-
Plotly.relayout(gd, update);
594+
Registry.call('relayout', [gd, update]);
598595
var notesBox = document.querySelector('.js-notes-box-panel');
599596
if(notesBox) notesBox.redraw(notesBox.selectedObj);
600597
}
@@ -676,7 +673,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
676673
},
677674
doneFn: function() {
678675
setCursor(annTextGroupInner);
679-
Plotly.relayout(gd, update);
676+
Registry.call('relayout', [gd, update]);
680677
var notesBox = document.querySelector('.js-notes-box-panel');
681678
if(notesBox) notesBox.redraw(notesBox.selectedObj);
682679
}
@@ -701,7 +698,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
701698
update[ya._name + '.autorange'] = true;
702699
}
703700

704-
Plotly.relayout(gd, update);
701+
Registry.call('relayout', [gd, update]);
705702
});
706703
}
707704
else annText.call(textLayout);

src/components/colorbar/draw.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
var d3 = require('d3');
1313
var tinycolor = require('tinycolor2');
1414

15-
var Plotly = require('../../plotly');
1615
var Plots = require('../../plots/plots');
1716
var Registry = require('../../registry');
1817
var Axes = require('../../plots/cartesian/axes');
@@ -588,9 +587,11 @@ module.exports = function draw(gd, id) {
588587
setCursor(container);
589588

590589
if(xf !== undefined && yf !== undefined) {
591-
Plotly.restyle(gd,
590+
Registry.call('restyle', [
591+
gd,
592592
{'colorbar.x': xf, 'colorbar.y': yf},
593-
getTrace().index);
593+
getTrace().index
594+
]);
594595
}
595596
}
596597
});

src/components/dragelement/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var mouseOffset = require('mouse-event-offset');
1313
var hasHover = require('has-hover');
1414
var supportsPassive = require('has-passive-events');
1515

16-
var Plotly = require('../../plotly');
16+
var Registry = require('../../registry');
1717
var Lib = require('../../lib');
1818

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

279279
function finishDrag(gd) {
280280
gd._dragging = false;
281-
if(gd._replotPending) Plotly.plot(gd);
281+
if(gd._replotPending) Registry.call('plot', [gd]);
282282
}
283283

284284
function pointerOffset(e) {

src/components/legend/draw.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var d3 = require('d3');
1212

13-
var Plotly = require('../../plotly');
1413
var Lib = require('../../lib');
1514
var Plots = require('../../plots/plots');
1615
var Registry = require('../../registry');
@@ -339,7 +338,7 @@ module.exports = function draw(gd) {
339338
},
340339
doneFn: function() {
341340
if(xf !== undefined && yf !== undefined) {
342-
Plotly.relayout(gd, {'legend.x': xf, 'legend.y': yf});
341+
Registry.call('relayout', [gd, {'legend.x': xf, 'legend.y': yf}]);
343342
}
344343
},
345344
clickFn: function(numClicks, e) {
@@ -431,7 +430,7 @@ function drawTexts(g, gd) {
431430
update.name = text;
432431
}
433432

434-
return Plotly.restyle(gd, update, traceIndex);
433+
return Registry.call('restyle', [gd, update, traceIndex]);
435434
});
436435
} else {
437436
text.call(textLayout);

src/components/legend/handle_click.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
'use strict';
1010

11-
var Plotly = require('../../plotly');
1211
var Lib = require('../../lib');
1312
var Registry = require('../../registry');
1413

@@ -112,7 +111,7 @@ module.exports = function handleClick(g, gd, numClicks) {
112111
}
113112
}
114113

115-
Plotly.relayout(gd, 'hiddenlabels', hiddenSlices);
114+
Registry.call('relayout', [gd, 'hiddenlabels', hiddenSlices]);
116115
} else {
117116
var hasLegendgroup = legendgroup && legendgroup.length;
118117
var traceIndicesInGroup = [];
@@ -218,6 +217,6 @@ module.exports = function handleClick(g, gd, numClicks) {
218217
}
219218
}
220219

221-
Plotly.restyle(gd, attrUpdate, attrIndices);
220+
Registry.call('restyle', [gd, attrUpdate, attrIndices]);
222221
}
223222
};

src/components/modebar/buttons.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
12+
var Registry = require('../../registry');
1313
var Plots = require('../../plots/plots');
1414
var axisIds = require('../../plots/cartesian/axis_ids');
1515
var Lib = require('../../lib');
1616
var downloadImage = require('../../snapshot/download');
1717
var Icons = require('../../../build/ploticon');
1818

19-
2019
var _ = Lib._;
2120

2221
var modeBarButtons = module.exports = {};
@@ -250,7 +249,7 @@ function handleCartesian(gd, ev) {
250249
aobj[astr] = val;
251250
}
252251

253-
Plotly.relayout(gd, aobj);
252+
Registry.call('relayout', [gd, aobj]);
254253
}
255254

256255
modeBarButtons.zoom3d = {
@@ -306,7 +305,7 @@ function handleDrag3d(gd, ev) {
306305
var val2d = (val === 'pan') ? val : 'zoom';
307306
layoutUpdate.dragmode = val2d;
308307

309-
Plotly.relayout(gd, layoutUpdate);
308+
Registry.call('relayout', [gd, layoutUpdate]);
310309
}
311310

312311
modeBarButtons.resetCameraDefault3d = {
@@ -345,7 +344,7 @@ function handleCamera3d(gd, ev) {
345344
}
346345
}
347346

348-
Plotly.relayout(gd, aobj);
347+
Registry.call('relayout', [gd, aobj]);
349348
}
350349

351350
modeBarButtons.hoverClosest3d = {
@@ -406,7 +405,7 @@ function handleHover3d(gd, ev) {
406405
button._previousVal = Lib.extendDeep({}, currentSpikes);
407406
}
408407

409-
Plotly.relayout(gd, layoutUpdate);
408+
Registry.call('relayout', [gd, layoutUpdate]);
410409
}
411410

412411
modeBarButtons.zoomInGeo = {
@@ -462,7 +461,7 @@ function handleGeo(gd, ev) {
462461
var scale = geoLayout.projection.scale;
463462
var newScale = (val === 'in') ? 2 * scale : 0.5 * scale;
464463

465-
Plotly.relayout(gd, id + '.projection.scale', newScale);
464+
Registry.call('relayout', [gd, id + '.projection.scale', newScale]);
466465
} else if(attr === 'reset') {
467466
resetView(gd, 'geo');
468467
}
@@ -501,7 +500,7 @@ function toggleHover(gd) {
501500

502501
var newHover = gd._fullLayout.hovermode ? false : onHoverVal;
503502

504-
Plotly.relayout(gd, 'hovermode', newHover);
503+
Registry.call('relayout', [gd, 'hovermode', newHover]);
505504
}
506505

507506
// buttons when more then one plot types are present
@@ -556,7 +555,7 @@ modeBarButtons.toggleSpikelines = {
556555

557556
var aobj = setSpikelineVisibility(gd);
558557

559-
Plotly.relayout(gd, aobj);
558+
Registry.call('relayout', [gd, aobj]);
560559
}
561560
};
562561

@@ -603,5 +602,5 @@ function resetView(gd, subplotType) {
603602
}
604603
}
605604

606-
Plotly.relayout(gd, aObj);
605+
Registry.call('relayout', [gd, aObj]);
607606
}

src/components/rangeselector/draw.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var d3 = require('d3');
1312

14-
var Plotly = require('../../plotly');
13+
var Registry = require('../../registry');
1514
var Plots = require('../../plots/plots');
1615
var Color = require('../color');
1716
var Drawing = require('../drawing');
@@ -69,7 +68,7 @@ module.exports = function draw(gd) {
6968
button.on('click', function() {
7069
if(gd._dragged) return;
7170

72-
Plotly.relayout(gd, update);
71+
Registry.call('relayout', [gd, update]);
7372
});
7473

7574
button.on('mouseover', function() {

src/components/rangeslider/draw.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
var d3 = require('d3');
1212

13-
var Plotly = require('../../plotly');
13+
var Registry = require('../../registry');
1414
var Plots = require('../../plots/plots');
1515

1616
var Lib = require('../../lib');
@@ -25,7 +25,6 @@ var setCursor = require('../../lib/setcursor');
2525

2626
var constants = require('./constants');
2727

28-
2928
module.exports = function(gd) {
3029
var fullLayout = gd._fullLayout,
3130
rangeSliderData = makeRangeSliderData(fullLayout);
@@ -262,7 +261,7 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
262261
dataMax = clamp(opts.p2d(opts._pixelMax));
263262

264263
window.requestAnimationFrame(function() {
265-
Plotly.relayout(gd, axisOpts._name + '.range', [dataMin, dataMax]);
264+
Registry.call('relayout', [gd, axisOpts._name + '.range', [dataMin, dataMax]]);
266265
});
267266
}
268267

src/components/shapes/draw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
12+
var Registry = require('../../registry');
1313
var Lib = require('../../lib');
1414
var Axes = require('../../plots/cartesian/axes');
1515
var Color = require('../color');
@@ -213,7 +213,7 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
213213

214214
function endDrag() {
215215
setCursor(shapePath);
216-
Plotly.relayout(gd, update);
216+
Registry.call('relayout', [gd, update]);
217217
}
218218

219219
function moveShape(dx, dy) {

src/components/titles/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
var d3 = require('d3');
1313
var isNumeric = require('fast-isnumeric');
1414

15-
var Plotly = require('../../plotly');
1615
var Plots = require('../../plots/plots');
16+
var Registry = require('../../registry');
1717
var Lib = require('../../lib');
1818
var Drawing = require('../drawing');
1919
var Color = require('../color');
@@ -237,8 +237,11 @@ Titles.draw = function(gd, titleClass, options) {
237237

238238
el.call(svgTextUtils.makeEditable, {gd: gd})
239239
.on('edit', function(text) {
240-
if(traceIndex !== undefined) Plotly.restyle(gd, prop, text, traceIndex);
241-
else Plotly.relayout(gd, prop, text);
240+
if(traceIndex !== undefined) {
241+
Registry.call('restyle', [gd, prop, text, traceIndex]);
242+
} else {
243+
Registry.call('relayout', [gd, prop, text]);
244+
}
242245
})
243246
.on('cancel', function() {
244247
this.text(this.attr('data-unformatted'))

src/plot_api/subroutines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ exports.doColorBars = function(gd) {
462462
exports.layoutReplot = function(gd) {
463463
var layout = gd.layout;
464464
gd.layout = undefined;
465-
return Plotly.plot(gd, '', layout);
465+
return Registry.call('plot', [gd, '', layout]);
466466
};
467467

468468
exports.doLegend = function(gd) {

src/plot_api/to_image.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var Plotly = require('../plotly');
11+
var Registry = require('../registry');
1212
var Lib = require('../lib');
1313

1414
var helpers = require('../snapshot/helpers');
@@ -155,7 +155,7 @@ function toImage(gd, opts) {
155155
var width = clonedGd._fullLayout.width;
156156
var height = clonedGd._fullLayout.height;
157157

158-
Plotly.purge(clonedGd);
158+
Registry.call('purge', [clonedGd]);
159159
document.body.removeChild(clonedGd);
160160

161161
if(format === 'svg') {
@@ -196,7 +196,7 @@ function toImage(gd, opts) {
196196
}
197197

198198
return new Promise(function(resolve, reject) {
199-
Plotly.plot(clonedGd, data, layoutImage, configImage)
199+
Registry.call('plot', [clonedGd, data, layoutImage, configImage])
200200
.then(redrawFunc)
201201
.then(wait)
202202
.then(convert)

0 commit comments

Comments
 (0)