Skip to content

Commit 70b31cc

Browse files
committed
fix issue with color levels being computed incorrectly
1 parent e8b944d commit 70b31cc

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

src/traces/surface/calc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var colorscaleCalc = require('../../components/colorscale/calc');
1414

1515
// Compute auto-z and autocolorscale if applicable
1616
module.exports = function calc(gd, trace) {
17-
if(trace.intensity) {
17+
if(trace.surfacecolor) {
1818
colorscaleCalc(trace, trace.surfacecolor, '', 'c');
1919
} else {
20-
colorscaleCalc(trace, trace.z, '', 'z');
20+
colorscaleCalc(trace, trace.z, '', 'c');
2121
}
2222
};

src/traces/surface/colorbar.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright 2012-2016, 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+
10+
'use strict';
11+
12+
var d3 = require('d3');
13+
var isNumeric = require('fast-isnumeric');
14+
15+
var Lib = require('../../lib');
16+
var Plots = require('../../plots/plots');
17+
var getColorscale = require('../../components/colorscale/get_scale');
18+
var drawColorbar = require('../../components/colorbar/draw');
19+
20+
21+
module.exports = function colorbar(gd, cd) {
22+
var trace = cd[0].trace,
23+
cbId = 'cb' + trace.uid,
24+
scl = getColorscale(trace.colorscale),
25+
zmin = trace.cmin,
26+
zmax = trace.cmax,
27+
vals = trace.surfacecolor || trace.z;
28+
29+
if(!isNumeric(zmin)) zmin = Lib.aggNums(Math.min, null, vals);
30+
if(!isNumeric(zmax)) zmax = Lib.aggNums(Math.max, null, vals);
31+
32+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
33+
34+
if(!trace.showscale) {
35+
Plots.autoMargin(gd, cbId);
36+
return;
37+
}
38+
39+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
40+
cb.fillcolor(d3.scale.linear()
41+
.domain(scl.map(function(v) { return zmin + v[0]*(zmax-zmin); }))
42+
.range(scl.map(function(v) { return v[1]; })))
43+
.filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254})
44+
.options(trace.colorbar)();
45+
46+
Lib.markTime('done colorbar');
47+
};

src/traces/surface/convert.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,6 @@ proto.update = function(data) {
248248
opacity: 1
249249
};
250250

251-
if('cmin' in data && 'cmax' in data) {
252-
params.intensityBounds = [ data.cmin, data.cmax ];
253-
}
254-
255251
//Refine if necessary
256252
if(data.surfacecolor) {
257253
var intensity = ndarray(

src/traces/surface/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Surface = {};
1313

1414
Surface.attributes = require('./attributes');
1515
Surface.supplyDefaults = require('./defaults');
16-
Surface.colorbar = require('../heatmap/colorbar');
16+
Surface.colorbar = require('./colorbar');
1717
Surface.calc = require('./calc');
1818
Surface.plot = require('./convert');
1919

test/image/mocks/gl3d_autocolorscale.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
["zero two", "one two", "two two"]
2626
],
2727
"autocolorscale": true,
28-
"zmin": 0,
29-
"zmax": "50"
28+
"cmin": 0,
29+
"cmax": "50"
3030
}
3131
],
3232
"layout": {

0 commit comments

Comments
 (0)