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)
- Feature Request: Remove label gap in treemap
- Adding a negative `zorder` to one scatter trace could impact drawing order of other scatter traces and put all of them behind bars!
- Consolidate and add deprecation notice to figure factory
- Unified hover on splom shows duplicate point when setting `hoversubplots: "axis"`
- hoversubplots="axis" with hovermode="x" on stacked traces, shows x-axis label on first trace
- Feature Request: GeoJSON Layer Display
- Handle empty data in heatmaps
- Documentation for heatmap, boxplot, etc
- different spacing between tick labels and axis title with multi line text
- Colorbar Orientation Change Causes Render Issue
- Support `text-shadow` in SVG text
- Support `text-overflow` in SVG text
- Support `user-select` text from the graph elements HOT 2
- Clickmode "event+select" activated and Clicking outside of Graph calls onUpdate incorrectly HOT 1
- how can we set tick for bar
- Need help with multiple axes and subplots
- Hovertemplate use html tag is not working
- [FR] Change the height of the legend graphic (specifically for fill)
- Plotly-basic.js + table HOT 2
- Display tooltips on zero value bars HOT 2
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.