-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add color modifying expressions #5676
Comments
Let's broaden this to cover other color operations we may want -- I think it makes sense to consider the whole set together as we decide on how to add these. As @davidtheclark mentioned previously, the CSS color modifying spec proposal might be good inspiration: https://drafts.csswg.org/css-color/#modifying-colors |
saturate
and desaturate
expression color functions
While this is getting implemented, here is the workaround expression to implement desaturate with graying, i.e. it decreases the color value and makes the color more mid gray. "text-color": [
"let",
"rgba", ["to-rgba", ["to-color", ["get", "color_property"]]],
["let",
"r", ["number", ["*", 255, ["at", 0, ["var", "rgba"]]]],
"g", ["number", ["*", 255, ["at", 1, ["var", "rgba"]]]],
"b", ["number", ["*", 255, ["at", 2, ["var", "rgba"]]]],
"a", ["number", ["at", 3, ["var", "rgba"]]],
["let",
"avg", ["+", ["*", 0.299, ["var", "r"]], ["*", 0.587, ["var", "g"]], ["*", 0.114, ["var", "b"]]],
["let",
"desat_r", ["+", ["*", 0.4 , ["var", "avg"]], ["*", 0.4 , 128], ["*", 0.2 , ["var", "r"]]],
"desat_g", ["+", ["*", 0.4 , ["var", "avg"]], ["*", 0.4 , 128], ["*", 0.2 , ["var", "g"]]],
"desat_b", ["+", ["*", 0.4 , ["var", "avg"]], ["*", 0.4 , 128], ["*", 0.2 , ["var", "b"]]],
["rgba", ["var", "desat_r"], ["var", "desat_g"], ["var", "desat_b"], ["var", "a"]]
]
]
]
] |
Woah, thanks for sharing @mkv123 ! Looking at this, I'm seeing a bug in our |
Looking over the
So increasing the saturation by 10 percentage points would be This translation:
An alternative model is http://lesscss.org/functions/#color-operations. |
The proposal in #5676 (comment) adds 32 new operators with five distinct syntaxes. It feels like the operator name is being turned into a mini-language, whereas the structured expression syntax exists because we didn’t want to stuff a mini-language inside a string (mapbox/mapbox-gl-style-spec#362 (comment)). What if we add a single new operator that applies a “color transform” or “color filter” to a color? A color transform could take the form of an object specifying various parameters for the transformation. |
I have the opposite take, @1ec5 -- stuffing all of the potential color operations inside of a single operator with an object-based parameterization system feels like the sort of meta syntax we're aiming to avoid, while extending the language with additional operators is what we explicitly designed for. (I'm not sure what you mean by "five distinct syntaxes" -- as I see it, my proposal doesn't introduce any new syntax.) I do think that the |
@jfirebaugh: Why not pre-parse the arguments, in a sense, by making them items in the array? Instead of I was looking through the spec for something similar that exists and the closest I found was |
The major difference is that the type signature of In contrast, the number and types of arguments to color operators vary. This would make a single "uber-operator" difficult to implement and document. |
In #5676 (comment), I was thinking of |
I just wanted to see if there has been any movement on this. I'm currently working on a visualization where the missing piece seems to be the ability to subtract saturation from HSL colors from layers beneath, and I haven't had a lot of success finding what I'm looking for in the official documentation. |
@audaciouscode This is not on our roadmap at this time. We have a general interest in extending the expressions system over time but balance that against other necessary work. I'd suggest reaching out to Mapbox Support if you have a specific example as they may be able to help provide an alternate implementation. |
mapbox-gl-js version: 0.42.0
Problem
Developers want to use GL expressions for common color operations. A common use case is to indicate feature selection on a hover or click event of a feature by changing the color saturation.
There are no color functions in Expressions that can calculate changes in colors without using a third-party library such as chroma.js or the built-in color-space interpolations in GL JS Style Spec today.
Proposal
Add two new color expressions:
cc @anandthakker
The text was updated successfully, but these errors were encountered: