-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Mesh3d colorscale settings #1719
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
bf6da79
bca5814
60b4f44
f55c6f5
5d37bd6
c898252
4cd0876
76a103f
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-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'); | ||
} | ||
}; |
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)(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
[1, "rgb(0, 0, 255)"] | ||
], | ||
"intensity": [0, 0.33, 0.66, 1], | ||
"cmin": -0.5, | ||
"cmax": 0.5, | ||
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. Weird. That made the axis labels disappear. I might have to revert back those 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. fixed in f55c6f5 via gl-vis/gl-error3d#3 |
||
"colorbar": { | ||
"x": 0, | ||
"title": "for colorscale + intensity tetrahedra", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var Plotly = require('@lib'); | ||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var fail = require('../assets/fail_test'); | ||
|
||
describe('Test mesh3d restyle', function() { | ||
afterEach(destroyGraphDiv); | ||
|
||
it('should clear *cauto* when restyle *cmin* and/or *cmax*', function(done) { | ||
var gd = createGraphDiv(); | ||
|
||
function _assert(user, full) { | ||
var trace = gd.data[0]; | ||
var fullTrace = gd._fullData[0]; | ||
|
||
expect(trace.cauto).toBe(user[0], 'user cauto'); | ||
expect(trace.cmin).toEqual(user[1], 'user cmin'); | ||
expect(trace.cmax).toEqual(user[2], 'user cmax'); | ||
expect(fullTrace.cauto).toBe(full[0], 'full cauto'); | ||
expect(fullTrace.cmin).toEqual(full[1], 'full cmin'); | ||
expect(fullTrace.cmax).toEqual(full[2], 'full cmax'); | ||
} | ||
|
||
Plotly.plot(gd, [{ | ||
type: 'mesh3d', | ||
x: [0, 1, 2, 0], | ||
y: [0, 0, 1, 2], | ||
z: [0, 2, 0, 1], | ||
i: [0, 0, 0, 1], | ||
j: [1, 2, 3, 2], | ||
k: [2, 3, 1, 3], | ||
intensity: [0, 0.33, 0.66, 3] | ||
}]) | ||
.then(function() { | ||
_assert([true, 0, 3], [true, 0, 3]); | ||
|
||
return Plotly.restyle(gd, 'cmin', 0); | ||
}) | ||
.then(function() { | ||
_assert([false, 0, 3], [false, 0, 3]); | ||
|
||
return Plotly.restyle(gd, 'cmax', 10); | ||
}) | ||
.then(function() { | ||
_assert([false, 0, 10], [false, 0, 10]); | ||
|
||
return Plotly.restyle(gd, 'cauto', true); | ||
}) | ||
.then(function() { | ||
_assert([true, 0, 3], [true, 0, 3]); | ||
|
||
return Plotly.purge(gd); | ||
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. why purge? 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. To destroy the webgl context. We should perhaps add that Plotly.purge statement in destroyGraphDiv? 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. ah interesting... yeah, would be good to put that in |
||
}) | ||
.catch(fail) | ||
.then(done); | ||
}); | ||
}); |
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.
nice when you can remove code to add features and fix bugs 🎉