@fengwk/kchart 0.1.0 → 0.1.1
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 +8 -0
- package/dist/esm/assets/themes/cloudmusic.js +1 -1
- package/dist/esm/chart/multivariate.js +50 -35
- package/dist/esm/chart/spec.js +6 -2
- package/dist/esm/diagram/eventmodeling.js +17 -8
- package/dist/esm/diagram/numeric-xy.js +3 -3
- package/dist/esm/diagram/venn.js +82 -134
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/theme.js +1 -1
- package/dist/units/diagram/eventmodeling.js +4 -4
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/venn.js +2 -2
- package/dist/units.json +8 -6
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/numeric-xy"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)`;RegExp(`^${a}$`);var o=RegExp(`^(.*?)\\s*(${a})\\s*-->\\s*(${a})\\s*$`),s=/^(.*?)\s*\[([^\]]*)\]\s*$/,c=/^(bar|line)\b([\s\S]*)$/i,l=RegExp(`^(${a})\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)')?$`),u=/^\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^\s[\]"]+))?\s*\[([\s\S]*)\]\s*$/,d=6,f=24,p=120,m=(e,n,r,i,a=`修正 Mermaid xychart 语法`,o=`Correct the Mermaid xychart syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),h=(e,n,r,i,a,o=`检查图表声明`,s=`Check the chart declaration`)=>e.push((0,t.warning)(`DIAGRAM_HINT`,n.lang,r,i,a,o,s)),g=e=>/^en(?:-|$)/i.test(String(e||``)),_=e=>String(e).replace(/\\([\\"'])/g,`$1`),v=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?_(t.slice(1,-1)):t},y=(e,t,n)=>[e,t,n].find(e=>e!==void 0);function b(e,t=`,`){let n=[],r=``,i=``,a=0;for(let o of String(e))i?(r+=o,o===i&&(i=``)):o===`"`||o===`'`?(i=o,r+=o):((o===`[`||o===`{`)&&(a+=1),(o===`]`||o===`}`)&&--a,o===t&&a===0?(n.push(r.trim()),r=``):r+=o);return n.push(r.trim()),n}function x(e,t){let n=[];return String(e).split(`
|
|
2
|
-
`).forEach((e,r)=>{let i=e.trim();if(i&&!i.startsWith(`%%`))for(let e of b(i,`;`))e&&n.push({text:e,line:t+r})}),n}function S(e,t){let n=null;for(let r of String(e.params||``).split(/\s+/).filter(Boolean))/^(?:horizontal|vertical)$/i.test(r)?n=r.toLowerCase():t.push(m(e,e.headerLine||e.firstLine,`xychart 不支持头行选项「${r}」`,`xychart does not accept header options: ${r}`,`头行只接受 horizontal 或 vertical`,`Only horizontal or vertical is allowed after the header`));return n}function C(e,t,n,r){let i=[];for(let a of b(e)){let e=l.exec(a);if(!e)return r.push(m(t,n,`数据点「${a}」须为数值,可带一个引号标签`,`Data point "${a}" must be a number, optionally with a quoted label`,'写成 `12` 或 `12 "标签"`','Write `12` or `12 "Label"`')),null;let o=y(e[2],e[3],void 0);i.push({value:Number(e[1]),label:o===void 0?null:_(o)||null})}return i}function w(e,t,n,r){let i=s.exec(t);if(i){let t=i[1].trim()?v(i[1]):null,a=b(i[2]);return!a.length||a.some(e=>!e)?(r.push(m(e,n,`x-axis 需要非空类别列表`,`x-axis needs a non-empty category list`,`去掉空类别或多余的逗号`,`Remove empty categories or extra commas`)),{title:t,data:null}):{title:t,data:{kind:`band`,categories:a.map(v)}}}let a=o.exec(t);if(a&&!/-$/.test(a[1])){let e=Number(a[2]),t=Number(a[3]);return{title:a[1].trim()?v(a[1]):null,data:{kind:`linear`,min:e,max:t}}}return{title:t?v(t):null,data:null}}function T(e,t,n,r){let i=new Map,a=[],o=!1;for(let e of r){let t=(i.get(e)||0)+1;i.set(e,t),t===1?a.push(e):(o=!0,a.push(`${e} (${t})`))}return o&&h(e,t,n,`x-axis 类别名重复,已按出现顺序加序号区分`,`Duplicate x-axis categories were numbered in source order`,`让每个类别名唯一`,`Give every category a unique name`),a}function E(e,t,n){let r=e=>String(Number(e.toPrecision(12)));if(n<=0)return[];if(n===1)return[r(e)];let i=(t-e)/(n-1);return Array.from({length:n},(t,n)=>r(e+n*i))}function D(e,t,n,r){let i=c.exec(t),a=i[1].toLowerCase(),o=u.exec(i[2]);if(!o)return r.push(m(e,n,`无法识别 ${a} 数据「${t}」`,`Unrecognized ${a} data "${t}"`,`写成 \`${a} [值, 值]\` 或 \`${a} "名称" [值, 值]\``,`Write \`${a} [value, value]\` or \`${a} "Name" [value, value]\``)),null;let s=C(o[4],e,n,r);if(!s)return null;let l=y(o[1],o[2],o[3]);return{type:a,name:l===void 0?null:_(l),points:s,line:n}}function O(e,t){let r=[],i=null,a=null,o=null,s=null,l=null,u=null,d=null,g=null,_=[],y=S(t,r);for(let f of x(e,t.firstLine))if(/^title\b/i.test(f.text)){let e=f.text.replace(/^title\b/i,``).trim();if(!e){r.push(m(t,f.line,`title 需要标题文字`,`title needs some text`));continue}if(i!==null){r.push(m(t,f.line,`xychart 只能有一个 title`,`xychart accepts one title`));continue}i=(0,n.numericLabel)(v(e),t,f.line,r),a=f.line}else if(/^x-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^x-axis\b/i,``).trim(),f.line,r);e.title!==null&&(o!==null&&h(r,t,f.line,`xychart 重复的 x-axis,只保留最后一条`,`Duplicate x-axis; the last one is used`),o=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&(l&&h(r,t,f.line,`xychart 重复的 x-axis 数据,只保留最后一条`,`Duplicate x-axis data; the last one is used`),l=e.data,u=f.line),u??=f.line}else if(/^y-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^y-axis\b/i,``).trim(),f.line,r);d??=f.line,e.title!==null&&(s!==null&&h(r,t,f.line,`xychart 重复的 y-axis,只保留最后一条`,`Duplicate y-axis; the last one is used`),s=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&e.data.kind===`linear`?(g&&h(r,t,f.line,`xychart 重复的 y-axis 范围,只保留最后一条`,`Duplicate y-axis range; the last one is used`),g=[e.data.min,e.data.max]):e.data?.kind===`band`&&r.push(m(t,f.line,"y-axis 只接受数值范围 `min --> max`","y-axis accepts only a numeric range `min --> max`",'改成 `y-axis "标题" 0 --> 100`','Use `y-axis "Title" 0 --> 100`'))}else if(c.test(f.text)){let e=D(t,f.text,f.line,r);e&&_.push(e)}else r.push(m(t,f.line,`无法识别 xychart 语句「${f.text}」`,`Unrecognized xychart statement "${f.text}"`,`支持 title、x-axis、y-axis、bar、line`,`Supported: title, x-axis, y-axis, bar, line`));_.length||r.push(m(t,t.firstLine,`xychart 至少需要一条 bar 或 line 数据`,`xychart needs at least one bar or line plot`)),_.length>f&&r.push(m(t,_[f].line,`xychart 安全上限为 ${f} 条数据序列,当前 ${_.length} 条`,`xychart safety cap is ${f} plots; got ${_.length}`,`将数据序列合并到 ${f} 条以内,或拆成多张图`,`Merge series to stay within ${f} plots, or split the chart`));let b=_.length===1&&_[0].name,C=_.some(e=>e.type===`line`&&e.points.some(e=>e.label)),O=_.length>1||b&&!(_[0].type===`line`&&_[0].points.some(e=>e.label))?`combo`:_[0]?.type===`bar`?`column`:`line`,k=u||_[0]?.line||t.firstLine,A=_.map(e=>e.points.length),j=l?.kind===`band`?l.categories.length:Math.max(0,...A);j>p&&O!==`column`&&r.push(m(t,k,`xychart 最多支持 ${p} 个横轴类别`,`xychart supports at most ${p} x-axis categories`,`按横轴范围拆分图表`,`Split the chart by x-axis range`));let M;M=l?.kind===`band`?T(r,t,k,l.categories.map(e=>(0,n.numericLabel)(e,t,k,r))):l?.kind===`linear`?E(l.min,l.max,j):Array.from({length:j},(e,t)=>String(t+1));let N=_.map(e=>{let i=e.points.length>M.length,a=O===`combo`||e.type===`line`?null:0;return i?h(r,t,e.line,`数据点数 ${e.points.length} 多于类别数 ${M.length},多余的点已略去`,`${e.points.length} points exceed ${M.length} categories; extra points were dropped`,`补齐 x-axis 类别或删去多余的点`,`Add x-axis categories or remove the extra points`):e.points.length<M.length&&a===0&&h(r,t,e.line,`bar 数据点数少于类别数,缺少的点按 0 绘制`,`The bar plot has fewer points than categories; missing points are drawn as 0`,`补齐数据点`,`Provide a value for every category`),{type:e.type,name:e.name&&(0,n.numericLabel)(e.name,t,e.line,r),line:e.line,values:M.map((t,n)=>e.points[n]?.value??a),pointLabels:M.map((i,a)=>{let o=e.points[a]?.label;return o?(0,n.numericLabel)(o,t,e.line,r):null})}});O===`combo`&&C&&h(r,t,_[0].line,`组合图中的数据点标签未绘制`,`Point labels are not drawn on a combined chart`,`把该序列拆成单独的 line 图,或删去标签`,`Split that plot into a line-only chart or drop the labels`),O!==`combo`&&N[0]?.name&&C&&h(r,t,_[0].line,`单序列折线的名称「${N[0].name}」未作为图例绘制`,`The name "${N[0].name}" of this single line is not drawn as a legend`,`需要图例时不要同时使用数据点标签`,`Do not combine point labels with a series name if the legend matters`);let P=_.find(e=>e.type===`bar`&&e.points.some(e=>e.label));P&&h(r,t,P.line,`bar 的数据点标签被忽略(Mermaid 也只对 line 绘制点标签)`,`Point labels on a bar plot are ignored (Mermaid draws them on line plots only)`,`改用 line 绘制带标签的序列`,`Use line for a labeled series`);let F=_.flatMap(e=>e.points.map(e=>e.value)),I=Math.min(...F),L=Math.max(...F),R=null;return g&&(g[1]>g[0]?R=[g[0],g[1]]:h(r,t,d,`y-axis 范围 ${g[0]} --> ${g[1]} 不是递增区间,已改为按数据取值`,`y-axis range ${g[0]} --> ${g[1]} is not increasing; derived from data instead`,"把范围写成 `小值 --> 大值`","Write the range as `low --> high`")),R&&(R[0]>I&&(h(r,t,d,`y-axis 最小值 ${R[0]} 高于数据最小值 ${I},已扩展到 ${I}`,`y-axis minimum ${R[0]} is above the data minimum ${I}; extended to ${I}`,`把最小值改为不大于 ${I}`,`Set the minimum to at most ${I}`),R[0]=I),R[1]<L&&(h(r,t,d,`y-axis 最大值 ${R[1]} 低于数据最大值 ${L},已扩展到 ${L}`,`y-axis maximum ${R[1]} is below the data maximum ${L}; extended to ${L}`,`把最大值改为不小于 ${L}`,`Set the maximum to at least ${L}`),R[1]=L),_.some(e=>e.type===`bar`)&&(R[0]>0||R[1]<0)&&(h(r,t,d,`柱形 y 轴已自动包含 0 基线(${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`The bar y-axis now includes the zero baseline (${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`把 y-axis 范围写成包含 0 的区间`,`Declare a y-axis range that includes 0`),R=[Math.min(0,R[0]),Math.max(0,R[1])])),y===`horizontal`&&h(r,t,t.headerLine||t.firstLine,`xychart horizontal 暂不支持,按纵向绘制`,`Horizontal xychart is not supported yet; drawing vertically`,"改成 `xychart` 或 `xychart vertical`","Use `xychart` or `xychart vertical`"),l?.kind===`linear`&&new Set(M).size!==M.length&&h(r,t,k,`数值 x 轴 ${l.min} --> ${l.max} 的刻度有重复,类别名已加序号`,`The numeric x-axis ${l.min} --> ${l.max} produces repeated ticks; categories were numbered`,`扩大范围或减少数据点`,`Widen the range or use fewer points`),{model:{chart:O,title:i,titleLine:a,xLabel:o,yLabel:s,xLine:u,yLine:d,yDomain:R,categories:M,datasets:N,horizontal:y===`horizontal`},errors:r}}function k(e,t){let n=g(t?.lang),a=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,o=e.yDomain?{domain:e.yDomain}:{};if(e.chart===`combo`){let t=e.categories.map((t,n)=>Object.fromEntries([[`category`,t],...e.datasets.map((e,t)=>[`v${t}`,e.values[n]])]));return{chart:`combo`,[i.diagramCombo]:!0,...e.title?{title:e.title}:{},...a?{subtitle:a}:{},data:t,encode:{category:`category`},layers:e.datasets.map((e,t)=>({mark:e.type===`bar`?`column`:`line`,field:`v${t}`,axis:`left`})),fields:Object.fromEntries(e.datasets.map((e,t)=>[`v${t}`,{label:e.name||(n?`Series ${t+1}`:`系列 ${t+1}`),...o}]))}}let s=e.datasets[0],c=s.pointLabels.some(Boolean),l=e.categories.map((e,t)=>({category:e,value:s.values[t],...c?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...a?{subtitle:a}:{},data:l,encode:{category:`category`,value:`value`,...c?{id:`id`}:{}},fields:{value:{...o,...s.name?{label:s.name}:{}}},...c?{annotations:s.pointLabels.flatMap((e,t)=>e?[{kind:`note`,field:`value`,record:String(t),text:e}]:[])}:{}}}function A(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>{let t=/^v(\d+)$/.exec(String(e||``));return t?Number(t[1]):null};if(n[0]===`title`)return e.titleLine;if(n[0]===`subtitle`)return e.xLine||e.yLine;if(n[0]===`layers`)return e.datasets[Number(n[1])]?.line||e.datasets[0]?.line;if(n[0]===`fields`){let t=r(n[1]);return(t===null?null:e.datasets[t]?.line)||e.yLine||e.datasets[0]?.line}if(n[0]===`encode`)return e.xLine||e.datasets[0]?.line;if(n[0]===`annotations`)return e.datasets[0]?.line;if(n[0]===`data`){let t=r(n[2]);return(t===null?null:e.datasets[t]?.line)||e.datasets[0]?.line}return e.datasets[0]?.line}function j(e,t){if(e.datasets.length<=d)return[e];let n=e.datasets.flatMap(e=>e.values.filter(Number.isFinite)),r=e.datasets.some(e=>e.type===`bar`)?[0]:[],i=Math.min(...n,...r),a=Math.max(...n,...r),o=e.yDomain??[i,a>i?a:i+1],s=[];for(let n=0;n<e.datasets.length;n+=d)s.push({...e,yDomain:o,title:n?null:e.title,datasets:e.datasets.slice(n,n+d).map((e,r)=>({...e,name:e.name||`${g(t.lang)?`Series `:`系列 `}${n+r+1}`}))});return s}return e.implementations={xychart:{parse:O,validate:(e,t)=>j(e,t).flatMap(e=>(0,n.validateWith)(k(e,t),t,t=>A(e,t))),layout:(e,r,i)=>{let a=j(e,i).map(e=>(0,n.renderWith)(k(e,i),r,i,t=>A(e,t)));if(a.some(e=>!e.scene))return a.find(e=>!e.scene);let o=a[0];if(a.length>1){let e=0,t=a.map(({scene:t})=>{let n=r.ctx.el(`g`,{transform:`translate(${e} 0)`},t.children);return e+=t.width+24,n});o.width=e-24,o.height=Math.max(...a.map(e=>e.height)),o.scene={...o.scene,width:o.width,height:o.height,children:t}}return(e.categories.length>60||o.width>r.width*2||a.length>1)&&o.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.xLine||e.datasets[0]?.line||i.firstLine,a.length>1?`XY 图按数据序列分栏,可横向滚动`:`XY 图较大,可滚动查看`,a.length>1?`XY series are arranged in panels; scroll horizontally`:`Large XY chart; scroll to view it`,`按数据序列或横轴范围拆分图表`,`Split the chart by series or x-axis range`)),o},optionMode:`raw`}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/basic`],KChartUnits[`chart/multivariate`]);
|
|
2
|
+
`).forEach((e,r)=>{let i=e.trim();if(i&&!i.startsWith(`%%`))for(let e of b(i,`;`))e&&n.push({text:e,line:t+r})}),n}function S(e,t){let n=null;for(let r of String(e.params||``).split(/\s+/).filter(Boolean))/^(?:horizontal|vertical)$/i.test(r)?n=r.toLowerCase():t.push(m(e,e.headerLine||e.firstLine,`xychart 不支持头行选项「${r}」`,`xychart does not accept header options: ${r}`,`头行只接受 horizontal 或 vertical`,`Only horizontal or vertical is allowed after the header`));return n}function C(e,t,n,r){let i=[];for(let a of b(e)){let e=l.exec(a);if(!e)return r.push(m(t,n,`数据点「${a}」须为数值,可带一个引号标签`,`Data point "${a}" must be a number, optionally with a quoted label`,'写成 `12` 或 `12 "标签"`','Write `12` or `12 "Label"`')),null;let o=y(e[2],e[3],void 0);i.push({value:Number(e[1]),label:o===void 0?null:_(o)||null})}return i}function w(e,t,n,r){let i=s.exec(t);if(i){let t=i[1].trim()?v(i[1]):null,a=b(i[2]);return!a.length||a.some(e=>!e)?(r.push(m(e,n,`x-axis 需要非空类别列表`,`x-axis needs a non-empty category list`,`去掉空类别或多余的逗号`,`Remove empty categories or extra commas`)),{title:t,data:null}):{title:t,data:{kind:`band`,categories:a.map(v)}}}let a=o.exec(t);if(a&&!/-$/.test(a[1])){let e=Number(a[2]),t=Number(a[3]);return{title:a[1].trim()?v(a[1]):null,data:{kind:`linear`,min:e,max:t}}}return{title:t?v(t):null,data:null}}function T(e,t,n,r){let i=new Map,a=[],o=!1;for(let e of r){let t=(i.get(e)||0)+1;i.set(e,t),t===1?a.push(e):(o=!0,a.push(`${e} (${t})`))}return o&&h(e,t,n,`x-axis 类别名重复,已按出现顺序加序号区分`,`Duplicate x-axis categories were numbered in source order`,`让每个类别名唯一`,`Give every category a unique name`),a}function E(e,t,n){let r=e=>String(Number(e.toPrecision(12)));if(n<=0)return[];if(n===1)return[r(e)];let i=(t-e)/(n-1);return Array.from({length:n},(t,n)=>r(e+n*i))}function D(e,t,n,r){let i=c.exec(t),a=i[1].toLowerCase(),o=u.exec(i[2]);if(!o)return r.push(m(e,n,`无法识别 ${a} 数据「${t}」`,`Unrecognized ${a} data "${t}"`,`写成 \`${a} [值, 值]\` 或 \`${a} "名称" [值, 值]\``,`Write \`${a} [value, value]\` or \`${a} "Name" [value, value]\``)),null;let s=C(o[4],e,n,r);if(!s)return null;let l=y(o[1],o[2],o[3]);return{type:a,name:l===void 0?null:_(l),points:s,line:n}}function O(e,t){let r=[],i=null,a=null,o=null,s=null,l=null,u=null,d=null,g=null,_=[],y=S(t,r);for(let f of x(e,t.firstLine))if(/^title\b/i.test(f.text)){let e=f.text.replace(/^title\b/i,``).trim();if(!e){r.push(m(t,f.line,`title 需要标题文字`,`title needs some text`));continue}if(i!==null){r.push(m(t,f.line,`xychart 只能有一个 title`,`xychart accepts one title`));continue}i=(0,n.numericLabel)(v(e),t,f.line,r),a=f.line}else if(/^x-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^x-axis\b/i,``).trim(),f.line,r);e.title!==null&&(o!==null&&h(r,t,f.line,`xychart 重复的 x-axis,只保留最后一条`,`Duplicate x-axis; the last one is used`),o=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&(l&&h(r,t,f.line,`xychart 重复的 x-axis 数据,只保留最后一条`,`Duplicate x-axis data; the last one is used`),l=e.data,u=f.line),u??=f.line}else if(/^y-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^y-axis\b/i,``).trim(),f.line,r);d??=f.line,e.title!==null&&(s!==null&&h(r,t,f.line,`xychart 重复的 y-axis,只保留最后一条`,`Duplicate y-axis; the last one is used`),s=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&e.data.kind===`linear`?(g&&h(r,t,f.line,`xychart 重复的 y-axis 范围,只保留最后一条`,`Duplicate y-axis range; the last one is used`),g=[e.data.min,e.data.max]):e.data?.kind===`band`&&r.push(m(t,f.line,"y-axis 只接受数值范围 `min --> max`","y-axis accepts only a numeric range `min --> max`",'改成 `y-axis "标题" 0 --> 100`','Use `y-axis "Title" 0 --> 100`'))}else if(c.test(f.text)){let e=D(t,f.text,f.line,r);e&&_.push(e)}else r.push(m(t,f.line,`无法识别 xychart 语句「${f.text}」`,`Unrecognized xychart statement "${f.text}"`,`支持 title、x-axis、y-axis、bar、line`,`Supported: title, x-axis, y-axis, bar, line`));_.length||r.push(m(t,t.firstLine,`xychart 至少需要一条 bar 或 line 数据`,`xychart needs at least one bar or line plot`)),_.length>f&&r.push(m(t,_[f].line,`xychart 安全上限为 ${f} 条数据序列,当前 ${_.length} 条`,`xychart safety cap is ${f} plots; got ${_.length}`,`将数据序列合并到 ${f} 条以内,或拆成多张图`,`Merge series to stay within ${f} plots, or split the chart`));let b=_.length===1&&_[0].name,C=_.some(e=>e.type===`line`&&e.points.some(e=>e.label)),O=_.length>1||b&&!(_[0].type===`line`&&_[0].points.some(e=>e.label))?`combo`:_[0]?.type===`bar`?`column`:`line`,k=u||_[0]?.line||t.firstLine,A=_.map(e=>e.points.length),j=l?.kind===`band`?l.categories.length:Math.max(0,...A);j>p&&O!==`column`&&r.push(m(t,k,`xychart 最多支持 ${p} 个横轴类别`,`xychart supports at most ${p} x-axis categories`,`按横轴范围拆分图表`,`Split the chart by x-axis range`));let M;M=l?.kind===`band`?T(r,t,k,l.categories.map(e=>(0,n.numericLabel)(e,t,k,r))):l?.kind===`linear`?E(l.min,l.max,j):Array.from({length:j},(e,t)=>String(t+1));let N=_.map(e=>{let i=e.points.length>M.length,a=O===`combo`||e.type===`line`?null:0;return i?h(r,t,e.line,`数据点数 ${e.points.length} 多于类别数 ${M.length},多余的点已略去`,`${e.points.length} points exceed ${M.length} categories; extra points were dropped`,`补齐 x-axis 类别或删去多余的点`,`Add x-axis categories or remove the extra points`):e.points.length<M.length&&a===0&&h(r,t,e.line,`bar 数据点数少于类别数,缺少的点按 0 绘制`,`The bar plot has fewer points than categories; missing points are drawn as 0`,`补齐数据点`,`Provide a value for every category`),{type:e.type,name:e.name&&(0,n.numericLabel)(e.name,t,e.line,r),line:e.line,values:M.map((t,n)=>e.points[n]?.value??a),pointLabels:M.map((i,a)=>{let o=e.points[a]?.label;return o?(0,n.numericLabel)(o,t,e.line,r):null})}});O===`combo`&&C&&h(r,t,_[0].line,`组合图中的数据点标签未绘制`,`Point labels are not drawn on a combined chart`,`把该序列拆成单独的 line 图,或删去标签`,`Split that plot into a line-only chart or drop the labels`),O!==`combo`&&N[0]?.name&&C&&h(r,t,_[0].line,`单序列折线的名称「${N[0].name}」未作为图例绘制`,`The name "${N[0].name}" of this single line is not drawn as a legend`,`需要图例时不要同时使用数据点标签`,`Do not combine point labels with a series name if the legend matters`);let P=_.find(e=>e.type===`bar`&&e.points.some(e=>e.label));P&&h(r,t,P.line,`bar 的数据点标签被忽略(Mermaid 也只对 line 绘制点标签)`,`Point labels on a bar plot are ignored (Mermaid draws them on line plots only)`,`改用 line 绘制带标签的序列`,`Use line for a labeled series`);let F=_.flatMap(e=>e.points.map(e=>e.value)),I=Math.min(...F),L=Math.max(...F),R=null;return g&&(g[1]>g[0]?R=[g[0],g[1]]:h(r,t,d,`y-axis 范围 ${g[0]} --> ${g[1]} 不是递增区间,已改为按数据取值`,`y-axis range ${g[0]} --> ${g[1]} is not increasing; derived from data instead`,"把范围写成 `小值 --> 大值`","Write the range as `low --> high`")),R&&(R[0]>I&&(h(r,t,d,`y-axis 最小值 ${R[0]} 高于数据最小值 ${I},已扩展到 ${I}`,`y-axis minimum ${R[0]} is above the data minimum ${I}; extended to ${I}`,`把最小值改为不大于 ${I}`,`Set the minimum to at most ${I}`),R[0]=I),R[1]<L&&(h(r,t,d,`y-axis 最大值 ${R[1]} 低于数据最大值 ${L},已扩展到 ${L}`,`y-axis maximum ${R[1]} is below the data maximum ${L}; extended to ${L}`,`把最大值改为不小于 ${L}`,`Set the maximum to at least ${L}`),R[1]=L),_.some(e=>e.type===`bar`)&&(R[0]>0||R[1]<0)&&(h(r,t,d,`柱形 y 轴已自动包含 0 基线(${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`The bar y-axis now includes the zero baseline (${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`把 y-axis 范围写成包含 0 的区间`,`Declare a y-axis range that includes 0`),R=[Math.min(0,R[0]),Math.max(0,R[1])])),y===`horizontal`&&h(r,t,t.headerLine||t.firstLine,`xychart horizontal 暂不支持,按纵向绘制`,`Horizontal xychart is not supported yet; drawing vertically`,"改成 `xychart` 或 `xychart vertical`","Use `xychart` or `xychart vertical`"),l?.kind===`linear`&&new Set(M).size!==M.length&&h(r,t,k,`数值 x 轴 ${l.min} --> ${l.max} 的刻度有重复,类别名已加序号`,`The numeric x-axis ${l.min} --> ${l.max} produces repeated ticks; categories were numbered`,`扩大范围或减少数据点`,`Widen the range or use fewer points`),{model:{chart:O,title:i,titleLine:a,xLabel:o,yLabel:s,xLine:u,yLine:d,yDomain:R,categories:M,datasets:N,horizontal:y===`horizontal`},errors:r}}function k(e,t,n=0){let a=g(t?.lang),o=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,s=e.yDomain?{domain:e.yDomain}:{};if(e.chart===`combo`){let t=e.categories.map((t,n)=>Object.fromEntries([[`category`,t],...e.datasets.map((e,t)=>[`v${t}`,e.values[n]])]));return{chart:`combo`,[i.diagramCombo]:{index:n},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:t,encode:{category:`category`},layers:e.datasets.map((e,t)=>({mark:e.type===`bar`?`column`:`line`,field:`v${t}`,axis:`left`})),fields:Object.fromEntries(e.datasets.map((e,t)=>[`v${t}`,{label:e.name||(a?`Series ${t+1}`:`系列 ${t+1}`),...s}]))}}let c=e.datasets[0],l=c.pointLabels.some(Boolean),u=e.categories.map((e,t)=>({category:e,value:c.values[t],...l?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:u,encode:{category:`category`,value:`value`,...l?{id:`id`}:{}},fields:{value:{...s,...c.name?{label:c.name}:{}}},...l?{annotations:c.pointLabels.flatMap((e,t)=>e?[{kind:`note`,field:`value`,record:String(t),text:e}]:[])}:{}}}function A(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>{let t=/^v(\d+)$/.exec(String(e||``));return t?Number(t[1]):null};if(n[0]===`title`)return e.titleLine;if(n[0]===`subtitle`)return e.xLine||e.yLine;if(n[0]===`layers`)return e.datasets[Number(n[1])]?.line||e.datasets[0]?.line;if(n[0]===`fields`){let t=r(n[1]);return(t===null?null:e.datasets[t]?.line)||e.yLine||e.datasets[0]?.line}if(n[0]===`encode`)return e.xLine||e.datasets[0]?.line;if(n[0]===`annotations`)return e.datasets[0]?.line;if(n[0]===`data`){let t=r(n[2]);return(t===null?null:e.datasets[t]?.line)||e.datasets[0]?.line}return e.datasets[0]?.line}function j(e,t){if(e.datasets.length<=d)return[e];let n=e.datasets.flatMap(e=>e.values.filter(Number.isFinite)),r=e.datasets.some(e=>e.type===`bar`)?[0]:[],i=Math.min(...n,...r),a=Math.max(...n,...r),o=e.yDomain??[i,a>i?a:i+1],s=[];for(let n=0;n<e.datasets.length;n+=d)s.push({...e,yDomain:o,title:n?null:e.title,datasets:e.datasets.slice(n,n+d).map((e,r)=>({...e,name:e.name||`${g(t.lang)?`Series `:`系列 `}${n+r+1}`}))});return s}return e.implementations={xychart:{parse:O,validate:(e,t)=>j(e,t).flatMap(e=>(0,n.validateWith)(k(e,t),t,t=>A(e,t))),layout:(e,r,i)=>{let a=j(e,i).map((e,t)=>(0,n.renderWith)(k(e,i,t),r,i,t=>A(e,t)));if(a.some(e=>!e.scene))return a.find(e=>!e.scene);let o=a[0];if(a.length>1){let e=0,t=a.map(({scene:t})=>{let n=r.ctx.el(`g`,{transform:`translate(${e} 0)`},t.children);return e+=t.width+24,n});o.width=e-24,o.height=Math.max(...a.map(e=>e.height)),o.scene={...o.scene,width:o.width,height:o.height,children:t}}return(e.categories.length>60||o.width>r.width*2||a.length>1)&&o.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.xLine||e.datasets[0]?.line||i.firstLine,a.length>1?`XY 图按数据序列分栏,可横向滚动`:`XY 图较大,可滚动查看`,a.length>1?`XY series are arranged in panels; scroll horizontally`:`Large XY chart; scroll to view it`,`按数据序列或横轴范围拆分图表`,`Split the chart by series or x-axis range`)),o},optionMode:`raw`}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/basic`],KChartUnits[`chart/multivariate`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
KChartUnits["diagram/venn"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
2
|
-
`).entries()){let e=o+t,r=P(n).trim();if(!r)continue;let i=/^[ \t]/.test(n),a=/^style\s+/i.exec(r);if(a){let t=z(r,a[0].length);if(t.ids.length>1){l.accept(`style ${JSON.stringify([...t.ids].sort().join(`|`))} ${r.slice(t.at).trimStart()}`,e);continue}}if(l.accept(r,e))continue;let s=R(r),c=r.slice(s.at);if(v&&i&&s.word===`text`){let t=L(c,0),n=B(c,t?t.at:0);if(!t||c.slice(n.at).trim()){b(e);continue}_?D(t.id,n.label,_.ids,e):x(e)}else if(i||(v=!1),s.word===`title`){let t=c.trim();if(!t){y(e,`title 后面缺少标题文字`,`title needs a heading after it`,`写成 title 标题文字`,`Write title followed by the heading`);continue}h=w(t.replace(/^"(.*)"$/,`$1`).trim(),e).text,g=e}else if(s.word===`set`){let t=L(c,0);if(!t){b(e);continue}let n=B(c,t.at),r=V(c,n.at);if(c.slice(r.at).trim()){b(e);continue}T(t.id,n.label,r.size,e)&&(v=!0)}else if(s.word===`union`){let t=z(c,0),n=B(c,t.at),r=V(c,n.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}E(t.ids,n.label,r.size,e)&&(v=!0)}else if(s.word===`text`){let t=z(c,0),n=L(c,t.at),r=B(c,n?n.at:t.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}n?D(n.id,r.label,t.ids,e):D(t.ids[0],r.label,_?_.ids:[],e)}else b(e)}c.push(...l.diagnostics()),d.length||y(o,`文氏图没有任何 set`,`A Venn diagram needs at least one set`,`至少写一行 set`,`Write at least one set line`);let O=(e,t)=>({...e,status:l.statusOf(t),link:l.linkOf(t)});for(let e of d)Object.assign(e,O({},e.id));for(let e of f)Object.assign(e,O({},e.ids.join(`|`)));for(let e of p)Object.assign(e,O({},e.id));return{model:{kind:`venn-beta`,title:h,titleLine:g,sets:d,unions:f,texts:p},errors:c}}function H(e,t,n,r){let i=1/0;for(let r of n)i=Math.min(i,r.r-Math.hypot(e-r.cx,t-r.cy));for(let n of r)i=Math.min(i,Math.hypot(e-n.cx,t-n.cy)-n.r);return i}function U(e,t,n=3,r=16){let i=e.reduce((e,t)=>e+t.cx,0)/e.length,a=e.reduce((e,t)=>e+t.cy,0)/e.length,o={x:i,y:a,value:H(i,a,e,t)},s=Math.max(...e.map(e=>e.r));for(let i=0;i<n;i+=1){let n=o;for(let i=-r/2;i<=r/2;i+=1)for(let c=-r/2;c<=r/2;c+=1){let l=n.x+i*s/(r/2),u=n.y+c*s/(r/2),d=H(l,u,e,t);(d>o.value+1e-9||Math.abs(d-o.value)<=1e-9&&Math.abs(u-a)<Math.abs(o.y-a)-1e-9)&&(o={x:l,y:u,value:d})}s/=r/4}return o}function W(e,t){let n=e.map(e=>Number.isFinite(e.size)?Math.max(0,e.size):C),r=Math.max(0,...n);return n.map(e=>t*(r>0?Math.max(.3,Math.sqrt(e/r)):1))}function G(e,t,n){let r=W(e,t),i=e.map((e,t)=>({id:e.id,label:e.label,icon:e.icon,tone:e.tone,status:e.status,link:e.link,line:e.line,r:r[t],cx:0,cy:0}));if(i.length===1)return i;if(i.length===2){let e=Math.min(r[0],r[1]),t=Math.abs(r[0]-r[1])+.25*e,a=r[0]+r[1]-.1*e,o=t+Math.min(1,Math.max(0,n))*(a-t);return i[0].cx=-o/2,i[1].cx=o/2,i}let a=i.map((e,t)=>({index:t,r:e.r})).sort((e,t)=>t.r-e.r||t.index-e.index)[0].index,o=[0,1,2].filter(e=>e!==a).sort((e,t)=>e-t),s=(te+Math.min(1,Math.max(0,n))*.7)*(r.reduce((e,t)=>e+t,0)/3),c=[];return c[a]=-Math.PI/2,c[o[0]]=5*Math.PI/6,c[o[1]]=Math.PI/6,i.forEach((e,t)=>{e.cx=Math.cos(c[t])*s,e.cy=Math.sin(c[t])*s}),i}function K(e,t){if(e.length<=1)return .5;let n=W(e,t);if(e.length===2){let e=Math.min(n[0],n[1]),t=Math.abs(n[0]-n[1])+.25*e,r=n[0]+n[1]-.1*e;return r>t?Math.min(1,Math.max(0,(n[0]+n[1]-A*e-t)/(r-t))):.5}return .44999999999999996/.7}function q(e){let t=Math.min(...e.map(e=>e.cx-e.r)),n=Math.max(...e.map(e=>e.cx+e.r)),r=Math.min(...e.map(e=>e.cy-e.r)),i=Math.max(...e.map(e=>e.cy+e.r));return{x:t,y:r,w:n-t,h:i-r}}function J(e,n){let r=e.kind===`set`?d:f,i=e.kind===`set`?0:14,a=[...e.labels.map(e=>e.text),...e.items.map(e=>e.text)],o=e.kind===`set`?M:N,s=Math.max(0,...a.flatMap(e=>String(e).split(/\s+/).filter(Boolean).map(e=>n(e,o)))),m=Math.max(48,s+2,(e.clear-r)*2-20-i),h=(e,r)=>(0,t.wrapText)(e,m,r,(e,t)=>n(e,t)),g=e.kind===`set`?M:N,_=[];for(let t of e.labels)for(let e of h(t.text,g))_.push({text:e,font:g,icon:t.icon,link:t.link});let v=[];for(let t of e.items)for(let e of h(t.text,N))v.push({text:e,font:N,icon:t.icon,link:t.link,status:t.status});let y=e=>e.length?Math.max(...e.map(e=>n(e.text,e.font)+(e.icon?18:0))):0,b=_.length?y(_)+i:0,x=_.length*((e.kind===`set`?c:l)+4/_.length),S=y(v),C=v.length*l,w=Math.max(b,S),T=x+(v.length?(_.length?u:0)+C:0),E={labels:_,items:v,slack:r,pad:i,labelW:b,labelH:x,itemW:S,itemH:C,w,h:T,chip:e.kind!==`set`&&_.length>0};return E.room=T?Y(e,w,T)-p:1/0,E.fits=E.room>=-.5,E}function Y(e,t,n){let r=1/0;for(let[i,a]of[[-1,-1],[1,-1],[1,1],[-1,1],[0,-1],[1,0],[0,1],[-1,0]])r=Math.min(r,H(e.x+i*t/2,e.y+a*n/2,e.inside,e.outside));return r}function X(e,t){let n=new Map;for(let e of t.texts){let t=n.get(e.key)||[];t.push(e),n.set(e.key,t)}let r=[];for(let t of e)r.push({key:t.id,kind:`set`,ids:[t.id],line:t.line,tone:t.tone,labels:[{text:t.label||t.id,icon:t.icon,line:t.line,link:t.link}],items:(n.get(t.id)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),texts:n.get(t.id)||[]});let i=new Map;for(let a of t.unions){let t=a.ids.join(`|`),o=i.get(t);if(o){a.label&&o.labels.push({text:a.label,line:a.line});continue}let s={key:t,kind:`union`,ids:a.ids,line:a.line,tone:e.find(e=>e.id===a.ids[0])?.tone||1,labels:a.label?[{text:a.label,icon:a.icon,line:a.line,link:a.link}]:[],items:(n.get(t)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),status:a.status,link:a.link,texts:n.get(t)||[]};i.set(t,s),r.push(s)}return Z(r,e),r}function Z(e,t){for(let n of e)n.inside=n.ids.map(e=>t.find(t=>t.id===e)).filter(Boolean),n.outside=t.filter(e=>!n.inside.includes(e))}function Q(e,t,n){let r=1/0;for(let i of e){let e=U(i.inside,i.outside,n?2:3,n?10:16);i.x=e.x,i.y=e.y,i.clear=e.value,i.block=J(i,t),r=Math.min(r,i.block.room)}return r}function re(e,t,n,r){let i=[];for(let e=0;e<T;e+=1)i.push(e/16);i.sort((e,t)=>Math.abs(e-r)-Math.abs(t-r)||t-e);let a=null;for(let r of i){Z(t,e(r));let i=Q(t,n,!0);if((!a||i>a.worst+1e-9)&&(a={spread:r,worst:i}),i>=0)return Z(t,e(r)),Q(t,n,!1),{rings:e(r),worst:i}}return Z(t,e(a.spread)),{rings:e(a.spread),worst:Q(t,n,!1)}}function ie(e){let t=e.block,n=e.y-t.h/2,r=e.kind===`set`?c:l;e.rows=[],e.chip=null,t.labels.length&&(e.chip={x:e.x-t.labelW/2,y:n,w:t.labelW,h:t.labelH},t.labels.forEach((t,i)=>e.rows.push({text:t.text,font:t.font,icon:t.icon,link:t.link,status:t.status,x:e.x,y:n+m+(i+.5)*r,anchor:`middle`})));let i=n+t.labelH+(t.labels.length&&t.items.length?u:0);t.items.forEach((t,n)=>e.rows.push({text:t.text,font:t.font,icon:t.icon,link:t.link,status:t.status,x:e.x,anchor:`middle`,y:i+(n+.5)*l}))}function ae(e,{measure:n,width:r,lang:i}){let a=Math.max(240,r-48),o=K(e.sets,1),s=q(G(e.sets,1,o)),c=Math.max(56,Math.min(a/Math.max(1,s.w),O/Math.max(1,s.h))),l=X(G(e.sets,c,o),e),u=null;for(let t=0;t<=D&&(u=re(t=>G(e.sets,c,t),l,n,o),!(u.worst>=0));t+=1){let t=c*E;if(q(G(e.sets,t,o)).w>a*2)break;c=t}let d=u.rings,f=[];for(let e of l)e.block.fits||(f.push({region:e,rows:[...e.block.labels,...e.block.items]}),e.block={...e.block,labels:[],labelW:0,labelH:0,chip:!1});let p=new Set(l.map(e=>e.key));for(let t of e.texts)p.has(t.key)||f.push({region:{x:null,y:null,tone:1,line:t.line,caption:t.ids.join(` ∩ `)},rows:[{text:t.label,font:N}]});let m=[];f.length&&m.push((0,t.warning)(`DIAGRAM_HINT`,i,f[0].region.line??e.sets[0].line,`有 ${f.length} 个标签放不进所属区域,已排在图下方并用引线指向该区域`,`${f.length} label(s) do not fit their region and moved below the plot with a leader`,`缩短标签,或减少同一区域的 text`,`Shorten the labels, or use fewer text nodes per region`));for(let e of l)if(!(e.texts.length<=S)){m.push((0,t.warning)(`DIAGRAM_HINT`,i,e.texts[S].line,`「${e.key}」区域有 ${e.texts.length} 个 text,超过 ${S} 个后很难阅读`,`Region "${e.key}" holds ${e.texts.length} text nodes; more than ${S} is hard to read`,`把说明移到图外,或拆成多张图`,`Move details outside, or split the diagram`));break}let h=l.filter(e=>e.block.h>0||e.block.labels.length);for(let e of h)ie(e);return $({mode:`rings`,rings:d,regions:h,plot:q(d),rows:h.flatMap(e=>e.rows),shelf:f,notes:m},e,{measure:n,width:r})}function oe(e,{measure:n,width:r,lang:i}){let a=new Map;for(let t of e.texts){let e=a.get(t.key)||[];e.push(t),a.set(t.key,e)}let o=[];for(let t of e.sets)o.push({kind:`set`,key:t.id,tone:t.tone,status:t.status,link:t.link,line:t.line,titles:[{...t,label:t.label||t.id}],caption:``,items:a.get(t.id)||[]});let s=new Map;for(let t of e.unions){let n=t.ids.join(`|`),r=s.get(n);if(r){t.label&&r.titles.push(t);continue}let i={kind:`union`,key:n,tone:e.sets.find(e=>e.id===t.ids[0])?.tone||1,status:t.status,link:t.link,line:t.line,titles:t.label||t.icon?[t]:[],caption:t.ids.join(` ∩ `),items:a.get(n)||[]};s.set(n,i),o.push(i)}let u=new Set(o.map(e=>e.key));for(let t of e.texts)u.has(t.key)||o.push({kind:`loose`,key:t.key,tone:1,line:t.line,titles:[t],caption:t.ids.join(` ∩ `),items:[]});let d=(e,r)=>(0,t.wrapText)(e,140,r,(e,t)=>n(e,t));for(let e of o){let t=(e,t)=>e.flatMap(e=>d(e.label,t).map((n,r)=>({text:n,font:t,status:e.status,link:e.link,icon:r===0?e.icon:null})));e.header=t(e.titles,M),e.captionLines=e.caption?d(e.caption,N):[],e.itemLines=t(e.items,N);let r=[...e.header.map(e=>n(e.text,e.font)+(e.icon?18:0)),...e.captionLines.map(e=>n(e,N)),...e.itemLines.map(e=>n(e.text,e.font)+(e.icon?18:0))];e.w=Math.max(b,Math.ceil(Math.max(0,...r)+28)),e.h=28+e.header.length*c+(e.captionLines.length?4+e.captionLines.length*l:0)+(e.itemLines.length?6+e.itemLines.length*l:0)}let f=Math.max(...o.map(e=>e.w)),p=Math.max(240,r-48),m=Math.min(x,o.length);for(;m>1&&m*f+(m-1)*y>p*2;)--m;let h=Math.ceil(o.length/m),g=[];o.forEach((e,t)=>{e.column=t%m,e.row=Math.floor(t/m),g[e.row]=Math.max(g[e.row]||0,e.h)});let _=[],S=0;for(let e=0;e<h;e+=1)_[e]=S,S+=g[e]+y;o.forEach(e=>{e.w=f,e.x=e.column*(f+y),e.y=_[e.row],e.rows=[];let t=e.y+v;for(let n of e.header)e.rows.push({...n,x:e.x+v,y:t+c/2,anchor:`start`}),t+=c;if(e.captionLines.length){t+=4;for(let n of e.captionLines)e.rows.push({text:n,font:N,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l}if(e.itemLines.length){t+=6;for(let n of e.itemLines)e.rows.push({...n,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l}});let C=[(0,t.warning)(`DIAGRAM_HINT`,i,e.sets[0].line,`${e.sets.length} 个集合画成圆环后重叠区无法阅读,已改用分区面板`,`${e.sets.length} sets would leave unreadable overlaps; drawn as a region grid instead`,`集合减到 3 个可获得圆环布局,或接受分区面板`,`Keep three sets for rings, or accept the region grid`)];return $({mode:`grid`,panels:o,plot:{x:0,y:0,w:m*f+(m-1)*y,h:S-y},rows:o.flatMap(e=>e.rows),shelf:[],notes:C},e,{measure:n,width:r})}function $(e,n,{measure:r,width:i}){let c=n.title?(0,t.wrapText)(n.title,Math.max(160,Math.min(i-48,480)),j,(e,t)=>r(e,t)):[],u=c.length?c.length*o+s:0,d=[],f=e.plot.x+e.plot.w,p=e.plot.y+e.plot.h;if(e.shelf.length){let t=Math.max(e.plot.w,240),n=e.plot.x,i=e.plot.y+e.plot.h+h,a=0;for(let o of e.shelf){let s=[...o.region.caption?[{text:o.region.caption,font:N,kind:`caption`}]:[],...o.rows.map(e=>({...e,kind:e.font===M?`label`:`item`}))],c=Math.max(0,...s.map(e=>r(e.text,e.font)));n>e.plot.x&&n+c>e.plot.x+t&&(n=e.plot.x,i+=a+y/2,a=0);let u=s.map((e,t)=>({text:e.text,font:e.font,kind:e.kind,x:n,y:i+(t+.5)*l}));d.push({lines:u,tone:o.region.tone,from:o.region.x==null?null:{x:o.region.x,y:o.region.y},to:{x:n+c/2,y:i-_}}),p=Math.max(p,i+s.length*l),f=Math.max(f,n+c),a=Math.max(a,s.length*l),n+=c+g}}let m=Math.max(e.plot.x+e.plot.w,f)-e.plot.x,v=Math.max(m,...c.map(e=>r(e,j))),b=a+(v-m)/2-e.plot.x,x=a+u-e.plot.y,S=Math.ceil(p-e.plot.y+u+48),C=Math.ceil(v+48);for(let t of e.rings||[])t.cx+=b,t.cy+=x;for(let t of e.panels||[])t.x+=b,t.y+=x;for(let t of e.rows)t.x+=b,t.y+=x;for(let t of e.regions||[])t.x+=b,t.y+=x,t.chip&&(t.chip.x+=b,t.chip.y+=x);for(let e of d){for(let t of e.lines)t.x+=b,t.y+=x;e.from&&={x:e.from.x+b,y:e.from.y+x},e.to={x:e.to.x+b,y:e.to.y+x}}return{width:C,height:S,mode:e.mode,title:c.length?{lines:c,x:a+v/2,top:34}:null,rings:e.rings||[],regions:e.regions||[],panels:e.panels||[],rows:e.rows,shelf:d,notes:e.notes,anchor:{x:a+v/2,y:a+u+e.plot.h/2}}}function se(e,n={}){let r=n.measure||t.fallbackMeasure,i=Math.max(1,Number(n.width)||800),a=n.lang||`zh`;if(!e.sets.length)return{width:i,height:0,errors:[]};let o=e.sets.length<=k?ae(e,{measure:r,width:i,lang:a}):oe(e,{measure:r,width:i,lang:a}),s=[...o.notes],c=e.sets.length+e.unions.length+e.texts.length;return c>ee?s.push((0,t.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图有 ${c} 个元素,建议拆分`,`The Venn diagram has ${c} parts; consider splitting it`,`按集合拆成多张图`,`Split the diagram by set`)):o.width>i*2&&s.push((0,t.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图需要 ${o.width}px 宽,超过图框两倍`,`The Venn diagram needs ${o.width}px, more than twice the frame`,`加宽图框,或拆分文氏图`,`Widen the frame, or split the diagram`)),{...o,errors:s}}function ce(e,n){let r=(0,t.appearance)(n),a=n.color(`bg`),s=e=>n.frameTone(n.color(`tone${(e-1)%6+1}`)),c=e=>{let t=e.status?n.textColor(r[e.status]):e.kind===`caption`?r.fg3:e.font===M?r.fg1:r.fg2,a=[n.text(e.x+(e.icon?e.anchor===`middle`?9:18:0),e.y,e.text,{anchor:e.anchor,size:e.font.size,weight:e.font.weight,"dominant-baseline":`central`,fill:t})];if(e.icon){let r=e.anchor===`middle`?e.x-n.measure(e.text,e.font.size,e.font.weight)/2-3:e.x+6;a.unshift((0,i.labelIcon)(n,e.icon,r,e.y,12,t))}return e.link?n.link(e.link.href,a,e.link):n.el(`g`,{},a)},l=[];if(e.mode===`rings`){for(let t of e.rings)l.push(n.circle(t.cx,t.cy,t.r,{fill:t.status?n.frameTone(r[t.status]):s(t.tone),"fill-opacity":.1}));for(let t of e.rings)l.push(n.circle(t.cx,t.cy,t.r,{fill:`none`,stroke:t.status?n.frameTone(r[t.status]):s(t.tone),"stroke-width":w,meta:{kind:`node`,id:t.id,label:t.id}}));for(let t of e.regions)t.chip&&l.push(n.rect(t.chip.x,t.chip.y,t.chip.w,t.chip.h,{rx:r.smallRadius,fill:t.status?n.tint(a,r[t.status],.12):a}));for(let t of e.rows)l.push(c(t));for(let t of e.shelf){t.from&&l.push(n.line(t.from.x,t.from.y,t.to.x,t.to.y,{stroke:n.tint(a,s(t.tone),.55),"stroke-width":1,"stroke-dasharray":`3 3`}));for(let e of t.lines)l.push(c(e))}}else for(let t of e.panels){let e=t.status?n.frameTone(r[t.status]):s(t.tone);l.push(n.rect(t.x,t.y,t.w,t.h,{rx:r.radius,fill:n.tint(a,e,t.kind===`set`?.07:.04),stroke:n.tint(a,e,.45),"stroke-width":1,...t.kind===`set`?{}:{"stroke-dasharray":`5 4`},meta:{kind:t.kind===`set`?`node`:`frame`,id:t.key,label:t.key}}));for(let e of t.rows)l.push(c(e))}return e.title&&e.title.lines.forEach((t,i)=>l.push(n.text(e.title.x,e.title.top+i*o,t,{anchor:`middle`,size:j.size,weight:j.weight,fill:r.fg1,"dominant-baseline":`central`}))),{width:e.width,height:e.height,title:e.title?e.title.lines.join(` `):void 0,children:l,anchor:e.anchor}}return e.implementations={"venn-beta":{acceptsPresentation:!0,parse:ne,layout:se,scene:ce}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/tree-family-icon`]);
|
|
1
|
+
KChartUnits["diagram/venn"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=24,s=20,c=12,l=18,u=16,d=4,f=12,p=10,m=4,h=26,g=28,_=8,v=14,y=16,b=168,x=3,S=12,C=10,w=1.5,T=.1,E=4.5,D=17,O=1.12,ee=6,k=460,A=60,te=3,ne=.55,re=.55,j={size:n.FONT.title.size,weight:n.FONT.title.weight},M={size:n.FONT.title.size,weight:n.FONT.title.weight},N={size:n.FONT.label.size,weight:n.FONT.label.weight},P={...N,weight:600};function F(e){let t=!1;for(let n=0;n<e.length;n+=1)if(e[n]===`"`)t=!t;else if(!t&&e[n]===`%`&&e[n+1]===`%`)return e.slice(0,n);return e}var I=/^"([^"]*)"|^([A-Za-z_][\w-]*)/,L=/^[ \t]*/;function R(e,t){let n=t+L.exec(e.slice(t))[0].length,r=I.exec(e.slice(n));return r?{id:r[1]??r[2],at:n+r[0].length}:null}function ie(e){let t=/^[A-Za-z][\w-]*/.exec(e);return t?{word:t[0].toLowerCase(),at:t[0].length}:{word:``,at:0}}function z(e,t){let n=[],r=t;for(;;){let t=R(e,r);if(!t||/^\s*:/.test(e.slice(t.at)))break;n.push(t.id);let i=t.at+L.exec(e.slice(t.at))[0].length;if(e[i]!==`,`){r=t.at;break}r=i+1}let i=n.length?r:t;return{ids:n,at:i+L.exec(e.slice(i))[0].length}}function B(e,t){let n=/^\[([^\]]*)\]/.exec(e.slice(t));if(!n)return{label:null,at:t};let r=n[1];return r.length>=2&&r.startsWith(`"`)&&r.endsWith(`"`)&&(r=r.slice(1,-1)),{label:r.trim(),at:t+n[0].length}}function V(e,t){let n=/^:\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))/.exec(e.slice(t));return n?{size:Number(n[1]),at:t+n[0].length}:{size:null,at:t}}function H(e,t={}){let a=t.lang||`zh`,o=Number.isInteger(t.firstLine)?t.firstLine:2,s=Number.isInteger(t.headerLine)?t.headerLine:Math.max(1,o-1),c=[],l=(0,i.presentation)({lang:a}),u=new Set,d=[],f=[],p=[],m=new Map,h=``,g=s,_=null,v=!1,y=(e,t,r,i,o)=>c.push((0,n.error)(a,e,t,r,i,o)),b=e=>y(e,`无法识别这一行`,`Unrecognized line`,`使用 set、union、text、title 或 style`,`Use set, union, text, title, or style`),x=e=>y(e,`text 前缺少 set 或 union`,`A text line needs an owning set or union`,`把 text 缩进到 set/union 下面,或先写集合 id`,`Indent text under a set/union, or name the set first`),S=typeof t.params==`string`?t.params.trim():``;S&&y(s,`venn-beta 头行不能带内容「${S}」`,`Unexpected text after "venn-beta": ${S}`,`把内容写成 set、union 或 text 行`,`Move the text into set, union, or text lines`);for(let e of Object.keys(t.options||{}))y(s,`venn-beta 不支持选项「${e}」`,`Unsupported venn-beta option: ${e}`,`删除这个选项`,`Remove this option`);let w=(e,t)=>{let n=(0,r.normalizeLabel)(e,{lang:a,line:t});for(let e of n.diagnostics){let t=`${e.code}:${e.message}`;u.has(t)||(u.add(t),c.push(e))}return{text:n.text,icon:n.icon}},T=(e,t,n,r)=>{if(!e)return b(r),!1;if(m.has(e))return y(r,`集合「${e}」重复定义`,`Duplicate set identifier: ${e}`,`把同一个集合合并成一行 set`,`Merge the duplicate into a single set line`),!1;let i=t?w(t,r):{text:``,icon:null};return d.push({id:e,label:i.text,icon:i.icon,size:n??C,tone:d.length%6+1,line:r}),m.set(e,d.at(-1)),_={ids:[e]},!0},E=(e,t,n,r)=>{let i=e.filter((t,n)=>e.indexOf(t)===n);if(i.length<2)return y(r,`union 至少需要两个集合`,`A union needs at least two sets`,`写成 union A,B 或列更多集合`,`Write union A,B or list more sets`),!1;let a=i.filter(e=>!m.has(e));if(a.length)return y(r,`union 引用了未定义的集合「${a.join(`、`)}」`,`Unknown set identifier: ${a.join(`, `)}`,`先用 set 声明集合,再写 union`,`Declare each set with set before the union`),!1;let o=[...i].sort(),s=t?w(t,r):{text:``,icon:null};return f.push({ids:o,label:s.text,icon:s.icon,size:n??C/i.length**2,line:r}),_={ids:o},!0},D=(e,t,n,r)=>{let i=n.filter((e,t)=>n.indexOf(e)===t);if(!i.length){x(r);return}let a=w(t||e,r);p.push({id:e,label:a.text,icon:a.icon,ids:[...i].sort(),key:[...i].sort().join(`|`),line:r})};for(let[t,n]of String(e??``).split(`
|
|
2
|
+
`).entries()){let e=o+t,r=F(n).trim();if(!r)continue;let i=/^[ \t]/.test(n),a=/^style\s+/i.exec(r);if(a){let t=z(r,a[0].length);if(t.ids.length>1){l.accept(`style ${JSON.stringify([...t.ids].sort().join(`|`))} ${r.slice(t.at).trimStart()}`,e);continue}}if(l.accept(r,e))continue;let s=ie(r),c=r.slice(s.at);if(v&&i&&s.word===`text`){let t=R(c,0),n=B(c,t?t.at:0);if(!t||c.slice(n.at).trim()){b(e);continue}_?D(t.id,n.label,_.ids,e):x(e)}else if(i||(v=!1),s.word===`title`){let t=c.trim();if(!t){y(e,`title 后面缺少标题文字`,`title needs a heading after it`,`写成 title 标题文字`,`Write title followed by the heading`);continue}h=w(t.replace(/^"(.*)"$/,`$1`).trim(),e).text,g=e}else if(s.word===`set`){let t=R(c,0);if(!t){b(e);continue}let n=B(c,t.at),r=V(c,n.at);if(c.slice(r.at).trim()){b(e);continue}T(t.id,n.label,r.size,e)&&(v=!0)}else if(s.word===`union`){let t=z(c,0),n=B(c,t.at),r=V(c,n.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}E(t.ids,n.label,r.size,e)&&(v=!0)}else if(s.word===`text`){let t=z(c,0),n=R(c,t.at),r=B(c,n?n.at:t.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}n?D(n.id,r.label,t.ids,e):D(t.ids[0],r.label,_?_.ids:[],e)}else b(e)}c.push(...l.diagnostics()),d.length||y(o,`文氏图没有任何 set`,`A Venn diagram needs at least one set`,`至少写一行 set`,`Write at least one set line`);let O=(e,t)=>({...e,status:l.statusOf(t),link:l.linkOf(t)});for(let e of d)Object.assign(e,O({},e.id));for(let e of f)Object.assign(e,O({},e.ids.join(`|`)));for(let e of p)Object.assign(e,O({},e.id));return{model:{kind:`venn-beta`,title:h,titleLine:g,sets:d,unions:f,texts:p},errors:c}}function U(e,t,n,r){let i=1/0;for(let r of n)i=Math.min(i,r.r-Math.hypot(e-r.cx,t-r.cy));for(let n of r)i=Math.min(i,Math.hypot(e-n.cx,t-n.cy)-n.r);return i}function W(e,t,n=3,r=16){let i=e.reduce((e,t)=>e+t.cx,0)/e.length,a=e.reduce((e,t)=>e+t.cy,0)/e.length,o={x:i,y:a,value:U(i,a,e,t)},s=Math.max(...e.map(e=>e.r));for(let i=0;i<n;i+=1){let n=o;for(let i=-r/2;i<=r/2;i+=1)for(let c=-r/2;c<=r/2;c+=1){let l=n.x+i*s/(r/2),u=n.y+c*s/(r/2),d=U(l,u,e,t);(d>o.value+1e-9||Math.abs(d-o.value)<=1e-9&&Math.abs(u-a)<Math.abs(o.y-a)-1e-9)&&(o={x:l,y:u,value:d})}s/=r/4}return o}function G(e,t){let n=e.map(e=>Number.isFinite(e.size)?Math.max(0,e.size):C),r=Math.max(0,...n);return n.map(e=>t*(r>0?Math.max(.3,Math.sqrt(e/r)):1))}function K(e,t,n){let r=G(e,t),i=e.map((e,t)=>({id:e.id,label:e.label,icon:e.icon,tone:e.tone,status:e.status,link:e.link,line:e.line,r:r[t],cx:0,cy:0}));if(i.length===1)return i;if(i.length===2){let e=Math.min(r[0],r[1]),t=Math.abs(r[0]-r[1])+.25*e,a=r[0]+r[1]-.1*e,o=t+Math.min(1,Math.max(0,n))*(a-t);return i[0].cx=-o/2,i[1].cx=o/2,i}let a=i.map((e,t)=>({index:t,r:e.r})).sort((e,t)=>t.r-e.r||t.index-e.index)[0].index,o=[0,1,2].filter(e=>e!==a).sort((e,t)=>e-t),s=(re+Math.min(1,Math.max(0,n))*.7)*(r.reduce((e,t)=>e+t,0)/3),c=[];return c[a]=-Math.PI/2,c[o[0]]=5*Math.PI/6,c[o[1]]=Math.PI/6,i.forEach((e,t)=>{e.cx=Math.cos(c[t])*s,e.cy=Math.sin(c[t])*s}),i}function q(e,t){if(e.length<=1)return .5;let n=G(e,t);if(e.length===2){let e=Math.min(n[0],n[1]),t=Math.abs(n[0]-n[1])+.25*e,r=n[0]+n[1]-.1*e;return r>t?Math.min(1,Math.max(0,(n[0]+n[1]-ne*e-t)/(r-t))):.5}return .44999999999999996/.7}function J(e){let t=Math.min(...e.map(e=>e.cx-e.r)),n=Math.max(...e.map(e=>e.cx+e.r)),r=Math.min(...e.map(e=>e.cy-e.r)),i=Math.max(...e.map(e=>e.cy+e.r));return{x:t,y:r,w:n-t,h:i-r}}function ae(e,t){let r=e.kind===`set`?f:p,i=e.kind===`set`?M:P,a=(e,n)=>Math.max(0,...e.flatMap(({text:e})=>String(e).split(/\s+/).filter(Boolean).map(e=>t(e,n)))),o=Math.max(48,a(e.labels,i)+2,a(e.items,N)+2,(e.clear-r)*2-20),s=(e,r,i)=>e.flatMap(e=>(0,n.wrapText)(e.text,o,r,t).map(t=>({text:t,font:r,icon:e.icon,link:e.link,status:e.status||i}))),c=s(e.labels,i,e.status),h=s(e.items,N,c.length?null:e.status),g=c.length*(e.kind===`set`?l:u),_=Math.max(0,...[...c,...h].map(e=>Y(e,t))),v=g+(c.length&&h.length?d:0)+h.length*u;return{labels:c,items:h,labelH:g,w:_,h:v,room:v?oe(e,_,v)-m:1/0}}function Y(e,t){return t(e.text,e.font)+(e.icon?18:0)}function oe(e,t,n){let r=1/0;for(let i of e.inside)r=Math.min(r,i.r-Math.hypot(Math.abs(e.x-i.cx)+t/2,Math.abs(e.y-i.cy)+n/2));for(let i of e.outside)r=Math.min(r,Math.hypot(Math.max(0,Math.abs(e.x-i.cx)-t/2),Math.max(0,Math.abs(e.y-i.cy)-n/2))-i.r);return r}function se(e,t){let n=new Map;for(let e of t.texts){let t=n.get(e.key)||[];t.push(e),n.set(e.key,t)}let r=[];for(let t of e)r.push({key:t.id,kind:`set`,ids:[t.id],line:t.line,tone:t.tone,labels:[{text:t.label||t.id,icon:t.icon,line:t.line,link:t.link}],items:(n.get(t.id)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),texts:n.get(t.id)||[]});let i=new Map;for(let a of t.unions){let t=a.ids.join(`|`),o=i.get(t),s=a.label||a.icon?[{text:a.label,icon:a.icon,line:a.line,link:a.link}]:[];if(o){o.labels.push(...s);continue}let c={key:t,kind:`union`,ids:a.ids,line:a.line,tone:e.find(e=>e.id===a.ids[0])?.tone||1,labels:s,items:(n.get(t)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),status:a.status,link:a.link,texts:n.get(t)||[]};i.set(t,c),r.push(c)}return X(r,e),r}function X(e,t){for(let n of e)n.inside=n.ids.map(e=>t.find(t=>t.id===e)).filter(Boolean),n.outside=t.filter(e=>!n.inside.includes(e))}function Z(e,t,n){let r=1/0;for(let i of e){let e=W(i.inside,i.outside,n?2:3,n?10:16);i.x=e.x,i.y=e.y,i.clear=e.value,i.block=ae(i,t),r=Math.min(r,i.block.room)}return r}function Q(e,t,n,r){let i=[];for(let e=0;e<D;e+=1)i.push(e/16);i.sort((e,t)=>Math.abs(e-r)-Math.abs(t-r)||t-e);let a=null;for(let r of i){let i=e(r);X(t,i);let o=Z(t,n,!0),s=o>=0?Z(t,n,!1):o;if(s>=0)return{rings:i,worst:s};(!a||s>a.worst+1e-9)&&(a={spread:r,worst:s})}let o=e(a.spread);return X(t,o),{rings:o,worst:Z(t,n,!1)}}function ce(e){let t=e.block,n=e.y-t.h/2,r=e.kind===`set`?l:u;e.rows=t.labels.map((t,i)=>({...t,x:e.x,y:n+(i+.5)*r,anchor:`middle`}));let i=n+t.labelH+(t.labels.length&&t.items.length?d:0);t.items.forEach((t,n)=>e.rows.push({...t,x:e.x,anchor:`middle`,y:i+(n+.5)*u}))}function le(e,{measure:t,width:r,lang:i}){let a=Math.max(240,r-48),o=q(e.sets,1),s=J(K(e.sets,1,o)),c=Math.max(56,Math.min(a/Math.max(1,s.w),k/Math.max(1,s.h))),l=se(K(e.sets,c,o),e),u=null;for(let n=0;n<=ee&&(u=Q(t=>K(e.sets,c,t),l,t,o),!(u.worst>=0));n+=1){let t=c*O;if(J(K(e.sets,t,o)).w>a*2)break;c=t}let d=u.rings,f=[];for(let e of l)e.block.room>=0||f.push({region:e,rows:[...e.block.labels,...e.block.items]});let p=new Set(l.map(e=>e.key));for(let t of e.texts)p.has(t.key)||f.push({region:{x:null,y:null,tone:1,line:t.line,caption:t.ids.join(` ∩ `)},rows:[{text:t.label,font:N,icon:t.icon,link:t.link,status:t.status}]});let m=[];f.length&&m.push((0,n.warning)(`DIAGRAM_HINT`,i,f[0].region.line??e.sets[0].line,`有 ${f.length} 个标签放不进所属区域,已排在图下方并用引线指向该区域`,`${f.length} label(s) do not fit their region and moved below the plot with a leader`,`缩短标签,或减少同一区域的 text`,`Shorten the labels, or use fewer text nodes per region`));for(let e of l)if(!(e.texts.length<=S)){m.push((0,n.warning)(`DIAGRAM_HINT`,i,e.texts[S].line,`「${e.key}」区域有 ${e.texts.length} 个 text,超过 ${S} 个后很难阅读`,`Region "${e.key}" holds ${e.texts.length} text nodes; more than ${S} is hard to read`,`把说明移到图外,或拆成多张图`,`Move details outside, or split the diagram`));break}let h=l.filter(e=>e.block.h>0&&e.block.room>=0);for(let e of h)ce(e);return $({mode:`rings`,rings:d,regions:h,plot:J(d),rows:h.flatMap(e=>e.rows),shelf:f,notes:m},e,{measure:t,width:r})}function ue(e,{measure:t,width:r,lang:i}){let a=new Map;for(let t of e.texts){let e=a.get(t.key)||[];e.push(t),a.set(t.key,e)}let o=[];for(let t of e.sets)o.push({kind:`set`,key:t.id,tone:t.tone,status:t.status,link:t.link,line:t.line,titles:[{...t,label:t.label||t.id}],caption:``,items:a.get(t.id)||[]});let s=new Map;for(let t of e.unions){let n=t.ids.join(`|`),r=s.get(n);if(r){t.label&&r.titles.push(t);continue}let i={kind:`union`,key:n,tone:e.sets.find(e=>e.id===t.ids[0])?.tone||1,status:t.status,link:t.link,line:t.line,titles:t.label||t.icon?[t]:[],caption:t.ids.join(` ∩ `),items:a.get(n)||[]};s.set(n,i),o.push(i)}let c=new Set(o.map(e=>e.key));for(let t of e.texts)c.has(t.key)||o.push({kind:`loose`,key:t.key,tone:1,line:t.line,titles:[t],caption:t.ids.join(` ∩ `),items:[]});let d=(e,r)=>(0,n.wrapText)(e,140,r,(e,n)=>t(e,n));for(let e of o){let n=(e,t)=>e.flatMap(e=>d(e.label,t).map((n,r)=>({text:n,font:t,status:e.status,link:e.link,icon:r===0?e.icon:null})));e.header=n(e.titles,M),e.captionLines=e.caption?d(e.caption,N):[],e.itemLines=n(e.items,N);let r=[...e.header.map(e=>t(e.text,e.font)+(e.icon?18:0)),...e.captionLines.map(e=>t(e,N)),...e.itemLines.map(e=>t(e.text,e.font)+(e.icon?18:0))];e.w=Math.max(b,Math.ceil(Math.max(0,...r)+28)),e.h=28+e.header.length*l+(e.captionLines.length?4+e.captionLines.length*u:0)+(e.itemLines.length?6+e.itemLines.length*u:0)}let f=Math.max(...o.map(e=>e.w)),p=Math.max(240,r-48),m=Math.min(x,o.length);for(;m>1&&m*f+(m-1)*y>p*2;)--m;let h=Math.ceil(o.length/m),g=[];o.forEach((e,t)=>{e.column=t%m,e.row=Math.floor(t/m),g[e.row]=Math.max(g[e.row]||0,e.h)});let _=[],S=0;for(let e=0;e<h;e+=1)_[e]=S,S+=g[e]+y;o.forEach(e=>{e.w=f,e.x=e.column*(f+y),e.y=_[e.row],e.rows=[];let t=e.y+v;for(let n of e.header)e.rows.push({...n,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l;if(e.captionLines.length){t+=4;for(let n of e.captionLines)e.rows.push({text:n,font:N,x:e.x+v,y:t+u/2,anchor:`start`}),t+=u}if(e.itemLines.length){t+=6;for(let n of e.itemLines)e.rows.push({...n,x:e.x+v,y:t+u/2,anchor:`start`}),t+=u}});let C=[(0,n.warning)(`DIAGRAM_HINT`,i,e.sets[0].line,`${e.sets.length} 个集合画成圆环后重叠区无法阅读,已改用分区面板`,`${e.sets.length} sets would leave unreadable overlaps; drawn as a region grid instead`,`集合减到 3 个可获得圆环布局,或接受分区面板`,`Keep three sets for rings, or accept the region grid`)];return $({mode:`grid`,panels:o,plot:{x:0,y:0,w:m*f+(m-1)*y,h:S-y},rows:o.flatMap(e=>e.rows),shelf:[],notes:C},e,{measure:t,width:r})}function $(e,t,{measure:r,width:i}){let a=t.title?(0,n.wrapText)(t.title,Math.max(160,Math.min(i-48,480)),j,(e,t)=>r(e,t)):[],l=a.length?a.length*s+c:0,d=[],f=e.plot.x+e.plot.w,p=e.plot.y+e.plot.h;if(e.shelf.length){let t=Math.max(e.plot.w,240),n=e.plot.x,i=e.plot.y+e.plot.h+h,a=0;for(let o of e.shelf){let s=[...o.region.caption?[{text:o.region.caption,font:N,kind:`caption`}]:[],...o.rows],c=Math.max(0,...s.map(e=>Y(e,r)));n>e.plot.x&&n+c>e.plot.x+t&&(n=e.plot.x,i+=a+y/2,a=0);let l=s.map((e,t)=>({...e,anchor:`start`,x:n,y:i+(t+.5)*u}));d.push({lines:l,tone:o.region.tone,from:o.region.x==null?null:{x:o.region.x,y:o.region.y},to:{x:n+c/2,y:i-_}}),p=Math.max(p,i+s.length*u),f=Math.max(f,n+c),a=Math.max(a,s.length*u),n+=c+g}}let m=Math.max(e.plot.x+e.plot.w,f)-e.plot.x,v=Math.max(m,...a.map(e=>r(e,j))),b=o+(v-m)/2-e.plot.x,x=o+l-e.plot.y,S=Math.ceil(p-e.plot.y+l+48),C=Math.ceil(v+48);for(let t of e.rings||[])t.cx+=b,t.cy+=x;for(let t of e.panels||[])t.x+=b,t.y+=x;for(let t of e.rows)t.x+=b,t.y+=x;for(let t of e.regions||[])t.x+=b,t.y+=x;for(let e of d){for(let t of e.lines)t.x+=b,t.y+=x;e.from&&={x:e.from.x+b,y:e.from.y+x},e.to={x:e.to.x+b,y:e.to.y+x}}return{width:C,height:S,mode:e.mode,title:a.length?{lines:a,x:o+v/2,top:34}:null,rings:e.rings||[],regions:e.regions||[],panels:e.panels||[],rows:e.rows,shelf:d,notes:e.notes,anchor:{x:o+v/2,y:o+l+e.plot.h/2}}}function de(e,t={}){let r=t.measure||n.fallbackMeasure,i=Math.max(1,Number(t.width)||800),a=t.lang||`zh`;if(!e.sets.length)return{width:i,height:0,errors:[]};let o=e.sets.length<=te?le(e,{measure:r,width:i,lang:a}):ue(e,{measure:r,width:i,lang:a}),s=[...o.notes],c=e.sets.length+e.unions.length+e.texts.length;return c>A?s.push((0,n.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图有 ${c} 个元素,建议拆分`,`The Venn diagram has ${c} parts; consider splitting it`,`按集合拆成多张图`,`Split the diagram by set`)):o.width>i*2&&s.push((0,n.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图需要 ${o.width}px 宽,超过图框两倍`,`The Venn diagram needs ${o.width}px, more than twice the frame`,`加宽图框,或拆分文氏图`,`Widen the frame, or split the diagram`)),{...o,errors:s}}function fe(e,r){let i=(0,n.appearance)(r),o=r.color(`bg`),c=e=>r.frameTone(r.color(`tone${(e-1)%6+1}`)),l=(e,n)=>{let o=e.status?r.textColor(i[e.status]):e.kind===`caption`?i.fg3:e.font===M?i.fg1:i.fg2;if(n&&(0,t.contrast)(o,n)<E){let e=r.textOn(n);(0,t.contrast)(e,n)<E&&(e=(0,t.contrast)(`#000000`,n)>=E?`#000000`:`#ffffff`),o=(0,t.pushContrast)(o,e,n,E)}let s=[r.text(e.x+(e.icon?e.anchor===`middle`?9:18:0),e.y,e.text,{anchor:e.anchor,size:e.font.size,weight:e.font.weight,"dominant-baseline":`central`,fill:o})];if(e.icon){let t=e.anchor===`middle`?e.x-r.measure(e.text,e.font.size,e.font.weight)/2-3:e.x+6;s.unshift((0,a.labelIcon)(r,e.icon,t,e.y,12,o))}return e.link?r.link(e.link.href,s,e.link):r.el(`g`,{},s)},u=[];if(e.mode===`rings`){let t=e.rings.map(e=>e.status?r.frameTone(i[e.status]):c(e.tone));for(let[n,i]of e.rings.entries())u.push(r.circle(i.cx,i.cy,i.r,{fill:t[n],"fill-opacity":T}));for(let[n,i]of e.rings.entries())u.push(r.circle(i.cx,i.cy,i.r,{fill:`none`,stroke:t[n],"stroke-width":w,meta:{kind:`node`,id:i.id,label:i.id}}));for(let n of e.regions){let i=e.rings.reduce((e,i,a)=>n.ids.includes(i.id)?r.mix(e,t[a],T):e,o);for(let e of n.rows)u.push(l(e,i))}for(let t of e.shelf){t.from&&u.push(r.line(t.from.x,t.from.y,t.to.x,t.to.y,{stroke:r.tint(o,c(t.tone),.55),"stroke-width":1,"stroke-dasharray":`3 3`}));for(let e of t.lines)u.push(l(e,o))}}else for(let t of e.panels){let e=t.status?r.frameTone(i[t.status]):c(t.tone);u.push(r.rect(t.x,t.y,t.w,t.h,{rx:i.radius,fill:r.tint(o,e,t.kind===`set`?.07:.04),stroke:r.tint(o,e,.45),"stroke-width":1,...t.kind===`set`?{}:{"stroke-dasharray":`5 4`},meta:{kind:t.kind===`set`?`node`:`frame`,id:t.key,label:t.key}}));for(let e of t.rows)u.push(l(e))}return e.title&&e.title.lines.forEach((t,n)=>u.push(r.text(e.title.x,e.title.top+n*s,t,{anchor:`middle`,size:j.size,weight:j.weight,fill:i.fg1,"dominant-baseline":`central`}))),{width:e.width,height:e.height,title:e.title?e.title.lines.join(` `):void 0,children:u,anchor:e.anchor}}return e.implementations={"venn-beta":{acceptsPresentation:!0,parse:H,layout:de,scene:fe}},e})({},KChartUnits[`core/color`],KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/tree-family-icon`]);
|
package/dist/units.json
CHANGED
|
@@ -61,9 +61,10 @@
|
|
|
61
61
|
"file": "units/chart/multivariate.js",
|
|
62
62
|
"deps": [
|
|
63
63
|
"chart/registry",
|
|
64
|
-
"core/geometry"
|
|
64
|
+
"core/geometry",
|
|
65
|
+
"core/color"
|
|
65
66
|
],
|
|
66
|
-
"bytes":
|
|
67
|
+
"bytes": 28462
|
|
67
68
|
},
|
|
68
69
|
"chart/registry": {
|
|
69
70
|
"file": "units/chart/registry.js",
|
|
@@ -89,7 +90,7 @@
|
|
|
89
90
|
"deps": [
|
|
90
91
|
"chart/catalog"
|
|
91
92
|
],
|
|
92
|
-
"bytes":
|
|
93
|
+
"bytes": 40455
|
|
93
94
|
},
|
|
94
95
|
"chart/stat-compare": {
|
|
95
96
|
"file": "units/chart/stat-compare.js",
|
|
@@ -311,7 +312,7 @@
|
|
|
311
312
|
"diagram/support",
|
|
312
313
|
"diagram/map-label"
|
|
313
314
|
],
|
|
314
|
-
"bytes":
|
|
315
|
+
"bytes": 19875
|
|
315
316
|
},
|
|
316
317
|
"diagram/gantt-date": {
|
|
317
318
|
"file": "units/diagram/gantt-date.js",
|
|
@@ -505,7 +506,7 @@
|
|
|
505
506
|
"chart/basic",
|
|
506
507
|
"chart/multivariate"
|
|
507
508
|
],
|
|
508
|
-
"bytes":
|
|
509
|
+
"bytes": 13434
|
|
509
510
|
},
|
|
510
511
|
"diagram/packet": {
|
|
511
512
|
"file": "units/diagram/packet.js",
|
|
@@ -680,12 +681,13 @@
|
|
|
680
681
|
"diagram/venn": {
|
|
681
682
|
"file": "units/diagram/venn.js",
|
|
682
683
|
"deps": [
|
|
684
|
+
"core/color",
|
|
683
685
|
"diagram/support",
|
|
684
686
|
"diagram/label",
|
|
685
687
|
"diagram/presentation",
|
|
686
688
|
"diagram/tree-family-icon"
|
|
687
689
|
],
|
|
688
|
-
"bytes":
|
|
690
|
+
"bytes": 18478
|
|
689
691
|
},
|
|
690
692
|
"diagram/wardley": {
|
|
691
693
|
"file": "units/diagram/wardley.js",
|