Skip to content

Colorscale opacity #422

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 5 commits into from
Apr 15, 2016
Merged

Colorscale opacity #422

merged 5 commits into from
Apr 15, 2016

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented Apr 13, 2016

The d3 color interpolation only supports rgb and not rgba, but we can use d3's object interpolation, to go between channel values for colors and fairly cleanly get opacity support on colorscales.

@timelyportfolio
Copy link
Contributor

not sure that it matters for now, but just in case https://github.com/d3/d3-interpolate/releases/tag/v0.5.2 supports opacity interpolation

@mdtusz
Copy link
Contributor Author

mdtusz commented Apr 13, 2016

Definitely good to know for when we go the modular route!

@@ -26,18 +26,20 @@ module.exports = function makeScaleFunction(scl, cmin, cmax) {
for(var i = 0; i < N; i++) {
si = scl[i];
domain[i] = cmin + si[0] * (cmax - cmin);
range[i] = si[1];
range[i] = tinycolor(si[1]).toRgb();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brilliant ✨

@etpinard
Copy link
Contributor

@mdtusz scatter3d, scattergeo choropleth and scattergl use to same code path to generate color scale functions, Could you check (manually, no need to add tests) that they work as expected?

Moreover, should we add rgba support for 2D color scales (e.g. for heatmap and contour) too (cc @tbreloff ) ? I can't come up with a good use case for this. It might now be worth the trouble. But, in that case we should document this behavior in the colorscale attribute description.

@mdtusz
Copy link
Contributor Author

mdtusz commented Apr 13, 2016

I could see it being useful in the future for contours laid overtop a map or geo outline, but it may not be worth it until we confirm that we will be adding support for that.

@n-riesco
Copy link
Contributor

Related #323 ?

@mdtusz
Copy link
Contributor Author

mdtusz commented Apr 14, 2016

Yes - this is the fix for that. I discovered this affects colorbars as well so this will require more work before it's ready for a full review.

@mdtusz mdtusz force-pushed the colorscale-opacity branch from a98cc44 to 0fe718d Compare April 14, 2016 22:15
})
.style('fill',fillcolormap(d));
height: Math.max(d3.max(z)-d3.min(z),2),
fill: opaqueColor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little hacky, but the alternative will require a substantial amount of work refactoring the colorbar component so it can use native svg gradients.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with this.

But to make sure we don't forget about this hack, could you write an issue about refactoring colorbar/draw.js , possibly using SVG gradients.

@mdtusz
Copy link
Contributor Author

mdtusz commented Apr 15, 2016

The small fix in the colorbar module will allow transparent colors to be used, but the colorbar will still display fully opaque.

@@ -10,6 +10,7 @@
'use strict';

var d3 = require('d3');
var tc = require('tinycolor2');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 we've been using var tinycolor = require('tinycolor2'); in other files. Let's stay consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh whoops - there's a few places with var tc = tinycolor('rgb(1,2,3)'); that I was head-referencing.

Copy link
Contributor

@etpinard etpinard Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right:

image

var tinycolor = require('tinycolor2'); is the winner by a big margin though:"

image

Wanna change the other var tc too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scratch that comment ⏫

those var tc refer to tinycolor output, not ref to the tinycolor module. No change require.

@etpinard
Copy link
Contributor

💃 after that 1 🐄

@mdtusz mdtusz merged commit 688639f into master Apr 15, 2016
@mdtusz mdtusz deleted the colorscale-opacity branch April 15, 2016 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants