Skip to content

Commit

Permalink
feat(chart): modifiy cahrt series datalabel solidFill color
Browse files Browse the repository at this point in the history
  • Loading branch information
singerla committed Dec 18, 2024
1 parent 7eb8809 commit 3bf517c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
19 changes: 17 additions & 2 deletions __tests__/modify-chart-datalabels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test('modify chart data label.', async () => {

const pres = automizer
.loadRoot(`RootTemplate.pptx`)
.load(`ChartBarsStackedLabels.pptx`, 'charts');
.load(`ChartBarsStackedLabels.pptx`, 'charts')
.load(`ChartLinesVertical.pptx`, 'chartLines');

const DataLabelAttributes = {
dLblPos: LabelPosition.Top,
Expand Down Expand Up @@ -38,7 +39,21 @@ test('modify chart data label.', async () => {
}),
]);
})
.addSlide('chartLines', 1, (slide) => {
slide.modifyElement('DotMatrix', [
modify.setDataLabelAttributes({
dLblPos: LabelPosition.Top,
showLegendKey: true,
showCatName: true,
showSerName: true,
solidFill: {
type: 'srgbClr',
value: '#FF00CC',
},
}),
]);
})
.write(`modify-chart-datalabels.test.pptx`);

expect(result.charts).toBe(4);
expect(result.charts).toBe(6);
});
Binary file modified __tests__/pptx-templates/ChartLinesVertical.pptx
Binary file not shown.
8 changes: 7 additions & 1 deletion src/helper/modify-chart-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import ModifyXmlHelper from './modify-xml-helper';
import { XmlDocument, XmlElement } from '../types/xml-types';
import { XmlHelper } from './xml-helper';
import ModifyColorHelper from './modify-color-helper';

export default class ModifyChartHelper {
/**
Expand Down Expand Up @@ -534,7 +535,7 @@ export default class ModifyChartHelper {

/**
* Set the title of a chart. This requires an already existing, manually edited chart title.
@param newTitle
@param newTitle
*
*/
static setChartTitle =
Expand Down Expand Up @@ -570,6 +571,9 @@ export default class ModifyChartHelper {
children: {
'c:dLbls': {
children: {
'c:spPr': {
modify: [ModifyColorHelper.solidFill(dataLabel.solidFill)],
},
'c:dLblPos': {
modify: [ModifyXmlHelper.attribute('val', dataLabel.dLblPos)],
},
Expand Down Expand Up @@ -631,5 +635,7 @@ export default class ModifyChartHelper {
},
},
});

XmlHelper.dump(chart.getElementsByTagName('c:dLbls').item(0));
};
}
1 change: 1 addition & 0 deletions src/types/chart-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type ChartDataLabelAttributes = {
showPercent?: boolean;
showBubbleSize?: boolean;
showLeaderLines?: boolean;
solidFill?: Color;
};
// Elements inside a chart (e.g. a legend) require shares as coordinates.
// E.g. "w: 0.5" means "half of chart width"
Expand Down

0 comments on commit 3bf517c

Please sign in to comment.