@lincyaw/aegis-ui 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"LineChart.js","sources":["../../../src/components/ui/LineChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport { type ChartColor, chartColorValue, niceTicks } from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './LineChart.css';\n\nexport interface LineChartPoint {\n x: number;\n y: number;\n}\n\nexport interface LineChartSeries {\n key: string;\n /** Written at the end of the line, with its last value. */\n label: string;\n color: ChartColor;\n points: LineChartPoint[];\n}\n\nexport interface LineChartMarker {\n key: string;\n x: number;\n color: ChartColor;\n /** Names the event in its tooltip. */\n label: string;\n}\n\nexport interface LineChartProps {\n series: LineChartSeries[];\n /** Names the chart for a screen reader. */\n label: string;\n /** False when the host supplies a separate series legend. */\n endLabels?: boolean;\n /** Names the horizontal axis, e.g. \"回合\". */\n xLabel?: string;\n /** The gridlines. Defaults to about five round values. */\n yTicks?: number[];\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n /** Where a replay's playhead is on the horizontal axis. */\n playhead?: number;\n /** Lets the reader click or use the arrow keys to move the playhead. */\n onSeek?: (x: number) => void;\n /** Events on the horizontal axis, e.g. a replay's key moments. */\n markers?: LineChartMarker[];\n /**\n * How far the lines are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, it shows its final state.\n */\n progress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst HEIGHT = 240;\nconst PAD_LEFT = 32;\nconst PAD_RIGHT = 8;\nconst PAD_TOP = 20;\nconst PAD_BOTTOM = 28;\nconst END_LABEL_GAP = 8;\nconst END_LABEL_LINE = 16;\nconst MARKER_RADIUS = 4;\n\n/**\n * Lines over a shared horizontal axis, labelled at their ends instead of\n * in a legend, with an optional playhead the reader can move.\n */\nexport function LineChart({\n series,\n label,\n endLabels = true,\n xLabel,\n yTicks,\n formatX = String,\n formatY = String,\n playhead,\n onSeek,\n markers = [],\n progress,\n className,\n}: LineChartProps): ReactElement {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const points = series.flatMap((line) => line.points);\n const xs = [...new Set(points.map((point) => point.x))].sort((a, b) => a - b);\n const cls = ['aegis-line-chart', className ?? ''].filter(Boolean).join(' ');\n if (width === 0 || xs.length === 0) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const xLo = xs[0];\n const xHi = xs[xs.length - 1];\n const values = points.map((point) => point.y);\n const ticks = yTicks ?? niceTicks(0, Math.max(...values, 1));\n const yHi = Math.max(...ticks, ...values);\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = HEIGHT - PAD_BOTTOM;\n const sx = (x: number): number =>\n left + (xHi > xLo ? (x - xLo) / (xHi - xLo) : 0) * (right - left);\n const sy = (y: number): number => bottom - (y / yHi) * (bottom - top);\n\n // The end labels stack upwards when two lines finish close together, so\n // the lowest stays where its line ends and none runs into the x axis.\n const ends = series\n .flatMap((line) => {\n const last = line.points[line.points.length - 1] as\n | LineChartPoint\n | undefined;\n return last === undefined ? [] : [{ line, last, y: sy(last.y) }];\n })\n .sort((a, b) => b.y - a.y);\n for (let i = 1; i < ends.length; i += 1) {\n if (ends[i - 1].y - ends[i].y < END_LABEL_LINE) {\n ends[i].y = ends[i - 1].y - END_LABEL_LINE;\n }\n }\n\n const nearestX = (x: number): number =>\n xs.reduce((best, candidate) =>\n Math.abs(candidate - x) < Math.abs(best - x) ? candidate : best,\n );\n const seekFromPointer = (event: MouseEvent<SVGRectElement>): void => {\n const box = event.currentTarget.getBoundingClientRect();\n const share = (event.clientX - box.left) / box.width;\n onSeek?.(nearestX(xLo + share * (xHi - xLo)));\n };\n const seekFromKey = (event: KeyboardEvent<SVGRectElement>): void => {\n const index = xs.indexOf(nearestX(playhead ?? xLo));\n const target: Record<string, number> = {\n ArrowLeft: index - 1,\n ArrowDown: index - 1,\n ArrowRight: index + 1,\n ArrowUp: index + 1,\n Home: 0,\n End: xs.length - 1,\n };\n if (event.key in target) {\n event.preventDefault();\n onSeek?.(xs[Math.min(Math.max(target[event.key], 0), xs.length - 1)]);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-line-chart__svg\"\n width={width}\n height={HEIGHT}\n viewBox={`0 0 ${width.toString()} ${HEIGHT.toString()}`}\n role={onSeek ? 'group' : 'img'}\n aria-label={label}\n >\n {ticks.map((tick) => (\n <g key={tick}>\n <line\n className=\"aegis-line-chart__grid\"\n x1={left}\n x2={right}\n y1={sy(tick)}\n y2={sy(tick)}\n />\n <text\n className=\"aegis-line-chart__tick\"\n x={left - END_LABEL_GAP}\n y={sy(tick)}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(tick)}\n </text>\n </g>\n ))}\n {series.map((line) => (\n <polyline\n key={line.key}\n className=\"aegis-line-chart__line\"\n pathLength={1}\n points={line.points\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n style={\n {\n stroke: chartColorValue(line.color),\n ...(progress === undefined\n ? {}\n : { '--aegis-line-chart-progress': progress }),\n } as CSSProperties\n }\n />\n ))}\n {endLabels &&\n ends.map(({ line, last, y }) => (\n <text\n key={line.key}\n className=\"aegis-line-chart__end-label\"\n x={right}\n y={y - END_LABEL_GAP}\n textAnchor=\"end\"\n style={{ fill: chartColorValue(line.color) }}\n >\n {`${line.label} ${formatY(last.y)}`}\n </text>\n ))}\n {playhead !== undefined && (\n <g>\n <line\n className=\"aegis-line-chart__playhead\"\n x1={sx(playhead)}\n x2={sx(playhead)}\n y1={top}\n y2={bottom}\n />\n <text\n className=\"aegis-line-chart__playhead-label\"\n x={sx(playhead)}\n y={top - END_LABEL_GAP / 2}\n textAnchor=\"middle\"\n >\n {formatX(playhead)}\n </text>\n </g>\n )}\n <text\n className=\"aegis-line-chart__tick\"\n x={left}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"start\"\n >\n {formatX(xLo)}\n </text>\n <text\n className=\"aegis-line-chart__tick\"\n x={right}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"end\"\n >\n {formatX(xHi)}\n </text>\n {xLabel !== undefined && (\n <text\n className=\"aegis-line-chart__tick\"\n x={(left + right) / 2}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"middle\"\n >\n {xLabel}\n </text>\n )}\n {onSeek && (\n <rect\n className=\"aegis-line-chart__seek\"\n x={left}\n y={top}\n width={right - left}\n height={bottom - top}\n role=\"slider\"\n tabIndex={0}\n aria-label={strings.replayPosition}\n aria-valuemin={xLo}\n aria-valuemax={xHi}\n aria-valuenow={playhead ?? xLo}\n aria-valuetext={formatX(playhead ?? xLo)}\n onClick={seekFromPointer}\n onKeyDown={seekFromKey}\n />\n )}\n {markers.map((marker) => (\n <circle\n key={marker.key}\n className=\"aegis-line-chart__marker\"\n cx={sx(marker.x)}\n cy={bottom}\n r={MARKER_RADIUS}\n style={{ fill: chartColorValue(marker.color) }}\n onClick={\n onSeek\n ? () => {\n onSeek(marker.x);\n }\n : undefined\n }\n >\n <title>{marker.label}</title>\n </circle>\n ))}\n </svg>\n </div>\n );\n}\n"],"names":["HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","END_LABEL_GAP","END_LABEL_LINE","MARKER_RADIUS","LineChart","series","label","endLabels","xLabel","yTicks","formatX","formatY","playhead","onSeek","markers","progress","className","strings","useStrings","wrapRef","useRef","width","useElementWidth","points","line","xs","point","a","b","cls","jsx","xLo","xHi","values","ticks","niceTicks","yHi","left","right","top","bottom","sx","x","sy","y","ends","last","i","nearestX","best","candidate","seekFromPointer","event","box","share","seekFromKey","index","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":3,"file":"LineChart.js","sources":["../../../src/components/ui/LineChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n useId,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport {\n type ChartColor,\n type ChartLineStyle,\n chartColorValue,\n chartLineDash,\n niceTicks,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './LineChart.css';\n\nexport interface LineChartPoint {\n x: number;\n y: number;\n}\n\nexport interface LineChartSeries {\n key: string;\n /** Written at the end of the line, with its last value. */\n label: string;\n color: ChartColor;\n lineStyle?: ChartLineStyle;\n points: LineChartPoint[];\n}\n\nexport interface LineChartMarker {\n key: string;\n x: number;\n color: ChartColor;\n /** Names the event in its tooltip. */\n label: string;\n}\n\nexport interface LineChartProps {\n series: LineChartSeries[];\n /** Names the chart for a screen reader. */\n label: string;\n /** False when the host supplies a separate series legend. */\n endLabels?: boolean;\n /** Names the horizontal axis, e.g. \"回合\". */\n xLabel?: string;\n /** The gridlines. Defaults to about five round values. */\n yTicks?: number[];\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n /** Where a replay's playhead is on the horizontal axis. */\n playhead?: number;\n /** Lets the reader click or use the arrow keys to move the playhead. */\n onSeek?: (x: number) => void;\n /** Events on the horizontal axis, e.g. a replay's key moments. */\n markers?: LineChartMarker[];\n /**\n * How far the lines are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, it shows its final state.\n */\n progress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst HEIGHT = 240;\nconst PAD_LEFT = 32;\nconst PAD_RIGHT = 8;\nconst PAD_TOP = 20;\nconst PAD_BOTTOM = 28;\nconst END_LABEL_GAP = 8;\nconst END_LABEL_LINE = 16;\nconst MARKER_RADIUS = 4;\n\n/**\n * Lines over a shared horizontal axis, labelled at their ends instead of\n * in a legend, with an optional playhead the reader can move.\n */\nexport function LineChart({\n series,\n label,\n endLabels = true,\n xLabel,\n yTicks,\n formatX = String,\n formatY = String,\n playhead,\n onSeek,\n markers = [],\n progress,\n className,\n}: LineChartProps): ReactElement {\n const strings = useStrings();\n const maskId = useId();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const points = series.flatMap((line) => line.points);\n const xs = [...new Set(points.map((point) => point.x))].sort((a, b) => a - b);\n const cls = ['aegis-line-chart', className ?? ''].filter(Boolean).join(' ');\n if (width === 0 || xs.length === 0) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const xLo = xs[0];\n const xHi = xs[xs.length - 1];\n const values = points.map((point) => point.y);\n const ticks = yTicks ?? niceTicks(0, Math.max(...values, 1));\n const yHi = Math.max(...ticks, ...values);\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = HEIGHT - PAD_BOTTOM;\n const sx = (x: number): number =>\n left + (xHi > xLo ? (x - xLo) / (xHi - xLo) : 0) * (right - left);\n const sy = (y: number): number => bottom - (y / yHi) * (bottom - top);\n\n // The end labels stack upwards when two lines finish close together, so\n // the lowest stays where its line ends and none runs into the x axis.\n const ends = series\n .flatMap((line) => {\n const last = line.points[line.points.length - 1] as\n | LineChartPoint\n | undefined;\n return last === undefined ? [] : [{ line, last, y: sy(last.y) }];\n })\n .sort((a, b) => b.y - a.y);\n for (let i = 1; i < ends.length; i += 1) {\n if (ends[i - 1].y - ends[i].y < END_LABEL_LINE) {\n ends[i].y = ends[i - 1].y - END_LABEL_LINE;\n }\n }\n\n const nearestX = (x: number): number =>\n xs.reduce((best, candidate) =>\n Math.abs(candidate - x) < Math.abs(best - x) ? candidate : best,\n );\n const seekFromPointer = (event: MouseEvent<SVGRectElement>): void => {\n const box = event.currentTarget.getBoundingClientRect();\n const share = (event.clientX - box.left) / box.width;\n onSeek?.(nearestX(xLo + share * (xHi - xLo)));\n };\n const seekFromKey = (event: KeyboardEvent<SVGRectElement>): void => {\n const index = xs.indexOf(nearestX(playhead ?? xLo));\n const target: Record<string, number> = {\n ArrowLeft: index - 1,\n ArrowDown: index - 1,\n ArrowRight: index + 1,\n ArrowUp: index + 1,\n Home: 0,\n End: xs.length - 1,\n };\n if (event.key in target) {\n event.preventDefault();\n onSeek?.(xs[Math.min(Math.max(target[event.key], 0), xs.length - 1)]);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-line-chart__svg\"\n width={width}\n height={HEIGHT}\n viewBox={`0 0 ${width.toString()} ${HEIGHT.toString()}`}\n role={onSeek ? 'group' : 'img'}\n aria-label={label}\n >\n {ticks.map((tick) => (\n <g key={tick}>\n <line\n className=\"aegis-line-chart__grid\"\n x1={left}\n x2={right}\n y1={sy(tick)}\n y2={sy(tick)}\n />\n <text\n className=\"aegis-line-chart__tick\"\n x={left - END_LABEL_GAP}\n y={sy(tick)}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(tick)}\n </text>\n </g>\n ))}\n {series.map((line) => (\n <g key={line.key}>\n {line.lineStyle &&\n line.lineStyle !== 'solid' &&\n progress !== undefined && (\n <mask\n id={`${maskId}-${line.key}`}\n maskUnits=\"userSpaceOnUse\"\n x={0}\n y={0}\n width={width}\n height={HEIGHT}\n >\n <polyline\n className=\"aegis-line-chart__line\"\n pathLength={1}\n points={line.points\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n style={\n {\n stroke: 'white',\n '--aegis-line-chart-progress': progress,\n } as CSSProperties\n }\n />\n </mask>\n )}\n <polyline\n className=\"aegis-line-chart__line\"\n pathLength={\n !line.lineStyle || line.lineStyle === 'solid' ? 1 : undefined\n }\n mask={\n line.lineStyle &&\n line.lineStyle !== 'solid' &&\n progress !== undefined\n ? `url(#${maskId}-${line.key})`\n : undefined\n }\n points={line.points\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n style={\n {\n stroke: chartColorValue(line.color),\n ...(line.lineStyle && line.lineStyle !== 'solid'\n ? {\n strokeDasharray: chartLineDash(line.lineStyle),\n strokeDashoffset: 0,\n }\n : {}),\n ...(progress === undefined\n ? {}\n : { '--aegis-line-chart-progress': progress }),\n } as CSSProperties\n }\n />\n </g>\n ))}\n {endLabels &&\n ends.map(({ line, last, y }) => (\n <text\n key={line.key}\n className=\"aegis-line-chart__end-label\"\n x={right}\n y={y - END_LABEL_GAP}\n textAnchor=\"end\"\n style={{ fill: chartColorValue(line.color) }}\n >\n {`${line.label} ${formatY(last.y)}`}\n </text>\n ))}\n {playhead !== undefined && (\n <g>\n <line\n className=\"aegis-line-chart__playhead\"\n x1={sx(playhead)}\n x2={sx(playhead)}\n y1={top}\n y2={bottom}\n />\n <text\n className=\"aegis-line-chart__playhead-label\"\n x={sx(playhead)}\n y={top - END_LABEL_GAP / 2}\n textAnchor=\"middle\"\n >\n {formatX(playhead)}\n </text>\n </g>\n )}\n <text\n className=\"aegis-line-chart__tick\"\n x={left}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"start\"\n >\n {formatX(xLo)}\n </text>\n <text\n className=\"aegis-line-chart__tick\"\n x={right}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"end\"\n >\n {formatX(xHi)}\n </text>\n {xLabel !== undefined && (\n <text\n className=\"aegis-line-chart__tick\"\n x={(left + right) / 2}\n y={HEIGHT - END_LABEL_GAP}\n textAnchor=\"middle\"\n >\n {xLabel}\n </text>\n )}\n {onSeek && (\n <rect\n className=\"aegis-line-chart__seek\"\n x={left}\n y={top}\n width={right - left}\n height={bottom - top}\n role=\"slider\"\n tabIndex={0}\n aria-label={strings.replayPosition}\n aria-valuemin={xLo}\n aria-valuemax={xHi}\n aria-valuenow={playhead ?? xLo}\n aria-valuetext={formatX(playhead ?? xLo)}\n onClick={seekFromPointer}\n onKeyDown={seekFromKey}\n />\n )}\n {markers.map((marker) => (\n <circle\n key={marker.key}\n className=\"aegis-line-chart__marker\"\n cx={sx(marker.x)}\n cy={bottom}\n r={MARKER_RADIUS}\n style={{ fill: chartColorValue(marker.color) }}\n onClick={\n onSeek\n ? () => {\n onSeek(marker.x);\n }\n : undefined\n }\n >\n <title>{marker.label}</title>\n </circle>\n ))}\n </svg>\n </div>\n );\n}\n"],"names":["HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","END_LABEL_GAP","END_LABEL_LINE","MARKER_RADIUS","LineChart","series","label","endLabels","xLabel","yTicks","formatX","formatY","playhead","onSeek","markers","progress","className","strings","useStrings","maskId","useId","wrapRef","useRef","width","useElementWidth","points","line","xs","point","a","b","cls","jsx","xLo","xHi","values","ticks","niceTicks","yHi","left","right","top","bottom","sx","x","sy","y","ends","last","i","nearestX","best","candidate","seekFromPointer","event","box","share","seekFromKey","index","target","jsxs","tick","chartColorValue","chartLineDash","marker"],"mappings":";;;;;;AAqEA,MAAMA,IAAS,KACTC,IAAW,IACXC,IAAY,GACZC,IAAU,IACVC,IAAa,IACbC,IAAgB,GAChBC,IAAiB,IACjBC,IAAgB;AAMf,SAASC,GAAU;AAAA,EACxB,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,SAAAC,IAAU;AAAA,EACV,UAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU,CAAA;AAAA,EACV,UAAAC;AAAA,EACA,WAAAC;AACF,GAAiC;AAC/B,QAAMC,IAAUC,EAAA,GACVC,IAASC,EAAA,GACTC,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,EAAgBH,CAAO,GAC/BI,IAASpB,EAAO,QAAQ,CAACqB,MAASA,EAAK,MAAM,GAC7CC,IAAK,CAAC,GAAG,IAAI,IAAIF,EAAO,IAAI,CAACG,MAAUA,EAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAACC,GAAGC,MAAMD,IAAIC,CAAC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MAAM;AACJ,cAAAA,EAAOmD,EAAO,CAAC;AAAA,YACjB,IACA;AAAA,YAGN,UAAA,gBAAAhC,EAAC,SAAA,EAAO,UAAAgC,EAAO,MAAA,CAAM;AAAA,UAAA;AAAA,UAdhBA,EAAO;AAAA,QAAA,CAgBf;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAEL;AAEJ;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("../../lib/chart.cjs");;/* empty css */const t=require("./linkComponent.cjs");function c({name:s,detail:a,color:l,to:i,linkComponent:r=t.DefaultLink,className:n}){return e.jsxs("span",{className:["aegis-series-label",n??""].filter(Boolean).join(" "),style:{"--aegis-series-label-color":o.chartColorValue(l)},children:[e.jsx("span",{className:"aegis-series-label__dot","aria-hidden":"true"}),i===void 0?e.jsx("span",{className:"aegis-series-label__name",children:s}):e.jsx(r,{to:i,className:"aegis-series-label__name aegis-series-label__name--link",children:s}),a!==void 0&&e.jsx("span",{className:"aegis-series-label__detail",children:a})]})}exports.SeriesLabel=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("../../lib/chart.cjs");;/* empty css */const c=require("./linkComponent.cjs");function d({name:s,detail:a,color:n,lineStyle:i,to:l,linkComponent:o=c.DefaultLink,className:t}){return e.jsxs("span",{className:["aegis-series-label",t??""].filter(Boolean).join(" "),style:{"--aegis-series-label-color":r.chartColorValue(n)},children:[i===void 0?e.jsx("span",{className:"aegis-series-label__dot","aria-hidden":"true"}):e.jsx("svg",{className:"aegis-series-label__line","aria-hidden":"true",viewBox:"0 0 32 10",children:e.jsx("line",{x1:0,x2:32,y1:5,y2:5,style:{strokeDasharray:r.chartLineDash(i)}})}),l===void 0?e.jsx("span",{className:"aegis-series-label__name",children:s}):e.jsx(o,{to:l,className:"aegis-series-label__name aegis-series-label__name--link",children:s}),a!==void 0&&e.jsx("span",{className:"aegis-series-label__detail",children:a})]})}exports.SeriesLabel=d;
2
2
  //# sourceMappingURL=SeriesLabel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SeriesLabel.cjs","sources":["../../../src/components/ui/SeriesLabel.tsx"],"sourcesContent":["import type { CSSProperties, ReactElement, ReactNode } from 'react';\n\nimport { type ChartColor, chartColorValue } from '../../lib/chart';\nimport './SeriesLabel.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface SeriesLabelProps {\n /** The series, e.g. a model's name. */\n name: ReactNode;\n /** A muted second part, e.g. the harness it ran with. */\n detail?: ReactNode;\n /** The series' colour, the same as its marks on the page's charts. */\n color: ChartColor;\n /** Makes the name a link. */\n to?: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/**\n * A series named in its colour, for charts that label their marks directly\n * instead of using a legend, and for the lists and tables around them.\n */\nexport function SeriesLabel({\n name,\n detail,\n color,\n to,\n linkComponent: Link = DefaultLink,\n className,\n}: SeriesLabelProps): ReactElement {\n return (\n <span\n className={['aegis-series-label', className ?? '']\n .filter(Boolean)\n .join(' ')}\n style={\n {\n '--aegis-series-label-color': chartColorValue(color),\n } as CSSProperties\n }\n >\n <span className=\"aegis-series-label__dot\" aria-hidden=\"true\" />\n {to === undefined ? (\n <span className=\"aegis-series-label__name\">{name}</span>\n ) : (\n <Link\n to={to}\n className=\"aegis-series-label__name aegis-series-label__name--link\"\n >\n {name}\n </Link>\n )}\n {detail !== undefined && (\n <span className=\"aegis-series-label__detail\">{detail}</span>\n )}\n </span>\n );\n}\n"],"names":["SeriesLabel","name","detail","color","to","Link","DefaultLink","className","jsxs","chartColorValue","jsx"],"mappings":"8NAwBO,SAASA,EAAY,CAC1B,KAAAC,EACA,OAAAC,EACA,MAAAC,EACA,GAAAC,EACA,cAAeC,EAAOC,EAAAA,YACtB,UAAAC,CACF,EAAmC,CACjC,OACEC,EAAAA,KAAC,OAAA,CACC,UAAW,CAAC,qBAAsBD,GAAa,EAAE,EAC9C,OAAO,OAAO,EACd,KAAK,GAAG,EACX,MACE,CACE,6BAA8BE,EAAAA,gBAAgBN,CAAK,CAAA,EAIvD,SAAA,CAAAO,EAAAA,IAAC,OAAA,CAAK,UAAU,0BAA0B,cAAY,OAAO,EAC5DN,IAAO,OACNM,EAAAA,IAAC,QAAK,UAAU,2BAA4B,WAAK,EAEjDA,EAAAA,IAACL,EAAA,CACC,GAAAD,EACA,UAAU,0DAET,SAAAH,CAAA,CAAA,EAGJC,IAAW,QACVQ,EAAAA,IAAC,OAAA,CAAK,UAAU,6BAA8B,SAAAR,CAAA,CAAO,CAAA,CAAA,CAAA,CAI7D"}
1
+ {"version":3,"file":"SeriesLabel.cjs","sources":["../../../src/components/ui/SeriesLabel.tsx"],"sourcesContent":["import type { CSSProperties, ReactElement, ReactNode } from 'react';\n\nimport {\n type ChartColor,\n type ChartLineStyle,\n chartColorValue,\n chartLineDash,\n} from '../../lib/chart';\nimport './SeriesLabel.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface SeriesLabelProps {\n /** The series, e.g. a model's name. */\n name: ReactNode;\n /** A muted second part, e.g. the harness it ran with. */\n detail?: ReactNode;\n /** The series' colour, the same as its marks on the page's charts. */\n color: ChartColor;\n lineStyle?: ChartLineStyle;\n /** Makes the name a link. */\n to?: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/**\n * A series named in its colour, for charts that label their marks directly\n * instead of using a legend, and for the lists and tables around them.\n */\nexport function SeriesLabel({\n name,\n detail,\n color,\n lineStyle,\n to,\n linkComponent: Link = DefaultLink,\n className,\n}: SeriesLabelProps): ReactElement {\n return (\n <span\n className={['aegis-series-label', className ?? '']\n .filter(Boolean)\n .join(' ')}\n style={\n {\n '--aegis-series-label-color': chartColorValue(color),\n } as CSSProperties\n }\n >\n {lineStyle === undefined ? (\n <span className=\"aegis-series-label__dot\" aria-hidden=\"true\" />\n ) : (\n <svg\n className=\"aegis-series-label__line\"\n aria-hidden=\"true\"\n viewBox=\"0 0 32 10\"\n >\n <line\n x1={0}\n x2={32}\n y1={5}\n y2={5}\n style={{ strokeDasharray: chartLineDash(lineStyle) }}\n />\n </svg>\n )}\n {to === undefined ? (\n <span className=\"aegis-series-label__name\">{name}</span>\n ) : (\n <Link\n to={to}\n className=\"aegis-series-label__name aegis-series-label__name--link\"\n >\n {name}\n </Link>\n )}\n {detail !== undefined && (\n <span className=\"aegis-series-label__detail\">{detail}</span>\n )}\n </span>\n );\n}\n"],"names":["SeriesLabel","name","detail","color","lineStyle","to","Link","DefaultLink","className","jsxs","chartColorValue","jsx","chartLineDash"],"mappings":"8NA8BO,SAASA,EAAY,CAC1B,KAAAC,EACA,OAAAC,EACA,MAAAC,EACA,UAAAC,EACA,GAAAC,EACA,cAAeC,EAAOC,EAAAA,YACtB,UAAAC,CACF,EAAmC,CACjC,OACEC,EAAAA,KAAC,OAAA,CACC,UAAW,CAAC,qBAAsBD,GAAa,EAAE,EAC9C,OAAO,OAAO,EACd,KAAK,GAAG,EACX,MACE,CACE,6BAA8BE,EAAAA,gBAAgBP,CAAK,CAAA,EAItD,SAAA,CAAAC,IAAc,OACbO,EAAAA,IAAC,OAAA,CAAK,UAAU,0BAA0B,cAAY,OAAO,EAE7DA,EAAAA,IAAC,MAAA,CACC,UAAU,2BACV,cAAY,OACZ,QAAQ,YAER,SAAAA,EAAAA,IAAC,OAAA,CACC,GAAI,EACJ,GAAI,GACJ,GAAI,EACJ,GAAI,EACJ,MAAO,CAAE,gBAAiBC,EAAAA,cAAcR,CAAS,CAAA,CAAE,CAAA,CACrD,CAAA,EAGHC,IAAO,OACNM,EAAAA,IAAC,QAAK,UAAU,2BAA4B,WAAK,EAEjDA,EAAAA,IAACL,EAAA,CACC,GAAAD,EACA,UAAU,0DAET,SAAAJ,CAAA,CAAA,EAGJC,IAAW,QACVS,EAAAA,IAAC,OAAA,CAAK,UAAU,6BAA8B,SAAAT,CAAA,CAAO,CAAA,CAAA,CAAA,CAI7D"}
@@ -1,5 +1,5 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
- import { ChartColor } from '../../lib/chart';
2
+ import { ChartColor, ChartLineStyle } from '../../lib/chart';
3
3
  import { LinkComponent } from './linkComponent';
4
4
  export interface SeriesLabelProps {
5
5
  /** The series, e.g. a model's name. */
@@ -8,6 +8,7 @@ export interface SeriesLabelProps {
8
8
  detail?: ReactNode;
9
9
  /** The series' colour, the same as its marks on the page's charts. */
10
10
  color: ChartColor;
11
+ lineStyle?: ChartLineStyle;
11
12
  /** Makes the name a link. */
12
13
  to?: string;
13
14
  /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */
@@ -18,4 +19,4 @@ export interface SeriesLabelProps {
18
19
  * A series named in its colour, for charts that label their marks directly
19
20
  * instead of using a legend, and for the lists and tables around them.
20
21
  */
21
- export declare function SeriesLabel({ name, detail, color, to, linkComponent: Link, className, }: SeriesLabelProps): ReactElement;
22
+ export declare function SeriesLabel({ name, detail, color, lineStyle, to, linkComponent: Link, className, }: SeriesLabelProps): ReactElement;
@@ -1,28 +1,46 @@
1
- import { jsxs as o, jsx as e } from "react/jsx-runtime";
2
- import { chartColorValue as m } from "../../lib/chart.js";
1
+ import { jsxs as m, jsx as e } from "react/jsx-runtime";
2
+ import { chartLineDash as t, chartColorValue as c } from "../../lib/chart.js";
3
3
  /* empty css */
4
- import { DefaultLink as t } from "./linkComponent.js";
5
- function b({
4
+ import { DefaultLink as d } from "./linkComponent.js";
5
+ function g({
6
6
  name: s,
7
7
  detail: a,
8
- color: l,
9
- to: i,
10
- linkComponent: r = t,
11
- className: n
8
+ color: r,
9
+ lineStyle: i,
10
+ to: l,
11
+ linkComponent: n = d,
12
+ className: o
12
13
  }) {
13
- return /* @__PURE__ */ o(
14
+ return /* @__PURE__ */ m(
14
15
  "span",
15
16
  {
16
- className: ["aegis-series-label", n ?? ""].filter(Boolean).join(" "),
17
+ className: ["aegis-series-label", o ?? ""].filter(Boolean).join(" "),
17
18
  style: {
18
- "--aegis-series-label-color": m(l)
19
+ "--aegis-series-label-color": c(r)
19
20
  },
20
21
  children: [
21
- /* @__PURE__ */ e("span", { className: "aegis-series-label__dot", "aria-hidden": "true" }),
22
- i === void 0 ? /* @__PURE__ */ e("span", { className: "aegis-series-label__name", children: s }) : /* @__PURE__ */ e(
23
- r,
22
+ i === void 0 ? /* @__PURE__ */ e("span", { className: "aegis-series-label__dot", "aria-hidden": "true" }) : /* @__PURE__ */ e(
23
+ "svg",
24
24
  {
25
- to: i,
25
+ className: "aegis-series-label__line",
26
+ "aria-hidden": "true",
27
+ viewBox: "0 0 32 10",
28
+ children: /* @__PURE__ */ e(
29
+ "line",
30
+ {
31
+ x1: 0,
32
+ x2: 32,
33
+ y1: 5,
34
+ y2: 5,
35
+ style: { strokeDasharray: t(i) }
36
+ }
37
+ )
38
+ }
39
+ ),
40
+ l === void 0 ? /* @__PURE__ */ e("span", { className: "aegis-series-label__name", children: s }) : /* @__PURE__ */ e(
41
+ n,
42
+ {
43
+ to: l,
26
44
  className: "aegis-series-label__name aegis-series-label__name--link",
27
45
  children: s
28
46
  }
@@ -33,6 +51,6 @@ function b({
33
51
  );
34
52
  }
35
53
  export {
36
- b as SeriesLabel
54
+ g as SeriesLabel
37
55
  };
38
56
  //# sourceMappingURL=SeriesLabel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SeriesLabel.js","sources":["../../../src/components/ui/SeriesLabel.tsx"],"sourcesContent":["import type { CSSProperties, ReactElement, ReactNode } from 'react';\n\nimport { type ChartColor, chartColorValue } from '../../lib/chart';\nimport './SeriesLabel.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface SeriesLabelProps {\n /** The series, e.g. a model's name. */\n name: ReactNode;\n /** A muted second part, e.g. the harness it ran with. */\n detail?: ReactNode;\n /** The series' colour, the same as its marks on the page's charts. */\n color: ChartColor;\n /** Makes the name a link. */\n to?: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/**\n * A series named in its colour, for charts that label their marks directly\n * instead of using a legend, and for the lists and tables around them.\n */\nexport function SeriesLabel({\n name,\n detail,\n color,\n to,\n linkComponent: Link = DefaultLink,\n className,\n}: SeriesLabelProps): ReactElement {\n return (\n <span\n className={['aegis-series-label', className ?? '']\n .filter(Boolean)\n .join(' ')}\n style={\n {\n '--aegis-series-label-color': chartColorValue(color),\n } as CSSProperties\n }\n >\n <span className=\"aegis-series-label__dot\" aria-hidden=\"true\" />\n {to === undefined ? (\n <span className=\"aegis-series-label__name\">{name}</span>\n ) : (\n <Link\n to={to}\n className=\"aegis-series-label__name aegis-series-label__name--link\"\n >\n {name}\n </Link>\n )}\n {detail !== undefined && (\n <span className=\"aegis-series-label__detail\">{detail}</span>\n )}\n </span>\n );\n}\n"],"names":["SeriesLabel","name","detail","color","to","Link","DefaultLink","className","jsxs","chartColorValue","jsx"],"mappings":";;;;AAwBO,SAASA,EAAY;AAAA,EAC1B,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,IAAAC;AAAA,EACA,eAAeC,IAAOC;AAAA,EACtB,WAAAC;AACF,GAAmC;AACjC,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW,CAAC,sBAAsBD,KAAa,EAAE,EAC9C,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,MACX,OACE;AAAA,QACE,8BAA8BE,EAAgBN,CAAK;AAAA,MAAA;AAAA,MAIvD,UAAA;AAAA,QAAA,gBAAAO,EAAC,QAAA,EAAK,WAAU,2BAA0B,eAAY,QAAO;AAAA,QAC5DN,MAAO,SACN,gBAAAM,EAAC,UAAK,WAAU,4BAA4B,aAAK,IAEjD,gBAAAA;AAAA,UAACL;AAAA,UAAA;AAAA,YACC,IAAAD;AAAA,YACA,WAAU;AAAA,YAET,UAAAH;AAAA,UAAA;AAAA,QAAA;AAAA,QAGJC,MAAW,UACV,gBAAAQ,EAAC,QAAA,EAAK,WAAU,8BAA8B,UAAAR,EAAA,CAAO;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAI7D;"}
1
+ {"version":3,"file":"SeriesLabel.js","sources":["../../../src/components/ui/SeriesLabel.tsx"],"sourcesContent":["import type { CSSProperties, ReactElement, ReactNode } from 'react';\n\nimport {\n type ChartColor,\n type ChartLineStyle,\n chartColorValue,\n chartLineDash,\n} from '../../lib/chart';\nimport './SeriesLabel.css';\nimport { DefaultLink, type LinkComponent } from './linkComponent';\n\nexport interface SeriesLabelProps {\n /** The series, e.g. a model's name. */\n name: ReactNode;\n /** A muted second part, e.g. the harness it ran with. */\n detail?: ReactNode;\n /** The series' colour, the same as its marks on the page's charts. */\n color: ChartColor;\n lineStyle?: ChartLineStyle;\n /** Makes the name a link. */\n to?: string;\n /** Renders the link. Defaults to an `<a href>`; routed apps pass their Link adapter. */\n linkComponent?: LinkComponent;\n className?: string;\n}\n\n/**\n * A series named in its colour, for charts that label their marks directly\n * instead of using a legend, and for the lists and tables around them.\n */\nexport function SeriesLabel({\n name,\n detail,\n color,\n lineStyle,\n to,\n linkComponent: Link = DefaultLink,\n className,\n}: SeriesLabelProps): ReactElement {\n return (\n <span\n className={['aegis-series-label', className ?? '']\n .filter(Boolean)\n .join(' ')}\n style={\n {\n '--aegis-series-label-color': chartColorValue(color),\n } as CSSProperties\n }\n >\n {lineStyle === undefined ? (\n <span className=\"aegis-series-label__dot\" aria-hidden=\"true\" />\n ) : (\n <svg\n className=\"aegis-series-label__line\"\n aria-hidden=\"true\"\n viewBox=\"0 0 32 10\"\n >\n <line\n x1={0}\n x2={32}\n y1={5}\n y2={5}\n style={{ strokeDasharray: chartLineDash(lineStyle) }}\n />\n </svg>\n )}\n {to === undefined ? (\n <span className=\"aegis-series-label__name\">{name}</span>\n ) : (\n <Link\n to={to}\n className=\"aegis-series-label__name aegis-series-label__name--link\"\n >\n {name}\n </Link>\n )}\n {detail !== undefined && (\n <span className=\"aegis-series-label__detail\">{detail}</span>\n )}\n </span>\n );\n}\n"],"names":["SeriesLabel","name","detail","color","lineStyle","to","Link","DefaultLink","className","jsxs","chartColorValue","jsx","chartLineDash"],"mappings":";;;;AA8BO,SAASA,EAAY;AAAA,EAC1B,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,IAAAC;AAAA,EACA,eAAeC,IAAOC;AAAA,EACtB,WAAAC;AACF,GAAmC;AACjC,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW,CAAC,sBAAsBD,KAAa,EAAE,EAC9C,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,MACX,OACE;AAAA,QACE,8BAA8BE,EAAgBP,CAAK;AAAA,MAAA;AAAA,MAItD,UAAA;AAAA,QAAAC,MAAc,SACb,gBAAAO,EAAC,QAAA,EAAK,WAAU,2BAA0B,eAAY,QAAO,IAE7D,gBAAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,eAAY;AAAA,YACZ,SAAQ;AAAA,YAER,UAAA,gBAAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,IAAI;AAAA,gBACJ,IAAI;AAAA,gBACJ,IAAI;AAAA,gBACJ,IAAI;AAAA,gBACJ,OAAO,EAAE,iBAAiBC,EAAcR,CAAS,EAAA;AAAA,cAAE;AAAA,YAAA;AAAA,UACrD;AAAA,QAAA;AAAA,QAGHC,MAAO,SACN,gBAAAM,EAAC,UAAK,WAAU,4BAA4B,aAAK,IAEjD,gBAAAA;AAAA,UAACL;AAAA,UAAA;AAAA,YACC,IAAAD;AAAA,YACA,WAAU;AAAA,YAET,UAAAJ;AAAA,UAAA;AAAA,QAAA;AAAA,QAGJC,MAAW,UACV,gBAAAS,EAAC,QAAA,EAAK,WAAU,8BAA8B,UAAAT,EAAA,CAAO;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAI7D;"}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { RelativeTimePreset, TimeRange } from './lib/timeRange';
7
7
  export { replaceTokenAtCursor, tokenizeAtCursor } from './lib/luceneQuery';
8
8
  export type { CursorToken } from './lib/luceneQuery';
9
9
  export { chartColorValue, niceTicks, stageProgress, staggeredProgress, zeroAnchoredDomain, } from './lib/chart';
10
- export type { ChartColor, ChartPaletteColor } from './lib/chart';
10
+ export type { ChartColor, ChartLineStyle, ChartPaletteColor, } from './lib/chart';
11
11
  export { PageWrapper } from './layouts/PageWrapper';
12
12
  export type { PageWrapperProps } from './layouts/PageWrapper';
13
13
  export { SiteAnchorNav, SiteFooter, SiteLayout, SiteNav, SiteSection, SiteSectionHeader, } from './layouts/site';
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M={seq:"var(--data-seq)","cat-1":"var(--data-cat-1)","cat-2":"var(--data-cat-2)","cat-3":"var(--data-cat-3)","cat-4":"var(--data-cat-4)","cat-5":"var(--data-cat-5)","cat-6":"var(--data-cat-6)",unknown:"var(--bg-muted)"};function l(t){return t.startsWith("var(")?t:M[t]}function m(t,n){const a=Math.min(0,...t),e=n??Math.max(0,...t);return e<=a?[a,a+1]:[a,e]}function u(t){if(!(t>0)||!Number.isFinite(t))return 1;const n=10**Math.floor(Math.log10(t)),a=t/n;return(a<=1?1:a<=2?2:a<=5?5:10)*n}const f=50;function v(t,n,a=5){if(!(n>t))return[];const e=u((n-t)/a),o=1e-9,h=Math.ceil(t/e-o),d=Math.floor(n/e+o),g=Math.max(0,-Math.floor(Math.log10(e))),c=[];for(let r=h;r<=d&&c.length<f;r+=1){const s=Number((r*e).toFixed(g));c.push(s===0?0:s)}return c}const i=.12;function p(t,n,a){const e=1+i*Math.max(a-1,0);return Math.min(1,Math.max(0,t*e-i*n))}function S(t,n,a){return Math.min(1,Math.max(0,(t-n)/(a-n)))}exports.chartColorValue=l;exports.niceStep=u;exports.niceTicks=v;exports.stageProgress=S;exports.staggeredProgress=p;exports.zeroAnchoredDomain=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(t){return{solid:void 0,dashed:"var(--space-2) var(--space-1)",dotted:"var(--size-hairline) var(--space-1)"}[t]}const M={seq:"var(--data-seq)","cat-1":"var(--data-cat-1)","cat-2":"var(--data-cat-2)","cat-3":"var(--data-cat-3)","cat-4":"var(--data-cat-4)","cat-5":"var(--data-cat-5)","cat-6":"var(--data-cat-6)",unknown:"var(--bg-muted)"};function m(t){return t.startsWith("var(")?t:M[t]}function f(t,n){const a=Math.min(0,...t),e=n??Math.max(0,...t);return e<=a?[a,a+1]:[a,e]}function h(t){if(!(t>0)||!Number.isFinite(t))return 1;const n=10**Math.floor(Math.log10(t)),a=t/n;return(a<=1?1:a<=2?2:a<=5?5:10)*n}const v=50;function p(t,n,a=5){if(!(n>t))return[];const e=h((n-t)/a),s=1e-9,u=Math.ceil(t/e-s),d=Math.floor(n/e+s),l=Math.max(0,-Math.floor(Math.log10(e))),r=[];for(let c=u;c<=d&&r.length<v;c+=1){const o=Number((c*e).toFixed(l));r.push(o===0?0:o)}return r}const i=.12;function S(t,n,a){const e=1+i*Math.max(a-1,0);return Math.min(1,Math.max(0,t*e-i*n))}function T(t,n,a){return Math.min(1,Math.max(0,(t-n)/(a-n)))}exports.chartColorValue=m;exports.chartLineDash=g;exports.niceStep=h;exports.niceTicks=p;exports.stageProgress=T;exports.staggeredProgress=S;exports.zeroAnchoredDomain=f;
2
2
  //# sourceMappingURL=chart.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart.cjs","sources":["../../src/lib/chart.ts"],"sourcesContent":["/** Colours of the data palette in theme.css. */\nexport type ChartPaletteColor =\n | 'seq'\n | 'cat-1'\n | 'cat-2'\n | 'cat-3'\n | 'cat-4'\n | 'cat-5'\n | 'cat-6'\n | 'unknown';\n\n/**\n * How a chart colours a series: a palette colour (`seq` for one\n * magnitude, `cat-1`…`cat-6` to tell series apart, `unknown` a neutral\n * fill for a share not classified yet), or a `var(…)` reference to a\n * token, such as a `--series-*` vendor colour, so one vendor keeps its\n * colour on every chart.\n */\nexport type ChartColor = ChartPaletteColor | `var(--${string})`;\n\nconst PALETTE_VALUES: Record<ChartPaletteColor, string> = {\n seq: 'var(--data-seq)',\n 'cat-1': 'var(--data-cat-1)',\n 'cat-2': 'var(--data-cat-2)',\n 'cat-3': 'var(--data-cat-3)',\n 'cat-4': 'var(--data-cat-4)',\n 'cat-5': 'var(--data-cat-5)',\n 'cat-6': 'var(--data-cat-6)',\n unknown: 'var(--bg-muted)',\n};\n\n/** The CSS colour of a chart colour. */\nexport function chartColorValue(color: ChartColor): string {\n return color.startsWith('var(')\n ? color\n : PALETTE_VALUES[color as ChartPaletteColor];\n}\n\n/**\n * The span an axis covers: from 0 (or the smallest value, when negative)\n * to `max` when given, else to the largest value. A span of all zeros\n * becomes [0, 1] so the scale still divides.\n */\nexport function zeroAnchoredDomain(\n values: number[],\n max?: number,\n): [number, number] {\n const lo = Math.min(0, ...values);\n const hi = max ?? Math.max(0, ...values);\n return hi <= lo ? [lo, lo + 1] : [lo, hi];\n}\n\n/** The smallest 1, 2 or 5 × 10ⁿ step not below `raw`. */\nexport function niceStep(raw: number): number {\n if (!(raw > 0) || !Number.isFinite(raw)) {\n return 1;\n }\n const base = 10 ** Math.floor(Math.log10(raw));\n const normalized = raw / base;\n const nice =\n normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;\n return nice * base;\n}\n\nconst MAX_TICKS = 50;\n\n/**\n * Round values from `lo` to `hi`, about `count` of them. Ticks are\n * computed by index rather than by repeated addition, so a span far from\n * zero (nanosecond timestamps) neither drifts nor stalls, and each is\n * rounded to the step's decimals, so 0.6 stays 0.6 and an end that is a\n * multiple of the step is a tick.\n */\nexport function niceTicks(lo: number, hi: number, count = 5): number[] {\n if (!(hi > lo)) {\n return [];\n }\n const step = niceStep((hi - lo) / count);\n // Absorbs division error such as 0.6 / 0.2 = 2.9999999999999996.\n const epsilon = 1e-9;\n const first = Math.ceil(lo / step - epsilon);\n const last = Math.floor(hi / step + epsilon);\n const decimals = Math.max(0, -Math.floor(Math.log10(step)));\n const ticks: number[] = [];\n for (let i = first; i <= last && ticks.length < MAX_TICKS; i += 1) {\n const tick = Number((i * step).toFixed(decimals));\n ticks.push(tick === 0 ? 0 : tick);\n }\n return ticks;\n}\n\n/** How far later rows lag behind the first, as a share of the draw. */\nconst STAGGER = 0.12;\n\n/**\n * The share of row `index` (of `count`) that is drawn when the chart as a\n * whole is `progress` of the way in: rows start one after another and\n * all finish at 1.\n */\nexport function staggeredProgress(\n progress: number,\n index: number,\n count: number,\n): number {\n const span = 1 + STAGGER * Math.max(count - 1, 0);\n return Math.min(1, Math.max(0, progress * span - STAGGER * index));\n}\n\n/**\n * Where `progress` is within one stage, `from` to `to`, of a chart's draw:\n * 0 before the stage, 1 after it.\n */\nexport function stageProgress(\n progress: number,\n from: number,\n to: number,\n): number {\n return Math.min(1, Math.max(0, (progress - from) / (to - from)));\n}\n"],"names":["PALETTE_VALUES","chartColorValue","color","zeroAnchoredDomain","values","max","lo","hi","niceStep","raw","base","normalized","MAX_TICKS","niceTicks","count","step","epsilon","first","last","decimals","ticks","i","tick","STAGGER","staggeredProgress","progress","index","span","stageProgress","from","to"],"mappings":"gFAoBA,MAAMA,EAAoD,CACxD,IAAK,kBACL,QAAS,oBACT,QAAS,oBACT,QAAS,oBACT,QAAS,oBACT,QAAS,oBACT,QAAS,oBACT,QAAS,iBACX,EAGO,SAASC,EAAgBC,EAA2B,CACzD,OAAOA,EAAM,WAAW,MAAM,EAC1BA,EACAF,EAAeE,CAA0B,CAC/C,CAOO,SAASC,EACdC,EACAC,EACkB,CAClB,MAAMC,EAAK,KAAK,IAAI,EAAG,GAAGF,CAAM,EAC1BG,EAAKF,GAAO,KAAK,IAAI,EAAG,GAAGD,CAAM,EACvC,OAAO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ACjE"}
1
+ {"version":3,"file":"chart.cjs","sources":["../../src/lib/chart.ts"],"sourcesContent":["/** Colours of the data palette in theme.css. */\nexport type ChartPaletteColor =\n | 'seq'\n | 'cat-1'\n | 'cat-2'\n | 'cat-3'\n | 'cat-4'\n | 'cat-5'\n | 'cat-6'\n | 'unknown';\n\n/**\n * How a chart colours a series: a palette colour (`seq` for one\n * magnitude, `cat-1`…`cat-6` to tell series apart, `unknown` a neutral\n * fill for a share not classified yet), or a `var(…)` reference to a\n * token, such as a `--series-*` vendor colour, so one vendor keeps its\n * colour on every chart.\n */\nexport type ChartColor = ChartPaletteColor | `var(--${string})`;\n\nexport type ChartLineStyle = 'solid' | 'dashed' | 'dotted';\n\nexport function chartLineDash(style: ChartLineStyle): string | undefined {\n return {\n solid: undefined,\n dashed: 'var(--space-2) var(--space-1)',\n dotted: 'var(--size-hairline) var(--space-1)',\n }[style];\n}\n\nconst PALETTE_VALUES: Record<ChartPaletteColor, string> = {\n seq: 'var(--data-seq)',\n 'cat-1': 'var(--data-cat-1)',\n 'cat-2': 'var(--data-cat-2)',\n 'cat-3': 'var(--data-cat-3)',\n 'cat-4': 'var(--data-cat-4)',\n 'cat-5': 'var(--data-cat-5)',\n 'cat-6': 'var(--data-cat-6)',\n unknown: 'var(--bg-muted)',\n};\n\n/** The CSS colour of a chart colour. */\nexport function chartColorValue(color: ChartColor): string {\n return color.startsWith('var(')\n ? color\n : PALETTE_VALUES[color as ChartPaletteColor];\n}\n\n/**\n * The span an axis covers: from 0 (or the smallest value, when negative)\n * to `max` when given, else to the largest value. A span of all zeros\n * becomes [0, 1] so the scale still divides.\n */\nexport function zeroAnchoredDomain(\n values: number[],\n max?: number,\n): [number, number] {\n const lo = Math.min(0, ...values);\n const hi = max ?? Math.max(0, ...values);\n return hi <= lo ? [lo, lo + 1] : [lo, hi];\n}\n\n/** The smallest 1, 2 or 5 × 10ⁿ step not below `raw`. */\nexport function niceStep(raw: number): number {\n if (!(raw > 0) || !Number.isFinite(raw)) {\n return 1;\n }\n const base = 10 ** Math.floor(Math.log10(raw));\n const normalized = raw / base;\n const nice =\n normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;\n return nice * base;\n}\n\nconst MAX_TICKS = 50;\n\n/**\n * Round values from `lo` to `hi`, about `count` of them. Ticks are\n * computed by index rather than by repeated addition, so a span far from\n * zero (nanosecond timestamps) neither drifts nor stalls, and each is\n * rounded to the step's decimals, so 0.6 stays 0.6 and an end that is a\n * multiple of the step is a tick.\n */\nexport function niceTicks(lo: number, hi: number, count = 5): number[] {\n if (!(hi > lo)) {\n return [];\n }\n const step = niceStep((hi - lo) / count);\n // Absorbs division error such as 0.6 / 0.2 = 2.9999999999999996.\n const epsilon = 1e-9;\n const first = Math.ceil(lo / step - epsilon);\n const last = Math.floor(hi / step + epsilon);\n const decimals = Math.max(0, -Math.floor(Math.log10(step)));\n const ticks: number[] = [];\n for (let i = first; i <= last && ticks.length < MAX_TICKS; i += 1) {\n const tick = Number((i * step).toFixed(decimals));\n ticks.push(tick === 0 ? 0 : tick);\n }\n return ticks;\n}\n\n/** How far later rows lag behind the first, as a share of the draw. */\nconst STAGGER = 0.12;\n\n/**\n * The share of row `index` (of `count`) that is drawn when the chart as a\n * whole is `progress` of the way in: rows start one after another and\n * all finish at 1.\n */\nexport function staggeredProgress(\n progress: number,\n index: number,\n count: number,\n): number {\n const span = 1 + STAGGER * Math.max(count - 1, 0);\n return Math.min(1, Math.max(0, progress * span - STAGGER * index));\n}\n\n/**\n * Where `progress` is within one stage, `from` to `to`, of a chart's draw:\n * 0 before the stage, 1 after it.\n */\nexport function stageProgress(\n progress: number,\n from: number,\n to: number,\n): number {\n return Math.min(1, Math.max(0, (progress - from) / (to - from)));\n}\n"],"names":["chartLineDash","style","PALETTE_VALUES","chartColorValue","color","zeroAnchoredDomain","values","max","lo","hi","niceStep","raw","base","normalized","MAX_TICKS","niceTicks","count","step","epsilon","first","last","decimals","ticks","i","tick","STAGGER","staggeredPro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AAQE,EAAM,OAASR,EAAWS,GAAK,EAAG,CACjE,MAAMC,EAAO,QAAQD,EAAIN,GAAM,QAAQI,CAAQ,CAAC,EAChDC,EAAM,KAAKE,IAAS,EAAI,EAAIA,CAAI,CAClC,CACA,OAAOF,CACT,CAGA,MAAMG,EAAU,IAOT,SAASC,EACdC,EACAC,EACAZ,EACQ,CACR,MAAMa,EAAO,EAAIJ,EAAU,KAAK,IAAIT,EAAQ,EAAG,CAAC,EAChD,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAGW,EAAWE,EAAOJ,EAAUG,CAAK,CAAC,CACnE,CAMO,SAASE,EACdH,EACAI,EACAC,EACQ,CACR,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,GAAIL,EAAWI,IAASC,EAAKD,EAAK,CAAC,CACjE"}
@@ -8,6 +8,8 @@ export type ChartPaletteColor = 'seq' | 'cat-1' | 'cat-2' | 'cat-3' | 'cat-4' |
8
8
  * colour on every chart.
9
9
  */
10
10
  export type ChartColor = ChartPaletteColor | `var(--${string})`;
11
+ export type ChartLineStyle = 'solid' | 'dashed' | 'dotted';
12
+ export declare function chartLineDash(style: ChartLineStyle): string | undefined;
11
13
  /** The CSS colour of a chart colour. */
12
14
  export declare function chartColorValue(color: ChartColor): string;
13
15
  /**
package/dist/lib/chart.js CHANGED
@@ -1,4 +1,11 @@
1
- const d = {
1
+ function v(t) {
2
+ return {
3
+ solid: void 0,
4
+ dashed: "var(--space-2) var(--space-1)",
5
+ dotted: "var(--size-hairline) var(--space-1)"
6
+ }[t];
7
+ }
8
+ const M = {
2
9
  seq: "var(--data-seq)",
3
10
  "cat-1": "var(--data-cat-1)",
4
11
  "cat-2": "var(--data-cat-2)",
@@ -9,42 +16,43 @@ const d = {
9
16
  unknown: "var(--bg-muted)"
10
17
  };
11
18
  function l(t) {
12
- return t.startsWith("var(") ? t : d[t];
19
+ return t.startsWith("var(") ? t : M[t];
13
20
  }
14
21
  function g(t, n) {
15
22
  const a = Math.min(0, ...t), c = n ?? Math.max(0, ...t);
16
23
  return c <= a ? [a, a + 1] : [a, c];
17
24
  }
18
- function m(t) {
25
+ function f(t) {
19
26
  if (!(t > 0) || !Number.isFinite(t))
20
27
  return 1;
21
28
  const n = 10 ** Math.floor(Math.log10(t)), a = t / n;
22
29
  return (a <= 1 ? 1 : a <= 2 ? 2 : a <= 5 ? 5 : 10) * n;
23
30
  }
24
- const f = 50;
25
- function v(t, n, a = 5) {
31
+ const m = 50;
32
+ function p(t, n, a = 5) {
26
33
  if (!(n > t))
27
34
  return [];
28
- const c = m((n - t) / a), o = 1e-9, u = Math.ceil(t / c - o), h = Math.floor(n / c + o), M = Math.max(0, -Math.floor(Math.log10(c))), r = [];
29
- for (let e = u; e <= h && r.length < f; e += 1) {
30
- const s = Number((e * c).toFixed(M));
31
- r.push(s === 0 ? 0 : s);
35
+ const c = f((n - t) / a), s = 1e-9, h = Math.ceil(t / c - s), u = Math.floor(n / c + s), d = Math.max(0, -Math.floor(Math.log10(c))), e = [];
36
+ for (let r = h; r <= u && e.length < m; r += 1) {
37
+ const o = Number((r * c).toFixed(d));
38
+ e.push(o === 0 ? 0 : o);
32
39
  }
33
- return r;
40
+ return e;
34
41
  }
35
42
  const i = 0.12;
36
43
  function x(t, n, a) {
37
44
  const c = 1 + i * Math.max(a - 1, 0);
38
45
  return Math.min(1, Math.max(0, t * c - i * n));
39
46
  }
40
- function p(t, n, a) {
47
+ function A(t, n, a) {
41
48
  return Math.min(1, Math.max(0, (t - n) / (a - n)));
42
49
  }
43
50
  export {
44
51
  l as chartColorValue,
45
- m as niceStep,
46
- v as niceTicks,
47
- p as stageProgress,
52
+ v as chartLineDash,
53
+ f as niceStep,
54
+ p as niceTicks,
55
+ A as stageProgress,
48
56
  x as staggeredProgress,
49
57
  g as zeroAnchoredDomain
50
58
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chart.js","sources":["../../src/lib/chart.ts"],"sourcesContent":["/** Colours of the data palette in theme.css. */\nexport type ChartPaletteColor =\n | 'seq'\n | 'cat-1'\n | 'cat-2'\n | 'cat-3'\n | 'cat-4'\n | 'cat-5'\n | 'cat-6'\n | 'unknown';\n\n/**\n * How a chart colours a series: a palette colour (`seq` for one\n * magnitude, `cat-1`…`cat-6` to tell series apart, `unknown` a neutral\n * fill for a share not classified yet), or a `var(…)` reference to a\n * token, such as a `--series-*` vendor colour, so one vendor keeps its\n * colour on every chart.\n */\nexport type ChartColor = ChartPaletteColor | `var(--${string})`;\n\nconst PALETTE_VALUES: Record<ChartPaletteColor, string> = {\n seq: 'var(--data-seq)',\n 'cat-1': 'var(--data-cat-1)',\n 'cat-2': 'var(--data-cat-2)',\n 'cat-3': 'var(--data-cat-3)',\n 'cat-4': 'var(--data-cat-4)',\n 'cat-5': 'var(--data-cat-5)',\n 'cat-6': 'var(--data-cat-6)',\n unknown: 'var(--bg-muted)',\n};\n\n/** The CSS colour of a chart colour. */\nexport function chartColorValue(color: ChartColor): string {\n return color.startsWith('var(')\n ? color\n : PALETTE_VALUES[color as ChartPaletteColor];\n}\n\n/**\n * The span an axis covers: from 0 (or the smallest value, when negative)\n * to `max` when given, else to the largest value. A span of all zeros\n * becomes [0, 1] so the scale still divides.\n */\nexport function zeroAnchoredDomain(\n values: number[],\n max?: number,\n): [number, number] {\n const lo = Math.min(0, ...values);\n const hi = max ?? Math.max(0, ...values);\n return hi <= lo ? [lo, lo + 1] : [lo, hi];\n}\n\n/** The smallest 1, 2 or 5 × 10ⁿ step not below `raw`. */\nexport function niceStep(raw: number): number {\n if (!(raw > 0) || !Number.isFinite(raw)) {\n return 1;\n }\n const base = 10 ** Math.floor(Math.log10(raw));\n const normalized = raw / base;\n const nice =\n normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;\n return nice * base;\n}\n\nconst MAX_TICKS = 50;\n\n/**\n * Round values from `lo` to `hi`, about `count` of them. Ticks are\n * computed by index rather than by repeated addition, so a span far from\n * zero (nanosecond timestamps) neither drifts nor stalls, and each is\n * rounded to the step's decimals, so 0.6 stays 0.6 and an end that is a\n * multiple of the step is a tick.\n */\nexport function niceTicks(lo: number, hi: number, count = 5): number[] {\n if (!(hi > lo)) {\n return [];\n }\n const step = niceStep((hi - lo) / count);\n // Absorbs division error such as 0.6 / 0.2 = 2.9999999999999996.\n const epsilon = 1e-9;\n const first = Math.ceil(lo / step - epsilon);\n const last = Math.floor(hi / step + epsilon);\n const decimals = Math.max(0, -Math.floor(Math.log10(step)));\n const ticks: number[] = [];\n for (let i = first; i <= last && ticks.length < MAX_TICKS; i += 1) {\n const tick = Number((i * step).toFixed(decimals));\n ticks.push(tick === 0 ? 0 : tick);\n }\n return ticks;\n}\n\n/** How far later rows lag behind the first, as a share of the draw. */\nconst STAGGER = 0.12;\n\n/**\n * The share of row `index` (of `count`) that is drawn when the chart as a\n * whole is `progress` of the way in: rows start one after another and\n * all finish at 1.\n */\nexport function staggeredProgress(\n progress: number,\n index: number,\n count: number,\n): number {\n const span = 1 + STAGGER * Math.max(count - 1, 0);\n return Math.min(1, Math.max(0, progress * span - STAGGER * index));\n}\n\n/**\n * Where `progress` is within one stage, `from` to `to`, of a chart's draw:\n * 0 before the stage, 1 after it.\n */\nexport function stageProgress(\n progress: number,\n from: number,\n to: number,\n): number {\n return Math.min(1, Math.max(0, (progress - from) / (to - from)));\n}\n"],"names":["PALETTE_VALUES","chartColorValue","color","zeroAnchoredDomain","values","max","lo","hi","niceStep","raw","base","normalized","MAX_TICKS","niceTicks","count","step","epsilon","first","last","decimals","ticks","i","tick","STAGGER","staggeredProgress","progress","index","span","stageProgress","from","to"],"mappings":"AAoBA,MAAMA,IAAoD;AAAA,EACxD,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAGO,SAASC,EAAgBC,GAA2B;AACzD,SAAOA,EAAM,WAAW,MAAM,IAC1BA,IACAF,EAAeE,C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AI,GAAGW,IAAWE,IAAOJ,IAAUG,CAAK,CAAC;AACnE;AAMO,SAASE,EACdH,GACAI,GACAC,GACQ;AACR,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,IAAIL,IAAWI,MAASC,IAAKD,EAAK,CAAC;AACjE;"}
1
+ {"version":3,"file":"chart.js","sources":["../../src/lib/chart.ts"],"sourcesContent":["/** Colours of the data palette in theme.css. */\nexport type ChartPaletteColor =\n | 'seq'\n | 'cat-1'\n | 'cat-2'\n | 'cat-3'\n | 'cat-4'\n | 'cat-5'\n | 'cat-6'\n | 'unknown';\n\n/**\n * How a chart colours a series: a palette colour (`seq` for one\n * magnitude, `cat-1`…`cat-6` to tell series apart, `unknown` a neutral\n * fill for a share not classified yet), or a `var(…)` reference to a\n * token, such as a `--series-*` vendor colour, so one vendor keeps its\n * colour on every chart.\n */\nexport type ChartColor = ChartPaletteColor | `var(--${string})`;\n\nexport type ChartLineStyle = 'solid' | 'dashed' | 'dotted';\n\nexport function chartLineDash(style: ChartLineStyle): string | undefined {\n return {\n solid: undefined,\n dashed: 'var(--space-2) var(--space-1)',\n dotted: 'var(--size-hairline) var(--space-1)',\n }[style];\n}\n\nconst PALETTE_VALUES: Record<ChartPaletteColor, string> = {\n seq: 'var(--data-seq)',\n 'cat-1': 'var(--data-cat-1)',\n 'cat-2': 'var(--data-cat-2)',\n 'cat-3': 'var(--data-cat-3)',\n 'cat-4': 'var(--data-cat-4)',\n 'cat-5': 'var(--data-cat-5)',\n 'cat-6': 'var(--data-cat-6)',\n unknown: 'var(--bg-muted)',\n};\n\n/** The CSS colour of a chart colour. */\nexport function chartColorValue(color: ChartColor): string {\n return color.startsWith('var(')\n ? color\n : PALETTE_VALUES[color as ChartPaletteColor];\n}\n\n/**\n * The span an axis covers: from 0 (or the smallest value, when negative)\n * to `max` when given, else to the largest value. A span of all zeros\n * becomes [0, 1] so the scale still divides.\n */\nexport function zeroAnchoredDomain(\n values: number[],\n max?: number,\n): [number, number] {\n const lo = Math.min(0, ...values);\n const hi = max ?? Math.max(0, ...values);\n return hi <= lo ? [lo, lo + 1] : [lo, hi];\n}\n\n/** The smallest 1, 2 or 5 × 10ⁿ step not below `raw`. */\nexport function niceStep(raw: number): number {\n if (!(raw > 0) || !Number.isFinite(raw)) {\n return 1;\n }\n const base = 10 ** Math.floor(Math.log10(raw));\n const normalized = raw / base;\n const nice =\n normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;\n return nice * base;\n}\n\nconst MAX_TICKS = 50;\n\n/**\n * Round values from `lo` to `hi`, about `count` of them. Ticks are\n * computed by index rather than by repeated addition, so a span far from\n * zero (nanosecond timestamps) neither drifts nor stalls, and each is\n * rounded to the step's decimals, so 0.6 stays 0.6 and an end that is a\n * multiple of the step is a tick.\n */\nexport function niceTicks(lo: number, hi: number, count = 5): number[] {\n if (!(hi > lo)) {\n return [];\n }\n const step = niceStep((hi - lo) / count);\n // Absorbs division error such as 0.6 / 0.2 = 2.9999999999999996.\n const epsilon = 1e-9;\n const first = Math.ceil(lo / step - epsilon);\n const last = Math.floor(hi / step + epsilon);\n const decimals = Math.max(0, -Math.floor(Math.log10(step)));\n const ticks: number[] = [];\n for (let i = first; i <= last && ticks.length < MAX_TICKS; i += 1) {\n const tick = Number((i * step).toFixed(decimals));\n ticks.push(tick === 0 ? 0 : tick);\n }\n return ticks;\n}\n\n/** How far later rows lag behind the first, as a share of the draw. */\nconst STAGGER = 0.12;\n\n/**\n * The share of row `index` (of `count`) that is drawn when the chart as a\n * whole is `progress` of the way in: rows start one after another and\n * all finish at 1.\n */\nexport function staggeredProgress(\n progress: number,\n index: number,\n count: number,\n): number {\n const span = 1 + STAGGER * Math.max(count - 1, 0);\n return Math.min(1, Math.max(0, progress * span - STAGGER * index));\n}\n\n/**\n * Where `progress` is within one stage, `from` to `to`, of a chart's draw:\n * 0 before the stage, 1 after it.\n */\nexport function stageProgress(\n progress: number,\n from: number,\n to: number,\n): number {\n return Math.min(1, Math.max(0, (progress - from) / (to - from)));\n}\n"],"names":["chartLineDash","style","PALETTE_VALUES","chartColorValue","color","zeroAnchoredDomain","values","max","lo","hi","niceStep","raw","base","normalized","MAX_TICKS","niceTicks","count","step","epsilon","first","last","decimals","ticks","i","tick","STAGGER","staggeredProgress","progress","index","span","stageProgress","from","to"],"mappings":"AAsBO,SAASA,EAAcC,GAA2C;AACvE,SAAO;AAAA,IACL,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA,EACRA,CAAK;AACT;AAEA,MAAMC,IAAoD;AAAA,EACxD,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAGO,SAASC,EAAgBC,GAA2B;AACzD,SAAOA,EAAM,WAAW,MAAM,IAC1BA,IACAF,EAAeE,CAA0B;AAC/C;AAOO,SAASC,EACdC,GACAC,GACkB;AAClB,QAAMC,IAAK,KAAK,IAAI,GAAG,GAAGF,CAAM,GAC1BG,IAAKF,KAAO,KAAK,IAAI,GAAG,GAAGD,CAAM;AACvC,SAAOG,KAAMD,IAAK,CAACA,GAAIA,IAAK,CAAC,IAAI,CAACA,GAAIC,CAAE;AAC1C;AAGO,SAASC,EAASC,GAAqB;AAC5C,MAAI,EAAEA,IAAM,MAAM,CAAC,OAAO,SAASA,CAAG;AACpC,WAAO;AAET,QAAMC,IAAO,MAAM,KAAK,MAAM,KAAK,MAAMD,CAAG,CAAC,GACvCE,IAAaF,IAAMC;AAGzB,UADEC,KAAc,IAAI,IAAIA,KAAc,IAAI,IAAIA,KAAc,IAAI,IAAI,MACtDD;AAChB;AAEA,MAAME,IAAY;AASX,SAASC,EAAUP,GAAYC,GAAYO,IAAQ,GAAa;AACrE,MAAI,EAAEP,IAAKD;AACT,WAAO,CAAA;AAET,QAAMS,IAAOP,GAAUD,IAAKD,KAAMQ,CAAK,GAEjCE,IAAU,MACVC,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