@worm-print-platform/echarts 1.5.3 → 1.6.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/dist/units.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.3
2
+ * @worm-print-platform/echarts v1.6.0
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
package/dist/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.3
2
+ * @worm-print-platform/echarts v1.6.0
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worm-print-platform/echarts",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "description": "兼容镜像包:源码唯一真源在 marketplace/plugins/echarts(@worm-print-platform/plugin-echarts),本包由同一源码生成,保留原包名与子路径供存量依赖方零改动使用",
6
6
  "main": "./dist/index.cjs",
@@ -61,8 +61,8 @@
61
61
  "test:watch": "npm --prefix ../../marketplace/plugins/echarts run test:watch"
62
62
  },
63
63
  "dependencies": {
64
- "@worm-print-platform/core": "^1.5.3",
65
- "@worm-print-platform/plugin-kit": "^1.5.3",
64
+ "@worm-print-platform/core": "^1.6.0",
65
+ "@worm-print-platform/plugin-kit": "^1.6.0",
66
66
  "echarts": "^6.1.0"
67
67
  },
68
68
  "devDependencies": {
@@ -1,6 +0,0 @@
1
- /*!
2
- * @worm-print-platform/echarts v1.5.3
3
- * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
- * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
- * SPDX-License-Identifier: MIT
6
- */"use strict";const C=require("@worm-print-platform/core/designer"),Z=require("@worm-print-platform/core"),A=require("echarts/charts"),x=require("echarts/components"),ee=require("echarts/core"),te=require("echarts/renderers");function re(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const L=re(ee),h=["left","top","width","height","chartOption"],O=["dataSource","categoryField","valueFields","seriesField"],y=["title","legend","palette"],P=[{type:"barChart",label:"柱状图",icon:"ChartColumn",seriesType:"bar",orientation:"vertical",fields:[...O,...y,"stack"],requiredOptionKeys:h,defaultWidth:100,defaultHeight:60,notes:"柱状图:类目 + 多个数值字段,每字段一个 series;series[].data 写 $data 占位;固定高,禁止 autoHeight"},{type:"barHChart",label:"条形图",icon:"ChartBar",seriesType:"bar",orientation:"horizontal",fields:[...O,...y,"stack"],requiredOptionKeys:h,defaultWidth:100,defaultHeight:60,notes:"横向条形图:xAxis 为数值、yAxis 为类目;类目写 yAxis.data 的 $data 占位"},{type:"lineChart",label:"折线图",icon:"ChartLine",seriesType:"line",fields:[...O,...y,"stack"],requiredOptionKeys:h,defaultWidth:100,defaultHeight:60,notes:"折线图:类目 + 多个数值字段;不写 areaStyle"},{type:"areaChart",label:"面积图",icon:"ChartArea",seriesType:"line",fields:[...O,...y,"stack"],requiredOptionKeys:h,defaultWidth:100,defaultHeight:60,notes:"面积图:折线 + series[].areaStyle;其余同折线图"},{type:"pieChart",label:"饼图",icon:"ChartPie",seriesType:"pie",fields:["dataSource","categoryField","valueFields",...y],requiredOptionKeys:h,defaultWidth:60,defaultHeight:60,notes:"饼图:类目 + 首个数值字段生成 { name, value };只需一个数值字段"},{type:"doughnutChart",label:"环形图",icon:"Donut",seriesType:"pie",fields:["dataSource","categoryField","valueFields",...y,"innerRadius"],requiredOptionKeys:h,defaultWidth:60,defaultHeight:60,notes:"环形图:饼图 + radius:[内径,外径];内径由面板配置"},{type:"scatterChart",label:"散点图",icon:"ChartScatter",seriesType:"scatter",fields:["dataSource","categoryField","valueFields",...y,"bubble"],requiredOptionKeys:h,defaultWidth:80,defaultHeight:60,notes:"散点图:类目字段作 x、首个数值字段作 y;chartBubble 开启时用第二个数值字段作点大小"},{type:"radarChart",label:"雷达图",icon:"Radar",seriesType:"radar",fields:["dataSource","categoryField","valueFields",...y,"radius"],requiredOptionKeys:h,defaultWidth:70,defaultHeight:60,notes:"雷达图:每个数值字段是一个维度(radar.indicator),每行数据是一个系列(类目字段作系列名);半径由面板写 radar.radius(%,默认 75)"},{type:"funnelChart",label:"漏斗图",icon:"Funnel",seriesType:"funnel",fields:["dataSource","categoryField","valueFields",...y,"padding"],requiredOptionKeys:h,defaultWidth:60,defaultHeight:60,notes:"漏斗图:类目 + 首个数值字段,按数值降序;四边内边距由面板写 series.left/right/top/bottom(%,右侧需留外置标签空间)"},{type:"gaugeChart",label:"仪表盘",icon:"Gauge",seriesType:"gauge",fields:["dataSource","valueFields",...y,"gaugeRange"],requiredOptionKeys:h,defaultWidth:60,defaultHeight:60,notes:"仪表盘:取首行数据的首个数值字段作指针值;min/max 由面板写入 series[0].min/max"}],ae=P.map(e=>e.type);function S(e){return P.find(t=>t.type===e)}function ne(e){return S(e)?.fields??[]}function ie(e){const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0}function I(e,t){if(typeof e=="string")return e.startsWith("$data")?e:e.includes("{")?Z.evaluateTemplate(e,t):e;if(Array.isArray(e))return e.map(r=>I(r,t));if(e&&typeof e=="object"){const r={};for(const[a,n]of Object.entries(e))r[a]=I(n,t);return r}return e}function b(e){return Array.isArray(e.data)&&e.data.includes("$data")}function se(e,t){const r=e.dataSource;if(typeof r=="string"&&Array.isArray(t[r]))return t[r];for(const a of Object.values(t))if(Array.isArray(a))return a;return[]}function w(e){return typeof e=="string"&&e.length>0?e:void 0}function oe(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function _(e){return Array.isArray(e.series)?e.series:[]}function p(e,t){return t?ie(e[t]):0}function $(e,t){for(const r of["xAxis","yAxis"]){const a=e[r],n=Array.isArray(a)?a:a?[a]:[];for(const s of n)s&&typeof s=="object"&&Array.isArray(s.data)&&s.data.includes("$data")&&(s.data=[...t])}}function le(e,t,r,a,n){const s=_(e);if(!s.some(b))return;const o=t.map((c,u)=>r?c[r]:u+1),i=c=>a[Math.min(c,a.length-1)];if(n){const c=s[0],u=new Map;for(const f of t){const g=String(f[n]??""),m=u.get(g)??new Map,M=String(f[r??""]);m.set(M,(m.get(M)??0)+p(f,i(0))),u.set(g,m)}const d=[...new Set(o)];e.series=[...u.entries()].map(([f,g])=>({...c,name:f,data:d.map(m=>g.get(String(m))??null)})),$(e,d);return}const l=s[s.length-1];for(;s.length<a.length;)s.push({...l,data:["$data"]});e.series=s.map((c,u)=>b(c)?{...c,data:t.map(d=>p(d,i(u)))}:c),$(e,o)}function K(e,t,r,a,n){const s=_(e);if(!s.some(b))return;const o=t.map(i=>({name:r?String(i[r]??""):"",value:p(i,a)}));n&&o.sort((i,l)=>l.value-i.value),e.series=s.map(i=>({...i,data:o}))}function ce(e,t,r,a,n){const s=_(e);if(!s.some(b))return;const o=a[0],i=n?a[1]:void 0,l=i?t.map(f=>p(f,i)):[],c=l.length>0?Math.min(...l):0,u=l.length>0?Math.max(...l):0,d=f=>u===c?12:Math.round(6+(f-c)/(u-c)*18);e.series=s.map(f=>({...f,data:t.map(g=>{const m=[p(g,r),p(g,o)];return i?{value:m,symbolSize:d(p(g,i))}:m})}))}function ue(e){if(e<=0)return 10;const t=10**Math.floor(Math.log10(e)),r=t>=10?t:10;return Math.ceil(e/r)*r}function de(e,t,r,a){const n=_(e);if(!n.some(b))return;const s=a.map(o=>Math.max(0,...t.map(i=>p(i,o))));e.radar={...e.radar??{},indicator:a.map((o,i)=>({name:o,max:ue(s[i])}))},e.series=n.map(o=>({...o,data:t.map(i=>({name:r?String(i[r]??""):"",value:a.map(l=>p(i,l))}))}))}function fe(e,t,r){const a=_(e);if(!a.some(b))return;const n=t[0]??{};e.series=a.map(s=>({...s,data:[{value:p(n,r),name:r}]}))}function q(e,t,r){const a=t.chartOption;if(!a||typeof a!="object"||Array.isArray(a))return{};const n=I(a,r),s=oe(t.chartValueFields);if(s.length===0)return{_chartOption:n};const o=se({...t,dataSource:t.chartDataSource??t.dataSource},r);if(o.length===0)return{_chartOption:n};const i=w(t.chartCategoryField);switch(S(e)?.seriesType){case"radar":de(n,o,i,s);break;case"gauge":fe(n,o,s[0]);break;case"funnel":K(n,o,i,s[0],!0);break;case"pie":K(n,o,i,s[0],!1);break;case"scatter":ce(n,o,i,s,t.chartBubble===!0);break;default:le(n,o,i,s,w(t.chartSeriesField));break}return{_chartOption:n}}const D="@worm-print-platform/echarts",v=[{key:"default",label:"默认蓝",colors:["#5470c6","#91cc75","#fac858","#ee6666","#73c0de"]},{key:"fresh",label:"清新绿",colors:["#2f9e6e","#5cc9a7","#9ad6c1","#f2c94c","#4a90e2"]},{key:"warm",label:"暖橙红",colors:["#f2704e","#f7a35c","#f7d56d","#c54e3f","#8f5a4a"]},{key:"purple",label:"紫灰",colors:["#7b61ff","#9b8cff","#c3baff","#596275","#8d99ae"]}],G=["示例一","示例二","示例三"],B={top:6,right:25,bottom:6,left:5},W=75,he=50,ye={top:60,right:80,bottom:65,left:80},U={left:"8%",right:"8%",bottom:"12%",top:"18%",containLabel:!0};function pe(e){return{top:`${e.top}%`,right:`${e.right}%`,bottom:`${e.bottom}%`,left:`${e.left}%`}}function z(e){const t=S(e),r={text:""};switch(t?.seriesType){case"pie":return{title:r,tooltip:{trigger:"item"},series:[{type:"pie",name:"数量",data:["$data"],radius:e==="doughnutChart"?["40%","70%"]:"62%"}]};case"scatter":return{title:r,grid:U,tooltip:{trigger:"axis"},xAxis:{type:"value"},yAxis:{type:"value"},series:[{type:"scatter",name:"数量",data:["$data"],symbolSize:8}]};case"radar":return{title:r,tooltip:{trigger:"item"},radar:{indicator:[],radius:`${W}%`},series:[{type:"radar",name:"数量",data:["$data"]}]};case"funnel":return{title:r,tooltip:{trigger:"item"},legend:{show:!1},series:[{type:"funnel",name:"数量",data:["$data"],sort:"descending",...pe(B)}]};case"gauge":return{title:r,tooltip:{trigger:"item"},series:[{type:"gauge",name:"数量",min:0,max:100,data:[{value:0,name:"数量"}]}]};default:{const a=t?.orientation==="horizontal",n=t?.seriesType==="line"&&e==="areaChart",s=t?.seriesType==="line"?"line":"bar";return{title:r,grid:U,tooltip:{trigger:"axis"},xAxis:a?{type:"value"}:{type:"category",data:["$data"]},yAxis:a?{type:"category",data:["$data"]}:{type:"value"},series:[{type:s,name:"数量",data:["$data"],...n?{areaStyle:{}}:{}}]}}}}function ge(e){C.configurePlugin(D,e)}function E(){return C.getPluginConfig(D)}function me(){const e=E().palettes??{},t=v.map(a=>{const n=e[a.key];return n?{key:a.key,label:n.label??a.label,colors:n.colors}:{key:a.key,label:a.label,colors:a.colors}}),r=Object.entries(e).filter(([a])=>!v.some(n=>n.key===a)).map(([a,n])=>({key:a,label:n.label??a,colors:n.colors}));return[...t,...r]}function Ae(){const e=E().sampleCategories;return Array.isArray(e)&&e.length>0?e:G}function V(e,t){const r=E(),a=S(e);return{width:typeof r.defaultWidth=="number"?r.defaultWidth:a?.defaultWidth??100,height:typeof r.defaultHeight=="number"?r.defaultHeight:a?.defaultHeight??60,title:a?.label??"图表",chartOption:z(e),chartDataSource:"",chartCategoryField:"name",chartValueFields:["value"],chartSeriesField:"",...t}}L.use([A.BarChart,A.LineChart,A.PieChart,A.ScatterChart,A.RadarChart,A.FunnelChart,A.GaugeChart,x.GridComponent,x.TooltipComponent,x.LegendComponent,x.TitleComponent,x.DatasetComponent,te.SVGRenderer]);const j=new Set;function Ce(){const t=(E().components??[]).filter(r=>r!=null&&!j.has(r));if(t.length!==0){L.use(t);for(const r of t)j.add(r)}}function be(e){return Array.isArray(e)?e.map(t=>({...t})):[]}function Se(e,t){const r={...e,type:t?"value":"category"};return t?delete r.data:Array.isArray(r.data)||(r.data=["$data"]),r}function xe(e,t){const r={...e,type:t?"category":"value"};return t&&!Array.isArray(r.data)&&(r.data=["$data"]),t||delete r.data,r}function F(e,t){return Array.isArray(e)?e.map(r=>t({...r})):t(e&&typeof e=="object"?{...e}:{})}function X(e,t){const r=S(e);if(!r)return t;const a=structuredClone(t),n=be(a.series);if(n.length===0)return a;if(r.seriesType==="pie")return a.series=n.map(i=>({...i,type:"pie",...e==="doughnutChart"?{radius:i.radius??["40%","70%"]}:{}})),delete a.xAxis,delete a.yAxis,a;if(r.seriesType==="scatter")return a.series=n.map(i=>({...i,type:"scatter"})),a.xAxis=F(a.xAxis,i=>({...i,type:"value",data:void 0})),a.yAxis=F(a.yAxis,i=>({...i,type:"value",data:void 0})),a;if(r.seriesType==="radar")return a.series=n.map(i=>({...i,type:"radar"})),a;if(r.seriesType==="funnel")return a.series=n.map(i=>({...i,type:"funnel",sort:"descending"})),a;if(r.seriesType==="gauge")return a.series=n.map(i=>({...i,type:"gauge"})),a;const s=r.orientation==="horizontal",o=r.seriesType==="line"?"line":"bar";return a.xAxis=F(a.xAxis,i=>Se(i,s)),a.yAxis=F(a.yAxis,i=>xe(i,s)),a.series=n.map(i=>{const l={...i,type:o};return e==="areaChart"?l.areaStyle=i.areaStyle??{}:delete l.areaStyle,l}),a}const Te=96/25.4;function H(e){const t=Number.isFinite(e)?e:0;return Math.max(1,Math.round(t*Te))}function Q(e,t,r){const a=/<svg\b[^>]*>/i.exec(e);if(!a)return e;const n=a[0],s=n.slice(4,-1),i=(/\sstyle\s*=\s*"([^"]*)"/i.exec(s)?.[1]??"").split(";").map(d=>d.trim()).filter(d=>d&&!/^(width|height|display)\s*:/i.test(d)).join(";"),l=s.replace(/\s(width|height|style|viewBox)\s*=\s*"[^"]*"/gi,"").trimEnd(),c=["display:block","width:100%","height:100%",i].filter(Boolean).join(";"),u=`<svg${l} width="100%" height="100%" viewBox="0 0 ${t} ${r}" style="${c}">`;return e.slice(0,a.index)+u+e.slice(a.index+n.length)}function Y(e){Ce();const t=X(e.type,e.option);if(!t||typeof t!="object"||Array.isArray(t))throw new Error("图表 option 非法:需要对象");const r=H(e.widthMm),a=H(e.heightMm),n=L.init(null,null,{renderer:"svg",ssr:!0,width:r,height:a});try{const s=t.textStyle&&typeof t.textStyle=="object"&&!Array.isArray(t.textStyle)?t.textStyle:void 0,o={...e.fontFamily?{fontFamily:e.fontFamily}:{},...s??{}};return n.setOption({animation:!1,...t,...Object.keys(o).length>0?{textStyle:o}:{}}),Q(n.renderToSVGString(),r,a)}finally{n.dispose()}}function _e(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function N(e){const t=e._chartOption??e.chartOption,r=`<span>${_e(String(e.title??"图表"))}</span>`;if(!t||typeof t!="object"||Array.isArray(t))return r;try{return Y({key:String(e.key??""),type:String(e.type??""),option:t,widthMm:Number(e.widthMm??0),heightMm:Number(e.heightMm??0),fontFamily:typeof e.fontFamily=="string"?e.fontFamily:void 0})}catch{return r}}const De="2",J={chartOption:{kind:"object",label:"图表 option"},chartDataSource:{kind:"text",label:"数据源"},chartCategoryField:{kind:"text",label:"类目字段"},chartValueFields:{kind:"object",label:"数值字段"},chartSeriesField:{kind:"text",label:"系列拆分字段"}},Ee={...J,chartBubble:{kind:"bool",label:"气泡大小"}},T=C.defineElementPlugin({id:D,version:De,kinds:P.map(e=>({type:e.type,label:e.label,icon:e.icon,fixedHeight:!0,requiredOptionKeys:e.requiredOptionKeys,notes:e.notes,optionMeta:e.type==="scatterChart"?Ee:J,defaultOptions:t=>V(e.type,t),binding:{bind:(t,r)=>q(e.type,t,r)}})),render:{html:N,createRenderer:()=>({render:N})}});let R;function k(e,t){const r=C.getElementPluginById(D);if(!e&&!t){const s=C.registerElementPlugin(T);return R=s,s}const a={...T,designer:e??r?.designer??T.designer,render:{...T.render,...r?.render,...t}},n=C.registerElementPlugin(a);return R=n,n}function Oe(e){return k(e)}function Fe(e){return k(void 0,{executorBundle:e})}function Re(){R?.(),R=void 0}k();exports.CHART_KINDS=ae;exports.CHART_KIND_DEFINITIONS=P;exports.CHART_PALETTES=v;exports.CHART_PLUGIN=T;exports.CHART_PLUGIN_ID=D;exports.ECHARTS_FUNNEL_PADDING_PX=ye;exports.ECHARTS_RADAR_RADIUS_DEFAULT=he;exports.FALLBACK_SAMPLE_CATEGORIES=G;exports.FUNNEL_PADDING_DEFAULTS=B;exports.RADAR_RADIUS_DEFAULT=W;exports.bindChartData=q;exports.chartFactoryDefaults=V;exports.configureChartPlugin=ge;exports.createDefaultChartOption=z;exports.fitSvgRoot=Q;exports.getChartKindDefinition=S;exports.getChartPalettes=me;exports.getChartPluginConfig=E;exports.getSampleCategories=Ae;exports.mmToChartPx=H;exports.normalizeChartOption=X;exports.registerChartDesigner=Oe;exports.registerChartExecutorBundle=Fe;exports.registerChartPlugin=k;exports.renderChartElement=N;exports.renderChartToSvg=Y;exports.resolveChartPanelFields=ne;exports.uninstallChartPlugin=Re;
@@ -1,573 +0,0 @@
1
- /*!
2
- * @worm-print-platform/echarts v1.5.3
3
- * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
- * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
- * SPDX-License-Identifier: MIT
6
- */import { getPluginConfig as q, configurePlugin as W, defineElementPlugin as B, getElementPluginById as G, registerElementPlugin as M } from "@worm-print-platform/core/designer";
7
- import { evaluateTemplate as U } from "@worm-print-platform/core";
8
- import { BarChart as z, LineChart as V, PieChart as X, ScatterChart as Q, RadarChart as Y, FunnelChart as J, GaugeChart as Z } from "echarts/charts";
9
- import { GridComponent as ee, TooltipComponent as te, LegendComponent as re, TitleComponent as ae, DatasetComponent as ie } from "echarts/components";
10
- import * as _ from "echarts/core";
11
- import { SVGRenderer as ne } from "echarts/renderers";
12
- const y = ["left", "top", "width", "height", "chartOption"], x = ["dataSource", "categoryField", "valueFields", "seriesField"], p = ["title", "legend", "palette"], v = [
13
- {
14
- type: "barChart",
15
- label: "柱状图",
16
- icon: "ChartColumn",
17
- seriesType: "bar",
18
- orientation: "vertical",
19
- fields: [...x, ...p, "stack"],
20
- requiredOptionKeys: y,
21
- defaultWidth: 100,
22
- defaultHeight: 60,
23
- notes: "柱状图:类目 + 多个数值字段,每字段一个 series;series[].data 写 $data 占位;固定高,禁止 autoHeight"
24
- },
25
- {
26
- type: "barHChart",
27
- label: "条形图",
28
- icon: "ChartBar",
29
- seriesType: "bar",
30
- orientation: "horizontal",
31
- fields: [...x, ...p, "stack"],
32
- requiredOptionKeys: y,
33
- defaultWidth: 100,
34
- defaultHeight: 60,
35
- notes: "横向条形图:xAxis 为数值、yAxis 为类目;类目写 yAxis.data 的 $data 占位"
36
- },
37
- {
38
- type: "lineChart",
39
- label: "折线图",
40
- icon: "ChartLine",
41
- seriesType: "line",
42
- fields: [...x, ...p, "stack"],
43
- requiredOptionKeys: y,
44
- defaultWidth: 100,
45
- defaultHeight: 60,
46
- notes: "折线图:类目 + 多个数值字段;不写 areaStyle"
47
- },
48
- {
49
- type: "areaChart",
50
- label: "面积图",
51
- icon: "ChartArea",
52
- seriesType: "line",
53
- fields: [...x, ...p, "stack"],
54
- requiredOptionKeys: y,
55
- defaultWidth: 100,
56
- defaultHeight: 60,
57
- notes: "面积图:折线 + series[].areaStyle;其余同折线图"
58
- },
59
- {
60
- type: "pieChart",
61
- label: "饼图",
62
- icon: "ChartPie",
63
- seriesType: "pie",
64
- fields: ["dataSource", "categoryField", "valueFields", ...p],
65
- requiredOptionKeys: y,
66
- defaultWidth: 60,
67
- defaultHeight: 60,
68
- notes: "饼图:类目 + 首个数值字段生成 { name, value };只需一个数值字段"
69
- },
70
- {
71
- type: "doughnutChart",
72
- label: "环形图",
73
- icon: "Donut",
74
- seriesType: "pie",
75
- fields: ["dataSource", "categoryField", "valueFields", ...p, "innerRadius"],
76
- requiredOptionKeys: y,
77
- defaultWidth: 60,
78
- defaultHeight: 60,
79
- notes: "环形图:饼图 + radius:[内径,外径];内径由面板配置"
80
- },
81
- {
82
- type: "scatterChart",
83
- label: "散点图",
84
- icon: "ChartScatter",
85
- seriesType: "scatter",
86
- fields: ["dataSource", "categoryField", "valueFields", ...p, "bubble"],
87
- requiredOptionKeys: y,
88
- defaultWidth: 80,
89
- defaultHeight: 60,
90
- notes: "散点图:类目字段作 x、首个数值字段作 y;chartBubble 开启时用第二个数值字段作点大小"
91
- },
92
- {
93
- type: "radarChart",
94
- label: "雷达图",
95
- icon: "Radar",
96
- seriesType: "radar",
97
- fields: ["dataSource", "categoryField", "valueFields", ...p, "radius"],
98
- requiredOptionKeys: y,
99
- defaultWidth: 70,
100
- defaultHeight: 60,
101
- notes: "雷达图:每个数值字段是一个维度(radar.indicator),每行数据是一个系列(类目字段作系列名);半径由面板写 radar.radius(%,默认 75)"
102
- },
103
- {
104
- type: "funnelChart",
105
- label: "漏斗图",
106
- icon: "Funnel",
107
- seriesType: "funnel",
108
- fields: ["dataSource", "categoryField", "valueFields", ...p, "padding"],
109
- requiredOptionKeys: y,
110
- defaultWidth: 60,
111
- defaultHeight: 60,
112
- notes: "漏斗图:类目 + 首个数值字段,按数值降序;四边内边距由面板写 series.left/right/top/bottom(%,右侧需留外置标签空间)"
113
- },
114
- {
115
- type: "gaugeChart",
116
- label: "仪表盘",
117
- icon: "Gauge",
118
- seriesType: "gauge",
119
- fields: ["dataSource", "valueFields", ...p, "gaugeRange"],
120
- requiredOptionKeys: y,
121
- defaultWidth: 60,
122
- defaultHeight: 60,
123
- notes: "仪表盘:取首行数据的首个数值字段作指针值;min/max 由面板写入 series[0].min/max"
124
- }
125
- ], Ie = v.map((e) => e.type);
126
- function A(e) {
127
- return v.find((t) => t.type === e);
128
- }
129
- function Le(e) {
130
- return A(e)?.fields ?? [];
131
- }
132
- function se(e) {
133
- const t = typeof e == "number" ? e : Number(e);
134
- return Number.isFinite(t) ? t : 0;
135
- }
136
- function E(e, t) {
137
- if (typeof e == "string")
138
- return e.startsWith("$data") ? e : e.includes("{") ? U(e, t) : e;
139
- if (Array.isArray(e)) return e.map((r) => E(r, t));
140
- if (e && typeof e == "object") {
141
- const r = {};
142
- for (const [a, i] of Object.entries(e))
143
- r[a] = E(i, t);
144
- return r;
145
- }
146
- return e;
147
- }
148
- function b(e) {
149
- return Array.isArray(e.data) && e.data.includes("$data");
150
- }
151
- function oe(e, t) {
152
- const r = e.dataSource;
153
- if (typeof r == "string" && Array.isArray(t[r])) return t[r];
154
- for (const a of Object.values(t))
155
- if (Array.isArray(a)) return a;
156
- return [];
157
- }
158
- function H(e) {
159
- return typeof e == "string" && e.length > 0 ? e : void 0;
160
- }
161
- function le(e) {
162
- return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.length > 0) : [];
163
- }
164
- function C(e) {
165
- return Array.isArray(e.series) ? e.series : [];
166
- }
167
- function h(e, t) {
168
- return t ? se(e[t]) : 0;
169
- }
170
- function P(e, t) {
171
- for (const r of ["xAxis", "yAxis"]) {
172
- const a = e[r], i = Array.isArray(a) ? a : a ? [a] : [];
173
- for (const s of i)
174
- s && typeof s == "object" && Array.isArray(s.data) && s.data.includes("$data") && (s.data = [...t]);
175
- }
176
- }
177
- function ce(e, t, r, a, i) {
178
- const s = C(e);
179
- if (!s.some(b)) return;
180
- const o = t.map((c, u) => r ? c[r] : u + 1), n = (c) => a[Math.min(c, a.length - 1)];
181
- if (i) {
182
- const c = s[0], u = /* @__PURE__ */ new Map();
183
- for (const f of t) {
184
- const g = String(f[i] ?? ""), m = u.get(g) ?? /* @__PURE__ */ new Map(), R = String(f[r ?? ""]);
185
- m.set(R, (m.get(R) ?? 0) + h(f, n(0))), u.set(g, m);
186
- }
187
- const d = [...new Set(o)];
188
- e.series = [...u.entries()].map(([f, g]) => ({
189
- ...c,
190
- name: f,
191
- data: d.map((m) => g.get(String(m)) ?? null)
192
- })), P(e, d);
193
- return;
194
- }
195
- const l = s[s.length - 1];
196
- for (; s.length < a.length; ) s.push({ ...l, data: ["$data"] });
197
- e.series = s.map((c, u) => b(c) ? { ...c, data: t.map((d) => h(d, n(u))) } : c), P(e, o);
198
- }
199
- function $(e, t, r, a, i) {
200
- const s = C(e);
201
- if (!s.some(b)) return;
202
- const o = t.map((n) => ({
203
- name: r ? String(n[r] ?? "") : "",
204
- value: h(n, a)
205
- }));
206
- i && o.sort((n, l) => l.value - n.value), e.series = s.map((n) => ({ ...n, data: o }));
207
- }
208
- function ue(e, t, r, a, i) {
209
- const s = C(e);
210
- if (!s.some(b)) return;
211
- const o = a[0], n = i ? a[1] : void 0, l = n ? t.map((f) => h(f, n)) : [], c = l.length > 0 ? Math.min(...l) : 0, u = l.length > 0 ? Math.max(...l) : 0, d = (f) => u === c ? 12 : Math.round(6 + (f - c) / (u - c) * 18);
212
- e.series = s.map((f) => ({
213
- ...f,
214
- data: t.map((g) => {
215
- const m = [h(g, r), h(g, o)];
216
- return n ? { value: m, symbolSize: d(h(g, n)) } : m;
217
- })
218
- }));
219
- }
220
- function de(e) {
221
- if (e <= 0) return 10;
222
- const t = 10 ** Math.floor(Math.log10(e)), r = t >= 10 ? t : 10;
223
- return Math.ceil(e / r) * r;
224
- }
225
- function fe(e, t, r, a) {
226
- const i = C(e);
227
- if (!i.some(b)) return;
228
- const s = a.map((o) => Math.max(0, ...t.map((n) => h(n, o))));
229
- e.radar = {
230
- ...e.radar ?? {},
231
- // 维度 = 数值字段;max 取该列最大值上浮取整
232
- indicator: a.map((o, n) => ({ name: o, max: de(s[n]) }))
233
- }, e.series = i.map((o) => ({
234
- ...o,
235
- data: t.map((n) => ({
236
- name: r ? String(n[r] ?? "") : "",
237
- value: a.map((l) => h(n, l))
238
- }))
239
- }));
240
- }
241
- function ye(e, t, r) {
242
- const a = C(e);
243
- if (!a.some(b)) return;
244
- const i = t[0] ?? {};
245
- e.series = a.map((s) => ({ ...s, data: [{ value: h(i, r), name: r }] }));
246
- }
247
- function pe(e, t, r) {
248
- const a = t.chartOption;
249
- if (!a || typeof a != "object" || Array.isArray(a)) return {};
250
- const i = E(a, r), s = le(t.chartValueFields);
251
- if (s.length === 0) return { _chartOption: i };
252
- const o = oe({ ...t, dataSource: t.chartDataSource ?? t.dataSource }, r);
253
- if (o.length === 0) return { _chartOption: i };
254
- const n = H(t.chartCategoryField);
255
- switch (A(e)?.seriesType) {
256
- case "radar":
257
- fe(i, o, n, s);
258
- break;
259
- case "gauge":
260
- ye(i, o, s[0]);
261
- break;
262
- case "funnel":
263
- $(i, o, n, s[0], !0);
264
- break;
265
- case "pie":
266
- $(i, o, n, s[0], !1);
267
- break;
268
- case "scatter":
269
- ue(i, o, n, s, t.chartBubble === !0);
270
- break;
271
- default:
272
- ce(i, o, n, s, H(t.chartSeriesField));
273
- break;
274
- }
275
- return { _chartOption: i };
276
- }
277
- const F = "@worm-print-platform/echarts", w = [
278
- { key: "default", label: "默认蓝", colors: ["#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de"] },
279
- { key: "fresh", label: "清新绿", colors: ["#2f9e6e", "#5cc9a7", "#9ad6c1", "#f2c94c", "#4a90e2"] },
280
- { key: "warm", label: "暖橙红", colors: ["#f2704e", "#f7a35c", "#f7d56d", "#c54e3f", "#8f5a4a"] },
281
- { key: "purple", label: "紫灰", colors: ["#7b61ff", "#9b8cff", "#c3baff", "#596275", "#8d99ae"] }
282
- ], he = ["示例一", "示例二", "示例三"], ge = { top: 6, right: 25, bottom: 6, left: 5 }, me = 75, Ne = 50, je = { top: 60, right: 80, bottom: 65, left: 80 }, I = { left: "8%", right: "8%", bottom: "12%", top: "18%", containLabel: !0 };
283
- function be(e) {
284
- return {
285
- top: `${e.top}%`,
286
- right: `${e.right}%`,
287
- bottom: `${e.bottom}%`,
288
- left: `${e.left}%`
289
- };
290
- }
291
- function Ae(e) {
292
- const t = A(e), r = { text: "" };
293
- switch (t?.seriesType) {
294
- case "pie":
295
- return {
296
- title: r,
297
- tooltip: { trigger: "item" },
298
- series: [{
299
- type: "pie",
300
- name: "数量",
301
- data: ["$data"],
302
- radius: e === "doughnutChart" ? ["40%", "70%"] : "62%"
303
- }]
304
- };
305
- case "scatter":
306
- return {
307
- title: r,
308
- grid: I,
309
- tooltip: { trigger: "axis" },
310
- xAxis: { type: "value" },
311
- yAxis: { type: "value" },
312
- series: [{ type: "scatter", name: "数量", data: ["$data"], symbolSize: 8 }]
313
- };
314
- case "radar":
315
- return {
316
- title: r,
317
- tooltip: { trigger: "item" },
318
- // indicator 由绑定阶段按 chartValueFields 生成;设计态预览见 previewChartOption
319
- radar: { indicator: [], radius: `${me}%` },
320
- series: [{ type: "radar", name: "数量", data: ["$data"] }]
321
- };
322
- case "funnel":
323
- return {
324
- title: r,
325
- tooltip: { trigger: "item" },
326
- legend: { show: !1 },
327
- // 不写内边距会吃 ECharts 的 px 默认(左右 80/上下 60~65),小框里图形只占一半不到
328
- series: [{ type: "funnel", name: "数量", data: ["$data"], sort: "descending", ...be(ge) }]
329
- };
330
- case "gauge":
331
- return {
332
- title: r,
333
- tooltip: { trigger: "item" },
334
- series: [{ type: "gauge", name: "数量", min: 0, max: 100, data: [{ value: 0, name: "数量" }] }]
335
- };
336
- default: {
337
- const a = t?.orientation === "horizontal", i = t?.seriesType === "line" && e === "areaChart", s = t?.seriesType === "line" ? "line" : "bar";
338
- return {
339
- title: r,
340
- grid: I,
341
- tooltip: { trigger: "axis" },
342
- xAxis: a ? { type: "value" } : { type: "category", data: ["$data"] },
343
- yAxis: a ? { type: "category", data: ["$data"] } : { type: "value" },
344
- series: [{ type: s, name: "数量", data: ["$data"], ...i ? { areaStyle: {} } : {} }]
345
- };
346
- }
347
- }
348
- }
349
- function Ke(e) {
350
- W(F, e);
351
- }
352
- function k() {
353
- return q(F);
354
- }
355
- function qe() {
356
- const e = k().palettes ?? {}, t = w.map((a) => {
357
- const i = e[a.key];
358
- return i ? { key: a.key, label: i.label ?? a.label, colors: i.colors } : { key: a.key, label: a.label, colors: a.colors };
359
- }), r = Object.entries(e).filter(([a]) => !w.some((i) => i.key === a)).map(([a, i]) => ({ key: a, label: i.label ?? a, colors: i.colors }));
360
- return [...t, ...r];
361
- }
362
- function We() {
363
- const e = k().sampleCategories;
364
- return Array.isArray(e) && e.length > 0 ? e : he;
365
- }
366
- function Ce(e, t) {
367
- const r = k(), a = A(e);
368
- return {
369
- width: typeof r.defaultWidth == "number" ? r.defaultWidth : a?.defaultWidth ?? 100,
370
- height: typeof r.defaultHeight == "number" ? r.defaultHeight : a?.defaultHeight ?? 60,
371
- title: a?.label ?? "图表",
372
- chartOption: Ae(e),
373
- chartDataSource: "",
374
- chartCategoryField: "name",
375
- chartValueFields: ["value"],
376
- chartSeriesField: "",
377
- ...t
378
- };
379
- }
380
- _.use([
381
- z,
382
- V,
383
- X,
384
- Q,
385
- Y,
386
- J,
387
- Z,
388
- ee,
389
- te,
390
- re,
391
- ae,
392
- ie,
393
- ne
394
- ]);
395
- const L = /* @__PURE__ */ new Set();
396
- function xe() {
397
- const t = (k().components ?? []).filter((r) => r != null && !L.has(r));
398
- if (t.length !== 0) {
399
- _.use(t);
400
- for (const r of t) L.add(r);
401
- }
402
- }
403
- function Se(e) {
404
- return Array.isArray(e) ? e.map((t) => ({ ...t })) : [];
405
- }
406
- function Te(e, t) {
407
- const r = { ...e, type: t ? "value" : "category" };
408
- return t ? delete r.data : Array.isArray(r.data) || (r.data = ["$data"]), r;
409
- }
410
- function Oe(e, t) {
411
- const r = { ...e, type: t ? "category" : "value" };
412
- return t && !Array.isArray(r.data) && (r.data = ["$data"]), t || delete r.data, r;
413
- }
414
- function S(e, t) {
415
- return Array.isArray(e) ? e.map((r) => t({ ...r })) : t(e && typeof e == "object" ? { ...e } : {});
416
- }
417
- function Fe(e, t) {
418
- const r = A(e);
419
- if (!r) return t;
420
- const a = structuredClone(t), i = Se(a.series);
421
- if (i.length === 0) return a;
422
- if (r.seriesType === "pie")
423
- return a.series = i.map((n) => ({
424
- ...n,
425
- type: "pie",
426
- ...e === "doughnutChart" ? { radius: n.radius ?? ["40%", "70%"] } : {}
427
- })), delete a.xAxis, delete a.yAxis, a;
428
- if (r.seriesType === "scatter")
429
- return a.series = i.map((n) => ({ ...n, type: "scatter" })), a.xAxis = S(a.xAxis, (n) => ({ ...n, type: "value", data: void 0 })), a.yAxis = S(a.yAxis, (n) => ({ ...n, type: "value", data: void 0 })), a;
430
- if (r.seriesType === "radar")
431
- return a.series = i.map((n) => ({ ...n, type: "radar" })), a;
432
- if (r.seriesType === "funnel")
433
- return a.series = i.map((n) => ({ ...n, type: "funnel", sort: "descending" })), a;
434
- if (r.seriesType === "gauge")
435
- return a.series = i.map((n) => ({ ...n, type: "gauge" })), a;
436
- const s = r.orientation === "horizontal", o = r.seriesType === "line" ? "line" : "bar";
437
- return a.xAxis = S(a.xAxis, (n) => Te(n, s)), a.yAxis = S(a.yAxis, (n) => Oe(n, s)), a.series = i.map((n) => {
438
- const l = { ...n, type: o };
439
- return e === "areaChart" ? l.areaStyle = n.areaStyle ?? {} : delete l.areaStyle, l;
440
- }), a;
441
- }
442
- const ke = 96 / 25.4;
443
- function N(e) {
444
- const t = Number.isFinite(e) ? e : 0;
445
- return Math.max(1, Math.round(t * ke));
446
- }
447
- function Ee(e, t, r) {
448
- const a = /<svg\b[^>]*>/i.exec(e);
449
- if (!a) return e;
450
- const i = a[0], s = i.slice(4, -1), n = (/\sstyle\s*=\s*"([^"]*)"/i.exec(s)?.[1] ?? "").split(";").map((d) => d.trim()).filter((d) => d && !/^(width|height|display)\s*:/i.test(d)).join(";"), l = s.replace(/\s(width|height|style|viewBox)\s*=\s*"[^"]*"/gi, "").trimEnd(), c = ["display:block", "width:100%", "height:100%", n].filter(Boolean).join(";"), u = `<svg${l} width="100%" height="100%" viewBox="0 0 ${t} ${r}" style="${c}">`;
451
- return e.slice(0, a.index) + u + e.slice(a.index + i.length);
452
- }
453
- function _e(e) {
454
- xe();
455
- const t = Fe(e.type, e.option);
456
- if (!t || typeof t != "object" || Array.isArray(t))
457
- throw new Error("图表 option 非法:需要对象");
458
- const r = N(e.widthMm), a = N(e.heightMm), i = _.init(null, null, { renderer: "svg", ssr: !0, width: r, height: a });
459
- try {
460
- const s = t.textStyle && typeof t.textStyle == "object" && !Array.isArray(t.textStyle) ? t.textStyle : void 0, o = {
461
- ...e.fontFamily ? { fontFamily: e.fontFamily } : {},
462
- ...s ?? {}
463
- };
464
- return i.setOption({
465
- animation: !1,
466
- ...t,
467
- ...Object.keys(o).length > 0 ? { textStyle: o } : {}
468
- }), Ee(i.renderToSVGString(), r, a);
469
- } finally {
470
- i.dispose();
471
- }
472
- }
473
- function ve(e) {
474
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
475
- }
476
- function j(e) {
477
- const t = e._chartOption ?? e.chartOption, r = `<span>${ve(String(e.title ?? "图表"))}</span>`;
478
- if (!t || typeof t != "object" || Array.isArray(t)) return r;
479
- try {
480
- return _e({
481
- key: String(e.key ?? ""),
482
- type: String(e.type ?? ""),
483
- option: t,
484
- widthMm: Number(e.widthMm ?? 0),
485
- heightMm: Number(e.heightMm ?? 0),
486
- fontFamily: typeof e.fontFamily == "string" ? e.fontFamily : void 0
487
- });
488
- } catch {
489
- return r;
490
- }
491
- }
492
- const De = "2", K = {
493
- chartOption: { kind: "object", label: "图表 option" },
494
- chartDataSource: { kind: "text", label: "数据源" },
495
- chartCategoryField: { kind: "text", label: "类目字段" },
496
- chartValueFields: { kind: "object", label: "数值字段" },
497
- chartSeriesField: { kind: "text", label: "系列拆分字段" }
498
- }, Re = {
499
- ...K,
500
- chartBubble: { kind: "bool", label: "气泡大小" }
501
- }, T = B({
502
- id: F,
503
- version: De,
504
- kinds: v.map((e) => ({
505
- type: e.type,
506
- label: e.label,
507
- icon: e.icon,
508
- fixedHeight: !0,
509
- requiredOptionKeys: e.requiredOptionKeys,
510
- notes: e.notes,
511
- optionMeta: e.type === "scatterChart" ? Re : K,
512
- defaultOptions: (t) => Ce(e.type, t),
513
- binding: { bind: (t, r) => pe(e.type, t, r) }
514
- })),
515
- render: {
516
- html: j,
517
- createRenderer: () => ({ render: j })
518
- }
519
- });
520
- let O;
521
- function D(e, t) {
522
- const r = G(F);
523
- if (!e && !t) {
524
- const s = M(T);
525
- return O = s, s;
526
- }
527
- const a = {
528
- ...T,
529
- designer: e ?? r?.designer ?? T.designer,
530
- render: { ...T.render, ...r?.render, ...t }
531
- }, i = M(a);
532
- return O = i, i;
533
- }
534
- function Be(e) {
535
- return D(e);
536
- }
537
- function Ge(e) {
538
- return D(void 0, { executorBundle: e });
539
- }
540
- function Ue() {
541
- O?.(), O = void 0;
542
- }
543
- D();
544
- export {
545
- Ie as C,
546
- je as E,
547
- he as F,
548
- me as R,
549
- v as a,
550
- w as b,
551
- T as c,
552
- F as d,
553
- pe as e,
554
- Ce as f,
555
- Ke as g,
556
- Ae as h,
557
- Ee as i,
558
- A as j,
559
- qe as k,
560
- k as l,
561
- We as m,
562
- N as n,
563
- Fe as o,
564
- Be as p,
565
- Ge as q,
566
- D as r,
567
- j as s,
568
- _e as t,
569
- Le as u,
570
- Ue as v,
571
- Ne as w,
572
- ge as x
573
- };