Skip to content

Handle colorscale with transparent colors in surface traces #5166

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

Merged
merged 6 commits into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"gl-select-box": "^1.0.4",
"gl-spikes2d": "^1.0.2",
"gl-streamtube3d": "^1.4.1",
"gl-surface3d": "^1.5.2",
"gl-surface3d": "git://github.com/gl-vis/gl-surface3d.git#77c2db23f81ba994047f82705afcfcc0d897e154",
"gl-text": "^1.1.8",
"glslify": "^7.1.1",
"has-hover": "^1.0.1",
Expand Down
11 changes: 4 additions & 7 deletions src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,19 @@ function formatColor(containerIn, opacityIn, len) {
return colorOut;
}

function parseColorScale(cont, alpha) {
if(alpha === undefined) alpha = 1;

function parseColorScale(cont) {
var cOpts = Colorscale.extractOpts(cont);

var colorscale = cOpts.reversescale ?
Colorscale.flipScale(cOpts.colorscale) :
cOpts.colorscale;
var colorscale = cOpts.colorscale;
if(cOpts.reversescale) colorscale = Colorscale.flipScale(cOpts.colorscale);

return colorscale.map(function(elem) {
var index = elem[0];
var color = tinycolor(elem[1]);
var rgb = color.toRgb();
return {
index: index,
rgb: [rgb.r, rgb.g, rgb.b, alpha]
rgb: [rgb.r, rgb.g, rgb.b, rgb.a]
};
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ proto.update = function(data) {
var sceneLayout = scene.fullSceneLayout;
var surface = this.surface;
var alpha = data.opacity;
var colormap = parseColorScale(data, alpha);
var colormap = parseColorScale(data);
var scaleFactor = scene.dataScale;
var xlen = data.z[0].length;
var ylen = data._ylength;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion test/image/compare_pixels_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ if(allMock || argv.filter) {
allMockList = allMockList.filter(function(mockName) {
var cond = !(
mockName === 'font-wishlist' ||
mockName === 'treemap_with-without_values' ||
mockName === 'gl3d_surface-heatmap-treemap_transparent-colorscale' ||
mockName.indexOf('mapbox_') !== -1
);
if(!cond) console.log(' -', mockName);
Expand All @@ -104,7 +106,10 @@ var FLAKY_LIST = [
'treemap_coffee',
'treemap_textposition',
'treemap_sunburst_marker_colors',
'treemap_with-without_values',
'gl3d_surface-lighting',
'gl3d_surface_contour_start-end-size',
'gl3d_directions-streamtube1',
'gl3d_traces-with-opacity',
];

console.log('');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"data": [
{
"type": "treemap",
"labels": [
"Alpha",
"Bravo",
"Charlie",
"Delta",
"Echo",
"Foxtrot",
"Golf",
"Hotel",
"India",
"Juliet",
"Kilo",
"Lima",
"Mike",
"November",
"Oscar",
"Papa",
"Quebec",
"Romeo",
"Sierra",
"Tango",
"Uniform",
"Victor",
"Whiskey",
"X ray",
"Yankee",
"Zulu"
],
"parents": [
"",
"Alpha",
"Alpha",
"Charlie",
"Charlie",
"Charlie",
"Foxtrot",
"Foxtrot",
"Foxtrot",
"Foxtrot",
"Juliet",
"Juliet",
"Juliet",
"Juliet",
"Juliet",
"Oscar",
"Oscar",
"Oscar",
"Oscar",
"Oscar",
"Oscar",
"Uniform",
"Uniform",
"Uniform",
"Uniform",
"Uniform",
"Uniform"
],
"level": "Juliet",
"count": "leaves+branches",
"textinfo": "label",
"insidetextorientation": "horizontal",
"marker": {
"line": {
"color": "#777"
},
"colorscale": [
[0, "rgba(0,0,255,1)"],
[0.5, "rgba(0,255,0,0.0)"],
[1, "rgba(255,0,0,1)"]
],
"showscale": false
},
"domain": {
"x": [0, 0.3]
}
},
{
"type": "heatmap",
"zsmooth": "best",
"coloraxis": "coloraxis",
"contours": {
"z": {
"show": true
}
},
"x": [0, 0.25, 0.5, 0.75, 1],
"y": [0, 0.25, 0.5, 0.75, 1],
"z": [
[0, 0, 0, 0, 0],
[0, 0.1, 0.8, 0.7, 0],
[0, 0.2, 0, 0.6, 0],
[0, 0.3, 0.4, 0.5, 0],
[0, 0, 0, 0, 0]
]
},
{
"type": "surface",
"coloraxis": "coloraxis",
"contours": {
"z": {
"show": true
}
},
"x": [0, 0.25, 0.5, 0.75, 1],
"y": [0, 0.25, 0.5, 0.75, 1],
"z": [
[0, 0, 0, 0, 0],
[0, 0.1, 0.8, 0.7, 0],
[0, 0.2, 0, 0.6, 0],
[0, 0.3, 0.4, 0.5, 0],
[0, 0, 0, 0, 0]
]
}
],
"layout": {
"width": 1000,
"height": 350,
"title": {
"text": "treemap, heatmap & surface plots with transparent colorscale"
},
"coloraxis": {
"colorscale": [
[0, "rgba(0,0,255,1)"],
[0.5, "rgba(0,255,0,0.0)"],
[1, "rgba(255,0,0,1)"]
]
},
"margin": {
"t": 75,
"l": 25,
"r": 25,
"b": 25
},
"xaxis": {
"domain": [0.35, 0.65]
},
"scene": {
"domain": {
"x": [0.7, 1]
},
"camera": {
"eye": {
"x": 0,
"y": 0,
"z": 2
},
"up": {
"x": 0,
"y": 1,
"z": 0
}
}
}
}
}
2 changes: 2 additions & 0 deletions test/jasmine/tests/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ var list = [
'gl3d_surface_transparent-with-contours',
'gl3d_surface-circular-colorscale',
'gl3d_surface-circular-opacityscale',
'gl3d_surface-heatmap-treemap_transparent-colorscale',
'gl3d_surface-lighting',
'gl3d_tetrahedra',
'gl3d_text-weirdness',
Expand Down Expand Up @@ -1614,6 +1615,7 @@ figs['gl3d_surface_opacity_match_mesh3d'] = require('@mocks/gl3d_surface_opacity
figs['gl3d_surface_transparent-with-contours'] = require('@mocks/gl3d_surface_transparent-with-contours');
figs['gl3d_surface-circular-colorscale'] = require('@mocks/gl3d_surface-circular-colorscale');
figs['gl3d_surface-circular-opacityscale'] = require('@mocks/gl3d_surface-circular-opacityscale');
// figs['gl3d_surface-heatmap-treemap_transparent-colorscale'] = require('@mocks/gl3d_surface-heatmap-treemap_transparent-colorscale');
// figs['gl3d_surface-lighting'] = require('@mocks/gl3d_surface-lighting');
figs['gl3d_tetrahedra'] = require('@mocks/gl3d_tetrahedra');
figs['gl3d_text-weirdness'] = require('@mocks/gl3d_text-weirdness');
Expand Down