Dashboard-level chart palette
A dashboard names the data colours its charts draw with: an ordered, distinct
subset of the `--chart-1…5` ramp, stored on the settings channel that already
carries `theme` and `locked`. No backend or client change — `SettingDef.value`
is free-form and a name this build does not wire up is left alone rather than
refused.
Naming none is the whole ramp, which resolves to the identical token per
series as the `--chart-${(index % 5) + 1}` charts drew with before, so every
existing dashboard is unaffected. `palette.check.ts` asserts that equivalence
rather than trusting it.
Distinct slots, not free assignment with repeats: only slot 1 against slot 5
clears 3:1 within the ramp, so two traces on one slot could not be told apart.
Status colour is deliberately outside the palette — a fault is `--destructive`
because of what it means, not because of where it sits.
The provider is mounted by the editor as well as the view, so picking a
palette repaints the charts beside the panel instead of describing them.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
import type { DashboardDef_Output, SettingDef } from "@/client"
|
||||
import { DEFAULT_PALETTE, paletteOf } from "@/components/Common/UplotChart"
|
||||
import { useLiveValue } from "@/components/Flow/liveStore"
|
||||
|
||||
/**
|
||||
@@ -35,7 +36,7 @@ export const SETTING_DTYPES: Record<string, string> = {
|
||||
}
|
||||
|
||||
/** The settings this build actually wires up. */
|
||||
export type SettingName = "theme" | "locked"
|
||||
export type SettingName = "theme" | "locked" | "palette"
|
||||
|
||||
/** What `theme` may be set to. `system` follows whatever the device says. */
|
||||
export const THEME_CHOICES = [
|
||||
@@ -99,6 +100,39 @@ export function useDashboardLocked(
|
||||
return useSetting(dashboard, "locked") === true
|
||||
}
|
||||
|
||||
const PaletteContext = createContext(DEFAULT_PALETTE)
|
||||
|
||||
/**
|
||||
* The data colours everything drawn under it uses.
|
||||
*
|
||||
* Mounted by the view *and* the editor: an editor showing the default ramp
|
||||
* while the panel beside it showed the dashboard's own palette would be a
|
||||
* preview that lies.
|
||||
*
|
||||
* Data colour only. A fault stays `--destructive` and a condition stays its
|
||||
* `ICON_COLORS` entry, because those name a state rather than tell one series
|
||||
* from another — a palette they followed could paint a failure the same blue
|
||||
* as a reading. Only the chart reads this today; a second consumer costs one
|
||||
* `usePalette()`.
|
||||
*/
|
||||
export function PaletteProvider({
|
||||
dashboard,
|
||||
children,
|
||||
}: {
|
||||
dashboard: DashboardDef_Output | undefined
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const palette = paletteOf(useSetting(dashboard, "palette"))
|
||||
return (
|
||||
<PaletteContext.Provider value={palette}>
|
||||
{children}
|
||||
</PaletteContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
/** The ramp slots the dashboard around this widget draws its data with. */
|
||||
export const usePalette = () => useContext(PaletteContext)
|
||||
|
||||
const LockedContext = createContext(false)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user