diff --git a/__tests__/modify-chart-datalabels.test.ts b/__tests__/modify-chart-datalabels.test.ts index 2d28449..3cbb79a 100644 --- a/__tests__/modify-chart-datalabels.test.ts +++ b/__tests__/modify-chart-datalabels.test.ts @@ -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, @@ -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); }); diff --git a/__tests__/pptx-templates/ChartLinesVertical.pptx b/__tests__/pptx-templates/ChartLinesVertical.pptx index 2a0988c..ac5071d 100644 Binary files a/__tests__/pptx-templates/ChartLinesVertical.pptx and b/__tests__/pptx-templates/ChartLinesVertical.pptx differ diff --git a/src/helper/modify-chart-helper.ts b/src/helper/modify-chart-helper.ts index 5b35fc3..893c83d 100644 --- a/src/helper/modify-chart-helper.ts +++ b/src/helper/modify-chart-helper.ts @@ -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 { /** @@ -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 = @@ -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)], }, @@ -631,5 +635,7 @@ export default class ModifyChartHelper { }, }, }); + + XmlHelper.dump(chart.getElementsByTagName('c:dLbls').item(0)); }; } diff --git a/src/types/chart-types.ts b/src/types/chart-types.ts index 1455ae3..b08ce0c 100644 --- a/src/types/chart-types.ts +++ b/src/types/chart-types.ts @@ -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"