@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,100 @@
|
|
|
1
|
+
import { resolveChartLineStroke, resolveSeriesColor, strokeAttrs } from "./style.js";
|
|
2
|
+
import { assertNever } from "./types.js";
|
|
3
|
+
// ../capabilities/dist/chart/preview/markers.js
|
|
4
|
+
const DEFAULT_MARKER_SIZE_PT = 5;
|
|
5
|
+
const AUTO_MARKER_SYMBOLS = [
|
|
6
|
+
"diamond",
|
|
7
|
+
"square",
|
|
8
|
+
"triangle",
|
|
9
|
+
"x",
|
|
10
|
+
"star",
|
|
11
|
+
"circle",
|
|
12
|
+
"plus",
|
|
13
|
+
"dot",
|
|
14
|
+
"dash"
|
|
15
|
+
];
|
|
16
|
+
function asMarkerObject(value) {
|
|
17
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves effective marker geometry and styling by merging point-level overrides over series
|
|
21
|
+
* and group defaults, converting size from points to pixel radius.
|
|
22
|
+
*/
|
|
23
|
+
function resolveEffectiveMarker(options) {
|
|
24
|
+
const { groupDefaultEnabled, seriesMarker, pointMarker, seriesColor, pointColor, seriesIndex, theme } = options;
|
|
25
|
+
let enabled;
|
|
26
|
+
if (pointMarker === false) enabled = false;
|
|
27
|
+
else if (pointMarker !== void 0) enabled = true;
|
|
28
|
+
else if (seriesMarker === false) enabled = false;
|
|
29
|
+
else if (seriesMarker !== void 0) enabled = true;
|
|
30
|
+
else enabled = groupDefaultEnabled;
|
|
31
|
+
if (!enabled) return void 0;
|
|
32
|
+
const seriesObj = asMarkerObject(seriesMarker);
|
|
33
|
+
const pointObj = asMarkerObject(pointMarker);
|
|
34
|
+
const rawSymbol = pointMarker === true ? seriesObj?.symbol ?? "circle" : pointObj?.symbol ?? seriesObj?.symbol ?? "circle";
|
|
35
|
+
if (rawSymbol === "none") return void 0;
|
|
36
|
+
const symbol = rawSymbol === "auto" ? AUTO_MARKER_SYMBOLS[seriesIndex % AUTO_MARKER_SYMBOLS.length] : rawSymbol;
|
|
37
|
+
const radius = (pointObj?.size ?? seriesObj?.size ?? DEFAULT_MARKER_SIZE_PT) * (4 / 3) / 2;
|
|
38
|
+
const fillColor = resolveSeriesColor(pointObj?.fill ?? seriesObj?.fill ?? pointColor ?? seriesColor, seriesIndex, theme);
|
|
39
|
+
const fillHex = fillColor.hex;
|
|
40
|
+
const fillAlpha = fillColor.alpha ?? 1;
|
|
41
|
+
const lineSpec = pointObj?.line ?? seriesObj?.line;
|
|
42
|
+
const explicitStroke = lineSpec === void 0 ? void 0 : resolveChartLineStroke(lineSpec, theme, {
|
|
43
|
+
color: "dk1",
|
|
44
|
+
width: 1
|
|
45
|
+
});
|
|
46
|
+
const stroke = symbol === "plus" || symbol === "x" || symbol === "star" ? explicitStroke ?? {
|
|
47
|
+
hex: fillHex,
|
|
48
|
+
alpha: fillAlpha,
|
|
49
|
+
width: Math.max(1.25, radius * .35)
|
|
50
|
+
} : explicitStroke;
|
|
51
|
+
return {
|
|
52
|
+
symbol,
|
|
53
|
+
radius,
|
|
54
|
+
fillHex,
|
|
55
|
+
fillAlpha,
|
|
56
|
+
...stroke === void 0 ? {} : { stroke }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders one SVG marker glyph centered at `(cx, cy)` covering all 11 OOXML marker symbols.
|
|
61
|
+
*/
|
|
62
|
+
function renderMarkerSvg(cx, cy, marker) {
|
|
63
|
+
const r = marker.radius;
|
|
64
|
+
const fillAttr = `fill="#${marker.fillHex}" fill-opacity="${marker.fillAlpha}"`;
|
|
65
|
+
const strokeAttr = marker.stroke === void 0 ? "" : ` ${strokeAttrs(marker.stroke)}`;
|
|
66
|
+
switch (marker.symbol) {
|
|
67
|
+
case "circle": return `<circle cx="${cx}" cy="${cy}" r="${r}" ${fillAttr}${strokeAttr}/>`;
|
|
68
|
+
case "square": return `<rect x="${cx - r}" y="${cy - r}" width="${2 * r}" height="${2 * r}" ${fillAttr}${strokeAttr}/>`;
|
|
69
|
+
case "diamond": return `<path d="M${cx} ${cy - r}L${cx + r} ${cy}L${cx} ${cy + r}L${cx - r} ${cy}Z" ${fillAttr}${strokeAttr}/>`;
|
|
70
|
+
case "triangle": return `<path d="M${cx} ${cy - r}L${cx + r} ${cy + r}L${cx - r} ${cy + r}Z" ${fillAttr}${strokeAttr}/>`;
|
|
71
|
+
case "plus": {
|
|
72
|
+
const stroke = marker.stroke ?? {
|
|
73
|
+
hex: marker.fillHex,
|
|
74
|
+
alpha: marker.fillAlpha,
|
|
75
|
+
width: Math.max(1.25, r * .35)
|
|
76
|
+
};
|
|
77
|
+
return `<path d="M${cx - r} ${cy}H${cx + r}M${cx} ${cy - r}V${cy + r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
|
|
78
|
+
}
|
|
79
|
+
case "x": {
|
|
80
|
+
const stroke = marker.stroke ?? {
|
|
81
|
+
hex: marker.fillHex,
|
|
82
|
+
alpha: marker.fillAlpha,
|
|
83
|
+
width: Math.max(1.25, r * .35)
|
|
84
|
+
};
|
|
85
|
+
return `<path d="M${cx - r} ${cy - r}L${cx + r} ${cy + r}M${cx - r} ${cy + r}L${cx + r} ${cy - r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
|
|
86
|
+
}
|
|
87
|
+
case "star": {
|
|
88
|
+
const stroke = marker.stroke ?? {
|
|
89
|
+
hex: marker.fillHex,
|
|
90
|
+
alpha: marker.fillAlpha,
|
|
91
|
+
width: Math.max(1.25, r * .35)
|
|
92
|
+
};
|
|
93
|
+
return `<path d="M${cx - r} ${cy - r}L${cx + r} ${cy + r}M${cx - r} ${cy + r}L${cx + r} ${cy - r}M${cx} ${cy - r}V${cy + r}" fill="none" ${strokeAttrs(stroke)} stroke-linecap="round"/>`;
|
|
94
|
+
}
|
|
95
|
+
case "dot": return `<rect x="${cx}" y="${cy - r * .25}" width="${r}" height="${r * .5}" ${fillAttr}${strokeAttr}/>`;
|
|
96
|
+
case "dash": return `<rect x="${cx - r}" y="${cy - r * .25}" width="${2 * r}" height="${r * .5}" ${fillAttr}${strokeAttr}/>`;
|
|
97
|
+
default: return assertNever(marker.symbol);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export { renderMarkerSvg, resolveEffectiveMarker };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// ../capabilities/dist/chart/preview/number-format.js
|
|
2
|
+
function splitSections(formatCode) {
|
|
3
|
+
const sections = [];
|
|
4
|
+
let current = "";
|
|
5
|
+
let inQuotes = false;
|
|
6
|
+
let inBracket = false;
|
|
7
|
+
for (let i = 0; i < formatCode.length; i += 1) {
|
|
8
|
+
const ch = formatCode[i];
|
|
9
|
+
if (inQuotes) {
|
|
10
|
+
current += ch;
|
|
11
|
+
if (ch === "\"") inQuotes = false;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (ch === "\\" || ch === "_") {
|
|
15
|
+
current += ch + (formatCode[i + 1] ?? "");
|
|
16
|
+
i += 1;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (ch === "[") {
|
|
20
|
+
inBracket = true;
|
|
21
|
+
current += ch;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (inBracket) {
|
|
25
|
+
current += ch;
|
|
26
|
+
if (ch === "]") inBracket = false;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (ch === "\"") {
|
|
30
|
+
inQuotes = true;
|
|
31
|
+
current += ch;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (ch === ";") {
|
|
35
|
+
sections.push(current);
|
|
36
|
+
current = "";
|
|
37
|
+
if (sections.length === 3) {
|
|
38
|
+
sections.push(formatCode.slice(i + 1));
|
|
39
|
+
return sections;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
current += ch;
|
|
44
|
+
}
|
|
45
|
+
sections.push(current);
|
|
46
|
+
return sections;
|
|
47
|
+
}
|
|
48
|
+
function tokenizeSection(section) {
|
|
49
|
+
const tokens = [];
|
|
50
|
+
for (let i = 0; i < section.length; i += 1) {
|
|
51
|
+
const ch = section[i];
|
|
52
|
+
if (ch === "\"") {
|
|
53
|
+
let literal = "";
|
|
54
|
+
for (i += 1; i < section.length; i += 1) {
|
|
55
|
+
if (section[i] === "\"") break;
|
|
56
|
+
literal += section[i];
|
|
57
|
+
}
|
|
58
|
+
if (literal !== "") tokens.push({
|
|
59
|
+
kind: "literal",
|
|
60
|
+
text: literal
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === "\\" || ch === "*") {
|
|
65
|
+
const next = section[i + 1];
|
|
66
|
+
if (next !== void 0) {
|
|
67
|
+
tokens.push({
|
|
68
|
+
kind: "literal",
|
|
69
|
+
text: next
|
|
70
|
+
});
|
|
71
|
+
i += 1;
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (ch === "_") {
|
|
76
|
+
i += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === "[") {
|
|
80
|
+
const end = section.indexOf("]", i + 1);
|
|
81
|
+
if (end >= 0) {
|
|
82
|
+
const directive = section.slice(i + 1, end);
|
|
83
|
+
if (directive.startsWith("$")) {
|
|
84
|
+
const rest = directive.slice(1);
|
|
85
|
+
const dash = rest.indexOf("-");
|
|
86
|
+
const currency = dash < 0 ? rest : rest.slice(0, dash);
|
|
87
|
+
if (currency !== "") tokens.push({
|
|
88
|
+
kind: "literal",
|
|
89
|
+
text: currency
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
i = end;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (ch === "0" || ch === "#" || ch === "?") {
|
|
97
|
+
tokens.push({
|
|
98
|
+
kind: "digit",
|
|
99
|
+
ch
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (ch === ".") {
|
|
104
|
+
tokens.push({ kind: "dot" });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (ch === ",") {
|
|
108
|
+
tokens.push({ kind: "comma" });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (ch === "%") {
|
|
112
|
+
tokens.push({ kind: "percent" });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (ch === "E" || ch === "e") {
|
|
116
|
+
const next = section[i + 1];
|
|
117
|
+
if (next === "+" || next === "-") {
|
|
118
|
+
tokens.push({
|
|
119
|
+
kind: "exp",
|
|
120
|
+
sign: next
|
|
121
|
+
});
|
|
122
|
+
i += 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if ((ch === "G" || ch === "g") && section.slice(i, i + 7).toLowerCase() === "general" && (section[i + 7] === void 0 || !/[a-z]/iu.test(section[i + 7]))) {
|
|
127
|
+
tokens.push({ kind: "general" });
|
|
128
|
+
i += 6;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
tokens.push({
|
|
132
|
+
kind: "literal",
|
|
133
|
+
text: ch
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return tokens;
|
|
137
|
+
}
|
|
138
|
+
function formatGeneral(value) {
|
|
139
|
+
if (Object.is(value, -0) || value === 0) return "0";
|
|
140
|
+
const clean = Number(value.toPrecision(12));
|
|
141
|
+
return String(clean);
|
|
142
|
+
}
|
|
143
|
+
function addGrouping(intStr) {
|
|
144
|
+
if (intStr.length <= 3) return intStr;
|
|
145
|
+
return intStr.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
146
|
+
}
|
|
147
|
+
function formatFixedParts(absValue, minInt, minFrac, maxFrac, useGrouping) {
|
|
148
|
+
const clampedFrac = Math.min(Math.max(0, maxFrac), 20);
|
|
149
|
+
const fixed = absValue.toFixed(clampedFrac);
|
|
150
|
+
const dotIdx = fixed.indexOf(".");
|
|
151
|
+
let intPart = dotIdx < 0 ? fixed : fixed.slice(0, dotIdx);
|
|
152
|
+
let fracPart = dotIdx < 0 ? "" : fixed.slice(dotIdx + 1);
|
|
153
|
+
if (intPart === "0" && minInt === 0) intPart = "";
|
|
154
|
+
else if (intPart.length < minInt) intPart = intPart.padStart(minInt, "0");
|
|
155
|
+
if (useGrouping && intPart.length > 3) intPart = addGrouping(intPart);
|
|
156
|
+
while (fracPart.length > minFrac && fracPart.endsWith("0")) fracPart = fracPart.slice(0, -1);
|
|
157
|
+
if (intPart === "" && fracPart === "" && minFrac === 0) return "";
|
|
158
|
+
return fracPart.length > 0 ? `${intPart}.${fracPart}` : intPart;
|
|
159
|
+
}
|
|
160
|
+
function formatSection(absValue, section) {
|
|
161
|
+
if (section === "") return "";
|
|
162
|
+
const tokens = tokenizeSection(section);
|
|
163
|
+
if (tokens.some((token) => token.kind === "general")) return tokens.map((token) => {
|
|
164
|
+
if (token.kind === "general") return formatGeneral(absValue);
|
|
165
|
+
if (token.kind === "literal") return token.text;
|
|
166
|
+
if (token.kind === "percent") return "%";
|
|
167
|
+
return "";
|
|
168
|
+
}).join("");
|
|
169
|
+
let firstNumIdx = -1;
|
|
170
|
+
let lastNumIdx = -1;
|
|
171
|
+
let lastDigitIdx = -1;
|
|
172
|
+
let expIdx = -1;
|
|
173
|
+
let expSignToken = "+";
|
|
174
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
175
|
+
const token = tokens[i];
|
|
176
|
+
if (token.kind === "digit" || token.kind === "dot") {
|
|
177
|
+
if (firstNumIdx < 0) firstNumIdx = i;
|
|
178
|
+
lastNumIdx = i;
|
|
179
|
+
}
|
|
180
|
+
if (token.kind === "digit") lastDigitIdx = i;
|
|
181
|
+
if (token.kind === "exp" && expIdx < 0) {
|
|
182
|
+
expIdx = i;
|
|
183
|
+
expSignToken = token.sign;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
let scaled = absValue;
|
|
187
|
+
let percentCount = 0;
|
|
188
|
+
for (const token of tokens) if (token.kind === "percent") percentCount += 1;
|
|
189
|
+
if (percentCount > 0) scaled *= 100 ** percentCount;
|
|
190
|
+
let trailingCommas = 0;
|
|
191
|
+
if (lastDigitIdx >= 0) for (let i = lastDigitIdx + 1; i < tokens.length; i += 1) {
|
|
192
|
+
const token = tokens[i];
|
|
193
|
+
if (token.kind === "comma") {
|
|
194
|
+
trailingCommas += 1;
|
|
195
|
+
lastNumIdx = Math.max(lastNumIdx, i);
|
|
196
|
+
} else if (token.kind === "literal" || token.kind === "percent") break;
|
|
197
|
+
}
|
|
198
|
+
if (trailingCommas > 0 && expIdx < 0) scaled /= 1e3 ** trailingCommas;
|
|
199
|
+
if (firstNumIdx < 0) return tokens.map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
|
|
200
|
+
const prefix = tokens.slice(0, firstNumIdx).map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
|
|
201
|
+
const suffix = tokens.slice(lastNumIdx + 1).map((token) => token.kind === "literal" ? token.text : token.kind === "percent" ? "%" : "").join("");
|
|
202
|
+
if (expIdx >= 0 && expIdx > firstNumIdx) {
|
|
203
|
+
const mantissaTokens = tokens.slice(firstNumIdx, expIdx);
|
|
204
|
+
const expTokens = tokens.slice(expIdx + 1, lastNumIdx + 1);
|
|
205
|
+
const dotPos = mantissaTokens.findIndex((token) => token.kind === "dot");
|
|
206
|
+
const intDigits = (dotPos < 0 ? mantissaTokens : mantissaTokens.slice(0, dotPos)).filter((token) => token.kind === "digit");
|
|
207
|
+
const fracDigits = (dotPos < 0 ? [] : mantissaTokens.slice(dotPos + 1)).filter((token) => token.kind === "digit");
|
|
208
|
+
const expMinDigits = expTokens.filter((token) => token.kind === "digit" && token.ch === "0").length;
|
|
209
|
+
const minInt = intDigits.filter((token) => token.ch === "0").length;
|
|
210
|
+
const minFrac = fracDigits.filter((token) => token.ch === "0").length;
|
|
211
|
+
const maxFrac = fracDigits.length;
|
|
212
|
+
let expVal = 0;
|
|
213
|
+
let mantissa = 0;
|
|
214
|
+
if (scaled > 0) {
|
|
215
|
+
const leadDigits = Math.max(1, intDigits.length);
|
|
216
|
+
expVal = Math.floor(Math.log10(scaled)) - (leadDigits - 1);
|
|
217
|
+
mantissa = scaled / 10 ** expVal;
|
|
218
|
+
}
|
|
219
|
+
return `${prefix}${formatFixedParts(mantissa, Math.max(1, minInt), minFrac, maxFrac, false)}E${expVal < 0 ? "-" : expSignToken === "+" ? "+" : ""}${String(Math.abs(expVal)).padStart(Math.max(1, expMinDigits), "0")}${suffix}`;
|
|
220
|
+
}
|
|
221
|
+
const numTokens = tokens.slice(firstNumIdx, lastNumIdx + 1);
|
|
222
|
+
const dotPos = numTokens.findIndex((token) => token.kind === "dot");
|
|
223
|
+
const intTokens = dotPos < 0 ? numTokens : numTokens.slice(0, dotPos);
|
|
224
|
+
const fracTokens = dotPos < 0 ? [] : numTokens.slice(dotPos + 1);
|
|
225
|
+
const minInt = intTokens.filter((token) => token.kind === "digit" && token.ch === "0").length;
|
|
226
|
+
const useGrouping = intTokens.some((token) => token.kind === "comma");
|
|
227
|
+
const fracDigits = fracTokens.filter((token) => token.kind === "digit");
|
|
228
|
+
const minFrac = fracDigits.filter((token) => token.kind === "digit" && token.ch === "0").length;
|
|
229
|
+
const maxFrac = fracDigits.length;
|
|
230
|
+
return `${prefix}${formatFixedParts(scaled, minInt, minFrac, maxFrac, useGrouping)}${numTokens.filter((token) => token.kind === "percent").map(() => "%").join("")}${suffix}`;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Formats a numeric chart value using an Excel/OOXML number format string.
|
|
234
|
+
*/
|
|
235
|
+
function formatChartNumber(value, formatCode) {
|
|
236
|
+
if (!Number.isFinite(value)) return String(value);
|
|
237
|
+
if (formatCode === void 0 || formatCode.trim().toLowerCase() === "general") return formatGeneral(value);
|
|
238
|
+
const sections = splitSections(formatCode);
|
|
239
|
+
const normalized = Object.is(value, -0) ? 0 : value;
|
|
240
|
+
if (normalized === 0 && sections.length >= 3) return formatSection(0, sections[2]);
|
|
241
|
+
if (normalized < 0) {
|
|
242
|
+
if (sections.length >= 2) return formatSection(Math.abs(normalized), sections[1]);
|
|
243
|
+
return `-${formatSection(Math.abs(normalized), sections[0])}`;
|
|
244
|
+
}
|
|
245
|
+
return formatSection(normalized, sections[0]);
|
|
246
|
+
}
|
|
247
|
+
export { formatChartNumber };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { mergeDataLabels } from "../chart-labels.js";
|
|
2
|
+
import { resolveChartLineStroke, resolveSeriesColor, strokeAttrs } from "./style.js";
|
|
3
|
+
// ../capabilities/dist/chart/preview/pie-doughnut.js
|
|
4
|
+
function toScreenRadians(degreesClockwiseFromTop) {
|
|
5
|
+
return (degreesClockwiseFromTop - 90) * Math.PI / 180;
|
|
6
|
+
}
|
|
7
|
+
function hasOuterSliceLabels(group) {
|
|
8
|
+
if (group.kind === "doughnut") return false;
|
|
9
|
+
const series = group.series[0];
|
|
10
|
+
for (let i = 0; i < series.values.length; i += 1) {
|
|
11
|
+
const val = series.values[i];
|
|
12
|
+
if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
|
|
13
|
+
const eff = mergeDataLabels(mergeDataLabels(group.dataLabels, series.dataLabels), series.points?.[i]?.dataLabels);
|
|
14
|
+
if (eff === void 0 || eff === false) continue;
|
|
15
|
+
if (!(eff.value === true || eff.percent === true || eff.category === true || eff.seriesName === true)) continue;
|
|
16
|
+
const pos = eff.position ?? "bestFit";
|
|
17
|
+
if (pos === "outsideEnd" || pos === "bestFit") return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function buildSlicePath(options) {
|
|
22
|
+
const { ox, oy, innerR, outerR, startRad, endRad, spanDeg } = options;
|
|
23
|
+
if (spanDeg >= 359.999) {
|
|
24
|
+
const oppRad = startRad + Math.PI;
|
|
25
|
+
const ox1 = ox + outerR * Math.cos(startRad);
|
|
26
|
+
const oy1 = oy + outerR * Math.sin(startRad);
|
|
27
|
+
const ox2 = ox + outerR * Math.cos(oppRad);
|
|
28
|
+
const oy2 = oy + outerR * Math.sin(oppRad);
|
|
29
|
+
if (innerR <= .001) return {
|
|
30
|
+
d: `M${ox1} ${oy1}A${outerR} ${outerR} 0 1 1 ${ox2} ${oy2}A${outerR} ${outerR} 0 1 1 ${ox1} ${oy1}Z`,
|
|
31
|
+
fullCircle: true
|
|
32
|
+
};
|
|
33
|
+
const ix1 = ox + innerR * Math.cos(startRad);
|
|
34
|
+
const iy1 = oy + innerR * Math.sin(startRad);
|
|
35
|
+
return {
|
|
36
|
+
d: `M${ox1} ${oy1}A${outerR} ${outerR} 0 1 1 ${ox2} ${oy2}A${outerR} ${outerR} 0 1 1 ${ox1} ${oy1}M${ix1} ${iy1}A${innerR} ${innerR} 0 1 0 ${ox + innerR * Math.cos(oppRad)} ${oy + innerR * Math.sin(oppRad)}A${innerR} ${innerR} 0 1 0 ${ix1} ${iy1}Z`,
|
|
37
|
+
fullCircle: true
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const largeArc = spanDeg > 180 ? 1 : 0;
|
|
41
|
+
const x1 = ox + outerR * Math.cos(startRad);
|
|
42
|
+
const y1 = oy + outerR * Math.sin(startRad);
|
|
43
|
+
const x2 = ox + outerR * Math.cos(endRad);
|
|
44
|
+
const y2 = oy + outerR * Math.sin(endRad);
|
|
45
|
+
if (innerR <= .001) return {
|
|
46
|
+
d: `M${ox} ${oy}L${x1} ${y1}A${outerR} ${outerR} 0 ${largeArc} 1 ${x2} ${y2}Z`,
|
|
47
|
+
fullCircle: false
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
d: `M${x1} ${y1}A${outerR} ${outerR} 0 ${largeArc} 1 ${x2} ${y2}L${ox + innerR * Math.cos(endRad)} ${oy + innerR * Math.sin(endRad)}A${innerR} ${innerR} 0 ${largeArc} 0 ${ox + innerR * Math.cos(startRad)} ${oy + innerR * Math.sin(startRad)}Z`,
|
|
51
|
+
fullCircle: false
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Renders pie and single/multi-ring doughnut chart groups with explosion, holeSize,
|
|
56
|
+
* custom starting angle, and slice anchors for data labels and leader lines.
|
|
57
|
+
*/
|
|
58
|
+
function renderPieOrDoughnutGroup(options) {
|
|
59
|
+
const { group, groupIndex, plotRect, theme } = options;
|
|
60
|
+
if (group.series.length === 0 || plotRect.width <= 0 || plotRect.height <= 0) return {
|
|
61
|
+
svg: "",
|
|
62
|
+
anchors: []
|
|
63
|
+
};
|
|
64
|
+
let maxExpRatio = 0;
|
|
65
|
+
for (const series of group.series) for (let j = 0; j < series.values.length; j += 1) {
|
|
66
|
+
const val = series.values[j];
|
|
67
|
+
if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
|
|
68
|
+
const exp = series.points?.[j]?.explosion ?? series.explosion ?? group.explosion ?? 0;
|
|
69
|
+
const ratio = Math.min(Math.max(0, exp), 100) / 100;
|
|
70
|
+
if (ratio > maxExpRatio) maxExpRatio = ratio;
|
|
71
|
+
}
|
|
72
|
+
const radiusScale = hasOuterSliceLabels(group) ? .68 : .88;
|
|
73
|
+
const rAvail = Math.min(plotRect.width, plotRect.height) / 2 * radiusScale;
|
|
74
|
+
const rOuterTotal = Math.max(2, rAvail / (1 + maxExpRatio));
|
|
75
|
+
const cx = plotRect.x + plotRect.width / 2;
|
|
76
|
+
const cy = plotRect.y + plotRect.height / 2;
|
|
77
|
+
const ringCount = group.kind === "pie" ? 1 : group.series.length;
|
|
78
|
+
const rHole = rOuterTotal * (group.kind === "doughnut" ? Math.max(.1, Math.min(.9, group.holeSize / 100)) : 0);
|
|
79
|
+
const ringThickness = (rOuterTotal - rHole) / Math.max(1, ringCount);
|
|
80
|
+
const parts = [];
|
|
81
|
+
const anchors = [];
|
|
82
|
+
for (let s = 0; s < group.series.length; s += 1) {
|
|
83
|
+
const series = group.series[s];
|
|
84
|
+
const rIn = group.kind === "pie" ? 0 : rHole + s * ringThickness;
|
|
85
|
+
const rOut = group.kind === "pie" ? rOuterTotal : rHole + (s + 1) * ringThickness;
|
|
86
|
+
let ringTotal = 0;
|
|
87
|
+
let positiveCount = 0;
|
|
88
|
+
for (const v of series.values) if (v !== null && v !== void 0 && Number.isFinite(v) && v > 0) {
|
|
89
|
+
ringTotal += v;
|
|
90
|
+
positiveCount += 1;
|
|
91
|
+
}
|
|
92
|
+
if (ringTotal <= 0) continue;
|
|
93
|
+
let currentDeg = group.firstSliceAngle;
|
|
94
|
+
for (let j = 0; j < series.values.length; j += 1) {
|
|
95
|
+
const val = series.values[j];
|
|
96
|
+
if (val === null || val === void 0 || !Number.isFinite(val) || val <= 0) continue;
|
|
97
|
+
const spanDeg = val / ringTotal * 360;
|
|
98
|
+
const startDeg = currentDeg;
|
|
99
|
+
const endDeg = startDeg + spanDeg;
|
|
100
|
+
const midDeg = startDeg + spanDeg / 2;
|
|
101
|
+
currentDeg = endDeg;
|
|
102
|
+
const startRad = toScreenRadians(startDeg);
|
|
103
|
+
const endRad = toScreenRadians(endDeg);
|
|
104
|
+
const midRad = toScreenRadians(midDeg);
|
|
105
|
+
const point = series.points?.[j];
|
|
106
|
+
const exp = point?.explosion ?? series.explosion ?? group.explosion ?? 0;
|
|
107
|
+
const expOffset = rOuterTotal * (Math.min(Math.max(0, exp), 100) / 100);
|
|
108
|
+
const ox = cx + expOffset * Math.cos(midRad);
|
|
109
|
+
const oy = cy + expOffset * Math.sin(midRad);
|
|
110
|
+
const { d, fullCircle } = buildSlicePath({
|
|
111
|
+
ox,
|
|
112
|
+
oy,
|
|
113
|
+
innerR: rIn,
|
|
114
|
+
outerR: rOut,
|
|
115
|
+
startRad,
|
|
116
|
+
endRad,
|
|
117
|
+
spanDeg
|
|
118
|
+
});
|
|
119
|
+
const fill = resolveSeriesColor(point?.color ?? series.color, j, theme);
|
|
120
|
+
const lineSpec = point?.line ?? series.line;
|
|
121
|
+
const stroke = lineSpec !== void 0 ? resolveChartLineStroke(lineSpec, theme, {
|
|
122
|
+
color: "dk1",
|
|
123
|
+
width: 1
|
|
124
|
+
}) : positiveCount > 1 || ringCount > 1 ? {
|
|
125
|
+
hex: "FFFFFF",
|
|
126
|
+
alpha: .9,
|
|
127
|
+
width: 1
|
|
128
|
+
} : void 0;
|
|
129
|
+
const strokeAttr = stroke === void 0 ? "" : ` ${strokeAttrs(stroke)}`;
|
|
130
|
+
const fillRuleAttr = fullCircle && rIn > .001 ? " fill-rule=\"evenodd\"" : "";
|
|
131
|
+
parts.push(`<path d="${d}" fill="#${fill.hex}" fill-opacity="${fill.alpha ?? 1}"${fillRuleAttr}${strokeAttr}/>`);
|
|
132
|
+
anchors.push({
|
|
133
|
+
kind: "slice",
|
|
134
|
+
groupIndex,
|
|
135
|
+
seriesIndex: series.seriesIndex,
|
|
136
|
+
groupSeriesIndex: s,
|
|
137
|
+
pointIndex: j,
|
|
138
|
+
value: val,
|
|
139
|
+
category: series.categories[j] ?? "",
|
|
140
|
+
seriesName: series.name,
|
|
141
|
+
cx: ox,
|
|
142
|
+
cy: oy,
|
|
143
|
+
innerR: rIn,
|
|
144
|
+
outerR: rOut,
|
|
145
|
+
startAngleRad: startRad,
|
|
146
|
+
endAngleRad: endRad,
|
|
147
|
+
midAngleRad: midRad,
|
|
148
|
+
sliceSum: ringTotal,
|
|
149
|
+
percent: val / ringTotal,
|
|
150
|
+
spanDeg
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
svg: parts.join(""),
|
|
156
|
+
anchors
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export { renderPieOrDoughnutGroup };
|