minerva-design 1.0.2 → 1.1.0
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/CHANGELOG.md +6 -0
- package/README.md +21 -19
- package/dist/charts/core.cjs +1 -0
- package/dist/charts/core.d.cts +3 -0
- package/dist/charts/core.d.ts +3 -0
- package/dist/charts/core.js +3 -0
- package/dist/charts/engine/axis.cjs +2 -0
- package/dist/charts/engine/axis.cjs.map +1 -0
- package/dist/charts/engine/axis.d.cts +13 -0
- package/dist/charts/engine/axis.d.ts +13 -0
- package/dist/charts/engine/axis.js +38 -0
- package/dist/charts/engine/axis.js.map +1 -0
- package/dist/charts/engine/chart.cjs +3 -0
- package/dist/charts/engine/chart.cjs.map +1 -0
- package/dist/charts/engine/chart.d.cts +6 -0
- package/dist/charts/engine/chart.d.ts +6 -0
- package/dist/charts/engine/chart.js +624 -0
- package/dist/charts/engine/chart.js.map +1 -0
- package/dist/charts/engine/color.cjs +2 -0
- package/dist/charts/engine/color.cjs.map +1 -0
- package/dist/charts/engine/color.d.cts +23 -0
- package/dist/charts/engine/color.d.ts +23 -0
- package/dist/charts/engine/color.js +95 -0
- package/dist/charts/engine/color.js.map +1 -0
- package/dist/charts/engine/data.cjs +2 -0
- package/dist/charts/engine/data.cjs.map +1 -0
- package/dist/charts/engine/data.d.cts +29 -0
- package/dist/charts/engine/data.d.ts +29 -0
- package/dist/charts/engine/data.js +104 -0
- package/dist/charts/engine/data.js.map +1 -0
- package/dist/charts/engine/decimate.cjs +2 -0
- package/dist/charts/engine/decimate.cjs.map +1 -0
- package/dist/charts/engine/decimate.d.cts +13 -0
- package/dist/charts/engine/decimate.d.ts +13 -0
- package/dist/charts/engine/decimate.js +28 -0
- package/dist/charts/engine/decimate.js.map +1 -0
- package/dist/charts/engine/dom.cjs +2 -0
- package/dist/charts/engine/dom.cjs.map +1 -0
- package/dist/charts/engine/dom.d.cts +21 -0
- package/dist/charts/engine/dom.d.ts +21 -0
- package/dist/charts/engine/dom.js +125 -0
- package/dist/charts/engine/dom.js.map +1 -0
- package/dist/charts/engine/format.cjs +2 -0
- package/dist/charts/engine/format.cjs.map +1 -0
- package/dist/charts/engine/format.d.cts +9 -0
- package/dist/charts/engine/format.d.ts +9 -0
- package/dist/charts/engine/format.js +34 -0
- package/dist/charts/engine/format.js.map +1 -0
- package/dist/charts/engine/items.cjs +2 -0
- package/dist/charts/engine/items.cjs.map +1 -0
- package/dist/charts/engine/items.d.cts +8 -0
- package/dist/charts/engine/items.d.ts +8 -0
- package/dist/charts/engine/items.js +91 -0
- package/dist/charts/engine/items.js.map +1 -0
- package/dist/charts/engine/layout.cjs +2 -0
- package/dist/charts/engine/layout.cjs.map +1 -0
- package/dist/charts/engine/layout.d.cts +37 -0
- package/dist/charts/engine/layout.d.ts +37 -0
- package/dist/charts/engine/layout.js +26 -0
- package/dist/charts/engine/layout.js.map +1 -0
- package/dist/charts/engine/model.cjs +2 -0
- package/dist/charts/engine/model.cjs.map +1 -0
- package/dist/charts/engine/model.d.cts +74 -0
- package/dist/charts/engine/model.d.ts +74 -0
- package/dist/charts/engine/model.js +175 -0
- package/dist/charts/engine/model.js.map +1 -0
- package/dist/charts/engine/overlay.cjs +2 -0
- package/dist/charts/engine/overlay.cjs.map +1 -0
- package/dist/charts/engine/overlay.d.cts +62 -0
- package/dist/charts/engine/overlay.d.ts +62 -0
- package/dist/charts/engine/overlay.js +123 -0
- package/dist/charts/engine/overlay.js.map +1 -0
- package/dist/charts/engine/renderers/canvas2d.cjs +2 -0
- package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -0
- package/dist/charts/engine/renderers/canvas2d.d.cts +4 -0
- package/dist/charts/engine/renderers/canvas2d.d.ts +4 -0
- package/dist/charts/engine/renderers/canvas2d.js +156 -0
- package/dist/charts/engine/renderers/canvas2d.js.map +1 -0
- package/dist/charts/engine/renderers/detect.cjs +2 -0
- package/dist/charts/engine/renderers/detect.cjs.map +1 -0
- package/dist/charts/engine/renderers/detect.d.cts +12 -0
- package/dist/charts/engine/renderers/detect.d.ts +12 -0
- package/dist/charts/engine/renderers/detect.js +33 -0
- package/dist/charts/engine/renderers/detect.js.map +1 -0
- package/dist/charts/engine/renderers/range.cjs +2 -0
- package/dist/charts/engine/renderers/range.cjs.map +1 -0
- package/dist/charts/engine/renderers/range.d.cts +5 -0
- package/dist/charts/engine/renderers/range.d.ts +5 -0
- package/dist/charts/engine/renderers/range.js +32 -0
- package/dist/charts/engine/renderers/range.js.map +1 -0
- package/dist/charts/engine/renderers/shaders.cjs +266 -0
- package/dist/charts/engine/renderers/shaders.cjs.map +1 -0
- package/dist/charts/engine/renderers/shaders.d.cts +20 -0
- package/dist/charts/engine/renderers/shaders.d.ts +20 -0
- package/dist/charts/engine/renderers/shaders.js +251 -0
- package/dist/charts/engine/renderers/shaders.js.map +1 -0
- package/dist/charts/engine/renderers/types.cjs +2 -0
- package/dist/charts/engine/renderers/types.cjs.map +1 -0
- package/dist/charts/engine/renderers/types.d.cts +83 -0
- package/dist/charts/engine/renderers/types.d.ts +83 -0
- package/dist/charts/engine/renderers/types.js +6 -0
- package/dist/charts/engine/renderers/types.js.map +1 -0
- package/dist/charts/engine/renderers/webgl2.cjs +2 -0
- package/dist/charts/engine/renderers/webgl2.cjs.map +1 -0
- package/dist/charts/engine/renderers/webgl2.d.cts +5 -0
- package/dist/charts/engine/renderers/webgl2.d.ts +5 -0
- package/dist/charts/engine/renderers/webgl2.js +134 -0
- package/dist/charts/engine/renderers/webgl2.js.map +1 -0
- package/dist/charts/engine/renderers/webgpu.cjs +2 -0
- package/dist/charts/engine/renderers/webgpu.cjs.map +1 -0
- package/dist/charts/engine/renderers/webgpu.d.cts +6 -0
- package/dist/charts/engine/renderers/webgpu.d.ts +6 -0
- package/dist/charts/engine/renderers/webgpu.js +220 -0
- package/dist/charts/engine/renderers/webgpu.js.map +1 -0
- package/dist/charts/engine/scale.cjs +2 -0
- package/dist/charts/engine/scale.cjs.map +1 -0
- package/dist/charts/engine/scale.d.cts +13 -0
- package/dist/charts/engine/scale.d.ts +13 -0
- package/dist/charts/engine/scale.js +37 -0
- package/dist/charts/engine/scale.js.map +1 -0
- package/dist/charts/engine/spatial.cjs +2 -0
- package/dist/charts/engine/spatial.cjs.map +1 -0
- package/dist/charts/engine/spatial.d.cts +18 -0
- package/dist/charts/engine/spatial.d.ts +18 -0
- package/dist/charts/engine/spatial.js +53 -0
- package/dist/charts/engine/spatial.js.map +1 -0
- package/dist/charts/engine/theme.cjs +2 -0
- package/dist/charts/engine/theme.cjs.map +1 -0
- package/dist/charts/engine/theme.d.cts +21 -0
- package/dist/charts/engine/theme.d.ts +21 -0
- package/dist/charts/engine/theme.js +70 -0
- package/dist/charts/engine/theme.js.map +1 -0
- package/dist/charts/engine/time.cjs +2 -0
- package/dist/charts/engine/time.cjs.map +1 -0
- package/dist/charts/engine/time.d.cts +10 -0
- package/dist/charts/engine/time.d.ts +10 -0
- package/dist/charts/engine/time.js +189 -0
- package/dist/charts/engine/time.js.map +1 -0
- package/dist/charts/engine/types.d.cts +289 -0
- package/dist/charts/engine/types.d.ts +289 -0
- package/dist/charts/engine/viewport.cjs +2 -0
- package/dist/charts/engine/viewport.cjs.map +1 -0
- package/dist/charts/engine/viewport.d.cts +12 -0
- package/dist/charts/engine/viewport.d.ts +12 -0
- package/dist/charts/engine/viewport.js +15 -0
- package/dist/charts/engine/viewport.js.map +1 -0
- package/dist/charts/index.cjs +1 -0
- package/dist/charts/index.d.cts +4 -0
- package/dist/charts/index.d.ts +4 -0
- package/dist/charts/index.js +7 -0
- package/dist/charts/react/Chart.cjs +2 -0
- package/dist/charts/react/Chart.cjs.map +1 -0
- package/dist/charts/react/Chart.d.cts +28 -0
- package/dist/charts/react/Chart.d.ts +28 -0
- package/dist/charts/react/Chart.js +75 -0
- package/dist/charts/react/Chart.js.map +1 -0
- package/dist/charts/react/charts.cjs +2 -0
- package/dist/charts/react/charts.cjs.map +1 -0
- package/dist/charts/react/charts.d.cts +13 -0
- package/dist/charts/react/charts.d.ts +13 -0
- package/dist/charts/react/charts.js +179 -0
- package/dist/charts/react/charts.js.map +1 -0
- package/dist/charts/react/types.d.cts +168 -0
- package/dist/charts/react/types.d.ts +168 -0
- package/package.json +28 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/engine/layout.ts
|
|
2
|
+
var e = (e, t, n, r) => {
|
|
3
|
+
let [i, a] = t.x, [o, s] = t.y, c = e.width / (a - i || 1), l = e.height / (s - o || 1), u = e.x, d = e.x + e.width, f = e.y, p = e.y + e.height;
|
|
4
|
+
return {
|
|
5
|
+
plot: e,
|
|
6
|
+
view: t,
|
|
7
|
+
xToPx: n ? (e) => d - (e - i) * c : (e) => u + (e - i) * c,
|
|
8
|
+
yToPx: r ? (e) => f + (e - o) * l : (e) => p - (e - o) * l,
|
|
9
|
+
pxToX: n ? (e) => i + (d - e) / c : (e) => i + (e - u) / c,
|
|
10
|
+
pxToY: r ? (e) => o + (e - f) / l : (e) => o + (p - e) / l,
|
|
11
|
+
xPerPx: 1 / c,
|
|
12
|
+
yPerPx: 1 / l
|
|
13
|
+
};
|
|
14
|
+
}, t = (e) => {
|
|
15
|
+
let { width: t, height: n, padding: r, fontSize: i } = e, a = Math.ceil(i * 1.4), o = r.left + (e.yLabelWidth > 0 ? e.yLabelWidth + 8 : 0) + (e.yTitle ? a + 6 : 0), s = r.bottom + (e.xAxisVisible ? a + 8 : 0) + (e.xTitle ? a + 4 : 0), c = r.top, l = r.right;
|
|
16
|
+
return {
|
|
17
|
+
x: Math.round(o),
|
|
18
|
+
y: Math.round(c),
|
|
19
|
+
width: Math.max(10, Math.round(t - o - l)),
|
|
20
|
+
height: Math.max(10, Math.round(n - c - s))
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { t as computePlot, e as createScales };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","names":["createScales","x0","x1","view","y0","y1","xs","plot","ys","left","right","top","bottom","reverseX","v","reverseY","p","computePlot","input","line","fontSize","padding","width","height"],"sources":["../../../../charts/src/engine/layout.ts"],"sourcesContent":["// Plot rectangle and data <-> pixel mappings (CSS pixels of the stage).\n\nimport type { ChartView } from \"./types\";\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface Scales {\n plot: Rect;\n view: ChartView;\n xToPx(value: number): number;\n yToPx(value: number): number;\n pxToX(px: number): number;\n pxToY(px: number): number;\n /** Data units per CSS pixel */\n xPerPx: number;\n yPerPx: number;\n}\n\nexport const createScales = (\n plot: Rect,\n view: ChartView,\n reverseX: boolean,\n reverseY: boolean,\n): Scales => {\n const [x0, x1] = view.x;\n const [y0, y1] = view.y;\n const xs = plot.width / (x1 - x0 || 1);\n const ys = plot.height / (y1 - y0 || 1);\n const left = plot.x;\n const right = plot.x + plot.width;\n const top = plot.y;\n const bottom = plot.y + plot.height;\n return {\n plot,\n view,\n xToPx: reverseX\n ? (v) => right - (v - x0) * xs\n : (v) => left + (v - x0) * xs,\n yToPx: reverseY\n ? (v) => top + (v - y0) * ys\n : (v) => bottom - (v - y0) * ys,\n pxToX: reverseX\n ? (p) => x0 + (right - p) / xs\n : (p) => x0 + (p - left) / xs,\n pxToY: reverseY\n ? (p) => y0 + (p - top) / ys\n : (p) => y0 + (bottom - p) / ys,\n xPerPx: 1 / xs,\n yPerPx: 1 / ys,\n };\n};\n\nexport interface LayoutInput {\n width: number;\n height: number;\n padding: { top: number; right: number; bottom: number; left: number };\n /** Width of the widest y tick label (0 when the axis is hidden) */\n yLabelWidth: number;\n xAxisVisible: boolean;\n xTitle: boolean;\n yTitle: boolean;\n fontSize: number;\n}\n\n/** Room for the axes, then the plot area */\nexport const computePlot = (input: LayoutInput): Rect => {\n const { width, height, padding, fontSize } = input;\n const line = Math.ceil(fontSize * 1.4);\n const left =\n padding.left +\n (input.yLabelWidth > 0 ? input.yLabelWidth + 8 : 0) +\n (input.yTitle ? line + 6 : 0);\n const bottom =\n padding.bottom +\n (input.xAxisVisible ? line + 8 : 0) +\n (input.xTitle ? line + 4 : 0);\n const top = padding.top;\n const right = padding.right;\n return {\n x: Math.round(left),\n y: Math.round(top),\n width: Math.max(10, Math.round(width - left - right)),\n height: Math.max(10, Math.round(height - top - bottom)),\n };\n};\n"],"mappings":";AAuBA,IAAaA,KACX,GACA,GACA,GACA,MACW;CACX,IAAM,CAACC,GAAIC,KAAMC,EAAK,GAChB,CAACC,GAAIC,KAAMF,EAAK,GAChBG,IAAKC,EAAK,SAASL,IAAKD,KAAM,IAC9BO,IAAKD,EAAK,UAAUF,IAAKD,KAAM,IAC/BK,IAAOF,EAAK,GACZG,IAAQH,EAAK,IAAIA,EAAK,OACtBI,IAAMJ,EAAK,GACXK,IAASL,EAAK,IAAIA,EAAK;CAC7B,OAAO;EACL;EACA;EACA,OAAOM,KACF,MAAMH,KAASI,IAAIb,KAAMK,KACzB,MAAMG,KAAQK,IAAIb,KAAMK;EAC7B,OAAOS,KACF,MAAMJ,KAAOG,IAAIV,KAAMI,KACvB,MAAMI,KAAUE,IAAIV,KAAMI;EAC/B,OAAOK,KACF,MAAMZ,KAAMS,IAAQM,KAAKV,KACzB,MAAML,KAAMe,IAAIP,KAAQH;EAC7B,OAAOS,KACF,MAAMX,KAAMY,IAAIL,KAAOH,KACvB,MAAMJ,KAAMQ,IAASI,KAAKR;EAC/B,QAAQ,IAAIF;EACZ,QAAQ,IAAIE;CACd;AACF,GAeaS,KAAe,MAA6B;CACvD,IAAM,EAAE,UAAO,WAAQ,YAAS,gBAAaC,GACvCC,IAAO,KAAK,KAAKC,IAAW,GAAG,GAC/BX,IACJY,EAAQ,QACPH,EAAM,cAAc,IAAIA,EAAM,cAAc,IAAI,MAChDA,EAAM,SAASC,IAAO,IAAI,IACvBP,IACJS,EAAQ,UACPH,EAAM,eAAeC,IAAO,IAAI,MAChCD,EAAM,SAASC,IAAO,IAAI,IACvBR,IAAMU,EAAQ,KACdX,IAAQW,EAAQ;CACtB,OAAO;EACL,GAAG,KAAK,MAAMZ,CAAI;EAClB,GAAG,KAAK,MAAME,CAAG;EACjB,OAAO,KAAK,IAAI,IAAI,KAAK,MAAMW,IAAQb,IAAOC,CAAK,CAAC;EACpD,QAAQ,KAAK,IAAI,IAAI,KAAK,MAAMa,IAASZ,IAAMC,CAAM,CAAC;CACxD;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./scale.cjs"),t=require("./color.cjs"),n=require("./data.cjs"),r=require("./spatial.cjs");var i=e=>{if(typeof e==`object`&&e&&!(`length`in e)){let t=e.x;return t&&t.length?t[0]:void 0}let t=e;for(let e=0;e<Math.min(t.length,8);e++){let n=t[e];if(Array.isArray(n))return n[0];if(n&&typeof n==`object`)return n.x}},a=e=>{for(let t of e){let e=i(t);if(e instanceof Date)return`time`;if(typeof e==`string`)return`category`}return`linear`},o=(e,t,n,r)=>({type:t,reverse:!!e?.reverse,categories:n,title:e?.title,format:e?.format,grid:e?.grid??r,visible:e?.visible??!0,tickCount:e?.tickCount}),s=e=>{let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){let i=e[r];Number.isFinite(i)&&(i<t&&(t=i),i>n&&(n=i))}return[t,n]},c=e=>{let t=1/0;for(let n of e){let e=n.sorted?n.x:Float64Array.from(n.x).sort();for(let r=1;r<n.count;r++){let n=e[r]-e[r-1];n>0&&n<t&&(t=n)}}return t},l=(r,i,l,u,d)=>{let f=r.series,p=f.map(e=>e.data),m=r.xAxis?.type??a(p),h=m===`category`?[...r.xAxis?.categories??n.collectCategories(p)]:[],g=new Map(h.map((e,t)=>[e,t])),_=n.xResolver(m,e=>g.get(e)??NaN),v=`${m}|${h.join(``)}`,y=new Set,b=f.map((e,r)=>{let a=e.id??`#${r}`;for(;y.has(a);)a+=`'`;y.add(a);let o=u.get(a);(!o||o.data!==e.data||o.resolverKey!==v)&&(o={data:e.data,resolverKey:v,cols:n.normalizeData(e.data,_)},u.set(a,o));let s=e.type??`line`,c=e.color?t.resolveColor(e.color,d,i.palette[r%i.palette.length]):i.palette[r%i.palette.length],f=o.cols,p=null;if(s===`scatter`&&f.colors){let e=new Map;p=f.colors.map(n=>{if(n===void 0)return;let r=e.get(n);return r||e.set(n,r=t.resolveColor(n,d,c)),r})}let m=e.id??String(r);return{index:r,key:a,id:m,name:e.name??`Series ${r+1}`,type:s,color:c,colorCss:t.toCss(c),lineWidth:e.lineWidth??2,pointSize:e.pointSize??8,opacity:e.opacity??(s===`area`?.28:s===`scatter`?.78:1),hidden:!!e.hidden||l.has(m),showLabels:!!e.showLabels,cols:f,barOffset:0,barHalfWidth:0,barBase:null,barTop:null,pointColors:p}}),x=b.filter(e=>!e.hidden),S=b.length>0&&b.every(e=>e.type===`scatter`),C=x.filter(e=>e.type===`bar`),w=m===`category`?1:(()=>{let e=c(C.map(e=>e.cols));return Number.isFinite(e)?e:1})();if(C.length){let e=new Map;for(let t of C){let n=f[t.index].stack??`\u0000${t.key}`;e.has(n)||e.set(n,e.size)}let t=w*(e.size>1?.78:.62),n=t/e.size,r=new Map;for(let i of C){let a=f[i.index].stack??`\u0000${i.key}`,o=e.get(a)??0;i.barOffset=-t/2+n*(o+.5),i.barHalfWidth=n/2*(e.size>1?.86:1);let s=r.get(a);s||r.set(a,s=new Map);let{x:c,y:l,count:u}=i.cols;i.barBase=new Float64Array(u),i.barTop=new Float64Array(u);for(let e=0;e<u;e++){let t=l[e];if(!Number.isFinite(t)){i.barBase[e]=NaN,i.barTop[e]=NaN;continue}let n=s.get(c[e])??[0,0],r=t>=0?n[0]:n[1];i.barBase[e]=r,i.barTop[e]=r+t,t>=0?n[0]+=t:n[1]+=t,s.set(c[e],n)}}}let T=r.xAxis,E;if(m===`category`)E=[-.5,Math.max(1,h.length)-.5];else{let t=[];for(let e of x)t.push(e.cols.xMin,e.cols.xMax),e.type===`bar`&&t.push(e.cols.xMin-w/2,e.cols.xMax+w/2);if(E=e.ensureSpan(...s(t),m===`time`?[Date.now()-864e5,Date.now()]:[0,1]),S){let e=(E[1]-E[0])*.04;E=[E[0]-e,E[1]+e]}(T?.nice??(S&&m===`linear`))&&m===`linear`&&(E=e.niceDomain(E[0],E[1],T?.tickCount??6))}T?.min!==void 0&&(E[0]=T.min),T?.max!==void 0&&(E[1]=T.max),E=e.ensureSpan(E[0],E[1]);let D=r.yAxis,O=[];for(let e of x)e.type===`bar`&&e.barBase&&e.barTop?O.push(...s(e.barBase),...s(e.barTop)):O.push(e.cols.yMin,e.cols.yMax);(C.length||D?.zero)&&O.push(0);let k=e.ensureSpan(...s(O));if(S){let e=(k[1]-k[0])*.06;k=[k[0]-e,k[1]+e]}(D?.nice??!0)&&(D?.type??`linear`)===`linear`&&(k=e.niceDomain(k[0],k[1],D?.tickCount??5)),C.length&&!D?.zero&&k[0]<0&&s(O)[0]>=0&&(k[0]=0),D?.min!==void 0&&(k[0]=D.min),D?.max!==void 0&&(k[1]=D.max),k=e.ensureSpan(k[0],k[1]);let A=r.interaction===!1?!1:r.interaction===!0||r.interaction===void 0?!0:r.interaction.zoom??!0,j=A===!1?{x:!1,y:!1}:A===!0?{x:!0,y:S}:{x:A.includes(`x`),y:A.includes(`y`)},M=typeof r.tooltip==`object`?r.tooltip:void 0;return{series:b,x:o(T,m,h,!1),y:o(D,D?.type===`time`?`time`:`linear`,[],!0),base:{x:E,y:k},allScatter:S,zoom:j,tooltipMode:M?.mode??(S?`nearest`:`axis`),baseline:Math.min(Math.max(0,k[0]),k[1]),minSpan:{x:m===`category`?1:(E[1]-E[0])*1e-7,y:(k[1]-k[0])*1e-7}}},u=new WeakMap,d=e=>{let t=u.get(e.cols);return t||(t=new r.GridIndex(e.cols.x,e.cols.y,e.cols.count),u.set(e.cols,t)),t};exports.buildModel=l,exports.detectXType=a,exports.gridOf=d;
|
|
2
|
+
//# sourceMappingURL=model.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.cjs","names":["collectCategories","xResolver","normalizeData","resolveColor","toCss","ensureSpan","niceDomain","GridIndex","require_scale","require_color","require_data","require_spatial","firstX","data","xs","list","i","item","detectXType","datas","x","axisModel","options","gridDefault","extent","min","max","values","v","smallestStep","step","c","cols","d","buildModel","input","s","xType","categories","categoryMap","resolveX","name","resolverKey","usedKeys","series","key","index","entry","cache","type","color","element","theme","pointColors","resolved","rgba","id","hidden","visible","allScatter","bars","band","slots","stack","group","slotWidth","sums","slot","totals","count","y","t","base","xOpts","xRange","pad","yOpts","yValues","yRange","zoomOption","zoomAxes","tooltip","grids","gridOf","grid"],"sources":["../../../../charts/src/engine/model.ts"],"sourcesContent":["// Options -> chart model: normalized data, colors, bar layout and the full\n// ranges of the axes. Pure (no DOM besides color resolution).\n\nimport { resolveColor, toCss, type Rgba } from \"./color\";\nimport {\n collectCategories,\n normalizeData,\n xResolver,\n type SeriesColumns,\n} from \"./data\";\nimport { ensureSpan, niceDomain } from \"./scale\";\nimport { GridIndex } from \"./spatial\";\nimport type { ChartTheme } from \"./theme\";\nimport type {\n ChartAxisOptions,\n ChartAxisType,\n ChartOptions,\n ChartSeriesData,\n ChartSeriesType,\n} from \"./types\";\nimport type { Range } from \"./viewport\";\n\nexport interface AxisModel {\n type: ChartAxisType;\n reverse: boolean;\n categories: string[];\n title?: string;\n format?: (value: number) => string;\n grid: boolean;\n visible: boolean;\n tickCount?: number;\n}\n\nexport interface SeriesModel {\n index: number;\n /** Key of the GPU resources and of the data cache */\n key: string;\n id: string;\n name: string;\n type: ChartSeriesType;\n color: Rgba;\n colorCss: string;\n lineWidth: number;\n pointSize: number;\n opacity: number;\n hidden: boolean;\n showLabels: boolean;\n cols: SeriesColumns;\n /** Bars: x offset of the series inside a group and half of the bar width */\n barOffset: number;\n barHalfWidth: number;\n /** Bars: bottom / top of every bar (stacks included) */\n barBase: Float64Array | null;\n barTop: Float64Array | null;\n /** Scatter: resolved per-point colors */\n pointColors: (Rgba | undefined)[] | null;\n}\n\nexport interface ChartModel {\n series: SeriesModel[];\n x: AxisModel;\n y: AxisModel;\n /** Full ranges (zoomed out) */\n base: { x: Range; y: Range };\n allScatter: boolean;\n zoom: { x: boolean; y: boolean };\n tooltipMode: \"nearest\" | \"axis\";\n /** Y value the areas are filled to */\n baseline: number;\n /** Smallest zoomed spans */\n minSpan: { x: number; y: number };\n}\n\nexport interface DataCacheEntry {\n data: ChartSeriesData;\n resolverKey: string;\n cols: SeriesColumns;\n}\n\nexport type DataCache = Map<string, DataCacheEntry>;\n\nconst firstX = (data: ChartSeriesData): unknown => {\n if (typeof data === \"object\" && data !== null && !(\"length\" in data)) {\n const xs = (data as { x?: ArrayLike<unknown> }).x;\n return xs && xs.length ? xs[0] : undefined;\n }\n const list = data as ArrayLike<unknown>;\n for (let i = 0; i < Math.min(list.length, 8); i++) {\n const item = list[i];\n if (Array.isArray(item)) return item[0];\n if (item && typeof item === \"object\") return (item as { x?: unknown }).x;\n }\n return undefined;\n};\n\n/** Axis type when not given: dates -> time, strings -> category */\nexport const detectXType = (\n datas: readonly ChartSeriesData[],\n): ChartAxisType => {\n for (const data of datas) {\n const x = firstX(data);\n if (x instanceof Date) return \"time\";\n if (typeof x === \"string\") return \"category\";\n }\n return \"linear\";\n};\n\nconst axisModel = (\n options: ChartAxisOptions | undefined,\n type: ChartAxisType,\n categories: string[],\n gridDefault: boolean,\n): AxisModel => ({\n type,\n reverse: !!options?.reverse,\n categories,\n title: options?.title,\n format: options?.format,\n grid: options?.grid ?? gridDefault,\n visible: options?.visible ?? true,\n tickCount: options?.tickCount,\n});\n\nconst extent = (values: ArrayLike<number>): Range => {\n let min = Infinity;\n let max = -Infinity;\n for (let i = 0; i < values.length; i++) {\n const v = values[i];\n if (!Number.isFinite(v)) continue;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n return [min, max];\n};\n\n/** Smallest positive gap between consecutive x values (bar width on numeric axes) */\nconst smallestStep = (cols: SeriesColumns[]): number => {\n let step = Infinity;\n for (const c of cols) {\n const xs = c.sorted ? c.x : Float64Array.from(c.x).sort();\n for (let i = 1; i < c.count; i++) {\n const d = xs[i] - xs[i - 1];\n if (d > 0 && d < step) step = d;\n }\n }\n return step;\n};\n\nexport const buildModel = (\n options: ChartOptions,\n theme: ChartTheme,\n hidden: ReadonlySet<string>,\n cache: DataCache,\n element: Element | null,\n): ChartModel => {\n const input = options.series;\n const datas = input.map((s) => s.data);\n const xType = options.xAxis?.type ?? detectXType(datas);\n const categories =\n xType === \"category\"\n ? [...(options.xAxis?.categories ?? collectCategories(datas))]\n : [];\n const categoryMap = new Map(categories.map((c, i) => [c, i]));\n const resolveX = xResolver(xType, (name) => categoryMap.get(name) ?? NaN);\n const resolverKey = `${xType}|${categories.join(\"\\u0001\")}`;\n\n const usedKeys = new Set<string>();\n const series: SeriesModel[] = input.map((s, index) => {\n let key = s.id ?? `#${index}`;\n while (usedKeys.has(key)) key += \"'\";\n usedKeys.add(key);\n let entry = cache.get(key);\n if (!entry || entry.data !== s.data || entry.resolverKey !== resolverKey) {\n entry = {\n data: s.data,\n resolverKey,\n cols: normalizeData(s.data, resolveX),\n };\n cache.set(key, entry);\n }\n const type = s.type ?? \"line\";\n const color = s.color\n ? resolveColor(\n s.color,\n element,\n theme.palette[index % theme.palette.length],\n )\n : theme.palette[index % theme.palette.length];\n const cols = entry.cols;\n let pointColors: (Rgba | undefined)[] | null = null;\n if (type === \"scatter\" && cols.colors) {\n const resolved = new Map<string, Rgba>();\n pointColors = cols.colors.map((c) => {\n if (c === undefined) return undefined;\n let rgba = resolved.get(c);\n if (!rgba) resolved.set(c, (rgba = resolveColor(c, element, color)));\n return rgba;\n });\n }\n const id = s.id ?? String(index);\n return {\n index,\n key,\n id,\n name: s.name ?? `Series ${index + 1}`,\n type,\n color,\n colorCss: toCss(color),\n lineWidth: s.lineWidth ?? 2,\n pointSize: s.pointSize ?? 8,\n opacity:\n s.opacity ?? (type === \"area\" ? 0.28 : type === \"scatter\" ? 0.78 : 1),\n hidden: !!s.hidden || hidden.has(id),\n showLabels: !!s.showLabels,\n cols,\n barOffset: 0,\n barHalfWidth: 0,\n barBase: null,\n barTop: null,\n pointColors,\n };\n });\n\n const visible = series.filter((s) => !s.hidden);\n const allScatter =\n series.length > 0 && series.every((s) => s.type === \"scatter\");\n\n // Bars: groups (one slot per stack) and stacking\n const bars = visible.filter((s) => s.type === \"bar\");\n const band =\n xType === \"category\"\n ? 1\n : (() => {\n const step = smallestStep(bars.map((s) => s.cols));\n return Number.isFinite(step) ? step : 1;\n })();\n if (bars.length) {\n const slots = new Map<string, number>();\n for (const s of bars) {\n const stack = input[s.index].stack ?? `\\u0000${s.key}`;\n if (!slots.has(stack)) slots.set(stack, slots.size);\n }\n const group = band * (slots.size > 1 ? 0.78 : 0.62);\n const slotWidth = group / slots.size;\n const sums = new Map<string, Map<number, [number, number]>>();\n for (const s of bars) {\n const stack = input[s.index].stack ?? `\\u0000${s.key}`;\n const slot = slots.get(stack) ?? 0;\n s.barOffset = -group / 2 + slotWidth * (slot + 0.5);\n s.barHalfWidth = (slotWidth / 2) * (slots.size > 1 ? 0.86 : 1);\n let totals = sums.get(stack);\n if (!totals) sums.set(stack, (totals = new Map()));\n const { x, y, count } = s.cols;\n s.barBase = new Float64Array(count);\n s.barTop = new Float64Array(count);\n for (let i = 0; i < count; i++) {\n const v = y[i];\n if (!Number.isFinite(v)) {\n s.barBase[i] = NaN;\n s.barTop[i] = NaN;\n continue;\n }\n const t = totals.get(x[i]) ?? [0, 0];\n const base = v >= 0 ? t[0] : t[1];\n s.barBase[i] = base;\n s.barTop[i] = base + v;\n if (v >= 0) t[0] += v;\n else t[1] += v;\n totals.set(x[i], t);\n }\n }\n }\n\n // X range\n const xOpts = options.xAxis;\n let xRange: Range;\n if (xType === \"category\") {\n xRange = [-0.5, Math.max(1, categories.length) - 0.5];\n } else {\n const values: number[] = [];\n for (const s of visible) {\n values.push(s.cols.xMin, s.cols.xMax);\n if (s.type === \"bar\") {\n values.push(s.cols.xMin - band / 2, s.cols.xMax + band / 2);\n }\n }\n xRange = ensureSpan(\n ...extent(values),\n xType === \"time\" ? [Date.now() - 86400000, Date.now()] : [0, 1],\n );\n if (allScatter) {\n const pad = (xRange[1] - xRange[0]) * 0.04;\n xRange = [xRange[0] - pad, xRange[1] + pad];\n }\n const nice = xOpts?.nice ?? (allScatter && xType === \"linear\");\n if (nice && xType === \"linear\") {\n xRange = niceDomain(xRange[0], xRange[1], xOpts?.tickCount ?? 6);\n }\n }\n if (xOpts?.min !== undefined) xRange[0] = xOpts.min;\n if (xOpts?.max !== undefined) xRange[1] = xOpts.max;\n xRange = ensureSpan(xRange[0], xRange[1]);\n\n // Y range\n const yOpts = options.yAxis;\n const yValues: number[] = [];\n for (const s of visible) {\n if (s.type === \"bar\" && s.barBase && s.barTop) {\n yValues.push(...extent(s.barBase), ...extent(s.barTop));\n } else {\n yValues.push(s.cols.yMin, s.cols.yMax);\n }\n }\n if (bars.length || yOpts?.zero) yValues.push(0);\n let yRange = ensureSpan(...extent(yValues));\n if (allScatter) {\n const pad = (yRange[1] - yRange[0]) * 0.06;\n yRange = [yRange[0] - pad, yRange[1] + pad];\n }\n if ((yOpts?.nice ?? true) && (yOpts?.type ?? \"linear\") === \"linear\") {\n yRange = niceDomain(yRange[0], yRange[1], yOpts?.tickCount ?? 5);\n }\n if (bars.length && !yOpts?.zero) {\n // bars start at zero: no padding below / above it\n if (yRange[0] < 0 && extent(yValues)[0] >= 0) yRange[0] = 0;\n }\n if (yOpts?.min !== undefined) yRange[0] = yOpts.min;\n if (yOpts?.max !== undefined) yRange[1] = yOpts.max;\n yRange = ensureSpan(yRange[0], yRange[1]);\n\n const zoomOption =\n options.interaction === false\n ? false\n : options.interaction === true || options.interaction === undefined\n ? true\n : (options.interaction.zoom ?? true);\n const zoomAxes =\n zoomOption === false\n ? { x: false, y: false }\n : zoomOption === true\n ? { x: true, y: allScatter }\n : { x: zoomOption.includes(\"x\"), y: zoomOption.includes(\"y\") };\n\n const tooltip =\n typeof options.tooltip === \"object\" ? options.tooltip : undefined;\n\n return {\n series,\n x: axisModel(xOpts, xType, categories, false),\n y: axisModel(yOpts, yOpts?.type === \"time\" ? \"time\" : \"linear\", [], true),\n base: { x: xRange, y: yRange },\n allScatter,\n zoom: zoomAxes,\n tooltipMode: tooltip?.mode ?? (allScatter ? \"nearest\" : \"axis\"),\n baseline: Math.min(Math.max(0, yRange[0]), yRange[1]),\n minSpan: {\n x: xType === \"category\" ? 1 : (xRange[1] - xRange[0]) * 1e-7,\n y: (yRange[1] - yRange[0]) * 1e-7,\n },\n };\n};\n\nconst grids = new WeakMap<SeriesColumns, GridIndex>();\n\n/** Spatial index of a scatter series, built on first use and kept with its data */\nexport const gridOf = (s: SeriesModel): GridIndex => {\n let grid = grids.get(s.cols);\n if (!grid) {\n grid = new GridIndex(s.cols.x, s.cols.y, s.cols.count);\n grids.set(s.cols, grid);\n }\n return grid;\n};\n"],"mappings":"2GAiFA,IAAMY,EAAU,GAAmC,CACjD,GAAI,OAAOC,GAAS,UAAYA,GAAiB,EAAE,WAAYA,GAAO,CACpE,IAAMC,EAAMD,EAAoC,EAChD,OAAOC,GAAMA,EAAG,OAASA,EAAG,GAAK,IAAA,EACnC,CACA,IAAMC,EAAOF,EACb,IAAK,IAAIG,EAAI,EAAGA,EAAI,KAAK,IAAID,EAAK,OAAQ,CAAC,EAAG,IAAK,CACjD,IAAME,EAAOF,EAAKC,GAClB,GAAI,MAAM,QAAQC,CAAI,EAAG,OAAOA,EAAK,GACrC,GAAIA,GAAQ,OAAOA,GAAS,SAAU,OAAQA,EAAyB,CACzE,CAEF,EAGaC,EACX,GACkB,CAClB,IAAK,IAAML,KAAQM,EAAO,CACxB,IAAMC,EAAIR,EAAOC,CAAI,EACrB,GAAIO,aAAa,KAAM,MAAO,OAC9B,GAAI,OAAOA,GAAM,SAAU,MAAO,UACpC,CACA,MAAO,QACT,EAEMC,GACJ,EACA,EACA,EACA,KACe,CACf,OACA,QAAS,CAAC,CAACC,GAAS,QACpB,aACA,MAAOA,GAAS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CAAW,EACzB,CAAE,EAAGoB,EAAW,SAAS,GAAG,EAAG,EAAGA,EAAW,SAAS,GAAG,CAAE,EAE7DE,EACJ,OAAO3D,EAAQ,SAAY,SAAWA,EAAQ,QAAU,IAAA,GAE1D,MAAO,CACL,SACA,EAAGD,EAAUoD,EAAOpC,EAAOC,EAAY,EAAK,EAC5C,EAAGjB,EAAUuD,EAAOA,GAAO,OAAS,OAAS,OAAS,SAAU,CAAC,EAAG,EAAI,EACxE,KAAM,CAAE,EAAGF,EAAQ,EAAGI,CAAO,EAC7B,aACA,KAAME,EACN,YAAaC,GAAS,OAAStB,EAAa,UAAY,QACxD,SAAU,KAAK,IAAI,KAAK,IAAI,EAAGmB,EAAO,EAAE,EAAGA,EAAO,EAAE,EACpD,QAAS,CACP,EAAGzC,IAAU,WAAa,GAAKqC,EAAO,GAAKA,EAAO,IAAM,KACxD,GAAII,EAAO,GAAKA,EAAO,IAAM,IAC/B,CACF,CACF,EAEMI,EAAQ,IAAI,QAGLC,EAAU,GAA8B,CACnD,IAAIC,EAAOF,EAAM,IAAI9C,EAAE,IAAI,EAK3B,OAJKgD,IACH,EAAO,IAAI7E,EAAAA,UAAU6B,EAAE,KAAK,EAAGA,EAAE,KAAK,EAAGA,EAAE,KAAK,KAAK,EACrD8C,EAAM,IAAI9C,EAAE,KAAMgD,CAAI,GAEjBA,CACT"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Rgba } from './color.cjs';
|
|
2
|
+
import { SeriesColumns } from './data.cjs';
|
|
3
|
+
import { GridIndex } from './spatial.cjs';
|
|
4
|
+
import { ChartTheme } from './theme.cjs';
|
|
5
|
+
import { ChartAxisType, ChartOptions, ChartSeriesData, ChartSeriesType } from './types.cjs';
|
|
6
|
+
import { Range } from './viewport.cjs';
|
|
7
|
+
export interface AxisModel {
|
|
8
|
+
type: ChartAxisType;
|
|
9
|
+
reverse: boolean;
|
|
10
|
+
categories: string[];
|
|
11
|
+
title?: string;
|
|
12
|
+
format?: (value: number) => string;
|
|
13
|
+
grid: boolean;
|
|
14
|
+
visible: boolean;
|
|
15
|
+
tickCount?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface SeriesModel {
|
|
18
|
+
index: number;
|
|
19
|
+
/** Key of the GPU resources and of the data cache */
|
|
20
|
+
key: string;
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: ChartSeriesType;
|
|
24
|
+
color: Rgba;
|
|
25
|
+
colorCss: string;
|
|
26
|
+
lineWidth: number;
|
|
27
|
+
pointSize: number;
|
|
28
|
+
opacity: number;
|
|
29
|
+
hidden: boolean;
|
|
30
|
+
showLabels: boolean;
|
|
31
|
+
cols: SeriesColumns;
|
|
32
|
+
/** Bars: x offset of the series inside a group and half of the bar width */
|
|
33
|
+
barOffset: number;
|
|
34
|
+
barHalfWidth: number;
|
|
35
|
+
/** Bars: bottom / top of every bar (stacks included) */
|
|
36
|
+
barBase: Float64Array | null;
|
|
37
|
+
barTop: Float64Array | null;
|
|
38
|
+
/** Scatter: resolved per-point colors */
|
|
39
|
+
pointColors: (Rgba | undefined)[] | null;
|
|
40
|
+
}
|
|
41
|
+
export interface ChartModel {
|
|
42
|
+
series: SeriesModel[];
|
|
43
|
+
x: AxisModel;
|
|
44
|
+
y: AxisModel;
|
|
45
|
+
/** Full ranges (zoomed out) */
|
|
46
|
+
base: {
|
|
47
|
+
x: Range;
|
|
48
|
+
y: Range;
|
|
49
|
+
};
|
|
50
|
+
allScatter: boolean;
|
|
51
|
+
zoom: {
|
|
52
|
+
x: boolean;
|
|
53
|
+
y: boolean;
|
|
54
|
+
};
|
|
55
|
+
tooltipMode: "nearest" | "axis";
|
|
56
|
+
/** Y value the areas are filled to */
|
|
57
|
+
baseline: number;
|
|
58
|
+
/** Smallest zoomed spans */
|
|
59
|
+
minSpan: {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface DataCacheEntry {
|
|
65
|
+
data: ChartSeriesData;
|
|
66
|
+
resolverKey: string;
|
|
67
|
+
cols: SeriesColumns;
|
|
68
|
+
}
|
|
69
|
+
export type DataCache = Map<string, DataCacheEntry>;
|
|
70
|
+
/** Axis type when not given: dates -> time, strings -> category */
|
|
71
|
+
export declare const detectXType: (datas: readonly ChartSeriesData[]) => ChartAxisType;
|
|
72
|
+
export declare const buildModel: (options: ChartOptions, theme: ChartTheme, hidden: ReadonlySet<string>, cache: DataCache, element: Element | null) => ChartModel;
|
|
73
|
+
/** Spatial index of a scatter series, built on first use and kept with its data */
|
|
74
|
+
export declare const gridOf: (s: SeriesModel) => GridIndex;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Rgba } from './color.js';
|
|
2
|
+
import { SeriesColumns } from './data.js';
|
|
3
|
+
import { GridIndex } from './spatial.js';
|
|
4
|
+
import { ChartTheme } from './theme.js';
|
|
5
|
+
import { ChartAxisType, ChartOptions, ChartSeriesData, ChartSeriesType } from './types.js';
|
|
6
|
+
import { Range } from './viewport.js';
|
|
7
|
+
export interface AxisModel {
|
|
8
|
+
type: ChartAxisType;
|
|
9
|
+
reverse: boolean;
|
|
10
|
+
categories: string[];
|
|
11
|
+
title?: string;
|
|
12
|
+
format?: (value: number) => string;
|
|
13
|
+
grid: boolean;
|
|
14
|
+
visible: boolean;
|
|
15
|
+
tickCount?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface SeriesModel {
|
|
18
|
+
index: number;
|
|
19
|
+
/** Key of the GPU resources and of the data cache */
|
|
20
|
+
key: string;
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: ChartSeriesType;
|
|
24
|
+
color: Rgba;
|
|
25
|
+
colorCss: string;
|
|
26
|
+
lineWidth: number;
|
|
27
|
+
pointSize: number;
|
|
28
|
+
opacity: number;
|
|
29
|
+
hidden: boolean;
|
|
30
|
+
showLabels: boolean;
|
|
31
|
+
cols: SeriesColumns;
|
|
32
|
+
/** Bars: x offset of the series inside a group and half of the bar width */
|
|
33
|
+
barOffset: number;
|
|
34
|
+
barHalfWidth: number;
|
|
35
|
+
/** Bars: bottom / top of every bar (stacks included) */
|
|
36
|
+
barBase: Float64Array | null;
|
|
37
|
+
barTop: Float64Array | null;
|
|
38
|
+
/** Scatter: resolved per-point colors */
|
|
39
|
+
pointColors: (Rgba | undefined)[] | null;
|
|
40
|
+
}
|
|
41
|
+
export interface ChartModel {
|
|
42
|
+
series: SeriesModel[];
|
|
43
|
+
x: AxisModel;
|
|
44
|
+
y: AxisModel;
|
|
45
|
+
/** Full ranges (zoomed out) */
|
|
46
|
+
base: {
|
|
47
|
+
x: Range;
|
|
48
|
+
y: Range;
|
|
49
|
+
};
|
|
50
|
+
allScatter: boolean;
|
|
51
|
+
zoom: {
|
|
52
|
+
x: boolean;
|
|
53
|
+
y: boolean;
|
|
54
|
+
};
|
|
55
|
+
tooltipMode: "nearest" | "axis";
|
|
56
|
+
/** Y value the areas are filled to */
|
|
57
|
+
baseline: number;
|
|
58
|
+
/** Smallest zoomed spans */
|
|
59
|
+
minSpan: {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface DataCacheEntry {
|
|
65
|
+
data: ChartSeriesData;
|
|
66
|
+
resolverKey: string;
|
|
67
|
+
cols: SeriesColumns;
|
|
68
|
+
}
|
|
69
|
+
export type DataCache = Map<string, DataCacheEntry>;
|
|
70
|
+
/** Axis type when not given: dates -> time, strings -> category */
|
|
71
|
+
export declare const detectXType: (datas: readonly ChartSeriesData[]) => ChartAxisType;
|
|
72
|
+
export declare const buildModel: (options: ChartOptions, theme: ChartTheme, hidden: ReadonlySet<string>, cache: DataCache, element: Element | null) => ChartModel;
|
|
73
|
+
/** Spatial index of a scatter series, built on first use and kept with its data */
|
|
74
|
+
export declare const gridOf: (s: SeriesModel) => GridIndex;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ensureSpan as e, niceDomain as t } from "./scale.js";
|
|
2
|
+
import { resolveColor as n, toCss as r } from "./color.js";
|
|
3
|
+
import { collectCategories as i, normalizeData as a, xResolver as o } from "./data.js";
|
|
4
|
+
import { GridIndex as s } from "./spatial.js";
|
|
5
|
+
//#region src/engine/model.ts
|
|
6
|
+
var c = (e) => {
|
|
7
|
+
if (typeof e == "object" && e && !("length" in e)) {
|
|
8
|
+
let t = e.x;
|
|
9
|
+
return t && t.length ? t[0] : void 0;
|
|
10
|
+
}
|
|
11
|
+
let t = e;
|
|
12
|
+
for (let e = 0; e < Math.min(t.length, 8); e++) {
|
|
13
|
+
let n = t[e];
|
|
14
|
+
if (Array.isArray(n)) return n[0];
|
|
15
|
+
if (n && typeof n == "object") return n.x;
|
|
16
|
+
}
|
|
17
|
+
}, l = (e) => {
|
|
18
|
+
for (let t of e) {
|
|
19
|
+
let e = c(t);
|
|
20
|
+
if (e instanceof Date) return "time";
|
|
21
|
+
if (typeof e == "string") return "category";
|
|
22
|
+
}
|
|
23
|
+
return "linear";
|
|
24
|
+
}, u = (e, t, n, r) => ({
|
|
25
|
+
type: t,
|
|
26
|
+
reverse: !!e?.reverse,
|
|
27
|
+
categories: n,
|
|
28
|
+
title: e?.title,
|
|
29
|
+
format: e?.format,
|
|
30
|
+
grid: e?.grid ?? r,
|
|
31
|
+
visible: e?.visible ?? !0,
|
|
32
|
+
tickCount: e?.tickCount
|
|
33
|
+
}), d = (e) => {
|
|
34
|
+
let t = Infinity, n = -Infinity;
|
|
35
|
+
for (let r = 0; r < e.length; r++) {
|
|
36
|
+
let i = e[r];
|
|
37
|
+
Number.isFinite(i) && (i < t && (t = i), i > n && (n = i));
|
|
38
|
+
}
|
|
39
|
+
return [t, n];
|
|
40
|
+
}, f = (e) => {
|
|
41
|
+
let t = Infinity;
|
|
42
|
+
for (let n of e) {
|
|
43
|
+
let e = n.sorted ? n.x : Float64Array.from(n.x).sort();
|
|
44
|
+
for (let r = 1; r < n.count; r++) {
|
|
45
|
+
let n = e[r] - e[r - 1];
|
|
46
|
+
n > 0 && n < t && (t = n);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
}, p = (s, c, p, m, h) => {
|
|
51
|
+
let g = s.series, _ = g.map((e) => e.data), v = s.xAxis?.type ?? l(_), y = v === "category" ? [...s.xAxis?.categories ?? i(_)] : [], b = new Map(y.map((e, t) => [e, t])), x = o(v, (e) => b.get(e) ?? NaN), S = `${v}|${y.join("")}`, C = /* @__PURE__ */ new Set(), w = g.map((e, t) => {
|
|
52
|
+
let i = e.id ?? `#${t}`;
|
|
53
|
+
for (; C.has(i);) i += "'";
|
|
54
|
+
C.add(i);
|
|
55
|
+
let o = m.get(i);
|
|
56
|
+
(!o || o.data !== e.data || o.resolverKey !== S) && (o = {
|
|
57
|
+
data: e.data,
|
|
58
|
+
resolverKey: S,
|
|
59
|
+
cols: a(e.data, x)
|
|
60
|
+
}, m.set(i, o));
|
|
61
|
+
let s = e.type ?? "line", l = e.color ? n(e.color, h, c.palette[t % c.palette.length]) : c.palette[t % c.palette.length], u = o.cols, d = null;
|
|
62
|
+
if (s === "scatter" && u.colors) {
|
|
63
|
+
let e = /* @__PURE__ */ new Map();
|
|
64
|
+
d = u.colors.map((t) => {
|
|
65
|
+
if (t === void 0) return;
|
|
66
|
+
let r = e.get(t);
|
|
67
|
+
return r || e.set(t, r = n(t, h, l)), r;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
let f = e.id ?? String(t);
|
|
71
|
+
return {
|
|
72
|
+
index: t,
|
|
73
|
+
key: i,
|
|
74
|
+
id: f,
|
|
75
|
+
name: e.name ?? `Series ${t + 1}`,
|
|
76
|
+
type: s,
|
|
77
|
+
color: l,
|
|
78
|
+
colorCss: r(l),
|
|
79
|
+
lineWidth: e.lineWidth ?? 2,
|
|
80
|
+
pointSize: e.pointSize ?? 8,
|
|
81
|
+
opacity: e.opacity ?? (s === "area" ? .28 : s === "scatter" ? .78 : 1),
|
|
82
|
+
hidden: !!e.hidden || p.has(f),
|
|
83
|
+
showLabels: !!e.showLabels,
|
|
84
|
+
cols: u,
|
|
85
|
+
barOffset: 0,
|
|
86
|
+
barHalfWidth: 0,
|
|
87
|
+
barBase: null,
|
|
88
|
+
barTop: null,
|
|
89
|
+
pointColors: d
|
|
90
|
+
};
|
|
91
|
+
}), T = w.filter((e) => !e.hidden), E = w.length > 0 && w.every((e) => e.type === "scatter"), D = T.filter((e) => e.type === "bar"), O = v === "category" ? 1 : (() => {
|
|
92
|
+
let e = f(D.map((e) => e.cols));
|
|
93
|
+
return Number.isFinite(e) ? e : 1;
|
|
94
|
+
})();
|
|
95
|
+
if (D.length) {
|
|
96
|
+
let e = /* @__PURE__ */ new Map();
|
|
97
|
+
for (let t of D) {
|
|
98
|
+
let n = g[t.index].stack ?? `\u0000${t.key}`;
|
|
99
|
+
e.has(n) || e.set(n, e.size);
|
|
100
|
+
}
|
|
101
|
+
let t = O * (e.size > 1 ? .78 : .62), n = t / e.size, r = /* @__PURE__ */ new Map();
|
|
102
|
+
for (let i of D) {
|
|
103
|
+
let a = g[i.index].stack ?? `\u0000${i.key}`, o = e.get(a) ?? 0;
|
|
104
|
+
i.barOffset = -t / 2 + n * (o + .5), i.barHalfWidth = n / 2 * (e.size > 1 ? .86 : 1);
|
|
105
|
+
let s = r.get(a);
|
|
106
|
+
s || r.set(a, s = /* @__PURE__ */ new Map());
|
|
107
|
+
let { x: c, y: l, count: u } = i.cols;
|
|
108
|
+
i.barBase = new Float64Array(u), i.barTop = new Float64Array(u);
|
|
109
|
+
for (let e = 0; e < u; e++) {
|
|
110
|
+
let t = l[e];
|
|
111
|
+
if (!Number.isFinite(t)) {
|
|
112
|
+
i.barBase[e] = NaN, i.barTop[e] = NaN;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let n = s.get(c[e]) ?? [0, 0], r = t >= 0 ? n[0] : n[1];
|
|
116
|
+
i.barBase[e] = r, i.barTop[e] = r + t, t >= 0 ? n[0] += t : n[1] += t, s.set(c[e], n);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let k = s.xAxis, A;
|
|
121
|
+
if (v === "category") A = [-.5, Math.max(1, y.length) - .5];
|
|
122
|
+
else {
|
|
123
|
+
let n = [];
|
|
124
|
+
for (let e of T) n.push(e.cols.xMin, e.cols.xMax), e.type === "bar" && n.push(e.cols.xMin - O / 2, e.cols.xMax + O / 2);
|
|
125
|
+
if (A = e(...d(n), v === "time" ? [Date.now() - 864e5, Date.now()] : [0, 1]), E) {
|
|
126
|
+
let e = (A[1] - A[0]) * .04;
|
|
127
|
+
A = [A[0] - e, A[1] + e];
|
|
128
|
+
}
|
|
129
|
+
(k?.nice ?? (E && v === "linear")) && v === "linear" && (A = t(A[0], A[1], k?.tickCount ?? 6));
|
|
130
|
+
}
|
|
131
|
+
k?.min !== void 0 && (A[0] = k.min), k?.max !== void 0 && (A[1] = k.max), A = e(A[0], A[1]);
|
|
132
|
+
let j = s.yAxis, M = [];
|
|
133
|
+
for (let e of T) e.type === "bar" && e.barBase && e.barTop ? M.push(...d(e.barBase), ...d(e.barTop)) : M.push(e.cols.yMin, e.cols.yMax);
|
|
134
|
+
(D.length || j?.zero) && M.push(0);
|
|
135
|
+
let N = e(...d(M));
|
|
136
|
+
if (E) {
|
|
137
|
+
let e = (N[1] - N[0]) * .06;
|
|
138
|
+
N = [N[0] - e, N[1] + e];
|
|
139
|
+
}
|
|
140
|
+
(j?.nice ?? !0) && (j?.type ?? "linear") === "linear" && (N = t(N[0], N[1], j?.tickCount ?? 5)), D.length && !j?.zero && N[0] < 0 && d(M)[0] >= 0 && (N[0] = 0), j?.min !== void 0 && (N[0] = j.min), j?.max !== void 0 && (N[1] = j.max), N = e(N[0], N[1]);
|
|
141
|
+
let P = s.interaction === !1 ? !1 : s.interaction === !0 || s.interaction === void 0 ? !0 : s.interaction.zoom ?? !0, F = P === !1 ? {
|
|
142
|
+
x: !1,
|
|
143
|
+
y: !1
|
|
144
|
+
} : P === !0 ? {
|
|
145
|
+
x: !0,
|
|
146
|
+
y: E
|
|
147
|
+
} : {
|
|
148
|
+
x: P.includes("x"),
|
|
149
|
+
y: P.includes("y")
|
|
150
|
+
}, I = typeof s.tooltip == "object" ? s.tooltip : void 0;
|
|
151
|
+
return {
|
|
152
|
+
series: w,
|
|
153
|
+
x: u(k, v, y, !1),
|
|
154
|
+
y: u(j, j?.type === "time" ? "time" : "linear", [], !0),
|
|
155
|
+
base: {
|
|
156
|
+
x: A,
|
|
157
|
+
y: N
|
|
158
|
+
},
|
|
159
|
+
allScatter: E,
|
|
160
|
+
zoom: F,
|
|
161
|
+
tooltipMode: I?.mode ?? (E ? "nearest" : "axis"),
|
|
162
|
+
baseline: Math.min(Math.max(0, N[0]), N[1]),
|
|
163
|
+
minSpan: {
|
|
164
|
+
x: v === "category" ? 1 : (A[1] - A[0]) * 1e-7,
|
|
165
|
+
y: (N[1] - N[0]) * 1e-7
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}, m = /* @__PURE__ */ new WeakMap(), h = (e) => {
|
|
169
|
+
let t = m.get(e.cols);
|
|
170
|
+
return t || (t = new s(e.cols.x, e.cols.y, e.cols.count), m.set(e.cols, t)), t;
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
export { p as buildModel, l as detectXType, h as gridOf };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":["firstX","data","xs","list","i","item","detectXType","datas","x","axisModel","options","gridDefault","extent","min","max","values","v","smallestStep","step","c","cols","d","buildModel","input","s","xType","categories","collectCategories","categoryMap","resolveX","xResolver","name","resolverKey","usedKeys","series","key","index","entry","cache","normalizeData","type","color","resolveColor","element","theme","pointColors","resolved","rgba","id","toCss","hidden","visible","allScatter","bars","band","slots","stack","group","slotWidth","sums","slot","totals","count","y","t","base","xOpts","xRange","ensureSpan","pad","niceDomain","yOpts","yValues","yRange","zoomOption","zoomAxes","tooltip","grids","gridOf","grid","GridIndex"],"sources":["../../../../charts/src/engine/model.ts"],"sourcesContent":["// Options -> chart model: normalized data, colors, bar layout and the full\n// ranges of the axes. Pure (no DOM besides color resolution).\n\nimport { resolveColor, toCss, type Rgba } from \"./color\";\nimport {\n collectCategories,\n normalizeData,\n xResolver,\n type SeriesColumns,\n} from \"./data\";\nimport { ensureSpan, niceDomain } from \"./scale\";\nimport { GridIndex } from \"./spatial\";\nimport type { ChartTheme } from \"./theme\";\nimport type {\n ChartAxisOptions,\n ChartAxisType,\n ChartOptions,\n ChartSeriesData,\n ChartSeriesType,\n} from \"./types\";\nimport type { Range } from \"./viewport\";\n\nexport interface AxisModel {\n type: ChartAxisType;\n reverse: boolean;\n categories: string[];\n title?: string;\n format?: (value: number) => string;\n grid: boolean;\n visible: boolean;\n tickCount?: number;\n}\n\nexport interface SeriesModel {\n index: number;\n /** Key of the GPU resources and of the data cache */\n key: string;\n id: string;\n name: string;\n type: ChartSeriesType;\n color: Rgba;\n colorCss: string;\n lineWidth: number;\n pointSize: number;\n opacity: number;\n hidden: boolean;\n showLabels: boolean;\n cols: SeriesColumns;\n /** Bars: x offset of the series inside a group and half of the bar width */\n barOffset: number;\n barHalfWidth: number;\n /** Bars: bottom / top of every bar (stacks included) */\n barBase: Float64Array | null;\n barTop: Float64Array | null;\n /** Scatter: resolved per-point colors */\n pointColors: (Rgba | undefined)[] | null;\n}\n\nexport interface ChartModel {\n series: SeriesModel[];\n x: AxisModel;\n y: AxisModel;\n /** Full ranges (zoomed out) */\n base: { x: Range; y: Range };\n allScatter: boolean;\n zoom: { x: boolean; y: boolean };\n tooltipMode: \"nearest\" | \"axis\";\n /** Y value the areas are filled to */\n baseline: number;\n /** Smallest zoomed spans */\n minSpan: { x: number; y: number };\n}\n\nexport interface DataCacheEntry {\n data: ChartSeriesData;\n resolverKey: string;\n cols: SeriesColumns;\n}\n\nexport type DataCache = Map<string, DataCacheEntry>;\n\nconst firstX = (data: ChartSeriesData): unknown => {\n if (typeof data === \"object\" && data !== null && !(\"length\" in data)) {\n const xs = (data as { x?: ArrayLike<unknown> }).x;\n return xs && xs.length ? xs[0] : undefined;\n }\n const list = data as ArrayLike<unknown>;\n for (let i = 0; i < Math.min(list.length, 8); i++) {\n const item = list[i];\n if (Array.isArray(item)) return item[0];\n if (item && typeof item === \"object\") return (item as { x?: unknown }).x;\n }\n return undefined;\n};\n\n/** Axis type when not given: dates -> time, strings -> category */\nexport const detectXType = (\n datas: readonly ChartSeriesData[],\n): ChartAxisType => {\n for (const data of datas) {\n const x = firstX(data);\n if (x instanceof Date) return \"time\";\n if (typeof x === \"string\") return \"category\";\n }\n return \"linear\";\n};\n\nconst axisModel = (\n options: ChartAxisOptions | undefined,\n type: ChartAxisType,\n categories: string[],\n gridDefault: boolean,\n): AxisModel => ({\n type,\n reverse: !!options?.reverse,\n categories,\n title: options?.title,\n format: options?.format,\n grid: options?.grid ?? gridDefault,\n visible: options?.visible ?? true,\n tickCount: options?.tickCount,\n});\n\nconst extent = (values: ArrayLike<number>): Range => {\n let min = Infinity;\n let max = -Infinity;\n for (let i = 0; i < values.length; i++) {\n const v = values[i];\n if (!Number.isFinite(v)) continue;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n return [min, max];\n};\n\n/** Smallest positive gap between consecutive x values (bar width on numeric axes) */\nconst smallestStep = (cols: SeriesColumns[]): number => {\n let step = Infinity;\n for (const c of cols) {\n const xs = c.sorted ? c.x : Float64Array.from(c.x).sort();\n for (let i = 1; i < c.count; i++) {\n const d = xs[i] - xs[i - 1];\n if (d > 0 && d < step) step = d;\n }\n }\n return step;\n};\n\nexport const buildModel = (\n options: ChartOptions,\n theme: ChartTheme,\n hidden: ReadonlySet<string>,\n cache: DataCache,\n element: Element | null,\n): ChartModel => {\n const input = options.series;\n const datas = input.map((s) => s.data);\n const xType = options.xAxis?.type ?? detectXType(datas);\n const categories =\n xType === \"category\"\n ? [...(options.xAxis?.categories ?? collectCategories(datas))]\n : [];\n const categoryMap = new Map(categories.map((c, i) => [c, i]));\n const resolveX = xResolver(xType, (name) => categoryMap.get(name) ?? NaN);\n const resolverKey = `${xType}|${categories.join(\"\\u0001\")}`;\n\n const usedKeys = new Set<string>();\n const series: SeriesModel[] = input.map((s, index) => {\n let key = s.id ?? `#${index}`;\n while (usedKeys.has(key)) key += \"'\";\n usedKeys.add(key);\n let entry = cache.get(key);\n if (!entry || entry.data !== s.data || entry.resolverKey !== resolverKey) {\n entry = {\n data: s.data,\n resolverKey,\n cols: normalizeData(s.data, resolveX),\n };\n cache.set(key, entry);\n }\n const type = s.type ?? \"line\";\n const color = s.color\n ? resolveColor(\n s.color,\n element,\n theme.palette[index % theme.palette.length],\n )\n : theme.palette[index % theme.palette.length];\n const cols = entry.cols;\n let pointColors: (Rgba | undefined)[] | null = null;\n if (type === \"scatter\" && cols.colors) {\n const resolved = new Map<string, Rgba>();\n pointColors = cols.colors.map((c) => {\n if (c === undefined) return undefined;\n let rgba = resolved.get(c);\n if (!rgba) resolved.set(c, (rgba = resolveColor(c, element, color)));\n return rgba;\n });\n }\n const id = s.id ?? String(index);\n return {\n index,\n key,\n id,\n name: s.name ?? `Series ${index + 1}`,\n type,\n color,\n colorCss: toCss(color),\n lineWidth: s.lineWidth ?? 2,\n pointSize: s.pointSize ?? 8,\n opacity:\n s.opacity ?? (type === \"area\" ? 0.28 : type === \"scatter\" ? 0.78 : 1),\n hidden: !!s.hidden || hidden.has(id),\n showLabels: !!s.showLabels,\n cols,\n barOffset: 0,\n barHalfWidth: 0,\n barBase: null,\n barTop: null,\n pointColors,\n };\n });\n\n const visible = series.filter((s) => !s.hidden);\n const allScatter =\n series.length > 0 && series.every((s) => s.type === \"scatter\");\n\n // Bars: groups (one slot per stack) and stacking\n const bars = visible.filter((s) => s.type === \"bar\");\n const band =\n xType === \"category\"\n ? 1\n : (() => {\n const step = smallestStep(bars.map((s) => s.cols));\n return Number.isFinite(step) ? step : 1;\n })();\n if (bars.length) {\n const slots = new Map<string, number>();\n for (const s of bars) {\n const stack = input[s.index].stack ?? `\\u0000${s.key}`;\n if (!slots.has(stack)) slots.set(stack, slots.size);\n }\n const group = band * (slots.size > 1 ? 0.78 : 0.62);\n const slotWidth = group / slots.size;\n const sums = new Map<string, Map<number, [number, number]>>();\n for (const s of bars) {\n const stack = input[s.index].stack ?? `\\u0000${s.key}`;\n const slot = slots.get(stack) ?? 0;\n s.barOffset = -group / 2 + slotWidth * (slot + 0.5);\n s.barHalfWidth = (slotWidth / 2) * (slots.size > 1 ? 0.86 : 1);\n let totals = sums.get(stack);\n if (!totals) sums.set(stack, (totals = new Map()));\n const { x, y, count } = s.cols;\n s.barBase = new Float64Array(count);\n s.barTop = new Float64Array(count);\n for (let i = 0; i < count; i++) {\n const v = y[i];\n if (!Number.isFinite(v)) {\n s.barBase[i] = NaN;\n s.barTop[i] = NaN;\n continue;\n }\n const t = totals.get(x[i]) ?? [0, 0];\n const base = v >= 0 ? t[0] : t[1];\n s.barBase[i] = base;\n s.barTop[i] = base + v;\n if (v >= 0) t[0] += v;\n else t[1] += v;\n totals.set(x[i], t);\n }\n }\n }\n\n // X range\n const xOpts = options.xAxis;\n let xRange: Range;\n if (xType === \"category\") {\n xRange = [-0.5, Math.max(1, categories.length) - 0.5];\n } else {\n const values: number[] = [];\n for (const s of visible) {\n values.push(s.cols.xMin, s.cols.xMax);\n if (s.type === \"bar\") {\n values.push(s.cols.xMin - band / 2, s.cols.xMax + band / 2);\n }\n }\n xRange = ensureSpan(\n ...extent(values),\n xType === \"time\" ? [Date.now() - 86400000, Date.now()] : [0, 1],\n );\n if (allScatter) {\n const pad = (xRange[1] - xRange[0]) * 0.04;\n xRange = [xRange[0] - pad, xRange[1] + pad];\n }\n const nice = xOpts?.nice ?? (allScatter && xType === \"linear\");\n if (nice && xType === \"linear\") {\n xRange = niceDomain(xRange[0], xRange[1], xOpts?.tickCount ?? 6);\n }\n }\n if (xOpts?.min !== undefined) xRange[0] = xOpts.min;\n if (xOpts?.max !== undefined) xRange[1] = xOpts.max;\n xRange = ensureSpan(xRange[0], xRange[1]);\n\n // Y range\n const yOpts = options.yAxis;\n const yValues: number[] = [];\n for (const s of visible) {\n if (s.type === \"bar\" && s.barBase && s.barTop) {\n yValues.push(...extent(s.barBase), ...extent(s.barTop));\n } else {\n yValues.push(s.cols.yMin, s.cols.yMax);\n }\n }\n if (bars.length || yOpts?.zero) yValues.push(0);\n let yRange = ensureSpan(...extent(yValues));\n if (allScatter) {\n const pad = (yRange[1] - yRange[0]) * 0.06;\n yRange = [yRange[0] - pad, yRange[1] + pad];\n }\n if ((yOpts?.nice ?? true) && (yOpts?.type ?? \"linear\") === \"linear\") {\n yRange = niceDomain(yRange[0], yRange[1], yOpts?.tickCount ?? 5);\n }\n if (bars.length && !yOpts?.zero) {\n // bars start at zero: no padding below / above it\n if (yRange[0] < 0 && extent(yValues)[0] >= 0) yRange[0] = 0;\n }\n if (yOpts?.min !== undefined) yRange[0] = yOpts.min;\n if (yOpts?.max !== undefined) yRange[1] = yOpts.max;\n yRange = ensureSpan(yRange[0], yRange[1]);\n\n const zoomOption =\n options.interaction === false\n ? false\n : options.interaction === true || options.interaction === undefined\n ? true\n : (options.interaction.zoom ?? true);\n const zoomAxes =\n zoomOption === false\n ? { x: false, y: false }\n : zoomOption === true\n ? { x: true, y: allScatter }\n : { x: zoomOption.includes(\"x\"), y: zoomOption.includes(\"y\") };\n\n const tooltip =\n typeof options.tooltip === \"object\" ? options.tooltip : undefined;\n\n return {\n series,\n x: axisModel(xOpts, xType, categories, false),\n y: axisModel(yOpts, yOpts?.type === \"time\" ? \"time\" : \"linear\", [], true),\n base: { x: xRange, y: yRange },\n allScatter,\n zoom: zoomAxes,\n tooltipMode: tooltip?.mode ?? (allScatter ? \"nearest\" : \"axis\"),\n baseline: Math.min(Math.max(0, yRange[0]), yRange[1]),\n minSpan: {\n x: xType === \"category\" ? 1 : (xRange[1] - xRange[0]) * 1e-7,\n y: (yRange[1] - yRange[0]) * 1e-7,\n },\n };\n};\n\nconst grids = new WeakMap<SeriesColumns, GridIndex>();\n\n/** Spatial index of a scatter series, built on first use and kept with its data */\nexport const gridOf = (s: SeriesModel): GridIndex => {\n let grid = grids.get(s.cols);\n if (!grid) {\n grid = new GridIndex(s.cols.x, s.cols.y, s.cols.count);\n grids.set(s.cols, grid);\n }\n return grid;\n};\n"],"mappings":";;;;;AAiFA,IAAMA,KAAU,MAAmC;CACjD,IAAI,OAAOC,KAAS,YAAYA,KAAiB,EAAE,YAAYA,IAAO;EACpE,IAAMC,IAAMD,EAAoC;EAChD,OAAOC,KAAMA,EAAG,SAASA,EAAG,KAAK,KAAA;CACnC;CACA,IAAMC,IAAOF;CACb,KAAK,IAAIG,IAAI,GAAGA,IAAI,KAAK,IAAID,EAAK,QAAQ,CAAC,GAAG,KAAK;EACjD,IAAME,IAAOF,EAAKC;EAClB,IAAI,MAAM,QAAQC,CAAI,GAAG,OAAOA,EAAK;EACrC,IAAIA,KAAQ,OAAOA,KAAS,UAAU,OAAQA,EAAyB;CACzE;AAEF,GAGaC,KACX,MACkB;CAClB,KAAK,IAAML,KAAQM,GAAO;EACxB,IAAMC,IAAIR,EAAOC,CAAI;EACrB,IAAIO,aAAa,MAAM,OAAO;EAC9B,IAAI,OAAOA,KAAM,UAAU,OAAO;CACpC;CACA,OAAO;AACT,GAEMC,KACJ,GACA,GACA,GACA,OACe;CACf;CACA,SAAS,CAAC,CAACC,GAAS;CACpB;CACA,OAAOA,GAAS;CAChB,QAAQA,GAAS;CACjB,MAAMA,GAAS,QAAQC;CACvB,SAASD,GAAS,WAAW;CAC7B,WAAWA,GAAS;AACtB,IAEME,KAAU,MAAqC;CACnD,IAAIC,IAAM,UACNC,IAAM;CACV,KAAK,IAAIV,IAAI,GAAGA,IAAIW,EAAO,QAAQ,KAAK;EACtC,IAAMC,IAAID,EAAOX;EACjB,AAAK,OAAO,SAASY,CAAC,MAClBA,IAAIH,MAAK,IAAMG,IACfA,IAAIF,MAAK,IAAME;CACrB;C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AU,CAAC,GAAG,EAAI;EACxE,MAAM;GAAE,GAAGJ;GAAQ,GAAGM;EAAO;EAC7B;EACA,MAAME;EACN,aAAaC,GAAS,SAASxB,IAAa,YAAY;EACxD,UAAU,KAAK,IAAI,KAAK,IAAI,GAAGqB,EAAO,EAAE,GAAGA,EAAO,EAAE;EACpD,SAAS;GACP,GAAGhD,MAAU,aAAa,KAAK0C,EAAO,KAAKA,EAAO,MAAM;GACxD,IAAIM,EAAO,KAAKA,EAAO,MAAM;EAC/B;CACF;AACF,GAEMI,oBAAQ,IAAI,QAAkC,GAGvCC,KAAU,MAA8B;CACnD,IAAIC,IAAOF,EAAM,IAAIrD,EAAE,IAAI;CAK3B,OAJKuD,MACH,IAAO,IAAIC,EAAUxD,EAAE,KAAK,GAAGA,EAAE,KAAK,GAAGA,EAAE,KAAK,KAAK,GACrDqD,EAAM,IAAIrD,EAAE,MAAMuD,CAAI,IAEjBA;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./color.cjs");var t=(e,t=e.fontSize,n=400)=>`${n} ${t}px ${e.fontFamily}`,n=e=>Math.round(e)+.5,r=(e,t)=>{let{plot:n}=t,r=e.x0===void 0?-1/0:t.xToPx(e.x0),i=e.x1===void 0?1/0:t.xToPx(e.x1),a=e.y0===void 0?1/0:t.yToPx(e.y0),o=e.y1===void 0?-1/0:t.yToPx(e.y1),s=Math.max(n.x,Math.min(r,i)),c=Math.min(n.x+n.width,Math.max(r,i)),l=Math.max(n.y,Math.min(a,o)),u=Math.min(n.y+n.height,Math.max(a,o));return{x:s,y:l,width:c-s,height:u-l}},i=(i,a)=>{let{scales:o,theme:s,x:c,y:l,xTicks:u,yTicks:d}=a,{plot:f}=o;i.clearRect(0,0,a.width,a.height),i.save(),i.beginPath(),i.rect(f.x,f.y,f.width,f.height),i.clip();for(let t of a.annotations){if(t.type!==`rect`)continue;let n=r(t,o);n.width<=0||n.height<=0||(i.fillStyle=e.toCss(t.color,t.opacity),i.fillRect(n.x,n.y,n.width,n.height))}if(i.restore(),i.lineWidth=1,i.strokeStyle=e.toCss(s.grid),i.beginPath(),l.grid)for(let e of d.values){let t=n(o.yToPx(e));t<f.y-1||t>f.y+f.height+1||(i.moveTo(f.x,t),i.lineTo(f.x+f.width,t))}if(c.grid)for(let e of u.values){let t=n(o.xToPx(e));t<f.x-1||t>f.x+f.width+1||(i.moveTo(t,f.y),i.lineTo(t,f.y+f.height))}i.stroke();let p=Math.ceil(s.fontSize*1.4);if(i.font=t(s),i.fillStyle=e.toCss(s.textMuted),c.visible){i.strokeStyle=e.toCss(s.axis),i.beginPath();let r=n(f.y+f.height);i.moveTo(f.x,r),i.lineTo(f.x+f.width,r),i.stroke(),i.textBaseline=`top`,i.textAlign=`center`;let l=-1/0,d=u.values.map((e,t)=>({px:o.xToPx(e),text:u.labels[t]})).sort((e,t)=>e.px-t.px);for(let{px:e,text:t}of d){if(e<f.x-.5||e>f.x+f.width+.5)continue;let n=i.measureText(t).width,r=Math.max(0,Math.min(a.width-n,e-n/2));r<l+6||(l=r+n,i.fillText(t,r+n/2,f.y+f.height+7))}c.title&&(i.font=t(s,s.fontSize+1,500),i.fillStyle=e.toCss(s.text,.8),i.fillText(c.title,f.x+f.width/2,f.y+f.height+p+10))}l.visible&&(i.font=t(s),i.fillStyle=e.toCss(s.textMuted),i.textAlign=`right`,i.textBaseline=`middle`,d.values.forEach((e,t)=>{let n=o.yToPx(e);n<f.y-.5||n>f.y+f.height+.5||i.fillText(d.labels[t],f.x-8,n)}),l.title&&(i.save(),i.font=t(s,s.fontSize+1,500),i.fillStyle=e.toCss(s.text,.8),i.translate(p/2+4,f.y+f.height/2),i.rotate(-Math.PI/2),i.textAlign=`center`,i.fillText(l.title,0,0),i.restore()))},a=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,o=(e,t)=>e.x>=t.x&&e.y>=t.y&&e.x+e.width<=t.x+t.width&&e.y+e.height<=t.y+t.height,s=(e,t,n,r,i,a)=>{e.lineWidth=3,e.lineJoin=`round`,e.strokeStyle=a,e.strokeText(t,n,r),e.fillStyle=i,e.fillText(t,n,r)},c=(e,t,n,r,i=[])=>{let s=[];for(let c of e){let e=n(c.text),l=c.r+4,u=[{x:c.x+l,y:c.y-r/2,width:e,height:r},{x:c.x-l-e,y:c.y-r/2,width:e,height:r},{x:c.x-e/2,y:c.y-l-r,width:e,height:r},{x:c.x-e/2,y:c.y+l,width:e,height:r}].find(e=>o(e,t)&&!i.some(t=>a(t,e)));u&&(i.push(u),s.push({label:c,box:u}))}return s},l=(i,a)=>{let{scales:o,theme:l}=a,{plot:u}=o;i.clearRect(0,0,a.width,a.height),i.save(),i.beginPath(),i.rect(u.x,u.y,u.width,u.height),i.clip();let d=e.toCss(l.background,.9),f=[],p=l.fontSize+4;for(let r of a.annotations){if(r.type!==`line`)continue;let a=e.toCss(r.color);if(i.strokeStyle=a,i.lineWidth=r.width,i.setLineDash(r.dash),i.beginPath(),r.axis===`y`){let e=n(o.yToPx(r.value));i.moveTo(u.x,e),i.lineTo(u.x+u.width,e),i.stroke(),r.label&&(i.setLineDash([]),i.font=t(l,l.fontSize,500),i.textAlign=`right`,i.textBaseline=`bottom`,s(i,r.label,u.x+u.width-6,e-3,a,d))}else{let e=n(o.xToPx(r.value));i.moveTo(e,u.y),i.lineTo(e,u.y+u.height),i.stroke(),r.label&&(i.setLineDash([]),i.font=t(l,l.fontSize,500),i.textAlign=`left`,i.textBaseline=`top`,s(i,r.label,e+5,u.y+5,a,d))}}i.setLineDash([]),i.font=t(l,l.fontSize+1,600);for(let t of a.annotations){if(t.type!==`rect`||!t.label)continue;let n=r(t,o);if(n.width<=0||n.height<=0)continue;let a=i.measureText(t.label).width,s=t.labelPosition,c=s.endsWith(`left`)?n.x+10:s.endsWith(`right`)?n.x+n.width-10-a:n.x+(n.width-a)/2,l=s.startsWith(`top`)?n.y+10:s.startsWith(`bottom`)?n.y+n.height-10-p:n.y+(n.height-p)/2;i.textAlign=`left`,i.textBaseline=`top`,i.fillStyle=e.toCss(t.labelColor),i.fillText(t.label,c,l),f.push({x:c,y:l,width:a,height:p})}if(a.pointLabels.length){i.font=t(l),i.textAlign=`left`,i.textBaseline=`middle`;let n=e.toCss(l.text,.85),r=c(a.pointLabels,u,e=>i.measureText(e).width,p-2,f);for(let{label:e,box:t}of r)s(i,e.text,t.x,t.y+t.height/2,n,d)}i.restore()};exports.drawBackground=i,exports.drawForeground=l,exports.font=t,exports.placeLabels=c;
|
|
2
|
+
//# sourceMappingURL=overlay.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.cjs","names":["toCss","require_color","font","theme","weight","size","crisp","v","rectOf","s","xa","a","xb","ya","yb","left","plot","right","top","bottom","drawBackground","input","scales","ctx","r","y","yTicks","py","x","xTicks","px","line","base","lastRight","order","i","b","w","text","overlaps","inside","haloText","halo","color","placeLabels","placed","label","labels","measure","gap","box","height","c","occupied","o","drawForeground","labelHeight","pos","tx","ty","textColor","t"],"sources":["../../../../charts/src/engine/overlay.ts"],"sourcesContent":["// Canvas2D layers around the data: background (areas, grid, axes, tick\n// labels) and foreground (reference lines, annotation and point labels).\n\nimport { toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport type { Rect, Scales } from \"./layout\";\nimport type { AxisModel } from \"./model\";\nimport type { ChartTheme } from \"./theme\";\nimport type { ChartLabelPosition } from \"./types\";\n\nexport interface ResolvedRect {\n type: \"rect\";\n x0?: number;\n x1?: number;\n y0?: number;\n y1?: number;\n color: Rgba;\n opacity: number;\n label?: string;\n labelPosition: ChartLabelPosition;\n labelColor: Rgba;\n}\n\nexport interface ResolvedLine {\n type: \"line\";\n axis: \"x\" | \"y\";\n value: number;\n color: Rgba;\n width: number;\n dash: number[];\n label?: string;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n}\n\nexport const font = (theme: ChartTheme, size = theme.fontSize, weight = 400) =>\n `${weight} ${size}px ${theme.fontFamily}`;\n\nconst crisp = (v: number) => Math.round(v) + 0.5;\n\nconst rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n const xa = a.x0 === undefined ? -Infinity : s.xToPx(a.x0);\n const xb = a.x1 === undefined ? Infinity : s.xToPx(a.x1);\n const ya = a.y0 === undefined ? Infinity : s.yToPx(a.y0);\n const yb = a.y1 === undefined ? -Infinity : s.yToPx(a.y1);\n const left = Math.max(plot.x, Math.min(xa, xb));\n const right = Math.min(plot.x + plot.width, Math.max(xa, xb));\n const top = Math.max(plot.y, Math.min(ya, yb));\n const bottom = Math.min(plot.y + plot.height, Math.max(ya, yb));\n return { x: left, y: top, width: right - left, height: bottom - top };\n};\n\nexport interface BackgroundInput {\n width: number;\n height: number;\n scales: Scales;\n x: AxisModel;\n y: AxisModel;\n xTicks: AxisTicks;\n yTicks: AxisTicks;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, x, y, xTicks, yTicks } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n\n // areas\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n for (const a of input.annotations) {\n if (a.type !== \"rect\") continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n ctx.fillStyle = toCss(a.color, a.opacity);\n ctx.fillRect(r.x, r.y, r.width, r.height);\n }\n ctx.restore();\n\n // grid\n ctx.lineWidth = 1;\n ctx.strokeStyle = toCss(theme.grid);\n ctx.beginPath();\n if (y.grid) {\n for (const v of yTicks.values) {\n const py = crisp(scales.yToPx(v));\n if (py < plot.y - 1 || py > plot.y + plot.height + 1) continue;\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n }\n }\n if (x.grid) {\n for (const v of xTicks.values) {\n const px = crisp(scales.xToPx(v));\n if (px < plot.x - 1 || px > plot.x + plot.width + 1) continue;\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n }\n }\n ctx.stroke();\n\n const line = Math.ceil(theme.fontSize * 1.4);\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n\n // x axis\n if (x.visible) {\n ctx.strokeStyle = toCss(theme.axis);\n ctx.beginPath();\n const base = crisp(plot.y + plot.height);\n ctx.moveTo(plot.x, base);\n ctx.lineTo(plot.x + plot.width, base);\n ctx.stroke();\n ctx.textBaseline = \"top\";\n ctx.textAlign = \"center\";\n let lastRight = -Infinity;\n // left to right (reversed axes list their ticks right to left)\n const order = xTicks.values\n .map((v, i) => ({ px: scales.xToPx(v), text: xTicks.labels[i] }))\n .sort((a, b) => a.px - b.px);\n for (const { px, text } of order) {\n if (px < plot.x - 0.5 || px > plot.x + plot.width + 0.5) continue;\n const w = ctx.measureText(text).width;\n const left = Math.max(0, Math.min(input.width - w, px - w / 2));\n if (left < lastRight + 6) continue;\n lastRight = left + w;\n ctx.fillText(text, left + w / 2, plot.y + plot.height + 7);\n }\n if (x.title) {\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.fillText(\n x.title,\n plot.x + plot.width / 2,\n plot.y + plot.height + line + 10,\n );\n }\n }\n\n // y axis\n if (y.visible) {\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"middle\";\n yTicks.values.forEach((v, i) => {\n const py = scales.yToPx(v);\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) return;\n ctx.fillText(yTicks.labels[i], plot.x - 8, py);\n });\n if (y.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(line / 2 + 4, plot.y + plot.height / 2);\n ctx.rotate(-Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y.title, 0, 0);\n ctx.restore();\n }\n }\n};\n\nconst overlaps = (a: Rect, b: Rect) =>\n a.x < b.x + b.width &&\n b.x < a.x + a.width &&\n a.y < b.y + b.height &&\n b.y < a.y + a.height;\n\nconst inside = (r: Rect, plot: Rect) =>\n r.x >= plot.x &&\n r.y >= plot.y &&\n r.x + r.width <= plot.x + plot.width &&\n r.y + r.height <= plot.y + plot.height;\n\n/** Text with a halo in the background color (readable over data) */\nconst haloText = (\n ctx: CanvasRenderingContext2D,\n text: string,\n x: number,\n y: number,\n color: string,\n halo: string,\n) => {\n ctx.lineWidth = 3;\n ctx.lineJoin = \"round\";\n ctx.strokeStyle = halo;\n ctx.strokeText(text, x, y);\n ctx.fillStyle = color;\n ctx.fillText(text, x, y);\n};\n\n/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */\nexport const placeLabels = (\n labels: readonly PointLabel[],\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: Rect[] = [],\n): { label: PointLabel; box: Rect }[] => {\n const placed: { label: PointLabel; box: Rect }[] = [];\n for (const label of labels) {\n const w = measure(label.text);\n const gap = label.r + 4;\n const candidates: Rect[] = [\n { x: label.x + gap, y: label.y - height / 2, width: w, height },\n { x: label.x - gap - w, y: label.y - height / 2, width: w, height },\n { x: label.x - w / 2, y: label.y - gap - height, width: w, height },\n { x: label.x - w / 2, y: label.y + gap, width: w, height },\n ];\n const box = candidates.find(\n (c) => inside(c, plot) && !occupied.some((o) => overlaps(o, c)),\n );\n if (!box) continue;\n occupied.push(box);\n placed.push({ label, box });\n }\n return placed;\n};\n\nexport interface ForegroundInput {\n width: number;\n height: number;\n scales: Scales;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n pointLabels: readonly PointLabel[];\n}\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n ctx.clearRect(0, 0, input.width, input.height);\n ctx.save();\n ctx.beginPath();\n ctx.rect(plot.x, plot.y, plot.width, plot.height);\n ctx.clip();\n\n const halo = toCss(theme.background, 0.9);\n const occupied: Rect[] = [];\n const labelHeight = theme.fontSize + 4;\n\n for (const a of input.annotations) {\n if (a.type !== \"line\") continue;\n const color = toCss(a.color);\n ctx.strokeStyle = color;\n ctx.lineWidth = a.width;\n ctx.setLineDash(a.dash);\n ctx.beginPath();\n if (a.axis === \"y\") {\n const py = crisp(scales.yToPx(a.value));\n ctx.moveTo(plot.x, py);\n ctx.lineTo(plot.x + plot.width, py);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"right\";\n ctx.textBaseline = \"bottom\";\n haloText(ctx, a.label, plot.x + plot.width - 6, py - 3, color, halo);\n }\n } else {\n const px = crisp(scales.xToPx(a.value));\n ctx.moveTo(px, plot.y);\n ctx.lineTo(px, plot.y + plot.height);\n ctx.stroke();\n if (a.label) {\n ctx.setLineDash([]);\n ctx.font = font(theme, theme.fontSize, 500);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n haloText(ctx, a.label, px + 5, plot.y + 5, color, halo);\n }\n }\n }\n ctx.setLineDash([]);\n\n // labels of areas\n ctx.font = font(theme, theme.fontSize + 1, 600);\n for (const a of input.annotations) {\n if (a.type !== \"rect\" || !a.label) continue;\n const r = rectOf(a, scales);\n if (r.width <= 0 || r.height <= 0) continue;\n const pad = 10;\n const w = ctx.measureText(a.label).width;\n const pos = a.labelPosition;\n const tx = pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - w\n : r.x + (r.width - w) / 2;\n const ty = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - labelHeight\n : r.y + (r.height - labelHeight) / 2;\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"top\";\n ctx.fillStyle = toCss(a.labelColor);\n ctx.fillText(a.label, tx, ty);\n occupied.push({ x: tx, y: ty, width: w, height: labelHeight });\n }\n\n // point labels\n if (input.pointLabels.length) {\n ctx.font = font(theme);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n const textColor = toCss(theme.text, 0.85);\n const placed = placeLabels(\n input.pointLabels,\n plot,\n (t) => ctx.measureText(t).width,\n labelHeight - 2,\n occupied,\n );\n for (const { label, box } of placed) {\n haloText(ctx, label.text, box.x, box.y + box.height / 2, textColor, halo);\n }\n }\n ctx.restore();\n};\n"],"mappings":"+BA2CA,IAAaE,GAAQ,EAAmB,EAAOC,EAAM,SAAU,EAAS,MACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,aAEzBG,EAAS,GAAc,KAAK,MAAMC,CAAC,EAAI,GAEvCC,GAAU,EAAiB,IAAoB,CACnD,GAAM,CAAE,QAASC,EACXC,EAAKC,EAAE,KAAO,IAAA,GAAY,KAAYF,EAAE,MAAME,EAAE,EAAE,EAClDC,EAAKD,EAAE,KAAO,IAAA,GAAY,IAAWF,EAAE,MAAME,EAAE,EAAE,EACjDE,EAAKF,EAAE,KAAO,IAAA,GAAY,IAAWF,EAAE,MAAME,EAAE,EAAE,EACjDG,EAAKH,EAAE,KAAO,IAAA,GAAY,KAAYF,EAAE,MAAME,EAAE,EAAE,EAClDI,EAAO,KAAK,IAAIC,EAAK,EAAG,KAAK,IAAIN,EAAIE,CAAE,CAAC,EACxCK,EAAQ,KAAK,IAAID,EAAK,EAAIA,EAAK,MAAO,KAAK,IAAIN,EAAIE,CAAE,CAAC,EACtDM,EAAM,KAAK,IAAIF,EAAK,EAAG,KAAK,IAAIH,EAAIC,CAAE,CAAC,EACvCK,EAAS,KAAK,IAAIH,EAAK,EAAIA,EAAK,OAAQ,KAAK,IAAIH,EAAIC,CAAE,CAAC,EAC9D,MAAO,CAAE,EAAGC,EAAM,EAAGG,EAAK,MAAOD,E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AI,QAAQ,CACd"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Rgba } from './color.cjs';
|
|
2
|
+
import { AxisTicks } from './axis.cjs';
|
|
3
|
+
import { Rect, Scales } from './layout.cjs';
|
|
4
|
+
import { AxisModel } from './model.cjs';
|
|
5
|
+
import { ChartTheme } from './theme.cjs';
|
|
6
|
+
import { ChartLabelPosition } from './types.cjs';
|
|
7
|
+
export interface ResolvedRect {
|
|
8
|
+
type: "rect";
|
|
9
|
+
x0?: number;
|
|
10
|
+
x1?: number;
|
|
11
|
+
y0?: number;
|
|
12
|
+
y1?: number;
|
|
13
|
+
color: Rgba;
|
|
14
|
+
opacity: number;
|
|
15
|
+
label?: string;
|
|
16
|
+
labelPosition: ChartLabelPosition;
|
|
17
|
+
labelColor: Rgba;
|
|
18
|
+
}
|
|
19
|
+
export interface ResolvedLine {
|
|
20
|
+
type: "line";
|
|
21
|
+
axis: "x" | "y";
|
|
22
|
+
value: number;
|
|
23
|
+
color: Rgba;
|
|
24
|
+
width: number;
|
|
25
|
+
dash: number[];
|
|
26
|
+
label?: string;
|
|
27
|
+
}
|
|
28
|
+
export type ResolvedAnnotation = ResolvedRect | ResolvedLine;
|
|
29
|
+
export interface PointLabel {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
/** Radius of the dot */
|
|
33
|
+
r: number;
|
|
34
|
+
text: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const font: (theme: ChartTheme, size?: number, weight?: number) => string;
|
|
37
|
+
export interface BackgroundInput {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
scales: Scales;
|
|
41
|
+
x: AxisModel;
|
|
42
|
+
y: AxisModel;
|
|
43
|
+
xTicks: AxisTicks;
|
|
44
|
+
yTicks: AxisTicks;
|
|
45
|
+
theme: ChartTheme;
|
|
46
|
+
annotations: readonly ResolvedAnnotation[];
|
|
47
|
+
}
|
|
48
|
+
export declare const drawBackground: (ctx: CanvasRenderingContext2D, input: BackgroundInput) => void;
|
|
49
|
+
/** Greedy placement: right, left, above, below the dot; skipped when no slot is free */
|
|
50
|
+
export declare const placeLabels: (labels: readonly PointLabel[], plot: Rect, measure: (text: string) => number, height: number, occupied?: Rect[]) => {
|
|
51
|
+
label: PointLabel;
|
|
52
|
+
box: Rect;
|
|
53
|
+
}[];
|
|
54
|
+
export interface ForegroundInput {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
scales: Scales;
|
|
58
|
+
theme: ChartTheme;
|
|
59
|
+
annotations: readonly ResolvedAnnotation[];
|
|
60
|
+
pointLabels: readonly PointLabel[];
|
|
61
|
+
}
|
|
62
|
+
export declare const drawForeground: (ctx: CanvasRenderingContext2D, input: ForegroundInput) => void;
|