@officedk/pptxdk 0.0.0-stage → 0.1.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/README.md +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -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 +2272 -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 +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -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 +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -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 +48 -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 +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -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 +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -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 +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -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 +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -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-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -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 +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -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 +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { parseTextContent } from "../../shared/text-service.js";
|
|
2
|
+
import { textOnlyChartStyle } from "../chart-model.js";
|
|
3
|
+
import { renderAxesSvg, renderGridlinesSvg } from "./axes-and-grid.js";
|
|
4
|
+
import { renderColumnOrBarGroup } from "./bar-column.js";
|
|
5
|
+
import { renderDataLabelsSvg } from "./data-labels.js";
|
|
6
|
+
import { renderErrorBarsSvg } from "./error-bars.js";
|
|
7
|
+
import { computeChartLayout } from "./layout.js";
|
|
8
|
+
import { renderLegendSvg } from "./legend.js";
|
|
9
|
+
import { renderLineOrAreaGroup } from "./line-area.js";
|
|
10
|
+
import { renderPieOrDoughnutGroup } from "./pie-doughnut.js";
|
|
11
|
+
import { buildAxisScales } from "./scales.js";
|
|
12
|
+
import { renderScatterGroup } from "./scatter.js";
|
|
13
|
+
import { resolveChartLineStroke, strokeAttrs } from "./style.js";
|
|
14
|
+
import { createChartClipAllocator, mergeChartTextStyle, renderChartTextSvg, resolveChartFontSizePixels } from "./text-render.js";
|
|
15
|
+
import { renderTrendlinesSvg } from "./trendlines.js";
|
|
16
|
+
import { assertNever } from "./types.js";
|
|
17
|
+
// ../capabilities/dist/chart/preview/index.js
|
|
18
|
+
/**
|
|
19
|
+
* Renders a static SVG preview for a resolved chart without mutating or leaking into native emit.
|
|
20
|
+
*/
|
|
21
|
+
function drawChartPreview(parsed, box, context) {
|
|
22
|
+
const baseChartTextStyle = textOnlyChartStyle(parsed.style);
|
|
23
|
+
const { style: resolvedChartStyle } = parseTextContent([], baseChartTextStyle, context.theme, { slideNumber: context.slideNumber }, "Chart.style");
|
|
24
|
+
const baseFontSizePx = resolveChartFontSizePixels(resolvedChartStyle.fontSize);
|
|
25
|
+
const scales = buildAxisScales(parsed);
|
|
26
|
+
const layout = computeChartLayout({
|
|
27
|
+
parsed,
|
|
28
|
+
box,
|
|
29
|
+
scales,
|
|
30
|
+
baseChartTextStyle,
|
|
31
|
+
baseFontSizePx,
|
|
32
|
+
theme: context.theme,
|
|
33
|
+
slideNumber: context.slideNumber
|
|
34
|
+
});
|
|
35
|
+
const clipAllocator = createChartClipAllocator(context.slideNumber, context.objectId);
|
|
36
|
+
const outerClipId = clipAllocator.nextClipId();
|
|
37
|
+
clipAllocator.defs.push(`<clipPath id="${outerClipId}" clipPathUnits="userSpaceOnUse"><rect x="${box.x}" y="${box.y}" width="${Math.max(0, box.width)}" height="${Math.max(0, box.height)}"/></clipPath>`);
|
|
38
|
+
const plotClipId = clipAllocator.nextClipId();
|
|
39
|
+
clipAllocator.defs.push(`<clipPath id="${plotClipId}" clipPathUnits="userSpaceOnUse"><rect x="${layout.plotRect.x}" y="${layout.plotRect.y}" width="${Math.max(0, layout.plotRect.width)}" height="${Math.max(0, layout.plotRect.height)}"/></clipPath>`);
|
|
40
|
+
const bodyParts = [];
|
|
41
|
+
bodyParts.push(renderGridlinesSvg({
|
|
42
|
+
parsed,
|
|
43
|
+
scales,
|
|
44
|
+
plotRect: layout.plotRect,
|
|
45
|
+
theme: context.theme
|
|
46
|
+
}));
|
|
47
|
+
const anchors = [];
|
|
48
|
+
const plotParts = [];
|
|
49
|
+
for (let groupIndex = 0; groupIndex < parsed.groups.length; groupIndex += 1) {
|
|
50
|
+
const group = parsed.groups[groupIndex];
|
|
51
|
+
switch (group.kind) {
|
|
52
|
+
case "column":
|
|
53
|
+
case "bar": {
|
|
54
|
+
const rendered = renderColumnOrBarGroup({
|
|
55
|
+
group,
|
|
56
|
+
groupIndex,
|
|
57
|
+
scales,
|
|
58
|
+
plotRect: layout.plotRect,
|
|
59
|
+
theme: context.theme
|
|
60
|
+
});
|
|
61
|
+
if (rendered.svg !== "") plotParts.push(rendered.svg);
|
|
62
|
+
anchors.push(...rendered.anchors);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "line":
|
|
66
|
+
case "area": {
|
|
67
|
+
const rendered = renderLineOrAreaGroup({
|
|
68
|
+
group,
|
|
69
|
+
groupIndex,
|
|
70
|
+
scales,
|
|
71
|
+
plotRect: layout.plotRect,
|
|
72
|
+
displayBlanksAs: parsed.displayBlanksAs,
|
|
73
|
+
theme: context.theme
|
|
74
|
+
});
|
|
75
|
+
if (rendered.svg !== "") plotParts.push(rendered.svg);
|
|
76
|
+
anchors.push(...rendered.anchors);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "scatter": {
|
|
80
|
+
const rendered = renderScatterGroup({
|
|
81
|
+
group,
|
|
82
|
+
groupIndex,
|
|
83
|
+
scales,
|
|
84
|
+
plotRect: layout.plotRect,
|
|
85
|
+
displayBlanksAs: parsed.displayBlanksAs,
|
|
86
|
+
theme: context.theme
|
|
87
|
+
});
|
|
88
|
+
if (rendered.svg !== "") plotParts.push(rendered.svg);
|
|
89
|
+
anchors.push(...rendered.anchors);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "pie":
|
|
93
|
+
case "doughnut": {
|
|
94
|
+
const rendered = renderPieOrDoughnutGroup({
|
|
95
|
+
group,
|
|
96
|
+
groupIndex,
|
|
97
|
+
plotRect: layout.plotRect,
|
|
98
|
+
theme: context.theme
|
|
99
|
+
});
|
|
100
|
+
if (rendered.svg !== "") plotParts.push(rendered.svg);
|
|
101
|
+
anchors.push(...rendered.anchors);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default: assertNever(group);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const errorBarsSvg = renderErrorBarsSvg({
|
|
108
|
+
parsed,
|
|
109
|
+
anchors,
|
|
110
|
+
scales,
|
|
111
|
+
plotRect: layout.plotRect,
|
|
112
|
+
theme: context.theme
|
|
113
|
+
});
|
|
114
|
+
if (errorBarsSvg !== "") plotParts.push(errorBarsSvg);
|
|
115
|
+
const trendlines = renderTrendlinesSvg({
|
|
116
|
+
parsed,
|
|
117
|
+
scales,
|
|
118
|
+
plotRect: layout.plotRect,
|
|
119
|
+
chartBox: box,
|
|
120
|
+
baseChartTextStyle,
|
|
121
|
+
theme: context.theme,
|
|
122
|
+
slideNumber: context.slideNumber,
|
|
123
|
+
clipAllocator
|
|
124
|
+
});
|
|
125
|
+
if (trendlines.linesSvg !== "") plotParts.push(trendlines.linesSvg);
|
|
126
|
+
if (plotParts.length > 0) bodyParts.push(`<g clip-path="url(#${plotClipId})">${plotParts.join("")}</g>`);
|
|
127
|
+
for (const axis of parsed.axes) {
|
|
128
|
+
if (axis.kind !== "value") continue;
|
|
129
|
+
const valScale = scales.get(axis.name);
|
|
130
|
+
if (valScale?.kind !== "value") continue;
|
|
131
|
+
if (valScale.logBase !== void 0) continue;
|
|
132
|
+
if (valScale.min < 0 && valScale.max > 0) {
|
|
133
|
+
const zeroCoord = valScale.zeroScreen(layout.plotRect);
|
|
134
|
+
const zeroStroke = resolveChartLineStroke(true, context.theme, {
|
|
135
|
+
color: "dk1",
|
|
136
|
+
width: .75,
|
|
137
|
+
alpha: .35
|
|
138
|
+
});
|
|
139
|
+
const path = axis.direction === "vertical" ? `M${layout.plotRect.x} ${zeroCoord}H${layout.plotRect.x + layout.plotRect.width}` : `M${zeroCoord} ${layout.plotRect.y}V${layout.plotRect.y + layout.plotRect.height}`;
|
|
140
|
+
bodyParts.push(`<path d="${path}" ${strokeAttrs(zeroStroke)} fill="none"/>`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
bodyParts.push(renderAxesSvg({
|
|
144
|
+
parsed,
|
|
145
|
+
chartBox: box,
|
|
146
|
+
layout,
|
|
147
|
+
scales,
|
|
148
|
+
baseChartTextStyle,
|
|
149
|
+
theme: context.theme,
|
|
150
|
+
slideNumber: context.slideNumber,
|
|
151
|
+
clipAllocator
|
|
152
|
+
}));
|
|
153
|
+
bodyParts.push(renderDataLabelsSvg({
|
|
154
|
+
parsed,
|
|
155
|
+
anchors,
|
|
156
|
+
chartBox: box,
|
|
157
|
+
baseChartTextStyle,
|
|
158
|
+
theme: context.theme,
|
|
159
|
+
slideNumber: context.slideNumber,
|
|
160
|
+
clipAllocator
|
|
161
|
+
}));
|
|
162
|
+
if (trendlines.labelsSvg !== "") bodyParts.push(trendlines.labelsSvg);
|
|
163
|
+
if (parsed.title !== void 0 && layout.titleBox !== void 0) {
|
|
164
|
+
const titleObj = typeof parsed.title === "string" ? { text: parsed.title } : parsed.title;
|
|
165
|
+
bodyParts.push(renderChartTextSvg({
|
|
166
|
+
text: titleObj.text,
|
|
167
|
+
box: layout.titleBox,
|
|
168
|
+
style: mergeChartTextStyle(baseChartTextStyle, titleObj.style),
|
|
169
|
+
theme: context.theme,
|
|
170
|
+
slideNumber: context.slideNumber,
|
|
171
|
+
labelPath: "Chart.title",
|
|
172
|
+
align: "center",
|
|
173
|
+
verticalAlign: "middle",
|
|
174
|
+
wrap: true,
|
|
175
|
+
clipBox: layout.titleBox,
|
|
176
|
+
clipAllocator
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
if (parsed.legend !== void 0 && parsed.legend !== false && layout.legendBox !== void 0 && layout.measuredLegend !== void 0) bodyParts.push(renderLegendSvg({
|
|
180
|
+
measured: layout.measuredLegend,
|
|
181
|
+
position: parsed.legend,
|
|
182
|
+
legendBox: layout.legendBox,
|
|
183
|
+
style: baseChartTextStyle,
|
|
184
|
+
theme: context.theme,
|
|
185
|
+
slideNumber: context.slideNumber,
|
|
186
|
+
clipAllocator
|
|
187
|
+
}));
|
|
188
|
+
return { svg: `${clipAllocator.defs.length > 0 ? `<defs>${clipAllocator.defs.join("")}</defs>` : ""}<g clip-path="url(#${outerClipId})">${bodyParts.join("")}</g>` };
|
|
189
|
+
}
|
|
190
|
+
export { drawChartPreview };
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { mergeDataLabels } from "../chart-labels.js";
|
|
2
|
+
import { collectLegendEntries, measureLegend } from "./legend.js";
|
|
3
|
+
import { formatChartNumber } from "./number-format.js";
|
|
4
|
+
import { resolveAxisCrossingNormalized } from "./scales.js";
|
|
5
|
+
import { measureChartText, mergeChartTextStyle, resolveChartFontSizePixels } from "./text-render.js";
|
|
6
|
+
// ../capabilities/dist/chart/preview/layout.js
|
|
7
|
+
function titleTextOf(title) {
|
|
8
|
+
return typeof title === "string" ? { text: title } : title;
|
|
9
|
+
}
|
|
10
|
+
function resolveAxisLabelSide(axis, crossScale) {
|
|
11
|
+
const tickPos = axis.spec.tickLabelPosition ?? "nextTo";
|
|
12
|
+
if (tickPos === "none") return "none";
|
|
13
|
+
if (tickPos === "low") return axis.direction === "horizontal" ? "bottom" : "left";
|
|
14
|
+
if (tickPos === "high") return axis.direction === "horizontal" ? "top" : "right";
|
|
15
|
+
if (crossScale !== void 0) {
|
|
16
|
+
const t = resolveAxisCrossingNormalized(axis, crossScale);
|
|
17
|
+
if (t > .02 && t < .98) return "interior";
|
|
18
|
+
if (axis.direction === "horizontal") return t >= .98 ? "top" : "bottom";
|
|
19
|
+
return t >= .98 ? "right" : "left";
|
|
20
|
+
}
|
|
21
|
+
return axis.position;
|
|
22
|
+
}
|
|
23
|
+
function resolveAxisTitleSide(axis, crossScale) {
|
|
24
|
+
const labelSide = resolveAxisLabelSide(axis, crossScale);
|
|
25
|
+
if (labelSide !== "none" && labelSide !== "interior") return labelSide;
|
|
26
|
+
return axis.position;
|
|
27
|
+
}
|
|
28
|
+
function hasOutsideEndBarLabels(parsed) {
|
|
29
|
+
let columnPos = false;
|
|
30
|
+
let columnNeg = false;
|
|
31
|
+
let barPos = false;
|
|
32
|
+
let barNeg = false;
|
|
33
|
+
for (const group of parsed.groups) {
|
|
34
|
+
if (group.kind !== "column" && group.kind !== "bar") continue;
|
|
35
|
+
for (const series of group.series) {
|
|
36
|
+
const serLabels = mergeDataLabels(group.dataLabels, series.dataLabels);
|
|
37
|
+
for (let i = 0; i < series.values.length; i += 1) {
|
|
38
|
+
const val = series.values[i];
|
|
39
|
+
if (val === null || val === void 0 || !Number.isFinite(val)) continue;
|
|
40
|
+
const ptOverride = series.points?.[i]?.dataLabels;
|
|
41
|
+
const eff = mergeDataLabels(serLabels, ptOverride);
|
|
42
|
+
if (eff === void 0 || eff === false) continue;
|
|
43
|
+
if (!eff.value && !eff.category && !eff.percent && !eff.seriesName) continue;
|
|
44
|
+
if ((eff.position ?? (group.stacking === "clustered" ? "outsideEnd" : "center")) !== "outsideEnd") continue;
|
|
45
|
+
if (group.kind === "column") {
|
|
46
|
+
if (val < 0) columnNeg = true;
|
|
47
|
+
else columnPos = true;
|
|
48
|
+
} else if (val < 0) barNeg = true;
|
|
49
|
+
else barPos = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
columnPos,
|
|
55
|
+
columnNeg,
|
|
56
|
+
barPos,
|
|
57
|
+
barNeg
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function hasPointDataLabels(parsed) {
|
|
61
|
+
let top = false;
|
|
62
|
+
let bottom = false;
|
|
63
|
+
let left = false;
|
|
64
|
+
let right = false;
|
|
65
|
+
for (const group of parsed.groups) {
|
|
66
|
+
if (group.kind !== "line" && group.kind !== "area" && group.kind !== "scatter") continue;
|
|
67
|
+
const defaultPos = group.kind === "scatter" ? "right" : group.kind === "area" ? "center" : "top";
|
|
68
|
+
for (const series of group.series) {
|
|
69
|
+
const serLabels = mergeDataLabels(group.dataLabels, series.dataLabels);
|
|
70
|
+
const count = "x" in series ? series.x.length : series.values.length;
|
|
71
|
+
for (let i = 0; i < count; i += 1) {
|
|
72
|
+
const ptOverride = series.points?.[i]?.dataLabels;
|
|
73
|
+
const eff = mergeDataLabels(serLabels, ptOverride);
|
|
74
|
+
if (eff === void 0 || eff === false) continue;
|
|
75
|
+
if (!eff.value && !eff.category && !eff.percent && !eff.xValue && !eff.seriesName) continue;
|
|
76
|
+
const pos = eff.position ?? defaultPos;
|
|
77
|
+
if (pos === "top") top = true;
|
|
78
|
+
else if (pos === "bottom") bottom = true;
|
|
79
|
+
else if (pos === "left") left = true;
|
|
80
|
+
else if (pos === "right") right = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
top,
|
|
86
|
+
bottom,
|
|
87
|
+
left,
|
|
88
|
+
right
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function computeChartLayout(options) {
|
|
92
|
+
const { parsed, box, scales, baseChartTextStyle, baseFontSizePx, theme, slideNumber } = options;
|
|
93
|
+
const legendEntries = parsed.legend !== void 0 && parsed.legend !== false ? collectLegendEntries(parsed, theme) : [];
|
|
94
|
+
if (parsed.plotArea !== void 0) {
|
|
95
|
+
const plotRect = {
|
|
96
|
+
x: box.x + parsed.plotArea.left,
|
|
97
|
+
y: box.y + parsed.plotArea.top,
|
|
98
|
+
width: parsed.plotArea.width,
|
|
99
|
+
height: parsed.plotArea.height
|
|
100
|
+
};
|
|
101
|
+
let titleBox;
|
|
102
|
+
if (parsed.title !== void 0) {
|
|
103
|
+
const topRoom = Math.max(0, parsed.plotArea.top - 4);
|
|
104
|
+
const t = titleTextOf(parsed.title);
|
|
105
|
+
const measured = measureChartText({
|
|
106
|
+
text: t.text,
|
|
107
|
+
style: mergeChartTextStyle(baseChartTextStyle, t.style),
|
|
108
|
+
theme,
|
|
109
|
+
slideNumber,
|
|
110
|
+
labelPath: "Chart.title",
|
|
111
|
+
availableWidth: Math.max(10, box.width - 16)
|
|
112
|
+
});
|
|
113
|
+
const h = Math.min(measured.height, Math.max(12, topRoom));
|
|
114
|
+
titleBox = {
|
|
115
|
+
x: box.x + 8,
|
|
116
|
+
y: box.y + 2,
|
|
117
|
+
width: Math.max(10, box.width - 16),
|
|
118
|
+
height: h
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
let measuredLegend;
|
|
122
|
+
let legendBox;
|
|
123
|
+
if (parsed.legend !== void 0 && parsed.legend !== false && legendEntries.length > 0) {
|
|
124
|
+
measuredLegend = measureLegend({
|
|
125
|
+
entries: legendEntries,
|
|
126
|
+
position: parsed.legend,
|
|
127
|
+
maxWidth: Math.max(20, box.width - 16),
|
|
128
|
+
fontSizePx: baseFontSizePx,
|
|
129
|
+
style: baseChartTextStyle,
|
|
130
|
+
theme,
|
|
131
|
+
slideNumber
|
|
132
|
+
});
|
|
133
|
+
const bottomRoom = Math.max(14, box.height - (parsed.plotArea.top + parsed.plotArea.height) - 4);
|
|
134
|
+
if (parsed.legend === "bottom") legendBox = {
|
|
135
|
+
x: box.x + 8,
|
|
136
|
+
y: box.y + box.height - bottomRoom - 2,
|
|
137
|
+
width: Math.max(10, box.width - 16),
|
|
138
|
+
height: bottomRoom
|
|
139
|
+
};
|
|
140
|
+
else if (parsed.legend === "top") legendBox = {
|
|
141
|
+
x: box.x + 8,
|
|
142
|
+
y: box.y + (titleBox ? titleBox.height + 4 : 2),
|
|
143
|
+
width: Math.max(10, box.width - 16),
|
|
144
|
+
height: Math.min(measuredLegend.height, Math.max(14, parsed.plotArea.top - 4))
|
|
145
|
+
};
|
|
146
|
+
else if (parsed.legend === "left") legendBox = {
|
|
147
|
+
x: box.x + 4,
|
|
148
|
+
y: plotRect.y,
|
|
149
|
+
width: Math.max(14, parsed.plotArea.left - 8),
|
|
150
|
+
height: plotRect.height
|
|
151
|
+
};
|
|
152
|
+
else {
|
|
153
|
+
const rightRoom = Math.max(14, box.width - (parsed.plotArea.left + parsed.plotArea.width) - 8);
|
|
154
|
+
legendBox = {
|
|
155
|
+
x: plotRect.x + plotRect.width + 4,
|
|
156
|
+
y: plotRect.y,
|
|
157
|
+
width: rightRoom,
|
|
158
|
+
height: parsed.legend === "topRight" ? Math.min(measuredLegend.height, plotRect.height) : plotRect.height
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const axisTitleBoxes = /* @__PURE__ */ new Map();
|
|
163
|
+
const labelZones = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const axis of parsed.axes) {
|
|
165
|
+
if (axis.spec.visible === false) continue;
|
|
166
|
+
const crossAxis = parsed.axes.find((a) => a.id === axis.crossAxisId);
|
|
167
|
+
const crossScale = crossAxis ? scales.get(crossAxis.name) : void 0;
|
|
168
|
+
const labelSide = resolveAxisLabelSide(axis, crossScale);
|
|
169
|
+
if (labelSide !== "none" && labelSide !== "interior") labelZones.set(axis.name, {
|
|
170
|
+
side: labelSide,
|
|
171
|
+
depth: 20,
|
|
172
|
+
offset: 0
|
|
173
|
+
});
|
|
174
|
+
if (axis.spec.title !== void 0) {
|
|
175
|
+
const titleSide = resolveAxisTitleSide(axis, crossScale);
|
|
176
|
+
const t = titleTextOf(axis.spec.title);
|
|
177
|
+
const titleStyle = mergeChartTextStyle(mergeChartTextStyle(baseChartTextStyle, axis.spec.style), t.style);
|
|
178
|
+
const thickness = resolveChartFontSizePixels(titleStyle?.fontSize) * 1.3;
|
|
179
|
+
if (titleSide === "bottom") axisTitleBoxes.set(axis.name, {
|
|
180
|
+
x: plotRect.x,
|
|
181
|
+
y: Math.min(box.y + box.height - thickness, plotRect.y + plotRect.height + 18),
|
|
182
|
+
width: plotRect.width,
|
|
183
|
+
height: thickness
|
|
184
|
+
});
|
|
185
|
+
else if (titleSide === "top") axisTitleBoxes.set(axis.name, {
|
|
186
|
+
x: plotRect.x,
|
|
187
|
+
y: Math.max(box.y, plotRect.y - 18 - thickness),
|
|
188
|
+
width: plotRect.width,
|
|
189
|
+
height: thickness
|
|
190
|
+
});
|
|
191
|
+
else if (titleSide === "left") axisTitleBoxes.set(axis.name, {
|
|
192
|
+
x: Math.max(box.x, plotRect.x - 24 - thickness),
|
|
193
|
+
y: plotRect.y,
|
|
194
|
+
width: thickness,
|
|
195
|
+
height: plotRect.height
|
|
196
|
+
});
|
|
197
|
+
else axisTitleBoxes.set(axis.name, {
|
|
198
|
+
x: Math.min(box.x + box.width - thickness, plotRect.x + plotRect.width + 24),
|
|
199
|
+
y: plotRect.y,
|
|
200
|
+
width: thickness,
|
|
201
|
+
height: plotRect.height
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
plotRect,
|
|
207
|
+
...titleBox === void 0 ? {} : { titleBox },
|
|
208
|
+
...legendBox === void 0 ? {} : { legendBox },
|
|
209
|
+
...measuredLegend === void 0 ? {} : { measuredLegend },
|
|
210
|
+
axisTitleBoxes,
|
|
211
|
+
labelZones
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const padX = Math.min(8, box.width * .025);
|
|
215
|
+
const padY = Math.min(8, box.height * .025);
|
|
216
|
+
const avail = {
|
|
217
|
+
x: box.x + padX,
|
|
218
|
+
y: box.y + padY,
|
|
219
|
+
width: Math.max(4, box.width - 2 * padX),
|
|
220
|
+
height: Math.max(4, box.height - 2 * padY)
|
|
221
|
+
};
|
|
222
|
+
let titleBox;
|
|
223
|
+
if (parsed.title !== void 0) {
|
|
224
|
+
const t = titleTextOf(parsed.title);
|
|
225
|
+
const titleStyle = mergeChartTextStyle(baseChartTextStyle, t.style);
|
|
226
|
+
const measured = measureChartText({
|
|
227
|
+
text: t.text,
|
|
228
|
+
style: titleStyle,
|
|
229
|
+
theme,
|
|
230
|
+
slideNumber,
|
|
231
|
+
labelPath: "Chart.title",
|
|
232
|
+
availableWidth: avail.width
|
|
233
|
+
});
|
|
234
|
+
const gap = Math.min(6, avail.height * .03);
|
|
235
|
+
const maxTitleH = Math.max(4, avail.height * .25);
|
|
236
|
+
const h = Math.min(measured.height, maxTitleH);
|
|
237
|
+
titleBox = {
|
|
238
|
+
x: avail.x,
|
|
239
|
+
y: avail.y,
|
|
240
|
+
width: avail.width,
|
|
241
|
+
height: h
|
|
242
|
+
};
|
|
243
|
+
const consume = Math.min(h + gap, Math.max(0, avail.height - 4));
|
|
244
|
+
avail.y += consume;
|
|
245
|
+
avail.height = Math.max(4, avail.height - consume);
|
|
246
|
+
}
|
|
247
|
+
let measuredLegend;
|
|
248
|
+
let legendBox;
|
|
249
|
+
if (parsed.legend !== void 0 && parsed.legend !== false && legendEntries.length > 0) {
|
|
250
|
+
const pos = parsed.legend;
|
|
251
|
+
measuredLegend = measureLegend({
|
|
252
|
+
entries: legendEntries,
|
|
253
|
+
position: pos,
|
|
254
|
+
maxWidth: avail.width,
|
|
255
|
+
fontSizePx: baseFontSizePx,
|
|
256
|
+
style: baseChartTextStyle,
|
|
257
|
+
theme,
|
|
258
|
+
slideNumber
|
|
259
|
+
});
|
|
260
|
+
const gap = Math.min(6, Math.min(avail.width, avail.height) * .03);
|
|
261
|
+
if (pos === "top" || pos === "bottom") {
|
|
262
|
+
const h = Math.min(measuredLegend.height, Math.max(4, avail.height * .28));
|
|
263
|
+
const consume = Math.min(h + gap, Math.max(0, avail.height - 4));
|
|
264
|
+
if (pos === "top") {
|
|
265
|
+
legendBox = {
|
|
266
|
+
x: avail.x,
|
|
267
|
+
y: avail.y,
|
|
268
|
+
width: avail.width,
|
|
269
|
+
height: h
|
|
270
|
+
};
|
|
271
|
+
avail.y += consume;
|
|
272
|
+
} else legendBox = {
|
|
273
|
+
x: avail.x,
|
|
274
|
+
y: avail.y + avail.height - h,
|
|
275
|
+
width: avail.width,
|
|
276
|
+
height: h
|
|
277
|
+
};
|
|
278
|
+
avail.height = Math.max(4, avail.height - consume);
|
|
279
|
+
} else if (pos === "left" || pos === "right") {
|
|
280
|
+
const w = Math.min(measuredLegend.width, Math.max(4, avail.width * .32));
|
|
281
|
+
const consume = Math.min(w + gap, Math.max(0, avail.width - 4));
|
|
282
|
+
if (pos === "left") {
|
|
283
|
+
legendBox = {
|
|
284
|
+
x: avail.x,
|
|
285
|
+
y: avail.y,
|
|
286
|
+
width: w,
|
|
287
|
+
height: avail.height
|
|
288
|
+
};
|
|
289
|
+
avail.x += consume;
|
|
290
|
+
} else legendBox = {
|
|
291
|
+
x: avail.x + avail.width - w,
|
|
292
|
+
y: avail.y,
|
|
293
|
+
width: w,
|
|
294
|
+
height: avail.height
|
|
295
|
+
};
|
|
296
|
+
avail.width = Math.max(4, avail.width - consume);
|
|
297
|
+
} else {
|
|
298
|
+
const w = Math.min(measuredLegend.width, Math.max(4, avail.width * .32));
|
|
299
|
+
const h = Math.min(measuredLegend.height, Math.max(4, avail.height * .5));
|
|
300
|
+
const consume = Math.min(w + gap, Math.max(0, avail.width - 4));
|
|
301
|
+
legendBox = {
|
|
302
|
+
x: avail.x + avail.width - w,
|
|
303
|
+
y: avail.y,
|
|
304
|
+
width: w,
|
|
305
|
+
height: h
|
|
306
|
+
};
|
|
307
|
+
avail.width = Math.max(4, avail.width - consume);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const edges = {
|
|
311
|
+
top: 0,
|
|
312
|
+
bottom: 0,
|
|
313
|
+
left: 0,
|
|
314
|
+
right: 0
|
|
315
|
+
};
|
|
316
|
+
const labelDepths = /* @__PURE__ */ new Map();
|
|
317
|
+
const addLabelZone = (axisName, side, depth) => {
|
|
318
|
+
const existing = edges[side];
|
|
319
|
+
const offset = existing > 0 ? existing + 2 : 0;
|
|
320
|
+
edges[side] = offset + depth;
|
|
321
|
+
labelDepths.set(axisName, {
|
|
322
|
+
side,
|
|
323
|
+
depth,
|
|
324
|
+
offset
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
const axisTitleSpecs = [];
|
|
328
|
+
for (const axis of parsed.axes) {
|
|
329
|
+
if (axis.spec.visible === false) continue;
|
|
330
|
+
const scale = scales.get(axis.name);
|
|
331
|
+
if (scale === void 0) continue;
|
|
332
|
+
const crossAxis = parsed.axes.find((a) => a.id === axis.crossAxisId);
|
|
333
|
+
const crossScale = crossAxis ? scales.get(crossAxis.name) : void 0;
|
|
334
|
+
const labelSide = resolveAxisLabelSide(axis, crossScale);
|
|
335
|
+
const axisTextStyle = mergeChartTextStyle(baseChartTextStyle, axis.spec.style);
|
|
336
|
+
const tickProtrusion = axis.spec.majorTickMark === "out" || axis.spec.majorTickMark === "cross" ? 4 : 0;
|
|
337
|
+
const labelGap = 4;
|
|
338
|
+
if (labelSide !== "none" && labelSide !== "interior") {
|
|
339
|
+
if (scale.kind === "value") {
|
|
340
|
+
const formattedTicks = scale.majorTicks.map((v) => formatChartNumber(v, scale.numberFormat));
|
|
341
|
+
let maxW = 0;
|
|
342
|
+
let maxH = 0;
|
|
343
|
+
for (const text of formattedTicks) {
|
|
344
|
+
const m = measureChartText({
|
|
345
|
+
text,
|
|
346
|
+
style: axisTextStyle,
|
|
347
|
+
theme,
|
|
348
|
+
slideNumber,
|
|
349
|
+
labelPath: `Chart.axes.${axis.name}.style`
|
|
350
|
+
});
|
|
351
|
+
maxW = Math.max(maxW, m.width);
|
|
352
|
+
maxH = Math.max(maxH, m.height);
|
|
353
|
+
}
|
|
354
|
+
if (axis.direction === "horizontal") {
|
|
355
|
+
const depth = maxH + labelGap + tickProtrusion;
|
|
356
|
+
addLabelZone(axis.name, labelSide, depth);
|
|
357
|
+
const overhang = Math.min(maxW / 2, avail.width * .1);
|
|
358
|
+
edges.left = Math.max(edges.left, overhang);
|
|
359
|
+
edges.right = Math.max(edges.right, overhang);
|
|
360
|
+
} else {
|
|
361
|
+
const depth = Math.min(maxW + labelGap + tickProtrusion, avail.width * .32);
|
|
362
|
+
addLabelZone(axis.name, labelSide, depth);
|
|
363
|
+
const overhang = Math.min(maxH / 2, avail.height * .1);
|
|
364
|
+
edges.top = Math.max(edges.top, overhang);
|
|
365
|
+
edges.bottom = Math.max(edges.bottom, overhang);
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
let maxW = 0;
|
|
369
|
+
let maxH = 0;
|
|
370
|
+
const estSlot = Math.max(12, avail.width * .8 / scale.count);
|
|
371
|
+
for (const cat of scale.categories) {
|
|
372
|
+
const m = measureChartText({
|
|
373
|
+
text: cat,
|
|
374
|
+
style: axisTextStyle,
|
|
375
|
+
theme,
|
|
376
|
+
slideNumber,
|
|
377
|
+
labelPath: `Chart.axes.${axis.name}.style`,
|
|
378
|
+
...axis.direction === "horizontal" ? { availableWidth: estSlot } : {}
|
|
379
|
+
});
|
|
380
|
+
maxW = Math.max(maxW, m.width);
|
|
381
|
+
maxH = Math.max(maxH, m.height);
|
|
382
|
+
}
|
|
383
|
+
if (axis.direction === "horizontal") {
|
|
384
|
+
const singleLineH = measureChartText({
|
|
385
|
+
text: "Ay",
|
|
386
|
+
style: axisTextStyle,
|
|
387
|
+
theme,
|
|
388
|
+
slideNumber,
|
|
389
|
+
labelPath: `Chart.axes.${axis.name}.style`
|
|
390
|
+
}).height;
|
|
391
|
+
const depth = Math.min(maxH, singleLineH * 2.2, avail.height * .25) + labelGap + tickProtrusion;
|
|
392
|
+
addLabelZone(axis.name, labelSide, depth);
|
|
393
|
+
} else {
|
|
394
|
+
const depth = Math.min(maxW + labelGap + tickProtrusion, avail.width * .34);
|
|
395
|
+
addLabelZone(axis.name, labelSide, depth);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (axis.spec.title !== void 0) {
|
|
400
|
+
const titleSide = resolveAxisTitleSide(axis, crossScale);
|
|
401
|
+
const t = titleTextOf(axis.spec.title);
|
|
402
|
+
const titleStyle = mergeChartTextStyle(axisTextStyle, t.style);
|
|
403
|
+
const thickness = measureChartText({
|
|
404
|
+
text: t.text,
|
|
405
|
+
style: titleStyle,
|
|
406
|
+
theme,
|
|
407
|
+
slideNumber,
|
|
408
|
+
labelPath: `Chart.axes.${axis.name}.title`
|
|
409
|
+
}).height + 4;
|
|
410
|
+
axisTitleSpecs.push({
|
|
411
|
+
axis,
|
|
412
|
+
side: titleSide,
|
|
413
|
+
thickness
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const axisTitleBoxes = /* @__PURE__ */ new Map();
|
|
418
|
+
const titleEdgeOffset = {
|
|
419
|
+
top: edges.top,
|
|
420
|
+
bottom: edges.bottom,
|
|
421
|
+
left: edges.left,
|
|
422
|
+
right: edges.right
|
|
423
|
+
};
|
|
424
|
+
for (const item of axisTitleSpecs) edges[item.side] += item.thickness;
|
|
425
|
+
const outside = hasOutsideEndBarLabels(parsed);
|
|
426
|
+
const pointLabels = hasPointDataLabels(parsed);
|
|
427
|
+
if (outside.columnPos || pointLabels.top) edges.top = Math.max(edges.top, Math.min(baseFontSizePx * 1.4, avail.height * .16));
|
|
428
|
+
if (outside.columnNeg || pointLabels.bottom) edges.bottom = Math.max(edges.bottom, Math.min(baseFontSizePx * 1.4, avail.height * .16));
|
|
429
|
+
if (outside.barPos || pointLabels.right) edges.right = Math.max(edges.right, Math.min(baseFontSizePx * 2.5, avail.width * .16));
|
|
430
|
+
if (outside.barNeg || pointLabels.left) edges.left = Math.max(edges.left, Math.min(baseFontSizePx * 2.5, avail.width * .16));
|
|
431
|
+
for (const side of [
|
|
432
|
+
"top",
|
|
433
|
+
"bottom",
|
|
434
|
+
"left",
|
|
435
|
+
"right"
|
|
436
|
+
]) if (edges[side] === 0) edges[side] = Math.min(6, (side === "left" || side === "right" ? avail.width : avail.height) * .03);
|
|
437
|
+
const maxHorizSum = Math.max(0, avail.width - 4);
|
|
438
|
+
if (edges.left + edges.right > maxHorizSum && edges.left + edges.right > 0) {
|
|
439
|
+
const ratio = maxHorizSum / (edges.left + edges.right);
|
|
440
|
+
edges.left *= ratio;
|
|
441
|
+
edges.right *= ratio;
|
|
442
|
+
titleEdgeOffset.left *= ratio;
|
|
443
|
+
titleEdgeOffset.right *= ratio;
|
|
444
|
+
}
|
|
445
|
+
const maxVertSum = Math.max(0, avail.height - 4);
|
|
446
|
+
if (edges.top + edges.bottom > maxVertSum && edges.top + edges.bottom > 0) {
|
|
447
|
+
const ratio = maxVertSum / (edges.top + edges.bottom);
|
|
448
|
+
edges.top *= ratio;
|
|
449
|
+
edges.bottom *= ratio;
|
|
450
|
+
titleEdgeOffset.top *= ratio;
|
|
451
|
+
titleEdgeOffset.bottom *= ratio;
|
|
452
|
+
}
|
|
453
|
+
const plotRect = {
|
|
454
|
+
x: avail.x + edges.left,
|
|
455
|
+
y: avail.y + edges.top,
|
|
456
|
+
width: Math.max(4, avail.width - edges.left - edges.right),
|
|
457
|
+
height: Math.max(4, avail.height - edges.top - edges.bottom)
|
|
458
|
+
};
|
|
459
|
+
const titleCursors = {
|
|
460
|
+
top: plotRect.y - titleEdgeOffset.top,
|
|
461
|
+
bottom: plotRect.y + plotRect.height + titleEdgeOffset.bottom,
|
|
462
|
+
left: plotRect.x - titleEdgeOffset.left,
|
|
463
|
+
right: plotRect.x + plotRect.width + titleEdgeOffset.right
|
|
464
|
+
};
|
|
465
|
+
for (const item of axisTitleSpecs) {
|
|
466
|
+
const hRatio = avail.width > 4 && edges.left + edges.right > 0 ? Math.min(1, maxHorizSum / (edges.left + edges.right)) : 1;
|
|
467
|
+
const vRatio = avail.height > 4 && edges.top + edges.bottom > 0 ? Math.min(1, maxVertSum / (edges.top + edges.bottom)) : 1;
|
|
468
|
+
if (item.side === "top") {
|
|
469
|
+
const th = item.thickness * vRatio;
|
|
470
|
+
const y = titleCursors.top - th;
|
|
471
|
+
axisTitleBoxes.set(item.axis.name, {
|
|
472
|
+
x: plotRect.x,
|
|
473
|
+
y,
|
|
474
|
+
width: plotRect.width,
|
|
475
|
+
height: th
|
|
476
|
+
});
|
|
477
|
+
titleCursors.top = y;
|
|
478
|
+
} else if (item.side === "bottom") {
|
|
479
|
+
const th = item.thickness * vRatio;
|
|
480
|
+
const y = titleCursors.bottom;
|
|
481
|
+
axisTitleBoxes.set(item.axis.name, {
|
|
482
|
+
x: plotRect.x,
|
|
483
|
+
y,
|
|
484
|
+
width: plotRect.width,
|
|
485
|
+
height: th
|
|
486
|
+
});
|
|
487
|
+
titleCursors.bottom = y + th;
|
|
488
|
+
} else if (item.side === "left") {
|
|
489
|
+
const tw = item.thickness * hRatio;
|
|
490
|
+
const x = titleCursors.left - tw;
|
|
491
|
+
axisTitleBoxes.set(item.axis.name, {
|
|
492
|
+
x,
|
|
493
|
+
y: plotRect.y,
|
|
494
|
+
width: tw,
|
|
495
|
+
height: plotRect.height
|
|
496
|
+
});
|
|
497
|
+
titleCursors.left = x;
|
|
498
|
+
} else {
|
|
499
|
+
const tw = item.thickness * hRatio;
|
|
500
|
+
const x = titleCursors.right;
|
|
501
|
+
axisTitleBoxes.set(item.axis.name, {
|
|
502
|
+
x,
|
|
503
|
+
y: plotRect.y,
|
|
504
|
+
width: tw,
|
|
505
|
+
height: plotRect.height
|
|
506
|
+
});
|
|
507
|
+
titleCursors.right = x + tw;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
plotRect,
|
|
512
|
+
...titleBox === void 0 ? {} : { titleBox },
|
|
513
|
+
...legendBox === void 0 ? {} : { legendBox },
|
|
514
|
+
...measuredLegend === void 0 ? {} : { measuredLegend },
|
|
515
|
+
axisTitleBoxes,
|
|
516
|
+
labelZones: labelDepths
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
export { computeChartLayout, resolveAxisLabelSide, resolveAxisTitleSide };
|