@officedk/pptxdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { mergeDataLabels } from "../chart-labels.js";
|
|
2
|
+
import { formatChartNumber } from "./number-format.js";
|
|
3
|
+
import { resolveChartLineStroke, strokeAttrs } from "./style.js";
|
|
4
|
+
import { measureChartText, mergeChartTextStyle, renderChartTextSvg, resolveChartFontSizePixels } from "./text-render.js";
|
|
5
|
+
// ../capabilities/dist/chart/preview/data-labels.js
|
|
6
|
+
function barLabelBox(anchor, position, textWidth, textHeight) {
|
|
7
|
+
const pad = 3;
|
|
8
|
+
const labelH = Math.max(textHeight, 10);
|
|
9
|
+
if (!anchor.horizontal) {
|
|
10
|
+
const colW = Math.max(anchor.width, textWidth + 2);
|
|
11
|
+
const colX = anchor.x + (anchor.width - colW) / 2;
|
|
12
|
+
if (position === "center") return {
|
|
13
|
+
box: {
|
|
14
|
+
x: colX,
|
|
15
|
+
y: anchor.y,
|
|
16
|
+
width: colW,
|
|
17
|
+
height: Math.max(anchor.height, labelH)
|
|
18
|
+
},
|
|
19
|
+
align: "center",
|
|
20
|
+
verticalAlign: "middle"
|
|
21
|
+
};
|
|
22
|
+
const endIsTop = anchor.valueEndSide === "top";
|
|
23
|
+
if (position === "insideEnd") return {
|
|
24
|
+
box: {
|
|
25
|
+
x: colX,
|
|
26
|
+
y: endIsTop ? anchor.y + pad : anchor.y + anchor.height - labelH - pad,
|
|
27
|
+
width: colW,
|
|
28
|
+
height: labelH
|
|
29
|
+
},
|
|
30
|
+
align: "center",
|
|
31
|
+
verticalAlign: endIsTop ? "top" : "bottom"
|
|
32
|
+
};
|
|
33
|
+
if (position === "insideBase") return {
|
|
34
|
+
box: {
|
|
35
|
+
x: colX,
|
|
36
|
+
y: endIsTop ? anchor.y + anchor.height - labelH - pad : anchor.y + pad,
|
|
37
|
+
width: colW,
|
|
38
|
+
height: labelH
|
|
39
|
+
},
|
|
40
|
+
align: "center",
|
|
41
|
+
verticalAlign: endIsTop ? "bottom" : "top"
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
box: {
|
|
45
|
+
x: colX,
|
|
46
|
+
y: endIsTop ? anchor.y - labelH - pad : anchor.y + anchor.height + pad,
|
|
47
|
+
width: colW,
|
|
48
|
+
height: labelH
|
|
49
|
+
},
|
|
50
|
+
align: "center",
|
|
51
|
+
verticalAlign: endIsTop ? "bottom" : "top"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const barW = Math.max(textWidth + 6, 12);
|
|
55
|
+
const barY = anchor.y + (anchor.height - labelH) / 2;
|
|
56
|
+
if (position === "center") return {
|
|
57
|
+
box: {
|
|
58
|
+
x: anchor.x,
|
|
59
|
+
y: barY,
|
|
60
|
+
width: Math.max(anchor.width, barW),
|
|
61
|
+
height: labelH
|
|
62
|
+
},
|
|
63
|
+
align: "center",
|
|
64
|
+
verticalAlign: "middle"
|
|
65
|
+
};
|
|
66
|
+
const endIsRight = anchor.valueEndSide === "right";
|
|
67
|
+
if (position === "insideEnd") return {
|
|
68
|
+
box: {
|
|
69
|
+
x: endIsRight ? anchor.x + anchor.width - barW - pad : anchor.x + pad,
|
|
70
|
+
y: barY,
|
|
71
|
+
width: barW,
|
|
72
|
+
height: labelH
|
|
73
|
+
},
|
|
74
|
+
align: endIsRight ? "right" : "left",
|
|
75
|
+
verticalAlign: "middle"
|
|
76
|
+
};
|
|
77
|
+
if (position === "insideBase") return {
|
|
78
|
+
box: {
|
|
79
|
+
x: endIsRight ? anchor.x + pad : anchor.x + anchor.width - barW - pad,
|
|
80
|
+
y: barY,
|
|
81
|
+
width: barW,
|
|
82
|
+
height: labelH
|
|
83
|
+
},
|
|
84
|
+
align: endIsRight ? "left" : "right",
|
|
85
|
+
verticalAlign: "middle"
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
box: {
|
|
89
|
+
x: endIsRight ? anchor.x + anchor.width + pad : anchor.x - barW - pad,
|
|
90
|
+
y: barY,
|
|
91
|
+
width: barW,
|
|
92
|
+
height: labelH
|
|
93
|
+
},
|
|
94
|
+
align: endIsRight ? "left" : "right",
|
|
95
|
+
verticalAlign: "middle"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function pointLabelBox(anchor, position, textWidth, textHeight) {
|
|
99
|
+
const offset = (anchor.markerRadius ?? 1.5) + 4;
|
|
100
|
+
const w = Math.max(textWidth + 4, 12);
|
|
101
|
+
const h = Math.max(textHeight, 10);
|
|
102
|
+
switch (position) {
|
|
103
|
+
case "center": return {
|
|
104
|
+
box: {
|
|
105
|
+
x: anchor.x - w / 2,
|
|
106
|
+
y: anchor.y - h / 2,
|
|
107
|
+
width: w,
|
|
108
|
+
height: h
|
|
109
|
+
},
|
|
110
|
+
align: "center",
|
|
111
|
+
verticalAlign: "middle"
|
|
112
|
+
};
|
|
113
|
+
case "bottom": return {
|
|
114
|
+
box: {
|
|
115
|
+
x: anchor.x - w / 2,
|
|
116
|
+
y: anchor.y + offset,
|
|
117
|
+
width: w,
|
|
118
|
+
height: h
|
|
119
|
+
},
|
|
120
|
+
align: "center",
|
|
121
|
+
verticalAlign: "top"
|
|
122
|
+
};
|
|
123
|
+
case "left": return {
|
|
124
|
+
box: {
|
|
125
|
+
x: anchor.x - offset - w,
|
|
126
|
+
y: anchor.y - h / 2,
|
|
127
|
+
width: w,
|
|
128
|
+
height: h
|
|
129
|
+
},
|
|
130
|
+
align: "right",
|
|
131
|
+
verticalAlign: "middle"
|
|
132
|
+
};
|
|
133
|
+
case "right": return {
|
|
134
|
+
box: {
|
|
135
|
+
x: anchor.x + offset,
|
|
136
|
+
y: anchor.y - h / 2,
|
|
137
|
+
width: w,
|
|
138
|
+
height: h
|
|
139
|
+
},
|
|
140
|
+
align: "left",
|
|
141
|
+
verticalAlign: "middle"
|
|
142
|
+
};
|
|
143
|
+
default: return {
|
|
144
|
+
box: {
|
|
145
|
+
x: anchor.x - w / 2,
|
|
146
|
+
y: anchor.y - offset - h,
|
|
147
|
+
width: w,
|
|
148
|
+
height: h
|
|
149
|
+
},
|
|
150
|
+
align: "center",
|
|
151
|
+
verticalAlign: "bottom"
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function sliceLabelBox(options) {
|
|
156
|
+
const { anchor, isDoughnut, requestedPosition, hasLeaderLines, textWidth, textHeight, leaderSpec, theme } = options;
|
|
157
|
+
const w = Math.max(textWidth + 4, 12);
|
|
158
|
+
const h = Math.max(textHeight, 10);
|
|
159
|
+
if (isDoughnut) {
|
|
160
|
+
const r = (anchor.innerR + anchor.outerR) / 2;
|
|
161
|
+
const lx = anchor.cx + r * Math.cos(anchor.midAngleRad);
|
|
162
|
+
const ly = anchor.cy + r * Math.sin(anchor.midAngleRad);
|
|
163
|
+
return {
|
|
164
|
+
placement: {
|
|
165
|
+
box: {
|
|
166
|
+
x: lx - w / 2,
|
|
167
|
+
y: ly - h / 2,
|
|
168
|
+
width: w,
|
|
169
|
+
height: h
|
|
170
|
+
},
|
|
171
|
+
align: "center",
|
|
172
|
+
verticalAlign: "middle"
|
|
173
|
+
},
|
|
174
|
+
leaderSvg: ""
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
let resolvedPos = requestedPosition ?? (hasLeaderLines ? "outsideEnd" : "bestFit");
|
|
178
|
+
if (resolvedPos === "bestFit") {
|
|
179
|
+
const midR = anchor.outerR * .62;
|
|
180
|
+
const spanRad = anchor.spanDeg * Math.PI / 180;
|
|
181
|
+
const chord = 2 * midR * Math.sin(Math.min(Math.PI / 2, spanRad / 2));
|
|
182
|
+
const radial = (anchor.outerR - anchor.innerR) * .7;
|
|
183
|
+
resolvedPos = !hasLeaderLines && spanRad >= .45 && w <= chord && h <= radial ? "center" : "outsideEnd";
|
|
184
|
+
}
|
|
185
|
+
if (resolvedPos === "center") {
|
|
186
|
+
const r = (anchor.innerR + anchor.outerR) * .56;
|
|
187
|
+
const lx = anchor.cx + r * Math.cos(anchor.midAngleRad);
|
|
188
|
+
const ly = anchor.cy + r * Math.sin(anchor.midAngleRad);
|
|
189
|
+
return {
|
|
190
|
+
placement: {
|
|
191
|
+
box: {
|
|
192
|
+
x: lx - w / 2,
|
|
193
|
+
y: ly - h / 2,
|
|
194
|
+
width: w,
|
|
195
|
+
height: h
|
|
196
|
+
},
|
|
197
|
+
align: "center",
|
|
198
|
+
verticalAlign: "middle"
|
|
199
|
+
},
|
|
200
|
+
leaderSvg: ""
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (resolvedPos === "insideEnd") {
|
|
204
|
+
const r = Math.max(anchor.innerR + 2, anchor.outerR - Math.max(10, (anchor.outerR - anchor.innerR) * .25));
|
|
205
|
+
const lx = anchor.cx + r * Math.cos(anchor.midAngleRad);
|
|
206
|
+
const ly = anchor.cy + r * Math.sin(anchor.midAngleRad);
|
|
207
|
+
return {
|
|
208
|
+
placement: {
|
|
209
|
+
box: {
|
|
210
|
+
x: lx - w / 2,
|
|
211
|
+
y: ly - h / 2,
|
|
212
|
+
width: w,
|
|
213
|
+
height: h
|
|
214
|
+
},
|
|
215
|
+
align: "center",
|
|
216
|
+
verticalAlign: "middle"
|
|
217
|
+
},
|
|
218
|
+
leaderSvg: ""
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const cosM = Math.cos(anchor.midAngleRad);
|
|
222
|
+
const sinM = Math.sin(anchor.midAngleRad);
|
|
223
|
+
const ax = anchor.cx + anchor.outerR * cosM;
|
|
224
|
+
const ay = anchor.cy + anchor.outerR * sinM;
|
|
225
|
+
const elbowR = anchor.outerR + 10;
|
|
226
|
+
const ex = anchor.cx + elbowR * cosM;
|
|
227
|
+
const ey = anchor.cy + elbowR * sinM;
|
|
228
|
+
const isRight = cosM >= 0;
|
|
229
|
+
const armLen = 8;
|
|
230
|
+
const lx = isRight ? ex + armLen : ex - armLen;
|
|
231
|
+
const ly = ey;
|
|
232
|
+
let leaderSvg = "";
|
|
233
|
+
if (hasLeaderLines && leaderSpec !== void 0 && leaderSpec !== false) {
|
|
234
|
+
const leaderStroke = resolveChartLineStroke(leaderSpec, theme, {
|
|
235
|
+
color: "dk2",
|
|
236
|
+
width: 1
|
|
237
|
+
});
|
|
238
|
+
if (leaderStroke !== void 0) leaderSvg = `<polyline points="${ax},${ay} ${ex},${ey} ${lx},${ly}" fill="none" ${strokeAttrs(leaderStroke)}/>`;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
placement: {
|
|
242
|
+
box: isRight ? {
|
|
243
|
+
x: lx + 2,
|
|
244
|
+
y: ly - h / 2,
|
|
245
|
+
width: w,
|
|
246
|
+
height: h
|
|
247
|
+
} : {
|
|
248
|
+
x: lx - 2 - w,
|
|
249
|
+
y: ly - h / 2,
|
|
250
|
+
width: w,
|
|
251
|
+
height: h
|
|
252
|
+
},
|
|
253
|
+
align: isRight ? "left" : "right",
|
|
254
|
+
verticalAlign: "middle"
|
|
255
|
+
},
|
|
256
|
+
leaderSvg
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function renderDataLabelsSvg(options) {
|
|
260
|
+
const { parsed, anchors, chartBox, baseChartTextStyle, theme, slideNumber, clipAllocator } = options;
|
|
261
|
+
const parts = [];
|
|
262
|
+
for (const anchor of anchors) {
|
|
263
|
+
const group = parsed.groups[anchor.groupIndex];
|
|
264
|
+
if (group === void 0) continue;
|
|
265
|
+
let series;
|
|
266
|
+
if (anchor.kind === "bar") {
|
|
267
|
+
if (group.kind !== "column" && group.kind !== "bar") continue;
|
|
268
|
+
series = group.series[anchor.groupSeriesIndex];
|
|
269
|
+
} else if (anchor.kind === "slice") {
|
|
270
|
+
if (group.kind !== "pie" && group.kind !== "doughnut") continue;
|
|
271
|
+
series = group.series[anchor.groupSeriesIndex];
|
|
272
|
+
} else {
|
|
273
|
+
if (group.kind !== "line" && group.kind !== "area" && group.kind !== "scatter") continue;
|
|
274
|
+
series = group.series[anchor.groupSeriesIndex];
|
|
275
|
+
}
|
|
276
|
+
if (series === void 0) continue;
|
|
277
|
+
const seriesMerged = mergeDataLabels(group.dataLabels, series.dataLabels);
|
|
278
|
+
const pointMerged = mergeDataLabels(seriesMerged, series.points?.[anchor.pointIndex]?.dataLabels);
|
|
279
|
+
if (pointMerged === void 0 || pointMerged === false) continue;
|
|
280
|
+
const labelSegments = [];
|
|
281
|
+
if (pointMerged.seriesName === true) labelSegments.push(anchor.seriesName);
|
|
282
|
+
if (group.kind === "scatter") {
|
|
283
|
+
if (pointMerged.xValue === true && anchor.kind === "point" && anchor.xValue !== void 0) labelSegments.push(formatChartNumber(anchor.xValue, pointMerged.numberFormat));
|
|
284
|
+
} else if (pointMerged.category === true && anchor.category !== void 0) labelSegments.push(anchor.category);
|
|
285
|
+
if (pointMerged.value === true) labelSegments.push(formatChartNumber(anchor.value, pointMerged.numberFormat));
|
|
286
|
+
if (pointMerged.percent === true && anchor.percent !== void 0) labelSegments.push(formatChartNumber(anchor.percent, pointMerged.numberFormat ?? "0%"));
|
|
287
|
+
if (labelSegments.length === 0) continue;
|
|
288
|
+
const text = labelSegments.join(pointMerged.separator ?? ", ");
|
|
289
|
+
const groupStyle = group.dataLabels !== void 0 && group.dataLabels !== false ? group.dataLabels.style : void 0;
|
|
290
|
+
const pointColor = series.points?.[anchor.pointIndex]?.labelColor;
|
|
291
|
+
const style = mergeChartTextStyle(mergeChartTextStyle(baseChartTextStyle, groupStyle), pointColor === void 0 ? void 0 : { color: pointColor });
|
|
292
|
+
const measured = measureChartText({
|
|
293
|
+
text,
|
|
294
|
+
style,
|
|
295
|
+
theme,
|
|
296
|
+
slideNumber,
|
|
297
|
+
labelPath: `Chart.groups[${anchor.groupIndex}].dataLabels`
|
|
298
|
+
});
|
|
299
|
+
const fontPx = resolveChartFontSizePixels(style?.fontSize);
|
|
300
|
+
const textH = Math.max(measured.height, fontPx * 1.15);
|
|
301
|
+
let placement;
|
|
302
|
+
if (anchor.kind === "bar") placement = barLabelBox(anchor, pointMerged.position ?? (group.kind === "column" || group.kind === "bar" ? group.stacking === "clustered" ? "outsideEnd" : "center" : "center"), measured.width, textH);
|
|
303
|
+
else if (anchor.kind === "slice") {
|
|
304
|
+
const leaderSpec = seriesMerged !== void 0 && seriesMerged !== false ? seriesMerged.leaderLines : pointMerged.leaderLines;
|
|
305
|
+
const slicePlacement = sliceLabelBox({
|
|
306
|
+
anchor,
|
|
307
|
+
isDoughnut: group.kind === "doughnut",
|
|
308
|
+
requestedPosition: pointMerged.position,
|
|
309
|
+
hasLeaderLines: leaderSpec !== void 0 && leaderSpec !== false,
|
|
310
|
+
textWidth: measured.width,
|
|
311
|
+
textHeight: textH,
|
|
312
|
+
leaderSpec,
|
|
313
|
+
theme
|
|
314
|
+
});
|
|
315
|
+
if (slicePlacement.leaderSvg !== "") parts.push(slicePlacement.leaderSvg);
|
|
316
|
+
placement = slicePlacement.placement;
|
|
317
|
+
} else placement = pointLabelBox(anchor, pointMerged.position ?? (group.kind === "scatter" ? "right" : group.kind === "area" ? "center" : "top"), measured.width, textH);
|
|
318
|
+
parts.push(renderChartTextSvg({
|
|
319
|
+
text,
|
|
320
|
+
box: placement.box,
|
|
321
|
+
style,
|
|
322
|
+
theme,
|
|
323
|
+
slideNumber,
|
|
324
|
+
labelPath: `Chart.groups[${anchor.groupIndex}].dataLabels`,
|
|
325
|
+
align: placement.align,
|
|
326
|
+
verticalAlign: placement.verticalAlign,
|
|
327
|
+
wrap: false,
|
|
328
|
+
clipBox: chartBox,
|
|
329
|
+
clipAllocator
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
return parts.join("");
|
|
333
|
+
}
|
|
334
|
+
export { renderDataLabelsSvg };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { resolveChartLineStroke, strokeAttrs } from "./style.js";
|
|
2
|
+
// ../capabilities/dist/chart/preview/error-bars.js
|
|
3
|
+
/**
|
|
4
|
+
* Computes per-slot error bar bounds in data space for any of the 5 OOXML error bar types.
|
|
5
|
+
*/
|
|
6
|
+
function computeErrorBarBounds(bars, values, options) {
|
|
7
|
+
const valid = [];
|
|
8
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
9
|
+
if (options?.skipMask?.[i]) continue;
|
|
10
|
+
const v = values[i];
|
|
11
|
+
if (v !== null && v !== void 0 && Number.isFinite(v)) valid.push(v);
|
|
12
|
+
}
|
|
13
|
+
const n = valid.length;
|
|
14
|
+
if (n === 0) return [];
|
|
15
|
+
let sum = 0;
|
|
16
|
+
for (const v of valid) sum += v;
|
|
17
|
+
const mean = sum / n;
|
|
18
|
+
let sqSum = 0;
|
|
19
|
+
for (const v of valid) {
|
|
20
|
+
const d = v - mean;
|
|
21
|
+
sqSum += d * d;
|
|
22
|
+
}
|
|
23
|
+
const stdDev = n > 1 ? Math.sqrt(sqSum / (n - 1)) : 0;
|
|
24
|
+
const stdErr = n > 1 ? stdDev / Math.sqrt(n) : 0;
|
|
25
|
+
const include = bars.include ?? "both";
|
|
26
|
+
const results = [];
|
|
27
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
28
|
+
if (options?.skipMask?.[i]) continue;
|
|
29
|
+
const raw = values[i];
|
|
30
|
+
if (raw === null || raw === void 0 || !Number.isFinite(raw)) continue;
|
|
31
|
+
let center = options?.centers?.[i] ?? raw;
|
|
32
|
+
let plusMag;
|
|
33
|
+
let minusMag;
|
|
34
|
+
switch (bars.type) {
|
|
35
|
+
case "fixed":
|
|
36
|
+
plusMag = bars.value;
|
|
37
|
+
minusMag = bars.value;
|
|
38
|
+
break;
|
|
39
|
+
case "percentage": {
|
|
40
|
+
const mag = Math.abs(raw) * (bars.value / 100);
|
|
41
|
+
plusMag = mag;
|
|
42
|
+
minusMag = mag;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case "standardError":
|
|
46
|
+
plusMag = stdErr;
|
|
47
|
+
minusMag = stdErr;
|
|
48
|
+
break;
|
|
49
|
+
case "standardDeviation": {
|
|
50
|
+
center = mean;
|
|
51
|
+
const mag = bars.value * stdDev;
|
|
52
|
+
plusMag = mag;
|
|
53
|
+
minusMag = mag;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case "custom":
|
|
57
|
+
plusMag = bars.plus?.[i] !== null && bars.plus?.[i] !== void 0 ? bars.plus[i] : void 0;
|
|
58
|
+
minusMag = bars.minus?.[i] !== null && bars.minus?.[i] !== void 0 ? bars.minus[i] : void 0;
|
|
59
|
+
}
|
|
60
|
+
const hasPlus = (include === "both" || include === "plus") && plusMag !== void 0 && Number.isFinite(plusMag);
|
|
61
|
+
const hasMinus = (include === "both" || include === "minus") && minusMag !== void 0 && Number.isFinite(minusMag);
|
|
62
|
+
if (!hasPlus && !hasMinus) continue;
|
|
63
|
+
results.push({
|
|
64
|
+
index: i,
|
|
65
|
+
low: hasMinus ? center - minusMag : center,
|
|
66
|
+
high: hasPlus ? center + plusMag : center,
|
|
67
|
+
hasPlus,
|
|
68
|
+
hasMinus
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
function clampForScale(value, scale) {
|
|
74
|
+
if (scale.logBase !== void 0 && value <= 0) return scale.min;
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
function renderSingleErrorBarSvg(options) {
|
|
78
|
+
const { bound, crossCoord, axisScale, horizontal, plotRect, endCap, strokeAttr } = options;
|
|
79
|
+
const lowCoord = axisScale.valueToScreen(clampForScale(bound.low, axisScale), plotRect);
|
|
80
|
+
const highCoord = axisScale.valueToScreen(clampForScale(bound.high, axisScale), plotRect);
|
|
81
|
+
const capHalf = 3;
|
|
82
|
+
if (horizontal) {
|
|
83
|
+
const segs = [`<line x1="${lowCoord}" y1="${crossCoord}" x2="${highCoord}" y2="${crossCoord}" ${strokeAttr} fill="none"/>`];
|
|
84
|
+
if (endCap) {
|
|
85
|
+
if (bound.hasPlus) segs.push(`<line x1="${highCoord}" y1="${crossCoord - capHalf}" x2="${highCoord}" y2="${crossCoord + capHalf}" ${strokeAttr} fill="none"/>`);
|
|
86
|
+
if (bound.hasMinus) segs.push(`<line x1="${lowCoord}" y1="${crossCoord - capHalf}" x2="${lowCoord}" y2="${crossCoord + capHalf}" ${strokeAttr} fill="none"/>`);
|
|
87
|
+
}
|
|
88
|
+
return segs.join("");
|
|
89
|
+
}
|
|
90
|
+
const segs = [`<line x1="${crossCoord}" y1="${highCoord}" x2="${crossCoord}" y2="${lowCoord}" ${strokeAttr} fill="none"/>`];
|
|
91
|
+
if (endCap) {
|
|
92
|
+
if (bound.hasPlus) segs.push(`<line x1="${crossCoord - capHalf}" y1="${highCoord}" x2="${crossCoord + capHalf}" y2="${highCoord}" ${strokeAttr} fill="none"/>`);
|
|
93
|
+
if (bound.hasMinus) segs.push(`<line x1="${crossCoord - capHalf}" y1="${lowCoord}" x2="${crossCoord + capHalf}" y2="${lowCoord}" ${strokeAttr} fill="none"/>`);
|
|
94
|
+
}
|
|
95
|
+
return segs.join("");
|
|
96
|
+
}
|
|
97
|
+
function renderErrorBarsSvg(options) {
|
|
98
|
+
const { parsed, anchors, scales, plotRect, theme } = options;
|
|
99
|
+
const anchorMap = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const anchor of anchors) {
|
|
101
|
+
if (anchor.kind === "slice") continue;
|
|
102
|
+
anchorMap.set(`${anchor.groupIndex}:${anchor.groupSeriesIndex}:${anchor.pointIndex}`, anchor);
|
|
103
|
+
}
|
|
104
|
+
const parts = [];
|
|
105
|
+
for (let groupIndex = 0; groupIndex < parsed.groups.length; groupIndex += 1) {
|
|
106
|
+
const group = parsed.groups[groupIndex];
|
|
107
|
+
if (group.kind === "pie" || group.kind === "doughnut") continue;
|
|
108
|
+
if (group.kind === "scatter") {
|
|
109
|
+
const xScale = scales.get(group.axes.x.name);
|
|
110
|
+
const yScale = scales.get(group.axes.y.name);
|
|
111
|
+
if (xScale?.kind !== "value" || yScale?.kind !== "value") continue;
|
|
112
|
+
for (let s = 0; s < group.series.length; s += 1) {
|
|
113
|
+
const series = group.series[s];
|
|
114
|
+
const xBars = series.errorBars?.x;
|
|
115
|
+
const yBars = series.errorBars?.y;
|
|
116
|
+
if (xBars === void 0 && yBars === void 0) continue;
|
|
117
|
+
const skipMask = series.x.map((_, i) => !anchorMap.has(`${groupIndex}:${s}:${i}`));
|
|
118
|
+
if (xBars !== void 0) {
|
|
119
|
+
const stroke = resolveChartLineStroke(xBars.line, theme, {
|
|
120
|
+
color: "dk1",
|
|
121
|
+
width: 1
|
|
122
|
+
});
|
|
123
|
+
if (stroke !== void 0) {
|
|
124
|
+
const strokeAttr = strokeAttrs(stroke);
|
|
125
|
+
const bounds = computeErrorBarBounds(xBars, series.x.map((v, i) => {
|
|
126
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${i}`);
|
|
127
|
+
return a?.kind === "point" ? a.xValue ?? v : v;
|
|
128
|
+
}), { skipMask });
|
|
129
|
+
for (const bound of bounds) {
|
|
130
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${bound.index}`);
|
|
131
|
+
if (a?.kind !== "point") continue;
|
|
132
|
+
parts.push(renderSingleErrorBarSvg({
|
|
133
|
+
bound,
|
|
134
|
+
crossCoord: a.y,
|
|
135
|
+
axisScale: xScale,
|
|
136
|
+
horizontal: true,
|
|
137
|
+
plotRect,
|
|
138
|
+
endCap: xBars.endCap !== false,
|
|
139
|
+
strokeAttr
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (yBars !== void 0) {
|
|
145
|
+
const stroke = resolveChartLineStroke(yBars.line, theme, {
|
|
146
|
+
color: "dk1",
|
|
147
|
+
width: 1
|
|
148
|
+
});
|
|
149
|
+
if (stroke !== void 0) {
|
|
150
|
+
const strokeAttr = strokeAttrs(stroke);
|
|
151
|
+
const bounds = computeErrorBarBounds(yBars, series.y.map((v, i) => {
|
|
152
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${i}`);
|
|
153
|
+
return a?.kind === "point" ? a.value : v;
|
|
154
|
+
}), { skipMask });
|
|
155
|
+
for (const bound of bounds) {
|
|
156
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${bound.index}`);
|
|
157
|
+
if (a?.kind !== "point") continue;
|
|
158
|
+
parts.push(renderSingleErrorBarSvg({
|
|
159
|
+
bound,
|
|
160
|
+
crossCoord: a.x,
|
|
161
|
+
axisScale: yScale,
|
|
162
|
+
horizontal: false,
|
|
163
|
+
plotRect,
|
|
164
|
+
endCap: yBars.endCap !== false,
|
|
165
|
+
strokeAttr
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const valScale = scales.get(group.axes.value.name);
|
|
174
|
+
if (valScale?.kind !== "value") continue;
|
|
175
|
+
const isHorizontal = group.kind === "bar";
|
|
176
|
+
for (let s = 0; s < group.series.length; s += 1) {
|
|
177
|
+
const series = group.series[s];
|
|
178
|
+
const bars = series.errorBars;
|
|
179
|
+
if (bars === void 0) continue;
|
|
180
|
+
const stroke = resolveChartLineStroke(bars.line, theme, {
|
|
181
|
+
color: "dk1",
|
|
182
|
+
width: 1
|
|
183
|
+
});
|
|
184
|
+
if (stroke === void 0) continue;
|
|
185
|
+
const strokeAttr = strokeAttrs(stroke);
|
|
186
|
+
const skipMask = series.values.map((_, i) => !anchorMap.has(`${groupIndex}:${s}:${i}`));
|
|
187
|
+
const centers = series.values.map((_, i) => {
|
|
188
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${i}`);
|
|
189
|
+
return a !== void 0 && a.kind !== "slice" ? a.plottedValue : void 0;
|
|
190
|
+
});
|
|
191
|
+
const bounds = computeErrorBarBounds(bars, series.values, {
|
|
192
|
+
centers,
|
|
193
|
+
skipMask
|
|
194
|
+
});
|
|
195
|
+
for (const bound of bounds) {
|
|
196
|
+
const a = anchorMap.get(`${groupIndex}:${s}:${bound.index}`);
|
|
197
|
+
if (a === void 0 || a.kind === "slice") continue;
|
|
198
|
+
const crossCoord = a.kind === "bar" ? isHorizontal ? a.y + a.height / 2 : a.x + a.width / 2 : a.x;
|
|
199
|
+
parts.push(renderSingleErrorBarSvg({
|
|
200
|
+
bound,
|
|
201
|
+
crossCoord,
|
|
202
|
+
axisScale: valScale,
|
|
203
|
+
horizontal: isHorizontal,
|
|
204
|
+
plotRect,
|
|
205
|
+
endCap: bars.endCap !== false,
|
|
206
|
+
strokeAttr
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return parts.join("");
|
|
212
|
+
}
|
|
213
|
+
export { computeErrorBarBounds, renderErrorBarsSvg };
|