dsh-ppt 0.27.2 → 0.29.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.en.md +23 -22
  3. package/README.md +23 -22
  4. package/docs/USAGE.en.md +2 -0
  5. package/docs/USAGE.md +2 -0
  6. package/docs/VALIDATION.md +8 -0
  7. package/docs/assets/intro/workflow-en-dark.svg +1 -1
  8. package/docs/assets/intro/workflow-en-light.svg +1 -1
  9. package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -1
  10. package/docs/assets/intro/workflow-en-mobile-light.svg +1 -1
  11. package/docs/assets/intro/workflow-zh-dark.svg +1 -1
  12. package/docs/assets/intro/workflow-zh-light.svg +1 -1
  13. package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -1
  14. package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -1
  15. package/lib/client.js +283 -33
  16. package/lib/execution.d.ts +7 -0
  17. package/lib/execution.js +47 -6
  18. package/lib/tools.js +62 -12
  19. package/lib/types.d.ts +51 -4
  20. package/lib/workbench.js +185 -9
  21. package/package.json +1 -1
  22. package/skills/dsh-ppt/SKILL.md +4 -2
  23. package/skills/dsh-ppt/package.json +1 -1
  24. package/skills/dsh-ppt/references/exemplars.md +116 -0
  25. package/skills/dsh-ppt/scripts/build-deck.mjs +20 -1
  26. package/skills/dsh-ppt/scripts/deck-absorb.mjs +27 -3
  27. package/skills/dsh-ppt/scripts/deck-advanced.mjs +107 -24
  28. package/skills/dsh-ppt/scripts/deck-charts-pro.mjs +1004 -0
  29. package/skills/dsh-ppt/scripts/deck-chrome.mjs +27 -6
  30. package/skills/dsh-ppt/scripts/deck-core.mjs +96 -3
  31. package/skills/dsh-ppt/scripts/deck-covers.mjs +157 -3
  32. package/skills/dsh-ppt/scripts/deck-exemplars.mjs +548 -0
  33. package/skills/dsh-ppt/scripts/deck-layouts.mjs +90 -2
  34. package/skills/dsh-ppt/scripts/deck-showcase.mjs +729 -0
  35. package/skills/dsh-ppt/scripts/deck-upgrader.mjs +618 -0
