[Lens] Categorical color functions #68330
Labels
enhancement
New value added to drive a business result
Feature:Lens
Team:Visualizations
Visualization editors, elastic-charts and infrastructure
Categorical coloring has many variations, and this issue will serve as a checklist of possible functionality to build. This issue will describe both the user perspective and how we will implement this behavior:
Defining a categorical color function
Defining the behavior of colors in terms of functions is the most flexible way to work with colors. If we want to define a simple color function that requires no configuration, we can. If we want to define a complex color function that needs a specific setup, we can do that too.
This approach is heavily based on @monfera's work on the
colorAccessorFn
property of the pie chart and treemap visualizations, but expressed in a way that is specific to our use case in Lens.Every color function returns a single color or "no color", given this input:
To explain why this is the shape of the categorical color function, we need to look at examples of different types of coloring that this function lets us do.
Keeping the Lens default color function
Lens has two default color functions today, for XY charts and for pie/treemap charts:
Using the name to assign custom colors
Another way of defining a color function is to assign specific values to specific series, such as what the Maps application does:
Assigning colors from an external service
One of the missing features in Lens is the ability to share colors with the dashboard. If we have a color function that takes the Name as input, then we can make this an option that the user can choose.
More possibilities
One of the most interesting color options that we haven't been able to do before is grouped coloring, and this type of color function allows it. One example of this is this palette, where each group gets a unique part of the spectrum:
Which functions should Lens provide users with by default?
What does this look like?
At various places in the UI, we will have a "color function picker" which is similar to a palette picker, but with extra options. The user will see the preview of the colors that would be used:
Because many of these functions will require additional arguments, this palette picker might be best implemented in an extensible way. For example, the "choose color by name" function requires the user to type a name, and would be best with an autocomplete.
Picking colors from the function
Once the user configures their color function, we need to actually call the function with the right information. There will be a hierarchy of color functions, and if any function lower in the hierarchy returns "no color" then we will use the higher level. This lets the user override the color function in specific cases, while keeping the overall feel. For example, the user could configure a grayscale palette except for the top ranked series.
It is up to the visualization to compile the necessary arguments, because the arguments depend on the structure of the data. We can use a lot of the same logic as the pie charts to do this.
The text was updated successfully, but these errors were encountered: