Skip to content

Commit 02ed2eb

Browse files
committed
move doAutoRangeAndConstraints, drawData and finalDraw to subroutines
... (i.e. out of plot_api.js), and move Plots.addLinks out of drawData into its own step in Plotly.plot.
1 parent e14013b commit 02ed2eb

File tree

2 files changed

+96
-93
lines changed

2 files changed

+96
-93
lines changed

src/plot_api/plot_api.js

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var Drawing = require('../components/drawing');
2929
var Color = require('../components/color');
3030
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
3131
var svgTextUtils = require('../lib/svg_text_utils');
32-
var clearGlCanvases = require('../lib/clear_gl_canvases');
3332

3433
var defaultConfig = require('./plot_config');
3534
var manageArrays = require('./manage_arrays');
@@ -38,10 +37,6 @@ var subroutines = require('./subroutines');
3837
var editTypes = require('./edit_types');
3938

4039
var cartesianConstants = require('../plots/cartesian/constants');
41-
var axisConstraints = require('../plots/cartesian/constraints');
42-
var enforceAxisConstraints = axisConstraints.enforce;
43-
var cleanAxisConstraints = axisConstraints.clean;
44-
var doAutoRange = require('../plots/cartesian/autorange').doAutoRange;
4540

4641
var numericNameWarningCount = 0;
4742
var numericNameWarningCountLimit = 5;
@@ -331,15 +326,7 @@ exports.plot = function(gd, data, layout, config) {
331326
function doAutoRangeAndConstraints() {
332327
if(gd._transitioning) return;
333328

334-
var axList = Axes.list(gd, '', true);
335-
for(var i = 0; i < axList.length; i++) {
336-
var ax = axList[i];
337-
cleanAxisConstraints(gd, ax);
338-
339-
doAutoRange(ax);
340-
}
341-
342-
enforceAxisConstraints(gd);
329+
subroutines.doAutoRangeAndConstraints(gd);
343330

344331
// store initial ranges *after* enforcing constraints, otherwise
345332
// we will never look like we're at the initial ranges
@@ -351,83 +338,6 @@ exports.plot = function(gd, data, layout, config) {
351338
return Axes.doTicks(gd, graphWasEmpty ? '' : 'redraw');
352339
}
353340

354-
// Now plot the data
355-
function drawData() {
356-
var calcdata = gd.calcdata,
357-
i,
358-
rangesliderContainers = fullLayout._infolayer.selectAll('g.rangeslider-container');
359-
360-
// in case of traces that were heatmaps or contour maps
361-
// previously, remove them and their colorbars explicitly
362-
for(i = 0; i < calcdata.length; i++) {
363-
var trace = calcdata[i][0].trace,
364-
isVisible = (trace.visible === true),
365-
uid = trace.uid;
366-
367-
if(!isVisible || !Registry.traceIs(trace, '2dMap')) {
368-
var query = (
369-
'.hm' + uid +
370-
',.contour' + uid +
371-
',#clip' + uid
372-
);
373-
374-
fullLayout._paper
375-
.selectAll(query)
376-
.remove();
377-
378-
rangesliderContainers
379-
.selectAll(query)
380-
.remove();
381-
}
382-
383-
if(!isVisible || !trace._module.colorbar) {
384-
fullLayout._infolayer.selectAll('.cb' + uid).remove();
385-
}
386-
}
387-
388-
// TODO does this break or slow down parcoords??
389-
clearGlCanvases(gd);
390-
391-
// loop over the base plot modules present on graph
392-
var basePlotModules = fullLayout._basePlotModules;
393-
for(i = 0; i < basePlotModules.length; i++) {
394-
basePlotModules[i].plot(gd);
395-
}
396-
397-
// keep reference to shape layers in subplots
398-
var layerSubplot = fullLayout._paper.selectAll('.layer-subplot');
399-
fullLayout._shapeSubplotLayers = layerSubplot.selectAll('.shapelayer');
400-
401-
// styling separate from drawing
402-
Plots.style(gd);
403-
404-
// show annotations and shapes
405-
Registry.getComponentMethod('shapes', 'draw')(gd);
406-
Registry.getComponentMethod('annotations', 'draw')(gd);
407-
408-
// source links
409-
Plots.addLinks(gd);
410-
411-
// Mark the first render as complete
412-
fullLayout._replotting = false;
413-
414-
return Plots.previousPromises(gd);
415-
}
416-
417-
// An initial paint must be completed before these components can be
418-
// correctly sized and the whole plot re-margined. fullLayout._replotting must
419-
// be set to false before these will work properly.
420-
function finalDraw() {
421-
Registry.getComponentMethod('shapes', 'draw')(gd);
422-
Registry.getComponentMethod('images', 'draw')(gd);
423-
Registry.getComponentMethod('annotations', 'draw')(gd);
424-
Registry.getComponentMethod('legend', 'draw')(gd);
425-
Registry.getComponentMethod('rangeslider', 'draw')(gd);
426-
Registry.getComponentMethod('rangeselector', 'draw')(gd);
427-
Registry.getComponentMethod('sliders', 'draw')(gd);
428-
Registry.getComponentMethod('updatemenus', 'draw')(gd);
429-
}
430-
431341
var seq = [
432342
Plots.previousPromises,
433343
addFrames,
@@ -439,9 +349,10 @@ exports.plot = function(gd, data, layout, config) {
439349
seq.push(subroutines.layoutStyles);
440350
if(hasCartesian) seq.push(drawAxes);
441351
seq.push(
442-
drawData,
443-
finalDraw,
352+
subroutines.drawData,
353+
subroutines.finalDraw,
444354
initInteractions,
355+
Plots.addLinks,
445356
Plots.rehover,
446357
Plots.previousPromises
447358
);

src/plot_api/subroutines.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
var d3 = require('d3');
1212
var Registry = require('../registry');
1313
var Plots = require('../plots/plots');
14+
1415
var Lib = require('../lib');
16+
var clearGlCanvases = require('../lib/clear_gl_canvases');
1517

1618
var Color = require('../components/color');
1719
var Drawing = require('../components/drawing');
@@ -21,6 +23,10 @@ var Axes = require('../plots/cartesian/axes');
2123
var initInteractions = require('../plots/cartesian/graph_interact');
2224
var cartesianConstants = require('../plots/cartesian/constants');
2325
var alignmentConstants = require('../constants/alignment');
26+
var axisConstraints = require('../plots/cartesian/constraints');
27+
var enforceAxisConstraints = axisConstraints.enforce;
28+
var cleanAxisConstraints = axisConstraints.clean;
29+
var doAutoRange = require('../plots/cartesian/autorange').doAutoRange;
2430

2531
exports.layoutStyles = function(gd) {
2632
return Lib.syncOrAsync([Plots.doAutoMargin, exports.lsInner], gd);
@@ -480,3 +486,89 @@ exports.doCamera = function(gd) {
480486
scene.setCamera(sceneLayout.camera);
481487
}
482488
};
489+
490+
exports.drawData = function(gd) {
491+
var fullLayout = gd._fullLayout;
492+
var calcdata = gd.calcdata;
493+
var rangesliderContainers = fullLayout._infolayer.selectAll('g.rangeslider-container');
494+
var i;
495+
496+
// in case of traces that were heatmaps or contour maps
497+
// previously, remove them and their colorbars explicitly
498+
for(i = 0; i < calcdata.length; i++) {
499+
var trace = calcdata[i][0].trace;
500+
var isVisible = (trace.visible === true);
501+
var uid = trace.uid;
502+
503+
if(!isVisible || !Registry.traceIs(trace, '2dMap')) {
504+
var query = (
505+
'.hm' + uid +
506+
',.contour' + uid +
507+
',#clip' + uid
508+
);
509+
510+
fullLayout._paper
511+
.selectAll(query)
512+
.remove();
513+
514+
rangesliderContainers
515+
.selectAll(query)
516+
.remove();
517+
}
518+
519+
if(!isVisible || !trace._module.colorbar) {
520+
fullLayout._infolayer.selectAll('.cb' + uid).remove();
521+
}
522+
}
523+
524+
// TODO does this break or slow down parcoords??
525+
clearGlCanvases(gd);
526+
527+
// loop over the base plot modules present on graph
528+
var basePlotModules = fullLayout._basePlotModules;
529+
for(i = 0; i < basePlotModules.length; i++) {
530+
basePlotModules[i].plot(gd);
531+
}
532+
533+
// keep reference to shape layers in subplots
534+
var layerSubplot = fullLayout._paper.selectAll('.layer-subplot');
535+
fullLayout._shapeSubplotLayers = layerSubplot.selectAll('.shapelayer');
536+
537+
// styling separate from drawing
538+
Plots.style(gd);
539+
540+
// show annotations and shapes
541+
Registry.getComponentMethod('shapes', 'draw')(gd);
542+
Registry.getComponentMethod('annotations', 'draw')(gd);
543+
544+
// Mark the first render as complete
545+
fullLayout._replotting = false;
546+
547+
return Plots.previousPromises(gd);
548+
};
549+
550+
exports.doAutoRangeAndConstraints = function(gd) {
551+
var axList = Axes.list(gd, '', true);
552+
553+
for(var i = 0; i < axList.length; i++) {
554+
var ax = axList[i];
555+
cleanAxisConstraints(gd, ax);
556+
doAutoRange(ax);
557+
}
558+
559+
enforceAxisConstraints(gd);
560+
};
561+
562+
// An initial paint must be completed before these components can be
563+
// correctly sized and the whole plot re-margined. fullLayout._replotting must
564+
// be set to false before these will work properly.
565+
exports.finalDraw = function(gd) {
566+
Registry.getComponentMethod('shapes', 'draw')(gd);
567+
Registry.getComponentMethod('images', 'draw')(gd);
568+
Registry.getComponentMethod('annotations', 'draw')(gd);
569+
Registry.getComponentMethod('legend', 'draw')(gd);
570+
Registry.getComponentMethod('rangeslider', 'draw')(gd);
571+
Registry.getComponentMethod('rangeselector', 'draw')(gd);
572+
Registry.getComponentMethod('sliders', 'draw')(gd);
573+
Registry.getComponentMethod('updatemenus', 'draw')(gd);
574+
};

0 commit comments

Comments
 (0)