-
Notifications
You must be signed in to change notification settings - Fork 8.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
[Lens] Categorical color palettes #75309
Conversation
…workspace_panel_wrapper.scss Co-authored-by: Caroline Horn <[email protected]>
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 tested this in Chrome and reviewed the code. I have left a few comments about the code, and I found one bug that I couldn't identify the cause of. The bug is:
- Add any saved Lens vis to canvas
- Edit the expression by adding an invalid palette, something like
palette={}
. This will cause an error stateCan not cast null to palette
- Delete the invalid palette and the visualization won't update, the console shows
Embeddable has been destroyed
at Embeddable.updateInput (embeddable.tsx:134)
```
'#F1932D', | ||
'#E8601C', | ||
'#DC050C', | ||
]; |
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 choice of palette for the fallback doesn't make a lot of sense to me- why not default to EUI, or throw an error when missing a palette definition?
I worry that we could get stuck with a palette that can never be changed, similar to the 7-color default vislib palette. Also, the name of the palette here is Paul Tol 14
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 done for BWC with Canvas. The palette
function is only used by canvas and is already in use there (with these defaults). We can think about changing this with 8.0
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 see, can you add a code comment about this?
src/plugins/charts/common/palette.ts
Outdated
params: { | ||
help: i18n.translate('charts.functions.systemPalette.args.paramsHelpText', { | ||
defaultMessage: 'Palette specific params of the palette', | ||
}), |
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 don't understand what this is supposed to contain- or even what the datatype is. Do we need this?
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.
It's not used right now, but this is the place system palettes would use that to serialize custom params. E.g.
{system_palette id="myFancyPalette" params={fancy_palette_params somethingCustom=true }}
. We can also remove it for now if you think that would be better.
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.
My preference would be to remove it until needed.
import { LegacyColorsService } from '../legacy_colors'; | ||
|
||
function buildRoundRobinCategoricalWithMappedColors(): Omit<PaletteDefinition, 'title'> { | ||
const colors = euiPaletteColorBlind({ rotations: 2 }); |
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 agree that increasing the number of EUI colors from 10 to 20 is helpful for medium-size charts, but have we showed this to others to confirm?
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 discussed this approach with @AlonaNadler
x-pack/plugins/canvas/canvas_plugin_src/functions/external/saved_lens.ts
Outdated
Show resolved
Hide resolved
@wylieconlon Thanks for the review - I either fixed your comments in code are answered to the comments. I checked the bug but it doesn't seem like this is caused by my changes. I did the same with the visualize embeddable and it causes the same problem there (embeddable destroyed). I think it makes sense to open a separate bug for this. |
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.
Thanks for the updates, did not test again but LGTM
'#F1932D', | ||
'#E8601C', | ||
'#DC050C', | ||
]; |
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 see, can you add a code comment about this?
src/plugins/charts/common/palette.ts
Outdated
params: { | ||
help: i18n.translate('charts.functions.systemPalette.args.paramsHelpText', { | ||
defaultMessage: 'Palette specific params of the palette', | ||
}), |
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.
My preference would be to remove it until needed.
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.
Hey, @flash1293. This looks great! I left one small comment below to use the compressed form style for the color palette picker.
Otherwise, I just had one question regarding adding Lens visualizations to Canvas workpads. I noticed that all visualizations added to Canvas workpads had transparent backgrounds by default, except for Lens visualizations (which had a white background). Is this intentional? Not sure if part of this PR, but thought I'd ask.
})} | ||
> | ||
<> | ||
<EuiColorPalettePicker |
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.
EuiColorPalettePicker
requires a prop of compressed
in order to be displayed in the same compressed style as the rest of the form.
@MichaelMarcialis Good point. It's not a side effect of this PR, but definitely something we should fix. Could you open a separate issue? |
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 have some feedback, but approving to unblock.
name: string; | ||
params?: T; | ||
} | ||
export const defaultCustomColors = [ |
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.
export const defaultCustomColors = [ | |
// This set of defaults originated in Canvas, which, at present, is the primary | |
// consumer of this function. Changing this default requires a change in Canvas | |
// logic, which would likely be a breaking change in 7.x. | |
export const defaultCustomColors = [ |
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.
Ah, forgot about that, thanks for the great suggestion!
import { FunctionHelp } from '../function_help'; | ||
import { FunctionFactory } from '../../../types'; | ||
import { Legend } from '../../../types'; | ||
import { CSS, FONT_FAMILY, FONT_WEIGHT, BOOLEAN_FALSE } from '../../constants'; | ||
|
||
export const help: FunctionHelp<FunctionFactory<typeof pie>> = { | ||
export const help: FunctionHelp<FunctionFactory<ReturnType<typeof pieFunctionFactory>>> = { |
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.
nit: this feels very dense... might be nice to shorten this to a common type? Probably beyond the scope of this PR, though.
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.
Good point, I added FunctionFactoryHelp
to function_help.ts
} | ||
|
||
export function pieFunctionFactory( | ||
initialize: InitializeArguments |
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 think it makes more sense to pass the Palette Service to this function, rather than InitializeArguments
. The contract is much more explicit.
Thanks for the feedback! @AlonaNadler answers to your questions:
Great catch, that's a bug. Should be fixed now.
I think that's caused by series not being available on all buckets. It's not caused by this PR, could you open an elastic-charts issue for this?
Yes, working on that separately. It will also be part of 7.11
The color is assigned based on the inner ring, then lightened up for the outer rings (like it's working right now, didn't change that behavior). Once we implement color sync for Lens (#81976), we can decide whether we want to color by value on the outer layers as well like visualize is doing it today. |
LGTM. Tested in Safari, it's working really well! |
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]@kbn/optimizer bundle module count
async chunk count
async chunks size
distributable file count
page load bundle size
History
To update your PR or re-run it, just comment with: |
This PR implements a general palette service in the
charts
plugin an exposes it in Lens to be able to pick palettes there.This PR roughly contains three separate pieces which are linked to each other but can be reviewed separately:
Canvas changes
palette
definition to thecharts
pluginpalette
expression data type togetColorsFromPalette
) inplot
andpie
functions into thecharts
plugin (part of the "custom" plugin)plot
andpie
functions into public plugin so they can depend on the public contract of thecharts
plugin to pull in palette logicCharts changes
palette
andsystem_palette
- both produce apalette
data type (palette is a shortcut function for the "custom" palette used in canvas):charts.palettes.getPalettes()
PaletteDefinition
, featuring functions for serializing it to the expression, a getter for an array of colors and a getter for an individual colors which gets a configuration passed indefault
: EUI palette, differentiating between behind text and regular palette - assigned by position of the current serieskibana_palette
: Using the vislib color assignment by series name only (will sync up with vislib charts)warm
/cool
/positive
/negative
/grey
/status
/temperature
/complimentary
: Assigned by position of the current series, using full spectrum of the palettecustom
: Using former canvas palette logic based on chrome-js or round-robin assignmentLens changes
availablePalettes
getMainPalette
to return current main palette based on state, and an optional parameter oninitialize
andgetSuggestions
to pass it into another chart type - this is the way to hand over a palette from one chart to another one. A visualization can use multiple palettes internally