-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Colorscale opacity #422
Changes from all commits
99d3fb8
0e41ea1
e645b1c
0fe718d
5518bef
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 |
---|---|---|
|
@@ -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(); | ||
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. brilliant ✨ |
||
} | ||
|
||
var sclFunc = d3.scale.linear() | ||
.domain(domain) | ||
.interpolate(d3.interpolateRgb) | ||
.interpolate(d3.interpolateObject) | ||
.range(range); | ||
|
||
return function(v) { | ||
if(isNumeric(v)) { | ||
var sclVal = Lib.constrain(v, cmin, cmax); | ||
return sclFunc(sclVal); | ||
var sclVal = Lib.constrain(v, cmin, cmax), | ||
colorObj = sclFunc(sclVal); | ||
|
||
return tinycolor(colorObj).toRgbString(); | ||
} | ||
else if(tinycolor(v).isValid()) return v; | ||
else return Color.defaultLine; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"y": [ | ||
5, | ||
5, | ||
5, | ||
5 | ||
], | ||
"mode": "markers", | ||
"marker": { | ||
"size": 40, | ||
"colorscale": [ | ||
[ | ||
0, | ||
"rgb(255,0.0,0.0)" | ||
], | ||
[ | ||
1, | ||
"rgba(0.0,0.0,255,0.5)" | ||
] | ||
], | ||
"color": [ | ||
0, | ||
1, | ||
2, | ||
3 | ||
], | ||
"cmin": 0, | ||
"cmax": 3 | ||
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. I'm curious to see how the colorbar looks in this case. Could you add a color bar to this mock? Adding |
||
}, | ||
"uid": "07bab4" | ||
} | ||
], | ||
"layout": { | ||
"title": "Scatter Plot with a Color Dimension", | ||
"xaxis": { | ||
"range": [ | ||
-0.271356783919598, | ||
3.271356783919598 | ||
], | ||
"autorange": true | ||
}, | ||
"yaxis": { | ||
"type": "linear", | ||
"range": [ | ||
4, | ||
6 | ||
], | ||
"autorange": true | ||
}, | ||
"height": 450, | ||
"width": 1100, | ||
"autosize": true | ||
} | ||
} |
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.
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.
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.
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.