@@ -0,0 +1,1004 @@
1
+ /**
2
+ * deck-charts-pro.mjs —— dsh-ppt 四大顶级商业分析与咨询矢量图表引擎(零外部依赖)。
3
+ *
4
+ * 100% 原生可编辑 PowerPoint DrawingML(<p:sp> / <p:cxnSp> / <a:custGeom>)+ HTML SVG 双端同构:
5
+ * 1. quadrant(魔力象限 / 波士顿 BCG 气泡矩阵):十字象限线、象限角标、面积比例气泡与防出界标签
6
+ * 2. radar(多维能力雷达图):4 层同心正多边形蛛网、辐条轴标、半透明多系列叠加多边形与顶点锚点
7
+ * 3. dumbbell(麦肯锡哑铃对比图 / Before→After):统一数轴、方向连接桥、外侧防撞直标值与右侧增减徽章
8
+ * 4. heatmap(热力图矩阵):顺序/发散色阶自动插值、WCAG 相对亮度自动反白字色与连续色带图例
9
+ */
10
+
11
+ import { relativeLuminance, mixHex } from './deck-themes.mjs'
12
+ import {
13
+ roundRectAdj,
14
+ escapeXml,
15
+ escapeHtml,
16
+ stripInlineMarkdown,
17
+ ooxmlRichParagraph,
18
+ ooxmlShape,
19
+ ooxmlCustGeomShape,
20
+ ooxmlLine,
21
+ computeBadgePillWidth,
22
+ } from './deck-chrome.mjs'
23
+
24
+ export const PRO_CHART_LAYOUTS = new Set(['quadrant', 'radar', 'dumbbell', 'heatmap'])
25
+
26
+ function parseNum(raw, fallback = NaN) {
27
+ if (typeof raw === 'number' && Number.isFinite(raw)) return raw
28
+ const cleaned = String(raw ?? '').replace(/[,,%%$¥€£\s]/g, '').replace(/[++]/g, '')
29
+ const m = /-?\d+(?:\.\d+)?/.exec(cleaned)
30
+ return m ? Number(m[0]) : fallback
31
+ }
32
+
33
+ function fmtNum(v, unit = '') {
34
+ if (!Number.isFinite(v)) return '—'
35
+ const rounded = Math.abs(v - Math.round(v)) < 0.05 ? String(Math.round(v)) : v.toFixed(1)
36
+ return unit ? `${rounded}${unit}` : rounded
37
+ }
38
+
39
+ // ---------------------------------------------------------------------------
40
+ // 1. 数据模型解析(Quadrant / Radar / Dumbbell / Heatmap)
41
+ // ---------------------------------------------------------------------------
42
+
43
+ export function computeQuadrantModel(slide, langEn = false) {
44
+ let points = []
45
+ if (Array.isArray(slide.items) && slide.items.length > 0) {
46
+ points = slide.items
47
+ .map((it, idx) => {
48
+ const x = parseNum(it.x ?? it.start, NaN)
49
+ const y = parseNum(it.y ?? it.value, NaN)
50
+ const size = parseNum(it.size ?? it.span, 36)
51
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return null
52
+ return {
53
+ title: stripInlineMarkdown(it.title || it.tag || `Item ${idx + 1}`),
54
+ tag: stripInlineMarkdown(it.tag || ''),
55
+ x,
56
+ y,
57
+ size: Number.isFinite(size) ? Math.max(8, size) : 36,
58
+ status: it.status || (idx === 0 ? 'accent' : 'neutral'),
59
+ }
60
+ })
61
+ .filter(Boolean)
62
+ } else if (Array.isArray(slide.rows) && slide.rows.length >= 2) {
63
+ points = slide.rows.slice(1).map((r, idx) => {
64
+ const x = parseNum(r[1], NaN)
65
+ const y = parseNum(r[2], NaN)
66
+ const size = parseNum(r[3], 36)
67
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return null
68
+ return {
69
+ title: stripInlineMarkdown(r[0] || `Item ${idx + 1}`),
70
+ tag: '',
71
+ x,
72
+ y,
73
+ size: Number.isFinite(size) ? Math.max(8, size) : 36,
74
+ status: idx === 0 ? 'accent' : 'neutral',
75
+ }
76
+ }).filter(Boolean)
77
+ }
78
+
79
+ if (points.length === 0) {
80
+ points = [
81
+ { title: langEn ? 'Our Platform' : '本平台', x: 82, y: 84, size: 78, status: 'accent' },
82
+ { title: langEn ? 'Vendor A' : '竞品 A', x: 66, y: 68, size: 58, status: 'neutral' },
83
+ { title: langEn ? 'Vendor B' : '竞品 B', x: 34, y: 74, size: 46, status: 'neutral' },
84
+ { title: langEn ? 'Vendor C' : '竞品 C', x: 72, y: 36, size: 40, status: 'neutral' },
85
+ { title: langEn ? 'Legacy Tool' : '传统方案', x: 26, y: 28, size: 52, status: 'negative' },
86
+ ]
87
+ }
88
+
89
+ const xs = points.map((p) => p.x)
90
+ const ys = points.map((p) => p.y)
91
+ const sizes = points.map((p) => p.size)
92
+ const xMin = Math.min(0, ...xs)
93
+ const xMax = Math.max(100, ...xs)
94
+ const yMin = Math.min(0, ...ys)
95
+ const yMax = Math.max(100, ...ys)
96
+ const sMin = Math.min(...sizes)
97
+ const sMax = Math.max(...sizes)
98
+
99
+ const normPoints = points.slice(0, 12).map((p) => ({
100
+ ...p,
101
+ nx: Math.max(0.06, Math.min(0.94, (p.x - xMin) / Math.max(1e-6, xMax - xMin))),
102
+ ny: Math.max(0.08, Math.min(0.92, (p.y - yMin) / Math.max(1e-6, yMax - yMin))),
103
+ ns: sMax === sMin ? 0.55 : (p.size - sMin) / Math.max(1e-6, sMax - sMin),
104
+ }))
105
+
106
+ const defaultQuads = langEn
107
+ ? ['Challengers', 'Leaders', 'Niche Players', 'Visionaries']
108
+ : ['挑战者', '领导者', '特定领域', '远见者']
109
+ const quadrants = Array.isArray(slide.quadrants) && slide.quadrants.length === 4
110
+ ? slide.quadrants.map((q) => stripInlineMarkdown(q))
111
+ : defaultQuads
112
+
113
+ return {
114
+ points: normPoints,
115
+ quadrants,
116
+ xLabel: stripInlineMarkdown(slide.xLabel || (langEn ? 'Completeness of Vision →' : '战略前瞻性与产品完整度 →')),
117
+ yLabel: stripInlineMarkdown(slide.yLabel || (langEn ? 'Ability to Execute ↑' : '工程交付与规模化执行力 ↑')),
118
+ }
119
+ }
120
+
121
+ export function computeRadarModel(slide, langEn = false) {
122
+ let axes = []
123
+ let series = []
124
+
125
+ if (Array.isArray(slide.rows) && slide.rows.length >= 4 && Array.isArray(slide.rows[0]) && slide.rows[0].length >= 2) {
126
+ const head = slide.rows[0]
127
+ const sNames = head.slice(1, 4).map((h, i) => stripInlineMarkdown(h || `Series ${i + 1}`))
128
+ axes = slide.rows.slice(1, 9).map((r, i) => stripInlineMarkdown(r[0] || `Axis ${i + 1}`))
129
+ series = sNames.map((name, si) => ({
130
+ name,
131
+ values: slide.rows.slice(1, 9).map((r) => Math.max(0, parseNum(r[si + 1], 0))),
132
+ }))
133
+ } else if (slide.chart && Array.isArray(slide.chart.categories) && Array.isArray(slide.chart.series) && slide.chart.categories.length >= 3) {
134
+ axes = slide.chart.categories.slice(0, 8).map((c) => stripInlineMarkdown(c))
135
+ series = slide.chart.series.slice(0, 3).map((s, si) => ({
136
+ name: stripInlineMarkdown(s.name || `Series ${si + 1}`),
137
+ values: axes.map((_, ai) => Math.max(0, parseNum(s.values?.[ai], 0))),
138
+ }))
139
+ } else if (Array.isArray(slide.items) && slide.items.length >= 3) {
140
+ axes = slide.items.slice(0, 8).map((it, i) => stripInlineMarkdown(it.title || it.tag || `Axis ${i + 1}`))
141
+ const valsA = slide.items.slice(0, 8).map((it) => Math.max(0, parseNum(it.after ?? it.value, 75)))
142
+ const hasSecond = slide.items.some((it) => Number.isFinite(parseNum(it.before, NaN)))
143
+ series = [{ name: langEn ? 'Target' : '核心方案', values: valsA }]
144
+ if (hasSecond) {
145
+ series.push({
146
+ name: langEn ? 'Baseline' : '行业基线',
147
+ values: slide.items.slice(0, 8).map((it) => Math.max(0, parseNum(it.before, 50))),
148
+ })
149
+ }
150
+ } else {
151
+ axes = langEn
152
+ ? ['Throughput', 'Latency', 'Reliability', 'Security', 'Cost Efficiency', 'Ecosystem']
153
+ : ['推理吞吐', '响应延迟', '高可用性', '安全合规', '成本效率', '生态兼容']
154
+ series = [
155
+ { name: langEn ? 'Our Platform' : '本平台', values: [94, 91, 96, 92, 88, 86] },
156
+ { name: langEn ? 'Industry Avg' : '行业均值', values: [70, 68, 76, 72, 64, 74] },
157
+ ]
158
+ }
159
+
160
+ const allVals = series.flatMap((s) => s.values)
161
+ const rawMax = Math.max(10, ...allVals)
162
+ const maxVal = rawMax <= 5 ? 5 : rawMax <= 10 ? 10 : rawMax <= 100 ? 100 : Math.ceil(rawMax / 10) * 10
163
+ return { axes, series, maxVal }
164
+ }
165
+
166
+ export function computeDumbbellModel(slide, langEn = false) {
167
+ let rows = []
168
+ let beforeLabel = langEn ? 'Before' : '优化前'
169
+ let afterLabel = langEn ? 'After' : '优化后'
170
+
171
+ if (Array.isArray(slide.items) && slide.items.length > 0) {
172
+ rows = slide.items.slice(0, 7).map((it, idx) => {
173
+ const b = parseNum(it.before ?? it.start, NaN)
174
+ const a = parseNum(it.after ?? it.value, NaN)
175
+ if (!Number.isFinite(b) || !Number.isFinite(a)) return null
176
+ const diff = a - b
177
+ const unit = stripInlineMarkdown(it.unit || '')
178
+ const autoDelta = `${diff >= 0 ? '+' : ''}${fmtNum(diff, unit)}`
179
+ return {
180
+ title: stripInlineMarkdown(it.title || it.tag || `Metric ${idx + 1}`),
181
+ before: b,
182
+ after: a,
183
+ unit,
184
+ delta: stripInlineMarkdown(it.delta || autoDelta),
185
+ status: it.status || (diff >= 0 ? 'positive' : 'negative'),
186
+ }
187
+ }).filter(Boolean)
188
+ } else if (Array.isArray(slide.rows) && slide.rows.length >= 2) {
189
+ if (slide.rows[0]?.[1]) beforeLabel = stripInlineMarkdown(slide.rows[0][1])
190
+ if (slide.rows[0]?.[2]) afterLabel = stripInlineMarkdown(slide.rows[0][2])
191
+ rows = slide.rows.slice(1, 8).map((r, idx) => {
192
+ const b = parseNum(r[1], NaN)
193
+ const a = parseNum(r[2], NaN)
194
+ if (!Number.isFinite(b) || !Number.isFinite(a)) return null
195
+ const unitMatch = /(%|pp|ms|s|x|×|亿|万)/.exec(String(r[2] ?? r[1] ?? ''))
196
+ const unit = unitMatch ? unitMatch[1] : ''
197
+ const diff = a - b
198
+ const delta = r[3] ? stripInlineMarkdown(r[3]) : `${diff >= 0 ? '+' : ''}${fmtNum(diff, unit)}`
199
+ return {
200
+ title: stripInlineMarkdown(r[0] || `Metric ${idx + 1}`),
201
+ before: b,
202
+ after: a,
203
+ unit,
204
+ delta,
205
+ status: diff >= 0 ? 'positive' : 'negative',
206
+ }
207
+ }).filter(Boolean)
208
+ }
209
+
210
+ if (rows.length === 0) {
211
+ rows = [
212
+ { title: langEn ? 'Automation Rate' : '核心流程自动化率', before: 38, after: 84, unit: '%', delta: '+46pp', status: 'positive' },
213
+ { title: langEn ? 'First-Pass Yield' : '一次交付达标率', before: 64, after: 93, unit: '%', delta: '+29pp', status: 'positive' },
214
+ { title: langEn ? 'Unit Cost Index' : '单笔处理成本指数', before: 92, after: 54, unit: '', delta: '-41%', status: 'accent' },
215
+ { title: langEn ? 'User Adoption' : '活跃部门渗透率', before: 45, after: 89, unit: '%', delta: '+44pp', status: 'positive' },
216
+ ]
217
+ }
218
+
219
+ const allVals = rows.flatMap((r) => [r.before, r.after])
220
+ const lo = Math.min(...allVals)
221
+ const hi = Math.max(...allVals)
222
+ const rawSpan = Math.max(1, hi - lo)
223
+ const paddedLo = lo >= 0 ? Math.max(0, lo - rawSpan * 0.12) : lo - rawSpan * 0.12
224
+ const paddedHi = hi + rawSpan * 0.10
225
+ const roughStep = Math.max(1e-6, (paddedHi - paddedLo) / 4)
226
+ const mag = Math.pow(10, Math.floor(Math.log10(roughStep)))
227
+ const norm = roughStep / mag
228
+ const niceMult = norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 2.5 ? 2.5 : norm <= 5 ? 5 : 10
229
+ const step = niceMult * mag
230
+ let minVal = Math.floor(paddedLo / step) * step
231
+ if (lo >= 0 && minVal < 0) minVal = 0
232
+ let maxVal = Math.ceil(paddedHi / step) * step
233
+ if (hi <= 100 && lo >= 0 && hi > 50 && maxVal > 100 && maxVal <= 160) {
234
+ minVal = 0
235
+ maxVal = 100
236
+ }
237
+ const tickStep = (maxVal - minVal) / 4
238
+ const ticks = []
239
+ const count = Math.round((maxVal - minVal) / (maxVal === 100 && minVal === 0 ? 25 : step))
240
+ const finalStep = (maxVal === 100 && minVal === 0) ? 25 : (count >= 3 && count <= 6 ? step : tickStep)
241
+ for (let v = minVal; v <= maxVal + finalStep * 0.01; v += finalStep) {
242
+ ticks.push(Math.abs(v) < 1e-9 ? 0 : +v.toFixed(2))
243
+ }
244
+ return { rows, minVal, maxVal: Math.max(minVal + 5, maxVal), ticks, beforeLabel, afterLabel }
245
+ }
246
+
247
+ export function computeHeatmapModel(slide, langEn = false) {
248
+ let rawRows = Array.isArray(slide.rows) && slide.rows.length >= 2 ? slide.rows : null
249
+ if (!rawRows) {
250
+ rawRows = langEn
251
+ ? [
252
+ ['Region \\ Quarter', 'Q1', 'Q2', 'Q3', 'Q4'],
253
+ ['North America', 72, 81, 88, 95],
254
+ ['Europe', 64, 70, 79, 86],
255
+ ['APAC', 58, 74, 85, 93],
256
+ ['LatAm', 41, 49, 57, 68],
257
+ ]
258
+ : [
259
+ ['区域 \\ 季度', 'Q1', 'Q2', 'Q3', 'Q4'],
260
+ ['华东大区', 78, 84, 91, 97],
261
+ ['华南大区', 68, 75, 83, 90],
262
+ ['华北大区', 62, 69, 77, 85],
263
+ ['海外新兴', 44, 56, 71, 88],
264
+ ]
265
+ }
266
+
267
+ const corner = stripInlineMarkdown(rawRows[0]?.[0] || '')
268
+ const colHeaders = rawRows[0].slice(1, 9).map((c) => stripInlineMarkdown(c))
269
+ const rowLabels = rawRows.slice(1, 8).map((r) => stripInlineMarkdown(r[0] || ''))
270
+ const matrix = rawRows.slice(1, 8).map((r) =>
271
+ colHeaders.map((_, ci) => {
272
+ const rawText = stripInlineMarkdown(r[ci + 1] ?? '')
273
+ const num = parseNum(rawText, NaN)
274
+ return { raw: rawText || (Number.isFinite(num) ? fmtNum(num) : '—'), num }
275
+ }),
276
+ )
277
+
278
+ const nums = matrix.flat().map((c) => c.num).filter(Number.isFinite)
279
+ const minVal = nums.length ? Math.min(...nums) : 0
280
+ const maxVal = nums.length ? Math.max(...nums) : 100
281
+ const diverging = minVal < 0 && maxVal > 0
282
+ return { corner, colHeaders, rowLabels, matrix, minVal, maxVal, diverging }
283
+ }
284
+
285
+ function heatCellColor(num, model, tk) {
286
+ if (!Number.isFinite(num)) return tk.surface1
287
+ if (model.diverging) {
288
+ const absMax = Math.max(Math.abs(model.minVal), Math.abs(model.maxVal), 1e-6)
289
+ const t = Math.max(-1, Math.min(1, num / absMax))
290
+ return t >= 0
291
+ ? mixHex(tk.surface1, tk.positive, 0.14 + t * 0.82)
292
+ : mixHex(tk.surface1, tk.negative, 0.14 + Math.abs(t) * 0.82)
293
+ }
294
+ const t = model.maxVal === model.minVal ? 0.5 : (num - model.minVal) / (model.maxVal - model.minVal)
295
+ return mixHex(tk.surface1, tk.accentPrimary, 0.08 + Math.max(0, Math.min(1, t)) * 0.86)
296
+ }
297
+
298
+ // ---------------------------------------------------------------------------
299
+ // 2. PPTX 原生 DrawingML 渲染器
300
+ // ---------------------------------------------------------------------------
301
+
302
+ export function renderProChartSlideBodyPptx(slide, ctx) {
303
+ const layout = slide.layout
304
+ if (!PRO_CHART_LAYOUTS.has(layout)) return null
305
+ const { theme, langAttr, chromeCfg, nextId, bodyTopY, bodyH } = ctx
306
+ const tk = theme.tokens
307
+ const langEn = langAttr === 'en-US'
308
+ const shapes = []
309
+
310
+ // ---------------- 1. QUADRANT / MAGIC QUADRANT BUBBLE MATRIX ----------------
311
+ if (layout === 'quadrant') {
312
+ const model = computeQuadrantModel(slide, langEn)
313
+ const plotX = 1.24
314
+ const plotY = bodyTopY + 0.08
315
+ const plotW = 11.35
316
+ const plotH = Math.max(2.6, bodyH - 0.56)
317
+ const midX = plotX + plotW / 2
318
+ const midY = plotY + plotH / 2
319
+
320
+ // 外框底板
321
+ shapes.push(ooxmlShape(nextId(), 'Quadrant Frame', { x: plotX, y: plotY, w: plotW, h: plotH }, {
322
+ preset: 'roundRect',
323
+ adj: roundRectAdj(plotW, plotH, Math.min(8, chromeCfg.cardRadiusPx)),
324
+ fill: tk.surface1,
325
+ stroke: tk.hairline,
326
+ strokePt: 0.9,
327
+ }))
328
+ // 右上领导者象限微弱主题光晕区
329
+ shapes.push(ooxmlShape(nextId(), 'Quadrant Leader Zone', { x: midX, y: plotY, w: plotW / 2, h: plotH / 2 }, {
330
+ preset: 'rect',
331
+ fill: tk.accentSoft,
332
+ fillAlpha: theme.dark ? 0.35 : 0.62,
333
+ }))
334
+ // 十字中位虚线
335
+ shapes.push(ooxmlLine(nextId(), 'Quadrant Mid V', { x: midX, y: plotY }, { x: midX, y: plotY + plotH }, {
336
+ color: tk.hairline,
337
+ widthPt: 1.0,
338
+ dash: 'dash',
339
+ }))
340
+ shapes.push(ooxmlLine(nextId(), 'Quadrant Mid H', { x: plotX, y: midY }, { x: plotX + plotW, y: midY }, {
341
+ color: tk.hairline,
342
+ widthPt: 1.0,
343
+ dash: 'dash',
344
+ }))
345
+
346
+ // 四象限角标(TL, TR, BL, BR)
347
+ const cornerPos = [
348
+ { x: plotX + 0.14, y: plotY + 0.10, align: 'l', accent: false },
349
+ { x: plotX + plotW - 2.34, y: plotY + 0.10, align: 'r', accent: true },
350
+ { x: plotX + 0.14, y: plotY + plotH - 0.36, align: 'l', accent: false },
351
+ { x: plotX + plotW - 2.34, y: plotY + plotH - 0.36, align: 'r', accent: false },
352
+ ]
353
+ model.quadrants.forEach((ql, qi) => {
354
+ const cp = cornerPos[qi]
355
+ shapes.push(ooxmlShape(nextId(), `Quadrant Corner ${qi + 1}`, { x: cp.x, y: cp.y, w: 2.2, h: 0.28 }, {
356
+ txBox: true,
357
+ anchor: 'ctr',
358
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
359
+ paragraphs: [
360
+ ooxmlRichParagraph(ql.toUpperCase(), {
361
+ sizePt: 10.5,
362
+ color: cp.accent ? tk.accentText : tk.inkMuted,
363
+ bold: true,
364
+ lang: langAttr,
365
+ align: cp.align,
366
+ font: theme.fonts.heading,
367
+ spc: 100,
368
+ }),
369
+ ],
370
+ }))
371
+ })
372
+
373
+ // 比例气泡 + 智能避让标签(内置安全边距,彻底避免贴边或遮挡象限角标)
374
+ const padX = 0.72
375
+ const padY = 0.68
376
+ const innerW = Math.max(2.0, plotW - padX * 2)
377
+ const innerH = Math.max(1.4, plotH - padY * 2)
378
+ model.points.forEach((p, idx) => {
379
+ const cx = plotX + padX + p.nx * innerW
380
+ const cy = plotY + padY + (1 - p.ny) * innerH
381
+ const r = 0.17 + p.ns * 0.21
382
+ const isFocal = idx === 0 || p.status === 'accent'
383
+ const fillCol = p.status === 'positive'
384
+ ? tk.positive
385
+ : p.status === 'negative'
386
+ ? tk.negative
387
+ : p.status === 'accent'
388
+ ? tk.accentPrimary
389
+ : (tk.chartSeries?.[idx % tk.chartSeries.length] || tk.accentSecondary)
390
+ shapes.push(ooxmlShape(nextId(), `Quadrant Bubble ${idx + 1}`, { x: cx - r, y: cy - r, w: r * 2, h: r * 2 }, {
391
+ preset: 'ellipse',
392
+ fill: fillCol,
393
+ fillAlpha: isFocal ? 0.90 : 0.76,
394
+ stroke: tk.canvas,
395
+ strokePt: isFocal ? 2.0 : 1.25,
396
+ }))
397
+ const lblW = Math.min(2.35, Math.max(1.15, computeBadgePillWidth(p.title, 11.5, 2.4, 1.0)))
398
+ const placeBelow = cy - r - 0.30 < plotY + 0.38
399
+ const lblY = placeBelow ? Math.min(plotY + plotH - 0.34, cy + r + 0.05) : cy - r - 0.29
400
+ const lblX = Math.max(plotX + 0.10, Math.min(plotX + plotW - lblW - 0.10, cx - lblW / 2))
401
+ shapes.push(ooxmlShape(nextId(), `Quadrant Label ${idx + 1}`, { x: lblX, y: lblY, w: lblW, h: 0.26 }, {
402
+ txBox: true,
403
+ anchor: 'ctr',
404
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
405
+ paragraphs: [
406
+ ooxmlRichParagraph(p.title, {
407
+ sizePt: isFocal ? 12 : 11,
408
+ color: idx === 0 ? tk.inkPrimary : (isFocal ? tk.accentText : tk.inkPrimary),
409
+ bold: isFocal,
410
+ lang: langAttr,
411
+ align: 'ctr',
412
+ font: theme.fonts.heading,
413
+ }),
414
+ ],
415
+ }))
416
+ })
417
+
418
+ // X / Y 坐标轴标题(Y 轴单行垂直排版 vert270,零换行折断)
419
+ shapes.push(ooxmlShape(nextId(), 'Quadrant X Axis', { x: plotX, y: plotY + plotH + 0.08, w: plotW, h: 0.30 }, {
420
+ txBox: true,
421
+ anchor: 'ctr',
422
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
423
+ paragraphs: [
424
+ ooxmlRichParagraph(model.xLabel, { sizePt: 11.5, color: tk.inkSecondary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body }),
425
+ ],
426
+ }))
427
+ shapes.push(ooxmlShape(nextId(), 'Quadrant Y Axis', { x: 0.62, y: plotY, w: 0.44, h: plotH }, {
428
+ txBox: true,
429
+ vert: 'vert270',
430
+ anchor: 'ctr',
431
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
432
+ paragraphs: [
433
+ ooxmlRichParagraph(model.yLabel, { sizePt: 11, color: tk.inkSecondary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body }),
434
+ ],
435
+ }))
436
+ return shapes.join('')
437
+ }
438
+
439
+ // ---------------- 2. RADAR / SPIDER CHART ----------------
440
+ if (layout === 'radar') {
441
+ const model = computeRadarModel(slide, langEn)
442
+ const n = model.axes.length
443
+ const legendY = bodyTopY + 0.02
444
+ const cx = 6.6667
445
+ const cy = bodyTopY + 0.38 + (bodyH - 0.48) / 2
446
+ const maxR = Math.min(2.02, (bodyH - 1.18) / 2)
447
+ const seriesColors = [tk.accentPrimary, tk.accentSecondary, tk.positive]
448
+
449
+ // 顶部图例胶囊
450
+ const legW = 2.25
451
+ const totalLegW = model.series.length * legW
452
+ let lx = cx - totalLegW / 2
453
+ model.series.forEach((s, si) => {
454
+ const col = seriesColors[si % seriesColors.length]
455
+ shapes.push(ooxmlShape(nextId(), `Radar Legend Swatch ${si + 1}`, { x: lx, y: legendY + 0.08, w: 0.16, h: 0.16 }, {
456
+ preset: 'ellipse',
457
+ fill: col,
458
+ }))
459
+ shapes.push(ooxmlShape(nextId(), `Radar Legend Label ${si + 1}`, { x: lx + 0.22, y: legendY, w: legW - 0.26, h: 0.30 }, {
460
+ txBox: true,
461
+ anchor: 'ctr',
462
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
463
+ paragraphs: [
464
+ ooxmlRichParagraph(s.name, { sizePt: 12, color: tk.inkPrimary, bold: si === 0, lang: langAttr, font: theme.fonts.body }),
465
+ ],
466
+ }))
467
+ lx += legW
468
+ })
469
+
470
+ const polarPt = (idx, frac) => {
471
+ const a = -Math.PI / 2 + (2 * Math.PI * idx) / n
472
+ return { x: cx + Math.cos(a) * maxR * frac, y: cy + Math.sin(a) * maxR * frac, cos: Math.cos(a), sin: Math.sin(a) }
473
+ }
474
+
475
+ // 4 层同心正多边形蛛网(25% / 50% / 75% / 100%)
476
+ const gridBox = { x: cx - maxR, y: cy - maxR, w: maxR * 2, h: maxR * 2 }
477
+ const SCALE = 10000
478
+ const relPt = (pt) => ({ x: ((pt.x - gridBox.x) / gridBox.w) * SCALE, y: ((pt.y - gridBox.y) / gridBox.h) * SCALE })
479
+ ;[1.0, 0.75, 0.5, 0.25].forEach((frac, gi) => {
480
+ const pts = Array.from({ length: n }, (_, i) => relPt(polarPt(i, frac)))
481
+ const cmds = pts.map((p, i) => (i === 0 ? `<a:moveTo><a:pt x="${Math.round(p.x)}" y="${Math.round(p.y)}"/></a:moveTo>` : `<a:lnTo><a:pt x="${Math.round(p.x)}" y="${Math.round(p.y)}"/></a:lnTo>`)).join('') + '<a:close/>'
482
+ shapes.push(ooxmlCustGeomShape(nextId(), `Radar Ring ${gi + 1}`, gridBox, cmds, {
483
+ pathW: SCALE,
484
+ pathH: SCALE,
485
+ fill: gi === 0 ? tk.surface1 : '',
486
+ fillAlpha: gi === 0 ? 0.52 : 1,
487
+ stroke: tk.hairline,
488
+ strokePt: gi === 0 ? 1.0 : 0.75,
489
+ }))
490
+ })
491
+
492
+ // 辐条轴线与外圈维度标签
493
+ for (let i = 0; i < n; i += 1) {
494
+ const tip = polarPt(i, 1.0)
495
+ shapes.push(ooxmlLine(nextId(), `Radar Spoke ${i + 1}`, { x: cx, y: cy }, { x: tip.x, y: tip.y }, {
496
+ color: tk.hairline,
497
+ widthPt: 0.65,
498
+ }))
499
+ const lp = polarPt(i, 1.18)
500
+ const align = lp.cos > 0.22 ? 'l' : lp.cos < -0.22 ? 'r' : 'ctr'
501
+ const lw = 2.05
502
+ const lxPos = align === 'l' ? lp.x - 0.04 : align === 'r' ? lp.x - lw + 0.04 : lp.x - lw / 2
503
+ shapes.push(ooxmlShape(nextId(), `Radar Axis ${i + 1}`, { x: lxPos, y: lp.y - 0.16, w: lw, h: 0.34 }, {
504
+ txBox: true,
505
+ anchor: 'ctr',
506
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
507
+ paragraphs: [
508
+ ooxmlRichParagraph(model.axes[i], { sizePt: 12.5, color: tk.inkPrimary, bold: true, lang: langAttr, align, font: theme.fonts.heading }),
509
+ ],
510
+ }))
511
+ }
512
+
513
+ // 顶轴轻刻度数字(50 / 75 / 100)
514
+ ;[0.5, 0.75, 1.0].forEach((frac, ri) => {
515
+ const rp = polarPt(0, frac)
516
+ shapes.push(ooxmlShape(nextId(), `Radar Tick ${ri + 1}`, { x: rp.x + 0.06, y: rp.y - 0.11, w: 0.44, h: 0.20 }, {
517
+ txBox: true,
518
+ anchor: 'ctr',
519
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
520
+ paragraphs: [
521
+ ooxmlRichParagraph(fmtNum(model.maxVal * frac), { sizePt: 8.5, color: tk.inkMuted, lang: 'en-US', align: 'l', font: theme.fonts.body }),
522
+ ],
523
+ }))
524
+ })
525
+
526
+ // 数据多边形(半透明填充 + 粗描边 + 顶点圆点,逆序绘制使主系列位于最顶层)
527
+ ;[...model.series].map((s, si) => ({ s, si })).reverse().forEach(({ s, si }) => {
528
+ const col = seriesColors[si % seriesColors.length]
529
+ const pts = s.values.map((v, i) => polarPt(i, Math.max(0.05, Math.min(1, v / model.maxVal))))
530
+ const rpts = pts.map(relPt)
531
+ const cmds = rpts.map((p, i) => (i === 0 ? `<a:moveTo><a:pt x="${Math.round(p.x)}" y="${Math.round(p.y)}"/></a:moveTo>` : `<a:lnTo><a:pt x="${Math.round(p.x)}" y="${Math.round(p.y)}"/></a:lnTo>`)).join('') + '<a:close/>'
532
+ shapes.push(ooxmlCustGeomShape(nextId(), `Radar Series ${si + 1}`, gridBox, cmds, {
533
+ pathW: SCALE,
534
+ pathH: SCALE,
535
+ fill: col,
536
+ fillAlpha: si === 0 ? 0.24 : 0.13,
537
+ stroke: col,
538
+ strokePt: si === 0 ? 2.4 : 1.5,
539
+ }))
540
+ pts.forEach((pt, pi) => {
541
+ shapes.push(ooxmlShape(nextId(), `Radar Dot ${si + 1}-${pi + 1}`, { x: pt.x - 0.065, y: pt.y - 0.065, w: 0.13, h: 0.13 }, {
542
+ preset: 'ellipse',
543
+ fill: col,
544
+ stroke: tk.canvas,
545
+ strokePt: 1.15,
546
+ }))
547
+ })
548
+ })
549
+ return shapes.join('')
550
+ }
551
+
552
+ // ---------------- 3. DUMBBELL / SLOPE COMPARISON CHART ----------------
553
+ if (layout === 'dumbbell') {
554
+ const model = computeDumbbellModel(slide, langEn)
555
+ const labelW = 2.75
556
+ const deltaW = 1.36
557
+ const trackX = 0.62 + labelW + 0.24
558
+ const trackW = 12.09 - labelW - deltaW - 0.82
559
+ const legendY = bodyTopY + 0.02
560
+ const areaTop = bodyTopY + 0.42
561
+ const areaH = Math.max(2.2, bodyH - 0.84)
562
+ const rowCount = model.rows.length
563
+ const rowH = areaH / rowCount
564
+
565
+ // 顶部图例(优化前 vs 优化后)
566
+ shapes.push(ooxmlShape(nextId(), 'Dumbbell Leg Dot B', { x: trackX, y: legendY + 0.06, w: 0.16, h: 0.16 }, {
567
+ preset: 'ellipse',
568
+ fill: tk.canvas,
569
+ stroke: tk.inkMuted,
570
+ strokePt: 1.6,
571
+ }))
572
+ shapes.push(ooxmlShape(nextId(), 'Dumbbell Leg Txt B', { x: trackX + 0.22, y: legendY, w: 1.45, h: 0.28 }, {
573
+ txBox: true,
574
+ anchor: 'ctr',
575
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
576
+ paragraphs: [ooxmlRichParagraph(model.beforeLabel, { sizePt: 11.5, color: tk.inkMuted, bold: true, lang: langAttr, font: theme.fonts.body })],
577
+ }))
578
+ shapes.push(ooxmlShape(nextId(), 'Dumbbell Leg Dot A', { x: trackX + 1.80, y: legendY + 0.06, w: 0.16, h: 0.16 }, {
579
+ preset: 'ellipse',
580
+ fill: tk.accentPrimary,
581
+ }))
582
+ shapes.push(ooxmlShape(nextId(), 'Dumbbell Leg Txt A', { x: trackX + 2.02, y: legendY, w: 1.65, h: 0.28 }, {
583
+ txBox: true,
584
+ anchor: 'ctr',
585
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
586
+ paragraphs: [ooxmlRichParagraph(model.afterLabel, { sizePt: 11.5, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.body })],
587
+ }))
588
+
589
+ // 垂直基准网格线与底轴刻度(1-2-5 规整刻度)
590
+ const tickVals = Array.isArray(model.ticks) && model.ticks.length >= 2
591
+ ? model.ticks
592
+ : [0, 0.25, 0.5, 0.75, 1].map((f) => model.minVal + f * (model.maxVal - model.minVal))
593
+ tickVals.forEach((tVal, ti) => {
594
+ const frac = (tVal - model.minVal) / Math.max(1e-6, model.maxVal - model.minVal)
595
+ const gx = trackX + frac * trackW
596
+ shapes.push(ooxmlLine(nextId(), `Dumbbell Grid ${ti}`, { x: gx, y: areaTop }, { x: gx, y: areaTop + areaH }, {
597
+ color: tk.hairline,
598
+ widthPt: 0.6,
599
+ dash: ti === 0 ? 'solid' : 'dash',
600
+ }))
601
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Tick ${ti}`, { x: gx - 0.45, y: areaTop + areaH + 0.06, w: 0.90, h: 0.26 }, {
602
+ txBox: true,
603
+ anchor: 'ctr',
604
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
605
+ paragraphs: [ooxmlRichParagraph(fmtNum(tVal), { sizePt: 10.5, color: tk.inkMuted, lang: 'en-US', align: 'ctr', font: theme.fonts.body })],
606
+ }))
607
+ })
608
+
609
+ const mapX = (v) => trackX + ((v - model.minVal) / Math.max(1e-6, model.maxVal - model.minVal)) * trackW
610
+
611
+ model.rows.forEach((r, idx) => {
612
+ const cy = areaTop + (idx + 0.5) * rowH
613
+ const bx = mapX(r.before)
614
+ const ax = mapX(r.after)
615
+ const barCol = r.status === 'negative' ? tk.negative : (r.status === 'positive' ? tk.positive : tk.accentPrimary)
616
+
617
+ // 左侧行标签
618
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Label ${idx + 1}`, { x: 0.62, y: cy - 0.24, w: labelW, h: 0.48 }, {
619
+ txBox: true,
620
+ anchor: 'ctr',
621
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
622
+ paragraphs: [ooxmlRichParagraph(r.title, { sizePt: 13.5, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'r', font: theme.fonts.heading })],
623
+ }))
624
+ // 淡色底轨道 + 方向连接桥
625
+ shapes.push(ooxmlLine(nextId(), `Dumbbell Track ${idx + 1}`, { x: trackX, y: cy }, { x: trackX + trackW, y: cy }, {
626
+ color: tk.hairline,
627
+ widthPt: 0.75,
628
+ }))
629
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Bridge ${idx + 1}`, { x: Math.min(bx, ax), y: cy - 0.045, w: Math.max(0.06, Math.abs(ax - bx)), h: 0.09 }, {
630
+ preset: 'roundRect',
631
+ adj: 50000,
632
+ fill: barCol,
633
+ fillAlpha: 0.85,
634
+ }))
635
+ // Before 空心点 + After 实心焦点
636
+ const dotR = 0.115
637
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Before ${idx + 1}`, { x: bx - dotR, y: cy - dotR, w: dotR * 2, h: dotR * 2 }, {
638
+ preset: 'ellipse',
639
+ fill: tk.canvas,
640
+ stroke: tk.inkMuted,
641
+ strokePt: 2.0,
642
+ }))
643
+ shapes.push(ooxmlShape(nextId(), `Dumbbell After ${idx + 1}`, { x: ax - dotR - 0.015, y: cy - dotR - 0.015, w: (dotR + 0.015) * 2, h: (dotR + 0.015) * 2 }, {
644
+ preset: 'ellipse',
645
+ fill: barCol,
646
+ stroke: tk.canvas,
647
+ strokePt: 1.25,
648
+ }))
649
+ // 外侧防撞数值标签(靠近左/右数轴边界时自动上移至圆点正上方,杜绝与行标题或徽章重叠)
650
+ const bLeft = bx <= ax
651
+ const bText = fmtNum(r.before, r.unit)
652
+ const aText = fmtNum(r.after, r.unit)
653
+ const bW = Math.max(0.68, Math.min(1.15, bText.length * 0.13 + 0.16))
654
+ const aW = Math.max(0.70, Math.min(1.15, aText.length * 0.13 + 0.18))
655
+ const bTightLeft = bLeft && (bx - trackX < bW + 0.14)
656
+ const bTightRight = !bLeft && (trackX + trackW - bx < bW + 0.14)
657
+ const aTightLeft = !bLeft && (ax - trackX < aW + 0.14)
658
+ const aTightRight = bLeft && (trackX + trackW - ax < aW + 0.14)
659
+ const bBox = bTightLeft
660
+ ? { x: Math.max(trackX, bx - 0.10), y: cy - 0.39, w: bW, h: 0.26, align: 'l' }
661
+ : bTightRight
662
+ ? { x: Math.min(trackX + trackW - bW, bx - bW + 0.12), y: cy - 0.39, w: bW, h: 0.26, align: 'r' }
663
+ : { x: bLeft ? bx - bW - 0.16 : bx + 0.18, y: cy - 0.15, w: bW, h: 0.30, align: bLeft ? 'r' : 'l' }
664
+ const aBox = aTightLeft
665
+ ? { x: Math.max(trackX, ax - 0.10), y: cy - 0.39, w: aW, h: 0.26, align: 'l' }
666
+ : aTightRight
667
+ ? { x: Math.min(trackX + trackW - aW, ax - aW + 0.12), y: cy - 0.39, w: aW, h: 0.26, align: 'r' }
668
+ : { x: bLeft ? ax + 0.18 : ax - aW - 0.16, y: cy - 0.15, w: aW, h: 0.30, align: bLeft ? 'l' : 'r' }
669
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Val B ${idx + 1}`, { x: bBox.x, y: bBox.y, w: bBox.w, h: bBox.h }, {
670
+ txBox: true,
671
+ anchor: 'ctr',
672
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
673
+ paragraphs: [ooxmlRichParagraph(bText, { sizePt: 11, color: tk.inkMuted, bold: true, lang: 'en-US', align: bBox.align, font: theme.fonts.body })],
674
+ }))
675
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Val A ${idx + 1}`, { x: aBox.x, y: aBox.y, w: aBox.w, h: aBox.h }, {
676
+ txBox: true,
677
+ anchor: 'ctr',
678
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
679
+ paragraphs: [ooxmlRichParagraph(aText, { sizePt: 11.5, color: barCol, bold: true, lang: 'en-US', align: aBox.align, font: theme.fonts.heading })],
680
+ }))
681
+ // 右侧变化量胶囊
682
+ const pillX = 12.71 - deltaW
683
+ shapes.push(ooxmlShape(nextId(), `Dumbbell Delta ${idx + 1}`, { x: pillX, y: cy - 0.17, w: deltaW, h: 0.34 }, {
684
+ preset: 'roundRect',
685
+ adj: 50000,
686
+ fill: tk.surface1,
687
+ stroke: barCol,
688
+ strokePt: 0.8,
689
+ anchor: 'ctr',
690
+ marginsIn: { l: 0.04, r: 0.04, t: 0.01, b: 0.01 },
691
+ paragraphs: [ooxmlRichParagraph(r.delta, { sizePt: 11.5, color: barCol, bold: true, lang: 'en-US', align: 'ctr', font: theme.fonts.heading })],
692
+ }))
693
+ })
694
+ return shapes.join('')
695
+ }
696
+
697
+ // ---------------- 4. DATA HEATMAP MATRIX ----------------
698
+ const model = computeHeatmapModel(slide, langEn)
699
+ const cols = model.colHeaders.length
700
+ const rows = model.rowLabels.length
701
+ const rowLabelW = Math.min(2.45, Math.max(1.65, 12.09 * 0.18))
702
+ const headH = 0.44
703
+ const legendH = 0.36
704
+ const gap = 0.06
705
+ const gridX = 0.62 + rowLabelW + 0.12
706
+ const gridW = 12.09 - rowLabelW - 0.12
707
+ const gridY = bodyTopY + legendH + headH + 0.06
708
+ const gridH = Math.max(2.1, bodyH - legendH - headH - 0.12)
709
+ const cellW = (gridW - gap * (cols - 1)) / Math.max(1, cols)
710
+ const cellH = (gridH - gap * (rows - 1)) / Math.max(1, rows)
711
+
712
+ // 顶部色带图例(Low → High)
713
+ const rampW = 2.6
714
+ const rampX = 12.71 - rampW
715
+ const rampY = bodyTopY + 0.04
716
+ shapes.push(ooxmlShape(nextId(), 'Heatmap Scale Low', { x: rampX - 0.82, y: rampY, w: 0.74, h: 0.24 }, {
717
+ txBox: true,
718
+ anchor: 'ctr',
719
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
720
+ paragraphs: [ooxmlRichParagraph(fmtNum(model.minVal), { sizePt: 10, color: tk.inkMuted, lang: 'en-US', align: 'r', font: theme.fonts.body })],
721
+ }))
722
+ const rampSteps = 6
723
+ const segW = (rampW - 0.78) / rampSteps
724
+ for (let si = 0; si < rampSteps; si += 1) {
725
+ const sv = model.minVal + (si / Math.max(1, rampSteps - 1)) * (model.maxVal - model.minVal)
726
+ shapes.push(ooxmlShape(nextId(), `Heatmap Legend ${si + 1}`, { x: rampX + si * segW, y: rampY + 0.04, w: segW - 0.02, h: 0.16 }, {
727
+ preset: 'rect',
728
+ fill: heatCellColor(sv, model, tk),
729
+ }))
730
+ }
731
+ shapes.push(ooxmlShape(nextId(), 'Heatmap Scale High', { x: rampX + rampW - 0.72, y: rampY, w: 0.72, h: 0.24 }, {
732
+ txBox: true,
733
+ anchor: 'ctr',
734
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
735
+ paragraphs: [ooxmlRichParagraph(fmtNum(model.maxVal), { sizePt: 10, color: tk.inkPrimary, bold: true, lang: 'en-US', align: 'l', font: theme.fonts.body })],
736
+ }))
737
+
738
+ // 左上角标 & 列标题
739
+ if (model.corner) {
740
+ shapes.push(ooxmlShape(nextId(), 'Heatmap Corner', { x: 0.62, y: bodyTopY + legendH, w: rowLabelW, h: headH }, {
741
+ txBox: true,
742
+ anchor: 'ctr',
743
+ marginsIn: { l: 0, r: 0.06, t: 0, b: 0 },
744
+ paragraphs: [ooxmlRichParagraph(model.corner, { sizePt: 11.5, color: tk.inkMuted, bold: true, lang: langAttr, align: 'r', font: theme.fonts.body })],
745
+ }))
746
+ }
747
+ model.colHeaders.forEach((ch, ci) => {
748
+ shapes.push(ooxmlShape(nextId(), `Heatmap Col ${ci + 1}`, { x: gridX + ci * (cellW + gap), y: bodyTopY + legendH, w: cellW, h: headH }, {
749
+ txBox: true,
750
+ anchor: 'ctr',
751
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
752
+ paragraphs: [ooxmlRichParagraph(ch, { sizePt: 13, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
753
+ }))
754
+ })
755
+
756
+ // 矩阵行与色阶单元格
757
+ model.matrix.forEach((rowCells, ri) => {
758
+ const ry = gridY + ri * (cellH + gap)
759
+ shapes.push(ooxmlShape(nextId(), `Heatmap Row ${ri + 1}`, { x: 0.62, y: ry, w: rowLabelW, h: cellH }, {
760
+ txBox: true,
761
+ anchor: 'ctr',
762
+ marginsIn: { l: 0, r: 0.06, t: 0, b: 0 },
763
+ paragraphs: [ooxmlRichParagraph(model.rowLabels[ri], { sizePt: 13, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'r', font: theme.fonts.heading })],
764
+ }))
765
+ rowCells.forEach((cell, ci) => {
766
+ const cx = gridX + ci * (cellW + gap)
767
+ const bg = heatCellColor(cell.num, model, tk)
768
+ const fg = relativeLuminance(bg) < 0.36 ? '#FFFFFF' : '#0F172A'
769
+ const isPeak = Number.isFinite(cell.num) && cell.num === model.maxVal
770
+ shapes.push(ooxmlShape(nextId(), `Heatmap Cell ${ri + 1}-${ci + 1}`, { x: cx, y: ry, w: cellW, h: cellH }, {
771
+ preset: 'roundRect',
772
+ adj: roundRectAdj(cellW, cellH, Math.min(8, Math.max(4, chromeCfg.cardRadiusPx))),
773
+ fill: bg,
774
+ stroke: isPeak ? mixHex(tk.accentPrimary, '#000000', 0.24) : '',
775
+ strokePt: isPeak ? 1.5 : 0,
776
+ anchor: 'ctr',
777
+ marginsIn: { l: 0.04, r: 0.04, t: 0.02, b: 0.02 },
778
+ paragraphs: [
779
+ ooxmlRichParagraph(cell.raw, {
780
+ sizePt: cols >= 7 ? 12.5 : 14.5,
781
+ color: fg,
782
+ bold: isPeak || relativeLuminance(bg) < 0.36,
783
+ lang: 'en-US',
784
+ align: 'ctr',
785
+ font: theme.fonts.heading,
786
+ }),
787
+ ],
788
+ }))
789
+ })
790
+ })
791
+ return shapes.join('')
792
+ }
793
+
794
+ // ---------------------------------------------------------------------------
795
+ // 3. HTML SVG 双端同构渲染器
796
+ // ---------------------------------------------------------------------------
797
+
798
+ export function renderProChartSlideBodyHtml(slide, ctx = {}) {
799
+ const layout = slide.layout
800
+ if (!PRO_CHART_LAYOUTS.has(layout)) return null
801
+ const { theme, langId } = ctx
802
+ const tk = theme.tokens
803
+ const langEn = langId === 'en'
804
+
805
+ if (layout === 'quadrant') {
806
+ const model = computeQuadrantModel(slide, langEn)
807
+ const W = 960
808
+ const H = 430
809
+ const px = 86
810
+ const py = 18
811
+ const pw = W - 110
812
+ const ph = H - 62
813
+ const mx = px + pw / 2
814
+ const my = py + ph / 2
815
+ const padX = 56
816
+ const padY = 50
817
+ const bubbles = model.points.map((p, idx) => {
818
+ const cx = px + padX + p.nx * (pw - padX * 2)
819
+ const cy = py + padY + (1 - p.ny) * (ph - padY * 2)
820
+ const r = 14 + p.ns * 18
821
+ const isFocal = idx === 0 || p.status === 'accent'
822
+ const col = p.status === 'positive'
823
+ ? tk.positive
824
+ : p.status === 'negative'
825
+ ? tk.negative
826
+ : p.status === 'accent'
827
+ ? tk.accentPrimary
828
+ : (tk.chartSeries?.[idx % tk.chartSeries.length] || tk.accentSecondary)
829
+ const below = cy - r - 20 < py + 30
830
+ const ly = below ? Math.min(py + ph - 12, cy + r + 17) : cy - r - 9
831
+ return (
832
+ `<circle cx="${cx.toFixed(1)}" cy="${cy.toFixed(1)}" r="${r.toFixed(1)}" fill="${col}" fill-opacity="${isFocal ? 0.90 : 0.76}" stroke="${tk.canvas}" stroke-width="${isFocal ? 2.5 : 1.5}"/>` +
833
+ `<text x="${cx.toFixed(1)}" y="${ly.toFixed(1)}" text-anchor="middle" font-size="${isFocal ? 13 : 12}" font-weight="${isFocal ? 700 : 600}" fill="${idx === 0 ? tk.inkPrimary : (isFocal ? tk.accentText : tk.inkPrimary)}">${escapeHtml(p.title)}</text>`
834
+ )
835
+ }).join('')
836
+
837
+ return (
838
+ `<div class="pro-chart-wrap">` +
839
+ `<svg class="pro-chart-svg quadrant-svg" viewBox="0 0 ${W} ${H}" role="img" aria-label="${escapeHtml(slide.title || 'Quadrant chart')}">` +
840
+ `<rect x="${px}" y="${py}" width="${pw}" height="${ph}" rx="10" fill="${tk.surface1}" stroke="${tk.hairline}" stroke-width="1.2"/>` +
841
+ `<rect x="${mx}" y="${py}" width="${pw / 2}" height="${ph / 2}" fill="${tk.accentSoft}" fill-opacity="${theme.dark ? 0.35 : 0.65}"/>` +
842
+ `<line x1="${mx}" y1="${py}" x2="${mx}" y2="${py + ph}" stroke="${tk.hairline}" stroke-width="1.2" stroke-dasharray="5 4"/>` +
843
+ `<line x1="${px}" y1="${my}" x2="${px + pw}" y2="${my}" stroke="${tk.hairline}" stroke-width="1.2" stroke-dasharray="5 4"/>` +
844
+ `<text x="${px + 14}" y="${py + 22}" font-size="11" font-weight="700" letter-spacing="1" fill="${tk.inkMuted}">${escapeHtml(model.quadrants[0].toUpperCase())}</text>` +
845
+ `<text x="${px + pw - 14}" y="${py + 22}" text-anchor="end" font-size="11" font-weight="700" letter-spacing="1" fill="${tk.accentText}">${escapeHtml(model.quadrants[1].toUpperCase())}</text>` +
846
+ `<text x="${px + 14}" y="${py + ph - 12}" font-size="11" font-weight="700" letter-spacing="1" fill="${tk.inkMuted}">${escapeHtml(model.quadrants[2].toUpperCase())}</text>` +
847
+ `<text x="${px + pw - 14}" y="${py + ph - 12}" text-anchor="end" font-size="11" font-weight="700" letter-spacing="1" fill="${tk.inkMuted}">${escapeHtml(model.quadrants[3].toUpperCase())}</text>` +
848
+ bubbles +
849
+ `<text x="${px + pw / 2}" y="${H - 12}" text-anchor="middle" font-size="12.5" font-weight="700" fill="${tk.inkSecondary}">${escapeHtml(model.xLabel)}</text>` +
850
+ `<text x="26" y="${py + ph / 2}" text-anchor="middle" font-size="12" font-weight="700" fill="${tk.inkSecondary}" transform="rotate(-90 26 ${py + ph / 2})">${escapeHtml(model.yLabel)}</text>` +
851
+ `</svg></div>`
852
+ )
853
+ }
854
+
855
+ if (layout === 'radar') {
856
+ const model = computeRadarModel(slide, langEn)
857
+ const n = model.axes.length
858
+ const W = 880
859
+ const H = 430
860
+ const cx = W / 2
861
+ const cy = H / 2 + 16
862
+ const maxR = 152
863
+ const cols = [tk.accentPrimary, tk.accentSecondary, tk.positive]
864
+ const pt = (i, f) => {
865
+ const a = -Math.PI / 2 + (2 * Math.PI * i) / n
866
+ return { x: cx + Math.cos(a) * maxR * f, y: cy + Math.sin(a) * maxR * f, cos: Math.cos(a) }
867
+ }
868
+ const rings = [1, 0.75, 0.5, 0.25].map((f, gi) => {
869
+ const d = Array.from({ length: n }, (_, i) => pt(i, f)).map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(' ')
870
+ return `<polygon points="${d}" fill="${gi === 0 ? tk.surface1 : 'none'}" fill-opacity="0.45" stroke="${tk.hairline}" stroke-width="${gi === 0 ? 1.3 : 0.9}"/>`
871
+ }).join('')
872
+ const spokes = model.axes.map((ax, i) => {
873
+ const tip = pt(i, 1)
874
+ const lbl = pt(i, 1.18)
875
+ const anchor = lbl.cos > 0.2 ? 'start' : lbl.cos < -0.2 ? 'end' : 'middle'
876
+ return (
877
+ `<line x1="${cx}" y1="${cy}" x2="${tip.x.toFixed(1)}" y2="${tip.y.toFixed(1)}" stroke="${tk.hairline}" stroke-width="0.9"/>` +
878
+ `<text x="${lbl.x.toFixed(1)}" y="${(lbl.y + 4).toFixed(1)}" text-anchor="${anchor}" font-size="13" font-weight="700" fill="${tk.inkPrimary}">${escapeHtml(ax)}</text>`
879
+ )
880
+ }).join('')
881
+ const polys = model.series.map((s, si) => {
882
+ const col = cols[si % cols.length]
883
+ const pts = s.values.map((v, i) => pt(i, Math.max(0.05, Math.min(1, v / model.maxVal))))
884
+ const d = pts.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(' ')
885
+ const dots = pts.map((p) => `<circle cx="${p.x.toFixed(1)}" cy="${p.y.toFixed(1)}" r="4.5" fill="${col}" stroke="${tk.canvas}" stroke-width="1.5"/>`).join('')
886
+ return `<polygon points="${d}" fill="${col}" fill-opacity="${si === 0 ? 0.24 : 0.14}" stroke="${col}" stroke-width="${si === 0 ? 2.6 : 1.8}"/>${dots}`
887
+ }).join('')
888
+ const legend = model.series.map((s, si) => {
889
+ const col = cols[si % cols.length]
890
+ return `<span class="pro-leg-item"><i style="background:${col}"></i>${escapeHtml(s.name)}</span>`
891
+ }).join('')
892
+ return (
893
+ `<div class="pro-chart-wrap">` +
894
+ `<div class="pro-leg-bar">${legend}</div>` +
895
+ `<svg class="pro-chart-svg radar-svg" viewBox="0 0 ${W} ${H}" role="img" aria-label="${escapeHtml(slide.title || 'Radar chart')}">${rings}${spokes}${polys}</svg>` +
896
+ `</div>`
897
+ )
898
+ }
899
+
900
+ if (layout === 'dumbbell') {
901
+ const model = computeDumbbellModel(slide, langEn)
902
+ const W = 960
903
+ const H = Math.max(290, model.rows.length * 64 + 68)
904
+ const lx = 215
905
+ const rx = W - 125
906
+ const tw = rx - lx
907
+ const top = 26
908
+ const rowH = (H - 64) / model.rows.length
909
+ const mapX = (v) => lx + ((v - model.minVal) / Math.max(1e-6, model.maxVal - model.minVal)) * tw
910
+
911
+ const tickVals = Array.isArray(model.ticks) && model.ticks.length >= 2
912
+ ? model.ticks
913
+ : [0, 0.25, 0.5, 0.75, 1].map((f) => model.minVal + f * (model.maxVal - model.minVal))
914
+ const grids = tickVals.map((val, ti) => {
915
+ const f = (val - model.minVal) / Math.max(1e-6, model.maxVal - model.minVal)
916
+ const gx = lx + f * tw
917
+ return (
918
+ `<line x1="${gx.toFixed(1)}" y1="${top}" x2="${gx.toFixed(1)}" y2="${H - 36}" stroke="${tk.hairline}" stroke-dasharray="${ti === 0 ? '' : '4 4'}"/>` +
919
+ `<text x="${gx.toFixed(1)}" y="${H - 14}" text-anchor="middle" font-size="11.5" fill="${tk.inkMuted}">${escapeHtml(fmtNum(val))}</text>`
920
+ )
921
+ }).join('')
922
+
923
+ const rowsSvg = model.rows.map((r, idx) => {
924
+ const cy = top + (idx + 0.5) * rowH
925
+ const bx = mapX(r.before)
926
+ const ax = mapX(r.after)
927
+ const col = r.status === 'negative' ? tk.negative : (r.status === 'positive' ? tk.positive : tk.accentPrimary)
928
+ const bLeft = bx <= ax
929
+ const bTightL = bLeft && (bx - lx < 68)
930
+ const bTightR = !bLeft && (rx - bx < 68)
931
+ const aTightL = !bLeft && (ax - lx < 68)
932
+ const aTightR = bLeft && (rx - ax < 68)
933
+ const bLblX = bTightL ? Math.max(lx, bx - 4) : bTightR ? Math.min(rx, bx + 4) : (bLeft ? bx - 14 : bx + 14)
934
+ const bLblY = (bTightL || bTightR) ? cy - 15 : cy + 4
935
+ const bAnchor = bTightL ? 'start' : bTightR ? 'end' : (bLeft ? 'end' : 'start')
936
+ const aLblX = aTightL ? Math.max(lx, ax - 4) : aTightR ? Math.min(rx, ax + 4) : (bLeft ? ax + 14 : ax - 14)
937
+ const aLblY = (aTightL || aTightR) ? cy - 15 : cy + 4
938
+ const aAnchor = aTightL ? 'start' : aTightR ? 'end' : (bLeft ? 'start' : 'end')
939
+ return (
940
+ `<text x="${lx - 18}" y="${(cy + 5).toFixed(1)}" text-anchor="end" font-size="14" font-weight="700" fill="${tk.inkPrimary}">${escapeHtml(r.title)}</text>` +
941
+ `<line x1="${lx}" y1="${cy.toFixed(1)}" x2="${rx}" y2="${cy.toFixed(1)}" stroke="${tk.hairline}" stroke-width="1"/>` +
942
+ `<line x1="${bx.toFixed(1)}" y1="${cy.toFixed(1)}" x2="${ax.toFixed(1)}" y2="${cy.toFixed(1)}" stroke="${col}" stroke-width="6" stroke-linecap="round" stroke-opacity="0.85"/>` +
943
+ `<circle cx="${bx.toFixed(1)}" cy="${cy.toFixed(1)}" r="8" fill="${tk.canvas}" stroke="${tk.inkMuted}" stroke-width="2.5"/>` +
944
+ `<circle cx="${ax.toFixed(1)}" cy="${cy.toFixed(1)}" r="9" fill="${col}" stroke="${tk.canvas}" stroke-width="2"/>` +
945
+ `<text x="${bLblX.toFixed(1)}" y="${bLblY.toFixed(1)}" text-anchor="${bAnchor}" font-size="12" font-weight="700" fill="${tk.inkMuted}">${escapeHtml(fmtNum(r.before, r.unit))}</text>` +
946
+ `<text x="${aLblX.toFixed(1)}" y="${aLblY.toFixed(1)}" text-anchor="${aAnchor}" font-size="12.5" font-weight="800" fill="${col}">${escapeHtml(fmtNum(r.after, r.unit))}</text>` +
947
+ `<rect x="${rx + 18}" y="${(cy - 13).toFixed(1)}" width="94" height="26" rx="13" fill="${tk.surface1}" stroke="${col}" stroke-width="1.2"/>` +
948
+ `<text x="${rx + 65}" y="${(cy + 4).toFixed(1)}" text-anchor="middle" font-size="12" font-weight="700" fill="${col}">${escapeHtml(r.delta)}</text>`
949
+ )
950
+ }).join('')
951
+
952
+ return (
953
+ `<div class="pro-chart-wrap">` +
954
+ `<div class="pro-leg-bar"><span class="pro-leg-item"><i class="is-hollow" style="border-color:${tk.inkMuted}"></i>${escapeHtml(model.beforeLabel)}</span><span class="pro-leg-item"><i style="background:${tk.accentPrimary}"></i>${escapeHtml(model.afterLabel)}</span></div>` +
955
+ `<svg class="pro-chart-svg dumbbell-svg" viewBox="0 0 ${W} ${H}" role="img" aria-label="${escapeHtml(slide.title || 'Dumbbell chart')}">${grids}${rowsSvg}</svg>` +
956
+ `</div>`
957
+ )
958
+ }
959
+
960
+ // layout === 'heatmap'
961
+ const model = computeHeatmapModel(slide, langEn)
962
+ const rampStops = Array.from({ length: 6 }, (_, si) => {
963
+ const sv = model.minVal + (si / 5) * (model.maxVal - model.minVal)
964
+ return `<i style="background:${heatCellColor(sv, model, tk)}"></i>`
965
+ }).join('')
966
+ const headHtml = `<div class="hm-corner">${escapeHtml(model.corner)}</div>` +
967
+ model.colHeaders.map((c) => `<div class="hm-col">${escapeHtml(c)}</div>`).join('')
968
+ const rowsHtml = model.matrix.map((rowCells, ri) =>
969
+ `<div class="hm-row-lbl">${escapeHtml(model.rowLabels[ri])}</div>` +
970
+ rowCells.map((cell) => {
971
+ const bg = heatCellColor(cell.num, model, tk)
972
+ const fg = relativeLuminance(bg) < 0.36 ? '#FFFFFF' : '#0F172A'
973
+ const peak = Number.isFinite(cell.num) && cell.num === model.maxVal
974
+ return `<div class="hm-cell${peak ? ' is-peak' : ''}" style="background:${bg};color:${fg}">${escapeHtml(cell.raw)}</div>`
975
+ }).join(''),
976
+ ).join('')
977
+ return (
978
+ `<div class="pro-chart-wrap">` +
979
+ `<div class="hm-legend"><span>${escapeHtml(fmtNum(model.minVal))}</span><span class="hm-ramp">${rampStops}</span><strong>${escapeHtml(fmtNum(model.maxVal))}</strong></div>` +
980
+ `<div class="hm-grid" style="grid-template-columns:minmax(110px,1.25fr) repeat(${model.colHeaders.length},minmax(0,1fr))">${headHtml}${rowsHtml}</div>` +
981
+ `</div>`
982
+ )
983
+ }
984
+
985
+ export const PRO_CHARTS_CSS = `
986
+ /* Phase 7 Pinnacle Analyst Charts: Quadrant, Radar, Dumbbell & Heatmap */
987
+ .pro-chart-wrap{display:flex;flex-direction:column;gap:10px;width:100%;align-items:center}
988
+ .pro-chart-svg{width:100%;max-height:460px;height:auto;display:block}
989
+ .pro-leg-bar{display:flex;gap:18px;align-items:center;justify-content:center;font-size:13px;font-weight:600;color:var(--ink-secondary)}
990
+ .pro-leg-item{display:inline-flex;align-items:center;gap:7px}
991
+ .pro-leg-item i{width:11px;height:11px;border-radius:50%;display:inline-block}
992
+ .pro-leg-item i.is-hollow{background:var(--bg);border:2.2px solid var(--muted)}
993
+ .hm-legend{display:flex;align-items:center;gap:8px;align-self:flex-end;font-size:12px;color:var(--muted)}
994
+ .hm-legend strong{color:var(--fg)}
995
+ .hm-ramp{display:inline-flex;gap:2px}
996
+ .hm-ramp i{width:22px;height:12px;border-radius:2px;display:block}
997
+ .hm-grid{display:grid;gap:6px;width:100%;align-items:stretch}
998
+ .hm-corner,.hm-col,.hm-row-lbl{display:flex;align-items:center;font-family:var(--font-heading);font-weight:700;font-size:clamp(12px,1.2vw,15px);color:var(--fg)}
999
+ .hm-corner,.hm-row-lbl{justify-content:flex-end;padding-right:10px}
1000
+ .hm-corner{color:var(--muted);font-size:12px}
1001
+ .hm-col{justify-content:center;padding:6px 4px}
1002
+ .hm-cell{display:flex;align-items:center;justify-content:center;min-height:clamp(42px,5.2vw,66px);border-radius:calc(var(--radius) * .6);font-family:var(--font-heading);font-weight:700;font-size:clamp(14px,1.4vw,18px);font-variant-numeric:tabular-nums}
1003
+ .hm-cell.is-peak{outline:2px solid var(--fg);outline-offset:-2px}
1004
+ `