@lincyaw/aegis-ui 0.9.1 → 0.9.3
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.
- package/dist/components/ui/LineChart.cjs +1 -1
- package/dist/components/ui/LineChart.cjs.map +1 -1
- package/dist/components/ui/LineChart.d.ts +5 -2
- package/dist/components/ui/LineChart.js +140 -108
- package/dist/components/ui/LineChart.js.map +1 -1
- package/dist/components/ui/SeriesLabel.cjs +1 -1
- package/dist/components/ui/SeriesLabel.cjs.map +1 -1
- package/dist/components/ui/SeriesLabel.d.ts +3 -2
- package/dist/components/ui/SeriesLabel.js +34 -16
- package/dist/components/ui/SeriesLabel.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/lib/chart.cjs +1 -1
- package/dist/lib/chart.cjs.map +1 -1
- package/dist/lib/chart.d.ts +2 -0
- package/dist/lib/chart.js +22 -14
- package/dist/lib/chart.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),M=require("react"),F=require("../../hooks/useElementWidth.cjs"),A=require("../../lib/chart.cjs");;/* empty css */const G=require("../../locale/useStrings.cjs"),r=240,K=32,V=8,W=20,z=28,y=8,P=16,J=4;function Q({series:f,label:R,endLabels:T=!0,xLabel:N,yTicks:C,formatX:S=String,formatY:k=String,playhead:l,onSeek:c,markers:B=[],progress:m,className:I}){const q=G.useStrings(),w=M.useId(),v=M.useRef(null),u=F.useElementWidth(v),D=f.flatMap(t=>t.points),n=[...new Set(D.map(t=>t.x))].sort((t,e)=>t-e),L=["aegis-line-chart",I??""].filter(Boolean).join(" ");if(u===0||n.length===0)return s.jsx("div",{ref:v,className:L});const i=n[0],_=n[n.length-1],$=D.map(t=>t.y),b=C??A.niceTicks(0,Math.max(...$,1)),H=Math.max(...b,...$),o=K,h=u-V,j=W,p=r-z,x=t=>o+(_>i?(t-i)/(_-i):0)*(h-o),d=t=>p-t/H*(p-j),g=f.flatMap(t=>{const e=t.points[t.points.length-1];return e===void 0?[]:[{line:t,last:e,y:d(e.y)}]}).sort((t,e)=>e.y-t.y);for(let t=1;t<g.length;t+=1)g[t-1].y-g[t].y<P&&(g[t].y=g[t-1].y-P);const E=t=>n.reduce((e,a)=>Math.abs(a-t)<Math.abs(e-t)?a:e),O=t=>{const e=t.currentTarget.getBoundingClientRect(),a=(t.clientX-e.left)/e.width;c?.(E(i+a*(_-i)))},U=t=>{const e=n.indexOf(E(l??i)),a={ArrowLeft:e-1,ArrowDown:e-1,ArrowRight:e+1,ArrowUp:e+1,Home:0,End:n.length-1};t.key in a&&(t.preventDefault(),c?.(n[Math.min(Math.max(a[t.key],0),n.length-1)]))};return s.jsx("div",{ref:v,className:L,children:s.jsxs("svg",{className:"aegis-line-chart__svg",width:u,height:r,viewBox:`0 0 ${u.toString()} ${r.toString()}`,role:c?"group":"img","aria-label":R,children:[b.map(t=>s.jsxs("g",{children:[s.jsx("line",{className:"aegis-line-chart__grid",x1:o,x2:h,y1:d(t),y2:d(t)}),s.jsx("text",{className:"aegis-line-chart__tick",x:o-y,y:d(t),textAnchor:"end",dominantBaseline:"middle",children:k(t)})]},t)),f.map(t=>s.jsxs("g",{children:[t.lineStyle&&t.lineStyle!=="solid"&&m!==void 0&&s.jsx("mask",{id:`${w}-${t.key}`,maskUnits:"userSpaceOnUse",x:0,y:0,width:u,height:r,children:s.jsx("polyline",{className:"aegis-line-chart__line",pathLength:1,points:t.points.map(e=>`${x(e.x).toString()},${d(e.y).toString()}`).join(" "),style:{stroke:"white","--aegis-line-chart-progress":m}})}),s.jsx("polyline",{className:"aegis-line-chart__line",pathLength:!t.lineStyle||t.lineStyle==="solid"?1:void 0,mask:t.lineStyle&&t.lineStyle!=="solid"&&m!==void 0?`url(#${w}-${t.key})`:void 0,points:t.points.map(e=>`${x(e.x).toString()},${d(e.y).toString()}`).join(" "),style:{stroke:A.chartColorValue(t.color),...t.lineStyle&&t.lineStyle!=="solid"?{strokeDasharray:A.chartLineDash(t.lineStyle),strokeDashoffset:0}:{},...m===void 0?{}:{"--aegis-line-chart-progress":m}}})]},t.key)),T&&g.map(({line:t,last:e,y:a})=>s.jsx("text",{className:"aegis-line-chart__end-label",x:h,y:a-y,textAnchor:"end",style:{fill:A.chartColorValue(t.color)},children:`${t.label} ${k(e.y)}`},t.key)),l!==void 0&&s.jsxs("g",{children:[s.jsx("line",{className:"aegis-line-chart__playhead",x1:x(l),x2:x(l),y1:j,y2:p}),s.jsx("text",{className:"aegis-line-chart__playhead-label",x:x(l),y:j-y/2,textAnchor:"middle",children:S(l)})]}),s.jsx("text",{className:"aegis-line-chart__tick",x:o,y:r-y,textAnchor:"start",children:S(i)}),s.jsx("text",{className:"aegis-line-chart__tick",x:h,y:r-y,textAnchor:"end",children:S(_)}),N!==void 0&&s.jsx("text",{className:"aegis-line-chart__tick",x:(o+h)/2,y:r-y,textAnchor:"middle",children:N}),c&&s.jsx("rect",{className:"aegis-line-chart__seek",x:o,y:j,width:h-o,height:p-j,role:"slider",tabIndex:0,"aria-label":q.replayPosition,"aria-valuemin":i,"aria-valuemax":_,"aria-valuenow":l??i,"aria-valuetext":S(l??i),onClick:O,onKeyDown:U}),B.map(t=>s.jsx("circle",{className:"aegis-line-chart__marker",cx:x(t.x),cy:p,r:J,style:{fill:A.chartColorValue(t.color)},onClick:c?()=>{c(t.x)}:void 0,children:s.jsx("title",{children:t.label})},t.key))]})})}exports.LineChart=Q;
|
|
2
2
|
//# sourceMappingURL=LineChart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.cjs","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 /** 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 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 {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","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","target","jsxs","tick","chartColorValue","marker"],"mappings":"oSA2DMA,EAAS,IACTC,EAAW,GACXC,EAAY,EACZC,EAAU,GACVC,EAAa,GACbC,EAAgB,EAChBC,EAAiB,GACjBC,EAAgB,EAMf,SAASC,EAAU,CACxB,OAAAC,EACA,MAAAC,EACA,OAAAC,EACA,OAAAC,EACA,QAAAC,EAAU,OACV,QAAAC,EAAU,OACV,SAAAC,EACA,OAAAC,EACA,QAAAC,EAAU,CAAA,EACV,SAAAC,EACA,UAAAC,CACF,EAAi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A,CACnB,EACF,EAEFkB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGO,EACH,EAAGxC,EAASK,EACZ,WAAW,QAEV,WAAQ6B,CAAG,CAAA,CAAA,EAEdD,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGQ,EACH,EAAGzC,EAASK,EACZ,WAAW,MAEV,WAAQ8B,CAAG,CAAA,CAAA,EAEbxB,IAAW,QACVsB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,GAAIO,EAAOC,GAAS,EACpB,EAAGzC,EAASK,EACZ,WAAW,SAEV,SAAAM,CAAA,CAAA,EAGJK,GACCiB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGO,EACHE,EACA,MAAOD,EAAQD,EACf,OAAQG,EAASD,EACjB,KAAK,SACL,SAAU,EACV,aAAYtB,EAAQ,eACpB,gBAAec,EACf,gBAAeC,EACf,gBAAepB,GAAYmB,EAC3B,iBAAgBrB,EAAQE,GAAYmB,CAAG,EACvC,QAASoB,EACT,UAAWI,CAAA,CAAA,EAGdzC,EAAQ,IAAK+C,GACZ/B,EAAAA,IAAC,SAAA,CAEC,UAAU,2BACV,GAAIW,EAAGoB,EAAO,CAAC,EACf,GAAIrB,EACJ,EAAGpC,EACH,MAAO,CAAE,KAAMwD,EAAAA,gBAAgBC,EAAO,KAAK,CAAA,EAC3C,QACEhD,EACI,IAAM,CACJA,EAAOgD,EAAO,CAAC,CACjB,EACA,OAGN,SAAA/B,EAAAA,IAAC,QAAA,CAAO,SAAA+B,EAAO,KAAA,CAAM,CAAA,EAdhBA,EAAO,GAAA,CAgBf,CAAA,CAAA,CAAA,EAEL,CAEJ"}
|
|
1
|
+
{"version":3,"file":"LineChart.cjs","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":"oSAqEMA,EAAS,IACTC,EAAW,GACXC,EAAY,EACZC,EAAU,GACVC,EAAa,GACbC,EAAgB,EAChBC,EAAiB,GACjBC,EAAgB,EAMf,SAASC,EAAU,CACxB,OAAAC,EACA,MAAAC,EACA,UAAAC,EAAY,GACZ,OAAAC,EACA,OAAAC,EACA,QAAAC,EAAU,OACV,QAAAC,EAAU,OACV,SAAAC,EACA,OAAAC,EACA,QAAAC,EAAU,CAAA,EACV,SAAAC,EACA,UAAAC,CACF,EAAiC,CAC/B,MAAMC,EAAUC,EAAAA,WAAA,EACVC,EAASC,EAAAA,MAAA,EACTC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAQC,EAAAA,gBAAgBH,CAAO,EAC/BI,EAASpB,EAAO,QAASqB,GAASA,EAAK,MAAM,EAC7CC,EAAK,CAAC,GAAG,IAAI,IAAIF,EAAO,IAAKG,GAAUA,EAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAACC,EAAGC,IAAMD,EAAIC,CAAC,EACtEC,EAAM,CAAC,mBAAoBf,GAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAC1E,GAAIO,IAAU,GAAKI,EAAG,SAAW,EAC/B,OAAOK,EAAAA,IAAC,MAAA,CAAI,IAAKX,EAAS,UAAWU,EAAK,EAG5C,MAAME,EAAMN,EAAG,CAAC,EACVO,EAAMP,EAAGA,EAAG,OA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A,EAEL,CAEJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { ChartColor } from '../../lib/chart';
|
|
2
|
+
import { ChartColor, ChartLineStyle } from '../../lib/chart';
|
|
3
3
|
export interface LineChartPoint {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
@@ -9,6 +9,7 @@ export interface LineChartSeries {
|
|
|
9
9
|
/** Written at the end of the line, with its last value. */
|
|
10
10
|
label: string;
|
|
11
11
|
color: ChartColor;
|
|
12
|
+
lineStyle?: ChartLineStyle;
|
|
12
13
|
points: LineChartPoint[];
|
|
13
14
|
}
|
|
14
15
|
export interface LineChartMarker {
|
|
@@ -22,6 +23,8 @@ export interface LineChartProps {
|
|
|
22
23
|
series: LineChartSeries[];
|
|
23
24
|
/** Names the chart for a screen reader. */
|
|
24
25
|
label: string;
|
|
26
|
+
/** False when the host supplies a separate series legend. */
|
|
27
|
+
endLabels?: boolean;
|
|
25
28
|
/** Names the horizontal axis, e.g. "回合". */
|
|
26
29
|
xLabel?: string;
|
|
27
30
|
/** The gridlines. Defaults to about five round values. */
|
|
@@ -45,4 +48,4 @@ export interface LineChartProps {
|
|
|
45
48
|
* Lines over a shared horizontal axis, labelled at their ends instead of
|
|
46
49
|
* in a legend, with an optional playhead the reader can move.
|
|
47
50
|
*/
|
|
48
|
-
export declare function LineChart({ series, label, xLabel, yTicks, formatX, formatY, playhead, onSeek, markers, progress, className, }: LineChartProps): ReactElement;
|
|
51
|
+
export declare function LineChart({ series, label, endLabels, xLabel, yTicks, formatX, formatY, playhead, onSeek, markers, progress, className, }: LineChartProps): ReactElement;
|
|
@@ -1,191 +1,223 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { useElementWidth as
|
|
4
|
-
import { niceTicks as
|
|
1
|
+
import { jsx as i, jsxs as N } from "react/jsx-runtime";
|
|
2
|
+
import { useId as G, useRef as K } from "react";
|
|
3
|
+
import { useElementWidth as V } from "../../hooks/useElementWidth.js";
|
|
4
|
+
import { niceTicks as W, chartLineDash as q, chartColorValue as k } from "../../lib/chart.js";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { useStrings as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
series:
|
|
10
|
-
label:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
import { useStrings as z } from "../../locale/useStrings.js";
|
|
7
|
+
const c = 240, J = 32, Q = 8, Z = 20, X = 28, m = 8, R = 16, Y = 4;
|
|
8
|
+
function ot({
|
|
9
|
+
series: v,
|
|
10
|
+
label: T,
|
|
11
|
+
endLabels: B = !0,
|
|
12
|
+
xLabel: w,
|
|
13
|
+
yTicks: I,
|
|
14
|
+
formatX: A = String,
|
|
15
|
+
formatY: D = String,
|
|
16
|
+
playhead: o,
|
|
16
17
|
onSeek: r,
|
|
17
|
-
markers:
|
|
18
|
-
progress:
|
|
19
|
-
className:
|
|
18
|
+
markers: H = [],
|
|
19
|
+
progress: x,
|
|
20
|
+
className: j
|
|
20
21
|
}) {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
return /* @__PURE__ */
|
|
24
|
-
const
|
|
22
|
+
const C = z(), $ = G(), S = K(null), _ = V(S), L = v.flatMap((t) => t.points), n = [...new Set(L.map((t) => t.x))].sort((t, e) => t - e), E = ["aegis-line-chart", j ?? ""].filter(Boolean).join(" ");
|
|
23
|
+
if (_ === 0 || n.length === 0)
|
|
24
|
+
return /* @__PURE__ */ i("div", { ref: S, className: E });
|
|
25
|
+
const s = n[0], p = n[n.length - 1], M = L.map((t) => t.y), b = I ?? W(0, Math.max(...M, 1)), O = Math.max(...b, ...M), l = J, h = _ - Q, u = Z, f = c - X, d = (t) => l + (p > s ? (t - s) / (p - s) : 0) * (h - l), g = (t) => f - t / O * (f - u), y = v.flatMap((t) => {
|
|
25
26
|
const e = t.points[t.points.length - 1];
|
|
26
|
-
return e === void 0 ? [] : [{ line: t, last: e, y:
|
|
27
|
+
return e === void 0 ? [] : [{ line: t, last: e, y: g(e.y) }];
|
|
27
28
|
}).sort((t, e) => e.y - t.y);
|
|
28
|
-
for (let t = 1; t <
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
(e,
|
|
32
|
-
),
|
|
33
|
-
const e = t.currentTarget.getBoundingClientRect(),
|
|
34
|
-
r?.(
|
|
35
|
-
},
|
|
36
|
-
const e =
|
|
29
|
+
for (let t = 1; t < y.length; t += 1)
|
|
30
|
+
y[t - 1].y - y[t].y < R && (y[t].y = y[t - 1].y - R);
|
|
31
|
+
const P = (t) => n.reduce(
|
|
32
|
+
(e, a) => Math.abs(a - t) < Math.abs(e - t) ? a : e
|
|
33
|
+
), U = (t) => {
|
|
34
|
+
const e = t.currentTarget.getBoundingClientRect(), a = (t.clientX - e.left) / e.width;
|
|
35
|
+
r?.(P(s + a * (p - s)));
|
|
36
|
+
}, F = (t) => {
|
|
37
|
+
const e = n.indexOf(P(o ?? s)), a = {
|
|
37
38
|
ArrowLeft: e - 1,
|
|
38
39
|
ArrowDown: e - 1,
|
|
39
40
|
ArrowRight: e + 1,
|
|
40
41
|
ArrowUp: e + 1,
|
|
41
42
|
Home: 0,
|
|
42
|
-
End:
|
|
43
|
+
End: n.length - 1
|
|
43
44
|
};
|
|
44
|
-
t.key in
|
|
45
|
+
t.key in a && (t.preventDefault(), r?.(n[Math.min(Math.max(a[t.key], 0), n.length - 1)]));
|
|
45
46
|
};
|
|
46
|
-
return /* @__PURE__ */
|
|
47
|
+
return /* @__PURE__ */ i("div", { ref: S, className: E, children: /* @__PURE__ */ N(
|
|
47
48
|
"svg",
|
|
48
49
|
{
|
|
49
50
|
className: "aegis-line-chart__svg",
|
|
50
|
-
width:
|
|
51
|
-
height:
|
|
52
|
-
viewBox: `0 0 ${
|
|
51
|
+
width: _,
|
|
52
|
+
height: c,
|
|
53
|
+
viewBox: `0 0 ${_.toString()} ${c.toString()}`,
|
|
53
54
|
role: r ? "group" : "img",
|
|
54
|
-
"aria-label":
|
|
55
|
+
"aria-label": T,
|
|
55
56
|
children: [
|
|
56
|
-
|
|
57
|
-
/* @__PURE__ */
|
|
57
|
+
b.map((t) => /* @__PURE__ */ N("g", { children: [
|
|
58
|
+
/* @__PURE__ */ i(
|
|
58
59
|
"line",
|
|
59
60
|
{
|
|
60
61
|
className: "aegis-line-chart__grid",
|
|
61
|
-
x1:
|
|
62
|
-
x2:
|
|
63
|
-
y1:
|
|
64
|
-
y2:
|
|
62
|
+
x1: l,
|
|
63
|
+
x2: h,
|
|
64
|
+
y1: g(t),
|
|
65
|
+
y2: g(t)
|
|
65
66
|
}
|
|
66
67
|
),
|
|
67
|
-
/* @__PURE__ */
|
|
68
|
+
/* @__PURE__ */ i(
|
|
68
69
|
"text",
|
|
69
70
|
{
|
|
70
71
|
className: "aegis-line-chart__tick",
|
|
71
|
-
x:
|
|
72
|
-
y:
|
|
72
|
+
x: l - m,
|
|
73
|
+
y: g(t),
|
|
73
74
|
textAnchor: "end",
|
|
74
75
|
dominantBaseline: "middle",
|
|
75
|
-
children:
|
|
76
|
+
children: D(t)
|
|
76
77
|
}
|
|
77
78
|
)
|
|
78
79
|
] }, t)),
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
v.map((t) => /* @__PURE__ */ N("g", { children: [
|
|
81
|
+
t.lineStyle && t.lineStyle !== "solid" && x !== void 0 && /* @__PURE__ */ i(
|
|
82
|
+
"mask",
|
|
83
|
+
{
|
|
84
|
+
id: `${$}-${t.key}`,
|
|
85
|
+
maskUnits: "userSpaceOnUse",
|
|
86
|
+
x: 0,
|
|
87
|
+
y: 0,
|
|
88
|
+
width: _,
|
|
89
|
+
height: c,
|
|
90
|
+
children: /* @__PURE__ */ i(
|
|
91
|
+
"polyline",
|
|
92
|
+
{
|
|
93
|
+
className: "aegis-line-chart__line",
|
|
94
|
+
pathLength: 1,
|
|
95
|
+
points: t.points.map(
|
|
96
|
+
(e) => `${d(e.x).toString()},${g(e.y).toString()}`
|
|
97
|
+
).join(" "),
|
|
98
|
+
style: {
|
|
99
|
+
stroke: "white",
|
|
100
|
+
"--aegis-line-chart-progress": x
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
)
|
|
90
104
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ i(
|
|
107
|
+
"polyline",
|
|
108
|
+
{
|
|
109
|
+
className: "aegis-line-chart__line",
|
|
110
|
+
pathLength: !t.lineStyle || t.lineStyle === "solid" ? 1 : void 0,
|
|
111
|
+
mask: t.lineStyle && t.lineStyle !== "solid" && x !== void 0 ? `url(#${$}-${t.key})` : void 0,
|
|
112
|
+
points: t.points.map(
|
|
113
|
+
(e) => `${d(e.x).toString()},${g(e.y).toString()}`
|
|
114
|
+
).join(" "),
|
|
115
|
+
style: {
|
|
116
|
+
stroke: k(t.color),
|
|
117
|
+
...t.lineStyle && t.lineStyle !== "solid" ? {
|
|
118
|
+
strokeDasharray: q(t.lineStyle),
|
|
119
|
+
strokeDashoffset: 0
|
|
120
|
+
} : {},
|
|
121
|
+
...x === void 0 ? {} : { "--aegis-line-chart-progress": x }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
] }, t.key)),
|
|
126
|
+
B && y.map(({ line: t, last: e, y: a }) => /* @__PURE__ */ i(
|
|
95
127
|
"text",
|
|
96
128
|
{
|
|
97
129
|
className: "aegis-line-chart__end-label",
|
|
98
|
-
x:
|
|
99
|
-
y:
|
|
130
|
+
x: h,
|
|
131
|
+
y: a - m,
|
|
100
132
|
textAnchor: "end",
|
|
101
|
-
style: { fill:
|
|
102
|
-
children: `${t.label} ${
|
|
133
|
+
style: { fill: k(t.color) },
|
|
134
|
+
children: `${t.label} ${D(e.y)}`
|
|
103
135
|
},
|
|
104
136
|
t.key
|
|
105
137
|
)),
|
|
106
|
-
|
|
107
|
-
/* @__PURE__ */
|
|
138
|
+
o !== void 0 && /* @__PURE__ */ N("g", { children: [
|
|
139
|
+
/* @__PURE__ */ i(
|
|
108
140
|
"line",
|
|
109
141
|
{
|
|
110
142
|
className: "aegis-line-chart__playhead",
|
|
111
|
-
x1:
|
|
112
|
-
x2:
|
|
113
|
-
y1:
|
|
114
|
-
y2:
|
|
143
|
+
x1: d(o),
|
|
144
|
+
x2: d(o),
|
|
145
|
+
y1: u,
|
|
146
|
+
y2: f
|
|
115
147
|
}
|
|
116
148
|
),
|
|
117
|
-
/* @__PURE__ */
|
|
149
|
+
/* @__PURE__ */ i(
|
|
118
150
|
"text",
|
|
119
151
|
{
|
|
120
152
|
className: "aegis-line-chart__playhead-label",
|
|
121
|
-
x:
|
|
122
|
-
y:
|
|
153
|
+
x: d(o),
|
|
154
|
+
y: u - m / 2,
|
|
123
155
|
textAnchor: "middle",
|
|
124
|
-
children:
|
|
156
|
+
children: A(o)
|
|
125
157
|
}
|
|
126
158
|
)
|
|
127
159
|
] }),
|
|
128
|
-
/* @__PURE__ */
|
|
160
|
+
/* @__PURE__ */ i(
|
|
129
161
|
"text",
|
|
130
162
|
{
|
|
131
163
|
className: "aegis-line-chart__tick",
|
|
132
|
-
x:
|
|
133
|
-
y:
|
|
164
|
+
x: l,
|
|
165
|
+
y: c - m,
|
|
134
166
|
textAnchor: "start",
|
|
135
|
-
children:
|
|
167
|
+
children: A(s)
|
|
136
168
|
}
|
|
137
169
|
),
|
|
138
|
-
/* @__PURE__ */
|
|
170
|
+
/* @__PURE__ */ i(
|
|
139
171
|
"text",
|
|
140
172
|
{
|
|
141
173
|
className: "aegis-line-chart__tick",
|
|
142
|
-
x:
|
|
143
|
-
y:
|
|
174
|
+
x: h,
|
|
175
|
+
y: c - m,
|
|
144
176
|
textAnchor: "end",
|
|
145
|
-
children:
|
|
177
|
+
children: A(p)
|
|
146
178
|
}
|
|
147
179
|
),
|
|
148
|
-
|
|
180
|
+
w !== void 0 && /* @__PURE__ */ i(
|
|
149
181
|
"text",
|
|
150
182
|
{
|
|
151
183
|
className: "aegis-line-chart__tick",
|
|
152
|
-
x: (
|
|
153
|
-
y:
|
|
184
|
+
x: (l + h) / 2,
|
|
185
|
+
y: c - m,
|
|
154
186
|
textAnchor: "middle",
|
|
155
|
-
children:
|
|
187
|
+
children: w
|
|
156
188
|
}
|
|
157
189
|
),
|
|
158
|
-
r && /* @__PURE__ */
|
|
190
|
+
r && /* @__PURE__ */ i(
|
|
159
191
|
"rect",
|
|
160
192
|
{
|
|
161
193
|
className: "aegis-line-chart__seek",
|
|
162
|
-
x:
|
|
163
|
-
y:
|
|
164
|
-
width:
|
|
165
|
-
height:
|
|
194
|
+
x: l,
|
|
195
|
+
y: u,
|
|
196
|
+
width: h - l,
|
|
197
|
+
height: f - u,
|
|
166
198
|
role: "slider",
|
|
167
199
|
tabIndex: 0,
|
|
168
|
-
"aria-label":
|
|
169
|
-
"aria-valuemin":
|
|
170
|
-
"aria-valuemax":
|
|
171
|
-
"aria-valuenow":
|
|
172
|
-
"aria-valuetext":
|
|
173
|
-
onClick:
|
|
174
|
-
onKeyDown:
|
|
200
|
+
"aria-label": C.replayPosition,
|
|
201
|
+
"aria-valuemin": s,
|
|
202
|
+
"aria-valuemax": p,
|
|
203
|
+
"aria-valuenow": o ?? s,
|
|
204
|
+
"aria-valuetext": A(o ?? s),
|
|
205
|
+
onClick: U,
|
|
206
|
+
onKeyDown: F
|
|
175
207
|
}
|
|
176
208
|
),
|
|
177
|
-
|
|
209
|
+
H.map((t) => /* @__PURE__ */ i(
|
|
178
210
|
"circle",
|
|
179
211
|
{
|
|
180
212
|
className: "aegis-line-chart__marker",
|
|
181
|
-
cx:
|
|
182
|
-
cy:
|
|
183
|
-
r:
|
|
184
|
-
style: { fill:
|
|
213
|
+
cx: d(t.x),
|
|
214
|
+
cy: f,
|
|
215
|
+
r: Y,
|
|
216
|
+
style: { fill: k(t.color) },
|
|
185
217
|
onClick: r ? () => {
|
|
186
218
|
r(t.x);
|
|
187
219
|
} : void 0,
|
|
188
|
-
children: /* @__PURE__ */
|
|
220
|
+
children: /* @__PURE__ */ i("title", { children: t.label })
|
|
189
221
|
},
|
|
190
222
|
t.key
|
|
191
223
|
))
|
|
@@ -194,6 +226,6 @@ function nt({
|
|
|
194
226
|
) });
|
|
195
227
|
}
|
|
196
228
|
export {
|
|
197
|
-
|
|
229
|
+
ot as LineChart
|
|
198
230
|
};
|
|
199
231
|
//# sourceMappingURL=LineChart.js.map
|
|
@@ -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 /** 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 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 {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","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","target","jsxs","tick","chartColorValue","marker"],"mappings":";;;;;;AA2DA,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,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,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,EAAgBH,CAAO,GAC/BI,IAASjB,EAAO,QAAQ,CAACkB,MAASA,EAAK,MAAM,GAC7CC,IAAK,CAAC,GAAG,IAAI,IAAIF,EAAO,IAAI,CAACG,MAAUA,EAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAACC,GAAGC,MAAMD,IAAIC,CAAC,GACtEC,IAAM,CAAC,oBAAoBb,KAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAC1E,MAAIK,MAAU,KAAKI,EAAG,WAAW;AAC/B,WAAO,gBAAAK,EAAC,OAAA,EAAI,KAAKX,GAAS,WAAWU,GAAK;AAG5C,QAAME,IAAMN,EAAG,CAAC,GACVO,IAAMP,EAAGA,EAAG,SAAS,CAAC,GACtBQ,IAASV,EAAO,IAAI,CAACG,MAAUA,EAAM,CAAC,GACtCQ,IAAQzB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C;AAAA,YACjB,IACA;AAAA,YAGN,UAAA,gBAAA/B,EAAC,SAAA,EAAO,UAAA+B,EAAO,MAAA,CAAM;AAAA,UAAA;AAAA,UAdhBA,EAAO;AAAA,QAAA,CAgBf;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAEL;AAEJ;"}
|
|
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 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,GACrC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gBAAAhC;AAAA,UAAC;AAAA,UAAA;AAAA,YAEC,WAAU;AAAA,YACV,IAAIW,EAAGqB,EAAO,CAAC;AAAA,YACf,IAAItB;AAAA,YACJ,GAAGvC;AAAA,YACH,OAAO,EAAE,MAAM2D,EAAgBE,EAAO,KAAK,EAAA;AAAA,YAC3C,SACEnD,IACI,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"),
|
|
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 {
|
|
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;
|