@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,2403 @@
|
|
|
1
|
+
import { bcp47LangSchema, schemeColorNameSchema } from "../../../core/dist/theme.js";
|
|
2
|
+
import "../../../core/dist/capability.js";
|
|
3
|
+
import { A_NS, C_NS, MC_NS, P_NS, R_NS, emuToPx } from "../../../import/dist/namespaces.js";
|
|
4
|
+
import { XmlElementCursor, parseXmlPart } from "../../../import/dist/xml-reader.js";
|
|
5
|
+
import { resolvePartPath } from "../../../import/dist/opc.js";
|
|
6
|
+
import { extentEmuFragmentSchema, hexRgb6Schema, offsetEmuFragmentSchema, ooxmlBoolSchema, ooxmlIntSchema, ooxmlNonNegativeIntSchema, ooxmlPositiveLineWidthEmuSchema, ooxmlWritableExtentEmuSchema, transformAttributesFragmentSchema } from "../../../import/dist/xml-fragments.js";
|
|
7
|
+
import { readRunFontSlots } from "../../../import/dist/fonts.js";
|
|
8
|
+
import "../../../import/dist/index.js";
|
|
9
|
+
import { attachDeferredSlideLink, readClickLink } from "../shared/identity.js";
|
|
10
|
+
import { emitPlaceholderUnbindDiagnostic, isPlaceholderGraphicFrameElement, readNvPrPlaceholder, resolvePlaceholderImportClaim } from "../shared/placeholder-import.js";
|
|
11
|
+
import { createChartNode } from "./chart-declaration.js";
|
|
12
|
+
import { chartAxisPositionFromNative, chartDataLabelPositionFromNative, chartErrorBarValueTypeFromNative, chartLegendPositionFromNative, chartLineDashFromNative, chartTrendlineTypeFromNative } from "./chart-labels.js";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
// ../capabilities/dist/chart/chart-import.js
|
|
15
|
+
const C14_NS = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart";
|
|
16
|
+
const C15_NS = "http://schemas.microsoft.com/office/drawing/2012/chart";
|
|
17
|
+
const WPS_ET_NS = "https://web.wps.cn/et/2018/main";
|
|
18
|
+
const C15_CAT_RANGE_EXT_URI = "{02D57815-91ED-43cb-92C2-25804820EDAC}";
|
|
19
|
+
const C15_DLBL_RANGE_FLAG_EXT_URI = "{CE6537A1-D6FC-4f65-9D91-7224C49458BB}";
|
|
20
|
+
const C16_UNIQUE_ID_EXT_URI = "{C3380CC4-5D6E-409C-BE32-E72D297353CC}";
|
|
21
|
+
const WPS_CHART_PROPS_EXT_URI = "{0b15fc19-7d7d-44ad-8c2d-2c3a37ce22c3}";
|
|
22
|
+
const NonVisualIdSchema = z.object({
|
|
23
|
+
id: ooxmlNonNegativeIntSchema,
|
|
24
|
+
name: z.string().optional()
|
|
25
|
+
});
|
|
26
|
+
const GraphicDataAttrSchema = z.object({ uri: z.string().min(1) });
|
|
27
|
+
const OoxmlFloatSchema = z.string().transform((value) => Number(value.trim())).refine((value) => Number.isFinite(value));
|
|
28
|
+
const SchemeColorSchema = z.object({ val: schemeColorNameSchema });
|
|
29
|
+
const BarDirSchema = z.object({ val: z.enum(["col", "bar"]) });
|
|
30
|
+
const GroupingSchema = z.object({ val: z.enum([
|
|
31
|
+
"clustered",
|
|
32
|
+
"stacked",
|
|
33
|
+
"percentStacked",
|
|
34
|
+
"standard"
|
|
35
|
+
]) });
|
|
36
|
+
const ScatterStyleSchema = z.object({ val: z.enum([
|
|
37
|
+
"none",
|
|
38
|
+
"line",
|
|
39
|
+
"lineMarker",
|
|
40
|
+
"marker",
|
|
41
|
+
"smooth",
|
|
42
|
+
"smoothMarker"
|
|
43
|
+
]) });
|
|
44
|
+
const CrossesSchema = z.object({ val: z.enum([
|
|
45
|
+
"autoZero",
|
|
46
|
+
"max",
|
|
47
|
+
"min"
|
|
48
|
+
]) });
|
|
49
|
+
const TickMarkSchema = z.object({ val: z.enum([
|
|
50
|
+
"none",
|
|
51
|
+
"in",
|
|
52
|
+
"out",
|
|
53
|
+
"cross"
|
|
54
|
+
]) });
|
|
55
|
+
const TickLblPosSchema = z.object({ val: z.enum([
|
|
56
|
+
"nextTo",
|
|
57
|
+
"high",
|
|
58
|
+
"low",
|
|
59
|
+
"none"
|
|
60
|
+
]) });
|
|
61
|
+
const DispBlanksAsSchema = z.object({ val: z.enum([
|
|
62
|
+
"gap",
|
|
63
|
+
"zero",
|
|
64
|
+
"span"
|
|
65
|
+
]) });
|
|
66
|
+
const DLblPosSchema = z.object({ val: z.enum([
|
|
67
|
+
"ctr",
|
|
68
|
+
"inEnd",
|
|
69
|
+
"inBase",
|
|
70
|
+
"outEnd",
|
|
71
|
+
"bestFit",
|
|
72
|
+
"l",
|
|
73
|
+
"r",
|
|
74
|
+
"b",
|
|
75
|
+
"t"
|
|
76
|
+
]) });
|
|
77
|
+
const MarkerSymbolSchema = z.object({ val: z.enum([
|
|
78
|
+
"auto",
|
|
79
|
+
"circle",
|
|
80
|
+
"dash",
|
|
81
|
+
"diamond",
|
|
82
|
+
"dot",
|
|
83
|
+
"none",
|
|
84
|
+
"plus",
|
|
85
|
+
"square",
|
|
86
|
+
"star",
|
|
87
|
+
"triangle",
|
|
88
|
+
"x"
|
|
89
|
+
]) });
|
|
90
|
+
const ErrBarTypeSchema = z.object({ val: z.enum([
|
|
91
|
+
"both",
|
|
92
|
+
"plus",
|
|
93
|
+
"minus"
|
|
94
|
+
]) });
|
|
95
|
+
function directElementChild(parent, namespaceUri, localName) {
|
|
96
|
+
for (let child = parent.firstChild; child !== null; child = child.nextSibling) {
|
|
97
|
+
if (child.nodeType !== 1) continue;
|
|
98
|
+
const el = child;
|
|
99
|
+
if ((el.namespaceURI ?? "") === namespaceUri && (el.localName ?? el.tagName) === localName) return el;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Side-effect-free predicate matching `<p:graphicFrame>` elements containing DrawingML charts. */
|
|
103
|
+
function isChartGraphicFrame(cursor) {
|
|
104
|
+
const graphic = directElementChild(cursor.element, A_NS, "graphic");
|
|
105
|
+
if (graphic === void 0) return false;
|
|
106
|
+
const graphicData = directElementChild(graphic, A_NS, "graphicData");
|
|
107
|
+
if (graphicData === void 0) return false;
|
|
108
|
+
return graphicData.getAttribute("uri") === C_NS;
|
|
109
|
+
}
|
|
110
|
+
function consumeAllAttributes(cursor) {
|
|
111
|
+
const attrs = cursor.element.attributes;
|
|
112
|
+
for (let i = 0; i < attrs.length; i += 1) {
|
|
113
|
+
const attr = attrs.item(i);
|
|
114
|
+
if (attr === null) continue;
|
|
115
|
+
const ns = attr.namespaceURI ?? "";
|
|
116
|
+
const local = attr.localName ?? attr.name;
|
|
117
|
+
if (ns === "http://www.w3.org/2000/xmlns/" || attr.name === "xmlns" || attr.prefix === "xmlns") continue;
|
|
118
|
+
cursor.consumeAttr(local, ns);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Recursively consumes a known benign Office/WPS boilerplate element and its descendants. */
|
|
122
|
+
function consumeSubtree(cursor) {
|
|
123
|
+
consumeAllAttributes(cursor);
|
|
124
|
+
for (const child of cursor.remainingElementChildren()) consumeSubtree(child);
|
|
125
|
+
}
|
|
126
|
+
function readValAttr(cursor) {
|
|
127
|
+
return cursor?.attr("val");
|
|
128
|
+
}
|
|
129
|
+
function readBoolVal(cursor) {
|
|
130
|
+
const raw = readValAttr(cursor);
|
|
131
|
+
if (raw === void 0) return void 0;
|
|
132
|
+
const parsed = ooxmlBoolSchema.safeParse(raw);
|
|
133
|
+
return parsed.success ? parsed.data : void 0;
|
|
134
|
+
}
|
|
135
|
+
function readIntVal(cursor) {
|
|
136
|
+
const raw = readValAttr(cursor);
|
|
137
|
+
if (raw === void 0) return void 0;
|
|
138
|
+
const parsed = ooxmlIntSchema.safeParse(raw);
|
|
139
|
+
return parsed.success ? parsed.data : void 0;
|
|
140
|
+
}
|
|
141
|
+
function readFloatVal(cursor) {
|
|
142
|
+
const raw = readValAttr(cursor);
|
|
143
|
+
if (raw === void 0) return void 0;
|
|
144
|
+
const parsed = OoxmlFloatSchema.safeParse(raw);
|
|
145
|
+
return parsed.success ? parsed.data : void 0;
|
|
146
|
+
}
|
|
147
|
+
function readColorModifier(colorCursor, localName) {
|
|
148
|
+
const mod = colorCursor.child(A_NS, localName);
|
|
149
|
+
if (mod === void 0) return void 0;
|
|
150
|
+
const val = readIntVal(mod);
|
|
151
|
+
if (val === void 0 || val < 0 || val > 1e5) return void 0;
|
|
152
|
+
return val / 1e5;
|
|
153
|
+
}
|
|
154
|
+
function readSolidFillColor(fillCursor) {
|
|
155
|
+
const srgb = fillCursor.child(A_NS, "srgbClr");
|
|
156
|
+
const scheme = srgb === void 0 ? fillCursor.child(A_NS, "schemeClr") : void 0;
|
|
157
|
+
const colorCursor = srgb ?? scheme;
|
|
158
|
+
if (colorCursor === void 0) {
|
|
159
|
+
consumeSubtree(fillCursor);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
let baseString;
|
|
163
|
+
let schemeSlot;
|
|
164
|
+
if (srgb !== void 0) {
|
|
165
|
+
const raw = srgb.attrsObject(["val"]);
|
|
166
|
+
const parsed = hexRgb6Schema.safeParse(raw["val"]);
|
|
167
|
+
if (parsed.success) baseString = `#${parsed.data.toUpperCase()}`;
|
|
168
|
+
} else if (scheme !== void 0) {
|
|
169
|
+
const raw = scheme.attrsObject(["val"]);
|
|
170
|
+
const parsed = SchemeColorSchema.safeParse(raw);
|
|
171
|
+
if (parsed.success) schemeSlot = parsed.data.val;
|
|
172
|
+
}
|
|
173
|
+
const lumMod = readColorModifier(colorCursor, "lumMod");
|
|
174
|
+
const lumOff = readColorModifier(colorCursor, "lumOff");
|
|
175
|
+
const alpha = readColorModifier(colorCursor, "alpha");
|
|
176
|
+
consumeSubtree(colorCursor);
|
|
177
|
+
const baseColor = schemeSlot !== void 0 && lumMod !== void 0 ? {
|
|
178
|
+
slot: schemeSlot,
|
|
179
|
+
lumMod: Math.min(1, lumMod),
|
|
180
|
+
...lumOff === void 0 ? {} : { lumOff: Math.min(1, lumOff) }
|
|
181
|
+
} : schemeSlot ?? baseString;
|
|
182
|
+
if (baseColor === void 0) return void 0;
|
|
183
|
+
return alpha === void 0 ? baseColor : {
|
|
184
|
+
color: baseColor,
|
|
185
|
+
alpha
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function isEmptyXmlElement(el) {
|
|
189
|
+
return el.children.length === 0 && el.attributes.length === 0;
|
|
190
|
+
}
|
|
191
|
+
function consumeBenignLineElement(spPr) {
|
|
192
|
+
const lnEl = directElementChild(spPr.element, A_NS, "ln");
|
|
193
|
+
if (lnEl === void 0) return false;
|
|
194
|
+
const lnChildren = Array.from(lnEl.children);
|
|
195
|
+
if (!lnChildren.some((c) => c.namespaceURI === "http://schemas.openxmlformats.org/drawingml/2006/main" && c.localName === "noFill") && lnChildren.length > 0) return false;
|
|
196
|
+
if (!lnChildren.every((c) => c.namespaceURI === "http://schemas.openxmlformats.org/drawingml/2006/main" && (c.localName === "noFill" || c.localName === "round") && isEmptyXmlElement(c))) return false;
|
|
197
|
+
const ln = spPr.child(A_NS, "ln");
|
|
198
|
+
ln.consumeAttr("w");
|
|
199
|
+
ln.consumeAttr("cap");
|
|
200
|
+
for (const child of ln.remainingElementChildren()) consumeSubtree(child);
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
function consumeBenignChartSpPr(spPr) {
|
|
204
|
+
const noFillEl = directElementChild(spPr.element, A_NS, "noFill");
|
|
205
|
+
if (noFillEl !== void 0 && isEmptyXmlElement(noFillEl)) spPr.child(A_NS, "noFill");
|
|
206
|
+
consumeBenignLineElement(spPr);
|
|
207
|
+
const effectEl = directElementChild(spPr.element, A_NS, "effectLst");
|
|
208
|
+
if (effectEl !== void 0 && isEmptyXmlElement(effectEl)) spPr.child(A_NS, "effectLst");
|
|
209
|
+
const extEl = directElementChild(spPr.element, A_NS, "extLst");
|
|
210
|
+
if (extEl !== void 0 && isEmptyXmlElement(extEl)) spPr.child(A_NS, "extLst");
|
|
211
|
+
}
|
|
212
|
+
function readLineFromSpPr(spPr) {
|
|
213
|
+
const lnEl = directElementChild(spPr.element, A_NS, "ln");
|
|
214
|
+
if (lnEl === void 0) return { noLine: false };
|
|
215
|
+
if (directElementChild(lnEl, "http://schemas.openxmlformats.org/drawingml/2006/main", "noFill") !== void 0 && consumeBenignLineElement(spPr)) return { noLine: true };
|
|
216
|
+
const ln = spPr.child(A_NS, "ln");
|
|
217
|
+
const rawW = ln.attr("w");
|
|
218
|
+
ln.consumeAttr("cap");
|
|
219
|
+
const solidFill = ln.child(A_NS, "solidFill");
|
|
220
|
+
const color = solidFill === void 0 ? void 0 : readSolidFillColor(solidFill);
|
|
221
|
+
const prstDash = ln.child(A_NS, "prstDash");
|
|
222
|
+
let dash;
|
|
223
|
+
if (prstDash !== void 0) {
|
|
224
|
+
const rawDash = prstDash.attrsObject(["val"])["val"];
|
|
225
|
+
if (rawDash !== void 0) dash = chartLineDashFromNative[rawDash];
|
|
226
|
+
}
|
|
227
|
+
const roundEl = directElementChild(ln.element, A_NS, "round");
|
|
228
|
+
if (roundEl !== void 0 && isEmptyXmlElement(roundEl)) ln.child(A_NS, "round");
|
|
229
|
+
let width;
|
|
230
|
+
if (rawW !== void 0) {
|
|
231
|
+
const parsedW = ooxmlPositiveLineWidthEmuSchema.safeParse(rawW);
|
|
232
|
+
if (parsedW.success) width = emuToPx(parsedW.data);
|
|
233
|
+
}
|
|
234
|
+
if (color === void 0 && width === void 0 && dash === void 0) return { noLine: false };
|
|
235
|
+
return {
|
|
236
|
+
noLine: false,
|
|
237
|
+
line: {
|
|
238
|
+
...color === void 0 ? {} : { color },
|
|
239
|
+
...width === void 0 ? {} : { width },
|
|
240
|
+
...dash === void 0 ? {} : { dash }
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function readSeriesSpPr(spPr, ignoreLine) {
|
|
245
|
+
const solidFill = spPr.child(A_NS, "solidFill");
|
|
246
|
+
const color = solidFill === void 0 ? void 0 : readSolidFillColor(solidFill);
|
|
247
|
+
const { line } = ignoreLine ? (consumeBenignLineElement(spPr), { line: void 0 }) : readLineFromSpPr(spPr);
|
|
248
|
+
consumeBenignChartSpPr(spPr);
|
|
249
|
+
return {
|
|
250
|
+
...color === void 0 ? {} : { color },
|
|
251
|
+
...line === void 0 ? {} : { line }
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function readChartOuterShadow(rPrCursor) {
|
|
255
|
+
const effectLst = rPrCursor.child(A_NS, "effectLst");
|
|
256
|
+
if (effectLst === void 0) return void 0;
|
|
257
|
+
const outerShdw = effectLst.child(A_NS, "outerShdw");
|
|
258
|
+
if (outerShdw === void 0) {
|
|
259
|
+
consumeSubtree(effectLst);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const blurRadRaw = outerShdw.attr("blurRad");
|
|
263
|
+
const distRaw = outerShdw.attr("dist");
|
|
264
|
+
const dirRaw = outerShdw.attr("dir");
|
|
265
|
+
outerShdw.consumeAttr("algn");
|
|
266
|
+
outerShdw.consumeAttr("rotWithShape");
|
|
267
|
+
const color = readSolidFillColor(outerShdw);
|
|
268
|
+
consumeSubtree(outerShdw);
|
|
269
|
+
consumeSubtree(effectLst);
|
|
270
|
+
const blurRad = blurRadRaw === void 0 ? void 0 : ooxmlWritableExtentEmuSchema.safeParse(blurRadRaw);
|
|
271
|
+
const dist = distRaw === void 0 ? void 0 : ooxmlWritableExtentEmuSchema.safeParse(distRaw);
|
|
272
|
+
const dir = dirRaw === void 0 ? void 0 : ooxmlIntSchema.safeParse(dirRaw);
|
|
273
|
+
if (blurRad !== void 0 && !blurRad.success || dist !== void 0 && !dist.success || dir !== void 0 && !dir.success) return;
|
|
274
|
+
return {
|
|
275
|
+
...color === void 0 ? {} : { color },
|
|
276
|
+
...blurRad?.success ? { blur: emuToPx(blurRad.data) } : {},
|
|
277
|
+
...dist?.success ? { distance: emuToPx(dist.data) } : {},
|
|
278
|
+
...dir?.success ? { angle: dir.data / 6e4 } : {}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function readChartRunProperties(rPrCursor) {
|
|
282
|
+
const rawLang = rPrCursor.attr("lang");
|
|
283
|
+
const parsedLang = rawLang === void 0 ? void 0 : bcp47LangSchema.safeParse(rawLang);
|
|
284
|
+
const lang = parsedLang?.success ? parsedLang.data : void 0;
|
|
285
|
+
const szRaw = rPrCursor.attr("sz");
|
|
286
|
+
const szParsed = szRaw === void 0 ? void 0 : ooxmlIntSchema.safeParse(szRaw);
|
|
287
|
+
const fontSize = szParsed?.success && szParsed.data >= 100 && szParsed.data <= 4e5 ? `${szParsed.data / 100}pt` : void 0;
|
|
288
|
+
const bRaw = rPrCursor.attr("b");
|
|
289
|
+
const bParsed = bRaw === void 0 ? void 0 : ooxmlBoolSchema.safeParse(bRaw);
|
|
290
|
+
const fontWeight = bParsed?.success ? bParsed.data ? "bold" : "normal" : void 0;
|
|
291
|
+
const iRaw = rPrCursor.attr("i");
|
|
292
|
+
const iParsed = iRaw === void 0 ? void 0 : ooxmlBoolSchema.safeParse(iRaw);
|
|
293
|
+
const fontStyle = iParsed?.success ? iParsed.data ? "italic" : "normal" : void 0;
|
|
294
|
+
const uRaw = rPrCursor.attr("u");
|
|
295
|
+
const strikeRaw = rPrCursor.attr("strike");
|
|
296
|
+
let textDecoration;
|
|
297
|
+
if (uRaw === "sng") textDecoration = "underline";
|
|
298
|
+
else if (strikeRaw === "sngStrike") textDecoration = "line-through";
|
|
299
|
+
else if (uRaw === "none" && strikeRaw === "noStrike") textDecoration = "none";
|
|
300
|
+
const capRaw = rPrCursor.attr("cap");
|
|
301
|
+
let textTransform;
|
|
302
|
+
if (capRaw === "all") textTransform = "uppercase";
|
|
303
|
+
else if (capRaw === "none") textTransform = "none";
|
|
304
|
+
const spcRaw = rPrCursor.attr("spc");
|
|
305
|
+
const spcParsed = spcRaw === void 0 ? void 0 : ooxmlIntSchema.safeParse(spcRaw);
|
|
306
|
+
const letterSpacing = spcParsed?.success && spcParsed.data >= -4e5 && spcParsed.data <= 4e5 ? spcParsed.data / 75 : void 0;
|
|
307
|
+
const solidFill = rPrCursor.child(A_NS, "solidFill");
|
|
308
|
+
const color = solidFill === void 0 ? void 0 : readSolidFillColor(solidFill);
|
|
309
|
+
if (solidFill !== void 0) consumeSubtree(solidFill);
|
|
310
|
+
const textShadow = readChartOuterShadow(rPrCursor);
|
|
311
|
+
const { fontFamily, eastAsianFontFamily } = readRunFontSlots(rPrCursor);
|
|
312
|
+
consumeSubtree(rPrCursor);
|
|
313
|
+
return {
|
|
314
|
+
...fontFamily === void 0 ? {} : { fontFamily },
|
|
315
|
+
...eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily },
|
|
316
|
+
...fontSize === void 0 ? {} : { fontSize },
|
|
317
|
+
...fontWeight === void 0 ? {} : { fontWeight },
|
|
318
|
+
...fontStyle === void 0 ? {} : { fontStyle },
|
|
319
|
+
...color === void 0 ? {} : { color },
|
|
320
|
+
...letterSpacing === void 0 ? {} : { letterSpacing },
|
|
321
|
+
...textTransform === void 0 ? {} : { textTransform },
|
|
322
|
+
...textDecoration === void 0 ? {} : { textDecoration },
|
|
323
|
+
...textShadow === void 0 ? {} : { textShadow },
|
|
324
|
+
...lang === void 0 ? {} : { lang }
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function readChartTextProperties(txPrCursor) {
|
|
328
|
+
let verticalAlign;
|
|
329
|
+
const bodyPr = txPrCursor.child(A_NS, "bodyPr");
|
|
330
|
+
if (bodyPr !== void 0) {
|
|
331
|
+
const anchor = bodyPr.attr("anchor");
|
|
332
|
+
if (anchor === "t") verticalAlign = "top";
|
|
333
|
+
else if (anchor === "ctr") verticalAlign = "middle";
|
|
334
|
+
else if (anchor === "b") verticalAlign = "bottom";
|
|
335
|
+
consumeSubtree(bodyPr);
|
|
336
|
+
}
|
|
337
|
+
let align;
|
|
338
|
+
let lineHeight;
|
|
339
|
+
let spacingAfter;
|
|
340
|
+
let defStyle = {};
|
|
341
|
+
let runStyle = {};
|
|
342
|
+
let endLang;
|
|
343
|
+
const p = txPrCursor.child(A_NS, "p");
|
|
344
|
+
if (p !== void 0) {
|
|
345
|
+
const pPr = p.child(A_NS, "pPr");
|
|
346
|
+
if (pPr !== void 0) {
|
|
347
|
+
const algn = pPr.attr("algn");
|
|
348
|
+
if (algn === "l") align = "left";
|
|
349
|
+
else if (algn === "ctr") align = "center";
|
|
350
|
+
else if (algn === "r") align = "right";
|
|
351
|
+
else if (algn === "just") align = "justify";
|
|
352
|
+
const lnSpc = pPr.child(A_NS, "lnSpc");
|
|
353
|
+
if (lnSpc !== void 0) {
|
|
354
|
+
const spcPts = readIntVal(lnSpc.child(A_NS, "spcPts"));
|
|
355
|
+
const spcPct = readIntVal(lnSpc.child(A_NS, "spcPct"));
|
|
356
|
+
if (spcPts !== void 0 && spcPts > 0 && spcPts <= 158400) lineHeight = `${spcPts / 100}pt`;
|
|
357
|
+
else if (spcPct !== void 0 && spcPct > 0 && spcPct <= 132e5) lineHeight = `${spcPct / 1e3}%`;
|
|
358
|
+
consumeSubtree(lnSpc);
|
|
359
|
+
}
|
|
360
|
+
const spcAft = pPr.child(A_NS, "spcAft");
|
|
361
|
+
if (spcAft !== void 0) {
|
|
362
|
+
const spcPts = readIntVal(spcAft.child(A_NS, "spcPts"));
|
|
363
|
+
if (spcPts !== void 0 && spcPts >= 0 && spcPts <= 158400) spacingAfter = spcPts / 75;
|
|
364
|
+
consumeSubtree(spcAft);
|
|
365
|
+
}
|
|
366
|
+
const defRPr = pPr.child(A_NS, "defRPr");
|
|
367
|
+
if (defRPr !== void 0) defStyle = readChartRunProperties(defRPr);
|
|
368
|
+
consumeSubtree(pPr);
|
|
369
|
+
}
|
|
370
|
+
const r = p.child(A_NS, "r");
|
|
371
|
+
if (r !== void 0) {
|
|
372
|
+
const rPr = r.child(A_NS, "rPr");
|
|
373
|
+
if (rPr !== void 0) runStyle = readChartRunProperties(rPr);
|
|
374
|
+
consumeSubtree(r);
|
|
375
|
+
}
|
|
376
|
+
const endParaRPr = p.child(A_NS, "endParaRPr");
|
|
377
|
+
if (endParaRPr !== void 0) {
|
|
378
|
+
const rawLang = endParaRPr.attr("lang");
|
|
379
|
+
const parsedLang = rawLang === void 0 ? void 0 : bcp47LangSchema.safeParse(rawLang);
|
|
380
|
+
if (parsedLang?.success) endLang = parsedLang.data;
|
|
381
|
+
consumeSubtree(endParaRPr);
|
|
382
|
+
}
|
|
383
|
+
consumeSubtree(p);
|
|
384
|
+
}
|
|
385
|
+
consumeSubtree(txPrCursor);
|
|
386
|
+
const merged = {
|
|
387
|
+
...defStyle,
|
|
388
|
+
...runStyle,
|
|
389
|
+
...endLang !== void 0 && defStyle.lang === void 0 && runStyle.lang === void 0 ? { lang: endLang } : {},
|
|
390
|
+
...verticalAlign === void 0 ? {} : { verticalAlign },
|
|
391
|
+
...align === void 0 ? {} : { align },
|
|
392
|
+
...lineHeight === void 0 ? {} : { lineHeight },
|
|
393
|
+
...spacingAfter === void 0 ? {} : { spacingAfter }
|
|
394
|
+
};
|
|
395
|
+
return Object.keys(merged).length === 0 ? void 0 : merged;
|
|
396
|
+
}
|
|
397
|
+
function fontSizePointsValue(value) {
|
|
398
|
+
if (typeof value === "number") return value * .75;
|
|
399
|
+
if (typeof value === "string") {
|
|
400
|
+
if (value.endsWith("pt")) return Number(value.slice(0, -2));
|
|
401
|
+
if (value.endsWith("px")) return Number(value.slice(0, -2)) * .75;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function stableJsonEqual(left, right) {
|
|
405
|
+
if (left === right) return true;
|
|
406
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
|
|
407
|
+
const leftKeys = Object.keys(left).filter((k) => left[k] !== void 0);
|
|
408
|
+
const rightKeys = Object.keys(right).filter((k) => right[k] !== void 0);
|
|
409
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
410
|
+
return leftKeys.every((key) => stableJsonEqual(left[key], right[key]));
|
|
411
|
+
}
|
|
412
|
+
function styleFieldEqual(key, left, right) {
|
|
413
|
+
if (left === right) return true;
|
|
414
|
+
if (key === "fontSize" || key === "lineHeight") {
|
|
415
|
+
if (key === "lineHeight" && typeof left === "string" && typeof right === "string" && left.endsWith("%") && right.endsWith("%")) return Math.abs(Number(left.slice(0, -1)) - Number(right.slice(0, -1))) < 1e-6;
|
|
416
|
+
const lPt = fontSizePointsValue(left);
|
|
417
|
+
const rPt = fontSizePointsValue(right);
|
|
418
|
+
return lPt !== void 0 && rPt !== void 0 && Math.abs(lPt - rPt) < 1e-6;
|
|
419
|
+
}
|
|
420
|
+
return stableJsonEqual(left, right);
|
|
421
|
+
}
|
|
422
|
+
function diffChartTextStyle(child, inherited) {
|
|
423
|
+
if (child === void 0) return void 0;
|
|
424
|
+
const baseline = {
|
|
425
|
+
fontWeight: "normal",
|
|
426
|
+
fontStyle: "normal",
|
|
427
|
+
verticalAlign: "top",
|
|
428
|
+
textDecoration: "none",
|
|
429
|
+
textTransform: "none",
|
|
430
|
+
color: "dk1",
|
|
431
|
+
...inherited
|
|
432
|
+
};
|
|
433
|
+
const out = {};
|
|
434
|
+
for (const [key, value] of Object.entries(child)) {
|
|
435
|
+
if (value === void 0) continue;
|
|
436
|
+
const baseValue = baseline[key];
|
|
437
|
+
if (!styleFieldEqual(key, value, baseValue)) out[key] = value;
|
|
438
|
+
}
|
|
439
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
440
|
+
}
|
|
441
|
+
function normalizeRootChartStyle(rawStyle) {
|
|
442
|
+
if (rawStyle === void 0) return void 0;
|
|
443
|
+
const out = {};
|
|
444
|
+
for (const [key, value] of Object.entries(rawStyle)) {
|
|
445
|
+
if (value === void 0) continue;
|
|
446
|
+
if (key === "fontWeight" && value === "normal") continue;
|
|
447
|
+
if (key === "fontStyle" && value === "normal") continue;
|
|
448
|
+
if (key === "verticalAlign" && value === "top") continue;
|
|
449
|
+
if (key === "textDecoration" && value === "none") continue;
|
|
450
|
+
if (key === "textTransform" && value === "none") continue;
|
|
451
|
+
out[key] = value;
|
|
452
|
+
}
|
|
453
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
454
|
+
}
|
|
455
|
+
function readChartTitle(titleCursor, inheritedStyle) {
|
|
456
|
+
let titleText;
|
|
457
|
+
let richStyle;
|
|
458
|
+
const tx = titleCursor.child(C_NS, "tx");
|
|
459
|
+
if (tx !== void 0) {
|
|
460
|
+
const rich = tx.child(C_NS, "rich");
|
|
461
|
+
if (rich !== void 0) {
|
|
462
|
+
const bodyPr = rich.child(A_NS, "bodyPr");
|
|
463
|
+
const anchor = bodyPr?.attr("anchor");
|
|
464
|
+
const verticalAlign = anchor === "t" ? "top" : anchor === "ctr" ? "middle" : anchor === "b" ? "bottom" : void 0;
|
|
465
|
+
if (bodyPr !== void 0) consumeSubtree(bodyPr);
|
|
466
|
+
let align;
|
|
467
|
+
let lineHeight;
|
|
468
|
+
let spacingAfter;
|
|
469
|
+
let defRun = {};
|
|
470
|
+
let explicitRun = {};
|
|
471
|
+
const parts = [];
|
|
472
|
+
for (const [paraIndex, para] of rich.children(A_NS, "p").entries()) {
|
|
473
|
+
if (paraIndex === 0) {
|
|
474
|
+
const pPr = para.child(A_NS, "pPr");
|
|
475
|
+
if (pPr !== void 0) {
|
|
476
|
+
const algn = pPr.attr("algn");
|
|
477
|
+
align = algn === "l" ? "left" : algn === "ctr" ? "center" : algn === "r" ? "right" : algn === "just" ? "justify" : void 0;
|
|
478
|
+
const lnSpc = pPr.child(A_NS, "lnSpc");
|
|
479
|
+
if (lnSpc !== void 0) {
|
|
480
|
+
const spcPts = readIntVal(lnSpc.child(A_NS, "spcPts"));
|
|
481
|
+
const spcPct = readIntVal(lnSpc.child(A_NS, "spcPct"));
|
|
482
|
+
if (spcPts !== void 0 && spcPts > 0 && spcPts <= 158400) lineHeight = `${spcPts / 100}pt`;
|
|
483
|
+
else if (spcPct !== void 0 && spcPct > 0 && spcPct <= 132e5) lineHeight = `${spcPct / 1e3}%`;
|
|
484
|
+
consumeSubtree(lnSpc);
|
|
485
|
+
}
|
|
486
|
+
const spcAft = pPr.child(A_NS, "spcAft");
|
|
487
|
+
if (spcAft !== void 0) {
|
|
488
|
+
const spcPts = readIntVal(spcAft.child(A_NS, "spcPts"));
|
|
489
|
+
if (spcPts !== void 0 && spcPts >= 0 && spcPts <= 158400) spacingAfter = spcPts / 75;
|
|
490
|
+
consumeSubtree(spcAft);
|
|
491
|
+
}
|
|
492
|
+
const defRPr = pPr.child(A_NS, "defRPr");
|
|
493
|
+
if (defRPr !== void 0) defRun = readChartRunProperties(defRPr);
|
|
494
|
+
consumeSubtree(pPr);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const runs = [];
|
|
498
|
+
for (const child of para.remainingElementChildren()) if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "r") {
|
|
499
|
+
if (paraIndex === 0 && Object.keys(explicitRun).length === 0) {
|
|
500
|
+
const rPr = child.child(A_NS, "rPr");
|
|
501
|
+
if (rPr !== void 0) explicitRun = readChartRunProperties(rPr);
|
|
502
|
+
}
|
|
503
|
+
const t = child.child(A_NS, "t");
|
|
504
|
+
if (t !== void 0) runs.push(t.textContent);
|
|
505
|
+
consumeSubtree(child);
|
|
506
|
+
} else if (child.namespaceUri === "http://schemas.openxmlformats.org/drawingml/2006/main" && child.localName === "br") {
|
|
507
|
+
runs.push("\n");
|
|
508
|
+
consumeSubtree(child);
|
|
509
|
+
} else consumeSubtree(child);
|
|
510
|
+
consumeSubtree(para);
|
|
511
|
+
parts.push(runs.join(""));
|
|
512
|
+
}
|
|
513
|
+
titleText = parts.join("\n");
|
|
514
|
+
consumeSubtree(rich);
|
|
515
|
+
richStyle = {
|
|
516
|
+
...defRun,
|
|
517
|
+
...explicitRun,
|
|
518
|
+
...verticalAlign === void 0 ? {} : { verticalAlign },
|
|
519
|
+
...align === void 0 ? {} : { align },
|
|
520
|
+
...lineHeight === void 0 ? {} : { lineHeight },
|
|
521
|
+
...spacingAfter === void 0 ? {} : { spacingAfter }
|
|
522
|
+
};
|
|
523
|
+
} else {
|
|
524
|
+
const strRef = tx.child(C_NS, "strRef");
|
|
525
|
+
if (strRef !== void 0) {
|
|
526
|
+
const strCache = strRef.child(C_NS, "strCache");
|
|
527
|
+
if (strCache !== void 0) {
|
|
528
|
+
const v = strCache.children(C_NS, "pt")[0]?.child(C_NS, "v");
|
|
529
|
+
if (v !== void 0) titleText = v.textContent;
|
|
530
|
+
}
|
|
531
|
+
consumeSubtree(strRef);
|
|
532
|
+
} else {
|
|
533
|
+
const v = tx.child(C_NS, "v");
|
|
534
|
+
if (v !== void 0) titleText = v.textContent;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
consumeSubtree(tx);
|
|
538
|
+
}
|
|
539
|
+
const txPr = titleCursor.child(C_NS, "txPr");
|
|
540
|
+
const txPrStyle = txPr === void 0 ? void 0 : readChartTextProperties(txPr);
|
|
541
|
+
consumeSubtree(titleCursor);
|
|
542
|
+
if (titleText === void 0 || titleText.trim() === "") return void 0;
|
|
543
|
+
const styleDiff = diffChartTextStyle(richStyle !== void 0 || txPrStyle !== void 0 ? {
|
|
544
|
+
...txPrStyle,
|
|
545
|
+
...richStyle
|
|
546
|
+
} : void 0, inheritedStyle);
|
|
547
|
+
return styleDiff === void 0 ? titleText : {
|
|
548
|
+
text: titleText,
|
|
549
|
+
style: styleDiff
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function readPtCount(container) {
|
|
553
|
+
const ptCountCursor = container.child(C_NS, "ptCount");
|
|
554
|
+
if (ptCountCursor === void 0) return void 0;
|
|
555
|
+
const raw = readValAttr(ptCountCursor);
|
|
556
|
+
if (raw === void 0) return void 0;
|
|
557
|
+
const parsed = ooxmlNonNegativeIntSchema.safeParse(raw);
|
|
558
|
+
return parsed.success ? parsed.data : void 0;
|
|
559
|
+
}
|
|
560
|
+
function readStringCacheOrLit(container) {
|
|
561
|
+
const ptCount = readPtCount(container) ?? 0;
|
|
562
|
+
const pts = container.children(C_NS, "pt");
|
|
563
|
+
const size = Math.max(ptCount, pts.length);
|
|
564
|
+
if (size === 0) {
|
|
565
|
+
consumeSubtree(container);
|
|
566
|
+
return [];
|
|
567
|
+
}
|
|
568
|
+
const result = Array.from({ length: size }).fill("");
|
|
569
|
+
for (const pt of pts) {
|
|
570
|
+
const rawIdx = pt.attr("idx");
|
|
571
|
+
const parsedIdx = rawIdx === void 0 ? void 0 : ooxmlNonNegativeIntSchema.safeParse(rawIdx);
|
|
572
|
+
const text = pt.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "v")?.textContent ?? "";
|
|
573
|
+
consumeSubtree(pt);
|
|
574
|
+
if (parsedIdx?.success && parsedIdx.data < result.length) result[parsedIdx.data] = text;
|
|
575
|
+
}
|
|
576
|
+
consumeSubtree(container);
|
|
577
|
+
return result;
|
|
578
|
+
}
|
|
579
|
+
function readNumericCacheOrLitAsStrings(container) {
|
|
580
|
+
const formatCode = container.child(C_NS, "formatCode");
|
|
581
|
+
if (formatCode !== void 0) consumeSubtree(formatCode);
|
|
582
|
+
return readStringCacheOrLit(container);
|
|
583
|
+
}
|
|
584
|
+
function readNumericCacheOrLit(container) {
|
|
585
|
+
const formatCode = container.child(C_NS, "formatCode");
|
|
586
|
+
if (formatCode !== void 0) consumeSubtree(formatCode);
|
|
587
|
+
const ptCount = readPtCount(container);
|
|
588
|
+
const pts = container.children(C_NS, "pt");
|
|
589
|
+
if (ptCount === void 0 && pts.length === 0) {
|
|
590
|
+
consumeSubtree(container);
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
const length = ptCount ?? pts.length;
|
|
594
|
+
const result = Array.from({ length }).fill(null);
|
|
595
|
+
for (const pt of pts) {
|
|
596
|
+
const rawIdx = pt.attr("idx");
|
|
597
|
+
pt.consumeAttr("formatCode");
|
|
598
|
+
const parsedIdx = rawIdx === void 0 ? void 0 : ooxmlNonNegativeIntSchema.safeParse(rawIdx);
|
|
599
|
+
const rawVal = pt.child(C_NS, "v")?.textContent.trim();
|
|
600
|
+
consumeSubtree(pt);
|
|
601
|
+
if (parsedIdx?.success && parsedIdx.data < result.length && rawVal !== void 0 && rawVal !== "") {
|
|
602
|
+
const numeric = Number(rawVal);
|
|
603
|
+
if (Number.isFinite(numeric)) result[parsedIdx.data] = numeric;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
consumeSubtree(container);
|
|
607
|
+
return result;
|
|
608
|
+
}
|
|
609
|
+
function readStringDataSource(sourceCursor) {
|
|
610
|
+
const strRef = sourceCursor.child(C_NS, "strRef");
|
|
611
|
+
if (strRef !== void 0) {
|
|
612
|
+
const formula = strRef.child(C_NS, "f")?.textContent;
|
|
613
|
+
const strCache = strRef.child(C_NS, "strCache");
|
|
614
|
+
const values = strCache === void 0 ? [] : readStringCacheOrLit(strCache);
|
|
615
|
+
consumeSubtree(strRef);
|
|
616
|
+
return {
|
|
617
|
+
...formula === void 0 ? {} : { formula },
|
|
618
|
+
values
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
const strLit = sourceCursor.child(C_NS, "strLit");
|
|
622
|
+
if (strLit !== void 0) return { values: readStringCacheOrLit(strLit) };
|
|
623
|
+
const numRef = sourceCursor.child(C_NS, "numRef");
|
|
624
|
+
if (numRef !== void 0) {
|
|
625
|
+
const formula = numRef.child(C_NS, "f")?.textContent;
|
|
626
|
+
const numCache = numRef.child(C_NS, "numCache");
|
|
627
|
+
const values = numCache === void 0 ? [] : readNumericCacheOrLitAsStrings(numCache);
|
|
628
|
+
consumeSubtree(numRef);
|
|
629
|
+
return {
|
|
630
|
+
...formula === void 0 ? {} : { formula },
|
|
631
|
+
values
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
const numLit = sourceCursor.child(C_NS, "numLit");
|
|
635
|
+
if (numLit !== void 0) return { values: readNumericCacheOrLitAsStrings(numLit) };
|
|
636
|
+
const multiLvlStrRef = sourceCursor.child(C_NS, "multiLvlStrRef");
|
|
637
|
+
if (multiLvlStrRef !== void 0) {
|
|
638
|
+
const formula = multiLvlStrRef.child(C_NS, "f")?.textContent;
|
|
639
|
+
const cache = multiLvlStrRef.child(C_NS, "multiLvlStrCache");
|
|
640
|
+
let values = [];
|
|
641
|
+
if (cache !== void 0) {
|
|
642
|
+
const ptCount = readPtCount(cache) ?? 0;
|
|
643
|
+
const lvls = cache.children(C_NS, "lvl");
|
|
644
|
+
if (ptCount > 0 && lvls.length > 0) {
|
|
645
|
+
const arr = Array.from({ length: ptCount }).fill("");
|
|
646
|
+
for (const pt of lvls[0].children(C_NS, "pt")) {
|
|
647
|
+
const rawIdx = pt.attr("idx");
|
|
648
|
+
const parsedIdx = rawIdx === void 0 ? void 0 : ooxmlNonNegativeIntSchema.safeParse(rawIdx);
|
|
649
|
+
const v = pt.child(C_NS, "v");
|
|
650
|
+
if (parsedIdx?.success && parsedIdx.data < arr.length && v !== void 0) arr[parsedIdx.data] = v.textContent;
|
|
651
|
+
consumeSubtree(pt);
|
|
652
|
+
}
|
|
653
|
+
values = arr;
|
|
654
|
+
}
|
|
655
|
+
consumeSubtree(cache);
|
|
656
|
+
}
|
|
657
|
+
consumeSubtree(multiLvlStrRef);
|
|
658
|
+
return {
|
|
659
|
+
...formula === void 0 ? {} : { formula },
|
|
660
|
+
values
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
return { values: [] };
|
|
664
|
+
}
|
|
665
|
+
function readNumericDataSource(sourceCursor) {
|
|
666
|
+
const numRef = sourceCursor.child(C_NS, "numRef");
|
|
667
|
+
if (numRef !== void 0) {
|
|
668
|
+
const f = numRef.child(C_NS, "f");
|
|
669
|
+
if (f !== void 0) consumeSubtree(f);
|
|
670
|
+
const numCache = numRef.child(C_NS, "numCache");
|
|
671
|
+
const values = numCache === void 0 ? [] : readNumericCacheOrLit(numCache);
|
|
672
|
+
consumeSubtree(numRef);
|
|
673
|
+
return values;
|
|
674
|
+
}
|
|
675
|
+
const numLit = sourceCursor.child(C_NS, "numLit");
|
|
676
|
+
if (numLit !== void 0) return readNumericCacheOrLit(numLit);
|
|
677
|
+
return [];
|
|
678
|
+
}
|
|
679
|
+
function readSeriesName(txCursor) {
|
|
680
|
+
if (txCursor === void 0) return void 0;
|
|
681
|
+
const strRef = txCursor.child(C_NS, "strRef");
|
|
682
|
+
if (strRef !== void 0) {
|
|
683
|
+
const f = strRef.child(C_NS, "f");
|
|
684
|
+
if (f !== void 0) consumeSubtree(f);
|
|
685
|
+
const strCache = strRef.child(C_NS, "strCache");
|
|
686
|
+
const values = strCache === void 0 ? [] : readStringCacheOrLit(strCache);
|
|
687
|
+
consumeSubtree(strRef);
|
|
688
|
+
consumeSubtree(txCursor);
|
|
689
|
+
return values[0];
|
|
690
|
+
}
|
|
691
|
+
const text = txCursor.child(C_NS, "v")?.textContent;
|
|
692
|
+
consumeSubtree(txCursor);
|
|
693
|
+
return text;
|
|
694
|
+
}
|
|
695
|
+
function readMarkerElement(markerCursor) {
|
|
696
|
+
const symbolCursor = markerCursor.child(C_NS, "symbol");
|
|
697
|
+
const parsedSymbol = symbolCursor === void 0 ? void 0 : MarkerSymbolSchema.safeParse(symbolCursor.attrsObject(["val"]));
|
|
698
|
+
const symbol = parsedSymbol?.success ? parsedSymbol.data.val : void 0;
|
|
699
|
+
const size = readIntVal(markerCursor.child(C_NS, "size"));
|
|
700
|
+
const spPr = markerCursor.child(C_NS, "spPr");
|
|
701
|
+
let fill;
|
|
702
|
+
let line;
|
|
703
|
+
if (spPr !== void 0) {
|
|
704
|
+
const solidFill = spPr.child(A_NS, "solidFill");
|
|
705
|
+
if (solidFill !== void 0) fill = readSolidFillColor(solidFill);
|
|
706
|
+
line = readLineFromSpPr(spPr).line;
|
|
707
|
+
consumeSubtree(spPr);
|
|
708
|
+
}
|
|
709
|
+
consumeSubtree(markerCursor);
|
|
710
|
+
if (symbol === "none" && size === void 0 && fill === void 0 && line === void 0) return false;
|
|
711
|
+
if (symbol === void 0 && size === void 0 && fill === void 0 && line === void 0) return;
|
|
712
|
+
return {
|
|
713
|
+
...symbol === void 0 ? {} : { symbol },
|
|
714
|
+
...size !== void 0 && size >= 2 && size <= 72 ? { size } : {},
|
|
715
|
+
...fill === void 0 ? {} : { fill },
|
|
716
|
+
...line === void 0 ? {} : { line }
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function readDataLabelSettingsBody(cursor, kind, isPointLevel = false) {
|
|
720
|
+
const numFmtCursor = cursor.child(C_NS, "numFmt");
|
|
721
|
+
let numberFormat;
|
|
722
|
+
if (numFmtCursor !== void 0) {
|
|
723
|
+
const code = numFmtCursor.attr("formatCode");
|
|
724
|
+
const slRaw = numFmtCursor.attr("sourceLinked");
|
|
725
|
+
if (code !== void 0 && code.trim() !== "" && (slRaw === "0" || slRaw === "false" || code !== "General")) numberFormat = code;
|
|
726
|
+
consumeSubtree(numFmtCursor);
|
|
727
|
+
}
|
|
728
|
+
const spPr = cursor.child(C_NS, "spPr");
|
|
729
|
+
if (spPr !== void 0) consumeSubtree(spPr);
|
|
730
|
+
const txPr = cursor.child(C_NS, "txPr");
|
|
731
|
+
const rawStyle = txPr === void 0 ? void 0 : readChartTextProperties(txPr);
|
|
732
|
+
const dLblPos = cursor.child(C_NS, "dLblPos");
|
|
733
|
+
let position;
|
|
734
|
+
if (dLblPos !== void 0) {
|
|
735
|
+
const parsed = DLblPosSchema.safeParse(dLblPos.attrsObject(["val"]));
|
|
736
|
+
if (parsed.success && kind !== "area" && kind !== "doughnut") {
|
|
737
|
+
const mapped = chartDataLabelPositionFromNative[parsed.data.val];
|
|
738
|
+
if (mapped !== void 0 && (kind !== "scatter" || [
|
|
739
|
+
"left",
|
|
740
|
+
"right",
|
|
741
|
+
"bottom",
|
|
742
|
+
"top",
|
|
743
|
+
"center"
|
|
744
|
+
].includes(mapped))) position = mapped;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const legendKey = cursor.child(C_NS, "showLegendKey");
|
|
748
|
+
if (legendKey !== void 0) consumeSubtree(legendKey);
|
|
749
|
+
const showVal = readBoolVal(cursor.child(C_NS, "showVal"));
|
|
750
|
+
const showCatName = readBoolVal(cursor.child(C_NS, "showCatName"));
|
|
751
|
+
const showSerName = readBoolVal(cursor.child(C_NS, "showSerName"));
|
|
752
|
+
const showPercent = readBoolVal(cursor.child(C_NS, "showPercent"));
|
|
753
|
+
const showBubbleSize = cursor.child(C_NS, "showBubbleSize");
|
|
754
|
+
if (showBubbleSize !== void 0) consumeSubtree(showBubbleSize);
|
|
755
|
+
const sepCursor = cursor.child(C_NS, "separator");
|
|
756
|
+
const separator = sepCursor !== void 0 && sepCursor.textContent.length > 0 ? sepCursor.textContent : void 0;
|
|
757
|
+
const showLeaderLines = readBoolVal(cursor.child(C_NS, "showLeaderLines"));
|
|
758
|
+
const leaderLinesCursor = cursor.child(C_NS, "leaderLines");
|
|
759
|
+
let leaderLineStyle;
|
|
760
|
+
if (leaderLinesCursor !== void 0) {
|
|
761
|
+
const lSpPr = leaderLinesCursor.child(C_NS, "spPr");
|
|
762
|
+
if (lSpPr !== void 0) {
|
|
763
|
+
leaderLineStyle = readLineFromSpPr(lSpPr).line;
|
|
764
|
+
consumeSubtree(lSpPr);
|
|
765
|
+
}
|
|
766
|
+
consumeSubtree(leaderLinesCursor);
|
|
767
|
+
}
|
|
768
|
+
let showDataLabelsRange;
|
|
769
|
+
const extLst = cursor.child(C_NS, "extLst");
|
|
770
|
+
if (extLst !== void 0) for (const ext of extLst.children(C_NS, "ext")) {
|
|
771
|
+
const uri = ext.attr("uri");
|
|
772
|
+
if (uri === C15_DLBL_RANGE_FLAG_EXT_URI) {
|
|
773
|
+
showDataLabelsRange = readBoolVal(ext.child(C15_NS, "showDataLabelsRange"));
|
|
774
|
+
consumeSubtree(ext);
|
|
775
|
+
} else if (uri === "{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" || uri === "{0b15fc19-7d7d-44ad-8c2d-2c3a37ce22c3}" || uri === C16_UNIQUE_ID_EXT_URI) consumeSubtree(ext);
|
|
776
|
+
else if (directElementChild(ext.element, C15_NS, "layout") !== void 0 || directElementChild(ext.element, C15_NS, "showLeaderLines") !== void 0 || directElementChild(ext.element, C15_NS, "leaderLines") !== void 0 || directElementChild(ext.element, C15_NS, "showDataLabelsRange") !== void 0) consumeSubtree(ext);
|
|
777
|
+
}
|
|
778
|
+
for (const rem of cursor.remainingElementChildren()) if (rem.namespaceUri === C15_NS) consumeSubtree(rem);
|
|
779
|
+
const category = kind === "scatter" ? void 0 : showDataLabelsRange === true ? true : showCatName === true ? true : showCatName === false && showDataLabelsRange === false ? false : void 0;
|
|
780
|
+
const xValue = kind === "scatter" && showCatName === true ? true : void 0;
|
|
781
|
+
const value = showVal === true ? true : showVal === false ? false : void 0;
|
|
782
|
+
const percent = (kind === "pie" || kind === "doughnut") && showPercent === true ? true : (kind === "pie" || kind === "doughnut") && showPercent === false ? false : void 0;
|
|
783
|
+
const seriesName = showSerName === true ? true : showSerName === false ? false : void 0;
|
|
784
|
+
const hasVisibleContent = value === true || percent === true || category === true || xValue === true || seriesName === true;
|
|
785
|
+
let leaderLines;
|
|
786
|
+
if (!isPointLevel && (kind === "pie" || kind === "doughnut") && hasVisibleContent) {
|
|
787
|
+
if (leaderLineStyle !== void 0) leaderLines = leaderLineStyle;
|
|
788
|
+
else if (showLeaderLines !== void 0) leaderLines = showLeaderLines;
|
|
789
|
+
}
|
|
790
|
+
return {
|
|
791
|
+
settings: {
|
|
792
|
+
...value === void 0 ? {} : { value },
|
|
793
|
+
...percent === void 0 ? {} : { percent },
|
|
794
|
+
...category === void 0 ? {} : { category },
|
|
795
|
+
...xValue === void 0 ? {} : { xValue },
|
|
796
|
+
...seriesName === void 0 ? {} : { seriesName },
|
|
797
|
+
...separator === void 0 ? {} : { separator },
|
|
798
|
+
...position === void 0 ? {} : { position },
|
|
799
|
+
...numberFormat === void 0 ? {} : { numberFormat },
|
|
800
|
+
...leaderLines === void 0 ? {} : { leaderLines }
|
|
801
|
+
},
|
|
802
|
+
...rawStyle === void 0 ? {} : { rawStyle },
|
|
803
|
+
...showDataLabelsRange === void 0 ? {} : { showDataLabelsRange }
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
function readDataLabelsElement(dLblsCursor, kind, isGroupLevel, inheritedChartStyle) {
|
|
807
|
+
const pointLabels = /* @__PURE__ */ new Map();
|
|
808
|
+
const pointRawColors = /* @__PURE__ */ new Map();
|
|
809
|
+
for (const dLbl of dLblsCursor.children(C_NS, "dLbl")) {
|
|
810
|
+
const idx = readIntVal(dLbl.child(C_NS, "idx"));
|
|
811
|
+
const del = readBoolVal(dLbl.child(C_NS, "delete"));
|
|
812
|
+
if (idx !== void 0) {
|
|
813
|
+
if (del === true) pointLabels.set(idx, false);
|
|
814
|
+
else {
|
|
815
|
+
const { settings, rawStyle } = readDataLabelSettingsBody(dLbl, kind, true);
|
|
816
|
+
pointLabels.set(idx, settings);
|
|
817
|
+
if (rawStyle?.color !== void 0) pointRawColors.set(idx, rawStyle.color);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
consumeSubtree(dLbl);
|
|
821
|
+
}
|
|
822
|
+
if (readBoolVal(dLblsCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "delete")) === true) {
|
|
823
|
+
consumeSubtree(dLblsCursor);
|
|
824
|
+
return {
|
|
825
|
+
dataLabels: false,
|
|
826
|
+
pointLabels,
|
|
827
|
+
pointLabelColors: /* @__PURE__ */ new Map()
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
const { settings, rawStyle, showDataLabelsRange } = readDataLabelSettingsBody(dLblsCursor, kind, false);
|
|
831
|
+
const dataLabelsStyle = diffChartTextStyle(rawStyle, inheritedChartStyle);
|
|
832
|
+
const inheritedLabelColor = rawStyle?.color ?? inheritedChartStyle?.color ?? "dk1";
|
|
833
|
+
const pointLabelColors = /* @__PURE__ */ new Map();
|
|
834
|
+
for (const [idx, color] of pointRawColors.entries()) if (!stableJsonEqual(color, inheritedLabelColor)) pointLabelColors.set(idx, color);
|
|
835
|
+
const hasAnyEnabledOrCustomized = settings.value === true || settings.percent === true || settings.category === true || settings.xValue === true || settings.seriesName === true || settings.separator !== void 0 || settings.numberFormat !== void 0 || settings.position !== void 0 || settings.leaderLines !== void 0 || dataLabelsStyle !== void 0;
|
|
836
|
+
if (isGroupLevel && !hasAnyEnabledOrCustomized) return {
|
|
837
|
+
pointLabels,
|
|
838
|
+
pointLabelColors
|
|
839
|
+
};
|
|
840
|
+
const normalized = {
|
|
841
|
+
...settings.value === true ? { value: true } : {},
|
|
842
|
+
...settings.percent === true ? { percent: true } : {},
|
|
843
|
+
...settings.category === true ? { category: true } : {},
|
|
844
|
+
...settings.xValue === true ? { xValue: true } : {},
|
|
845
|
+
...settings.seriesName === true ? { seriesName: true } : {},
|
|
846
|
+
...settings.separator === void 0 ? {} : { separator: settings.separator },
|
|
847
|
+
...settings.position === void 0 ? {} : { position: settings.position },
|
|
848
|
+
...settings.numberFormat === void 0 ? {} : { numberFormat: settings.numberFormat },
|
|
849
|
+
...settings.leaderLines === void 0 ? {} : { leaderLines: settings.leaderLines }
|
|
850
|
+
};
|
|
851
|
+
return {
|
|
852
|
+
...Object.keys(normalized).length > 0 ? { dataLabels: normalized } : {},
|
|
853
|
+
...dataLabelsStyle === void 0 ? {} : { dataLabelsStyle },
|
|
854
|
+
pointLabels,
|
|
855
|
+
pointLabelColors,
|
|
856
|
+
...showDataLabelsRange === void 0 ? {} : { showDataLabelsRange }
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function diffPointDataLabels(pointLabels, seriesLabels) {
|
|
860
|
+
if (pointLabels === false) return false;
|
|
861
|
+
if (seriesLabels === void 0 || seriesLabels === false) return Object.keys(pointLabels).length === 0 ? void 0 : pointLabels;
|
|
862
|
+
const out = {};
|
|
863
|
+
for (const [key, value] of Object.entries(pointLabels)) {
|
|
864
|
+
if (value === void 0) continue;
|
|
865
|
+
const baseVal = seriesLabels[key];
|
|
866
|
+
if (!stableJsonEqual(value, baseVal)) out[key] = value;
|
|
867
|
+
}
|
|
868
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
869
|
+
}
|
|
870
|
+
function readSeriesTrendlines(serCursor, kind, stacking, pointCount, fitPoints) {
|
|
871
|
+
const nodes = serCursor.children(C_NS, "trendline");
|
|
872
|
+
if (nodes.length === 0) return void 0;
|
|
873
|
+
const supported = kind !== "pie" && kind !== "doughnut" && stacking === void 0;
|
|
874
|
+
const result = [];
|
|
875
|
+
for (const tl of nodes) {
|
|
876
|
+
const nameEl = tl.child(C_NS, "name");
|
|
877
|
+
if (nameEl !== void 0) consumeSubtree(nameEl);
|
|
878
|
+
const spPr = tl.child(C_NS, "spPr");
|
|
879
|
+
const line = spPr === void 0 ? void 0 : readLineFromSpPr(spPr).line;
|
|
880
|
+
if (spPr !== void 0) consumeSubtree(spPr);
|
|
881
|
+
const typeRaw = readValAttr(tl.child(C_NS, "trendlineType"));
|
|
882
|
+
const type = typeRaw === void 0 ? void 0 : chartTrendlineTypeFromNative[typeRaw];
|
|
883
|
+
const order = readIntVal(tl.child(C_NS, "order"));
|
|
884
|
+
const period = readIntVal(tl.child(C_NS, "period"));
|
|
885
|
+
const rawForward = readFloatVal(tl.child(C_NS, "forward"));
|
|
886
|
+
const rawBackward = readFloatVal(tl.child(C_NS, "backward"));
|
|
887
|
+
const rawIntercept = readFloatVal(tl.child(C_NS, "intercept"));
|
|
888
|
+
const displayRSquared = readBoolVal(tl.child(C_NS, "dispRSqr"));
|
|
889
|
+
const displayEquation = readBoolVal(tl.child(C_NS, "dispEq"));
|
|
890
|
+
consumeSubtree(tl);
|
|
891
|
+
if (!supported || type === void 0) continue;
|
|
892
|
+
const validForecast = (value) => {
|
|
893
|
+
if (value === void 0 || !Number.isFinite(value) || value <= 0) return;
|
|
894
|
+
if (kind !== "scatter" && Math.abs(value * 2 - Math.round(value * 2)) > 1e-9) return;
|
|
895
|
+
return value;
|
|
896
|
+
};
|
|
897
|
+
const forward = validForecast(rawForward);
|
|
898
|
+
const backward = validForecast(rawBackward);
|
|
899
|
+
const baseFields = {
|
|
900
|
+
...line === void 0 ? {} : { line },
|
|
901
|
+
...forward === void 0 ? {} : { forward },
|
|
902
|
+
...backward === void 0 ? {} : { backward }
|
|
903
|
+
};
|
|
904
|
+
if (type === "movingAverage") {
|
|
905
|
+
if (period !== void 0 && period >= 2 && period <= 255 && period < pointCount) result.push({
|
|
906
|
+
...baseFields,
|
|
907
|
+
type: "movingAverage",
|
|
908
|
+
period
|
|
909
|
+
});
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
const displayFields = {
|
|
913
|
+
...baseFields,
|
|
914
|
+
...displayEquation === void 0 ? {} : { displayEquation },
|
|
915
|
+
...displayRSquared === void 0 ? {} : { displayRSquared }
|
|
916
|
+
};
|
|
917
|
+
if (type === "polynomial") {
|
|
918
|
+
if (order !== void 0 && order >= 2 && order <= 6) result.push({
|
|
919
|
+
...displayFields,
|
|
920
|
+
type: "polynomial",
|
|
921
|
+
order,
|
|
922
|
+
...rawIntercept === void 0 ? {} : { intercept: rawIntercept }
|
|
923
|
+
});
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
if (type === "logarithmic") {
|
|
927
|
+
if (!fitPoints.some(({ x }) => x <= 0)) result.push({
|
|
928
|
+
...displayFields,
|
|
929
|
+
type: "logarithmic"
|
|
930
|
+
});
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
if (type === "exponential") {
|
|
934
|
+
if (!fitPoints.some(({ y }) => y <= 0)) result.push({
|
|
935
|
+
...displayFields,
|
|
936
|
+
type: "exponential",
|
|
937
|
+
...rawIntercept === void 0 ? {} : { intercept: rawIntercept }
|
|
938
|
+
});
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (type === "power") {
|
|
942
|
+
if (!fitPoints.some(({ x, y }) => x <= 0 || y <= 0)) result.push({
|
|
943
|
+
...displayFields,
|
|
944
|
+
type: "power"
|
|
945
|
+
});
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
result.push({
|
|
949
|
+
...displayFields,
|
|
950
|
+
type: "linear",
|
|
951
|
+
...rawIntercept === void 0 ? {} : { intercept: rawIntercept }
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
return result.length === 0 ? void 0 : result;
|
|
955
|
+
}
|
|
956
|
+
function alignErrorBarValues(values, pointCount) {
|
|
957
|
+
return Array.from({ length: pointCount }, (_, idx) => {
|
|
958
|
+
const v = values[idx];
|
|
959
|
+
return v !== void 0 && v !== null && Number.isFinite(v) && v >= 0 ? v : null;
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
function readSingleErrorBars(errCursor, pointCount) {
|
|
963
|
+
const direction = readValAttr(errCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "errDir")) === "x" ? "x" : "y";
|
|
964
|
+
const includeParsed = ErrBarTypeSchema.safeParse(errCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "errBarType")?.attrsObject(["val"]) ?? {});
|
|
965
|
+
const include = includeParsed.success ? includeParsed.data.val : "both";
|
|
966
|
+
const errValTypeRaw = readValAttr(errCursor.child(C_NS, "errValType"));
|
|
967
|
+
const barType = errValTypeRaw === void 0 ? void 0 : chartErrorBarValueTypeFromNative[errValTypeRaw];
|
|
968
|
+
const endCap = readBoolVal(errCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "noEndCap")) === true ? false : void 0;
|
|
969
|
+
const plusCursor = errCursor.child(C_NS, "plus");
|
|
970
|
+
const rawPlus = plusCursor === void 0 ? void 0 : readNumericDataSource(plusCursor);
|
|
971
|
+
if (plusCursor !== void 0) consumeSubtree(plusCursor);
|
|
972
|
+
const minusCursor = errCursor.child(C_NS, "minus");
|
|
973
|
+
const rawMinus = minusCursor === void 0 ? void 0 : readNumericDataSource(minusCursor);
|
|
974
|
+
if (minusCursor !== void 0) consumeSubtree(minusCursor);
|
|
975
|
+
const val = readFloatVal(errCursor.child(C_NS, "val"));
|
|
976
|
+
const spPr = errCursor.child(C_NS, "spPr");
|
|
977
|
+
const line = spPr === void 0 ? void 0 : readLineFromSpPr(spPr).line;
|
|
978
|
+
if (spPr !== void 0) consumeSubtree(spPr);
|
|
979
|
+
consumeSubtree(errCursor);
|
|
980
|
+
if (barType === void 0) return { direction };
|
|
981
|
+
const styleFields = {
|
|
982
|
+
...endCap === void 0 ? {} : { endCap },
|
|
983
|
+
...line === void 0 ? {} : { line }
|
|
984
|
+
};
|
|
985
|
+
if (barType === "standardError") return {
|
|
986
|
+
direction,
|
|
987
|
+
bars: {
|
|
988
|
+
...styleFields,
|
|
989
|
+
type: "standardError",
|
|
990
|
+
...include === "both" ? {} : { include }
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
if (barType === "custom") {
|
|
994
|
+
const plus = rawPlus === void 0 ? void 0 : alignErrorBarValues(rawPlus, pointCount);
|
|
995
|
+
const minus = rawMinus === void 0 ? void 0 : alignErrorBarValues(rawMinus, pointCount);
|
|
996
|
+
let custom;
|
|
997
|
+
if (include === "plus" && plus !== void 0) custom = {
|
|
998
|
+
...styleFields,
|
|
999
|
+
type: "custom",
|
|
1000
|
+
include: "plus",
|
|
1001
|
+
plus
|
|
1002
|
+
};
|
|
1003
|
+
else if (include === "minus" && minus !== void 0) custom = {
|
|
1004
|
+
...styleFields,
|
|
1005
|
+
type: "custom",
|
|
1006
|
+
include: "minus",
|
|
1007
|
+
minus
|
|
1008
|
+
};
|
|
1009
|
+
else if (plus !== void 0 && minus !== void 0) custom = {
|
|
1010
|
+
...styleFields,
|
|
1011
|
+
type: "custom",
|
|
1012
|
+
include: "both",
|
|
1013
|
+
plus,
|
|
1014
|
+
minus
|
|
1015
|
+
};
|
|
1016
|
+
return {
|
|
1017
|
+
direction,
|
|
1018
|
+
...custom === void 0 ? {} : { bars: custom }
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
if (val === void 0 || !Number.isFinite(val) || val < 0) return { direction };
|
|
1022
|
+
return {
|
|
1023
|
+
direction,
|
|
1024
|
+
bars: {
|
|
1025
|
+
...styleFields,
|
|
1026
|
+
type: barType,
|
|
1027
|
+
value: val,
|
|
1028
|
+
...include === "both" ? {} : { include }
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function readCategoryErrorBars(serCursor, kind, pointCount) {
|
|
1033
|
+
const nodes = serCursor.children(C_NS, "errBars");
|
|
1034
|
+
if (nodes.length === 0) return void 0;
|
|
1035
|
+
let result;
|
|
1036
|
+
for (const node of nodes) {
|
|
1037
|
+
const parsed = readSingleErrorBars(node, pointCount);
|
|
1038
|
+
if (kind !== "pie" && kind !== "doughnut" && result === void 0) result = parsed.bars;
|
|
1039
|
+
}
|
|
1040
|
+
return result;
|
|
1041
|
+
}
|
|
1042
|
+
function readScatterErrorBars(serCursor, pointCount) {
|
|
1043
|
+
const nodes = serCursor.children(C_NS, "errBars");
|
|
1044
|
+
if (nodes.length === 0) return void 0;
|
|
1045
|
+
let x;
|
|
1046
|
+
let y;
|
|
1047
|
+
for (const node of nodes) {
|
|
1048
|
+
const parsed = readSingleErrorBars(node, pointCount);
|
|
1049
|
+
if (parsed.bars === void 0) continue;
|
|
1050
|
+
if (parsed.direction === "x" && x === void 0) x = parsed.bars;
|
|
1051
|
+
else if (parsed.direction === "y" && y === void 0) y = parsed.bars;
|
|
1052
|
+
}
|
|
1053
|
+
if (x === void 0 && y === void 0) return void 0;
|
|
1054
|
+
return {
|
|
1055
|
+
...x === void 0 ? {} : { x },
|
|
1056
|
+
...y === void 0 ? {} : { y }
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
function readCategorySeries(serCursor, kind, fallbackIndex, stacking, inheritedChartStyle) {
|
|
1060
|
+
const idx = readIntVal(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "idx")) ?? fallbackIndex;
|
|
1061
|
+
const order = readIntVal(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "order")) ?? idx;
|
|
1062
|
+
const name = readSeriesName(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "tx")) ?? `Series ${fallbackIndex + 1}`;
|
|
1063
|
+
const spPr = serCursor.child(C_NS, "spPr");
|
|
1064
|
+
const { color, line } = spPr === void 0 ? {} : readSeriesSpPr(spPr, false);
|
|
1065
|
+
const invertIfNegative = serCursor.child(C_NS, "invertIfNegative");
|
|
1066
|
+
if (invertIfNegative !== void 0) consumeSubtree(invertIfNegative);
|
|
1067
|
+
const markerCursor = serCursor.child(C_NS, "marker");
|
|
1068
|
+
const marker = markerCursor === void 0 ? void 0 : kind === "line" ? readMarkerElement(markerCursor) : (consumeSubtree(markerCursor), void 0);
|
|
1069
|
+
const explosionVal = readIntVal(serCursor.child(C_NS, "explosion"));
|
|
1070
|
+
const explosion = (kind === "pie" || kind === "doughnut") && explosionVal !== void 0 && explosionVal >= 0 ? explosionVal : void 0;
|
|
1071
|
+
const pointsRecord = {};
|
|
1072
|
+
for (const dPt of serCursor.children(C_NS, "dPt")) {
|
|
1073
|
+
const pointIdx = readIntVal(dPt.child(C_NS, "idx"));
|
|
1074
|
+
const inv = dPt.child(C_NS, "invertIfNegative");
|
|
1075
|
+
if (inv !== void 0) consumeSubtree(inv);
|
|
1076
|
+
const bubble3D = dPt.child(C_NS, "bubble3D");
|
|
1077
|
+
if (bubble3D !== void 0) consumeSubtree(bubble3D);
|
|
1078
|
+
const pMarkerCursor = dPt.child(C_NS, "marker");
|
|
1079
|
+
const pMarker = pMarkerCursor === void 0 ? void 0 : kind === "line" ? readMarkerElement(pMarkerCursor) : (consumeSubtree(pMarkerCursor), void 0);
|
|
1080
|
+
const pExplosionVal = readIntVal(dPt.child(C_NS, "explosion"));
|
|
1081
|
+
const pExplosion = (kind === "pie" || kind === "doughnut") && pExplosionVal !== void 0 && pExplosionVal >= 0 ? pExplosionVal : void 0;
|
|
1082
|
+
const pSpPr = dPt.child(C_NS, "spPr");
|
|
1083
|
+
const pStyle = pSpPr === void 0 ? {} : readSeriesSpPr(pSpPr, false);
|
|
1084
|
+
consumeSubtree(dPt);
|
|
1085
|
+
if (pointIdx !== void 0 && pointIdx >= 0) {
|
|
1086
|
+
const pointColor = kind === "area" ? void 0 : pStyle.color;
|
|
1087
|
+
if (pointColor !== void 0 || pStyle.line !== void 0 || pMarker !== void 0 || pExplosion !== void 0) pointsRecord[pointIdx] = {
|
|
1088
|
+
...pointColor === void 0 ? {} : { color: pointColor },
|
|
1089
|
+
...pStyle.line === void 0 ? {} : { line: pStyle.line },
|
|
1090
|
+
...pMarker === void 0 ? {} : { marker: pMarker },
|
|
1091
|
+
...pExplosion === void 0 ? {} : { explosion: pExplosion }
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
const dLblsCursor = serCursor.child(C_NS, "dLbls");
|
|
1096
|
+
const dLblsResult = dLblsCursor === void 0 ? void 0 : readDataLabelsElement(dLblsCursor, kind, false, inheritedChartStyle);
|
|
1097
|
+
if (dLblsResult !== void 0) {
|
|
1098
|
+
for (const [ptIdx, labelColor] of dLblsResult.pointLabelColors.entries()) pointsRecord[ptIdx] = {
|
|
1099
|
+
...pointsRecord[ptIdx] ?? {},
|
|
1100
|
+
labelColor
|
|
1101
|
+
};
|
|
1102
|
+
for (const [ptIdx, ptLabel] of dLblsResult.pointLabels.entries()) {
|
|
1103
|
+
const diffed = diffPointDataLabels(ptLabel, dLblsResult.dataLabels);
|
|
1104
|
+
if (diffed === void 0) continue;
|
|
1105
|
+
pointsRecord[ptIdx] = {
|
|
1106
|
+
...pointsRecord[ptIdx] ?? {},
|
|
1107
|
+
dataLabels: diffed
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
const catCursor = serCursor.child(C_NS, "cat");
|
|
1112
|
+
const catData = catCursor === void 0 ? { values: [] } : readStringDataSource(catCursor);
|
|
1113
|
+
const valCursor = serCursor.child(C_NS, "val");
|
|
1114
|
+
const valData = valCursor === void 0 ? [] : readNumericDataSource(valCursor);
|
|
1115
|
+
const smoothVal = readBoolVal(serCursor.child(C_NS, "smooth"));
|
|
1116
|
+
const smooth = kind === "line" ? smoothVal : void 0;
|
|
1117
|
+
const fitPoints = valData.flatMap((y, valueIndex) => y === null || !Number.isFinite(y) ? [] : [{
|
|
1118
|
+
x: valueIndex + 1,
|
|
1119
|
+
y
|
|
1120
|
+
}]);
|
|
1121
|
+
const trendlines = readSeriesTrendlines(serCursor, kind, stacking, valData.length, fitPoints);
|
|
1122
|
+
const errorBars = readCategoryErrorBars(serCursor, kind, valData.length);
|
|
1123
|
+
let datalabelsRange;
|
|
1124
|
+
const extLst = serCursor.child(C_NS, "extLst");
|
|
1125
|
+
if (extLst !== void 0) for (const ext of extLst.children(C_NS, "ext")) {
|
|
1126
|
+
const uri = ext.attr("uri");
|
|
1127
|
+
if (uri === C15_CAT_RANGE_EXT_URI) {
|
|
1128
|
+
const range = ext.child(C15_NS, "datalabelsRange");
|
|
1129
|
+
if (range !== void 0) {
|
|
1130
|
+
const f = range.child(C15_NS, "f");
|
|
1131
|
+
if (f !== void 0) consumeSubtree(f);
|
|
1132
|
+
const cache = range.child(C15_NS, "dlblRangeCache");
|
|
1133
|
+
if (cache !== void 0) datalabelsRange = readStringCacheOrLit(cache);
|
|
1134
|
+
consumeSubtree(range);
|
|
1135
|
+
}
|
|
1136
|
+
consumeSubtree(ext);
|
|
1137
|
+
} else if (uri === C16_UNIQUE_ID_EXT_URI) consumeSubtree(ext);
|
|
1138
|
+
}
|
|
1139
|
+
const pointCount = Math.max(catData.values.length, valData.length);
|
|
1140
|
+
const categories = catData.values.length === 0 && valData.length > 0 ? Array.from({ length: valData.length }, (_, i) => String(i + 1)) : catData.values;
|
|
1141
|
+
const normalizedPoints = {};
|
|
1142
|
+
for (const [key, pt] of Object.entries(pointsRecord)) {
|
|
1143
|
+
const numKey = Number(key);
|
|
1144
|
+
if (numKey >= 0 && Number.isSafeInteger(numKey)) normalizedPoints[numKey] = pt;
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
order,
|
|
1148
|
+
name: name.trim() === "" ? `Series ${fallbackIndex + 1}` : name,
|
|
1149
|
+
categories,
|
|
1150
|
+
...catData.formula === void 0 ? {} : { categoryFormula: catData.formula },
|
|
1151
|
+
values: valData,
|
|
1152
|
+
...color === void 0 ? {} : { color },
|
|
1153
|
+
...line === void 0 ? {} : { line },
|
|
1154
|
+
...explosion === void 0 ? {} : { explosion },
|
|
1155
|
+
...marker === void 0 ? {} : { marker },
|
|
1156
|
+
...smooth === void 0 ? {} : { smooth },
|
|
1157
|
+
...dLblsResult?.dataLabels === void 0 ? {} : { dataLabels: dLblsResult.dataLabels },
|
|
1158
|
+
...dLblsResult?.dataLabelsStyle === void 0 ? {} : { dataLabelsStyle: dLblsResult.dataLabelsStyle },
|
|
1159
|
+
...Object.keys(normalizedPoints).length === 0 ? {} : { points: normalizedPoints },
|
|
1160
|
+
...trendlines === void 0 || pointCount === 0 ? {} : { trendlines },
|
|
1161
|
+
...errorBars === void 0 ? {} : { errorBars },
|
|
1162
|
+
...datalabelsRange === void 0 || datalabelsRange.length === 0 ? {} : { datalabelsRange }
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
function readScatterSeries(serCursor, groupLine, groupMarkers, fallbackIndex, inheritedChartStyle) {
|
|
1166
|
+
const idx = readIntVal(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "idx")) ?? fallbackIndex;
|
|
1167
|
+
const order = readIntVal(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "order")) ?? idx;
|
|
1168
|
+
const name = readSeriesName(serCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "tx")) ?? `Series ${fallbackIndex + 1}`;
|
|
1169
|
+
const spPr = serCursor.child(C_NS, "spPr");
|
|
1170
|
+
const spStyle = spPr === void 0 ? {} : readSeriesSpPr(spPr, !(groupLine !== void 0 && groupLine !== false));
|
|
1171
|
+
const markerCursor = serCursor.child(C_NS, "marker");
|
|
1172
|
+
const rawMarker = markerCursor === void 0 ? void 0 : readMarkerElement(markerCursor);
|
|
1173
|
+
const marker = !groupMarkers && rawMarker !== void 0 && rawMarker !== false ? void 0 : rawMarker;
|
|
1174
|
+
const pointsRecord = {};
|
|
1175
|
+
for (const dPt of serCursor.children(C_NS, "dPt")) {
|
|
1176
|
+
const pointIdx = readIntVal(dPt.child(C_NS, "idx"));
|
|
1177
|
+
const pMarkerCursor = dPt.child(C_NS, "marker");
|
|
1178
|
+
const rawPMarker = pMarkerCursor === void 0 ? void 0 : readMarkerElement(pMarkerCursor);
|
|
1179
|
+
const pMarker = !groupMarkers && rawPMarker !== void 0 && rawPMarker !== false ? void 0 : rawPMarker;
|
|
1180
|
+
const pSpPr = dPt.child(C_NS, "spPr");
|
|
1181
|
+
const pStyle = pSpPr === void 0 ? {} : readSeriesSpPr(pSpPr, false);
|
|
1182
|
+
consumeSubtree(dPt);
|
|
1183
|
+
if (pointIdx !== void 0 && pointIdx >= 0) {
|
|
1184
|
+
if (pStyle.color !== void 0 || pStyle.line !== void 0 || pMarker !== void 0) pointsRecord[pointIdx] = {
|
|
1185
|
+
...pStyle.color === void 0 ? {} : { color: pStyle.color },
|
|
1186
|
+
...pStyle.line === void 0 ? {} : { line: pStyle.line },
|
|
1187
|
+
...pMarker === void 0 ? {} : { marker: pMarker }
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
const dLblsCursor = serCursor.child(C_NS, "dLbls");
|
|
1192
|
+
const dLblsResult = dLblsCursor === void 0 ? void 0 : readDataLabelsElement(dLblsCursor, "scatter", false, inheritedChartStyle);
|
|
1193
|
+
if (dLblsResult !== void 0) {
|
|
1194
|
+
for (const [ptIdx, labelColor] of dLblsResult.pointLabelColors.entries()) pointsRecord[ptIdx] = {
|
|
1195
|
+
...pointsRecord[ptIdx] ?? {},
|
|
1196
|
+
labelColor
|
|
1197
|
+
};
|
|
1198
|
+
for (const [ptIdx, ptLabel] of dLblsResult.pointLabels.entries()) {
|
|
1199
|
+
const diffed = diffPointDataLabels(ptLabel, dLblsResult.dataLabels);
|
|
1200
|
+
if (diffed === void 0) continue;
|
|
1201
|
+
pointsRecord[ptIdx] = {
|
|
1202
|
+
...pointsRecord[ptIdx] ?? {},
|
|
1203
|
+
dataLabels: diffed
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
const xCursor = serCursor.child(C_NS, "xVal");
|
|
1208
|
+
const yCursor = serCursor.child(C_NS, "yVal");
|
|
1209
|
+
let x = xCursor === void 0 ? [] : readNumericDataSource(xCursor);
|
|
1210
|
+
let y = yCursor === void 0 ? [] : readNumericDataSource(yCursor);
|
|
1211
|
+
if (x.length !== y.length) {
|
|
1212
|
+
const maxLen = Math.max(x.length, y.length);
|
|
1213
|
+
if (x.length < maxLen) x = [...x, ...Array.from({ length: maxLen - x.length }).fill(null)];
|
|
1214
|
+
if (y.length < maxLen) y = [...y, ...Array.from({ length: maxLen - y.length }).fill(null)];
|
|
1215
|
+
}
|
|
1216
|
+
const fitPoints = x.flatMap((xv, pointIdx) => {
|
|
1217
|
+
const yv = y[pointIdx];
|
|
1218
|
+
return xv === null || yv === void 0 || yv === null || !Number.isFinite(xv) || !Number.isFinite(yv) ? [] : [{
|
|
1219
|
+
x: xv,
|
|
1220
|
+
y: yv
|
|
1221
|
+
}];
|
|
1222
|
+
});
|
|
1223
|
+
const trendlines = readSeriesTrendlines(serCursor, "scatter", void 0, x.length, fitPoints);
|
|
1224
|
+
const errorBars = readScatterErrorBars(serCursor, x.length);
|
|
1225
|
+
const smoothCursor = serCursor.child(C_NS, "smooth");
|
|
1226
|
+
if (smoothCursor !== void 0) consumeSubtree(smoothCursor);
|
|
1227
|
+
const extLst = serCursor.child(C_NS, "extLst");
|
|
1228
|
+
if (extLst !== void 0) {
|
|
1229
|
+
for (const ext of extLst.children(C_NS, "ext")) if (ext.attr("uri") === C16_UNIQUE_ID_EXT_URI) consumeSubtree(ext);
|
|
1230
|
+
}
|
|
1231
|
+
const normalizedPoints = {};
|
|
1232
|
+
for (const [key, pt] of Object.entries(pointsRecord)) {
|
|
1233
|
+
const numKey = Number(key);
|
|
1234
|
+
if (numKey >= 0 && Number.isSafeInteger(numKey)) normalizedPoints[numKey] = pt;
|
|
1235
|
+
}
|
|
1236
|
+
return {
|
|
1237
|
+
order,
|
|
1238
|
+
...dLblsResult?.dataLabelsStyle === void 0 ? {} : { dataLabelsStyle: dLblsResult.dataLabelsStyle },
|
|
1239
|
+
series: {
|
|
1240
|
+
name: name.trim() === "" ? `Series ${fallbackIndex + 1}` : name,
|
|
1241
|
+
x,
|
|
1242
|
+
y,
|
|
1243
|
+
...spStyle.color === void 0 ? {} : { color: spStyle.color },
|
|
1244
|
+
...spStyle.line === void 0 ? {} : { line: spStyle.line },
|
|
1245
|
+
...dLblsResult?.dataLabels === void 0 ? {} : { dataLabels: dLblsResult.dataLabels },
|
|
1246
|
+
...marker === void 0 ? {} : { marker },
|
|
1247
|
+
...Object.keys(normalizedPoints).length === 0 ? {} : { points: normalizedPoints },
|
|
1248
|
+
...trendlines === void 0 ? {} : { trendlines },
|
|
1249
|
+
...errorBars === void 0 ? {} : { errorBars }
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
function readAxisGridline(el) {
|
|
1254
|
+
if (el === void 0) return void 0;
|
|
1255
|
+
const spPr = el.child(C_NS, "spPr");
|
|
1256
|
+
const result = spPr === void 0 ? true : readLineFromSpPr(spPr).line ?? true;
|
|
1257
|
+
consumeSubtree(el);
|
|
1258
|
+
return result;
|
|
1259
|
+
}
|
|
1260
|
+
function readAxisElement(axisCursor, kind, inheritedChartStyle) {
|
|
1261
|
+
const id = readIntVal(axisCursor.child(C_NS, "axId"));
|
|
1262
|
+
if (id === void 0) return void 0;
|
|
1263
|
+
let reversed;
|
|
1264
|
+
let min;
|
|
1265
|
+
let max;
|
|
1266
|
+
let logBase;
|
|
1267
|
+
const scaling = axisCursor.child(C_NS, "scaling");
|
|
1268
|
+
if (scaling !== void 0) {
|
|
1269
|
+
if (readValAttr(scaling.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "orientation")) === "maxMin") reversed = true;
|
|
1270
|
+
if (kind === "value") {
|
|
1271
|
+
logBase = readFloatVal(scaling.child(C_NS, "logBase"));
|
|
1272
|
+
min = readFloatVal(scaling.child(C_NS, "min"));
|
|
1273
|
+
max = readFloatVal(scaling.child(C_NS, "max"));
|
|
1274
|
+
}
|
|
1275
|
+
consumeSubtree(scaling);
|
|
1276
|
+
}
|
|
1277
|
+
const visible = readBoolVal(axisCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "delete")) === true ? false : void 0;
|
|
1278
|
+
let position;
|
|
1279
|
+
const axPos = axisCursor.child(C_NS, "axPos");
|
|
1280
|
+
if (axPos !== void 0) {
|
|
1281
|
+
const val = axPos.attrsObject(["val"])["val"];
|
|
1282
|
+
if (val !== void 0) position = chartAxisPositionFromNative[val];
|
|
1283
|
+
}
|
|
1284
|
+
const gridlines = readAxisGridline(axisCursor.child(C_NS, "majorGridlines"));
|
|
1285
|
+
const minorGridlines = readAxisGridline(axisCursor.child(C_NS, "minorGridlines"));
|
|
1286
|
+
const txPr = axisCursor.child(C_NS, "txPr");
|
|
1287
|
+
const rawAxisStyle = txPr === void 0 ? void 0 : readChartTextProperties(txPr);
|
|
1288
|
+
const style = diffChartTextStyle(rawAxisStyle, inheritedChartStyle);
|
|
1289
|
+
const titleCursor = axisCursor.child(C_NS, "title");
|
|
1290
|
+
const title = titleCursor === void 0 ? void 0 : readChartTitle(titleCursor, rawAxisStyle === void 0 && inheritedChartStyle === void 0 ? void 0 : {
|
|
1291
|
+
...inheritedChartStyle,
|
|
1292
|
+
...rawAxisStyle
|
|
1293
|
+
});
|
|
1294
|
+
const numFmtCursor = axisCursor.child(C_NS, "numFmt");
|
|
1295
|
+
let numberFormat;
|
|
1296
|
+
if (numFmtCursor !== void 0) {
|
|
1297
|
+
const code = numFmtCursor.attr("formatCode");
|
|
1298
|
+
const sourceLinked = numFmtCursor.attr("sourceLinked");
|
|
1299
|
+
if (kind === "value" && code !== void 0 && code.trim() !== "" && (sourceLinked === "0" || sourceLinked === "false" || code !== "General")) numberFormat = code;
|
|
1300
|
+
consumeSubtree(numFmtCursor);
|
|
1301
|
+
}
|
|
1302
|
+
const majorTickParsed = TickMarkSchema.safeParse(axisCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "majorTickMark")?.attrsObject(["val"]) ?? {});
|
|
1303
|
+
const majorTickMark = majorTickParsed.success ? majorTickParsed.data.val : void 0;
|
|
1304
|
+
const minorTickParsed = TickMarkSchema.safeParse(axisCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "minorTickMark")?.attrsObject(["val"]) ?? {});
|
|
1305
|
+
const minorTickMark = minorTickParsed.success ? minorTickParsed.data.val : void 0;
|
|
1306
|
+
const tickLblParsed = TickLblPosSchema.safeParse(axisCursor.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "tickLblPos")?.attrsObject(["val"]) ?? {});
|
|
1307
|
+
const tickLabelPosition = tickLblParsed.success ? tickLblParsed.data.val : void 0;
|
|
1308
|
+
let line;
|
|
1309
|
+
const spPr = axisCursor.child(C_NS, "spPr");
|
|
1310
|
+
if (spPr !== void 0) {
|
|
1311
|
+
const lineRes = readLineFromSpPr(spPr);
|
|
1312
|
+
if (lineRes.noLine) line = false;
|
|
1313
|
+
else if (lineRes.line !== void 0) line = lineRes.line;
|
|
1314
|
+
consumeSubtree(spPr);
|
|
1315
|
+
}
|
|
1316
|
+
const crossAxisId = readIntVal(axisCursor.child(C_NS, "crossAx"));
|
|
1317
|
+
let rawCrossing;
|
|
1318
|
+
const crossesAtCursor = axisCursor.child(C_NS, "crossesAt");
|
|
1319
|
+
const crossesCursor = axisCursor.child(C_NS, "crosses");
|
|
1320
|
+
if (crossesAtCursor !== void 0) {
|
|
1321
|
+
const val = readFloatVal(crossesAtCursor);
|
|
1322
|
+
if (val !== void 0) rawCrossing = {
|
|
1323
|
+
kind: "crossesAt",
|
|
1324
|
+
value: val
|
|
1325
|
+
};
|
|
1326
|
+
} else if (crossesCursor !== void 0) {
|
|
1327
|
+
const parsedCross = CrossesSchema.safeParse(crossesCursor.attrsObject(["val"]));
|
|
1328
|
+
if (parsedCross.success) rawCrossing = {
|
|
1329
|
+
kind: "crosses",
|
|
1330
|
+
value: parsedCross.data.val
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
const majorUnit = kind === "value" ? readFloatVal(axisCursor.child(C_NS, "majorUnit")) : void 0;
|
|
1334
|
+
const minorUnit = kind === "value" ? readFloatVal(axisCursor.child(C_NS, "minorUnit")) : void 0;
|
|
1335
|
+
for (const tag of [
|
|
1336
|
+
"crossBetween",
|
|
1337
|
+
"auto",
|
|
1338
|
+
"lblAlgn",
|
|
1339
|
+
"lblOffset",
|
|
1340
|
+
"noMultiLvlLbl",
|
|
1341
|
+
"tickLblSkip",
|
|
1342
|
+
"tickMarkSkip"
|
|
1343
|
+
]) {
|
|
1344
|
+
const el = axisCursor.child(C_NS, tag);
|
|
1345
|
+
if (el !== void 0) consumeSubtree(el);
|
|
1346
|
+
}
|
|
1347
|
+
return {
|
|
1348
|
+
id,
|
|
1349
|
+
kind,
|
|
1350
|
+
...crossAxisId === void 0 ? {} : { crossAxisId },
|
|
1351
|
+
...position === void 0 ? {} : { position },
|
|
1352
|
+
...visible === void 0 ? {} : { visible },
|
|
1353
|
+
...reversed === void 0 ? {} : { reversed },
|
|
1354
|
+
...gridlines === void 0 ? {} : { gridlines },
|
|
1355
|
+
...minorGridlines === void 0 ? {} : { minorGridlines },
|
|
1356
|
+
...line === void 0 ? {} : { line },
|
|
1357
|
+
...style === void 0 ? {} : { style },
|
|
1358
|
+
...title === void 0 ? {} : { title },
|
|
1359
|
+
...majorTickMark === void 0 ? {} : { majorTickMark },
|
|
1360
|
+
...minorTickMark === void 0 ? {} : { minorTickMark },
|
|
1361
|
+
...tickLabelPosition === void 0 ? {} : { tickLabelPosition },
|
|
1362
|
+
...min === void 0 ? {} : { min },
|
|
1363
|
+
...max === void 0 ? {} : { max },
|
|
1364
|
+
...majorUnit !== void 0 && majorUnit > 0 ? { majorUnit } : {},
|
|
1365
|
+
...minorUnit !== void 0 && minorUnit > 0 ? { minorUnit } : {},
|
|
1366
|
+
...numberFormat === void 0 ? {} : { numberFormat },
|
|
1367
|
+
...logBase !== void 0 && logBase >= 2 && logBase <= 1e3 ? { logBase } : {},
|
|
1368
|
+
...rawCrossing === void 0 ? {} : { rawCrossing }
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
function readChartGroupElement(groupCursor, inheritedChartStyle) {
|
|
1372
|
+
const local = groupCursor.localName;
|
|
1373
|
+
const varyColors = groupCursor.child(C_NS, "varyColors");
|
|
1374
|
+
if (varyColors !== void 0) consumeSubtree(varyColors);
|
|
1375
|
+
if (local === "scatterChart") {
|
|
1376
|
+
const styleCursor = groupCursor.child(C_NS, "scatterStyle");
|
|
1377
|
+
const parsedStyle = ScatterStyleSchema.safeParse(styleCursor?.attrsObject(["val"]) ?? {});
|
|
1378
|
+
const styleVal = parsedStyle.success ? parsedStyle.data.val : "lineMarker";
|
|
1379
|
+
let line;
|
|
1380
|
+
let markers = true;
|
|
1381
|
+
if (styleVal === "marker") {
|
|
1382
|
+
line = false;
|
|
1383
|
+
markers = true;
|
|
1384
|
+
} else if (styleVal === "line") {
|
|
1385
|
+
line = "straight";
|
|
1386
|
+
markers = false;
|
|
1387
|
+
} else if (styleVal === "lineMarker") {
|
|
1388
|
+
line = "straight";
|
|
1389
|
+
markers = true;
|
|
1390
|
+
} else if (styleVal === "smooth") {
|
|
1391
|
+
line = "smooth";
|
|
1392
|
+
markers = false;
|
|
1393
|
+
} else if (styleVal === "smoothMarker") {
|
|
1394
|
+
line = "smooth";
|
|
1395
|
+
markers = true;
|
|
1396
|
+
}
|
|
1397
|
+
const rawEntries = groupCursor.children(C_NS, "ser").map((ser, idx) => readScatterSeries(ser, line, markers, idx, inheritedChartStyle)).toSorted((a, b) => a.order - b.order);
|
|
1398
|
+
const rawSeries = rawEntries.map((entry) => entry.series);
|
|
1399
|
+
const seriesDataLabelsStyle = rawEntries.find((entry) => entry.dataLabelsStyle !== void 0)?.dataLabelsStyle;
|
|
1400
|
+
const dLblsCursor = groupCursor.child(C_NS, "dLbls");
|
|
1401
|
+
const groupLabels = (dLblsCursor === void 0 ? void 0 : readDataLabelsElement(dLblsCursor, "scatter", true, inheritedChartStyle))?.dataLabels;
|
|
1402
|
+
return {
|
|
1403
|
+
kind: "scatter",
|
|
1404
|
+
axisIds: groupCursor.children(C_NS, "axId").map((c) => readIntVal(c)).filter((v) => v !== void 0),
|
|
1405
|
+
series: rawSeries,
|
|
1406
|
+
markers,
|
|
1407
|
+
...line === void 0 ? {} : { line },
|
|
1408
|
+
...groupLabels === void 0 ? {} : { dataLabels: groupLabels },
|
|
1409
|
+
...seriesDataLabelsStyle === void 0 ? {} : { seriesDataLabelsStyle }
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
let kind;
|
|
1413
|
+
if (local === "barChart") {
|
|
1414
|
+
const barDirCursor = groupCursor.child(C_NS, "barDir");
|
|
1415
|
+
const parsedDir = BarDirSchema.safeParse(barDirCursor?.attrsObject(["val"]) ?? {});
|
|
1416
|
+
kind = parsedDir.success && parsedDir.data.val === "bar" ? "bar" : "column";
|
|
1417
|
+
} else if (local === "lineChart") kind = "line";
|
|
1418
|
+
else if (local === "areaChart") kind = "area";
|
|
1419
|
+
else if (local === "pieChart") kind = "pie";
|
|
1420
|
+
else if (local === "doughnutChart") kind = "doughnut";
|
|
1421
|
+
else return;
|
|
1422
|
+
let stacking;
|
|
1423
|
+
if (kind === "column" || kind === "bar" || kind === "line" || kind === "area") {
|
|
1424
|
+
const groupingCursor = groupCursor.child(C_NS, "grouping");
|
|
1425
|
+
const parsedGrouping = GroupingSchema.safeParse(groupingCursor?.attrsObject(["val"]) ?? {});
|
|
1426
|
+
if (parsedGrouping.success) {
|
|
1427
|
+
if (parsedGrouping.data.val === "stacked") stacking = "stacked";
|
|
1428
|
+
else if (parsedGrouping.data.val === "percentStacked") stacking = "percent";
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const rawSeries = groupCursor.children(C_NS, "ser").map((ser, idx) => readCategorySeries(ser, kind, idx, stacking, inheritedChartStyle)).toSorted((a, b) => a.order - b.order);
|
|
1432
|
+
const seriesDataLabelsStyle = rawSeries.find((entry) => entry.dataLabelsStyle !== void 0)?.dataLabelsStyle;
|
|
1433
|
+
const dLblsCursor = groupCursor.child(C_NS, "dLbls");
|
|
1434
|
+
const groupLabels = (dLblsCursor === void 0 ? void 0 : readDataLabelsElement(dLblsCursor, kind, true, inheritedChartStyle))?.dataLabels;
|
|
1435
|
+
let gapWidth;
|
|
1436
|
+
let overlap;
|
|
1437
|
+
if (kind === "column" || kind === "bar") {
|
|
1438
|
+
const gw = readIntVal(groupCursor.child(C_NS, "gapWidth"));
|
|
1439
|
+
if (gw !== void 0 && gw >= 0 && gw <= 500) gapWidth = gw;
|
|
1440
|
+
const ov = readIntVal(groupCursor.child(C_NS, "overlap"));
|
|
1441
|
+
if (ov !== void 0 && ov >= -100 && ov <= 100) overlap = ov;
|
|
1442
|
+
}
|
|
1443
|
+
if (kind === "line") {
|
|
1444
|
+
const markerEl = groupCursor.child(C_NS, "marker");
|
|
1445
|
+
if (markerEl !== void 0) consumeSubtree(markerEl);
|
|
1446
|
+
const smoothEl = groupCursor.child(C_NS, "smooth");
|
|
1447
|
+
if (smoothEl !== void 0) consumeSubtree(smoothEl);
|
|
1448
|
+
}
|
|
1449
|
+
let firstSliceAngle;
|
|
1450
|
+
let holeSize;
|
|
1451
|
+
if (kind === "pie" || kind === "doughnut") {
|
|
1452
|
+
const ang = readIntVal(groupCursor.child(C_NS, "firstSliceAng"));
|
|
1453
|
+
if (ang !== void 0 && ang >= 0 && ang <= 360) firstSliceAngle = ang;
|
|
1454
|
+
if (kind === "doughnut") {
|
|
1455
|
+
const hs = readIntVal(groupCursor.child(C_NS, "holeSize"));
|
|
1456
|
+
if (hs !== void 0 && hs >= 10 && hs <= 90) holeSize = hs;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
const axisIds = groupCursor.children(C_NS, "axId").map((c) => readIntVal(c)).filter((v) => v !== void 0);
|
|
1460
|
+
return {
|
|
1461
|
+
kind,
|
|
1462
|
+
axisIds,
|
|
1463
|
+
series: rawSeries,
|
|
1464
|
+
...groupLabels === void 0 ? {} : { dataLabels: groupLabels },
|
|
1465
|
+
...seriesDataLabelsStyle === void 0 ? {} : { seriesDataLabelsStyle },
|
|
1466
|
+
...stacking === void 0 ? {} : { stacking },
|
|
1467
|
+
...gapWidth === void 0 ? {} : { gapWidth },
|
|
1468
|
+
...overlap === void 0 ? {} : { overlap },
|
|
1469
|
+
...firstSliceAngle === void 0 ? {} : { firstSliceAngle },
|
|
1470
|
+
...holeSize === void 0 ? {} : { holeSize }
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function narrowGroupDataLabels(labels, allowedPositions) {
|
|
1474
|
+
if (labels === void 0 || labels === false) return labels;
|
|
1475
|
+
const { position, xValue: _xValue, ...rest } = labels;
|
|
1476
|
+
if (position !== void 0 && allowedPositions.includes(position)) return {
|
|
1477
|
+
...rest,
|
|
1478
|
+
position
|
|
1479
|
+
};
|
|
1480
|
+
return rest;
|
|
1481
|
+
}
|
|
1482
|
+
function sameStringArray(a, b) {
|
|
1483
|
+
return a.length === b.length && a.every((item, idx) => item === b[idx]);
|
|
1484
|
+
}
|
|
1485
|
+
function sameRawCrossing(left, right) {
|
|
1486
|
+
return left.kind === right.kind && left.value === right.value;
|
|
1487
|
+
}
|
|
1488
|
+
function positionForImportedRawCrossing(crossing, partner, direction) {
|
|
1489
|
+
if (crossing.kind !== "crosses" || crossing.value === "autoZero") return;
|
|
1490
|
+
const maxAtFarEnd = partner.reversed !== true;
|
|
1491
|
+
if (direction === "vertical") return crossing.value === "max" === maxAtFarEnd ? "right" : "left";
|
|
1492
|
+
return crossing.value === "max" === maxAtFarEnd ? "top" : "bottom";
|
|
1493
|
+
}
|
|
1494
|
+
function importedCrossesKnownValueInterior(crossing, partner) {
|
|
1495
|
+
if (partner.kind !== "value") return false;
|
|
1496
|
+
if (partner.min === void 0 || partner.max === void 0) return false;
|
|
1497
|
+
const low = Math.min(partner.min, partner.max);
|
|
1498
|
+
const high = Math.max(partner.min, partner.max);
|
|
1499
|
+
if (crossing.kind === "crossesAt") return crossing.value > low && crossing.value < high;
|
|
1500
|
+
return crossing.kind === "crosses" && crossing.value === "autoZero" && low < 0 && high > 0;
|
|
1501
|
+
}
|
|
1502
|
+
function importedKnownValueEndpoint(crossing, partner) {
|
|
1503
|
+
if (partner.kind !== "value") return void 0;
|
|
1504
|
+
if (partner.min === void 0 || partner.max === void 0 || partner.min === partner.max) return;
|
|
1505
|
+
if (crossing.kind === "crossesAt") {
|
|
1506
|
+
if (crossing.value === partner.min) return "min";
|
|
1507
|
+
if (crossing.value === partner.max) return "max";
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (crossing.kind !== "crosses" || crossing.value !== "autoZero") return;
|
|
1511
|
+
if (partner.min === 0) return "min";
|
|
1512
|
+
if (partner.max === 0) return "max";
|
|
1513
|
+
}
|
|
1514
|
+
function withLiftedDataLabelsStyle(groupLabels, seriesStyle) {
|
|
1515
|
+
if (seriesStyle === void 0) return groupLabels;
|
|
1516
|
+
if (groupLabels === false || groupLabels === void 0) return { style: seriesStyle };
|
|
1517
|
+
return groupLabels.style === void 0 ? {
|
|
1518
|
+
...groupLabels,
|
|
1519
|
+
style: seriesStyle
|
|
1520
|
+
} : groupLabels;
|
|
1521
|
+
}
|
|
1522
|
+
function trimSeriesPointsToLength(points, pointCount, chartLocation, diagnostics) {
|
|
1523
|
+
if (points === void 0) return void 0;
|
|
1524
|
+
const trimmed = {};
|
|
1525
|
+
for (const [rawKey, value] of Object.entries(points)) {
|
|
1526
|
+
const idx = Number(rawKey);
|
|
1527
|
+
if (!Number.isSafeInteger(idx) || idx < 0 || idx >= pointCount) {
|
|
1528
|
+
diagnostics.push({
|
|
1529
|
+
code: "invalid-xml-value",
|
|
1530
|
+
category: "corrupt-input",
|
|
1531
|
+
disposition: "recovered",
|
|
1532
|
+
location: chartLocation,
|
|
1533
|
+
attributeOrElement: "c:dPt/@idx",
|
|
1534
|
+
rawValue: rawKey
|
|
1535
|
+
});
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
trimmed[idx] = value;
|
|
1539
|
+
}
|
|
1540
|
+
return Object.keys(trimmed).length === 0 ? void 0 : trimmed;
|
|
1541
|
+
}
|
|
1542
|
+
function alignCustomErrorBars(errorBars, pointCount) {
|
|
1543
|
+
if (errorBars === void 0 || errorBars.type !== "custom") return errorBars;
|
|
1544
|
+
const plus = errorBars.plus === void 0 ? void 0 : alignErrorBarValues(errorBars.plus, pointCount);
|
|
1545
|
+
const minus = errorBars.minus === void 0 ? void 0 : alignErrorBarValues(errorBars.minus, pointCount);
|
|
1546
|
+
if (errorBars.include === "plus" && plus !== void 0) return {
|
|
1547
|
+
...errorBars,
|
|
1548
|
+
plus
|
|
1549
|
+
};
|
|
1550
|
+
if (errorBars.include === "minus" && minus !== void 0) return {
|
|
1551
|
+
...errorBars,
|
|
1552
|
+
minus
|
|
1553
|
+
};
|
|
1554
|
+
if (errorBars.include === "both" && plus !== void 0 && minus !== void 0) return {
|
|
1555
|
+
...errorBars,
|
|
1556
|
+
plus,
|
|
1557
|
+
minus
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
function filterValidTrendlines(trendlines, pointCount) {
|
|
1561
|
+
if (trendlines === void 0) return void 0;
|
|
1562
|
+
const kept = trendlines.filter((item) => item.type !== "movingAverage" || item.period < pointCount);
|
|
1563
|
+
return kept.length === 0 ? void 0 : kept;
|
|
1564
|
+
}
|
|
1565
|
+
function buildChartAxesAndGroups(groupDrafts, importedAxes, chartLocation, diagnostics) {
|
|
1566
|
+
const axisById = new Map(importedAxes.map((ax) => [ax.id, ax]));
|
|
1567
|
+
const axisDirectionById = /* @__PURE__ */ new Map();
|
|
1568
|
+
const referencedAxisIds = /* @__PURE__ */ new Set();
|
|
1569
|
+
const validGroupDrafts = [];
|
|
1570
|
+
for (const group of groupDrafts) {
|
|
1571
|
+
if (group.series.length === 0) {
|
|
1572
|
+
diagnostics.push({
|
|
1573
|
+
code: "corrupt-part",
|
|
1574
|
+
category: "corrupt-input",
|
|
1575
|
+
disposition: "omitted",
|
|
1576
|
+
location: chartLocation
|
|
1577
|
+
});
|
|
1578
|
+
continue;
|
|
1579
|
+
}
|
|
1580
|
+
if (group.kind === "pie" || group.kind === "doughnut") {
|
|
1581
|
+
validGroupDrafts.push(group);
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
if (group.kind === "scatter") {
|
|
1585
|
+
const [xId, yId] = group.axisIds;
|
|
1586
|
+
const xAx = xId === void 0 ? void 0 : axisById.get(xId);
|
|
1587
|
+
const yAx = yId === void 0 ? void 0 : axisById.get(yId);
|
|
1588
|
+
const xDir = xId === void 0 ? void 0 : axisDirectionById.get(xId);
|
|
1589
|
+
const yDir = yId === void 0 ? void 0 : axisDirectionById.get(yId);
|
|
1590
|
+
const nextAxisCount = referencedAxisIds.size + (xId !== void 0 && !referencedAxisIds.has(xId) ? 1 : 0) + (yId !== void 0 && yId !== xId && !referencedAxisIds.has(yId) ? 1 : 0);
|
|
1591
|
+
if (xAx === void 0 || yAx === void 0 || xAx.id === yAx.id || xAx.kind !== "value" || yAx.kind !== "value" || xDir !== void 0 && xDir !== "horizontal" || yDir !== void 0 && yDir !== "vertical" || nextAxisCount > 4) {
|
|
1592
|
+
diagnostics.push({
|
|
1593
|
+
code: "corrupt-part",
|
|
1594
|
+
category: "corrupt-input",
|
|
1595
|
+
disposition: "omitted",
|
|
1596
|
+
location: chartLocation
|
|
1597
|
+
});
|
|
1598
|
+
continue;
|
|
1599
|
+
}
|
|
1600
|
+
axisDirectionById.set(xAx.id, "horizontal");
|
|
1601
|
+
axisDirectionById.set(yAx.id, "vertical");
|
|
1602
|
+
referencedAxisIds.add(xAx.id);
|
|
1603
|
+
referencedAxisIds.add(yAx.id);
|
|
1604
|
+
validGroupDrafts.push(group);
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
const [catId, valId] = group.axisIds;
|
|
1608
|
+
const catAx = catId === void 0 ? void 0 : axisById.get(catId);
|
|
1609
|
+
const valAx = valId === void 0 ? void 0 : axisById.get(valId);
|
|
1610
|
+
const expectedCatDir = group.kind === "bar" ? "vertical" : "horizontal";
|
|
1611
|
+
const expectedValDir = group.kind === "bar" ? "horizontal" : "vertical";
|
|
1612
|
+
const catDir = catId === void 0 ? void 0 : axisDirectionById.get(catId);
|
|
1613
|
+
const valDir = valId === void 0 ? void 0 : axisDirectionById.get(valId);
|
|
1614
|
+
const nextAxisCount = referencedAxisIds.size + (catId !== void 0 && !referencedAxisIds.has(catId) ? 1 : 0) + (valId !== void 0 && valId !== catId && !referencedAxisIds.has(valId) ? 1 : 0);
|
|
1615
|
+
if (catAx === void 0 || valAx === void 0 || catAx.id === valAx.id || catAx.kind !== "category" || valAx.kind !== "value" || catDir !== void 0 && catDir !== expectedCatDir || valDir !== void 0 && valDir !== expectedValDir || nextAxisCount > 4) {
|
|
1616
|
+
diagnostics.push({
|
|
1617
|
+
code: "corrupt-part",
|
|
1618
|
+
category: "corrupt-input",
|
|
1619
|
+
disposition: "omitted",
|
|
1620
|
+
location: chartLocation
|
|
1621
|
+
});
|
|
1622
|
+
continue;
|
|
1623
|
+
}
|
|
1624
|
+
axisDirectionById.set(catAx.id, expectedCatDir);
|
|
1625
|
+
axisDirectionById.set(valAx.id, expectedValDir);
|
|
1626
|
+
referencedAxisIds.add(catAx.id);
|
|
1627
|
+
referencedAxisIds.add(valAx.id);
|
|
1628
|
+
validGroupDrafts.push(group);
|
|
1629
|
+
}
|
|
1630
|
+
if (validGroupDrafts.length === 0) return { groups: [] };
|
|
1631
|
+
const incomingByTarget = /* @__PURE__ */ new Map();
|
|
1632
|
+
for (const ax of importedAxes) {
|
|
1633
|
+
if (ax.crossAxisId === void 0) continue;
|
|
1634
|
+
const list = incomingByTarget.get(ax.crossAxisId) ?? [];
|
|
1635
|
+
list.push(ax);
|
|
1636
|
+
incomingByTarget.set(ax.crossAxisId, list);
|
|
1637
|
+
}
|
|
1638
|
+
const partnerCrossingFor = /* @__PURE__ */ new Map();
|
|
1639
|
+
const omitPositionIds = /* @__PURE__ */ new Set();
|
|
1640
|
+
for (const [targetId, incoming] of incomingByTarget.entries()) {
|
|
1641
|
+
const targetAxis = axisById.get(targetId);
|
|
1642
|
+
if (targetAxis === void 0 || incoming.length === 0) continue;
|
|
1643
|
+
const firstCrossing = incoming[0]?.rawCrossing;
|
|
1644
|
+
if (firstCrossing === void 0) continue;
|
|
1645
|
+
if (!incoming.every((ax) => ax.rawCrossing !== void 0 && sameRawCrossing(ax.rawCrossing, firstCrossing))) continue;
|
|
1646
|
+
if (firstCrossing.kind === "crossesAt") {
|
|
1647
|
+
if (targetAxis.kind === "category" && (!Number.isSafeInteger(firstCrossing.value) || firstCrossing.value < 1)) continue;
|
|
1648
|
+
partnerCrossingFor.set(targetId, firstCrossing);
|
|
1649
|
+
for (const ax of incoming) {
|
|
1650
|
+
if (ax.position === void 0) continue;
|
|
1651
|
+
const axDir = axisDirectionById.get(ax.id);
|
|
1652
|
+
const endpoint = importedKnownValueEndpoint(firstCrossing, targetAxis);
|
|
1653
|
+
const endpointEdge = endpoint !== void 0 && axDir !== void 0 ? positionForImportedRawCrossing({
|
|
1654
|
+
kind: "crosses",
|
|
1655
|
+
value: endpoint
|
|
1656
|
+
}, targetAxis, axDir) : void 0;
|
|
1657
|
+
if (importedCrossesKnownValueInterior(firstCrossing, targetAxis) || endpointEdge !== void 0 && endpointEdge !== ax.position) omitPositionIds.add(ax.id);
|
|
1658
|
+
}
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
if (firstCrossing.value === "autoZero") {
|
|
1662
|
+
if (importedCrossesKnownValueInterior(firstCrossing, targetAxis)) {
|
|
1663
|
+
partnerCrossingFor.set(targetId, firstCrossing);
|
|
1664
|
+
for (const ax of incoming) omitPositionIds.add(ax.id);
|
|
1665
|
+
}
|
|
1666
|
+
continue;
|
|
1667
|
+
}
|
|
1668
|
+
if (incoming.every((ax) => {
|
|
1669
|
+
if (ax.position === void 0) return true;
|
|
1670
|
+
const axDir = axisDirectionById.get(ax.id);
|
|
1671
|
+
if (axDir === void 0) return true;
|
|
1672
|
+
const edge = positionForImportedRawCrossing(firstCrossing, targetAxis, axDir);
|
|
1673
|
+
return edge === void 0 || edge === ax.position;
|
|
1674
|
+
})) partnerCrossingFor.set(targetId, firstCrossing);
|
|
1675
|
+
}
|
|
1676
|
+
const axisNameById = /* @__PURE__ */ new Map();
|
|
1677
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
1678
|
+
const assignName = (id, preferred) => {
|
|
1679
|
+
const existing = axisNameById.get(id);
|
|
1680
|
+
if (existing !== void 0) return existing;
|
|
1681
|
+
let candidate = preferred;
|
|
1682
|
+
let suffix = 2;
|
|
1683
|
+
while (usedNames.has(candidate)) {
|
|
1684
|
+
candidate = `${preferred}${suffix}`;
|
|
1685
|
+
suffix += 1;
|
|
1686
|
+
}
|
|
1687
|
+
usedNames.add(candidate);
|
|
1688
|
+
axisNameById.set(id, candidate);
|
|
1689
|
+
return candidate;
|
|
1690
|
+
};
|
|
1691
|
+
for (const group of validGroupDrafts) {
|
|
1692
|
+
if (group.kind === "pie" || group.kind === "doughnut") continue;
|
|
1693
|
+
if (group.kind === "scatter") {
|
|
1694
|
+
const [xId, yId] = group.axisIds;
|
|
1695
|
+
if (xId !== void 0) assignName(xId, "x");
|
|
1696
|
+
if (yId !== void 0) assignName(yId, "y");
|
|
1697
|
+
} else {
|
|
1698
|
+
const [catId, valId] = group.axisIds;
|
|
1699
|
+
if (catId !== void 0) assignName(catId, "category");
|
|
1700
|
+
if (valId !== void 0) assignName(valId, "value");
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
const axesRecord = {};
|
|
1704
|
+
for (const ax of importedAxes) {
|
|
1705
|
+
const name = axisNameById.get(ax.id);
|
|
1706
|
+
if (name === void 0) continue;
|
|
1707
|
+
const partnerCrossing = partnerCrossingFor.get(ax.id);
|
|
1708
|
+
const keepPosition = ax.position !== void 0 && !omitPositionIds.has(ax.id);
|
|
1709
|
+
const common = {
|
|
1710
|
+
...ax.visible === void 0 ? {} : { visible: ax.visible },
|
|
1711
|
+
...ax.gridlines === void 0 ? {} : { gridlines: ax.gridlines },
|
|
1712
|
+
...ax.minorGridlines === void 0 ? {} : { minorGridlines: ax.minorGridlines },
|
|
1713
|
+
...ax.line === void 0 ? {} : { line: ax.line },
|
|
1714
|
+
...ax.style === void 0 ? {} : { style: ax.style },
|
|
1715
|
+
...ax.title === void 0 ? {} : { title: ax.title },
|
|
1716
|
+
...ax.majorTickMark === void 0 ? {} : { majorTickMark: ax.majorTickMark },
|
|
1717
|
+
...ax.minorTickMark === void 0 ? {} : { minorTickMark: ax.minorTickMark },
|
|
1718
|
+
...ax.tickLabelPosition === void 0 ? {} : { tickLabelPosition: ax.tickLabelPosition },
|
|
1719
|
+
...ax.reversed === void 0 ? {} : { reversed: ax.reversed },
|
|
1720
|
+
...keepPosition ? { position: ax.position } : {},
|
|
1721
|
+
...partnerCrossing?.kind === "crosses" ? { crosses: partnerCrossing.value } : {},
|
|
1722
|
+
...partnerCrossing?.kind === "crossesAt" && (ax.kind !== "category" || Number.isSafeInteger(partnerCrossing.value) && partnerCrossing.value >= 1) ? { crossesAt: partnerCrossing.value } : {}
|
|
1723
|
+
};
|
|
1724
|
+
if (ax.kind === "category") axesRecord[name] = {
|
|
1725
|
+
kind: "category",
|
|
1726
|
+
...common
|
|
1727
|
+
};
|
|
1728
|
+
else axesRecord[name] = {
|
|
1729
|
+
kind: "value",
|
|
1730
|
+
...common,
|
|
1731
|
+
...ax.min === void 0 ? {} : { min: ax.min },
|
|
1732
|
+
...ax.max === void 0 ? {} : { max: ax.max },
|
|
1733
|
+
...ax.majorUnit === void 0 ? {} : { majorUnit: ax.majorUnit },
|
|
1734
|
+
...ax.minorUnit === void 0 ? {} : { minorUnit: ax.minorUnit },
|
|
1735
|
+
...ax.numberFormat === void 0 ? {} : { numberFormat: ax.numberFormat },
|
|
1736
|
+
...ax.logBase === void 0 ? {} : { logBase: ax.logBase }
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
const sharedDomainByCatAxis = /* @__PURE__ */ new Map();
|
|
1740
|
+
for (const group of validGroupDrafts) {
|
|
1741
|
+
if (group.kind === "scatter" || group.kind === "pie" || group.kind === "doughnut") continue;
|
|
1742
|
+
const catId = group.axisIds[0];
|
|
1743
|
+
if (catId === void 0 || sharedDomainByCatAxis.has(catId)) continue;
|
|
1744
|
+
const nonEmpty = group.series.find((s) => s.categories.length > 0);
|
|
1745
|
+
if (nonEmpty !== void 0) sharedDomainByCatAxis.set(catId, nonEmpty.categories);
|
|
1746
|
+
}
|
|
1747
|
+
const groups = validGroupDrafts.map((group) => {
|
|
1748
|
+
const liftedDataLabels = withLiftedDataLabelsStyle(group.dataLabels, group.seriesDataLabelsStyle);
|
|
1749
|
+
if (group.kind === "scatter") {
|
|
1750
|
+
const [xId, yId] = group.axisIds;
|
|
1751
|
+
const xName = xId === void 0 ? void 0 : axisNameById.get(xId);
|
|
1752
|
+
const yName = yId === void 0 ? void 0 : axisNameById.get(yId);
|
|
1753
|
+
const scatterMarkers = group.line !== void 0 && group.line !== false ? group.markers : true;
|
|
1754
|
+
return {
|
|
1755
|
+
kind: "scatter",
|
|
1756
|
+
data: { kind: "xy" },
|
|
1757
|
+
series: group.series.map((item) => {
|
|
1758
|
+
const trimmedPoints = trimSeriesPointsToLength(item.points, item.x.length, chartLocation, diagnostics);
|
|
1759
|
+
const trimmedTrendlines = filterValidTrendlines(item.trendlines, item.x.length);
|
|
1760
|
+
const xErr = alignCustomErrorBars(item.errorBars?.x, item.x.length);
|
|
1761
|
+
const yErr = alignCustomErrorBars(item.errorBars?.y, item.y.length);
|
|
1762
|
+
const errorBars = xErr !== void 0 || yErr !== void 0 ? {
|
|
1763
|
+
...xErr === void 0 ? {} : { x: xErr },
|
|
1764
|
+
...yErr === void 0 ? {} : { y: yErr }
|
|
1765
|
+
} : void 0;
|
|
1766
|
+
return {
|
|
1767
|
+
...item,
|
|
1768
|
+
...trimmedPoints === void 0 ? { points: void 0 } : { points: trimmedPoints },
|
|
1769
|
+
...trimmedTrendlines === void 0 ? { trendlines: void 0 } : { trendlines: trimmedTrendlines },
|
|
1770
|
+
...errorBars === void 0 ? { errorBars: void 0 } : { errorBars }
|
|
1771
|
+
};
|
|
1772
|
+
}).map((item) => {
|
|
1773
|
+
const { points: pt, trendlines: tl, errorBars: eb, ...rest } = item;
|
|
1774
|
+
return {
|
|
1775
|
+
...rest,
|
|
1776
|
+
...pt === void 0 ? {} : { points: pt },
|
|
1777
|
+
...tl === void 0 ? {} : { trendlines: tl },
|
|
1778
|
+
...eb === void 0 ? {} : { errorBars: eb }
|
|
1779
|
+
};
|
|
1780
|
+
}),
|
|
1781
|
+
...xName !== void 0 && yName !== void 0 && xName !== yName ? { axes: {
|
|
1782
|
+
x: xName,
|
|
1783
|
+
y: yName
|
|
1784
|
+
} } : {},
|
|
1785
|
+
...group.line === void 0 ? {} : { line: group.line },
|
|
1786
|
+
markers: scatterMarkers,
|
|
1787
|
+
...liftedDataLabels === void 0 ? {} : { dataLabels: liftedDataLabels }
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
if (group.kind === "doughnut") {
|
|
1791
|
+
if (group.series.some((s) => s.datalabelsRange !== void 0) || group.series.length > 1 && group.series.some((s) => s.categoryFormula !== void 0 && group.series[0]?.categoryFormula !== void 0 && s.categoryFormula !== group.series[0].categoryFormula || !sameStringArray(s.categories, group.series[0]?.categories ?? []))) {
|
|
1792
|
+
const series = group.series.map((item) => {
|
|
1793
|
+
const cats = item.datalabelsRange ?? item.categories;
|
|
1794
|
+
const values = (item.values.length === cats.length ? item.values : cats.map((_, idx) => item.values[idx] ?? null)).map((v) => v !== null && v < 0 ? null : v);
|
|
1795
|
+
const trimmedPoints = trimSeriesPointsToLength(item.points, cats.length, chartLocation, diagnostics);
|
|
1796
|
+
return {
|
|
1797
|
+
name: item.name,
|
|
1798
|
+
categories: cats,
|
|
1799
|
+
values,
|
|
1800
|
+
...item.color === void 0 ? {} : { color: item.color },
|
|
1801
|
+
...item.line === void 0 ? {} : { line: item.line },
|
|
1802
|
+
...item.explosion === void 0 ? {} : { explosion: item.explosion },
|
|
1803
|
+
...item.dataLabels === void 0 ? {} : { dataLabels: item.dataLabels },
|
|
1804
|
+
...trimmedPoints === void 0 ? {} : { points: trimmedPoints }
|
|
1805
|
+
};
|
|
1806
|
+
});
|
|
1807
|
+
const indDoughnutLabels = narrowGroupDataLabels(liftedDataLabels, []);
|
|
1808
|
+
return {
|
|
1809
|
+
kind: "doughnut",
|
|
1810
|
+
data: { kind: "independent-categories" },
|
|
1811
|
+
series,
|
|
1812
|
+
...group.firstSliceAngle === void 0 ? {} : { firstSliceAngle: group.firstSliceAngle },
|
|
1813
|
+
...group.holeSize === void 0 ? {} : { holeSize: group.holeSize },
|
|
1814
|
+
...indDoughnutLabels === void 0 ? {} : { dataLabels: indDoughnutLabels }
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
const catAxisId = group.kind === "pie" || group.kind === "doughnut" ? void 0 : group.axisIds[0];
|
|
1819
|
+
const domain = (catAxisId !== void 0 ? sharedDomainByCatAxis.get(catAxisId) : void 0) ?? group.series.find((s) => s.categories.length > 0)?.categories ?? [];
|
|
1820
|
+
const normalizedSeries = (group.kind === "pie" ? group.series.slice(0, 1) : group.series).map((item) => {
|
|
1821
|
+
const values = domain.length === 0 ? [] : item.values.length === domain.length ? item.values : domain.map((_, idx) => item.values[idx] ?? null);
|
|
1822
|
+
const safeValues = group.kind === "pie" || group.kind === "doughnut" ? values.map((v) => v !== null && v < 0 ? null : v) : values;
|
|
1823
|
+
const trimmedPoints = trimSeriesPointsToLength(item.points, domain.length, chartLocation, diagnostics);
|
|
1824
|
+
const trimmedTrendlines = filterValidTrendlines(item.trendlines, domain.length);
|
|
1825
|
+
const alignedErrorBars = alignCustomErrorBars(item.errorBars, domain.length);
|
|
1826
|
+
return {
|
|
1827
|
+
name: item.name,
|
|
1828
|
+
values: safeValues,
|
|
1829
|
+
...item.color === void 0 ? {} : { color: item.color },
|
|
1830
|
+
...item.line === void 0 ? {} : { line: item.line },
|
|
1831
|
+
...item.explosion === void 0 ? {} : { explosion: item.explosion },
|
|
1832
|
+
...item.dataLabels === void 0 ? {} : { dataLabels: item.dataLabels },
|
|
1833
|
+
...item.marker === void 0 ? {} : { marker: item.marker },
|
|
1834
|
+
...item.smooth === void 0 ? {} : { smooth: item.smooth },
|
|
1835
|
+
...trimmedPoints === void 0 ? {} : { points: trimmedPoints },
|
|
1836
|
+
...trimmedTrendlines === void 0 ? {} : { trendlines: trimmedTrendlines },
|
|
1837
|
+
...alignedErrorBars === void 0 ? {} : { errorBars: alignedErrorBars }
|
|
1838
|
+
};
|
|
1839
|
+
});
|
|
1840
|
+
if (group.kind === "pie") {
|
|
1841
|
+
const pieLabels = narrowGroupDataLabels(liftedDataLabels, [
|
|
1842
|
+
"center",
|
|
1843
|
+
"insideEnd",
|
|
1844
|
+
"outsideEnd",
|
|
1845
|
+
"bestFit"
|
|
1846
|
+
]);
|
|
1847
|
+
return {
|
|
1848
|
+
kind: "pie",
|
|
1849
|
+
data: {
|
|
1850
|
+
kind: "shared-categories",
|
|
1851
|
+
categories: domain
|
|
1852
|
+
},
|
|
1853
|
+
series: normalizedSeries,
|
|
1854
|
+
...group.firstSliceAngle === void 0 ? {} : { firstSliceAngle: group.firstSliceAngle },
|
|
1855
|
+
...pieLabels === void 0 ? {} : { dataLabels: pieLabels }
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
if (group.kind === "doughnut") {
|
|
1859
|
+
const doughnutLabels = narrowGroupDataLabels(liftedDataLabels, []);
|
|
1860
|
+
return {
|
|
1861
|
+
kind: "doughnut",
|
|
1862
|
+
data: {
|
|
1863
|
+
kind: "shared-categories",
|
|
1864
|
+
categories: domain
|
|
1865
|
+
},
|
|
1866
|
+
series: normalizedSeries,
|
|
1867
|
+
...group.firstSliceAngle === void 0 ? {} : { firstSliceAngle: group.firstSliceAngle },
|
|
1868
|
+
...group.holeSize === void 0 ? {} : { holeSize: group.holeSize },
|
|
1869
|
+
...doughnutLabels === void 0 ? {} : { dataLabels: doughnutLabels }
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
const [catId, valId] = group.axisIds;
|
|
1873
|
+
const catName = catId !== void 0 && axisById.has(catId) ? axisNameById.get(catId) : void 0;
|
|
1874
|
+
const valName = valId !== void 0 && axisById.has(valId) ? axisNameById.get(valId) : void 0;
|
|
1875
|
+
const axesRef = catName !== void 0 && valName !== void 0 && catName !== valName ? {
|
|
1876
|
+
category: catName,
|
|
1877
|
+
value: valName
|
|
1878
|
+
} : void 0;
|
|
1879
|
+
if (group.kind === "column" || group.kind === "bar") {
|
|
1880
|
+
const commonColBar = {
|
|
1881
|
+
kind: group.kind,
|
|
1882
|
+
data: {
|
|
1883
|
+
kind: "shared-categories",
|
|
1884
|
+
categories: domain
|
|
1885
|
+
},
|
|
1886
|
+
series: normalizedSeries,
|
|
1887
|
+
...axesRef === void 0 ? {} : { axes: axesRef },
|
|
1888
|
+
...group.gapWidth === void 0 ? {} : { gapWidth: group.gapWidth },
|
|
1889
|
+
...group.overlap === void 0 ? {} : { overlap: group.overlap }
|
|
1890
|
+
};
|
|
1891
|
+
if (group.stacking !== void 0) {
|
|
1892
|
+
const stackedLabels = narrowGroupDataLabels(liftedDataLabels, [
|
|
1893
|
+
"center",
|
|
1894
|
+
"insideEnd",
|
|
1895
|
+
"insideBase"
|
|
1896
|
+
]);
|
|
1897
|
+
return {
|
|
1898
|
+
...commonColBar,
|
|
1899
|
+
stacking: group.stacking,
|
|
1900
|
+
...stackedLabels === void 0 ? {} : { dataLabels: stackedLabels }
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
const unstackedLabels = narrowGroupDataLabels(liftedDataLabels, [
|
|
1904
|
+
"center",
|
|
1905
|
+
"insideEnd",
|
|
1906
|
+
"insideBase",
|
|
1907
|
+
"outsideEnd"
|
|
1908
|
+
]);
|
|
1909
|
+
return {
|
|
1910
|
+
...commonColBar,
|
|
1911
|
+
...unstackedLabels === void 0 ? {} : { dataLabels: unstackedLabels }
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
if (group.kind === "line") {
|
|
1915
|
+
const lineLabels = narrowGroupDataLabels(liftedDataLabels, [
|
|
1916
|
+
"left",
|
|
1917
|
+
"right",
|
|
1918
|
+
"bottom",
|
|
1919
|
+
"top",
|
|
1920
|
+
"center"
|
|
1921
|
+
]);
|
|
1922
|
+
return {
|
|
1923
|
+
kind: "line",
|
|
1924
|
+
data: {
|
|
1925
|
+
kind: "shared-categories",
|
|
1926
|
+
categories: domain
|
|
1927
|
+
},
|
|
1928
|
+
series: normalizedSeries,
|
|
1929
|
+
...axesRef === void 0 ? {} : { axes: axesRef },
|
|
1930
|
+
...group.stacking === void 0 ? {} : { stacking: group.stacking },
|
|
1931
|
+
...lineLabels === void 0 ? {} : { dataLabels: lineLabels }
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
const areaLabels = narrowGroupDataLabels(liftedDataLabels, []);
|
|
1935
|
+
return {
|
|
1936
|
+
kind: "area",
|
|
1937
|
+
data: {
|
|
1938
|
+
kind: "shared-categories",
|
|
1939
|
+
categories: domain
|
|
1940
|
+
},
|
|
1941
|
+
series: normalizedSeries,
|
|
1942
|
+
...axesRef === void 0 ? {} : { axes: axesRef },
|
|
1943
|
+
...group.stacking === void 0 ? {} : { stacking: group.stacking },
|
|
1944
|
+
...areaLabels === void 0 ? {} : { dataLabels: areaLabels }
|
|
1945
|
+
};
|
|
1946
|
+
});
|
|
1947
|
+
return {
|
|
1948
|
+
...Object.keys(axesRecord).length > 0 ? { axes: axesRecord } : {},
|
|
1949
|
+
groups
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
function consumeChartAlternateContent(ac) {
|
|
1953
|
+
const choice = ac.child(MC_NS, "Choice");
|
|
1954
|
+
const fallback = ac.child(MC_NS, "Fallback");
|
|
1955
|
+
if (choice !== void 0) {
|
|
1956
|
+
choice.consumeAttr("Requires");
|
|
1957
|
+
const c14Style = choice.child(C14_NS, "style");
|
|
1958
|
+
if (c14Style !== void 0) {
|
|
1959
|
+
consumeSubtree(c14Style);
|
|
1960
|
+
if (fallback !== void 0) consumeSubtree(fallback);
|
|
1961
|
+
return true;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
return false;
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Reads a Transitional `<p:graphicFrame>` chart and its `ppt/charts/chart{n}.xml` part into an editable `ChartNode`.
|
|
1968
|
+
*/
|
|
1969
|
+
function readChartGraphicFrame(context) {
|
|
1970
|
+
const { cursor, part, slideIndex, package: pkg } = context;
|
|
1971
|
+
const diagnostics = [];
|
|
1972
|
+
const nvGraphicFramePr = cursor.child(P_NS, "nvGraphicFramePr");
|
|
1973
|
+
if (nvGraphicFramePr === void 0) {
|
|
1974
|
+
diagnostics.push({
|
|
1975
|
+
code: "corrupt-part",
|
|
1976
|
+
category: "corrupt-input",
|
|
1977
|
+
disposition: "omitted",
|
|
1978
|
+
location: {
|
|
1979
|
+
part,
|
|
1980
|
+
xpath: cursor.xpath,
|
|
1981
|
+
slideIndex
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
return { diagnostics };
|
|
1985
|
+
}
|
|
1986
|
+
let objectId;
|
|
1987
|
+
let objectName;
|
|
1988
|
+
let clickResult;
|
|
1989
|
+
const cNvPr = nvGraphicFramePr.child(P_NS, "cNvPr");
|
|
1990
|
+
if (cNvPr !== void 0) {
|
|
1991
|
+
const rawCNvPr = cNvPr.attrsObject(["id", "name"]);
|
|
1992
|
+
const parsedCNvPr = NonVisualIdSchema.safeParse(rawCNvPr);
|
|
1993
|
+
if (!parsedCNvPr.success) diagnostics.push({
|
|
1994
|
+
code: "invalid-xml-value",
|
|
1995
|
+
category: "corrupt-input",
|
|
1996
|
+
disposition: "recovered",
|
|
1997
|
+
location: {
|
|
1998
|
+
part,
|
|
1999
|
+
xpath: cNvPr.xpath,
|
|
2000
|
+
slideIndex
|
|
2001
|
+
},
|
|
2002
|
+
attributeOrElement: "p:cNvPr",
|
|
2003
|
+
rawValue: JSON.stringify(rawCNvPr)
|
|
2004
|
+
});
|
|
2005
|
+
else {
|
|
2006
|
+
objectId = parsedCNvPr.data.id;
|
|
2007
|
+
if (parsedCNvPr.data.name !== void 0 && parsedCNvPr.data.name.trim() !== "") objectName = parsedCNvPr.data.name;
|
|
2008
|
+
}
|
|
2009
|
+
const hlinkClick = cNvPr.child(A_NS, "hlinkClick");
|
|
2010
|
+
if (hlinkClick !== void 0) {
|
|
2011
|
+
clickResult = readClickLink(hlinkClick, context, {
|
|
2012
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2013
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2014
|
+
});
|
|
2015
|
+
diagnostics.push(...clickResult.diagnostics);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
const cNvGraphicFramePr = nvGraphicFramePr.child(P_NS, "cNvGraphicFramePr");
|
|
2019
|
+
if (cNvGraphicFramePr !== void 0) {
|
|
2020
|
+
const locks = cNvGraphicFramePr.child(A_NS, "graphicFrameLocks");
|
|
2021
|
+
if (locks !== void 0) consumeSubtree(locks);
|
|
2022
|
+
}
|
|
2023
|
+
const chartLocation = {
|
|
2024
|
+
part,
|
|
2025
|
+
xpath: cursor.xpath,
|
|
2026
|
+
slideIndex,
|
|
2027
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2028
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2029
|
+
};
|
|
2030
|
+
const nvPr = nvGraphicFramePr.child(P_NS, "nvPr");
|
|
2031
|
+
const phResult = readNvPrPlaceholder(nvPr, chartLocation, diagnostics);
|
|
2032
|
+
if (phResult.kind === "error") return { diagnostics };
|
|
2033
|
+
const nativeRef = phResult.kind === "ok" ? phResult.nativeRef : void 0;
|
|
2034
|
+
const claim = nativeRef === void 0 ? void 0 : resolvePlaceholderImportClaim({
|
|
2035
|
+
context,
|
|
2036
|
+
nativeRef,
|
|
2037
|
+
compatibleRoles: /* @__PURE__ */ new Set(["chart", "obj"])
|
|
2038
|
+
});
|
|
2039
|
+
const matchedKey = claim?.bound === true ? claim.key : void 0;
|
|
2040
|
+
const unboundPlaceholder = claim !== void 0 && !claim.bound;
|
|
2041
|
+
const xfrm = cursor.child(P_NS, "xfrm");
|
|
2042
|
+
const off = xfrm?.child(A_NS, "off");
|
|
2043
|
+
const ext = xfrm?.child(A_NS, "ext");
|
|
2044
|
+
if (xfrm === void 0 || off === void 0 || ext === void 0) {
|
|
2045
|
+
diagnostics.push({
|
|
2046
|
+
code: "corrupt-part",
|
|
2047
|
+
category: "corrupt-input",
|
|
2048
|
+
disposition: "omitted",
|
|
2049
|
+
location: {
|
|
2050
|
+
part,
|
|
2051
|
+
xpath: cursor.xpath,
|
|
2052
|
+
slideIndex,
|
|
2053
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2054
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
return { diagnostics };
|
|
2058
|
+
}
|
|
2059
|
+
const rawXfrm = xfrm.attrsObject([
|
|
2060
|
+
"rot",
|
|
2061
|
+
"flipH",
|
|
2062
|
+
"flipV"
|
|
2063
|
+
]);
|
|
2064
|
+
transformAttributesFragmentSchema.safeParse(rawXfrm);
|
|
2065
|
+
const parsedOff = offsetEmuFragmentSchema.safeParse(off.attrsObject(["x", "y"]));
|
|
2066
|
+
const parsedExt = extentEmuFragmentSchema.safeParse(ext.attrsObject(["cx", "cy"]));
|
|
2067
|
+
if (!parsedOff.success || !parsedExt.success) {
|
|
2068
|
+
diagnostics.push({
|
|
2069
|
+
code: "invalid-xml-value",
|
|
2070
|
+
category: "corrupt-input",
|
|
2071
|
+
disposition: "omitted",
|
|
2072
|
+
location: {
|
|
2073
|
+
part,
|
|
2074
|
+
xpath: xfrm.xpath,
|
|
2075
|
+
slideIndex,
|
|
2076
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2077
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2078
|
+
},
|
|
2079
|
+
attributeOrElement: "a:xfrm"
|
|
2080
|
+
});
|
|
2081
|
+
return { diagnostics };
|
|
2082
|
+
}
|
|
2083
|
+
const boxX = emuToPx(parsedOff.data.x);
|
|
2084
|
+
const boxY = emuToPx(parsedOff.data.y);
|
|
2085
|
+
const boxWidth = emuToPx(parsedExt.data.cx);
|
|
2086
|
+
const boxHeight = emuToPx(parsedExt.data.cy);
|
|
2087
|
+
const graphicData = cursor.child(A_NS, "graphic")?.child(A_NS, "graphicData");
|
|
2088
|
+
if (graphicData !== void 0) GraphicDataAttrSchema.safeParse(graphicData.attrsObject(["uri"]));
|
|
2089
|
+
const cChart = graphicData?.child(C_NS, "chart");
|
|
2090
|
+
const rId = cChart?.attr("id", R_NS);
|
|
2091
|
+
if (cChart === void 0 || rId === void 0) {
|
|
2092
|
+
diagnostics.push({
|
|
2093
|
+
code: "corrupt-part",
|
|
2094
|
+
category: "corrupt-input",
|
|
2095
|
+
disposition: "omitted",
|
|
2096
|
+
location: {
|
|
2097
|
+
part,
|
|
2098
|
+
xpath: cursor.xpath,
|
|
2099
|
+
slideIndex,
|
|
2100
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2101
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2104
|
+
return { diagnostics };
|
|
2105
|
+
}
|
|
2106
|
+
const relsResult = pkg.readRelationships(part);
|
|
2107
|
+
diagnostics.push(...relsResult.diagnostics);
|
|
2108
|
+
const rel = relsResult.entries.find((entry) => entry.Id === rId && entry.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" && entry.TargetMode === "Internal");
|
|
2109
|
+
if (rel === void 0) {
|
|
2110
|
+
diagnostics.push({
|
|
2111
|
+
code: "broken-relationship",
|
|
2112
|
+
category: "corrupt-input",
|
|
2113
|
+
disposition: "omitted",
|
|
2114
|
+
location: {
|
|
2115
|
+
part,
|
|
2116
|
+
xpath: cChart.xpath,
|
|
2117
|
+
slideIndex,
|
|
2118
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2119
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2120
|
+
},
|
|
2121
|
+
relationshipId: rId
|
|
2122
|
+
});
|
|
2123
|
+
return { diagnostics };
|
|
2124
|
+
}
|
|
2125
|
+
const chartPartPath = resolvePartPath(part, rel.Target);
|
|
2126
|
+
const chartXml = chartPartPath === void 0 ? void 0 : pkg.readTextPart(chartPartPath);
|
|
2127
|
+
if (chartPartPath === void 0 || chartXml === void 0) {
|
|
2128
|
+
diagnostics.push({
|
|
2129
|
+
code: "missing-target-part",
|
|
2130
|
+
category: "corrupt-input",
|
|
2131
|
+
disposition: "omitted",
|
|
2132
|
+
location: {
|
|
2133
|
+
part,
|
|
2134
|
+
xpath: cChart.xpath,
|
|
2135
|
+
slideIndex,
|
|
2136
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2137
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2138
|
+
},
|
|
2139
|
+
relationshipId: rId,
|
|
2140
|
+
targetPart: chartPartPath ?? rel.Target
|
|
2141
|
+
});
|
|
2142
|
+
return { diagnostics };
|
|
2143
|
+
}
|
|
2144
|
+
let chartRootEl;
|
|
2145
|
+
try {
|
|
2146
|
+
chartRootEl = parseXmlPart(chartPartPath, chartXml);
|
|
2147
|
+
} catch {
|
|
2148
|
+
diagnostics.push({
|
|
2149
|
+
code: "corrupt-part",
|
|
2150
|
+
category: "corrupt-input",
|
|
2151
|
+
disposition: "omitted",
|
|
2152
|
+
location: {
|
|
2153
|
+
part: chartPartPath,
|
|
2154
|
+
slideIndex,
|
|
2155
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2156
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2157
|
+
}
|
|
2158
|
+
});
|
|
2159
|
+
return { diagnostics };
|
|
2160
|
+
}
|
|
2161
|
+
const chartSpace = XmlElementCursor.createRoot(chartRootEl, chartPartPath, "/c:chartSpace");
|
|
2162
|
+
chartSpace.consumeAttr("lang", "http://www.w3.org/XML/1998/namespace");
|
|
2163
|
+
for (const tag of [
|
|
2164
|
+
"date1904",
|
|
2165
|
+
"lang",
|
|
2166
|
+
"roundedCorners",
|
|
2167
|
+
"style",
|
|
2168
|
+
"clrMapOvr"
|
|
2169
|
+
]) {
|
|
2170
|
+
const el = chartSpace.child(C_NS, tag);
|
|
2171
|
+
if (el !== void 0) consumeSubtree(el);
|
|
2172
|
+
}
|
|
2173
|
+
for (const ac of chartSpace.children(MC_NS, "AlternateContent")) consumeChartAlternateContent(ac);
|
|
2174
|
+
const chartTxPr = chartSpace.child(C_NS, "txPr");
|
|
2175
|
+
const rawChartStyle = chartTxPr === void 0 ? void 0 : readChartTextProperties(chartTxPr);
|
|
2176
|
+
const chartStyle = normalizeRootChartStyle(rawChartStyle);
|
|
2177
|
+
for (const tag of ["spPr", "externalData"]) {
|
|
2178
|
+
const el = chartSpace.child(C_NS, tag);
|
|
2179
|
+
if (el !== void 0) consumeSubtree(el);
|
|
2180
|
+
}
|
|
2181
|
+
const chartEl = chartSpace.child(C_NS, "chart");
|
|
2182
|
+
if (chartEl === void 0) {
|
|
2183
|
+
diagnostics.push({
|
|
2184
|
+
code: "corrupt-part",
|
|
2185
|
+
category: "corrupt-input",
|
|
2186
|
+
disposition: "omitted",
|
|
2187
|
+
location: {
|
|
2188
|
+
part: chartPartPath,
|
|
2189
|
+
xpath: chartSpace.xpath,
|
|
2190
|
+
slideIndex,
|
|
2191
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2192
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
return { diagnostics };
|
|
2196
|
+
}
|
|
2197
|
+
const titleEl = chartEl.child(C_NS, "title");
|
|
2198
|
+
const title = titleEl === void 0 ? void 0 : readChartTitle(titleEl, rawChartStyle);
|
|
2199
|
+
const autoTitleDeleted = chartEl.child(C_NS, "autoTitleDeleted");
|
|
2200
|
+
if (autoTitleDeleted !== void 0) consumeSubtree(autoTitleDeleted);
|
|
2201
|
+
const pivotFmts = chartEl.child(C_NS, "pivotFmts");
|
|
2202
|
+
if (pivotFmts !== void 0) consumeSubtree(pivotFmts);
|
|
2203
|
+
let legend;
|
|
2204
|
+
const legendEl = chartEl.child(C_NS, "legend");
|
|
2205
|
+
if (legendEl !== void 0) {
|
|
2206
|
+
const posVal = legendEl.child(C_NS, "legendPos")?.attrsObject(["val"])["val"];
|
|
2207
|
+
legend = (posVal === void 0 ? void 0 : chartLegendPositionFromNative[posVal]) ?? "right";
|
|
2208
|
+
legendEl.child(C_NS, "overlay")?.attr("val");
|
|
2209
|
+
const legendLayoutEl = directElementChild(legendEl.element, C_NS, "layout");
|
|
2210
|
+
if (legendLayoutEl !== void 0 && isEmptyXmlElement(legendLayoutEl)) legendEl.child(C_NS, "layout");
|
|
2211
|
+
const legendTxPr = legendEl.child(C_NS, "txPr");
|
|
2212
|
+
if (legendTxPr !== void 0) readChartTextProperties(legendTxPr);
|
|
2213
|
+
for (const legendEntry of legendEl.children(C_NS, "legendEntry")) {
|
|
2214
|
+
legendEntry.child(C_NS, "idx")?.attr("val");
|
|
2215
|
+
legendEntry.child(C_NS, "delete")?.attr("val");
|
|
2216
|
+
}
|
|
2217
|
+
const legendSpPr = legendEl.child(C_NS, "spPr");
|
|
2218
|
+
if (legendSpPr !== void 0) consumeBenignChartSpPr(legendSpPr);
|
|
2219
|
+
}
|
|
2220
|
+
const plotVisOnly = chartEl.child(C_NS, "plotVisOnly");
|
|
2221
|
+
if (plotVisOnly !== void 0) consumeSubtree(plotVisOnly);
|
|
2222
|
+
const dispParsed = DispBlanksAsSchema.safeParse(chartEl.child("http://schemas.openxmlformats.org/drawingml/2006/chart", "dispBlanksAs")?.attrsObject(["val"]) ?? {});
|
|
2223
|
+
let displayBlanksAs = dispParsed.success ? dispParsed.data.val : void 0;
|
|
2224
|
+
const showDLblsOverMax = chartEl.child(C_NS, "showDLblsOverMax");
|
|
2225
|
+
if (showDLblsOverMax !== void 0) consumeSubtree(showDLblsOverMax);
|
|
2226
|
+
const chartExtLst = chartEl.child(C_NS, "extLst");
|
|
2227
|
+
if (chartExtLst !== void 0) {
|
|
2228
|
+
for (const extEntry of chartExtLst.children(C_NS, "ext")) if (extEntry.attr("uri") === WPS_CHART_PROPS_EXT_URI || directElementChild(extEntry.element, WPS_ET_NS, "chartProps") !== void 0) consumeSubtree(extEntry);
|
|
2229
|
+
}
|
|
2230
|
+
const plotAreaEl = chartEl.child(C_NS, "plotArea");
|
|
2231
|
+
if (plotAreaEl === void 0) {
|
|
2232
|
+
diagnostics.push({
|
|
2233
|
+
code: "corrupt-part",
|
|
2234
|
+
category: "corrupt-input",
|
|
2235
|
+
disposition: "omitted",
|
|
2236
|
+
location: {
|
|
2237
|
+
part: chartPartPath,
|
|
2238
|
+
xpath: chartEl.xpath,
|
|
2239
|
+
slideIndex,
|
|
2240
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2241
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
return { diagnostics };
|
|
2245
|
+
}
|
|
2246
|
+
let plotArea;
|
|
2247
|
+
const layoutEl = plotAreaEl.child(C_NS, "layout");
|
|
2248
|
+
if (layoutEl !== void 0) {
|
|
2249
|
+
const manual = layoutEl.child(C_NS, "manualLayout");
|
|
2250
|
+
if (manual !== void 0) {
|
|
2251
|
+
const target = readValAttr(manual.child(C_NS, "layoutTarget"));
|
|
2252
|
+
const xMode = readValAttr(manual.child(C_NS, "xMode"));
|
|
2253
|
+
const yMode = readValAttr(manual.child(C_NS, "yMode"));
|
|
2254
|
+
const wMode = readValAttr(manual.child(C_NS, "wMode"));
|
|
2255
|
+
const hMode = readValAttr(manual.child(C_NS, "hMode"));
|
|
2256
|
+
const xFrac = readFloatVal(manual.child(C_NS, "x"));
|
|
2257
|
+
const yFrac = readFloatVal(manual.child(C_NS, "y"));
|
|
2258
|
+
const wFrac = readFloatVal(manual.child(C_NS, "w"));
|
|
2259
|
+
const hFrac = readFloatVal(manual.child(C_NS, "h"));
|
|
2260
|
+
if ((target === void 0 || target === "inner") && (xMode === void 0 || xMode === "edge") && (yMode === void 0 || yMode === "edge") && (wMode === void 0 || wMode === "factor") && (hMode === void 0 || hMode === "factor") && xFrac !== void 0 && yFrac !== void 0 && wFrac !== void 0 && hFrac !== void 0 && wFrac > 0 && hFrac > 0) {
|
|
2261
|
+
const left = Math.max(0, xFrac * boxWidth);
|
|
2262
|
+
const top = Math.max(0, yFrac * boxHeight);
|
|
2263
|
+
const width = Math.min(boxWidth - left, wFrac * boxWidth);
|
|
2264
|
+
const height = Math.min(boxHeight - top, hFrac * boxHeight);
|
|
2265
|
+
if (width > 0 && height > 0) plotArea = {
|
|
2266
|
+
left,
|
|
2267
|
+
top,
|
|
2268
|
+
width,
|
|
2269
|
+
height
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2272
|
+
consumeSubtree(manual);
|
|
2273
|
+
}
|
|
2274
|
+
consumeSubtree(layoutEl);
|
|
2275
|
+
}
|
|
2276
|
+
const plotSpPr = plotAreaEl.child(C_NS, "spPr");
|
|
2277
|
+
if (plotSpPr !== void 0) consumeBenignChartSpPr(plotSpPr);
|
|
2278
|
+
const groupDrafts = [];
|
|
2279
|
+
const importedAxes = [];
|
|
2280
|
+
for (const child of plotAreaEl.remainingElementChildren()) {
|
|
2281
|
+
if (child.namespaceUri !== "http://schemas.openxmlformats.org/drawingml/2006/chart") continue;
|
|
2282
|
+
if (child.localName === "catAx") {
|
|
2283
|
+
const ax = readAxisElement(child, "category", rawChartStyle);
|
|
2284
|
+
if (ax !== void 0) importedAxes.push(ax);
|
|
2285
|
+
continue;
|
|
2286
|
+
}
|
|
2287
|
+
if (child.localName === "valAx") {
|
|
2288
|
+
const ax = readAxisElement(child, "value", rawChartStyle);
|
|
2289
|
+
if (ax !== void 0) importedAxes.push(ax);
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
const group = readChartGroupElement(child, rawChartStyle);
|
|
2293
|
+
if (group !== void 0) {
|
|
2294
|
+
groupDrafts.push(group);
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
diagnostics.push({
|
|
2298
|
+
code: "unsupported-mechanism",
|
|
2299
|
+
category: "unsupported",
|
|
2300
|
+
disposition: "omitted",
|
|
2301
|
+
location: {
|
|
2302
|
+
part: chartPartPath,
|
|
2303
|
+
xpath: child.xpath,
|
|
2304
|
+
slideIndex,
|
|
2305
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2306
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2307
|
+
},
|
|
2308
|
+
namespaceUri: child.namespaceUri,
|
|
2309
|
+
localName: child.localName
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
for (const unconsumed of chartSpace.collectUnconsumed()) diagnostics.push({
|
|
2313
|
+
code: "unconsumed-xml",
|
|
2314
|
+
category: "unsupported",
|
|
2315
|
+
disposition: "omitted",
|
|
2316
|
+
kind: unconsumed.kind,
|
|
2317
|
+
location: {
|
|
2318
|
+
...unconsumed.location,
|
|
2319
|
+
slideIndex,
|
|
2320
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2321
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2322
|
+
},
|
|
2323
|
+
namespaceUri: unconsumed.namespaceUri,
|
|
2324
|
+
localName: unconsumed.localName
|
|
2325
|
+
});
|
|
2326
|
+
if (groupDrafts.length === 0) {
|
|
2327
|
+
diagnostics.push({
|
|
2328
|
+
code: "corrupt-part",
|
|
2329
|
+
category: "corrupt-input",
|
|
2330
|
+
disposition: "omitted",
|
|
2331
|
+
location: {
|
|
2332
|
+
part: chartPartPath,
|
|
2333
|
+
xpath: plotAreaEl.xpath,
|
|
2334
|
+
slideIndex,
|
|
2335
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2336
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
return { diagnostics };
|
|
2340
|
+
}
|
|
2341
|
+
const { axes, groups } = buildChartAxesAndGroups(groupDrafts, importedAxes, {
|
|
2342
|
+
part: chartPartPath,
|
|
2343
|
+
xpath: plotAreaEl.xpath,
|
|
2344
|
+
slideIndex,
|
|
2345
|
+
...objectId === void 0 ? {} : { objectId },
|
|
2346
|
+
...objectName === void 0 ? {} : { objectName }
|
|
2347
|
+
}, diagnostics);
|
|
2348
|
+
if (groups.length === 0) return { diagnostics };
|
|
2349
|
+
if (displayBlanksAs !== void 0) {
|
|
2350
|
+
if (!groups.every((group) => {
|
|
2351
|
+
if (group.kind === "scatter") return !(displayBlanksAs === "span" && (group.line === void 0 || group.line === false));
|
|
2352
|
+
if (group.kind === "line") return group.stacking === void 0 ? true : displayBlanksAs === "zero";
|
|
2353
|
+
if (group.kind === "area") return group.stacking === void 0 ? displayBlanksAs === "gap" || displayBlanksAs === "zero" : displayBlanksAs === "zero";
|
|
2354
|
+
return displayBlanksAs === "gap" || displayBlanksAs === "zero";
|
|
2355
|
+
})) displayBlanksAs = void 0;
|
|
2356
|
+
}
|
|
2357
|
+
const props = {
|
|
2358
|
+
...objectName === void 0 ? {} : { name: objectName },
|
|
2359
|
+
...matchedKey === void 0 ? {} : { placeholder: matchedKey },
|
|
2360
|
+
...matchedKey === void 0 || nativeRef === void 0 ? {} : { nativePlaceholder: nativeRef },
|
|
2361
|
+
...clickResult?.link === void 0 ? {} : { link: clickResult.link },
|
|
2362
|
+
...axes === void 0 ? {} : { axes },
|
|
2363
|
+
groups,
|
|
2364
|
+
...title === void 0 ? {} : { title },
|
|
2365
|
+
style: {
|
|
2366
|
+
position: "absolute",
|
|
2367
|
+
left: boxX,
|
|
2368
|
+
top: boxY,
|
|
2369
|
+
width: boxWidth,
|
|
2370
|
+
height: boxHeight,
|
|
2371
|
+
...chartStyle
|
|
2372
|
+
},
|
|
2373
|
+
...displayBlanksAs === void 0 ? {} : { displayBlanksAs },
|
|
2374
|
+
...legend === void 0 ? {} : { legend },
|
|
2375
|
+
...plotArea === void 0 ? {} : { plotArea }
|
|
2376
|
+
};
|
|
2377
|
+
if (unboundPlaceholder) emitPlaceholderUnbindDiagnostic({
|
|
2378
|
+
diagnostics,
|
|
2379
|
+
location: chartLocation,
|
|
2380
|
+
retainedAs: "chart"
|
|
2381
|
+
});
|
|
2382
|
+
const node = createChartNode(props);
|
|
2383
|
+
attachDeferredSlideLink(node, clickResult?.deferredSlideLink, context);
|
|
2384
|
+
return {
|
|
2385
|
+
node,
|
|
2386
|
+
diagnostics
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
/** Shape-tree import handler wired into free chart canvas mechanisms. */
|
|
2390
|
+
const chartImportHandler = {
|
|
2391
|
+
target: "shape-tree",
|
|
2392
|
+
localName: "graphicFrame",
|
|
2393
|
+
matches: (cursor) => isChartGraphicFrame(cursor) && !isPlaceholderGraphicFrameElement(cursor),
|
|
2394
|
+
read: readChartGraphicFrame
|
|
2395
|
+
};
|
|
2396
|
+
/** Shape-tree import handler wired into `chartPlaceholderMechanism` for placeholder-bound charts. */
|
|
2397
|
+
const chartPlaceholderImportHandler = {
|
|
2398
|
+
target: "shape-tree",
|
|
2399
|
+
localName: "graphicFrame",
|
|
2400
|
+
matches: (cursor) => isChartGraphicFrame(cursor) && isPlaceholderGraphicFrameElement(cursor),
|
|
2401
|
+
read: readChartGraphicFrame
|
|
2402
|
+
};
|
|
2403
|
+
export { chartImportHandler, chartPlaceholderImportHandler, isChartGraphicFrame, readChartGraphicFrame };
|