@@ -22,26 +22,21 @@ var Registry = require('../registry');
22
22
var PlotSchema = require ( './plot_schema' ) ;
23
23
var Plots = require ( '../plots/plots' ) ;
24
24
var Polar = require ( '../plots/polar/legacy' ) ;
25
- var initInteractions = require ( '../plots/cartesian/graph_interact' ) ;
26
25
27
26
var Axes = require ( '../plots/cartesian/axes' ) ;
28
27
var Drawing = require ( '../components/drawing' ) ;
29
28
var Color = require ( '../components/color' ) ;
29
+ var initInteractions = require ( '../plots/cartesian/graph_interact' ) . initInteractions ;
30
30
var xmlnsNamespaces = require ( '../constants/xmlns_namespaces' ) ;
31
31
var svgTextUtils = require ( '../lib/svg_text_utils' ) ;
32
- var clearGlCanvases = require ( '../lib/clear_gl_canvases' ) ;
33
32
34
33
var defaultConfig = require ( './plot_config' ) ;
35
34
var manageArrays = require ( './manage_arrays' ) ;
36
35
var helpers = require ( './helpers' ) ;
37
36
var subroutines = require ( './subroutines' ) ;
38
37
var editTypes = require ( './edit_types' ) ;
39
38
40
- 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 ;
39
+ var AX_NAME_PATTERN = require ( '../plots/cartesian/constants' ) . AX_NAME_PATTERN ;
45
40
46
41
var numericNameWarningCount = 0 ;
47
42
var numericNameWarningCountLimit = 5 ;
@@ -331,15 +326,7 @@ exports.plot = function(gd, data, layout, config) {
331
326
function doAutoRangeAndConstraints ( ) {
332
327
if ( gd . _transitioning ) return ;
333
328
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 ) ;
343
330
344
331
// store initial ranges *after* enforcing constraints, otherwise
345
332
// we will never look like we're at the initial ranges
@@ -351,83 +338,6 @@ exports.plot = function(gd, data, layout, config) {
351
338
return Axes . doTicks ( gd , graphWasEmpty ? '' : 'redraw' ) ;
352
339
}
353
340
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
-
431
341
var seq = [
432
342
Plots . previousPromises ,
433
343
addFrames ,
@@ -439,9 +349,10 @@ exports.plot = function(gd, data, layout, config) {
439
349
seq . push ( subroutines . layoutStyles ) ;
440
350
if ( hasCartesian ) seq . push ( drawAxes ) ;
441
351
seq . push (
442
- drawData ,
443
- finalDraw ,
352
+ subroutines . drawData ,
353
+ subroutines . finalDraw ,
444
354
initInteractions ,
355
+ Plots . addLinks ,
445
356
Plots . rehover ,
446
357
Plots . previousPromises
447
358
) ;
@@ -1385,8 +1296,8 @@ exports.restyle = function restyle(gd, astr, val, _traces) {
1385
1296
1386
1297
var traces = helpers . coerceTraceIndices ( gd , _traces ) ;
1387
1298
1388
- var specs = _restyle ( gd , aobj , traces ) ,
1389
- flags = specs . flags ;
1299
+ var specs = _restyle ( gd , aobj , traces ) ;
1300
+ var flags = specs . flags ;
1390
1301
1391
1302
// clear calcdata and/or axis types if required so they get regenerated
1392
1303
if ( flags . clearCalc ) gd . calcdata = undefined ;
@@ -1750,8 +1661,8 @@ exports.relayout = function relayout(gd, astr, val) {
1750
1661
1751
1662
if ( Object . keys ( aobj ) . length ) gd . changed = true ;
1752
1663
1753
- var specs = _relayout ( gd , aobj ) ,
1754
- flags = specs . flags ;
1664
+ var specs = _relayout ( gd , aobj ) ;
1665
+ var flags = specs . flags ;
1755
1666
1756
1667
// clear calcdata if required
1757
1668
if ( flags . calc ) gd . calcdata = undefined ;
@@ -1772,6 +1683,30 @@ exports.relayout = function relayout(gd, astr, val) {
1772
1683
1773
1684
if ( flags . legend ) seq . push ( subroutines . doLegend ) ;
1774
1685
if ( flags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
1686
+
1687
+ if ( flags . axrange ) {
1688
+ // N.B. leave as sequence of subroutines (for now) instead of
1689
+ // subroutine of its own so that finalDraw always gets
1690
+ // executed after drawData
1691
+ seq . push (
1692
+ // TODO
1693
+ // no test fail when commenting out doAutoRangeAndConstraints,
1694
+ // but I think we do need this (maybe just the enforce part?)
1695
+ // Am I right?
1696
+ // More info in:
1697
+ // https://github.com/plotly/plotly.js/issues/2540
1698
+ subroutines . doAutoRangeAndConstraints ,
1699
+ // TODO
1700
+ // can target specific axes,
1701
+ // do not have to redraw all axes here
1702
+ // See:
1703
+ // https://github.com/plotly/plotly.js/issues/2547
1704
+ subroutines . doTicksRelayout ,
1705
+ subroutines . drawData ,
1706
+ subroutines . finalDraw
1707
+ ) ;
1708
+ }
1709
+
1775
1710
if ( flags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
1776
1711
if ( flags . modebar ) seq . push ( subroutines . doModeBar ) ;
1777
1712
if ( flags . camera ) seq . push ( subroutines . doCamera ) ;
@@ -1992,7 +1927,7 @@ function _relayout(gd, aobj) {
1992
1927
}
1993
1928
Lib . nestedProperty ( fullLayout , ptrunk + '._inputRange' ) . set ( null ) ;
1994
1929
}
1995
- else if ( pleaf . match ( cartesianConstants . AX_NAME_PATTERN ) ) {
1930
+ else if ( pleaf . match ( AX_NAME_PATTERN ) ) {
1996
1931
var fullProp = Lib . nestedProperty ( fullLayout , ai ) . get ( ) ,
1997
1932
newType = ( vi || { } ) . type ;
1998
1933
@@ -2045,8 +1980,9 @@ function _relayout(gd, aobj) {
2045
1980
if ( checkForAutorange && ( refAutorange ( gd , objToAutorange , 'x' ) || refAutorange ( gd , objToAutorange , 'y' ) ) ) {
2046
1981
flags . calc = true ;
2047
1982
}
2048
- else editTypes . update ( flags , updateValObject ) ;
2049
-
1983
+ else {
1984
+ editTypes . update ( flags , updateValObject ) ;
1985
+ }
2050
1986
2051
1987
// prepare the edits object we'll send to applyContainerArrayChanges
2052
1988
if ( ! arrayEdits [ arrayStr ] ) arrayEdits [ arrayStr ] = { } ;
@@ -2197,11 +2133,11 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
2197
2133
2198
2134
var traces = helpers . coerceTraceIndices ( gd , _traces ) ;
2199
2135
2200
- var restyleSpecs = _restyle ( gd , Lib . extendFlat ( { } , traceUpdate ) , traces ) ,
2201
- restyleFlags = restyleSpecs . flags ;
2136
+ var restyleSpecs = _restyle ( gd , Lib . extendFlat ( { } , traceUpdate ) , traces ) ;
2137
+ var restyleFlags = restyleSpecs . flags ;
2202
2138
2203
- var relayoutSpecs = _relayout ( gd , Lib . extendFlat ( { } , layoutUpdate ) ) ,
2204
- relayoutFlags = relayoutSpecs . flags ;
2139
+ var relayoutSpecs = _relayout ( gd , Lib . extendFlat ( { } , layoutUpdate ) ) ;
2140
+ var relayoutFlags = relayoutSpecs . flags ;
2205
2141
2206
2142
// clear calcdata and/or axis types if required
2207
2143
if ( restyleFlags . clearCalc || relayoutFlags . calc ) gd . calcdata = undefined ;
@@ -2236,6 +2172,14 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
2236
2172
if ( restyleFlags . colorbars ) seq . push ( subroutines . doColorBars ) ;
2237
2173
if ( relayoutFlags . legend ) seq . push ( subroutines . doLegend ) ;
2238
2174
if ( relayoutFlags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
2175
+ if ( relayoutFlags . axrange ) {
2176
+ seq . push (
2177
+ subroutines . doAutoRangeAndConstraints ,
2178
+ subroutines . doTicksRelayout ,
2179
+ subroutines . drawData ,
2180
+ subroutines . finalDraw
2181
+ ) ;
2182
+ }
2239
2183
if ( relayoutFlags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
2240
2184
if ( relayoutFlags . modebar ) seq . push ( subroutines . doModeBar ) ;
2241
2185
if ( relayoutFlags . camera ) seq . push ( subroutines . doCamera ) ;
@@ -2388,6 +2332,14 @@ exports.react = function(gd, data, layout, config) {
2388
2332
if ( restyleFlags . colorbars ) seq . push ( subroutines . doColorBars ) ;
2389
2333
if ( relayoutFlags . legend ) seq . push ( subroutines . doLegend ) ;
2390
2334
if ( relayoutFlags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
2335
+ if ( relayoutFlags . axrange ) {
2336
+ seq . push (
2337
+ subroutines . doAutoRangeAndConstraints ,
2338
+ subroutines . doTicksRelayout ,
2339
+ subroutines . drawData ,
2340
+ subroutines . finalDraw
2341
+ ) ;
2342
+ }
2391
2343
if ( relayoutFlags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
2392
2344
if ( relayoutFlags . modebar ) seq . push ( subroutines . doModeBar ) ;
2393
2345
if ( relayoutFlags . camera ) seq . push ( subroutines . doCamera ) ;
0 commit comments