-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add surfacecolor
functionality to surface traces
#347
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
Changes from all commits
93f1781
00109fd
52ab89c
4c4db95
cf23c09
7f1371e
d7a3fe1
e8b944d
70b31cc
78600b9
608a706
3c26428
b6d2a15
9d03cbf
04a7f47
579dcb2
76a627e
861197b
63ea534
863a6f5
b07c429
bf2658a
15354d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2012-2016, 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) { | ||
colorscaleCalc(trace, trace.z, '', 'z'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2012-2016, 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 d3 = require('d3'); | ||
var isNumeric = require('fast-isnumeric'); | ||
|
||
var Lib = require('../../lib'); | ||
var Plots = require('../../plots/plots'); | ||
var getColorscale = require('../../components/colorscale/get_scale'); | ||
var drawColorbar = require('../../components/colorbar/draw'); | ||
|
||
|
||
module.exports = function colorbar(gd, cd) { | ||
var trace = cd[0].trace, | ||
cbId = 'cb' + trace.uid, | ||
scl = getColorscale(trace.colorscale), | ||
zmin = trace.cmin, | ||
zmax = trace.cmax, | ||
vals = trace.surfacecolor || trace.z; | ||
|
||
if(!isNumeric(zmin)) zmin = Lib.aggNums(Math.min, null, vals); | ||
if(!isNumeric(zmax)) zmax = 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); | ||
cb.fillcolor(d3.scale.linear() | ||
.domain(scl.map(function(v) { return zmin + v[0]*(zmax-zmin); })) | ||
.range(scl.map(function(v) { return v[1]; }))) | ||
.filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254}) | ||
.options(trace.colorbar)(); | ||
|
||
Lib.markTime('done colorbar'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
coerce('hidesurface'); | ||
coerce('opacity'); | ||
|
||
var surfaceColor = coerce('surfacecolor'); | ||
|
||
coerce('colorscale'); | ||
|
||
var dims = ['x', 'y', 'z']; | ||
|
@@ -85,7 +87,20 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
} | ||
} | ||
|
||
// backward compatibility block | ||
if(!surfaceColor) { | ||
mapLegacy(traceIn, 'zmin', 'cmin'); | ||
mapLegacy(traceIn, 'zmax', 'cmax'); | ||
mapLegacy(traceIn, 'zauto', 'cauto'); | ||
} | ||
|
||
colorscaleDefaults( | ||
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'} | ||
traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'} | ||
); | ||
}; | ||
|
||
function mapLegacy(traceIn, oldAttr, newAttr) { | ||
if(oldAttr in traceIn && !(newAttr in traceIn)) { | ||
traceIn[newAttr] = traceIn[oldAttr]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdtusz @cldougl @chriddyp Are you ok with this way of preserving backward compatibility?
The deprecated If both a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I'm ok with this. Ideally we would/should be able to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly. That's why I took the conservative route here. We'll clean this up in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok for me |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a more descriptive description? I'm still a little unclear on how this is used.