pptx-templates 0.3.8 → 0.4.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/AI-INSTRUCTOR.md +91 -2
- package/CHANGELOG.md +125 -1
- package/dist/automizer.js +143 -176
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js +23 -36
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +129 -148
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js +81 -126
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js +47 -67
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js +70 -89
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js +48 -37
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js +65 -86
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js +79 -110
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js +108 -130
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js +24 -41
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js +112 -141
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js +82 -117
- package/dist/classes/template.js.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js +3 -13
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js +48 -46
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.d.ts +10 -0
- package/dist/extensions/regexp-escape/index.js +15 -0
- package/dist/extensions/regexp-escape/index.js.map +1 -0
- package/dist/extensions/run-merge/index.js +4 -5
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.d.ts +2 -0
- package/dist/extensions/shape-geometry/index.js +13 -13
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +49 -41
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +18 -10
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js +17 -20
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.js +12 -17
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.js +195 -62
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +10 -14
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js +8 -9
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-logic/clone.d.ts +2 -16
- package/dist/extensions/template-logic/clone.js +15 -90
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +8 -0
- package/dist/extensions/template-logic/commands.js +21 -12
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +6 -0
- package/dist/extensions/template-logic/expression.js +56 -54
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.d.ts +14 -0
- package/dist/extensions/template-logic/images.js +277 -49
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +20 -27
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +31 -16
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +24 -0
- package/dist/extensions/template-logic/renderer.js +505 -380
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +5 -0
- package/dist/extensions/template-logic/types.js +6 -0
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +7 -18
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js +152 -107
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.d.ts +14 -0
- package/dist/extensions/template-render/prune.js +131 -0
- package/dist/extensions/template-render/prune.js.map +1 -0
- package/dist/extensions/template-render/zip-text.d.ts +9 -0
- package/dist/extensions/template-render/zip-text.js +27 -0
- package/dist/extensions/template-render/zip-text.js.map +1 -0
- package/dist/extensions/template-render/zip-writer.d.ts +16 -0
- package/dist/extensions/template-render/zip-writer.js +151 -0
- package/dist/extensions/template-render/zip-writer.js.map +1 -0
- package/dist/extensions/text-flow/flow.d.ts +5 -0
- package/dist/extensions/text-flow/flow.js +196 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.js +9 -7
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.d.ts +4 -0
- package/dist/extensions/text-flow/fonts.js +45 -22
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +5 -6
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js +18 -22
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +11 -0
- package/dist/extensions/text-flow/styles.js +121 -62
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.js +102 -138
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js +101 -125
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.d.ts +6 -0
- package/dist/helper/archive/archive.js +21 -30
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +19 -0
- package/dist/helper/archive/jszip-fast-read.js +153 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/compute-src-rect.js +4 -5
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js +86 -114
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js +48 -78
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.js +1 -2
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js +30 -48
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js +36 -48
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.js +34 -18
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js +125 -139
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/jszip-helper.js +23 -32
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js +51 -71
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js +4 -4
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.d.ts +24 -0
- package/dist/helper/media-deduplicator.js +81 -34
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js +46 -46
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.js +597 -591
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +112 -112
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.js +53 -53
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js +25 -25
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +143 -154
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.js +121 -132
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js +137 -154
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js +262 -262
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +84 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.js +187 -189
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js +36 -36
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +9 -7
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js +17 -17
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js +18 -29
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +6 -7
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml-clone.d.ts +24 -0
- package/dist/helper/xml-clone.js +269 -0
- package/dist/helper/xml-clone.js.map +1 -0
- package/dist/helper/xml-elements.js +17 -20
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.d.ts +4 -0
- package/dist/helper/xml-find.js +48 -0
- package/dist/helper/xml-find.js.map +1 -0
- package/dist/helper/xml-helper.js +99 -134
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.d.ts +31 -0
- package/dist/helper/xml-parse-cache.js +71 -0
- package/dist/helper/xml-parse-cache.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.js +10 -10
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +120 -144
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.d.ts +2 -0
- package/dist/helper/xml-serializer.js +192 -0
- package/dist/helper/xml-serializer.js.map +1 -0
- package/dist/helper/xml-slide-helper.js +109 -129
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js +120 -144
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js +52 -2
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.js +11 -14
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js +238 -287
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.js +73 -104
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js +62 -83
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.js +98 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +112 -151
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/package.json +3 -4
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
var _a;
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
const logger_1 = require("./logger");
|
|
8
7
|
const modify_chart_1 = require("../modify/modify-chart");
|
|
@@ -10,633 +9,640 @@ const modify_xml_helper_1 = __importDefault(require("./modify-xml-helper"));
|
|
|
10
9
|
const xml_helper_1 = require("./xml-helper");
|
|
11
10
|
const modify_color_helper_1 = __importDefault(require("./modify-color-helper"));
|
|
12
11
|
class ModifyChartHelper {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const slots = [];
|
|
27
|
-
data.series.forEach((series, s) => {
|
|
28
|
-
slots.push({
|
|
29
|
-
index: s,
|
|
30
|
-
series: series,
|
|
31
|
-
targetCol: s + 1,
|
|
32
|
-
type: 'defaultSeries',
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
36
|
-
// XmlHelper.dump(chart)
|
|
37
|
-
// XmlHelper.dump(workbook.table)
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Set chart data to modify vertical line charts.
|
|
41
|
-
* See `__tests__/modify-chart-vertical-lines.test.js`
|
|
42
|
-
*/
|
|
43
|
-
ModifyChartHelper.setChartVerticalLines = (data) => (element, chart, workbook) => {
|
|
44
|
-
const slots = [];
|
|
45
|
-
slots.push({
|
|
46
|
-
label: `Y-Values`,
|
|
47
|
-
mapData: (point, category) => category.y,
|
|
48
|
-
targetCol: 1,
|
|
49
|
-
});
|
|
50
|
-
data.series.forEach((series, s) => {
|
|
51
|
-
slots.push({
|
|
52
|
-
index: s,
|
|
53
|
-
series: series,
|
|
54
|
-
targetCol: s + 2,
|
|
55
|
-
type: 'xySeries',
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
59
|
-
// ModifyChartHelper.setAxisRange({
|
|
60
|
-
// axisIndex: 0,
|
|
61
|
-
// min: 0,
|
|
62
|
-
// max: data.categories.length,
|
|
63
|
-
// })(element, chart);
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Set chart data to modify scatter charts.
|
|
67
|
-
* See `__tests__/modify-chart-scatter.test.js`
|
|
68
|
-
*/
|
|
69
|
-
ModifyChartHelper.setChartScatter = (data) => (element, chart, workbook) => {
|
|
70
|
-
const slots = [];
|
|
71
|
-
data.series.forEach((series, s) => {
|
|
72
|
-
const colId = s * 2;
|
|
73
|
-
slots.push({
|
|
74
|
-
index: s,
|
|
75
|
-
series: series,
|
|
76
|
-
targetCol: colId + 1,
|
|
77
|
-
type: 'customSeries',
|
|
78
|
-
tag: 'c:xVal',
|
|
79
|
-
mapData: (point) => point.x,
|
|
12
|
+
/**
|
|
13
|
+
* Set chart data to modify default chart types.
|
|
14
|
+
* See `__tests__/modify-existing-chart.test.js`
|
|
15
|
+
*/
|
|
16
|
+
static { this.setChartData = (data) => (element, chart, workbook) => {
|
|
17
|
+
const slots = [];
|
|
18
|
+
data.series.forEach((series, s) => {
|
|
19
|
+
slots.push({
|
|
20
|
+
index: s,
|
|
21
|
+
series: series,
|
|
22
|
+
targetCol: s + 1,
|
|
23
|
+
type: 'defaultSeries',
|
|
24
|
+
});
|
|
80
25
|
});
|
|
26
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
27
|
+
// XmlHelper.dump(chart)
|
|
28
|
+
// XmlHelper.dump(workbook.table)
|
|
29
|
+
}; }
|
|
30
|
+
/**
|
|
31
|
+
* Set chart data to modify vertical line charts.
|
|
32
|
+
* See `__tests__/modify-chart-vertical-lines.test.js`
|
|
33
|
+
*/
|
|
34
|
+
static { this.setChartVerticalLines = (data) => (element, chart, workbook) => {
|
|
35
|
+
const slots = [];
|
|
81
36
|
slots.push({
|
|
82
|
-
label:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
targetCol: colId + 2,
|
|
86
|
-
type: 'customSeries',
|
|
87
|
-
tag: 'c:yVal',
|
|
88
|
-
mapData: (point) => point.y,
|
|
89
|
-
isStrRef: false,
|
|
37
|
+
label: `Y-Values`,
|
|
38
|
+
mapData: (point, category) => category.y,
|
|
39
|
+
targetCol: 1,
|
|
90
40
|
});
|
|
91
|
-
|
|
92
|
-
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
93
|
-
// XmlHelper.dump(chart)
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Set chart data to modify combo charts.
|
|
97
|
-
* This type is prepared for
|
|
98
|
-
* first series: bar chart (e.g. total)
|
|
99
|
-
* other series: vertical lines
|
|
100
|
-
* See `__tests__/modify-chart-scatter.test.js`
|
|
101
|
-
*/
|
|
102
|
-
ModifyChartHelper.setChartCombo = (data) => (element, chart, workbook) => {
|
|
103
|
-
const slots = [];
|
|
104
|
-
slots.push({
|
|
105
|
-
index: 0,
|
|
106
|
-
series: data.series[0],
|
|
107
|
-
targetCol: 1,
|
|
108
|
-
type: 'defaultSeries',
|
|
109
|
-
});
|
|
110
|
-
slots.push({
|
|
111
|
-
index: 1,
|
|
112
|
-
label: `Y-Values`,
|
|
113
|
-
mapData: (point, category) => category.y,
|
|
114
|
-
targetCol: 2,
|
|
115
|
-
});
|
|
116
|
-
data.series.forEach((series, s) => {
|
|
117
|
-
if (s > 0)
|
|
41
|
+
data.series.forEach((series, s) => {
|
|
118
42
|
slots.push({
|
|
119
43
|
index: s,
|
|
120
44
|
series: series,
|
|
121
45
|
targetCol: s + 2,
|
|
122
|
-
targetYCol: 2,
|
|
123
46
|
type: 'xySeries',
|
|
124
47
|
});
|
|
125
|
-
});
|
|
126
|
-
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
127
|
-
_a.setAxisRange({
|
|
128
|
-
axisIndex: 1,
|
|
129
|
-
min: 0,
|
|
130
|
-
max: data.categories.length,
|
|
131
|
-
})(element, chart);
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Set chart data to modify bubble charts.
|
|
135
|
-
* See `__tests__/modify-chart-bubbles.test.js`
|
|
136
|
-
*/
|
|
137
|
-
ModifyChartHelper.setChartBubbles = (data) => (element, chart, workbook) => {
|
|
138
|
-
const slots = [];
|
|
139
|
-
data.series.forEach((series, s) => {
|
|
140
|
-
const colId = s * 3;
|
|
141
|
-
slots.push({
|
|
142
|
-
index: s,
|
|
143
|
-
series: series,
|
|
144
|
-
targetCol: colId + 1,
|
|
145
|
-
type: 'customSeries',
|
|
146
|
-
tag: 'c:xVal',
|
|
147
|
-
mapData: (point) => point.x,
|
|
148
48
|
});
|
|
149
|
-
slots.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
49
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
50
|
+
// ModifyChartHelper.setAxisRange({
|
|
51
|
+
// axisIndex: 0,
|
|
52
|
+
// min: 0,
|
|
53
|
+
// max: data.categories.length,
|
|
54
|
+
// })(element, chart);
|
|
55
|
+
}; }
|
|
56
|
+
/**
|
|
57
|
+
* Set chart data to modify scatter charts.
|
|
58
|
+
* See `__tests__/modify-chart-scatter.test.js`
|
|
59
|
+
*/
|
|
60
|
+
static { this.setChartScatter = (data) => (element, chart, workbook) => {
|
|
61
|
+
const slots = [];
|
|
62
|
+
data.series.forEach((series, s) => {
|
|
63
|
+
const colId = s * 2;
|
|
64
|
+
slots.push({
|
|
65
|
+
index: s,
|
|
66
|
+
series: series,
|
|
67
|
+
targetCol: colId + 1,
|
|
68
|
+
type: 'customSeries',
|
|
69
|
+
tag: 'c:xVal',
|
|
70
|
+
mapData: (point) => point.x,
|
|
71
|
+
});
|
|
72
|
+
slots.push({
|
|
73
|
+
label: `${series.label}-Y-Value`,
|
|
74
|
+
index: s,
|
|
75
|
+
series: series,
|
|
76
|
+
targetCol: colId + 2,
|
|
77
|
+
type: 'customSeries',
|
|
78
|
+
tag: 'c:yVal',
|
|
79
|
+
mapData: (point) => point.y,
|
|
80
|
+
isStrRef: false,
|
|
81
|
+
});
|
|
158
82
|
});
|
|
83
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
84
|
+
// XmlHelper.dump(chart)
|
|
85
|
+
}; }
|
|
86
|
+
/**
|
|
87
|
+
* Set chart data to modify combo charts.
|
|
88
|
+
* This type is prepared for
|
|
89
|
+
* first series: bar chart (e.g. total)
|
|
90
|
+
* other series: vertical lines
|
|
91
|
+
* See `__tests__/modify-chart-scatter.test.js`
|
|
92
|
+
*/
|
|
93
|
+
static { this.setChartCombo = (data) => (element, chart, workbook) => {
|
|
94
|
+
const slots = [];
|
|
159
95
|
slots.push({
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
type: 'customSeries',
|
|
165
|
-
tag: 'c:bubbleSize',
|
|
166
|
-
mapData: (point) => point.size,
|
|
167
|
-
isStrRef: false,
|
|
96
|
+
index: 0,
|
|
97
|
+
series: data.series[0],
|
|
98
|
+
targetCol: 1,
|
|
99
|
+
type: 'defaultSeries',
|
|
168
100
|
});
|
|
169
|
-
});
|
|
170
|
-
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
171
|
-
// XmlHelper.dump(chart)
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Set chart data to modify extended chart types.
|
|
175
|
-
* See `__tests__/modify-existing-extended-chart.test.js`
|
|
176
|
-
*/
|
|
177
|
-
ModifyChartHelper.setExtendedChartData = (data) => (element, chart, workbook) => {
|
|
178
|
-
const slots = [];
|
|
179
|
-
data.series.forEach((series, s) => {
|
|
180
101
|
slots.push({
|
|
181
|
-
index:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
102
|
+
index: 1,
|
|
103
|
+
label: `Y-Values`,
|
|
104
|
+
mapData: (point, category) => category.y,
|
|
105
|
+
targetCol: 2,
|
|
185
106
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
107
|
+
data.series.forEach((series, s) => {
|
|
108
|
+
if (s > 0)
|
|
109
|
+
slots.push({
|
|
110
|
+
index: s,
|
|
111
|
+
series: series,
|
|
112
|
+
targetCol: s + 2,
|
|
113
|
+
targetYCol: 2,
|
|
114
|
+
type: 'xySeries',
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
118
|
+
ModifyChartHelper.setAxisRange({
|
|
119
|
+
axisIndex: 1,
|
|
120
|
+
min: 0,
|
|
121
|
+
max: data.categories.length,
|
|
122
|
+
})(element, chart);
|
|
123
|
+
}; }
|
|
124
|
+
/**
|
|
125
|
+
* Set chart data to modify bubble charts.
|
|
126
|
+
* See `__tests__/modify-chart-bubbles.test.js`
|
|
127
|
+
*/
|
|
128
|
+
static { this.setChartBubbles = (data) => (element, chart, workbook) => {
|
|
129
|
+
const slots = [];
|
|
130
|
+
data.series.forEach((series, s) => {
|
|
131
|
+
const colId = s * 3;
|
|
132
|
+
slots.push({
|
|
133
|
+
index: s,
|
|
134
|
+
series: series,
|
|
135
|
+
targetCol: colId + 1,
|
|
136
|
+
type: 'customSeries',
|
|
137
|
+
tag: 'c:xVal',
|
|
138
|
+
mapData: (point) => point.x,
|
|
139
|
+
});
|
|
140
|
+
slots.push({
|
|
141
|
+
label: `${series.label}-Y-Value`,
|
|
142
|
+
index: s,
|
|
143
|
+
series: series,
|
|
144
|
+
targetCol: colId + 2,
|
|
145
|
+
type: 'customSeries',
|
|
146
|
+
tag: 'c:yVal',
|
|
147
|
+
mapData: (point) => point.y,
|
|
148
|
+
isStrRef: false,
|
|
149
|
+
});
|
|
150
|
+
slots.push({
|
|
151
|
+
label: `${series.label}-Size`,
|
|
152
|
+
index: s,
|
|
153
|
+
series: series,
|
|
154
|
+
targetCol: colId + 3,
|
|
155
|
+
type: 'customSeries',
|
|
156
|
+
tag: 'c:bubbleSize',
|
|
157
|
+
mapData: (point) => point.size,
|
|
158
|
+
isStrRef: false,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
|
|
162
|
+
// XmlHelper.dump(chart)
|
|
163
|
+
}; }
|
|
164
|
+
/**
|
|
165
|
+
* Set chart data to modify extended chart types.
|
|
166
|
+
* See `__tests__/modify-existing-extended-chart.test.js`
|
|
167
|
+
*/
|
|
168
|
+
static { this.setExtendedChartData = (data) => (element, chart, workbook) => {
|
|
169
|
+
const slots = [];
|
|
170
|
+
data.series.forEach((series, s) => {
|
|
171
|
+
slots.push({
|
|
172
|
+
index: s,
|
|
173
|
+
series: series,
|
|
174
|
+
targetCol: s + 1,
|
|
175
|
+
type: 'extendedSeries',
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
new modify_chart_1.ModifyChart(chart, workbook, data, slots).modifyExtended();
|
|
179
|
+
// XmlHelper.dump(chart);
|
|
180
|
+
// XmlHelper.dump(workbook.table)
|
|
181
|
+
}; }
|
|
182
|
+
/**
|
|
183
|
+
* Read chart workbook data
|
|
184
|
+
* See `__tests__/read-chart-data.test.js`
|
|
185
|
+
*/
|
|
186
|
+
static { this.readWorkbookData = (data) => (element, chart, workbook) => {
|
|
187
|
+
const getSharedString = (index) => {
|
|
188
|
+
return workbook.sharedStrings.getElementsByTagName('si').item(index)
|
|
189
|
+
?.textContent;
|
|
190
|
+
};
|
|
191
|
+
const parseCell = (cell) => {
|
|
192
|
+
const type = cell.getAttribute('t');
|
|
193
|
+
const cellValue = cell.getElementsByTagName('v').item(0).textContent;
|
|
194
|
+
if (type === 's') {
|
|
195
|
+
return getSharedString(Number(cellValue));
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return Number(cellValue);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const rows = workbook.sheet.getElementsByTagName('row');
|
|
202
|
+
for (let r = 0; r < rows.length; r++) {
|
|
203
|
+
const row = rows.item(r);
|
|
204
|
+
const columns = row.getElementsByTagName('c');
|
|
205
|
+
const rowData = [];
|
|
206
|
+
for (let c = 0; c < columns.length; c++) {
|
|
207
|
+
rowData.push(parseCell(columns.item(c)));
|
|
208
|
+
}
|
|
209
|
+
data.push(rowData);
|
|
231
210
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
211
|
+
}; }
|
|
212
|
+
/**
|
|
213
|
+
* Read chart info
|
|
214
|
+
* See `__tests__/read-chart-data.test.js`
|
|
215
|
+
*/
|
|
216
|
+
static { this.readChartInfo = (info) => (element, chart, _workbook) => {
|
|
217
|
+
const series = chart.getElementsByTagName('c:ser');
|
|
218
|
+
xml_helper_1.XmlHelper.modifyCollection(series, (tmpSeries, s) => {
|
|
219
|
+
const solidFill = tmpSeries.getElementsByTagName('a:solidFill').item(0);
|
|
220
|
+
if (!solidFill) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const schemeClr = solidFill.getElementsByTagName('a:schemeClr').item(0);
|
|
224
|
+
const srgbClr = solidFill.getElementsByTagName('a:srgbClr').item(0);
|
|
225
|
+
const colorElement = schemeClr ? schemeClr : srgbClr;
|
|
226
|
+
info.series.push({
|
|
227
|
+
seriesId: s,
|
|
228
|
+
colorType: colorElement.tagName,
|
|
229
|
+
colorValue: colorElement.getAttribute('val'),
|
|
230
|
+
});
|
|
239
231
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
232
|
+
const chartTagName = series.item(0).parentNode.nodeName;
|
|
233
|
+
info.chartType = chartTagName?.split(':')[1];
|
|
234
|
+
}; }
|
|
235
|
+
/**
|
|
236
|
+
* Set range and format for chart axis.
|
|
237
|
+
* Please notice: It will only work if the value to update is not set to
|
|
238
|
+
* "Auto" in powerpoint. Only manually scaled min/max can be altered by this.
|
|
239
|
+
* See `__tests__/modify-chart-axis.test.js`
|
|
240
|
+
*/
|
|
241
|
+
static { this.setAxisRange = (range) => (element, chart) => {
|
|
242
|
+
const axis = chart.getElementsByTagName('c:valAx')[range.axisIndex || 0];
|
|
243
|
+
if (!axis)
|
|
244
|
+
return;
|
|
245
|
+
ModifyChartHelper.setAxisAttribute(axis, 'c:majorUnit', range.majorUnit);
|
|
246
|
+
ModifyChartHelper.setAxisAttribute(axis, 'c:minorUnit', range.minorUnit);
|
|
247
|
+
ModifyChartHelper.setAxisAttribute(axis, 'c:numFmt', range.formatCode, 'formatCode');
|
|
248
|
+
ModifyChartHelper.setAxisAttribute(axis, 'c:numFmt', range.sourceLinked, 'sourceLinked');
|
|
249
|
+
const scaling = axis.getElementsByTagName('c:scaling')[0];
|
|
250
|
+
ModifyChartHelper.setAxisAttribute(scaling, 'c:min', range.min);
|
|
251
|
+
ModifyChartHelper.setAxisAttribute(scaling, 'c:max', range.max);
|
|
252
|
+
}; }
|
|
253
|
+
static { this.setAxisAttribute = (element, tag, value, attribute) => {
|
|
254
|
+
if (value === undefined || !element)
|
|
255
|
+
return;
|
|
256
|
+
const target = element.getElementsByTagName(tag);
|
|
257
|
+
if (target.length > 0) {
|
|
258
|
+
attribute = attribute || 'val';
|
|
259
|
+
if (typeof value === 'boolean') {
|
|
260
|
+
modify_xml_helper_1.default.booleanAttribute(attribute, value)(target[0]);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
modify_xml_helper_1.default.attribute(attribute, value)(target[0]);
|
|
264
|
+
}
|
|
270
265
|
}
|
|
271
|
-
|
|
272
|
-
|
|
266
|
+
}; }
|
|
267
|
+
/**
|
|
268
|
+
* Set legend coordinates to zero. Could be advantageous for pptx users to
|
|
269
|
+
* be able to maximize a legend easily. Legend will still be selectible for
|
|
270
|
+
* a user.
|
|
271
|
+
*/
|
|
272
|
+
static { this.minimizeChartLegend = () => (element, chart, workbook) => {
|
|
273
|
+
this.setLegendPosition({
|
|
274
|
+
w: 0.0,
|
|
275
|
+
h: 0.0,
|
|
276
|
+
x: 0.0,
|
|
277
|
+
y: 0.0,
|
|
278
|
+
})(element, chart, workbook);
|
|
279
|
+
}; }
|
|
280
|
+
/**
|
|
281
|
+
* Completely remove a chart legend. Please notice: This will trigger
|
|
282
|
+
* PowerPoint to automatically maximize chart space.
|
|
283
|
+
*/
|
|
284
|
+
static { this.removeChartLegend = () => (element, chart) => {
|
|
285
|
+
if (chart.getElementsByTagName('c:legend')) {
|
|
286
|
+
xml_helper_1.XmlHelper.remove(chart.getElementsByTagName('c:legend')[0]);
|
|
273
287
|
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
* legendArea coordinates are shares of chart coordinates, e.g.
|
|
301
|
-
* "w: 0.5" means "half of chart width"
|
|
302
|
-
* @param legendArea
|
|
303
|
-
*/
|
|
304
|
-
ModifyChartHelper.setLegendPosition = (legendArea) => (element, chart) => {
|
|
305
|
-
const modifyXmlHelper = new modify_xml_helper_1.default(chart);
|
|
306
|
-
modifyXmlHelper.modify({
|
|
307
|
-
'c:legend': {
|
|
308
|
-
children: {
|
|
309
|
-
'c:manualLayout': {
|
|
310
|
-
children: {
|
|
311
|
-
'c:w': {
|
|
312
|
-
modify: [modify_xml_helper_1.default.attribute('val', legendArea.w)],
|
|
313
|
-
},
|
|
314
|
-
'c:h': {
|
|
315
|
-
modify: [modify_xml_helper_1.default.attribute('val', legendArea.h)],
|
|
316
|
-
},
|
|
317
|
-
'c:x': {
|
|
318
|
-
modify: [modify_xml_helper_1.default.attribute('val', legendArea.x)],
|
|
319
|
-
},
|
|
320
|
-
'c:y': {
|
|
321
|
-
modify: [modify_xml_helper_1.default.attribute('val', legendArea.y)],
|
|
288
|
+
}; }
|
|
289
|
+
/**
|
|
290
|
+
* Update the coordinates of a chart legend.
|
|
291
|
+
* legendArea coordinates are shares of chart coordinates, e.g.
|
|
292
|
+
* "w: 0.5" means "half of chart width"
|
|
293
|
+
* @param legendArea
|
|
294
|
+
*/
|
|
295
|
+
static { this.setLegendPosition = (legendArea) => (element, chart) => {
|
|
296
|
+
const modifyXmlHelper = new modify_xml_helper_1.default(chart);
|
|
297
|
+
modifyXmlHelper.modify({
|
|
298
|
+
'c:legend': {
|
|
299
|
+
children: {
|
|
300
|
+
'c:manualLayout': {
|
|
301
|
+
children: {
|
|
302
|
+
'c:w': {
|
|
303
|
+
modify: [modify_xml_helper_1.default.attribute('val', legendArea.w)],
|
|
304
|
+
},
|
|
305
|
+
'c:h': {
|
|
306
|
+
modify: [modify_xml_helper_1.default.attribute('val', legendArea.h)],
|
|
307
|
+
},
|
|
308
|
+
'c:x': {
|
|
309
|
+
modify: [modify_xml_helper_1.default.attribute('val', legendArea.x)],
|
|
310
|
+
},
|
|
311
|
+
'c:y': {
|
|
312
|
+
modify: [modify_xml_helper_1.default.attribute('val', legendArea.y)],
|
|
313
|
+
},
|
|
322
314
|
},
|
|
323
315
|
},
|
|
324
316
|
},
|
|
325
317
|
},
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
318
|
+
});
|
|
319
|
+
// XmlHelper.dump(chart.getElementsByTagName('c:legendPos')[0]);
|
|
320
|
+
}; }
|
|
321
|
+
/**
|
|
322
|
+
* Set the plot area coordinates of a chart.
|
|
323
|
+
*
|
|
324
|
+
* This modifier requires a 'c:manualLayout' element. It will only appear if
|
|
325
|
+
* plot area coordinates are edited manually in ppt before. Recently fresh
|
|
326
|
+
* created charts will not have a manualLayout by default.
|
|
327
|
+
*
|
|
328
|
+
* This is especially useful if you have problems with edgy elements on a
|
|
329
|
+
* chart area that do not fit into the given space, e.g. when having a lot
|
|
330
|
+
* of data labels. You can increase the chart and decrease the plot area
|
|
331
|
+
* to create a margin.
|
|
332
|
+
*
|
|
333
|
+
* plotArea coordinates are shares of chart coordinates, e.g.
|
|
334
|
+
* "w: 0.5" means "half of chart width"
|
|
335
|
+
*
|
|
336
|
+
* @param plotArea
|
|
337
|
+
*/
|
|
338
|
+
static { this.setPlotArea = (plotArea) => (element, chart) => {
|
|
339
|
+
// Each chart has a separate chart xml file. It is required
|
|
340
|
+
// to alter everything that's "inside" the chart, e.g. data, legend,
|
|
341
|
+
// axis... and: plot area
|
|
342
|
+
// ModifyXmlHelper class provides a lot of functions to access
|
|
343
|
+
// and edit xml elements.
|
|
344
|
+
const modifyXmlHelper = new modify_xml_helper_1.default(chart);
|
|
345
|
+
// We need to locate the required xml elements and target them
|
|
346
|
+
// with ModifyXmlHelper's help.
|
|
347
|
+
// We can therefore log the entire chart.xml to console:
|
|
348
|
+
// XmlHelper.dump(chart);
|
|
349
|
+
// There needs to be a 'c:manualLayout' element. This will only appear if
|
|
350
|
+
// a plot area was edited manually in ppt before. Recently fresh created
|
|
351
|
+
// charts will not have a manualLayout by default.
|
|
352
|
+
if (!chart
|
|
353
|
+
.getElementsByTagName('c:plotArea')[0]
|
|
354
|
+
.getElementsByTagName('c:manualLayout')[0]) {
|
|
355
|
+
logger_1.log.error("Can't update plot area. No c:manualLayout found.");
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
modifyXmlHelper.modify({
|
|
359
|
+
'c:plotArea': {
|
|
360
|
+
children: {
|
|
361
|
+
'c:manualLayout': {
|
|
362
|
+
children: {
|
|
363
|
+
'c:w': {
|
|
364
|
+
// Finally, we attach ModifyCallbacks to all
|
|
365
|
+
// matching elements
|
|
366
|
+
modify: [
|
|
367
|
+
modify_xml_helper_1.default.attribute('val', plotArea.w),
|
|
368
|
+
// ...
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
'c:h': {
|
|
372
|
+
modify: [modify_xml_helper_1.default.attribute('val', plotArea.h)],
|
|
373
|
+
},
|
|
374
|
+
'c:x': {
|
|
375
|
+
modify: [modify_xml_helper_1.default.attribute('val', plotArea.x)],
|
|
376
|
+
},
|
|
377
|
+
'c:y': {
|
|
378
|
+
modify: [modify_xml_helper_1.default.attribute('val', plotArea.y)],
|
|
379
|
+
},
|
|
388
380
|
},
|
|
389
381
|
},
|
|
390
382
|
},
|
|
391
383
|
},
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
384
|
+
});
|
|
385
|
+
// We can dump the target node and see if our modification
|
|
386
|
+
// took effect.
|
|
387
|
+
// XmlHelper.dump(
|
|
388
|
+
// chart
|
|
389
|
+
// .getElementsByTagName('c:plotArea')[0]
|
|
390
|
+
// .getElementsByTagName('c:manualLayout')[0],
|
|
391
|
+
// );
|
|
392
|
+
// You can also take a look at element xml, which is a child node
|
|
393
|
+
// of current slide. It holds general shape properties, but no
|
|
394
|
+
// data or so.
|
|
395
|
+
// XmlHelper.dump(chart);
|
|
396
|
+
// Rough ones might also want to look inside the linked workbook.
|
|
397
|
+
// It is located inside an extra xlsx file. We don't need this
|
|
398
|
+
// for now.
|
|
399
|
+
// XmlHelper.dump(workbook.table)
|
|
400
|
+
// XmlHelper.dump(workbook.sheet)
|
|
401
|
+
}; }
|
|
402
|
+
/**
|
|
403
|
+
* Set a waterfall Total column to last
|
|
404
|
+
* you may also optionally specify a different index.
|
|
405
|
+
@param TotalColumnIDX
|
|
406
|
+
*
|
|
407
|
+
*/
|
|
408
|
+
static { this.setWaterFallColumnTotalToLast = (TotalColumnIDX) => (element, chart) => {
|
|
409
|
+
const plotArea = chart.getElementsByTagName('cx:plotArea')[0];
|
|
410
|
+
const subTotals = plotArea
|
|
411
|
+
?.getElementsByTagName('cx:layoutPr')[0]
|
|
412
|
+
?.getElementsByTagName('cx:subtotals')[0];
|
|
413
|
+
if (subTotals) {
|
|
414
|
+
if (!TotalColumnIDX) {
|
|
415
|
+
const GetTotalPoints = chart
|
|
416
|
+
.getElementsByTagName('cx:chartData')[0]
|
|
417
|
+
?.getElementsByTagName('cx:data')[0]
|
|
418
|
+
?.getElementsByTagName('cx:strDim')[0]
|
|
419
|
+
?.getElementsByTagName('cx:lvl')[0]
|
|
420
|
+
?.getAttribute('ptCount');
|
|
421
|
+
if (GetTotalPoints) {
|
|
422
|
+
TotalColumnIDX = Number(GetTotalPoints) - 1;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (TotalColumnIDX !== undefined) {
|
|
426
|
+
const stIndexes = Array.from(subTotals.getElementsByTagName('cx:idx'));
|
|
427
|
+
stIndexes.forEach((sTValue, index) => {
|
|
428
|
+
modify_xml_helper_1.default.attribute('val', TotalColumnIDX.toString())(sTValue);
|
|
429
|
+
if (index > 0) {
|
|
430
|
+
subTotals.removeChild(sTValue);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
427
433
|
}
|
|
428
434
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
+
}; }
|
|
436
|
+
/**
|
|
437
|
+
* Set the title of a chart. This requires an already existing, manually edited chart title.
|
|
438
|
+
@param newTitle
|
|
439
|
+
*
|
|
440
|
+
*/
|
|
441
|
+
static { this.setChartTitle = (newTitle) => (element, chart) => {
|
|
442
|
+
const chartTitle = chart.getElementsByTagName('c:title').item(0);
|
|
443
|
+
const chartTitleText = chartTitle?.getElementsByTagName('a:t').item(0);
|
|
444
|
+
if (chartTitleText) {
|
|
445
|
+
chartTitleText.textContent = xml_helper_1.XmlHelper.sanitizeText(newTitle);
|
|
446
|
+
}
|
|
447
|
+
}; }
|
|
448
|
+
/**
|
|
449
|
+
* Remove datalabels of a chart.
|
|
450
|
+
*/
|
|
451
|
+
static { this.removeDataLabels = () => (element, chart) => {
|
|
452
|
+
const dLbls = chart.getElementsByTagName('c:dLbls');
|
|
453
|
+
Array.from(dLbls).forEach((dLbl) => {
|
|
454
|
+
dLbl.parentNode.removeChild(dLbl);
|
|
455
|
+
});
|
|
456
|
+
}; }
|
|
457
|
+
static { this.setPointLabelSuffix = (element, idx, labelStyle) => {
|
|
458
|
+
const doc = element.ownerDocument;
|
|
459
|
+
// Convert c:txPr to c:tx > c:rich so PowerPoint renders text runs.
|
|
460
|
+
const txPr = element.getElementsByTagName('c:txPr')[0];
|
|
461
|
+
if (txPr) {
|
|
462
|
+
const tx = doc.createElement('c:tx');
|
|
463
|
+
const rich = doc.createElement('c:rich');
|
|
464
|
+
while (txPr.firstChild) {
|
|
465
|
+
rich.appendChild(txPr.firstChild);
|
|
466
|
+
}
|
|
467
|
+
tx.appendChild(rich);
|
|
468
|
+
txPr.parentNode.insertBefore(tx, txPr);
|
|
469
|
+
txPr.parentNode.removeChild(txPr);
|
|
470
|
+
}
|
|
471
|
+
const paragraphs = element.getElementsByTagName('a:p');
|
|
472
|
+
if (!paragraphs.length)
|
|
473
|
+
return;
|
|
474
|
+
const p = paragraphs[0];
|
|
475
|
+
// Remove any existing a:r and a:fld elements that may have been
|
|
476
|
+
// carried over from cloning a previously modified c:dLbl.
|
|
477
|
+
const existingRuns = Array.from(p.getElementsByTagName('a:r'));
|
|
478
|
+
existingRuns.forEach((run) => run.parentNode.removeChild(run));
|
|
479
|
+
const existingFlds = Array.from(p.getElementsByTagName('a:fld'));
|
|
480
|
+
existingFlds.forEach((fld) => fld.parentNode.removeChild(fld));
|
|
481
|
+
// Add a:fld element to display the chart value
|
|
482
|
+
const endParaRPr = p.getElementsByTagName('a:endParaRPr')[0];
|
|
483
|
+
const defRPr = p.getElementsByTagName('a:defRPr')[0];
|
|
484
|
+
const fld = doc.createElement('a:fld');
|
|
485
|
+
fld.setAttribute('type', 'VALUE');
|
|
486
|
+
fld.setAttribute('id', '{AABBCCDD-1234-5678-9012-' + String(idx).padStart(12, '0') + '}');
|
|
487
|
+
const fldRPr = doc.createElement('a:rPr');
|
|
488
|
+
fldRPr.setAttribute('lang', 'en-US');
|
|
489
|
+
if (defRPr) {
|
|
490
|
+
Array.from(defRPr.childNodes).forEach((child) => {
|
|
491
|
+
fldRPr.appendChild(child.cloneNode(true));
|
|
492
|
+
});
|
|
493
|
+
Array.from(defRPr.attributes).forEach((attr) => {
|
|
494
|
+
if (attr.name !== 'sz' && attr.name !== 'b') {
|
|
495
|
+
fldRPr.setAttribute(attr.name, attr.value);
|
|
435
496
|
}
|
|
436
497
|
});
|
|
437
498
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
*/
|
|
445
|
-
ModifyChartHelper.setChartTitle = (newTitle) => (element, chart) => {
|
|
446
|
-
const chartTitle = chart.getElementsByTagName('c:title').item(0);
|
|
447
|
-
const chartTitleText = chartTitle === null || chartTitle === void 0 ? void 0 : chartTitle.getElementsByTagName('a:t').item(0);
|
|
448
|
-
if (chartTitleText) {
|
|
449
|
-
chartTitleText.textContent = xml_helper_1.XmlHelper.sanitizeText(newTitle);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
/**
|
|
453
|
-
* Remove datalabels of a chart.
|
|
454
|
-
*/
|
|
455
|
-
ModifyChartHelper.removeDataLabels = () => (element, chart) => {
|
|
456
|
-
const dLbls = chart.getElementsByTagName('c:dLbls');
|
|
457
|
-
Array.from(dLbls).forEach((dLbl) => {
|
|
458
|
-
dLbl.parentNode.removeChild(dLbl);
|
|
459
|
-
});
|
|
460
|
-
};
|
|
461
|
-
ModifyChartHelper.setPointLabelSuffix = (element, idx, labelStyle) => {
|
|
462
|
-
const doc = element.ownerDocument;
|
|
463
|
-
// Convert c:txPr to c:tx > c:rich so PowerPoint renders text runs.
|
|
464
|
-
const txPr = element.getElementsByTagName('c:txPr')[0];
|
|
465
|
-
if (txPr) {
|
|
466
|
-
const tx = doc.createElement('c:tx');
|
|
467
|
-
const rich = doc.createElement('c:rich');
|
|
468
|
-
while (txPr.firstChild) {
|
|
469
|
-
rich.appendChild(txPr.firstChild);
|
|
499
|
+
fld.appendChild(fldRPr);
|
|
500
|
+
const fldT = doc.createElement('a:t');
|
|
501
|
+
fldT.textContent = '[VALUE]';
|
|
502
|
+
fld.appendChild(fldT);
|
|
503
|
+
if (endParaRPr) {
|
|
504
|
+
p.insertBefore(fld, endParaRPr);
|
|
470
505
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
txPr.parentNode.removeChild(txPr);
|
|
474
|
-
}
|
|
475
|
-
const paragraphs = element.getElementsByTagName('a:p');
|
|
476
|
-
if (!paragraphs.length)
|
|
477
|
-
return;
|
|
478
|
-
const p = paragraphs[0];
|
|
479
|
-
// Remove any existing a:r and a:fld elements that may have been
|
|
480
|
-
// carried over from cloning a previously modified c:dLbl.
|
|
481
|
-
const existingRuns = Array.from(p.getElementsByTagName('a:r'));
|
|
482
|
-
existingRuns.forEach((run) => run.parentNode.removeChild(run));
|
|
483
|
-
const existingFlds = Array.from(p.getElementsByTagName('a:fld'));
|
|
484
|
-
existingFlds.forEach((fld) => fld.parentNode.removeChild(fld));
|
|
485
|
-
// Add a:fld element to display the chart value
|
|
486
|
-
const endParaRPr = p.getElementsByTagName('a:endParaRPr')[0];
|
|
487
|
-
const defRPr = p.getElementsByTagName('a:defRPr')[0];
|
|
488
|
-
const fld = doc.createElement('a:fld');
|
|
489
|
-
fld.setAttribute('type', 'VALUE');
|
|
490
|
-
fld.setAttribute('id', '{AABBCCDD-1234-5678-9012-' + String(idx).padStart(12, '0') + '}');
|
|
491
|
-
const fldRPr = doc.createElement('a:rPr');
|
|
492
|
-
fldRPr.setAttribute('lang', 'en-US');
|
|
493
|
-
if (defRPr) {
|
|
494
|
-
Array.from(defRPr.childNodes).forEach((child) => {
|
|
495
|
-
fldRPr.appendChild(child.cloneNode(true));
|
|
496
|
-
});
|
|
497
|
-
Array.from(defRPr.attributes).forEach((attr) => {
|
|
498
|
-
if (attr.name !== 'sz' && attr.name !== 'b') {
|
|
499
|
-
fldRPr.setAttribute(attr.name, attr.value);
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
fld.appendChild(fldRPr);
|
|
504
|
-
const fldT = doc.createElement('a:t');
|
|
505
|
-
fldT.textContent = '[VALUE]';
|
|
506
|
-
fld.appendChild(fldT);
|
|
507
|
-
if (endParaRPr) {
|
|
508
|
-
p.insertBefore(fld, endParaRPr);
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
p.appendChild(fld);
|
|
512
|
-
}
|
|
513
|
-
// Add the suffix a:r
|
|
514
|
-
const r = doc.createElement('a:r');
|
|
515
|
-
const rPr = doc.createElement('a:rPr');
|
|
516
|
-
rPr.setAttribute('lang', 'en-US');
|
|
517
|
-
rPr.setAttribute('dirty', '0');
|
|
518
|
-
if (labelStyle.suffix.color) {
|
|
519
|
-
const color = Object.assign({}, labelStyle.suffix.color);
|
|
520
|
-
if (color.value.indexOf('#') === 0) {
|
|
521
|
-
color.value = color.value.replace('#', '');
|
|
506
|
+
else {
|
|
507
|
+
p.appendChild(fld);
|
|
522
508
|
}
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
rPr.
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
r.appendChild(t);
|
|
533
|
-
const endParaRPr2 = p.getElementsByTagName('a:endParaRPr')[0];
|
|
534
|
-
if (endParaRPr2) {
|
|
535
|
-
p.insertBefore(r, endParaRPr2);
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
p.appendChild(r);
|
|
539
|
-
}
|
|
540
|
-
// Prevent line breaks in the data label by setting wrap="none"
|
|
541
|
-
const bodyPrs = element.getElementsByTagName('a:bodyPr');
|
|
542
|
-
if (bodyPrs.length) {
|
|
543
|
-
bodyPrs[0].setAttribute('wrap', 'none');
|
|
544
|
-
}
|
|
545
|
-
// Preserve the number format of the datalabel if it exists in the series or the current label.
|
|
546
|
-
// If it's missing in the current c:dLbl, look into the parent c:dLbls.
|
|
547
|
-
if (!element.getElementsByTagName('c:numFmt').length) {
|
|
548
|
-
const dLbls = element.parentNode;
|
|
549
|
-
if (dLbls && dLbls.nodeName === 'c:dLbls') {
|
|
550
|
-
const numFmt = dLbls.getElementsByTagName('c:numFmt')[0];
|
|
551
|
-
if (numFmt) {
|
|
552
|
-
element.insertBefore(numFmt.cloneNode(true), element.firstChild);
|
|
509
|
+
// Add the suffix a:r
|
|
510
|
+
const r = doc.createElement('a:r');
|
|
511
|
+
const rPr = doc.createElement('a:rPr');
|
|
512
|
+
rPr.setAttribute('lang', 'en-US');
|
|
513
|
+
rPr.setAttribute('dirty', '0');
|
|
514
|
+
if (labelStyle.suffix.color) {
|
|
515
|
+
const color = { ...labelStyle.suffix.color };
|
|
516
|
+
if (color.value.indexOf('#') === 0) {
|
|
517
|
+
color.value = color.value.replace('#', '');
|
|
553
518
|
}
|
|
519
|
+
const solidFill = doc.createElement('a:solidFill');
|
|
520
|
+
const colorEl = doc.createElement('a:' + color.type);
|
|
521
|
+
colorEl.setAttribute('val', color.value);
|
|
522
|
+
solidFill.appendChild(colorEl);
|
|
523
|
+
rPr.appendChild(solidFill);
|
|
554
524
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
ModifyChartHelper.setDataLabelAttributes = (dataLabel) => (element, chart) => {
|
|
563
|
-
const modifyXmlHelper = new modify_xml_helper_1.default(chart);
|
|
564
|
-
const applyToSeries = typeof dataLabel.applyToSeries === 'number'
|
|
565
|
-
? {
|
|
566
|
-
index: dataLabel.applyToSeries,
|
|
525
|
+
r.appendChild(rPr);
|
|
526
|
+
const t = doc.createElement('a:t');
|
|
527
|
+
t.textContent = labelStyle.suffix.text;
|
|
528
|
+
r.appendChild(t);
|
|
529
|
+
const endParaRPr2 = p.getElementsByTagName('a:endParaRPr')[0];
|
|
530
|
+
if (endParaRPr2) {
|
|
531
|
+
p.insertBefore(r, endParaRPr2);
|
|
567
532
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
'
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
533
|
+
else {
|
|
534
|
+
p.appendChild(r);
|
|
535
|
+
}
|
|
536
|
+
// Prevent line breaks in the data label by setting wrap="none"
|
|
537
|
+
const bodyPrs = element.getElementsByTagName('a:bodyPr');
|
|
538
|
+
if (bodyPrs.length) {
|
|
539
|
+
bodyPrs[0].setAttribute('wrap', 'none');
|
|
540
|
+
}
|
|
541
|
+
// Preserve the number format of the datalabel if it exists in the series or the current label.
|
|
542
|
+
// If it's missing in the current c:dLbl, look into the parent c:dLbls.
|
|
543
|
+
if (!element.getElementsByTagName('c:numFmt').length) {
|
|
544
|
+
const dLbls = element.parentNode;
|
|
545
|
+
if (dLbls && dLbls.nodeName === 'c:dLbls') {
|
|
546
|
+
const numFmt = dLbls.getElementsByTagName('c:numFmt')[0];
|
|
547
|
+
if (numFmt) {
|
|
548
|
+
element.insertBefore(numFmt.cloneNode(true), element.firstChild);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}; }
|
|
553
|
+
/**
|
|
554
|
+
* Specify a format for DataLabels
|
|
555
|
+
@param dataLabel
|
|
556
|
+
*
|
|
557
|
+
*/
|
|
558
|
+
static { this.setDataLabelAttributes = (dataLabel) => (element, chart) => {
|
|
559
|
+
const modifyXmlHelper = new modify_xml_helper_1.default(chart);
|
|
560
|
+
const applyToSeries = typeof dataLabel.applyToSeries === 'number'
|
|
561
|
+
? {
|
|
562
|
+
index: dataLabel.applyToSeries,
|
|
563
|
+
}
|
|
564
|
+
: {
|
|
565
|
+
all: true,
|
|
566
|
+
};
|
|
567
|
+
modifyXmlHelper.modify({
|
|
568
|
+
'c:ser': {
|
|
569
|
+
...applyToSeries,
|
|
570
|
+
children: {
|
|
571
|
+
'c:dLbls': {
|
|
572
|
+
// Modify label attributes only where the template carries
|
|
573
|
+
// labels — never fabricate a c:dLbls into a series.
|
|
574
|
+
isRequired: false,
|
|
575
|
+
children: ModifyChartHelper.setDataPointLabelAttributes(dataLabel),
|
|
576
|
+
},
|
|
578
577
|
},
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
};
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
}; }
|
|
581
|
+
static { this.setDataPointLabelAttributes = (dataLabel) => {
|
|
582
|
+
return {
|
|
583
|
+
'c:spPr': {
|
|
584
|
+
isRequired: false,
|
|
585
|
+
modify: [modify_color_helper_1.default.solidFill(dataLabel.solidFill)],
|
|
586
|
+
},
|
|
587
|
+
'c:numFmt': {
|
|
588
|
+
isRequired: false,
|
|
589
|
+
modify: [
|
|
590
|
+
modify_xml_helper_1.default.attribute('formatCode', dataLabel.formatCode),
|
|
591
|
+
modify_xml_helper_1.default.booleanAttribute('sourceLinked', dataLabel.sourceLinked),
|
|
592
|
+
],
|
|
593
|
+
},
|
|
594
|
+
'c:dLblPos': {
|
|
595
|
+
isRequired: false,
|
|
596
|
+
modify: [modify_xml_helper_1.default.attribute('val', dataLabel.dLblPos)],
|
|
597
|
+
},
|
|
598
|
+
'c:showLegendKey': {
|
|
599
|
+
isRequired: false,
|
|
600
|
+
modify: [
|
|
601
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLegendKey),
|
|
602
|
+
],
|
|
603
|
+
},
|
|
604
|
+
'c:showVal': {
|
|
605
|
+
isRequired: false,
|
|
606
|
+
modify: [modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showVal)],
|
|
607
|
+
},
|
|
608
|
+
'c:showCatName': {
|
|
609
|
+
isRequired: false,
|
|
610
|
+
modify: [
|
|
611
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showCatName),
|
|
612
|
+
],
|
|
613
|
+
},
|
|
614
|
+
'c:showSerName': {
|
|
615
|
+
isRequired: false,
|
|
616
|
+
modify: [
|
|
617
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showSerName),
|
|
618
|
+
],
|
|
619
|
+
},
|
|
620
|
+
'c:showPercent': {
|
|
621
|
+
isRequired: false,
|
|
622
|
+
modify: [
|
|
623
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showPercent),
|
|
624
|
+
],
|
|
625
|
+
},
|
|
626
|
+
'c:showBubbleSize': {
|
|
627
|
+
isRequired: false,
|
|
628
|
+
modify: [
|
|
629
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showBubbleSize),
|
|
630
|
+
],
|
|
631
|
+
},
|
|
632
|
+
'c:showLeaderLines': {
|
|
633
|
+
isRequired: false,
|
|
634
|
+
modify: [
|
|
635
|
+
modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLeaderLines),
|
|
636
|
+
],
|
|
637
|
+
},
|
|
638
|
+
};
|
|
639
|
+
}; }
|
|
640
|
+
// Prevent a "null" from being written to the xml file.
|
|
641
|
+
static parseCellValue(value) {
|
|
642
|
+
if (value === null)
|
|
643
|
+
return '';
|
|
644
|
+
return String(value);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
641
647
|
exports.default = ModifyChartHelper;
|
|
642
648
|
//# sourceMappingURL=modify-chart-helper.js.map
|