Skip to content

Commit 2067bc7

Browse files
committed
fix(chart): add support for user shapes in charts (drawings)
1 parent 84038fa commit 2067bc7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/shapes/chart.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class Chart extends Shape implements IChart {
2929
wbEmbeddingsPath: string;
3030
wbExtension: string;
3131
relTypeChartColorStyle: string;
32+
relTypeChartUserShapes: string;
3233
relTypeChartStyle: string;
3334
relTypeChartImage: string;
3435
relTypeChartThemeOverride: string;
@@ -63,6 +64,8 @@ export class Chart extends Shape implements IChart {
6364
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image';
6465
this.relTypeChartThemeOverride =
6566
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/themeOverride';
67+
this.relTypeChartUserShapes =
68+
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartUserShapes';
6669
this.styleRelationFiles = {};
6770
this.hasWorkbook = true;
6871
}
@@ -258,6 +261,7 @@ export class Chart extends Shape implements IChart {
258261

259262
async appendTypes(): Promise<void> {
260263
await this.appendChartExtensionToContentType();
264+
await this.appendChartUserShapesToContentType();
261265
await this.appendChartToContentType();
262266
await this.appendColorToContentType();
263267
await this.appendStyleToContentType();
@@ -315,6 +319,21 @@ export class Chart extends Shape implements IChart {
315319
}
316320
}
317321

322+
if (this.styleRelationFiles.relTypeChartUserShapes?.length) {
323+
const sourceFile =
324+
this.styleRelationFiles.relTypeChartUserShapes[0].replace(
325+
'../drawings/',
326+
'',
327+
);
328+
329+
await FileHelper.zipCopy(
330+
this.sourceArchive,
331+
`ppt/drawings/${sourceFile}`,
332+
this.targetArchive,
333+
`ppt/drawings/drawing${this.targetNumber}.xml`,
334+
);
335+
}
336+
318337
if (this.styleRelationFiles.relTypeChartThemeOverride?.length) {
319338
const sourceFile =
320339
this.styleRelationFiles.relTypeChartThemeOverride[0].replace(
@@ -336,6 +355,7 @@ export class Chart extends Shape implements IChart {
336355
'relTypeChartColorStyle',
337356
'relTypeChartImage',
338357
'relTypeChartThemeOverride',
358+
'relTypeChartUserShapes',
339359
];
340360

341361
for (const i in styleTypes) {
@@ -533,6 +553,15 @@ export class Chart extends Shape implements IChart {
533553
);
534554
}
535555

556+
appendChartUserShapesToContentType(): Promise<XmlElement> {
557+
return XmlHelper.append(
558+
XmlHelper.createContentTypeChild(this.targetArchive, {
559+
PartName: `/ppt/drawings/drawing${this.targetNumber}.xml`,
560+
ContentType: `application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml`,
561+
}),
562+
);
563+
}
564+
536565
static async getAllOnSlide(
537566
archive: IArchive,
538567
relsPath: string,

0 commit comments

Comments
 (0)