Skip to content

Commit 431b78a

Browse files
authored
Merge pull request #36 from singerla/bug-extended-chart
Merge pull request #35 from singerla/main
2 parents 643b7d5 + ac38712 commit 431b78a

File tree

5 files changed

+56
-39
lines changed

5 files changed

+56
-39
lines changed

src/classes/shape.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import JSZip from 'jszip';
22

33
import { XmlHelper } from '../helper/xml-helper';
4-
import { GeneralHelper, vd } from '../helper/general-helper';
4+
import { GeneralHelper } from '../helper/general-helper';
55
import {
66
ImportedElement,
77
ShapeModificationCallback,
@@ -132,6 +132,8 @@ export class Shape {
132132
sourceElementOnTargetSlide,
133133
);
134134

135+
// vd(insertBefore);
136+
135137
await XmlHelper.writeXmlToArchive(archive, slideFile, targetSlideXml);
136138
}
137139

src/classes/slide.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
AnalyzedElementType,
77
ImportedElement,
88
ImportElement,
9-
SlideModificationCallback,
109
ShapeModificationCallback,
10+
SlideModificationCallback,
1111
SourceSlideIdentifier,
1212
StatusTracker,
1313
} from '../types/types';
@@ -17,14 +17,14 @@ import { PresTemplate } from '../interfaces/pres-template';
1717
import { RootPresTemplate } from '../interfaces/root-pres-template';
1818
import { ElementType } from '../enums/element-type';
1919
import {
20+
HelperElement,
2021
RelationshipAttribute,
2122
SlideListAttribute,
22-
HelperElement,
2323
} from '../types/xml-types';
2424
import { Image } from '../shapes/image';
2525
import { Chart } from '../shapes/chart';
2626
import { GenericShape } from '../shapes/generic';
27-
import { GeneralHelper, vd } from '../helper/general-helper';
27+
import { vd } from '../helper/general-helper';
2828

