Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh3d colorscale settings #1719

Merged
merged 8 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/traces/mesh3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ module.exports = {
width: extendFlat({}, surfaceAtts.contours.x.width)
},

cauto: colorscaleAttrs.zauto,
cmin: colorscaleAttrs.zmin,
cmax: colorscaleAttrs.zmax,
colorscale: colorscaleAttrs.colorscale,
reversescale: colorscaleAttrs.reversescale,
autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}),
showscale: colorscaleAttrs.showscale,
colorbar: colorbarAttrs,

Expand Down
17 changes: 17 additions & 0 deletions src/traces/mesh3d/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var colorscaleCalc = require('../../components/colorscale/calc');

module.exports = function calc(gd, trace) {
if(trace.intensity) {
colorscaleCalc(trace, trace.intensity, '', 'c');
}
};
48 changes: 48 additions & 0 deletions src/traces/mesh3d/colorbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
var Plots = require('../../plots/plots');
var Colorscale = require('../../components/colorscale');
var drawColorbar = require('../../components/colorbar/draw');

module.exports = function colorbar(gd, cd) {
var trace = cd[0].trace,
cbId = 'cb' + trace.uid,
cmin = trace.cmin,
cmax = trace.cmax,
vals = trace.intensity || [];

if(!isNumeric(cmin)) cmin = Lib.aggNums(Math.min, null, vals);
if(!isNumeric(cmax)) cmax = Lib.aggNums(Math.max, null, vals);

gd._fullLayout._infolayer.selectAll('.' + cbId).remove();

if(!trace.showscale) {
Plots.autoMargin(gd, cbId);
return;
}

var cb = cd[0].t.cb = drawColorbar(gd, cbId);
var sclFunc = Colorscale.makeColorScaleFunc(
Colorscale.extractScale(
trace.colorscale,
cmin,
cmax
),
{ noNumericCheck: true }
);

cb.fillcolor(sclFunc)
.filllevels({start: cmin, end: cmax, size: (cmax - cmin) / 254})
.options(trace.colorbar)();
};
1 change: 1 addition & 0 deletions src/traces/mesh3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ proto.update = function(data) {
if(data.intensity) {
this.color = '#fff';
config.vertexIntensity = data.intensity;
config.vertexIntensityBounds = [data.cmin, data.cmax];
config.colormap = parseColorScale(data.colorscale);
}
else if(data.vertexcolor) {
Expand Down
18 changes: 3 additions & 15 deletions src/traces/mesh3d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

var Registry = require('../../registry');
var Lib = require('../../lib');
var colorbarDefaults = require('../../components/colorbar/defaults');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var attributes = require('./attributes');


module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
Expand Down Expand Up @@ -77,23 +76,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

if('intensity' in traceIn) {
coerce('intensity');
coerce('showscale', true);
}
else {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice when you can remove code to add features and fix bugs 🎉

} else {
traceOut.showscale = false;

if('facecolor' in traceIn) coerce('facecolor');
else if('vertexcolor' in traceIn) coerce('vertexcolor');
else coerce('color', defaultColor);
}

if(traceOut.reversescale) {
traceOut.colorscale = traceOut.colorscale.map(function(si) {
return [1 - si[0], si[1]];
}).reverse();
}

if(traceOut.showscale) {
colorbarDefaults(traceIn, traceOut, layout);
}
};
3 changes: 2 additions & 1 deletion src/traces/mesh3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var Mesh3D = {};

Mesh3D.attributes = require('./attributes');
Mesh3D.supplyDefaults = require('./defaults');
Mesh3D.colorbar = require('../heatmap/colorbar');
Mesh3D.calc = require('./calc');
Mesh3D.colorbar = require('./colorbar');
Mesh3D.plot = require('./convert');

Mesh3D.moduleType = 'trace';
Expand Down
1 change: 0 additions & 1 deletion src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ module.exports = {
].join(' ')
},

// Todo this block has a structure of colorscale/attributes.js but with colorscale/color_attributes.js names
cauto: colorscaleAttrs.zauto,
cmin: colorscaleAttrs.zmin,
cmax: colorscaleAttrs.zmax,
Expand Down
Binary file modified test/image/baselines/gl3d_tetrahedra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/image/mocks/gl3d_tetrahedra.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
[1, "rgb(0, 0, 255)"]
],
"intensity": [0, 0.33, 0.66, 1],
"cmin": -0.5,
"cmax": 0.5,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. That made the axis labels disappear. I might have to revert back those gl-error3d dependencies bump of commit gl-vis/gl-error3d@d756284

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"colorbar": {
"x": 0,
"title": "for colorscale + intensity tetrahedra",
Expand Down