@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.
- package/dist/components/ui/Collapse.cjs +1 -1
- package/dist/components/ui/Collapse.cjs.map +1 -1
- package/dist/components/ui/Collapse.js +23 -20
- package/dist/components/ui/Collapse.js.map +1 -1
- package/dist/components/ui/LineChart.cjs +1 -1
- package/dist/components/ui/LineChart.cjs.map +1 -1
- package/dist/components/ui/LineChart.d.ts +2 -1
- package/dist/components/ui/LineChart.js +138 -107
- 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"),r=require("react"),f=require("@ant-design/icons");;/* empty css */function v({items:t,activeKeys:c,defaultActiveKeys:d=[],onChange:p,className:u}){const[g,_]=r.useState(d),a=c??g,[n,h]=r.useState(a),o=a.filter(e=>!n.includes(e));o.length>0&&h([...n,...o]);const x=["aegis-collapse",u??""].filter(Boolean).join(" "),j=e=>{const l=a.includes(e)?a.filter(i=>i!==e):[...a,e];c===void 0&&_(l),p?.(l)};return s.jsx("div",{className:x,children:t.map(e=>{const l=a.includes(e.key);return s.jsxs("div",{className:"aegis-collapse__item",children:[s.jsxs("button",{type:"button",className:"aegis-collapse__header","aria-expanded":l,"aria-controls":`aegis-collapse-${e.key}`,onClick:()=>{j(e.key)},children:[s.jsx("span",{className:"aegis-collapse__label",children:e.label}),s.jsx(f.RightOutlined,{className:"aegis-collapse__chevron","aria-hidden":!0})]}),s.jsx("div",{ref:i=>{i!==null&&(i.inert=!l)},id:`aegis-collapse-${e.key}`,className:l?"aegis-collapse__panel aegis-collapse__panel--open":"aegis-collapse__panel",role:"region",children:s.jsx("div",{className:"aegis-collapse__clip",children:s.jsx("div",{className:"aegis-collapse__body",children:(l||n.includes(e.key))&&e.children})})})]},e.key)})})}exports.Collapse=v;
|
|
2
2
|
//# sourceMappingURL=Collapse.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collapse.cjs","sources":["../../../src/components/ui/Collapse.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport './Collapse.css';\n\nexport interface CollapseItem {\n key: string;\n label: ReactNode;\n children: ReactNode;\n}\n\ninterface CollapseProps {\n items: CollapseItem[];\n /** Controlled open keys. Omit for uncontrolled behaviour. */\n activeKeys?: string[];\n defaultActiveKeys?: string[];\n onChange?: (keys: string[]) => void;\n className?: string;\n}\n\nexport function Collapse({\n items,\n activeKeys,\n defaultActiveKeys = [],\n onChange,\n className,\n}: CollapseProps) {\n const [internal, setInternal] = useState<string[]>(defaultActiveKeys);\n const open = activeKeys ?? internal;\n // A panel mounts its children the first time it opens and keeps them, so\n // closing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState<string[]>(open);\n const unvisited = open.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const cls = ['aegis-collapse', className ?? ''].filter(Boolean).join(' ');\n const toggle = (key: string): void => {\n const next = open.includes(key)\n ? open.filter((item) => item !== key)\n : [...open, key];\n if (activeKeys === undefined) {\n setInternal(next);\n }\n onChange?.(next);\n };\n return (\n <div className={cls}>\n {items.map((item) => {\n const expanded = open.includes(item.key);\n return (\n <div className=\"aegis-collapse__item\" key={item.key}>\n <button\n type=\"button\"\n className=\"aegis-collapse__header\"\n aria-expanded={expanded}\n aria-controls={`aegis-collapse-${item.key}`}\n onClick={() => {\n toggle(item.key);\n }}\n >\n <span className=\"aegis-collapse__label\">{item.label}</span>\n <RightOutlined className=\"aegis-collapse__chevron\" aria-hidden />\n </button>\n <div\n id={`aegis-collapse-${item.key}`}\n className={\n expanded\n ? 'aegis-collapse__panel aegis-collapse__panel--open'\n : 'aegis-collapse__panel'\n }\n role=\"region\"\n >\n <div className=\"aegis-collapse__clip\">\n <div className=\"aegis-collapse__body\">\n {(expanded || visited.includes(item.key)) && item.children}\n </div>\n </div>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"names":["Collapse","items","activeKeys","defaultActiveKeys","onChange","className","internal","setInternal","useState","open","visited","setVisited","unvisited","key","cls","toggle","next","item","expanded","jsxs","jsx","RightOutlined"],"mappings":"qMAqBO,SAASA,EAAS,CACvB,MAAAC,EACA,WAAAC,EACA,kBAAAC,EAAoB,CAAA,EACpB,SAAAC,EACA,UAAAC,CACF,EAAkB,CAChB,KAAM,CAACC,EAAUC,CAAW,EAAIC,EAAAA,SAAmBL,CAAiB,EAC9DM,EAAOP,GAAcI,EAGrB,CAACI,EAASC,CAAU,EAAIH,EAAAA,SAAmBC,CAAI,EAC/CG,EAAYH,EAAK,OAAQI,GAAQ,CAACH,EAAQ,SAASG,CAAG,CAAC,EACzDD,EAAU,OAAS,GACrBD,EAAW,CAAC,GAAGD,EAAS,GAAGE,CAAS,CAAC,EAEvC,MAAME,EAAM,CAAC,iBAAkBT,GAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAClEU,EAAUF,GAAsB,CACpC,MAAMG,EAAOP,EAAK,SAASI,CAAG,EAC1BJ,EAAK,OAAQQ,GAASA,IAASJ,CAAG,EAClC,CAAC,GAAGJ,EAAMI,CAAG,EACbX,IAAe,QACjBK,EAAYS,CAAI,EAElBZ,IAAWY,CAAI,CACjB,EACA,aACG,MAAA,CAAI,UAAWF,EACb,SAAAb,EAAM,IAAKgB,GAAS,CACnB,MAAMC,EAAWT,EAAK,SAASQ,EAAK,GAAG,EACvC,OACEE,EAAAA,KAAC,MAAA,CAAI,UAAU,uBACb,SAAA,CAAAA,EAAAA,KAAC,SAAA,CACC,KAAK,SACL,UAAU,yBACV,gBAAeD,EACf,gBAAe,kBAAkBD,EAAK,GAAG,GACzC,QAAS,IAAM,CACbF,EAAOE,EAAK,GAAG,CACjB,EAEA,SAAA,CAAAG,EAAAA,IAAC,OAAA,CAAK,UAAU,wBAAyB,SAAAH,EAAK,MAAM,EACpDG,EAAAA,IAACC,EAAAA,cAAA,CAAc,UAAU,0BAA0B,cAAW,EAAA,CAAC,CAAA,CAAA,CAAA,EAEjED,EAAAA,IAAC,MAAA,CACC,GAAI,
|
|
1
|
+
{"version":3,"file":"Collapse.cjs","sources":["../../../src/components/ui/Collapse.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport './Collapse.css';\n\nexport interface CollapseItem {\n key: string;\n label: ReactNode;\n children: ReactNode;\n}\n\ninterface CollapseProps {\n items: CollapseItem[];\n /** Controlled open keys. Omit for uncontrolled behaviour. */\n activeKeys?: string[];\n defaultActiveKeys?: string[];\n onChange?: (keys: string[]) => void;\n className?: string;\n}\n\nexport function Collapse({\n items,\n activeKeys,\n defaultActiveKeys = [],\n onChange,\n className,\n}: CollapseProps) {\n const [internal, setInternal] = useState<string[]>(defaultActiveKeys);\n const open = activeKeys ?? internal;\n // A panel mounts its children the first time it opens and keeps them, so\n // closing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState<string[]>(open);\n const unvisited = open.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const cls = ['aegis-collapse', className ?? ''].filter(Boolean).join(' ');\n const toggle = (key: string): void => {\n const next = open.includes(key)\n ? open.filter((item) => item !== key)\n : [...open, key];\n if (activeKeys === undefined) {\n setInternal(next);\n }\n onChange?.(next);\n };\n return (\n <div className={cls}>\n {items.map((item) => {\n const expanded = open.includes(item.key);\n return (\n <div className=\"aegis-collapse__item\" key={item.key}>\n <button\n type=\"button\"\n className=\"aegis-collapse__header\"\n aria-expanded={expanded}\n aria-controls={`aegis-collapse-${item.key}`}\n onClick={() => {\n toggle(item.key);\n }}\n >\n <span className=\"aegis-collapse__label\">{item.label}</span>\n <RightOutlined className=\"aegis-collapse__chevron\" aria-hidden />\n </button>\n <div\n ref={(element) => {\n if (element !== null) {\n element.inert = !expanded;\n }\n }}\n id={`aegis-collapse-${item.key}`}\n className={\n expanded\n ? 'aegis-collapse__panel aegis-collapse__panel--open'\n : 'aegis-collapse__panel'\n }\n role=\"region\"\n >\n <div className=\"aegis-collapse__clip\">\n <div className=\"aegis-collapse__body\">\n {(expanded || visited.includes(item.key)) && item.children}\n </div>\n </div>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"names":["Collapse","items","activeKeys","defaultActiveKeys","onChange","className","internal","setInternal","useState","open","visited","setVisited","unvisited","key","cls","toggle","next","item","expanded","jsxs","jsx","RightOutlined","element"],"mappings":"qMAqBO,SAASA,EAAS,CACvB,MAAAC,EACA,WAAAC,EACA,kBAAAC,EAAoB,CAAA,EACpB,SAAAC,EACA,UAAAC,CACF,EAAkB,CAChB,KAAM,CAACC,EAAUC,CAAW,EAAIC,EAAAA,SAAmBL,CAAiB,EAC9DM,EAAOP,GAAcI,EAGrB,CAACI,EAASC,CAAU,EAAIH,EAAAA,SAAmBC,CAAI,EAC/CG,EAAYH,EAAK,OAAQI,GAAQ,CAACH,EAAQ,SAASG,CAAG,CAAC,EACzDD,EAAU,OAAS,GACrBD,EAAW,CAAC,GAAGD,EAAS,GAAGE,CAAS,CAAC,EAEvC,MAAME,EAAM,CAAC,iBAA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|
2
|
+
import { useState as t } from "react";
|
|
3
3
|
import { RightOutlined as N } from "@ant-design/icons";
|
|
4
4
|
/* empty css */
|
|
5
5
|
function j({
|
|
6
|
-
items:
|
|
7
|
-
activeKeys:
|
|
8
|
-
defaultActiveKeys:
|
|
9
|
-
onChange:
|
|
10
|
-
className:
|
|
6
|
+
items: d,
|
|
7
|
+
activeKeys: o,
|
|
8
|
+
defaultActiveKeys: p = [],
|
|
9
|
+
onChange: _,
|
|
10
|
+
className: g
|
|
11
11
|
}) {
|
|
12
|
-
const [
|
|
13
|
-
|
|
14
|
-
const m = ["aegis-collapse",
|
|
15
|
-
const
|
|
16
|
-
|
|
12
|
+
const [u, h] = t(p), s = o ?? u, [n, f] = t(s), c = s.filter((e) => !n.includes(e));
|
|
13
|
+
c.length > 0 && f([...n, ...c]);
|
|
14
|
+
const m = ["aegis-collapse", g ?? ""].filter(Boolean).join(" "), v = (e) => {
|
|
15
|
+
const l = s.includes(e) ? s.filter((i) => i !== e) : [...s, e];
|
|
16
|
+
o === void 0 && h(l), _?.(l);
|
|
17
17
|
};
|
|
18
|
-
return /* @__PURE__ */ a("div", { className: m, children:
|
|
19
|
-
const
|
|
20
|
-
return /* @__PURE__ */
|
|
21
|
-
/* @__PURE__ */
|
|
18
|
+
return /* @__PURE__ */ a("div", { className: m, children: d.map((e) => {
|
|
19
|
+
const l = s.includes(e.key);
|
|
20
|
+
return /* @__PURE__ */ r("div", { className: "aegis-collapse__item", children: [
|
|
21
|
+
/* @__PURE__ */ r(
|
|
22
22
|
"button",
|
|
23
23
|
{
|
|
24
24
|
type: "button",
|
|
25
25
|
className: "aegis-collapse__header",
|
|
26
|
-
"aria-expanded":
|
|
26
|
+
"aria-expanded": l,
|
|
27
27
|
"aria-controls": `aegis-collapse-${e.key}`,
|
|
28
28
|
onClick: () => {
|
|
29
|
-
|
|
29
|
+
v(e.key);
|
|
30
30
|
},
|
|
31
31
|
children: [
|
|
32
32
|
/* @__PURE__ */ a("span", { className: "aegis-collapse__label", children: e.label }),
|
|
@@ -37,10 +37,13 @@ function j({
|
|
|
37
37
|
/* @__PURE__ */ a(
|
|
38
38
|
"div",
|
|
39
39
|
{
|
|
40
|
+
ref: (i) => {
|
|
41
|
+
i !== null && (i.inert = !l);
|
|
42
|
+
},
|
|
40
43
|
id: `aegis-collapse-${e.key}`,
|
|
41
|
-
className:
|
|
44
|
+
className: l ? "aegis-collapse__panel aegis-collapse__panel--open" : "aegis-collapse__panel",
|
|
42
45
|
role: "region",
|
|
43
|
-
children: /* @__PURE__ */ a("div", { className: "aegis-collapse__clip", children: /* @__PURE__ */ a("div", { className: "aegis-collapse__body", children: (
|
|
46
|
+
children: /* @__PURE__ */ a("div", { className: "aegis-collapse__clip", children: /* @__PURE__ */ a("div", { className: "aegis-collapse__body", children: (l || n.includes(e.key)) && e.children }) })
|
|
44
47
|
}
|
|
45
48
|
)
|
|
46
49
|
] }, e.key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collapse.js","sources":["../../../src/components/ui/Collapse.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport './Collapse.css';\n\nexport interface CollapseItem {\n key: string;\n label: ReactNode;\n children: ReactNode;\n}\n\ninterface CollapseProps {\n items: CollapseItem[];\n /** Controlled open keys. Omit for uncontrolled behaviour. */\n activeKeys?: string[];\n defaultActiveKeys?: string[];\n onChange?: (keys: string[]) => void;\n className?: string;\n}\n\nexport function Collapse({\n items,\n activeKeys,\n defaultActiveKeys = [],\n onChange,\n className,\n}: CollapseProps) {\n const [internal, setInternal] = useState<string[]>(defaultActiveKeys);\n const open = activeKeys ?? internal;\n // A panel mounts its children the first time it opens and keeps them, so\n // closing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState<string[]>(open);\n const unvisited = open.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const cls = ['aegis-collapse', className ?? ''].filter(Boolean).join(' ');\n const toggle = (key: string): void => {\n const next = open.includes(key)\n ? open.filter((item) => item !== key)\n : [...open, key];\n if (activeKeys === undefined) {\n setInternal(next);\n }\n onChange?.(next);\n };\n return (\n <div className={cls}>\n {items.map((item) => {\n const expanded = open.includes(item.key);\n return (\n <div className=\"aegis-collapse__item\" key={item.key}>\n <button\n type=\"button\"\n className=\"aegis-collapse__header\"\n aria-expanded={expanded}\n aria-controls={`aegis-collapse-${item.key}`}\n onClick={() => {\n toggle(item.key);\n }}\n >\n <span className=\"aegis-collapse__label\">{item.label}</span>\n <RightOutlined className=\"aegis-collapse__chevron\" aria-hidden />\n </button>\n <div\n id={`aegis-collapse-${item.key}`}\n className={\n expanded\n ? 'aegis-collapse__panel aegis-collapse__panel--open'\n : 'aegis-collapse__panel'\n }\n role=\"region\"\n >\n <div className=\"aegis-collapse__clip\">\n <div className=\"aegis-collapse__body\">\n {(expanded || visited.includes(item.key)) && item.children}\n </div>\n </div>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"names":["Collapse","items","activeKeys","defaultActiveKeys","onChange","className","internal","setInternal","useState","open","visited","setVisited","unvisited","key","cls","toggle","next","item","expanded","jsxs","jsx","RightOutlined"],"mappings":";;;;AAqBO,SAASA,EAAS;AAAA,EACvB,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,mBAAAC,IAAoB,CAAA;AAAA,EACpB,UAAAC;AAAA,EACA,WAAAC;AACF,GAAkB;AAChB,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAmBL,CAAiB,GAC9DM,IAAOP,KAAcI,GAGrB,CAACI,GAASC,CAAU,IAAIH,EAAmBC,CAAI,GAC/CG,IAAYH,EAAK,OAAO,CAACI,MAAQ,CAACH,EAAQ,SAASG,CAAG,CAAC;AAC7D,EAAID,EAAU,SAAS,KACrBD,EAAW,CAAC,GAAGD,GAAS,GAAGE,CAAS,CAAC;AAEvC,QAAME,IAAM,CAAC,kBAAkBT,KAAa,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAClEU,IAAS,CAACF,MAAsB;AACpC,UAAMG,IAAOP,EAAK,SAASI,CAAG,IAC1BJ,EAAK,OAAO,CAACQ,MAASA,MAASJ,CAAG,IAClC,CAAC,GAAGJ,GAAMI,CAAG;AACjB,IAAIX,MAAe,UACjBK,EAAYS,CAAI,GAElBZ,IAAWY,CAAI;AAAA,EACjB;AACA,2BACG,OAAA,EAAI,WAAWF,GACb,UAAAb,EAAM,IAAI,CAACgB,MAAS;AACnB,UAAMC,IAAWT,EAAK,SAASQ,EAAK,GAAG;AACvC,WACE,gBAAAE,EAAC,OAAA,EAAI,WAAU,wBACb,UAAA;AAAA,MAAA,gBAAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,iBAAeD;AAAA,UACf,iBAAe,kBAAkBD,EAAK,GAAG;AAAA,UACzC,SAAS,MAAM;AACb,YAAAF,EAAOE,EAAK,GAAG;AAAA,UACjB;AAAA,UAEA,UAAA;AAAA,YAAA,gBAAAG,EAAC,QAAA,EAAK,WAAU,yBAAyB,UAAAH,EAAK,OAAM;AAAA,YACpD,gBAAAG,EAACC,GAAA,EAAc,WAAU,2BAA0B,eAAW,GAAA,CAAC;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,MAEjE,gBAAAD;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,IAAI,
|
|
1
|
+
{"version":3,"file":"Collapse.js","sources":["../../../src/components/ui/Collapse.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { RightOutlined } from '@ant-design/icons';\n\nimport './Collapse.css';\n\nexport interface CollapseItem {\n key: string;\n label: ReactNode;\n children: ReactNode;\n}\n\ninterface CollapseProps {\n items: CollapseItem[];\n /** Controlled open keys. Omit for uncontrolled behaviour. */\n activeKeys?: string[];\n defaultActiveKeys?: string[];\n onChange?: (keys: string[]) => void;\n className?: string;\n}\n\nexport function Collapse({\n items,\n activeKeys,\n defaultActiveKeys = [],\n onChange,\n className,\n}: CollapseProps) {\n const [internal, setInternal] = useState<string[]>(defaultActiveKeys);\n const open = activeKeys ?? internal;\n // A panel mounts its children the first time it opens and keeps them, so\n // closing can animate instead of dropping the content at once.\n const [visited, setVisited] = useState<string[]>(open);\n const unvisited = open.filter((key) => !visited.includes(key));\n if (unvisited.length > 0) {\n setVisited([...visited, ...unvisited]);\n }\n const cls = ['aegis-collapse', className ?? ''].filter(Boolean).join(' ');\n const toggle = (key: string): void => {\n const next = open.includes(key)\n ? open.filter((item) => item !== key)\n : [...open, key];\n if (activeKeys === undefined) {\n setInternal(next);\n }\n onChange?.(next);\n };\n return (\n <div className={cls}>\n {items.map((item) => {\n const expanded = open.includes(item.key);\n return (\n <div className=\"aegis-collapse__item\" key={item.key}>\n <button\n type=\"button\"\n className=\"aegis-collapse__header\"\n aria-expanded={expanded}\n aria-controls={`aegis-collapse-${item.key}`}\n onClick={() => {\n toggle(item.key);\n }}\n >\n <span className=\"aegis-collapse__label\">{item.label}</span>\n <RightOutlined className=\"aegis-collapse__chevron\" aria-hidden />\n </button>\n <div\n ref={(element) => {\n if (element !== null) {\n element.inert = !expanded;\n }\n }}\n id={`aegis-collapse-${item.key}`}\n className={\n expanded\n ? 'aegis-collapse__panel aegis-collapse__panel--open'\n : 'aegis-collapse__panel'\n }\n role=\"region\"\n >\n <div className=\"aegis-collapse__clip\">\n <div className=\"aegis-collapse__body\">\n {(expanded || visited.includes(item.key)) && item.children}\n </div>\n </div>\n </div>\n </div>\n );\n })}\n </div>\n );\n}\n"],"names":["Collapse","items","activeKeys","defaultActiveKeys","onChange","className","internal","setInternal","useState","open","visited","setVisited","unvisited","key","cls","toggle","next","item","expanded","jsxs","jsx","RightOutlined","element"],"mappings":";;;;AAqBO,SAASA,EAAS;AAAA,EACvB,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,mBAAAC,IAAoB,CAAA;AAAA,EACpB,UAAAC;AAAA,EACA,WAAAC;AACF,GAAkB;AAChB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AY,SACdA,EAAQ,QAAQ,CAACJ;AAAA,UAErB;AAAA,UACA,IAAI,kBAAkBD,EAAK,GAAG;AAAA,UAC9B,WACEC,IACI,sDACA;AAAA,UAEN,MAAK;AAAA,UAEL,4BAAC,OAAA,EAAI,WAAU,wBACb,UAAA,gBAAAE,EAAC,SAAI,WAAU,wBACX,WAAAF,KAAYR,EAAQ,SAASO,EAAK,GAAG,MAAMA,EAAK,UACpD,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IACF,EAAA,GAhCyCA,EAAK,GAiChD;AAAA,EAEJ,CAAC,EAAA,CACH;AAEJ;"}
|
|
@@ -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 /** 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","target","jsxs","tick","chartColorValue","marker"],"mappings":"oSA6DMA,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,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAQC,EAAAA,gBAAgBH,CAAO,EAC/BI,EAASlB,EAAO,QAASmB,GAASA,EAAK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A,IAAC,OAAA,CACC,UAAU,yBACV,EAAGQ,EACH,EAAG1C,EAASK,EACZ,WAAW,MAEV,WAAQ+B,CAAG,CAAA,CAAA,EAEbxB,IAAW,QACVsB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,GAAIO,EAAOC,GAAS,EACpB,EAAG1C,EAASK,EACZ,WAAW,SAEV,SAAAO,CAAA,CAAA,EAGJK,GACCiB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGO,EACH,EAAGE,EACH,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,EAAGrC,EACH,MAAO,CAAE,KAAMyD,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,OAAS,CAAC,EACtBQ,EAASV,EAAO,IAAKG,GAAUA,EAAM,CAAC,EACtCQ,EAAQ3B,GAAU4B,EAAAA,UAAU,EAAG,KAAK,IAAI,GAAGF,EAAQ,CAAC,C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CAAQ,EACd,EAAG6B,EAAMxC,EAAgB,EACzB,WAAW,SAEV,WAAQW,CAAQ,CAAA,CAAA,CACnB,EACF,EAEFoB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGO,EACH,EAAG3C,EAASK,EACZ,WAAW,QAEV,WAAQgC,CAAG,CAAA,CAAA,EAEdD,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGQ,EACH,EAAG5C,EAASK,EACZ,WAAW,MAEV,WAAQiC,CAAG,CAAA,CAAA,EAEb1B,IAAW,QACVwB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,GAAIO,EAAOC,GAAS,EACpB,EAAG5C,EAASK,EACZ,WAAW,SAEV,SAAAO,CAAA,CAAA,EAGJK,GACCmB,EAAAA,IAAC,OAAA,CACC,UAAU,yBACV,EAAGO,EACH,EAAGE,EACH,MAAOD,EAAQD,EACf,OAAQG,EAASD,EACjB,KAAK,SACL,SAAU,EACV,aAAYxB,EAAQ,eACpB,gBAAegB,EACf,gBAAeC,EACf,gBAAetB,GAAYqB,EAC3B,iBAAgBvB,EAAQE,GAAYqB,CAAG,EACvC,QAASoB,EACT,UAAWI,CAAA,CAAA,EAGd3C,EAAQ,IAAKkD,GACZhC,EAAAA,IAAC,SAAA,CAEC,UAAU,2BACV,GAAIW,EAAGqB,EAAO,CAAC,EACf,GAAItB,EACJ,EAAGvC,EACH,MAAO,CAAE,KAAM2D,EAAAA,gBAAgBE,EAAO,KAAK,CAAA,EAC3C,QACEnD,EACI,IAAM,CACJA,EAAOmD,EAAO,CAAC,CACjB,EACA,OAGN,SAAAhC,EAAAA,IAAC,QAAA,CAAO,SAAAgC,EAAO,KAAA,CAAM,CAAA,EAdhBA,EAAO,GAAA,CAgBf,CAAA,CAAA,CAAA,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 {
|
|
@@ -1,192 +1,223 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
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
|
-
endLabels:
|
|
12
|
-
xLabel:
|
|
13
|
-
yTicks:
|
|
14
|
-
formatX:
|
|
15
|
-
formatY:
|
|
16
|
-
playhead:
|
|
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,
|
|
17
17
|
onSeek: r,
|
|
18
|
-
markers:
|
|
19
|
-
progress:
|
|
20
|
-
className:
|
|
18
|
+
markers: H = [],
|
|
19
|
+
progress: x,
|
|
20
|
+
className: j
|
|
21
21
|
}) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
return /* @__PURE__ */
|
|
25
|
-
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) => {
|
|
26
26
|
const e = t.points[t.points.length - 1];
|
|
27
|
-
return e === void 0 ? [] : [{ line: t, last: e, y:
|
|
27
|
+
return e === void 0 ? [] : [{ line: t, last: e, y: g(e.y) }];
|
|
28
28
|
}).sort((t, e) => e.y - t.y);
|
|
29
|
-
for (let t = 1; t <
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
(e,
|
|
33
|
-
),
|
|
34
|
-
const e = t.currentTarget.getBoundingClientRect(),
|
|
35
|
-
r?.(
|
|
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
36
|
}, F = (t) => {
|
|
37
|
-
const e =
|
|
37
|
+
const e = n.indexOf(P(o ?? s)), a = {
|
|
38
38
|
ArrowLeft: e - 1,
|
|
39
39
|
ArrowDown: e - 1,
|
|
40
40
|
ArrowRight: e + 1,
|
|
41
41
|
ArrowUp: e + 1,
|
|
42
42
|
Home: 0,
|
|
43
|
-
End:
|
|
43
|
+
End: n.length - 1
|
|
44
44
|
};
|
|
45
|
-
t.key in
|
|
45
|
+
t.key in a && (t.preventDefault(), r?.(n[Math.min(Math.max(a[t.key], 0), n.length - 1)]));
|
|
46
46
|
};
|
|
47
|
-
return /* @__PURE__ */
|
|
47
|
+
return /* @__PURE__ */ i("div", { ref: S, className: E, children: /* @__PURE__ */ N(
|
|
48
48
|
"svg",
|
|
49
49
|
{
|
|
50
50
|
className: "aegis-line-chart__svg",
|
|
51
|
-
width:
|
|
52
|
-
height:
|
|
53
|
-
viewBox: `0 0 ${
|
|
51
|
+
width: _,
|
|
52
|
+
height: c,
|
|
53
|
+
viewBox: `0 0 ${_.toString()} ${c.toString()}`,
|
|
54
54
|
role: r ? "group" : "img",
|
|
55
|
-
"aria-label":
|
|
55
|
+
"aria-label": T,
|
|
56
56
|
children: [
|
|
57
|
-
|
|
58
|
-
/* @__PURE__ */
|
|
57
|
+
b.map((t) => /* @__PURE__ */ N("g", { children: [
|
|
58
|
+
/* @__PURE__ */ i(
|
|
59
59
|
"line",
|
|
60
60
|
{
|
|
61
61
|
className: "aegis-line-chart__grid",
|
|
62
|
-
x1:
|
|
63
|
-
x2:
|
|
64
|
-
y1:
|
|
65
|
-
y2:
|
|
62
|
+
x1: l,
|
|
63
|
+
x2: h,
|
|
64
|
+
y1: g(t),
|
|
65
|
+
y2: g(t)
|
|
66
66
|
}
|
|
67
67
|
),
|
|
68
|
-
/* @__PURE__ */
|
|
68
|
+
/* @__PURE__ */ i(
|
|
69
69
|
"text",
|
|
70
70
|
{
|
|
71
71
|
className: "aegis-line-chart__tick",
|
|
72
|
-
x:
|
|
73
|
-
y:
|
|
72
|
+
x: l - m,
|
|
73
|
+
y: g(t),
|
|
74
74
|
textAnchor: "end",
|
|
75
75
|
dominantBaseline: "middle",
|
|
76
|
-
children:
|
|
76
|
+
children: D(t)
|
|
77
77
|
}
|
|
78
78
|
)
|
|
79
79
|
] }, t)),
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
)
|
|
91
104
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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(
|
|
96
127
|
"text",
|
|
97
128
|
{
|
|
98
129
|
className: "aegis-line-chart__end-label",
|
|
99
|
-
x:
|
|
100
|
-
y:
|
|
130
|
+
x: h,
|
|
131
|
+
y: a - m,
|
|
101
132
|
textAnchor: "end",
|
|
102
|
-
style: { fill:
|
|
103
|
-
children: `${t.label} ${
|
|
133
|
+
style: { fill: k(t.color) },
|
|
134
|
+
children: `${t.label} ${D(e.y)}`
|
|
104
135
|
},
|
|
105
136
|
t.key
|
|
106
137
|
)),
|
|
107
|
-
|
|
108
|
-
/* @__PURE__ */
|
|
138
|
+
o !== void 0 && /* @__PURE__ */ N("g", { children: [
|
|
139
|
+
/* @__PURE__ */ i(
|
|
109
140
|
"line",
|
|
110
141
|
{
|
|
111
142
|
className: "aegis-line-chart__playhead",
|
|
112
|
-
x1:
|
|
113
|
-
x2:
|
|
114
|
-
y1:
|
|
115
|
-
y2:
|
|
143
|
+
x1: d(o),
|
|
144
|
+
x2: d(o),
|
|
145
|
+
y1: u,
|
|
146
|
+
y2: f
|
|
116
147
|
}
|
|
117
148
|
),
|
|
118
|
-
/* @__PURE__ */
|
|
149
|
+
/* @__PURE__ */ i(
|
|
119
150
|
"text",
|
|
120
151
|
{
|
|
121
152
|
className: "aegis-line-chart__playhead-label",
|
|
122
|
-
x:
|
|
123
|
-
y:
|
|
153
|
+
x: d(o),
|
|
154
|
+
y: u - m / 2,
|
|
124
155
|
textAnchor: "middle",
|
|
125
|
-
children:
|
|
156
|
+
children: A(o)
|
|
126
157
|
}
|
|
127
158
|
)
|
|
128
159
|
] }),
|
|
129
|
-
/* @__PURE__ */
|
|
160
|
+
/* @__PURE__ */ i(
|
|
130
161
|
"text",
|
|
131
162
|
{
|
|
132
163
|
className: "aegis-line-chart__tick",
|
|
133
|
-
x:
|
|
134
|
-
y:
|
|
164
|
+
x: l,
|
|
165
|
+
y: c - m,
|
|
135
166
|
textAnchor: "start",
|
|
136
|
-
children:
|
|
167
|
+
children: A(s)
|
|
137
168
|
}
|
|
138
169
|
),
|
|
139
|
-
/* @__PURE__ */
|
|
170
|
+
/* @__PURE__ */ i(
|
|
140
171
|
"text",
|
|
141
172
|
{
|
|
142
173
|
className: "aegis-line-chart__tick",
|
|
143
|
-
x:
|
|
144
|
-
y:
|
|
174
|
+
x: h,
|
|
175
|
+
y: c - m,
|
|
145
176
|
textAnchor: "end",
|
|
146
|
-
children:
|
|
177
|
+
children: A(p)
|
|
147
178
|
}
|
|
148
179
|
),
|
|
149
|
-
|
|
180
|
+
w !== void 0 && /* @__PURE__ */ i(
|
|
150
181
|
"text",
|
|
151
182
|
{
|
|
152
183
|
className: "aegis-line-chart__tick",
|
|
153
|
-
x: (
|
|
154
|
-
y:
|
|
184
|
+
x: (l + h) / 2,
|
|
185
|
+
y: c - m,
|
|
155
186
|
textAnchor: "middle",
|
|
156
|
-
children:
|
|
187
|
+
children: w
|
|
157
188
|
}
|
|
158
189
|
),
|
|
159
|
-
r && /* @__PURE__ */
|
|
190
|
+
r && /* @__PURE__ */ i(
|
|
160
191
|
"rect",
|
|
161
192
|
{
|
|
162
193
|
className: "aegis-line-chart__seek",
|
|
163
|
-
x:
|
|
164
|
-
y:
|
|
165
|
-
width:
|
|
166
|
-
height:
|
|
194
|
+
x: l,
|
|
195
|
+
y: u,
|
|
196
|
+
width: h - l,
|
|
197
|
+
height: f - u,
|
|
167
198
|
role: "slider",
|
|
168
199
|
tabIndex: 0,
|
|
169
|
-
"aria-label":
|
|
170
|
-
"aria-valuemin":
|
|
171
|
-
"aria-valuemax":
|
|
172
|
-
"aria-valuenow":
|
|
173
|
-
"aria-valuetext":
|
|
174
|
-
onClick:
|
|
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,
|
|
175
206
|
onKeyDown: F
|
|
176
207
|
}
|
|
177
208
|
),
|
|
178
|
-
|
|
209
|
+
H.map((t) => /* @__PURE__ */ i(
|
|
179
210
|
"circle",
|
|
180
211
|
{
|
|
181
212
|
className: "aegis-line-chart__marker",
|
|
182
|
-
cx:
|
|
183
|
-
cy:
|
|
184
|
-
r:
|
|
185
|
-
style: { fill:
|
|
213
|
+
cx: d(t.x),
|
|
214
|
+
cy: f,
|
|
215
|
+
r: Y,
|
|
216
|
+
style: { fill: k(t.color) },
|
|
186
217
|
onClick: r ? () => {
|
|
187
218
|
r(t.x);
|
|
188
219
|
} : void 0,
|
|
189
|
-
children: /* @__PURE__ */
|
|
220
|
+
children: /* @__PURE__ */ i("title", { children: t.label })
|
|
190
221
|
},
|
|
191
222
|
t.key
|
|
192
223
|
))
|
|
@@ -195,6 +226,6 @@ function it({
|
|
|
195
226
|
) });
|
|
196
227
|
}
|
|
197
228
|
export {
|
|
198
|
-
|
|
229
|
+
ot as LineChart
|
|
199
230
|
};
|
|
200
231
|
//# sourceMappingURL=LineChart.js.map
|