Comments (2)
Bug confirmed. Thanks
from plotly.js.
Hello, I made a quick-and-dirty fix for this. This may be useful for someone while we wait for the real fix.
I changed plotly.js/src/traces/surface/convert.js
by adding the following code to the update
function of SurfaceTrace
:
// Add the following code just before:
// //Save data
// this.data = data;
//Workaround for issue: https://github.com/plotly/plotly.js/issues/86
//Determining the original bounds.
var rzmin = 0.0;
var rzmax = 1.0;
if(z.length>0 && z[0].length>0){
rzmin = z[0][0];
rzmax = z[0][0];
}
for (var i = 0; i < z.length; i++) {
for (var j = 0; j < z[i].length; j++) {
rzmin = Math.min(rzmin,z[i][j]);
rzmax = Math.max(rzmax,z[i][j]);
}
}
//Rescale colormap indices to account for zmax and zmin.
colormap.map(function(d){
d.index = ((d.index)*(data.zmax-data.zmin)+data.zmin-rzmin)/(rzmax-rzmin);
return d;
});
//Simple color linear interpolation function.
function interpolateColors(torgba,fromrgba,fromIndex,toIndex,desired){
var m = (desired-fromIndex)/(toIndex-fromIndex);
var r = m*(torgba[0]-fromrgba[0])+fromrgba[0];
var g = m*(torgba[1]-fromrgba[1])+fromrgba[1];
var b = m*(torgba[2]-fromrgba[2])+fromrgba[2];
var a = m*(torgba[3]-fromrgba[3])+fromrgba[3];
return [r,g,b,a];
}
var lastIndexLEZero = false;
var newColormap = [];
var hasZero = false;
var hasOne = false;
for (var i = 0; i < colormap.length; i++) {
if(colormap[i].index<=0){
lastIndexLEZero = true;
}else{
//Interpolates for index=0.0.
if(lastIndexLEZero){
var torgba = colormap[i].rgb;
var fromrgba = colormap[i-1].rgb;
var toIndex = colormap[i].index;
var fromIndex = colormap[i-1].index;
var intrgba = interpolateColors(torgba,fromrgba,fromIndex,toIndex,0.0);
newColormap.push({index:0.0, rgb : intrgba});
lastIndexLEZero=false;
hasZero=true;
}
//Interpolates for index=1.0.
if(colormap[i].index>=1.0){
var torgba = colormap[i].rgb;
var fromrgba = colormap[i-1].rgb;
var toIndex = colormap[i].index;
var fromIndex = colormap[i-1].index;
var intrgba = interpolateColors(torgba,fromrgba,fromIndex,toIndex,1.0);
newColormap.push({index:1.0, rgb : intrgba});
hasOne=true;
break;
}else{
newColormap.push(colormap[i]);
}
}
}
//If endpoints are missing, add them.
if(!hasZero){
newColormap.unshift({index:0.0, rgb : newColormap[0].rgb});
}
if(!hasOne){
newColormap.push({index:1.0, rgb : newColormap[newColormap.length-1].rgb});
}
colormap=newColormap;
// Continues with:
// //Save data
// this.data = data;
// ...
What I did was rescale the colormap to [zmin,zmax] range, while also clamping the indices between 0 and 1.0. I tried, without success, to change the exported colormap
function, but it became troublesome to carry zmin, zmax and the original bounds along all the way down to the texture generation. This may introduce more bugs, but seems to work for various surfaces and colormaps.
from plotly.js.
Related Issues (20)
- Mismatch between legend and line colors when using uppercase css colors HOT 1
- Item toggle behavior when using multiple legends HOT 8
- insiderange on multiple overlaid axes edge case
- [Feature Request] Adding a Button to Copy Image to Clipboard HOT 1
- BUG: standoff causes axis title position to break if no tick labels
- Shapes - fill to infinity/-infinity
- Adding a dendrogram to heatmaps
- Smith Chart (scattersmith) pan & zoom functionality HOT 2
- axes range not working. Range is +-1, data is 0->1.6e10 HOT 3
- ScatterGL throws ` TypeError: r[v] is undefined` when using frames HOT 1
- Clicks are sometimes missed with clickmode layout key HOT 4
- Tooltip pointer (triangle) not correctly positioned with hovermode 'x'
- Plotly chart conflict with touchstart / touchmove event to scroll smartphone screen HOT 1
- [BUG] Rangeslider won't reset after zooming out HOT 1
- Inconsistent behavior when providing an array of marker sizes in "markers" mode on scatter3D
- hoverdistance broken in 3D scatter plots; hover radius vs click radius?
- `scattergl` line plots no longer working after upgrading to 2.29.1 HOT 3
- Combining rangemode tozero and tickformat set to "," produces unexpected results
- REOPENING BUG - pie chart hover label hidden
- Hoverlabel overlaps each other
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotly.js.