-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add optional intensity parameter for surfaces #314
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
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,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 |
---|---|---|
|
@@ -20,7 +20,6 @@ var str2RgbaArray = require('../../lib/str2rgbarray'); | |
|
||
var MIN_RESOLUTION = 128; | ||
|
||
|
||
function SurfaceTrace(scene, surface, uid) { | ||
this.scene = scene; | ||
this.uid = uid; | ||
|
@@ -136,7 +135,7 @@ function refine(coords) { | |
Math.floor((coords[0].shape[1]) * scaleF+1)|0 ]; | ||
var nsize = nshape[0] * nshape[1]; | ||
|
||
for(var i = 0; i < 3; ++i) { | ||
for(var i = 0; i < coords.length; ++i) { | ||
var padImg = padField(coords[i]); | ||
var scaledImg = ndarray(new Float32Array(nsize), nshape); | ||
homography(scaledImg, padImg, [scaleF, 0, 0, | ||
|
@@ -230,9 +229,6 @@ proto.update = function(data) { | |
}); | ||
} | ||
|
||
//Refine if necessary | ||
this.dataScale = refine(coords); | ||
|
||
var params = { | ||
colormap: colormap, | ||
levels: [[], [], []], | ||
|
@@ -249,10 +245,24 @@ proto.update = function(data) { | |
dynamicColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], | ||
dynamicWidth: [1, 1, 1], | ||
dynamicTint: [1, 1, 1], | ||
opacity: 1, | ||
colorBounds: [data.zmin * scaleFactor[2], data.zmax * scaleFactor[2]] | ||
opacity: 1 | ||
}; | ||
|
||
//Refine if necessary | ||
if(data.surfacecolor) { | ||
var intensity = ndarray( | ||
new Float32Array(xlen * ylen), [xlen, ylen]); | ||
fill(intensity, function(row, col) { | ||
return data.surfacecolor[col][row]; | ||
}); | ||
coords.push(intensity); | ||
} | ||
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. In order to preserve backward compatibility, we'll need to set the |
||
|
||
this.dataScale = refine(coords); | ||
|
||
if(data.surfacecolor) { | ||
params.intensity = coords.pop(); | ||
} | ||
|
||
if('opacity' in data) { | ||
if(data.opacity < 1) { | ||
|
@@ -300,6 +310,7 @@ proto.update = function(data) { | |
} | ||
|
||
params.coords = coords; | ||
|
||
surface.update(params); | ||
|
||
surface.highlightEnable = highlightEnable; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,8 @@ | |
["zero two", "one two", "two two"] | ||
], | ||
"autocolorscale": true, | ||
"zmin": 0, | ||
"zmax": "50" | ||
"cmin": 0, | ||
"cmax": "50" | ||
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. The old |
||
} | ||
], | ||
"layout": { | ||
|
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.
the
png
files below should be in./test/image/baselines/
not./test/image/mocks/