2929
export class Slide implements ISlide {
3030
/**
@@ -102,7 +102,11 @@ export class Slide implements ISlide {
102102
* List of unsupported tags in slide xml
103103
* @internal
104104
*/
105-
unsupportedTags = ['p:custDataLst', 'mc:AlternateContent', 'a14:imgProps'];
105+
unsupportedTags = [
106+
'p:custDataLst',
107+
//'mc:AlternateContent',
108+
//'a14:imgProps',
109+
];
106110

107111
constructor(params: {
108112
presentation: IPresentationProps;
@@ -268,11 +272,7 @@ export class Slide implements ISlide {
268272

269273
/**
270274
* Remove a single element from slide.
271-
* @param {string} presName - Filename or alias name of the template presentation.
272-
* Must have been importet with Automizer.load().
273-
* @param {number} slideNumber - Slide number within the specified template to search for the required element.
274-
* @param {ShapeModificationCallback | ShapeModificationCallback[]} callback - One or more callback functions to apply.
275-
* Depending on the shape type (e.g. chart or table), different arguments will be passed to the callback.
275+
* @param {string} selector - Element's name on the slide.
276276
*/
277277
removeElement(selector: string): this {
278278
const presName = this.sourceTemplate.name;

src/dev.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import Automizer, {
2-
ChartData,
3-
modify,
4-
TableRow,
5-
TableRowStyle,
6-
XmlHelper,
7-
} from './index';
8-
import { vd } from './helper/general-helper';
9-
import ModifyPresentationHelper from './helper/modify-presentation-helper';
1+
import Automizer, { ChartData, modify } from './index';
102

113
const automizer = new Automizer({
124
templateDir: `${__dirname}/../__tests__/pptx-templates`,
@@ -59,18 +51,34 @@ const run = async () => {
5951
// }),
6052
// ]);
6153

54+
// slide.modifyElement('Waterfall 1', [
55+
// modify.setExtendedChartData(<ChartData>{
56+
// series: [{ label: 'series 1' }],
57+
// categories: [
58+
// { label: 'cat 2-1', values: [100] },
59+
// { label: 'cat 2-2', values: [20] },
60+
// { label: 'cat 2-3', values: [50] },
61+
// { label: 'cat 2-4', values: [-40] },
62+
// { label: 'cat 2-5', values: [130] },
63+
// { label: 'cat 2-6', values: [-60] },
64+
// { label: 'cat 2-7', values: [70] },
65+
// { label: 'cat 2-8', values: [140] },
66+
// ],
67+
// }),
68+
// ]);
69+
6270
slide.addElement('ChartWaterfall', 1, 'Waterfall 1', [
6371
modify.setExtendedChartData(<ChartData>{
6472
series: [{ label: 'series 1' }],
6573
categories: [
66-
{ label: 'cat 2-1', values: [50] },
67-
{ label: 'cat 2-2', values: [14] },
68-
{ label: 'cat 2-3', values: [15] },
69-
{ label: 'cat 2-4', values: [26] },
70-
{ label: 'cat 2-4', values: [26] },
71-
{ label: 'cat 2-4', values: [26] },
72-
{ label: 'cat 2-4', values: [26] },
73-
{ label: 'cat 2-4', values: [26] },
74+
{ label: 'cat 2-1', values: [100] },
75+
{ label: 'cat 2-2', values: [20] },
76+
{ label: 'cat 2-3', values: [50] },
77+
{ label: 'cat 2-4', values: [-40] },
78+
{ label: 'cat 2-5', values: [130] },
79+
{ label: 'cat 2-6', values: [-60] },
80+
{ label: 'cat 2-7', values: [70] },
81+
{ label: 'cat 2-8', values: [140] },
7482
],
7583
}),
7684
]);

src/helper/modify-chart-helper.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { ModifyChart } from '../modify/modify-chart';
22
import { Workbook } from '../types/types';
33
import {
4-
ChartData,
4+
ChartAxisRange,
55
ChartBubble,
6-
ChartSlot,
76
ChartCategory,
8-
ChartSeries,
7+
ChartData,
98
ChartPoint,
10-
ChartAxisRange,
9+
ChartSeries,
10+
ChartSlot,
1111
} from '../types/chart-types';
12-
import { vd } from './general-helper';
13-
import { XmlHelper } from './xml-helper';
1412
import ModifyXmlHelper from './modify-xml-helper';
1513

1614
export default class ModifyChartHelper {
@@ -229,7 +227,7 @@ export default class ModifyChartHelper {
229227

230228
new ModifyChart(chart, workbook, data, slots).modifyExtended();
231229

232-
XmlHelper.dump(chart);
230+
// XmlHelper.dump(chart);
233231
// XmlHelper.dump(workbook.table)
234232
};
235233

src/shapes/chart.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { XmlHelper } from '../helper/xml-helper';
44
import { Shape } from '../classes/shape';
55
import path from 'path';
66

7-
import { RelationshipAttribute, HelperElement } from '../types/xml-types';
7+
import { HelperElement, RelationshipAttribute } from '../types/xml-types';
88
import { ImportedElement, Target, Workbook } from '../types/types';
99
import { IChart } from '../interfaces/ichart';
1010
import { RootPresTemplate } from '../interfaces/root-pres-template';
11-
import { vd } from '../helper/general-helper';
1211

1312
export class Chart extends Shape implements IChart {
1413
sourceWorksheet: number | string;
@@ -29,8 +28,13 @@ export class Chart extends Shape implements IChart {
2928

3029
this.relRootTag = this.subtype === 'chart' ? 'c:chart' : 'cx:chart';
3130
this.relAttribute = 'r:id';
32-
this.relParent = (element: Element) =>
33-
element.parentNode.parentNode.parentNode as Element;
31+
this.relParent =
32+
this.subtype === 'chart'
33+
? (element: Element) =>
34+
element.parentNode.parentNode.parentNode as Element
35+
: (element: Element) =>
36+
element.parentNode.parentNode.parentNode.parentNode
37+
.parentNode as Element;
3438

3539
this.wbEmbeddingsPath = `../embeddings/`;
3640
this.wbExtension = '.xlsx';
@@ -409,10 +413,15 @@ export class Chart extends Shape implements IChart {
409413
}
410414

411415
appendChartToContentType(): Promise<HelperElement> {
416+
const contentType =
417+
this.subtype === 'chart'
418+
? 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'
419+
: 'application/vnd.ms-office.chartex+xml';
420+
412421
return XmlHelper.append(
413422
XmlHelper.createContentTypeChild(this.targetArchive, {
414423
PartName: `/ppt/charts/${this.subtype}${this.targetNumber}.xml`,
415-
ContentType: `application/vnd.openxmlformats-officedocument.drawingml.chart+xml`,
424+
ContentType: contentType,
416425
}),
417426
);
418427
}

0 commit comments

Comments
 (0)