Skip to content

Commit bf6da79

Browse files
committed
first pass for mesh3d colorscale settings
1 parent cea9455 commit bf6da79

File tree

6 files changed

+74
-17
lines changed

6 files changed

+74
-17
lines changed

src/traces/mesh3d/attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ module.exports = {
165165
width: extendFlat({}, surfaceAtts.contours.x.width)
166166
},
167167

168+
cauto: colorscaleAttrs.zauto,
169+
cmin: colorscaleAttrs.zmin,
170+
cmax: colorscaleAttrs.zmax,
168171
colorscale: colorscaleAttrs.colorscale,
169172
reversescale: colorscaleAttrs.reversescale,
173+
autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}),
170174
showscale: colorscaleAttrs.showscale,
171175
colorbar: colorbarAttrs,
172176

src/traces/mesh3d/calc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 colorscaleCalc = require('../../components/colorscale/calc');
12+
13+
module.exports = function calc(gd, trace) {
14+
if(trace.intensity) {
15+
colorscaleCalc(trace, trace.intensity, '', 'c');
16+
}
17+
};

src/traces/mesh3d/colorbar.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 isNumeric = require('fast-isnumeric');
12+
13+
var Lib = require('../../lib');
14+
var Plots = require('../../plots/plots');
15+
var Colorscale = require('../../components/colorscale');
16+
var drawColorbar = require('../../components/colorbar/draw');
17+
18+
module.exports = function colorbar(gd, cd) {
19+
var trace = cd[0].trace,
20+
cbId = 'cb' + trace.uid,
21+
cmin = trace.cmin,
22+
cmax = trace.cmax,
23+
vals = trace.intensity || [];
24+
25+
if(!isNumeric(cmin)) cmin = Lib.aggNums(Math.min, null, vals);
26+
if(!isNumeric(cmax)) cmax = Lib.aggNums(Math.max, null, vals);
27+
28+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
29+
30+
if(!trace.showscale) {
31+
Plots.autoMargin(gd, cbId);
32+
return;
33+
}
34+
35+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
36+
var sclFunc = Colorscale.makeColorScaleFunc(
37+
Colorscale.extractScale(
38+
trace.colorscale,
39+
cmin,
40+
cmax
41+
),
42+
{ noNumericCheck: true }
43+
);
44+
45+
cb.fillcolor(sclFunc)
46+
.filllevels({start: cmin, end: cmax, size: (cmax - cmin) / 254})
47+
.options(trace.colorbar)();
48+
};

src/traces/mesh3d/defaults.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
var Registry = require('../../registry');
1313
var Lib = require('../../lib');
14-
var colorbarDefaults = require('../../components/colorbar/defaults');
14+
var colorscaleDefaults = require('../../components/colorscale/defaults');
1515
var attributes = require('./attributes');
1616

17-
1817
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
1918
function coerce(attr, dflt) {
2019
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
@@ -77,23 +76,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7776

7877
if('intensity' in traceIn) {
7978
coerce('intensity');
80-
coerce('showscale', true);
81-
}
82-
else {
79+
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
80+
} else {
8381
traceOut.showscale = false;
8482

8583
if('facecolor' in traceIn) coerce('facecolor');
8684
else if('vertexcolor' in traceIn) coerce('vertexcolor');
8785
else coerce('color', defaultColor);
8886
}
89-
90-
if(traceOut.reversescale) {
91-
traceOut.colorscale = traceOut.colorscale.map(function(si) {
92-
return [1 - si[0], si[1]];
93-
}).reverse();
94-
}
95-
96-
if(traceOut.showscale) {
97-
colorbarDefaults(traceIn, traceOut, layout);
98-
}
9987
};

src/traces/mesh3d/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var Mesh3D = {};
1313

1414
Mesh3D.attributes = require('./attributes');
1515
Mesh3D.supplyDefaults = require('./defaults');
16-
Mesh3D.colorbar = require('../heatmap/colorbar');
16+
Mesh3D.calc = require('./calc');
17+
Mesh3D.colorbar = require('./colorbar');
1718
Mesh3D.plot = require('./convert');
1819

1920
Mesh3D.moduleType = 'trace';

src/traces/surface/attributes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ module.exports = {
122122
].join(' ')
123123
},
124124

125-
// Todo this block has a structure of colorscale/attributes.js but with colorscale/color_attributes.js names
126125
cauto: colorscaleAttrs.zauto,
127126
cmin: colorscaleAttrs.zmin,
128127
cmax: colorscaleAttrs.zmax,

0 commit comments

Comments
 (0)