minerva-design 1.17.2 → 1.18.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 +10 -0
- package/dist/angular/fesm2022/minerva-angular.mjs +27 -25
- package/dist/angular/fesm2022/minerva-angular.mjs.map +1 -1
- package/dist/angular/types/minerva-angular.d.ts +1 -1
- package/dist/charts/engine/chart.cjs +1 -1
- package/dist/charts/engine/chart.cjs.map +1 -1
- package/dist/charts/engine/chart.js +309 -301
- package/dist/charts/engine/chart.js.map +1 -1
- package/dist/charts/engine/overlay.cjs +1 -1
- package/dist/charts/engine/overlay.cjs.map +1 -1
- package/dist/charts/engine/overlay.d.cts +5 -0
- package/dist/charts/engine/overlay.d.ts +5 -0
- package/dist/charts/engine/overlay.js +87 -69
- package/dist/charts/engine/overlay.js.map +1 -1
- package/dist/charts/engine/scene.cjs +1 -1
- package/dist/charts/engine/scene.cjs.map +1 -1
- package/dist/charts/engine/scene.d.cts +5 -0
- package/dist/charts/engine/scene.d.ts +5 -0
- package/dist/charts/engine/scene.js +32 -32
- package/dist/charts/engine/scene.js.map +1 -1
- package/dist/charts/engine/types.d.cts +14 -0
- package/dist/charts/engine/types.d.ts +14 -0
- package/dist/charts/react/Chart.cjs +1 -1
- package/dist/charts/react/Chart.cjs.map +1 -1
- package/dist/charts/react/Chart.d.cts +4 -2
- package/dist/charts/react/Chart.d.ts +4 -2
- package/dist/charts/react/Chart.js +42 -42
- package/dist/charts/react/Chart.js.map +1 -1
- package/dist/charts/react/charts.cjs +1 -1
- package/dist/charts/react/charts.cjs.map +1 -1
- package/dist/charts/react/charts.js +320 -231
- package/dist/charts/react/charts.js.map +1 -1
- package/dist/charts/react/types.d.cts +8 -2
- package/dist/charts/react/types.d.ts +8 -2
- package/dist/core/contracts.cjs +1 -1
- package/dist/core/contracts.cjs.map +1 -1
- package/dist/core/contracts.js +1 -1
- package/dist/core/contracts.js.map +1 -1
- package/dist/native/charts/src/engine/overlay.cjs +1 -1
- package/dist/native/charts/src/engine/overlay.cjs.map +1 -1
- package/dist/native/charts/src/engine/overlay.js +82 -65
- package/dist/native/charts/src/engine/overlay.js.map +1 -1
- package/dist/native/charts/src/engine/scene.cjs +1 -1
- package/dist/native/charts/src/engine/scene.cjs.map +1 -1
- package/dist/native/charts/src/engine/scene.js +32 -32
- package/dist/native/charts/src/engine/scene.js.map +1 -1
- package/dist/react/components/QuadrantTaskBoard/QuadrantTaskBoard.cjs +1 -1
- package/dist/react/components/QuadrantTaskBoard/QuadrantTaskBoard.cjs.map +1 -1
- package/dist/react/components/QuadrantTaskBoard/QuadrantTaskBoard.js +14 -8
- package/dist/react/components/QuadrantTaskBoard/QuadrantTaskBoard.js.map +1 -1
- package/dist/react/components/QuadrantTaskBoard/quadrantTaskBoard.module.scss.cjs +1 -1
- package/dist/react/components/QuadrantTaskBoard/quadrantTaskBoard.module.scss.cjs.map +1 -1
- package/dist/react/components/QuadrantTaskBoard/quadrantTaskBoard.module.scss.js +16 -15
- package/dist/react/components/QuadrantTaskBoard/quadrantTaskBoard.module.scss.js.map +1 -1
- package/dist/react/style.css +1 -1
- package/dist/react/styles/quadrant-task-board.css +1 -1
- package/dist/taro/index.js +1514 -1496
- package/dist/taro/style.css +22 -0
- package/dist/uni/style.css +22 -0
- package/dist/vue/components/QuadrantTaskBoard/QuadrantTaskBoard.vue.js.map +1 -1
- package/dist/vue/components/QuadrantTaskBoard/QuadrantTaskBoard.vue_vue_type_script_setup_true_lang.js +14 -8
- package/dist/vue/components/QuadrantTaskBoard/QuadrantTaskBoard.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/weapp/charts/canvas.js +35 -7
- package/dist/weapp/controls.wxss +22 -0
- package/dist/web-components/components/quadrant-task-board/quadrant-task-board.js +7 -7
- package/dist/web-components/components/quadrant-task-board/quadrant-task-board.js.map +1 -1
- package/dist/web-components/styles/QuadrantTaskBoard/quadrantTaskBoard.css.js +1 -1
- package/dist/web-components/styles/QuadrantTaskBoard/quadrantTaskBoard.css.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./color.cjs"),t=require("./layout.cjs");var n=6,r=(t,n)=>{let r=t[3];if(r<.6)return;let i=e.mix(n,t,r),a=e.relativeLuminance(i);return 1.05/(a+.05)>=(a+.05)/.062?`#ffffff`:`rgba(17, 24, 39, 0.92)`},i=(e,t=e.fontSize,n=400)=>`${n} ${t}px ${e.fontFamily}`,a=(e,n,r,i)=>{let{plot:a}=n,o=t.toScreen(n,e.x??0,e.y??0),s=n.horizontal?{x:e.y===void 0,y:e.x===void 0}:{x:e.x===void 0,y:e.y===void 0},c=s.x?a.x+a.width/2:o.x,l=s.y?a.y+a.height/2:o.y,u=c-r/2,d=l-i/2;return e.anchor===`top`?d=l+6:e.anchor===`bottom`?d=l-6-i:e.anchor===`left`?u=c+6:e.anchor===`right`&&(u=c-6-r),u=Math.max(a.x+6,Math.min(u,a.x+a.width-6-r)),d=Math.max(a.y+2,Math.min(d,a.y+a.height-2-i)),{x:u,y:d,width:r,height:i}},o=(e,n)=>{let{plot:r}=n,[i,a]=n.horizontal?[r.y,r.y+r.height]:[r.x,r.x+r.width],[o,s]=n.horizontal?[r.x,r.x+r.width]:[r.y,r.y+r.height],c=(e,t,n)=>e<t?t:e>n?n:e;return t.screenRect(n,c(n.xToPx(e.x0??-1/0),i,a),c(n.xToPx(e.x1??1/0),i,a),c(n.yToPx(e.y0??-1/0),o,s),c(n.yToPx(e.y1??1/0),o,s))},s=e=>!!(e.label||e.badge||e.detail||e.description),c=(e,t,n)=>{if(n(e)<=t)return e;let r=Array.from(e),i=0,a=r.length;for(;i<a;){let e=Math.ceil((i+a)/2);n(`${r.slice(0,e).join(``)}…`)<=t?i=e:a=e-1}return i>0?`${r.slice(0,i).join(``).trimEnd()}…`:``},l=(e,t,n,r)=>{if(!s(e)||t.width<=0||t.height<=0)return null;let i=n+4,a=Math.max(0,t.width-20),o=n+1,l=Math.max(9,n-1),u=e.badge?c(e.badge,Math.max(0,a-10),e=>r(e,l,700)):``,d=u?r(u,l,700)+10:0,f=e.detail??``,p=f?r(f,n,500):0,m=()=>a-(u?d+6:0)-(f?p+6:0);f&&e.label&&m()<32&&(f=``,p=0),f&&m()<0&&(f=c(f,Math.max(0,a-(u?d+6:0)),e=>r(e,n,500)),p=f?r(f,n,500):0);let h=e.label?c(e.label,Math.max(0,m()),e=>r(e,o,600)):``,g=[];u&&g.push({kind:`badge`,text:u,x:0,y:0,width:d,height:i,size:l,weight:700}),h&&g.push({kind:`label`,text:h,x:0,y:0,width:r(h,o,600),height:i,size:o,weight:600}),f&&g.push({kind:`detail`,text:f,x:0,y:0,width:p,height:i,size:n,weight:500});let _=e.description?c(e.description,a,e=>r(e,n,400)):``,v=g.reduce((e,t)=>e+t.width,0)+Math.max(0,g.length-1)*6,y=_?r(_,n,400):0;if(!g.length&&!_)return null;let b=(g.length?i:0)+(_?i+(g.length?2:0):0),x=e.labelPosition,S=x.startsWith(`top`)?t.y+10:x.startsWith(`bottom`)?t.y+t.height-10-b:t.y+(t.height-b)/2,C=e=>x.endsWith(`left`)?t.x+10:x.endsWith(`right`)?t.x+t.width-10-e:t.x+(t.width-e)/2,w=[],T=C(v);for(let e of g)w.push({...e,x:T,y:S}),T+=e.width+6;_&&w.push({kind:`description`,text:_,x:C(y),y:S+(g.length?i+2:0),width:y,height:i,size:n,weight:400});let E=Math.max(v,y);return{parts:w,box:{x:C(E),y:S,width:E,height:b}}},u=(e,t)=>({vertical:e.axis===`x`!==t.horizontal,at:e.axis===`x`?t.xToPx(e.value):t.yToPx(e.value)}),d=(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,f=(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,p=(e,t,r,i)=>{let a=e.bar;if(!a)return null;let o=Math.max(a.x,t.x),s=Math.min(a.x+a.width,t.x+t.width),l=Math.max(a.y,t.y),u=Math.min(a.y+a.height,t.y+t.height);if(u-l<i-2)return null;let d=c(e.text,s-o-12,r);if(!d)return null;let f=r(d),p=e.align===`start`?o+n:(o+s)/2-f/2;return{label:d===e.text?e:{...e,text:d},box:{x:p,y:(l+u)/2-i/2,width:f,height:i}}},m=2,h=(e,t,n,r,i,a)=>{let
|
|
1
|
+
const e=require("./color.cjs"),t=require("./layout.cjs");var n=6,r=(t,n)=>{let r=t[3];if(r<.6)return;let i=e.mix(n,t,r),a=e.relativeLuminance(i);return 1.05/(a+.05)>=(a+.05)/.062?`#ffffff`:`rgba(17, 24, 39, 0.92)`},i=(e,t=e.fontSize,n=400)=>`${n} ${t}px ${e.fontFamily}`,a=(e,n,r,i)=>{let{plot:a}=n,o=t.toScreen(n,e.x??0,e.y??0),s=n.horizontal?{x:e.y===void 0,y:e.x===void 0}:{x:e.x===void 0,y:e.y===void 0},c=s.x?a.x+a.width/2:o.x,l=s.y?a.y+a.height/2:o.y,u=c-r/2,d=l-i/2;return e.anchor===`top`?d=l+6:e.anchor===`bottom`?d=l-6-i:e.anchor===`left`?u=c+6:e.anchor===`right`&&(u=c-6-r),u=Math.max(a.x+6,Math.min(u,a.x+a.width-6-r)),d=Math.max(a.y+2,Math.min(d,a.y+a.height-2-i)),{x:u,y:d,width:r,height:i}},o=(e,n)=>{let{plot:r}=n,[i,a]=n.horizontal?[r.y,r.y+r.height]:[r.x,r.x+r.width],[o,s]=n.horizontal?[r.x,r.x+r.width]:[r.y,r.y+r.height],c=(e,t,n)=>e<t?t:e>n?n:e;return t.screenRect(n,c(n.xToPx(e.x0??-1/0),i,a),c(n.xToPx(e.x1??1/0),i,a),c(n.yToPx(e.y0??-1/0),o,s),c(n.yToPx(e.y1??1/0),o,s))},s=e=>!!(e.label||e.badge||e.detail||e.description),c=(e,t,n)=>{if(n(e)<=t)return e;let r=Array.from(e),i=0,a=r.length;for(;i<a;){let e=Math.ceil((i+a)/2);n(`${r.slice(0,e).join(``)}…`)<=t?i=e:a=e-1}return i>0?`${r.slice(0,i).join(``).trimEnd()}…`:``},l=(e,t,n,r)=>{if(!s(e)||t.width<=0||t.height<=0)return null;let i=n+4,a=Math.max(0,t.width-20),o=n+1,l=Math.max(9,n-1),u=e.badge?c(e.badge,Math.max(0,a-10),e=>r(e,l,700)):``,d=u?r(u,l,700)+10:0,f=e.detail??``,p=f?r(f,n,500):0,m=()=>a-(u?d+6:0)-(f?p+6:0);f&&e.label&&m()<32&&(f=``,p=0),f&&m()<0&&(f=c(f,Math.max(0,a-(u?d+6:0)),e=>r(e,n,500)),p=f?r(f,n,500):0);let h=e.label?c(e.label,Math.max(0,m()),e=>r(e,o,600)):``,g=[];u&&g.push({kind:`badge`,text:u,x:0,y:0,width:d,height:i,size:l,weight:700}),h&&g.push({kind:`label`,text:h,x:0,y:0,width:r(h,o,600),height:i,size:o,weight:600}),f&&g.push({kind:`detail`,text:f,x:0,y:0,width:p,height:i,size:n,weight:500});let _=e.description?c(e.description,a,e=>r(e,n,400)):``,v=g.reduce((e,t)=>e+t.width,0)+Math.max(0,g.length-1)*6,y=_?r(_,n,400):0;if(!g.length&&!_)return null;let b=(g.length?i:0)+(_?i+(g.length?2:0):0),x=e.labelPosition,S=x.startsWith(`top`)?t.y+10:x.startsWith(`bottom`)?t.y+t.height-10-b:t.y+(t.height-b)/2,C=e=>x.endsWith(`left`)?t.x+10:x.endsWith(`right`)?t.x+t.width-10-e:t.x+(t.width-e)/2,w=[],T=C(v);for(let e of g)w.push({...e,x:T,y:S}),T+=e.width+6;_&&w.push({kind:`description`,text:_,x:C(y),y:S+(g.length?i+2:0),width:y,height:i,size:n,weight:400});let E=Math.max(v,y);return{parts:w,box:{x:C(E),y:S,width:E,height:b}}},u=(e,t)=>({vertical:e.axis===`x`!==t.horizontal,at:e.axis===`x`?t.xToPx(e.value):t.yToPx(e.value)}),d=(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,f=(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,p=(e,t,r,i)=>{let a=e.bar;if(!a)return null;let o=Math.max(a.x,t.x),s=Math.min(a.x+a.width,t.x+t.width),l=Math.max(a.y,t.y),u=Math.min(a.y+a.height,t.y+t.height);if(u-l<i-2)return null;let d=c(e.text,s-o-12,r);if(!d)return null;let f=r(d),p=e.align===`start`?o+n:(o+s)/2-f/2;return{label:d===e.text?e:{...e,text:d},box:{x:p,y:(l+u)/2-i/2,width:f,height:i}}},m=2,h={x:4,y:2},g=(e,t,n)=>Math.hypot(Math.max(n.x-e,0,e-(n.x+n.width)),Math.max(n.y-t,0,t-(n.y+n.height))),_=(e,t,n,r,i,a,o=[])=>{let s=Math.max(t.x,n.x)+m,l=Math.min(t.x+t.width,n.x+n.width)-m,u=Math.max(t.y,n.y)+m,p=Math.min(t.y+t.height,n.y+n.height)-m;if(l-s<=0||p-u<i)return null;let _={x:s-.01,y:u-.01,width:l-s+.02,height:p-u+.02},v=o.filter(t=>Math.abs(t.x-e.x)>=.5||Math.abs(t.y-e.y)>=.5),y=t=>{if(!f(t,_))return!1;let n={x:t.x-h.x,y:t.y-h.y,width:t.width+h.x*2,height:t.height+h.y*2};if(a.some(e=>d(e,n)))return!1;let r=g(e.x,e.y,t);return v.every(e=>{let n=g(e.x,e.y,t);return n>=e.r+2&&n>r})},b=e.r+4,x=Math.min(Math.max(e.y-i/2,u),p-i),S={right:l-(e.x+b),left:e.x-b-s},C=S.right>=S.left?[`right`,`left`]:[`left`,`right`],w=(t,n)=>[{x:t===`right`?e.x+b:e.x-b-n,y:x,width:n,height:i}],T=t=>{let n=Math.min(Math.max(e.x-t/2,s),l-t);return[{x:n,y:e.y-b-i,width:t,height:i},{x:n,y:e.y+b,width:t,height:i}]},E=r(e.text),D=[...w(C[0],E),...w(C[1],E),...T(E)].find(y);if(D)return{label:e,box:D};let O=[[S[C[0]],e=>w(C[0],e)],[S[C[1]],e=>w(C[1],e)],[l-s,T]],k=null,A=Array.from(e.text).length,j=Math.min(4,Math.ceil(A*.4));for(let[t,n]of O){let i=c(e.text,t,r);if(!i||k&&i.length<=k.label.text.length||Array.from(i).length-1<j)continue;let a=n(r(i)).find(y);a&&(k={label:{...e,text:i},box:a})}return k},v=(e,t,n,r,i=[])=>{let a=[],o=e.filter(e=>e.bounds);for(let s of e){if(s.placement===`inside`){let e=p(s,t,n,r);e&&a.push(e);continue}if(s.bounds){let e=_(s,s.bounds,t,n,r,i,o);if(!e)continue;i.push(e.box),a.push(e);continue}let e=n(s.text),c=s.r+4,l={x:s.x-e/2,y:s.y-c-r,width:e,height:r},u={x:s.x-e/2,y:s.y+c,width:e,height:r},m={x:s.x+c,y:s.y-r/2,width:e,height:r},h={x:s.x-c-e,y:s.y-r/2,width:e,height:r},g=(s.placement===`above`?[l]:s.placement===`below`?[u]:s.placement===`right`?[m,h]:s.placement===`left`?[h,m]:[{x:s.x+c,y:s.y-r/2,width:e,height:r},{x:s.x-c-e,y:s.y-r/2,width:e,height:r},l,u]).find(e=>f(e,t)&&!i.some(t=>d(t,e)));g&&(i.push(g),a.push({label:s,box:g}))}return a};exports.areaTitleLayout=l,exports.font=i,exports.hasAreaTitle=s,exports.insideLabelColor=r,exports.lineOf=u,exports.placeLabels=v,exports.rectOf=o,exports.textBox=a;
|
|
2
2
|
//# sourceMappingURL=overlay.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.cjs","names":["mix","relativeLuminance","toScreen","screenRect","require_color","require_layout","INSIDE_PAD","insideLabelColor","alpha","fill","seen","background","l","font","theme","weight","size","textBox","s","at","a","free","px","plot","py","x","width","y","height","rectOf","xLo","xHi","yLo","yHi","along","lo","hi","hasAreaTitle","fitText","text","max","chars","mid","areaTitleLayout","r","lineHeight","fontSize","labelSize","badgeSize","badge","measure","t","badgeWidth","detail","detailWidth","room","label","line","description","lineWidth","sum","p","descriptionWidth","pos","top","startOf","parts","lineOf","overlaps","b","inside","insideBox","bar","x0","x1","y0","y1","w","CELL_PAD","cellBox","bounds","slack","c","occupied","o","gap","sideY","sides","beside","side","stacked","box","cuts","cw","best","total","keep","boxes","cut","placeLabels","placed","labels","fit","above","below","right","left"],"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 { mix, relativeLuminance, toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport { screenRect, toScreen, type Rect, type 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 badge?: string;\n detail?: string;\n description?: string;\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 interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n /**\n * Fixed side (bar values: above / below, left / right of horizontal\n * bars; `inside` the `bar`); any free side around the dot otherwise\n */\n placement?: \"above\" | \"below\" | \"left\" | \"right\" | \"inside\";\n /** `inside` labels: the bar, in CSS pixels */\n bar?: Rect;\n /** `inside` labels: at the start of the bar (horizontal bars) or centered */\n align?: \"start\" | \"center\";\n /**\n * Text color contrasting with a solid bar (`inside` labels), drawn\n * without a halo; the text color of the theme with a halo otherwise\n */\n color?: string;\n /**\n * Cell the label stays in (`labelCells`: the quadrant of the dot), in CSS\n * pixels: on the side of the dot with more room, cut with an ellipsis\n * when it does not fit\n */\n bounds?: Rect;\n}\n\n/** Padding of the labels inside the bars, CSS pixels */\nconst INSIDE_PAD = 6;\n\n/**\n * Color of a text written on a bar of color `fill` (alpha included) over\n * `background`: white or near-black, whichever contrasts more; `undefined`\n * for translucent bars (the theme text color with a halo reads better)\n */\nexport const insideLabelColor = (\n fill: Rgba,\n background: Rgba,\n): string | undefined => {\n const alpha = fill[3];\n if (alpha < 0.6) return undefined;\n const seen = mix(background, fill, alpha);\n const l = relativeLuminance(seen);\n // WCAG contrast with white (L = 1) and with #111827 (L ≈ 0.012)\n return 1.05 / (l + 0.05) >= (l + 0.05) / 0.062\n ? \"#ffffff\"\n : \"rgba(17, 24, 39, 0.92)\";\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\n/** Path of a rounded box with half-height corners */\nconst pill = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n) => {\n const r = Math.min(h / 2, w / 2);\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const at = toScreen(s, a.x ?? 0, a.y ?? 0);\n const free = s.horizontal\n ? { x: a.y === undefined, y: a.x === undefined }\n : { x: a.x === undefined, y: a.y === undefined };\n const px = free.x ? plot.x + plot.width / 2 : at.x;\n const py = free.y ? plot.y + plot.height / 2 : at.y;\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\n/** Screen box of an area annotation, clipped to the plot */\nexport const rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n // clamp every edge to the plot first: an open edge maps to ±Infinity and\n // `Infinity - Infinity` would make the size NaN (nothing drawn)\n const [xLo, xHi] = s.horizontal\n ? [plot.y, plot.y + plot.height]\n : [plot.x, plot.x + plot.width];\n const [yLo, yHi] = s.horizontal\n ? [plot.x, plot.x + plot.width]\n : [plot.y, plot.y + plot.height];\n const along = (px: number, lo: number, hi: number) =>\n px < lo ? lo : px > hi ? hi : px;\n return screenRect(\n s,\n along(s.xToPx(a.x0 ?? -Infinity), xLo, xHi),\n along(s.xToPx(a.x1 ?? Infinity), xLo, xHi),\n along(s.yToPx(a.y0 ?? -Infinity), yLo, yHi),\n along(s.yToPx(a.y1 ?? Infinity), yLo, yHi),\n );\n};\n\n/** A text of the title block of an area: badge, label, detail or description */\nexport interface AreaText {\n kind: \"badge\" | \"label\" | \"detail\" | \"description\";\n text: string;\n /** Box of the text (the pill of a badge), CSS pixels */\n x: number;\n y: number;\n width: number;\n height: number;\n /** Font size and weight */\n size: number;\n weight: number;\n}\n\n/** Title block of an area annotation, in its `labelPosition` corner */\nexport interface AreaTitle {\n parts: AreaText[];\n /** Box around the parts (the point labels avoid it) */\n box: Rect;\n}\n\n/** Whether an area annotation has a title block */\nexport const hasAreaTitle = (a: ResolvedRect): boolean =>\n !!(a.label || a.badge || a.detail || a.description);\n\n/** Text cut with an ellipsis to fit `max` pixels (\"\" when nothing fits) */\nconst fitText = (\n text: string,\n max: number,\n width: (text: string) => number,\n): string => {\n if (width(text) <= max) return text;\n const chars = Array.from(text);\n let lo = 0;\n let hi = chars.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (width(`${chars.slice(0, mid).join(\"\")}…`) <= max) lo = mid;\n else hi = mid - 1;\n }\n return lo > 0 ? `${chars.slice(0, lo).join(\"\").trimEnd()}…` : \"\";\n};\n\n/**\n * Layout of the title block of an area: `[badge] label detail` on the first\n * line, the description under it; the block sits in the `labelPosition`\n * corner, 10px from the edges, and the texts are cut to the area width\n */\nexport const areaTitleLayout = (\n a: ResolvedRect,\n r: Rect,\n fontSize: number,\n measure: (text: string, size: number, weight: number) => number,\n): AreaTitle | null => {\n if (!hasAreaTitle(a) || r.width <= 0 || r.height <= 0) return null;\n const pad = 10;\n const lineHeight = fontSize + 4;\n const max = Math.max(0, r.width - pad * 2);\n const labelSize = fontSize + 1;\n const badgeSize = Math.max(9, fontSize - 1);\n const gap = 6;\n const badge = a.badge\n ? fitText(a.badge, Math.max(0, max - 10), (t) => measure(t, badgeSize, 700))\n : \"\";\n const badgeWidth = badge ? measure(badge, badgeSize, 700) + 10 : 0;\n let detail = a.detail ?? \"\";\n let detailWidth = detail ? measure(detail, fontSize, 500) : 0;\n const room = () =>\n max - (badge ? badgeWidth + gap : 0) - (detail ? detailWidth + gap : 0);\n // a narrow area keeps the title rather than the detail\n if (detail && a.label && room() < 32) {\n detail = \"\";\n detailWidth = 0;\n }\n if (detail && room() < 0) {\n detail = fitText(\n detail,\n Math.max(0, max - (badge ? badgeWidth + gap : 0)),\n (t) => measure(t, fontSize, 500),\n );\n detailWidth = detail ? measure(detail, fontSize, 500) : 0;\n }\n const label = a.label\n ? fitText(a.label, Math.max(0, room()), (t) => measure(t, labelSize, 600))\n : \"\";\n const line: AreaText[] = [];\n if (badge)\n line.push({\n kind: \"badge\",\n text: badge,\n x: 0,\n y: 0,\n width: badgeWidth,\n height: lineHeight,\n size: badgeSize,\n weight: 700,\n });\n if (label)\n line.push({\n kind: \"label\",\n text: label,\n x: 0,\n y: 0,\n width: measure(label, labelSize, 600),\n height: lineHeight,\n size: labelSize,\n weight: 600,\n });\n if (detail)\n line.push({\n kind: \"detail\",\n text: detail,\n x: 0,\n y: 0,\n width: detailWidth,\n height: lineHeight,\n size: fontSize,\n weight: 500,\n });\n const description = a.description\n ? fitText(a.description, max, (t) => measure(t, fontSize, 400))\n : \"\";\n const lineWidth =\n line.reduce((sum, p) => sum + p.width, 0) +\n Math.max(0, line.length - 1) * gap;\n const descriptionWidth = description\n ? measure(description, fontSize, 400)\n : 0;\n if (!line.length && !description) return null;\n const height =\n (line.length ? lineHeight : 0) +\n (description ? lineHeight + (line.length ? 2 : 0) : 0);\n const pos = a.labelPosition;\n const top = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - height\n : r.y + (r.height - height) / 2;\n const startOf = (width: number) =>\n pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - width\n : r.x + (r.width - width) / 2;\n const parts: AreaText[] = [];\n let x = startOf(lineWidth);\n for (const p of line) {\n parts.push({ ...p, x, y: top });\n x += p.width + gap;\n }\n if (description)\n parts.push({\n kind: \"description\",\n text: description,\n x: startOf(descriptionWidth),\n y: top + (line.length ? lineHeight + 2 : 0),\n width: descriptionWidth,\n height: lineHeight,\n size: fontSize,\n weight: 400,\n });\n const width = Math.max(lineWidth, descriptionWidth);\n return {\n parts,\n box: { x: startOf(width), y: top, width, height },\n };\n};\n\n/**\n * Where a reference line goes: `vertical` lines run at screen x `at`,\n * horizontal ones at screen y `at`\n */\nexport const lineOf = (\n a: ResolvedLine,\n s: Scales,\n): { vertical: boolean; at: number } => {\n const vertical = (a.axis === \"x\") !== s.horizontal;\n return {\n vertical,\n at: a.axis === \"x\" ? s.xToPx(a.value) : s.yToPx(a.value),\n };\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 /** Right axis (dual axis charts) */\n y2?: AxisModel | null;\n y2Ticks?: AxisTicks | null;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, xTicks, yTicks } = input;\n const { plot } = scales;\n // horizontal charts: the value axis along the bottom, the x axis on the left\n const x = scales.horizontal ? input.y : input.x;\n const y = scales.horizontal ? input.x : input.y;\n const bottomTicks = scales.horizontal ? yTicks : xTicks;\n const leftTicks = scales.horizontal ? xTicks : yTicks;\n const bottomPx = scales.horizontal ? scales.yToPx : scales.xToPx;\n const leftPx = scales.horizontal ? scales.xToPx : scales.yToPx;\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 leftTicks.values) {\n const py = crisp(leftPx(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 bottomTicks.values) {\n const px = crisp(bottomPx(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 = bottomTicks.values\n .map((v, i) => ({ px: bottomPx(v), text: bottomTicks.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 let lastBottom = -Infinity;\n // top to bottom: category rows of horizontal charts never overlap\n const rows = leftTicks.values\n .map((v, i) => ({ py: leftPx(v), text: leftTicks.labels[i] }))\n .sort((a, b) => a.py - b.py);\n const rowHeight = theme.fontSize + 2;\n for (const { py, text } of rows) {\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) continue;\n if (scales.horizontal) {\n if (py - rowHeight / 2 < lastBottom) continue;\n lastBottom = py + rowHeight / 2;\n }\n ctx.fillText(text, 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 // right axis\n const y2 = scales.horizontal ? null : input.y2;\n const y2Ticks = input.y2Ticks;\n if (y2 && y2Ticks && y2.visible) {\n const right = plot.x + plot.width;\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n y2Ticks.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(y2Ticks.labels[i], right + 8, py);\n });\n if (y2.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(input.width - line / 2 - 4, plot.y + plot.height / 2);\n ctx.rotate(Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y2.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/**\n * Box of a label inside its bar (the visible part of it): the text cut with\n * an ellipsis to fit, at the start of horizontal bars and centered in\n * vertical ones; `null` when the bar is too small\n */\nconst insideBox = (\n label: PointLabel,\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n): { label: PointLabel; box: Rect } | null => {\n const bar = label.bar;\n if (!bar) return null;\n const x0 = Math.max(bar.x, plot.x);\n const x1 = Math.min(bar.x + bar.width, plot.x + plot.width);\n const y0 = Math.max(bar.y, plot.y);\n const y1 = Math.min(bar.y + bar.height, plot.y + plot.height);\n if (y1 - y0 < height - 2) return null;\n const text = fitText(label.text, x1 - x0 - INSIDE_PAD * 2, measure);\n if (!text) return null;\n const w = measure(text);\n const x = label.align === \"start\" ? x0 + INSIDE_PAD : (x0 + x1) / 2 - w / 2;\n return {\n label: text === label.text ? label : { ...label, text },\n box: { x, y: (y0 + y1) / 2 - height / 2, width: w, height },\n };\n};\n\n/** Room kept between a label and the edges of its cell, CSS pixels */\nconst CELL_PAD = 2;\n\n/**\n * Box of a label kept inside a cell of the plot (`bounds`): beside the dot\n * on the side with more room in the cell (moved up or down into the cell\n * near its edges), else above or below it (moved sideways into the cell);\n * cut with an ellipsis to the room left when the whole text fits nowhere;\n * `null` when no free slot is left\n */\nconst cellBox = (\n label: PointLabel,\n bounds: Rect,\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: readonly Rect[],\n): { label: PointLabel; box: Rect } | null => {\n const x0 = Math.max(bounds.x, plot.x) + CELL_PAD;\n const x1 = Math.min(bounds.x + bounds.width, plot.x + plot.width) - CELL_PAD;\n const y0 = Math.max(bounds.y, plot.y) + CELL_PAD;\n const y1 =\n Math.min(bounds.y + bounds.height, plot.y + plot.height) - CELL_PAD;\n if (x1 - x0 <= 0 || y1 - y0 < height) return null;\n // a hair of slack: a text cut to the exact room ends on the edge\n const slack = {\n x: x0 - 0.01,\n y: y0 - 0.01,\n width: x1 - x0 + 0.02,\n height: y1 - y0 + 0.02,\n };\n const free = (c: Rect) =>\n inside(c, slack) && !occupied.some((o) => overlaps(o, c));\n const gap = label.r + 4;\n // centered on the dot, moved into the cell near its top or bottom edge\n const sideY = Math.min(Math.max(label.y - height / 2, y0), y1 - height);\n const room = { right: x1 - (label.x + gap), left: label.x - gap - x0 };\n const sides: (\"right\" | \"left\")[] =\n room.right >= room.left ? [\"right\", \"left\"] : [\"left\", \"right\"];\n const beside = (side: \"right\" | \"left\", w: number): Rect[] => [\n {\n x: side === \"right\" ? label.x + gap : label.x - gap - w,\n y: sideY,\n width: w,\n height,\n },\n ];\n const stacked = (w: number): Rect[] => {\n // slid sideways into the cell near its edges (still over the dot)\n const x = Math.min(Math.max(label.x - w / 2, x0), x1 - w);\n return [\n { x, y: label.y - gap - height, width: w, height },\n { x, y: label.y + gap, width: w, height },\n ];\n };\n const w = measure(label.text);\n const whole = [\n ...beside(sides[0]!, w),\n ...beside(sides[1]!, w),\n ...stacked(w),\n ];\n const box = whole.find(free);\n if (box) return { label, box };\n // the whole text fits nowhere: cut it to the room beside the dot or above\n // / below it, keeping the longest text (the roomiest side on ties)\n const cuts: [number, (w: number) => Rect[]][] = [\n [room[sides[0]!], (cw) => beside(sides[0]!, cw)],\n [room[sides[1]!], (cw) => beside(sides[1]!, cw)],\n [x1 - x0, stacked],\n ];\n let best: { label: PointLabel; box: Rect } | null = null;\n // a cut keeps enough of the name to tell it (else the label is skipped,\n // like an overlapping one: the tooltip still names the point)\n const total = Array.from(label.text).length;\n const keep = Math.min(4, Math.ceil(total * 0.4));\n for (const [max, boxes] of cuts) {\n const text = fitText(label.text, max, measure);\n if (!text || (best && text.length <= best.label.text.length)) continue;\n if (Array.from(text).length - 1 < keep) continue;\n const cut = boxes(measure(text)).find(free);\n if (cut) best = { label: { ...label, text }, box: cut };\n }\n return best;\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 if (label.placement === \"inside\") {\n const fit = insideBox(label, plot, measure, height);\n if (fit) placed.push(fit);\n continue;\n }\n if (label.bounds) {\n const fit = cellBox(label, label.bounds, plot, measure, height, occupied);\n if (!fit) continue;\n occupied.push(fit.box);\n placed.push(fit);\n continue;\n }\n const w = measure(label.text);\n const gap = label.r + 4;\n const above = {\n x: label.x - w / 2,\n y: label.y - gap - height,\n width: w,\n height,\n };\n const below = { x: label.x - w / 2, y: label.y + gap, width: w, height };\n const right = {\n x: label.x + gap,\n y: label.y - height / 2,\n width: w,\n height,\n };\n const left = {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n };\n const candidates: Rect[] =\n label.placement === \"above\"\n ? [above]\n : label.placement === \"below\"\n ? [below]\n : label.placement === \"right\"\n ? [right, left]\n : label.placement === \"left\"\n ? [left, right]\n : [\n {\n x: label.x + gap,\n y: label.y - height / 2,\n width: w,\n height,\n },\n {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n },\n above,\n below,\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 * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n /** Lines between consecutive bars (waterfall connectors), drawn first */\n connectors?: readonly {\n x0: number;\n y0: number;\n x1: number;\n y1: number;\n color: string;\n width: number;\n dash: readonly number[];\n }[];\n /** Dependency arrows (Gantt charts), drawn over the connectors */\n arrows?: readonly ArrowPath[];\n}\n\n/** An elbow arrow in stage pixels (see `dependencyArrows`) */\nexport interface ArrowPath {\n points: readonly { x: number; y: number }[];\n head: readonly { x: number; y: number }[];\n color: string;\n width: number;\n}\n\n/** Elbow arrows: polylines with rounded corners and filled heads */\nexport const drawArrows = (\n ctx: CanvasRenderingContext2D,\n arrows: readonly ArrowPath[],\n) => {\n for (const a of arrows) {\n const pts = a.points;\n const first = pts[0];\n if (!first) continue;\n ctx.strokeStyle = a.color;\n ctx.fillStyle = a.color;\n ctx.lineWidth = a.width;\n ctx.lineJoin = \"round\";\n ctx.setLineDash([]);\n ctx.beginPath();\n ctx.moveTo(first.x, first.y);\n for (let i = 1; i < pts.length; i++) {\n const p = pts[i]!;\n const next = pts[i + 1];\n const prev = pts[i - 1]!;\n if (next && typeof ctx.arcTo === \"function\") {\n // rounded elbow, at most half of the shorter leg\n const r = Math.min(\n 4,\n Math.hypot(p.x - prev.x, p.y - prev.y) / 2,\n Math.hypot(next.x - p.x, next.y - p.y) / 2,\n );\n ctx.arcTo(p.x, p.y, next.x, next.y, r);\n } else {\n ctx.lineTo(p.x, p.y);\n }\n }\n ctx.stroke();\n const [tip, b0, b1] = a.head;\n if (tip && b0 && b1) {\n ctx.beginPath();\n ctx.moveTo(tip.x, tip.y);\n ctx.lineTo(b0.x, b0.y);\n ctx.lineTo(b1.x, b1.y);\n ctx.closePath();\n ctx.fill();\n }\n }\n};\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) 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 for (const c of input.connectors ?? []) {\n ctx.strokeStyle = c.color;\n ctx.lineWidth = c.width;\n ctx.setLineDash([...c.dash]);\n ctx.beginPath();\n // crisp hairlines along the pixel grid\n const along = c.y0 === c.y1;\n const x0 = along ? c.x0 : crisp(c.x0);\n const y0 = along ? crisp(c.y0) : c.y0;\n ctx.moveTo(x0, y0);\n ctx.lineTo(along ? c.x1 : x0, along ? y0 : c.y1);\n ctx.stroke();\n }\n ctx.setLineDash([]);\n if (input.arrows?.length) drawArrows(ctx, input.arrows);\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 const where = lineOf(a, scales);\n if (!where.vertical) {\n const py = crisp(where.at);\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(where.at);\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 for (const a of input.annotations) {\n if (a.type !== \"rect\" || !hasAreaTitle(a)) continue;\n const title = areaTitleLayout(\n a,\n rectOf(a, scales),\n theme.fontSize,\n (text, size, weight) => {\n ctx.font = font(theme, size, weight);\n return ctx.measureText(text).width;\n },\n );\n if (!title) continue;\n const color = toCss(a.labelColor);\n const muted = toCss(theme.textMuted);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n for (const p of title.parts) {\n const cy = p.y + p.height / 2;\n if (p.kind === \"badge\") {\n const h = p.height - 2;\n pill(ctx, p.x, cy - h / 2, p.width, h);\n ctx.fillStyle = toCss(a.labelColor, 0.16);\n ctx.fill();\n ctx.font = font(theme, p.size, p.weight);\n ctx.fillStyle = color;\n ctx.fillText(p.text, p.x + 5, cy);\n continue;\n }\n ctx.font = font(theme, p.size, p.weight);\n ctx.fillStyle = p.kind === \"label\" ? color : muted;\n ctx.fillText(p.text, p.x, cy);\n }\n occupied.push(title.box);\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n let placed: { label: PointLabel; box: Rect }[] = [];\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 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 const y = box.y + box.height / 2;\n if (label.color) {\n ctx.fillStyle = label.color;\n ctx.fillText(label.text, box.x, y);\n } else haloText(ctx, label.text, box.x, y, textColor, halo);\n }\n }\n ctx.restore();\n return placed;\n};\n"],"mappings":"yDA6EA,IAAMM,EAAa,EAONC,GACX,EACA,IACuB,CACvB,IAAMC,EAAQC,EAAK,GACnB,GAAID,EAAQ,GAAK,OACjB,IAAME,EAAOV,EAAAA,IAAIW,EAAYF,EAAMD,CAAK,EAClCI,EAAIX,EAAAA,kBAAkBS,CAAI,EAEhC,MAAO,OAAQE,EAAI,OAAUA,EAAI,KAAQ,KACrC,UACA,wBACN,EAEaC,GAAQ,EAAmB,EAAOC,EAAM,SAAU,EAAS,MACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,aA2BlBG,GACX,EACA,EACA,EACA,IACS,CACT,GAAM,CAAE,QAASC,EACXC,EAAKjB,EAAAA,SAASgB,EAAGE,EAAE,GAAK,EAAGA,EAAE,GAAK,CAAC,EACnCC,EAAOH,EAAE,WACX,CAAE,EAAGE,EAAE,IAAM,IAAA,GAAW,EAAGA,EAAE,IAAM,IAAA,EAAU,EAC7C,CAAE,EAAGA,EAAE,IAAM,IAAA,GAAW,EAAGA,EAAE,IAAM,IAAA,EAAU,EAC3CE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,CAAC,EAC5B,CACA,OAAOA,CACT"}
|
|
1
|
+
{"version":3,"file":"overlay.cjs","names":["mix","relativeLuminance","toScreen","screenRect","require_color","require_layout","INSIDE_PAD","insideLabelColor","alpha","fill","seen","background","l","font","theme","weight","size","textBox","s","at","a","free","px","plot","py","x","width","y","height","rectOf","xLo","xHi","yLo","yHi","along","lo","hi","hasAreaTitle","fitText","text","max","chars","mid","areaTitleLayout","r","lineHeight","fontSize","labelSize","badgeSize","badge","measure","t","badgeWidth","detail","detailWidth","room","label","line","description","lineWidth","sum","p","descriptionWidth","pos","top","startOf","parts","lineOf","overlaps","b","inside","insideBox","bar","x0","x1","y0","y1","w","CELL_PAD","LABEL_GAP","distanceTo","cellBox","bounds","slack","others","dots","d","c","spaced","occupied","o","own","far","gap","sideY","sides","beside","side","stacked","box","cuts","cw","best","total","keep","boxes","cut","placeLabels","placed","labels","fit","above","below","right","left"],"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 { mix, relativeLuminance, toCss, type Rgba } from \"./color\";\nimport type { AxisTicks } from \"./axis\";\nimport { screenRect, toScreen, type Rect, type 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 badge?: string;\n detail?: string;\n description?: string;\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 interface ResolvedText {\n type: \"text\";\n x?: number;\n y?: number;\n text: string;\n anchor: \"center\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n color: Rgba;\n weight: number;\n}\n\nexport type ResolvedAnnotation = ResolvedRect | ResolvedLine | ResolvedText;\n\nexport interface PointLabel {\n x: number;\n y: number;\n /** Radius of the dot */\n r: number;\n text: string;\n /**\n * Fixed side (bar values: above / below, left / right of horizontal\n * bars; `inside` the `bar`); any free side around the dot otherwise\n */\n placement?: \"above\" | \"below\" | \"left\" | \"right\" | \"inside\";\n /** `inside` labels: the bar, in CSS pixels */\n bar?: Rect;\n /** `inside` labels: at the start of the bar (horizontal bars) or centered */\n align?: \"start\" | \"center\";\n /**\n * Text color contrasting with a solid bar (`inside` labels), drawn\n * without a halo; the text color of the theme with a halo otherwise\n */\n color?: string;\n /**\n * Cell the label stays in (`labelCells`: the quadrant of the dot), in CSS\n * pixels: on the side of the dot with more room, cut with an ellipsis\n * when it does not fit\n */\n bounds?: Rect;\n /**\n * Placed (it keeps its room) but not drawn: a card over the chart names\n * the point\n */\n hidden?: boolean;\n}\n\n/** Padding of the labels inside the bars, CSS pixels */\nconst INSIDE_PAD = 6;\n\n/**\n * Color of a text written on a bar of color `fill` (alpha included) over\n * `background`: white or near-black, whichever contrasts more; `undefined`\n * for translucent bars (the theme text color with a halo reads better)\n */\nexport const insideLabelColor = (\n fill: Rgba,\n background: Rgba,\n): string | undefined => {\n const alpha = fill[3];\n if (alpha < 0.6) return undefined;\n const seen = mix(background, fill, alpha);\n const l = relativeLuminance(seen);\n // WCAG contrast with white (L = 1) and with #111827 (L ≈ 0.012)\n return 1.05 / (l + 0.05) >= (l + 0.05) / 0.062\n ? \"#ffffff\"\n : \"rgba(17, 24, 39, 0.92)\";\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\n/** Path of a rounded box with half-height corners */\nconst pill = (\n ctx: CanvasRenderingContext2D,\n x: number,\n y: number,\n w: number,\n h: number,\n) => {\n const r = Math.min(h / 2, w / 2);\n ctx.beginPath();\n ctx.moveTo(x + r, y);\n ctx.lineTo(x + w - r, y);\n ctx.arcTo(x + w, y, x + w, y + r, r);\n ctx.lineTo(x + w, y + h - r);\n ctx.arcTo(x + w, y + h, x + w - r, y + h, r);\n ctx.lineTo(x + r, y + h);\n ctx.arcTo(x, y + h, x, y + h - r, r);\n ctx.lineTo(x, y + r);\n ctx.arcTo(x, y, x + r, y, r);\n ctx.closePath();\n};\n\n/** Box of a text annotation, kept inside the plot */\nexport const textBox = (\n a: ResolvedText,\n s: Scales,\n width: number,\n height: number,\n): Rect => {\n const { plot } = s;\n const at = toScreen(s, a.x ?? 0, a.y ?? 0);\n const free = s.horizontal\n ? { x: a.y === undefined, y: a.x === undefined }\n : { x: a.x === undefined, y: a.y === undefined };\n const px = free.x ? plot.x + plot.width / 2 : at.x;\n const py = free.y ? plot.y + plot.height / 2 : at.y;\n const gap = 6;\n let x = px - width / 2;\n let y = py - height / 2;\n if (a.anchor === \"top\") y = py + gap;\n else if (a.anchor === \"bottom\") y = py - gap - height;\n else if (a.anchor === \"left\") x = px + gap;\n else if (a.anchor === \"right\") x = px - gap - width;\n x = Math.max(plot.x + gap, Math.min(x, plot.x + plot.width - gap - width));\n y = Math.max(plot.y + 2, Math.min(y, plot.y + plot.height - 2 - height));\n return { x, y, width, height };\n};\n\n/** Screen box of an area annotation, clipped to the plot */\nexport const rectOf = (a: ResolvedRect, s: Scales): Rect => {\n const { plot } = s;\n // clamp every edge to the plot first: an open edge maps to ±Infinity and\n // `Infinity - Infinity` would make the size NaN (nothing drawn)\n const [xLo, xHi] = s.horizontal\n ? [plot.y, plot.y + plot.height]\n : [plot.x, plot.x + plot.width];\n const [yLo, yHi] = s.horizontal\n ? [plot.x, plot.x + plot.width]\n : [plot.y, plot.y + plot.height];\n const along = (px: number, lo: number, hi: number) =>\n px < lo ? lo : px > hi ? hi : px;\n return screenRect(\n s,\n along(s.xToPx(a.x0 ?? -Infinity), xLo, xHi),\n along(s.xToPx(a.x1 ?? Infinity), xLo, xHi),\n along(s.yToPx(a.y0 ?? -Infinity), yLo, yHi),\n along(s.yToPx(a.y1 ?? Infinity), yLo, yHi),\n );\n};\n\n/** A text of the title block of an area: badge, label, detail or description */\nexport interface AreaText {\n kind: \"badge\" | \"label\" | \"detail\" | \"description\";\n text: string;\n /** Box of the text (the pill of a badge), CSS pixels */\n x: number;\n y: number;\n width: number;\n height: number;\n /** Font size and weight */\n size: number;\n weight: number;\n}\n\n/** Title block of an area annotation, in its `labelPosition` corner */\nexport interface AreaTitle {\n parts: AreaText[];\n /** Box around the parts (the point labels avoid it) */\n box: Rect;\n}\n\n/** Whether an area annotation has a title block */\nexport const hasAreaTitle = (a: ResolvedRect): boolean =>\n !!(a.label || a.badge || a.detail || a.description);\n\n/** Text cut with an ellipsis to fit `max` pixels (\"\" when nothing fits) */\nconst fitText = (\n text: string,\n max: number,\n width: (text: string) => number,\n): string => {\n if (width(text) <= max) return text;\n const chars = Array.from(text);\n let lo = 0;\n let hi = chars.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (width(`${chars.slice(0, mid).join(\"\")}…`) <= max) lo = mid;\n else hi = mid - 1;\n }\n return lo > 0 ? `${chars.slice(0, lo).join(\"\").trimEnd()}…` : \"\";\n};\n\n/**\n * Layout of the title block of an area: `[badge] label detail` on the first\n * line, the description under it; the block sits in the `labelPosition`\n * corner, 10px from the edges, and the texts are cut to the area width\n */\nexport const areaTitleLayout = (\n a: ResolvedRect,\n r: Rect,\n fontSize: number,\n measure: (text: string, size: number, weight: number) => number,\n): AreaTitle | null => {\n if (!hasAreaTitle(a) || r.width <= 0 || r.height <= 0) return null;\n const pad = 10;\n const lineHeight = fontSize + 4;\n const max = Math.max(0, r.width - pad * 2);\n const labelSize = fontSize + 1;\n const badgeSize = Math.max(9, fontSize - 1);\n const gap = 6;\n const badge = a.badge\n ? fitText(a.badge, Math.max(0, max - 10), (t) => measure(t, badgeSize, 700))\n : \"\";\n const badgeWidth = badge ? measure(badge, badgeSize, 700) + 10 : 0;\n let detail = a.detail ?? \"\";\n let detailWidth = detail ? measure(detail, fontSize, 500) : 0;\n const room = () =>\n max - (badge ? badgeWidth + gap : 0) - (detail ? detailWidth + gap : 0);\n // a narrow area keeps the title rather than the detail\n if (detail && a.label && room() < 32) {\n detail = \"\";\n detailWidth = 0;\n }\n if (detail && room() < 0) {\n detail = fitText(\n detail,\n Math.max(0, max - (badge ? badgeWidth + gap : 0)),\n (t) => measure(t, fontSize, 500),\n );\n detailWidth = detail ? measure(detail, fontSize, 500) : 0;\n }\n const label = a.label\n ? fitText(a.label, Math.max(0, room()), (t) => measure(t, labelSize, 600))\n : \"\";\n const line: AreaText[] = [];\n if (badge)\n line.push({\n kind: \"badge\",\n text: badge,\n x: 0,\n y: 0,\n width: badgeWidth,\n height: lineHeight,\n size: badgeSize,\n weight: 700,\n });\n if (label)\n line.push({\n kind: \"label\",\n text: label,\n x: 0,\n y: 0,\n width: measure(label, labelSize, 600),\n height: lineHeight,\n size: labelSize,\n weight: 600,\n });\n if (detail)\n line.push({\n kind: \"detail\",\n text: detail,\n x: 0,\n y: 0,\n width: detailWidth,\n height: lineHeight,\n size: fontSize,\n weight: 500,\n });\n const description = a.description\n ? fitText(a.description, max, (t) => measure(t, fontSize, 400))\n : \"\";\n const lineWidth =\n line.reduce((sum, p) => sum + p.width, 0) +\n Math.max(0, line.length - 1) * gap;\n const descriptionWidth = description\n ? measure(description, fontSize, 400)\n : 0;\n if (!line.length && !description) return null;\n const height =\n (line.length ? lineHeight : 0) +\n (description ? lineHeight + (line.length ? 2 : 0) : 0);\n const pos = a.labelPosition;\n const top = pos.startsWith(\"top\")\n ? r.y + pad\n : pos.startsWith(\"bottom\")\n ? r.y + r.height - pad - height\n : r.y + (r.height - height) / 2;\n const startOf = (width: number) =>\n pos.endsWith(\"left\")\n ? r.x + pad\n : pos.endsWith(\"right\")\n ? r.x + r.width - pad - width\n : r.x + (r.width - width) / 2;\n const parts: AreaText[] = [];\n let x = startOf(lineWidth);\n for (const p of line) {\n parts.push({ ...p, x, y: top });\n x += p.width + gap;\n }\n if (description)\n parts.push({\n kind: \"description\",\n text: description,\n x: startOf(descriptionWidth),\n y: top + (line.length ? lineHeight + 2 : 0),\n width: descriptionWidth,\n height: lineHeight,\n size: fontSize,\n weight: 400,\n });\n const width = Math.max(lineWidth, descriptionWidth);\n return {\n parts,\n box: { x: startOf(width), y: top, width, height },\n };\n};\n\n/**\n * Where a reference line goes: `vertical` lines run at screen x `at`,\n * horizontal ones at screen y `at`\n */\nexport const lineOf = (\n a: ResolvedLine,\n s: Scales,\n): { vertical: boolean; at: number } => {\n const vertical = (a.axis === \"x\") !== s.horizontal;\n return {\n vertical,\n at: a.axis === \"x\" ? s.xToPx(a.value) : s.yToPx(a.value),\n };\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 /** Right axis (dual axis charts) */\n y2?: AxisModel | null;\n y2Ticks?: AxisTicks | null;\n theme: ChartTheme;\n annotations: readonly ResolvedAnnotation[];\n}\n\nexport const drawBackground = (\n ctx: CanvasRenderingContext2D,\n input: BackgroundInput,\n) => {\n const { scales, theme, xTicks, yTicks } = input;\n const { plot } = scales;\n // horizontal charts: the value axis along the bottom, the x axis on the left\n const x = scales.horizontal ? input.y : input.x;\n const y = scales.horizontal ? input.x : input.y;\n const bottomTicks = scales.horizontal ? yTicks : xTicks;\n const leftTicks = scales.horizontal ? xTicks : yTicks;\n const bottomPx = scales.horizontal ? scales.yToPx : scales.xToPx;\n const leftPx = scales.horizontal ? scales.xToPx : scales.yToPx;\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 leftTicks.values) {\n const py = crisp(leftPx(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 bottomTicks.values) {\n const px = crisp(bottomPx(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 = bottomTicks.values\n .map((v, i) => ({ px: bottomPx(v), text: bottomTicks.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 let lastBottom = -Infinity;\n // top to bottom: category rows of horizontal charts never overlap\n const rows = leftTicks.values\n .map((v, i) => ({ py: leftPx(v), text: leftTicks.labels[i] }))\n .sort((a, b) => a.py - b.py);\n const rowHeight = theme.fontSize + 2;\n for (const { py, text } of rows) {\n if (py < plot.y - 0.5 || py > plot.y + plot.height + 0.5) continue;\n if (scales.horizontal) {\n if (py - rowHeight / 2 < lastBottom) continue;\n lastBottom = py + rowHeight / 2;\n }\n ctx.fillText(text, 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 // right axis\n const y2 = scales.horizontal ? null : input.y2;\n const y2Ticks = input.y2Ticks;\n if (y2 && y2Ticks && y2.visible) {\n const right = plot.x + plot.width;\n ctx.font = font(theme);\n ctx.fillStyle = toCss(theme.textMuted);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n y2Ticks.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(y2Ticks.labels[i], right + 8, py);\n });\n if (y2.title) {\n ctx.save();\n ctx.font = font(theme, theme.fontSize + 1, 500);\n ctx.fillStyle = toCss(theme.text, 0.8);\n ctx.translate(input.width - line / 2 - 4, plot.y + plot.height / 2);\n ctx.rotate(Math.PI / 2);\n ctx.textAlign = \"center\";\n ctx.fillText(y2.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/**\n * Box of a label inside its bar (the visible part of it): the text cut with\n * an ellipsis to fit, at the start of horizontal bars and centered in\n * vertical ones; `null` when the bar is too small\n */\nconst insideBox = (\n label: PointLabel,\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n): { label: PointLabel; box: Rect } | null => {\n const bar = label.bar;\n if (!bar) return null;\n const x0 = Math.max(bar.x, plot.x);\n const x1 = Math.min(bar.x + bar.width, plot.x + plot.width);\n const y0 = Math.max(bar.y, plot.y);\n const y1 = Math.min(bar.y + bar.height, plot.y + plot.height);\n if (y1 - y0 < height - 2) return null;\n const text = fitText(label.text, x1 - x0 - INSIDE_PAD * 2, measure);\n if (!text) return null;\n const w = measure(text);\n const x = label.align === \"start\" ? x0 + INSIDE_PAD : (x0 + x1) / 2 - w / 2;\n return {\n label: text === label.text ? label : { ...label, text },\n box: { x, y: (y0 + y1) / 2 - height / 2, width: w, height },\n };\n};\n\n/** Room kept between a label and the edges of its cell, CSS pixels */\nconst CELL_PAD = 2;\n/** Room kept between two labels of a cell (they never touch), CSS pixels */\nconst LABEL_GAP = { x: 4, y: 2 };\n\n/** Distance from a point to the nearest point of a box */\nconst distanceTo = (x: number, y: number, r: Rect) =>\n Math.hypot(\n Math.max(r.x - x, 0, x - (r.x + r.width)),\n Math.max(r.y - y, 0, y - (r.y + r.height)),\n );\n\n/** A dot of a cell label: its label is told apart from the others by it */\ntype Dot = Pick<PointLabel, \"x\" | \"y\" | \"r\">;\n\n/**\n * Box of a label kept inside a cell of the plot (`bounds`): beside the dot\n * on the side with more room in the cell (moved up or down into the cell\n * near its edges), else above or below it (moved sideways into the cell);\n * cut with an ellipsis to the room left when the whole text fits nowhere;\n * `null` when no free slot is left. A slot is free when it keeps a gap to\n * the other labels and its own dot is the nearest one (it covers no other\n * dot): a crowded cell never pairs a name with the wrong dot\n */\nconst cellBox = (\n label: PointLabel,\n bounds: Rect,\n plot: Rect,\n measure: (text: string) => number,\n height: number,\n occupied: readonly Rect[],\n dots: readonly Dot[] = [],\n): { label: PointLabel; box: Rect } | null => {\n const x0 = Math.max(bounds.x, plot.x) + CELL_PAD;\n const x1 = Math.min(bounds.x + bounds.width, plot.x + plot.width) - CELL_PAD;\n const y0 = Math.max(bounds.y, plot.y) + CELL_PAD;\n const y1 =\n Math.min(bounds.y + bounds.height, plot.y + plot.height) - CELL_PAD;\n if (x1 - x0 <= 0 || y1 - y0 < height) return null;\n // a hair of slack: a text cut to the exact room ends on the edge\n const slack = {\n x: x0 - 0.01,\n y: y0 - 0.01,\n width: x1 - x0 + 0.02,\n height: y1 - y0 + 0.02,\n };\n // the other dots: those at the very spot of this one count as its own\n const others = dots.filter(\n (d) => Math.abs(d.x - label.x) >= 0.5 || Math.abs(d.y - label.y) >= 0.5,\n );\n const free = (c: Rect) => {\n if (!inside(c, slack)) return false;\n const spaced = {\n x: c.x - LABEL_GAP.x,\n y: c.y - LABEL_GAP.y,\n width: c.width + LABEL_GAP.x * 2,\n height: c.height + LABEL_GAP.y * 2,\n };\n if (occupied.some((o) => overlaps(o, spaced))) return false;\n const own = distanceTo(label.x, label.y, c);\n return others.every((d) => {\n const far = distanceTo(d.x, d.y, c);\n return far >= d.r + 2 && far > own;\n });\n };\n const gap = label.r + 4;\n // centered on the dot, moved into the cell near its top or bottom edge\n const sideY = Math.min(Math.max(label.y - height / 2, y0), y1 - height);\n const room = { right: x1 - (label.x + gap), left: label.x - gap - x0 };\n const sides: (\"right\" | \"left\")[] =\n room.right >= room.left ? [\"right\", \"left\"] : [\"left\", \"right\"];\n const beside = (side: \"right\" | \"left\", w: number): Rect[] => [\n {\n x: side === \"right\" ? label.x + gap : label.x - gap - w,\n y: sideY,\n width: w,\n height,\n },\n ];\n const stacked = (w: number): Rect[] => {\n // slid sideways into the cell near its edges (still over the dot)\n const x = Math.min(Math.max(label.x - w / 2, x0), x1 - w);\n return [\n { x, y: label.y - gap - height, width: w, height },\n { x, y: label.y + gap, width: w, height },\n ];\n };\n const w = measure(label.text);\n const whole = [\n ...beside(sides[0]!, w),\n ...beside(sides[1]!, w),\n ...stacked(w),\n ];\n const box = whole.find(free);\n if (box) return { label, box };\n // the whole text fits nowhere: cut it to the room beside the dot or above\n // / below it, keeping the longest text (the roomiest side on ties)\n const cuts: [number, (w: number) => Rect[]][] = [\n [room[sides[0]!], (cw) => beside(sides[0]!, cw)],\n [room[sides[1]!], (cw) => beside(sides[1]!, cw)],\n [x1 - x0, stacked],\n ];\n let best: { label: PointLabel; box: Rect } | null = null;\n // a cut keeps enough of the name to tell it (else the label is skipped,\n // like an overlapping one: the tooltip still names the point)\n const total = Array.from(label.text).length;\n const keep = Math.min(4, Math.ceil(total * 0.4));\n for (const [max, boxes] of cuts) {\n const text = fitText(label.text, max, measure);\n if (!text || (best && text.length <= best.label.text.length)) continue;\n if (Array.from(text).length - 1 < keep) continue;\n const cut = boxes(measure(text)).find(free);\n if (cut) best = { label: { ...label, text }, box: cut };\n }\n return best;\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 // the dots of the labels kept in cells (labels placed later included)\n const dots = labels.filter((label) => label.bounds);\n for (const label of labels) {\n if (label.placement === \"inside\") {\n const fit = insideBox(label, plot, measure, height);\n if (fit) placed.push(fit);\n continue;\n }\n if (label.bounds) {\n const fit = cellBox(\n label,\n label.bounds,\n plot,\n measure,\n height,\n occupied,\n dots,\n );\n if (!fit) continue;\n occupied.push(fit.box);\n placed.push(fit);\n continue;\n }\n const w = measure(label.text);\n const gap = label.r + 4;\n const above = {\n x: label.x - w / 2,\n y: label.y - gap - height,\n width: w,\n height,\n };\n const below = { x: label.x - w / 2, y: label.y + gap, width: w, height };\n const right = {\n x: label.x + gap,\n y: label.y - height / 2,\n width: w,\n height,\n };\n const left = {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n };\n const candidates: Rect[] =\n label.placement === \"above\"\n ? [above]\n : label.placement === \"below\"\n ? [below]\n : label.placement === \"right\"\n ? [right, left]\n : label.placement === \"left\"\n ? [left, right]\n : [\n {\n x: label.x + gap,\n y: label.y - height / 2,\n width: w,\n height,\n },\n {\n x: label.x - gap - w,\n y: label.y - height / 2,\n width: w,\n height,\n },\n above,\n below,\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 * Clears the canvas first (off when the layers share one canvas)\n * @default true\n */\n clear?: boolean;\n /** Lines between consecutive bars (waterfall connectors), drawn first */\n connectors?: readonly {\n x0: number;\n y0: number;\n x1: number;\n y1: number;\n color: string;\n width: number;\n dash: readonly number[];\n }[];\n /** Dependency arrows (Gantt charts), drawn over the connectors */\n arrows?: readonly ArrowPath[];\n}\n\n/** An elbow arrow in stage pixels (see `dependencyArrows`) */\nexport interface ArrowPath {\n points: readonly { x: number; y: number }[];\n head: readonly { x: number; y: number }[];\n color: string;\n width: number;\n}\n\n/** Elbow arrows: polylines with rounded corners and filled heads */\nexport const drawArrows = (\n ctx: CanvasRenderingContext2D,\n arrows: readonly ArrowPath[],\n) => {\n for (const a of arrows) {\n const pts = a.points;\n const first = pts[0];\n if (!first) continue;\n ctx.strokeStyle = a.color;\n ctx.fillStyle = a.color;\n ctx.lineWidth = a.width;\n ctx.lineJoin = \"round\";\n ctx.setLineDash([]);\n ctx.beginPath();\n ctx.moveTo(first.x, first.y);\n for (let i = 1; i < pts.length; i++) {\n const p = pts[i]!;\n const next = pts[i + 1];\n const prev = pts[i - 1]!;\n if (next && typeof ctx.arcTo === \"function\") {\n // rounded elbow, at most half of the shorter leg\n const r = Math.min(\n 4,\n Math.hypot(p.x - prev.x, p.y - prev.y) / 2,\n Math.hypot(next.x - p.x, next.y - p.y) / 2,\n );\n ctx.arcTo(p.x, p.y, next.x, next.y, r);\n } else {\n ctx.lineTo(p.x, p.y);\n }\n }\n ctx.stroke();\n const [tip, b0, b1] = a.head;\n if (tip && b0 && b1) {\n ctx.beginPath();\n ctx.moveTo(tip.x, tip.y);\n ctx.lineTo(b0.x, b0.y);\n ctx.lineTo(b1.x, b1.y);\n ctx.closePath();\n ctx.fill();\n }\n }\n};\n\nexport const drawForeground = (\n ctx: CanvasRenderingContext2D,\n input: ForegroundInput,\n) => {\n const { scales, theme } = input;\n const { plot } = scales;\n if (input.clear !== false) 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 for (const c of input.connectors ?? []) {\n ctx.strokeStyle = c.color;\n ctx.lineWidth = c.width;\n ctx.setLineDash([...c.dash]);\n ctx.beginPath();\n // crisp hairlines along the pixel grid\n const along = c.y0 === c.y1;\n const x0 = along ? c.x0 : crisp(c.x0);\n const y0 = along ? crisp(c.y0) : c.y0;\n ctx.moveTo(x0, y0);\n ctx.lineTo(along ? c.x1 : x0, along ? y0 : c.y1);\n ctx.stroke();\n }\n ctx.setLineDash([]);\n if (input.arrows?.length) drawArrows(ctx, input.arrows);\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 const where = lineOf(a, scales);\n if (!where.vertical) {\n const py = crisp(where.at);\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(where.at);\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 for (const a of input.annotations) {\n if (a.type !== \"rect\" || !hasAreaTitle(a)) continue;\n const title = areaTitleLayout(\n a,\n rectOf(a, scales),\n theme.fontSize,\n (text, size, weight) => {\n ctx.font = font(theme, size, weight);\n return ctx.measureText(text).width;\n },\n );\n if (!title) continue;\n const color = toCss(a.labelColor);\n const muted = toCss(theme.textMuted);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n for (const p of title.parts) {\n const cy = p.y + p.height / 2;\n if (p.kind === \"badge\") {\n const h = p.height - 2;\n pill(ctx, p.x, cy - h / 2, p.width, h);\n ctx.fillStyle = toCss(a.labelColor, 0.16);\n ctx.fill();\n ctx.font = font(theme, p.size, p.weight);\n ctx.fillStyle = color;\n ctx.fillText(p.text, p.x + 5, cy);\n continue;\n }\n ctx.font = font(theme, p.size, p.weight);\n ctx.fillStyle = p.kind === \"label\" ? color : muted;\n ctx.fillText(p.text, p.x, cy);\n }\n occupied.push(title.box);\n }\n\n // free texts\n for (const a of input.annotations) {\n if (a.type !== \"text\" || !a.text) continue;\n ctx.font = font(theme, theme.fontSize, a.weight);\n const box = textBox(a, scales, ctx.measureText(a.text).width, labelHeight);\n ctx.textAlign = \"left\";\n ctx.textBaseline = \"middle\";\n haloText(ctx, a.text, box.x, box.y + box.height / 2, toCss(a.color), halo);\n occupied.push(box);\n }\n\n // point labels\n let placed: { label: PointLabel; box: Rect }[] = [];\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 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 if (label.hidden) continue;\n const y = box.y + box.height / 2;\n if (label.color) {\n ctx.fillStyle = label.color;\n ctx.fillText(label.text, box.x, y);\n } else haloText(ctx, label.text, box.x, y, textColor, halo);\n }\n }\n ctx.restore();\n return placed;\n};\n"],"mappings":"yDAkFA,IAAMM,EAAa,EAONC,GACX,EACA,IACuB,CACvB,IAAMC,EAAQC,EAAK,GACnB,GAAID,EAAQ,GAAK,OACjB,IAAME,EAAOV,EAAAA,IAAIW,EAAYF,EAAMD,CAAK,EAClCI,EAAIX,EAAAA,kBAAkBS,CAAI,EAEhC,MAAO,OAAQE,EAAI,OAAUA,EAAI,KAAQ,KACrC,UACA,wBACN,EAEaC,GAAQ,EAAmB,EAAOC,EAAM,SAAU,EAAS,MACtE,GAAGC,EAAO,GAAGC,EAAK,KAAKF,EAAM,aA2BlBG,GACX,EACA,EACA,EACA,IACS,CACT,GAAM,CAAE,QAASC,EACXC,EAAKjB,EAAAA,SAASgB,EAAGE,EAAE,GAAK,EAAGA,EAAE,GAAK,CAAC,EACnCC,EAAOH,EAAE,WACX,CAAE,EAAGE,EAAE,IAAM,IAAA,GAAW,EAAGA,EAAE,IAAM,IAAA,EAAU,EAC7C,CAAE,EAAGA,EAAE,IAAM,IAAA,GAAW,EAAGA,EAAE,IA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EAAIqC,EAAMjE,EACnB,MAAOiD,EACP,QACF,EACMmC,EAAQ,CAAE,EAAGxD,EAAM,EAAIqB,EAAI,EAAG,EAAGrB,EAAM,EAAIqC,EAAK,MAAOhB,EAAG,QAAO,EACjEoC,EAAQ,CACZ,EAAGzD,EAAM,EAAIqC,EACb,EAAGrC,EAAM,EAAI5B,EAAS,EACtB,MAAOiD,EACP,QACF,EACMqC,EAAO,CACX,EAAG1D,EAAM,EAAIqC,EAAMhB,EACnB,EAAGrB,EAAM,EAAI5B,EAAS,EACtB,MAAOiD,EACP,QACF,EA0BMsB,GAxBJ3C,EAAM,YAAc,QAChB,CAACuD,CAAK,EACNvD,EAAM,YAAc,QAClB,CAACwD,CAAK,EACNxD,EAAM,YAAc,QAClB,CAACyD,EAAOC,CAAI,EACZ1D,EAAM,YAAc,OAClB,CAAC0D,EAAMD,CAAK,EACZ,CACE,CACE,EAAGzD,EAAM,EAAIqC,EACb,EAAGrC,EAAM,EAAI5B,EAAS,EACtB,MAAOiD,EACP,QACF,EACA,CACE,EAAGrB,EAAM,EAAIqC,EAAMhB,EACnB,EAAGrB,EAAM,EAAI5B,EAAS,EACtB,MAAOiD,EACP,QACF,EACAkC,EACAC,CACF,EAAA,CACW,KACpB,GAAM1C,EAAOiB,EAAGhE,CAAI,GAAK,CAACkE,EAAS,KAAM,GAAMrB,EAASsB,EAAGH,CAAC,CAAC,CAChE,EACKY,IACLV,EAAS,KAAKU,CAAG,EACjBS,EAAO,KAAK,CAAE,QAAO,KAAI,CAAC,EAC5B,CACA,OAAOA,CACT"}
|
|
@@ -115,54 +115,71 @@ var i = 6, a = (n, r) => {
|
|
|
115
115
|
height: r
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
}, g = 2, _ =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
}, g = 2, _ = {
|
|
119
|
+
x: 4,
|
|
120
|
+
y: 2
|
|
121
|
+
}, v = (e, t, n) => Math.hypot(Math.max(n.x - e, 0, e - (n.x + n.width)), Math.max(n.y - t, 0, t - (n.y + n.height))), y = (e, t, n, r, i, a, o = []) => {
|
|
122
|
+
let s = Math.max(t.x, n.x) + g, c = Math.min(t.x + t.width, n.x + n.width) - g, l = Math.max(t.y, n.y) + g, d = Math.min(t.y + t.height, n.y + n.height) - g;
|
|
123
|
+
if (c - s <= 0 || d - l < i) return null;
|
|
124
|
+
let f = {
|
|
125
|
+
x: s - .01,
|
|
126
|
+
y: l - .01,
|
|
127
|
+
width: c - s + .02,
|
|
128
|
+
height: d - l + .02
|
|
129
|
+
}, h = o.filter((t) => Math.abs(t.x - e.x) >= .5 || Math.abs(t.y - e.y) >= .5), y = (t) => {
|
|
130
|
+
if (!m(t, f)) return !1;
|
|
131
|
+
let n = {
|
|
132
|
+
x: t.x - _.x,
|
|
133
|
+
y: t.y - _.y,
|
|
134
|
+
width: t.width + _.x * 2,
|
|
135
|
+
height: t.height + _.y * 2
|
|
136
|
+
};
|
|
137
|
+
if (a.some((e) => p(e, n))) return !1;
|
|
138
|
+
let r = v(e.x, e.y, t);
|
|
139
|
+
return h.every((e) => {
|
|
140
|
+
let n = v(e.x, e.y, t);
|
|
141
|
+
return n >= e.r + 2 && n > r;
|
|
142
|
+
});
|
|
143
|
+
}, b = e.r + 4, x = Math.min(Math.max(e.y - i / 2, l), d - i), S = {
|
|
144
|
+
right: c - (e.x + b),
|
|
145
|
+
left: e.x - b - s
|
|
146
|
+
}, C = S.right >= S.left ? ["right", "left"] : ["left", "right"], w = (t, n) => [{
|
|
147
|
+
x: t === "right" ? e.x + b : e.x - b - n,
|
|
148
|
+
y: x,
|
|
132
149
|
width: n,
|
|
133
150
|
height: i
|
|
134
|
-
}],
|
|
135
|
-
let n = Math.min(Math.max(e.x - t / 2,
|
|
151
|
+
}], T = (t) => {
|
|
152
|
+
let n = Math.min(Math.max(e.x - t / 2, s), c - t);
|
|
136
153
|
return [{
|
|
137
154
|
x: n,
|
|
138
|
-
y: e.y -
|
|
155
|
+
y: e.y - b - i,
|
|
139
156
|
width: t,
|
|
140
157
|
height: i
|
|
141
158
|
}, {
|
|
142
159
|
x: n,
|
|
143
|
-
y: e.y +
|
|
160
|
+
y: e.y + b,
|
|
144
161
|
width: t,
|
|
145
162
|
height: i
|
|
146
163
|
}];
|
|
147
|
-
},
|
|
148
|
-
...
|
|
149
|
-
...
|
|
150
|
-
...
|
|
151
|
-
].find(
|
|
152
|
-
if (
|
|
164
|
+
}, E = r(e.text), D = [
|
|
165
|
+
...w(C[0], E),
|
|
166
|
+
...w(C[1], E),
|
|
167
|
+
...T(E)
|
|
168
|
+
].find(y);
|
|
169
|
+
if (D) return {
|
|
153
170
|
label: e,
|
|
154
|
-
box:
|
|
171
|
+
box: D
|
|
155
172
|
};
|
|
156
|
-
let
|
|
157
|
-
[
|
|
158
|
-
[
|
|
159
|
-
[
|
|
160
|
-
],
|
|
161
|
-
for (let [t, n] of
|
|
173
|
+
let O = [
|
|
174
|
+
[S[C[0]], (e) => w(C[0], e)],
|
|
175
|
+
[S[C[1]], (e) => w(C[1], e)],
|
|
176
|
+
[c - s, T]
|
|
177
|
+
], k = null, A = Array.from(e.text).length, j = Math.min(4, Math.ceil(A * .4));
|
|
178
|
+
for (let [t, n] of O) {
|
|
162
179
|
let i = u(e.text, t, r);
|
|
163
|
-
if (!i ||
|
|
164
|
-
let a = n(r(i)).find(
|
|
165
|
-
a && (
|
|
180
|
+
if (!i || k && i.length <= k.label.text.length || Array.from(i).length - 1 < j) continue;
|
|
181
|
+
let a = n(r(i)).find(y);
|
|
182
|
+
a && (k = {
|
|
166
183
|
label: {
|
|
167
184
|
...e,
|
|
168
185
|
text: i
|
|
@@ -170,65 +187,65 @@ var i = 6, a = (n, r) => {
|
|
|
170
187
|
box: a
|
|
171
188
|
});
|
|
172
189
|
}
|
|
173
|
-
return
|
|
174
|
-
},
|
|
175
|
-
let a = [];
|
|
176
|
-
for (let
|
|
177
|
-
if (
|
|
178
|
-
let e = h(
|
|
190
|
+
return k;
|
|
191
|
+
}, b = (e, t, n, r, i = []) => {
|
|
192
|
+
let a = [], o = e.filter((e) => e.bounds);
|
|
193
|
+
for (let s of e) {
|
|
194
|
+
if (s.placement === "inside") {
|
|
195
|
+
let e = h(s, t, n, r);
|
|
179
196
|
e && a.push(e);
|
|
180
197
|
continue;
|
|
181
198
|
}
|
|
182
|
-
if (
|
|
183
|
-
let e =
|
|
199
|
+
if (s.bounds) {
|
|
200
|
+
let e = y(s, s.bounds, t, n, r, i, o);
|
|
184
201
|
if (!e) continue;
|
|
185
202
|
i.push(e.box), a.push(e);
|
|
186
203
|
continue;
|
|
187
204
|
}
|
|
188
|
-
let e = n(
|
|
189
|
-
x:
|
|
190
|
-
y:
|
|
191
|
-
width: e,
|
|
192
|
-
height: r
|
|
193
|
-
}, l = {
|
|
194
|
-
x: o.x - e / 2,
|
|
195
|
-
y: o.y + s,
|
|
205
|
+
let e = n(s.text), c = s.r + 4, l = {
|
|
206
|
+
x: s.x - e / 2,
|
|
207
|
+
y: s.y - c - r,
|
|
196
208
|
width: e,
|
|
197
209
|
height: r
|
|
198
210
|
}, u = {
|
|
199
|
-
x:
|
|
200
|
-
y:
|
|
211
|
+
x: s.x - e / 2,
|
|
212
|
+
y: s.y + c,
|
|
201
213
|
width: e,
|
|
202
214
|
height: r
|
|
203
215
|
}, d = {
|
|
204
|
-
x:
|
|
205
|
-
y:
|
|
216
|
+
x: s.x + c,
|
|
217
|
+
y: s.y - r / 2,
|
|
218
|
+
width: e,
|
|
219
|
+
height: r
|
|
220
|
+
}, f = {
|
|
221
|
+
x: s.x - c - e,
|
|
222
|
+
y: s.y - r / 2,
|
|
206
223
|
width: e,
|
|
207
224
|
height: r
|
|
208
|
-
},
|
|
225
|
+
}, g = (s.placement === "above" ? [l] : s.placement === "below" ? [u] : s.placement === "right" ? [d, f] : s.placement === "left" ? [f, d] : [
|
|
209
226
|
{
|
|
210
|
-
x:
|
|
211
|
-
y:
|
|
227
|
+
x: s.x + c,
|
|
228
|
+
y: s.y - r / 2,
|
|
212
229
|
width: e,
|
|
213
230
|
height: r
|
|
214
231
|
},
|
|
215
232
|
{
|
|
216
|
-
x:
|
|
217
|
-
y:
|
|
233
|
+
x: s.x - c - e,
|
|
234
|
+
y: s.y - r / 2,
|
|
218
235
|
width: e,
|
|
219
236
|
height: r
|
|
220
237
|
},
|
|
221
|
-
|
|
222
|
-
|
|
238
|
+
l,
|
|
239
|
+
u
|
|
223
240
|
]).find((e) => m(e, t) && !i.some((t) => p(t, e)));
|
|
224
|
-
|
|
225
|
-
label:
|
|
226
|
-
box:
|
|
241
|
+
g && (i.push(g), a.push({
|
|
242
|
+
label: s,
|
|
243
|
+
box: g
|
|
227
244
|
}));
|
|
228
245
|
}
|
|
229
246
|
return a;
|
|
230
247
|
};
|
|
231
248
|
//#endregion
|
|
232
|
-
export { d as areaTitleLayout, o as font, l as hasAreaTitle, a as insideLabelColor, f as lineOf,
|
|
249
|
+
export { d as areaTitleLayout, o as font, l as hasAreaTitle, a as insideLabelColor, f as lineOf, b as placeLabels, c as rectOf, s as textBox };
|
|
233
250
|
|
|
234
251
|
//# sourceMappingURL=overlay.js.map
|