Skip to content

Commit 92a3061

Browse files
committed
use same contours logic in histogram2dcontour as for contour traces
- which fixes the references issues on relayout when `autocontour: true`
1 parent 8ad7e93 commit 92a3061

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
var attributes = require('./attributes');
13+
14+
module.exports = function handleContourDefaults(traceIn, traceOut, coerce) {
15+
var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start');
16+
var contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end');
17+
var missingEnd = (contourStart === false) || (contourEnd === false);
18+
19+
// normally we only need size if autocontour is off. But contour.calc
20+
// pushes its calculated contour size back to the input trace, so for
21+
// things like restyle that can call supplyDefaults without calc
22+
// after the initial draw, we can just reuse the previous calculation
23+
var contourSize = coerce('contours.size');
24+
var autoContour;
25+
26+
if(missingEnd) autoContour = traceOut.autocontour = true;
27+
else autoContour = coerce('autocontour', false);
28+
29+
if(autoContour || !contourSize) coerce('ncontours');
30+
};

src/traces/contour/defaults.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var Lib = require('../../lib');
1313

1414
var hasColumns = require('../heatmap/has_columns');
1515
var handleXYZDefaults = require('../heatmap/xyz_defaults');
16-
var handleStyleDefaults = require('../contour/style_defaults');
16+
var handleContoursDefaults = require('./contours_defaults');
17+
var handleStyleDefaults = require('./style_defaults');
1718
var attributes = require('./attributes');
1819

1920

@@ -31,21 +32,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3132
coerce('text');
3233
coerce('connectgaps', hasColumns(traceOut));
3334

34-
var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start'),
35-
contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end'),
36-
missingEnd = (contourStart === false) || (contourEnd === false),
37-
38-
// normally we only need size if autocontour is off. But contour.calc
39-
// pushes its calculated contour size back to the input trace, so for
40-
// things like restyle that can call supplyDefaults without calc
41-
// after the initial draw, we can just reuse the previous calculation
42-
contourSize = coerce('contours.size'),
43-
autoContour;
44-
45-
if(missingEnd) autoContour = traceOut.autocontour = true;
46-
else autoContour = coerce('autocontour', false);
47-
48-
if(autoContour || !contourSize) coerce('ncontours');
49-
35+
handleContoursDefaults(traceIn, traceOut, coerce);
5036
handleStyleDefaults(traceIn, traceOut, coerce, layout);
5137
};

src/traces/histogram2dcontour/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
var Lib = require('../../lib');
1313

1414
var handleSampleDefaults = require('../histogram2d/sample_defaults');
15+
var handleContoursDefaults = require('../contour/contours_defaults');
1516
var handleStyleDefaults = require('../contour/style_defaults');
1617
var attributes = require('./attributes');
1718

@@ -30,5 +31,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3031
if(autocontour) coerce('ncontours');
3132
else coerce('contours.size');
3233

34+
handleContoursDefaults(traceIn, traceOut, coerce);
3335
handleStyleDefaults(traceIn, traceOut, coerce, layout);
3436
};

0 commit comments

Comments
 (0)