-
-
Notifications
You must be signed in to change notification settings - Fork 4.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 Tol palettes for accessibility #11914
Conversation
Hi @karen-poon thanks for your patience during busy end-of-year times. This PR looks fantastic. I only have a couple of comments/questions off the bat: Pale/Dark palettesThe Tol site has this to say about the Pale/Dark palettes:
By my understanding, these "palettes" are intended to be used by picking one of the few colors as a good text color (depending on light/dark background). This is opposed to how most palettes are used, which is to drive a colormapping that uses the entire palette. (I think the key difference of these palettes is captured in the sentence above "The colours are inherently not very distinct from each other", that definitely different from all the other palettes for colormapping) What do you think about renaming these two to stacked area exampleI have to be honest and the new stacked area PNG is pretty harsh to look at with that many layers of the rainbow palette stacked. What do you think about switching the palette to Muted or Sunset and/or reducing the number of stacked areas down to three or four? Namingcc @tcmetzger I think in the issue it was discussed to have the dictionary be named |
bokeh/palettes.py
Outdated
"Colorblind" : Colorblind | ||
tol = { | ||
"Bright": Bright, | ||
"HighContrast": cast(Dict[int, Any], HighContrast), |
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 not sure why this cast should be necessary, but I think it might be possible to fix this by explicitly specifying a type where HighContrast is defined, rather than a cast here (and I'd regard that as marginally 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.
Without the cast, mypy raises this error when I add HighContrast to dictionaries like accessible
or all_palettes
:
incompatible type "Dict[str, object]"; expected "Mapping[str, Dict[int, Tuple[str, ...]]]"
Mypy infers the type based on the first assignment it reads. We defined Bright = { 3: Bright3, 4: Bright4, 5: Bright5, 6: Bright6, 7: Bright7 }
, which has a type of Dict[int, Tuple[str, ...]]
. However, for HighContrast = { 3: HighContrast3 }
, it has a type of Dict[int, Tuple[str, str, str]]
, which mypy thinks they are different. So when we add HighContrast to accessible
and all_palettes
, it became Dict[str, object]
instead of Mapping[str, Dict[int, Tuple[str, ...]]]
.
The only way I can think of solving this is by casting... I can cast the original HighContrast with Dict[int, Tuple[str, ...]]
instead of Any
if that's preferred.? I'm a bit new to python too so it will be greatly appreciated if you could guide me on how to exactly solve 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.
I was suggesting something like this (but, I have not actually tried it)
HighContrast: Dict[int, Tuple[str, ...]] = { 3: HighContrast3 }
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! I think it's working :)
export const Bright4 = [0x4477aaff, 0xee6677ff, 0x228833ff, 0xccbb44ff] | ||
export const Bright5 = [0x4477aaff, 0xee6677ff, 0x228833ff, 0xccbb44ff, 0x66cceeff] | ||
export const Bright6 = [0x4477aaff, 0xee6677ff, 0x228833ff, 0xccbb44ff, 0x66cceeff, 0xaa3377ff] | ||
export const Bright7 = [0x4477aaff, 0xee6677ff, 0x228833ff, 0xccbb44ff, 0x66cceeff, 0xaa3377ff, 0xbbbbbbff] |
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.
In cases where the next palette only appends a value, one can use the following to reduce duplication and JS size:
export const Bright7 = [0x4477aaff, 0xee6677ff, 0x228833ff, 0xccbb44ff, 0x66cceeff, 0xaa3377ff, 0xbbbbbbff] | |
export const Bright7 = [...Bright6, 0xbbbbbbff] |
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.
Thank you for the suggestion. Should I apply this to all the other palettes? I saw some previously defined colours were also written with duplications.
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 would definitely be a good thing to apply this pattern everywhere that it can be applied
Thank you so much for reviewing my PR! Here are my thoughts:
|
@karen-poon Good questions!
|
@bryevdv I have performed the following updates:
Comments:
|
I expect sizes may differ slightly on different platforms, I would say let's see how things are once you can reduce the duplications, that might just solve things. If not we can bump the limit as needed. |
Unless there is anything more to address here, let's resolve code duplication in another PR. |
Thanks @karen-poon ! |
This PR is to add Paul Tol's palettes which can make Bokeh more accessible for people with colour vision deficiencies. This is also to follow up the discussion in the previously closed PR #11887.
Naming and Existing Palette
Colorblind
.palettes.py
, which aretol
andaccessible
. Theaccessible
dictionary would include bothtol
andColorblind
, whiletol
only includes Tol's palettes.bokehjs/src/lib/api/palettes.ts
.PRGn
andYlOrBr
, I have added a prefix to Tol’s:TolPRGn
andTolYlOrBr
. It is worth noting that Brewer and Tol uses slightly different colours for these 2 palettes, so this is the way we can distinguish them.rainbow
, I have named Tol's asTolRainbow
for now.Documentation
palettes.py
andpalettes.ts
.Colorblind
came from (https://jfly.uni-koeln.de/color/#pallet) to the page.tol
in the "Other Attributes" section so that people can know about such attribute's existence.Examples
I have updated the following examples into using the new accessible palettes (and those that appeared in the user guide). I have also updated the images of those appeared in the Gallery.
bar_colormapped.py
bar_colors.py
eclipse.py
image.py
stacked_area.py
Overview of the new palettes
*Quite a huge PR but please let me know if I have mistyped any colour codes or anything should be modified/added. Thank you!