Skip to content

Commit 3bf517c

Browse files
committed
feat(chart): modifiy cahrt series datalabel solidFill color
1 parent 7eb8809 commit 3bf517c

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

__tests__/modify-chart-datalabels.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ test('modify chart data label.', async () => {
88

99
const pres = automizer
1010
.loadRoot(`RootTemplate.pptx`)
11-
.load(`ChartBarsStackedLabels.pptx`, 'charts');
11+
.load(`ChartBarsStackedLabels.pptx`, 'charts')
12+
.load(`ChartLinesVertical.pptx`, 'chartLines');
1213

1314
const DataLabelAttributes = {
1415
dLblPos: LabelPosition.Top,
@@ -38,7 +39,21 @@ test('modify chart data label.', async () => {
3839
}),
3940
]);
4041
})
42+
.addSlide('chartLines', 1, (slide) => {
43+
slide.modifyElement('DotMatrix', [
44+
modify.setDataLabelAttributes({
45+
dLblPos: LabelPosition.Top,
46+
showLegendKey: true,
47+
showCatName: true,
48+
showSerName: true,
49+
solidFill: {
50+
type: 'srgbClr',
51+
value: '#FF00CC',
52+
},
53+
}),
54+
]);
55+
})
4156
.write(`modify-chart-datalabels.test.pptx`);
4257

43-
expect(result.charts).toBe(4);
58+
expect(result.charts).toBe(6);
4459
});
427 Bytes
Binary file not shown.

src/helper/modify-chart-helper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import ModifyXmlHelper from './modify-xml-helper';
1515
import { XmlDocument, XmlElement } from '../types/xml-types';
1616
import { XmlHelper } from './xml-helper';
17+
import ModifyColorHelper from './modify-color-helper';
1718

1819
export default class ModifyChartHelper {
1920
/**
@@ -534,7 +535,7 @@ export default class ModifyChartHelper {
534535

535536
/**
536537
* Set the title of a chart. This requires an already existing, manually edited chart title.
537-
@param newTitle
538+
@param newTitle
538539
*
539540
*/
540541
static setChartTitle =
@@ -570,6 +571,9 @@ export default class ModifyChartHelper {
570571
children: {
571572
'c:dLbls': {
572573
children: {
574+
'c:spPr': {
575+
modify: [ModifyColorHelper.solidFill(dataLabel.solidFill)],
576+
},
573577
'c:dLblPos': {
574578
modify: [ModifyXmlHelper.attribute('val', dataLabel.dLblPos)],
575579
},
@@ -631,5 +635,7 @@ export default class ModifyChartHelper {
631635
},
632636
},
633637
});
638+
639+
XmlHelper.dump(chart.getElementsByTagName('c:dLbls').item(0));
634640
};
635641
}

src/types/chart-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export type ChartDataLabelAttributes = {
9696
showPercent?: boolean;
9797
showBubbleSize?: boolean;
9898
showLeaderLines?: boolean;
99+
solidFill?: Color;
99100
};
100101
// Elements inside a chart (e.g. a legend) require shares as coordinates.
101102
// E.g. "w: 0.5" means "half of chart width"

0 commit comments

Comments
 (0)