Improve highlight colours

This commit is contained in:
Benji Grant 2023-06-09 16:18:06 +10:00
parent 25d029ba57
commit fee7122bfe
8 changed files with 30 additions and 13 deletions

View file

@ -16,6 +16,7 @@
"@microsoft/microsoft-graph-client": "^3.0.5", "@microsoft/microsoft-graph-client": "^3.0.5",
"@vercel/analytics": "^1.0.1", "@vercel/analytics": "^1.0.1",
"accept-language": "^3.0.18", "accept-language": "^3.0.18",
"chroma.ts": "^1.0.10",
"gapi-script": "^1.2.0", "gapi-script": "^1.2.0",
"hue-map": "^1.0.0", "hue-map": "^1.0.0",
"i18next": "^22.5.1", "i18next": "^22.5.1",

View file

@ -115,7 +115,7 @@ const AvailabilityEditor = ({
backgroundColor: ( backgroundColor: (
(!(mode.current === 'remove' && selecting.includes(cell.serialized)) && value.includes(cell.serialized)) (!(mode.current === 'remove' && selecting.includes(cell.serialized)) && value.includes(cell.serialized))
|| (mode.current === 'add' && selecting.includes(cell.serialized)) || (mode.current === 'add' && selecting.includes(cell.serialized))
) ? palette[1] : palette[0], ) ? palette[1].string : palette[0].string,
...cell.minute !== 0 && cell.minute !== 30 && { borderTopColor: 'transparent' }, ...cell.minute !== 0 && cell.minute !== 30 && { borderTopColor: 'transparent' },
...cell.minute === 30 && { borderTopStyle: 'dotted' }, ...cell.minute === 30 && { borderTopStyle: 'dotted' },
}} }}

View file

@ -113,8 +113,8 @@
45deg, 45deg,
transparent, transparent,
transparent 4.3px, transparent 4.3px,
rgba(0,0,0,.5) 4.3px, var(--highlight-color, rgba(0,0,0,.5)) 4.3px,
rgba(0,0,0,.5) 8.6px var(--highlight-color, rgba(0,0,0,.5)) 8.6px
); );
} }

View file

@ -79,6 +79,7 @@ const AvailabilityViewer = ({ times, timezone, people }: AvailabilityViewerProps
if (tempFocus) { if (tempFocus) {
peopleHere = peopleHere.filter(p => p === tempFocus) peopleHere = peopleHere.filter(p => p === tempFocus)
} }
const color = palette[tempFocus && peopleHere.length ? max : peopleHere.length]
return <div return <div
key={y} key={y}
@ -87,10 +88,11 @@ const AvailabilityViewer = ({ times, timezone, people }: AvailabilityViewerProps
(focusCount === undefined || focusCount === peopleHere.length) && highlight && (peopleHere.length === max || tempFocus) && peopleHere.length > 0 && styles.highlight, (focusCount === undefined || focusCount === peopleHere.length) && highlight && (peopleHere.length === max || tempFocus) && peopleHere.length > 0 && styles.highlight,
)} )}
style={{ style={{
backgroundColor: (focusCount === undefined || focusCount === peopleHere.length) ? palette[tempFocus && peopleHere.length ? max : peopleHere.length] : 'transparent', backgroundColor: (focusCount === undefined || focusCount === peopleHere.length) ? color.string : 'transparent',
'--highlight-color': color.highlight,
...cell.minute !== 0 && cell.minute !== 30 && { borderTopColor: 'transparent' }, ...cell.minute !== 0 && cell.minute !== 30 && { borderTopColor: 'transparent' },
...cell.minute === 30 && { borderTopStyle: 'dotted' }, ...cell.minute === 30 && { borderTopStyle: 'dotted' },
}} } as React.CSSProperties}
aria-label={peopleHere.join(', ')} aria-label={peopleHere.join(', ')}
onMouseEnter={e => { onMouseEnter={e => {
const cellBox = e.currentTarget.getBoundingClientRect() const cellBox = e.currentTarget.getBoundingClientRect()

View file

@ -39,7 +39,7 @@
45deg, 45deg,
transparent, transparent,
transparent 4.5px, transparent 4.5px,
rgba(0,0,0,.5) 4.5px, var(--highlight-color, rgba(0,0,0,.5)) 4.5px,
rgba(0,0,0,.5) 9px var(--highlight-color, rgba(0,0,0,.5)) 9px
); );
} }

View file

@ -8,7 +8,7 @@ interface LegendProps {
min: number min: number
max: number max: number
total: number total: number
palette: string[] palette: { string: string, highlight: string }[]
onSegmentFocus: (segment: number | undefined) => void onSegmentFocus: (segment: number | undefined) => void
} }
@ -29,7 +29,7 @@ const Legend = ({ min, max, total, palette, onSegmentFocus }: LegendProps) => {
{[...Array(max + 1 - min).keys()].map(i => i + min).map(i => {[...Array(max + 1 - min).keys()].map(i => i + min).map(i =>
<div <div
key={i} key={i}
style={{ flex: 1, backgroundColor: palette[i] }} style={{ flex: 1, backgroundColor: palette[i].string, '--highlight-color': palette[i].highlight } as React.CSSProperties}
className={highlight && i === max && max > 0 ? styles.highlight : undefined} className={highlight && i === max && max > 0 ? styles.highlight : undefined}
onMouseOver={() => onSegmentFocus(i)} onMouseOver={() => onSegmentFocus(i)}
/> />

View file

@ -1,4 +1,5 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import { color } from 'chroma.ts'
import { createPalette } from 'hue-map' import { createPalette } from 'hue-map'
import { useStore } from '/src/stores' import { useStore } from '/src/stores'
@ -7,8 +8,16 @@ import useSettingsStore from '/src/stores/settingsStore'
export const usePalette = (steps: number) => { export const usePalette = (steps: number) => {
const colormap = useStore(useSettingsStore, state => state.colormap) const colormap = useStore(useSettingsStore, state => state.colormap)
return useMemo(() => createPalette({ return useMemo(() =>
createPalette({
map: (colormap === undefined || colormap === 'crabfit') ? [[0, [247, 158, 0, 0]], [1, [247, 158, 0, 255]]] : colormap, map: (colormap === undefined || colormap === 'crabfit') ? [[0, [247, 158, 0, 0]], [1, [247, 158, 0, 255]]] : colormap,
steps, steps,
}).format(), [steps, colormap]) })
.format('rgba')
.map(([r, g, b, a]) => color(r, g, b, a / 255))
.map(c => ({
string: c.hex('rgba'),
highlight: c.luminance() > .5 ? c.darker().hex('rgba') : c.brighter().hex('rgba'),
})),
[steps, colormap])
} }

View file

@ -643,6 +643,11 @@ chalk@^4.0.0:
optionalDependencies: optionalDependencies:
fsevents "~2.3.2" fsevents "~2.3.2"
chroma.ts@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/chroma.ts/-/chroma.ts-1.0.10.tgz#2b965d8f2c2eee44d25072902e5787fe259d4565"
integrity sha512-0FOQiB6LaiOwoyaxP+a4d3sCIOSf7YvBKj3TfeQM4ZBb2yskRxe4FlT2P4YNpHz7kIB5rXsfmpyniyrYRRyVHw==
client-only@0.0.1: client-only@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1" resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"