Skip to content

Commit 7f04bf8

Browse files
committed
added support for Scheme Colors as dataBorder (Issue #1389)
1 parent cee3aa6 commit 7f04bf8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Border is a string instead of a number in demo_tables.mjs [\#1389](https://github.com/gitbrent/PptxGenJS/issues/1389) ([hesi726](https://github.com/hesi726))
13+
- Fixed support for Scheme Colors as `dataBorder` [\#1389](https://github.com/gitbrent/PptxGenJS/issues/1389) ([hesi726](https://github.com/hesi726))
1314
- Hyperlinks cause "needs repair" when using table auto-paging [\#1392](https://github.com/gitbrent/PptxGenJS/issues/1392) ([gitbrent](https://github.com/gitbrent))
1415

1516
### Changed

demos/modules/demo_chart.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ function genSlide02(pptx) {
251251
valAxisMaxVal: 5000,
252252
valAxisLabelColor: COLORS_ACCENT[0],
253253
//
254-
dataBorder: { pt: 1, color: "F1F1F1" },
254+
//dataBorder: { pt: 1, color: "F1F1F1" },
255+
//dataBorder: { pt: 1, color: pptx.colors.BACKGROUND2 },
256+
dataBorder: { pt: 1, color: pptx.colors.ACCENT1 },
255257
dataLabelColor: "FFFFFF",
256258
dataLabelFontFace: "Arial",
257259
dataLabelFontSize: 10,

src/gen-objects.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
IMG_PLAYBTN,
1818
MASTER_OBJECTS,
1919
PIECHART_COLORS,
20+
SCHEME_COLOR_NAMES,
2021
SHAPE_NAME,
2122
SHAPE_TYPE,
2223
SLIDE_OBJECT_TYPES,
@@ -329,7 +330,13 @@ export function addChartDefinition(target: PresSlide, type: CHART_NAME | IChartM
329330
//
330331
options.dataBorder = options.dataBorder && typeof options.dataBorder === 'object' ? options.dataBorder : null
331332
if (options.dataBorder && (!options.dataBorder.pt || isNaN(options.dataBorder.pt))) options.dataBorder.pt = 0.75
332-
if (options.dataBorder && (!options.dataBorder.color || typeof options.dataBorder.color !== 'string' || options.dataBorder.color.length !== 6)) { options.dataBorder.color = 'F9F9F9' }
333+
if (options.dataBorder && options.dataBorder.color) {
334+
const isHexColor = typeof options.dataBorder.color === 'string' && options.dataBorder.color.length === 6 && /^[0-9A-Fa-f]{6}$/.test(options.dataBorder.color)
335+
const isSchemeColor = Object.values(SCHEME_COLOR_NAMES).includes(options.dataBorder.color as SCHEME_COLOR_NAMES)
336+
if (!isHexColor && !isSchemeColor) {
337+
options.dataBorder.color = 'F9F9F9' // Fallback if neither hex nor scheme color
338+
}
339+
}
333340
//
334341
if (!options.dataLabelFormatCode && options._type === CHART_TYPE.SCATTER) options.dataLabelFormatCode = 'General'
335342
if (!options.dataLabelFormatCode && (options._type === CHART_TYPE.PIE || options._type === CHART_TYPE.DOUGHNUT)) { options.dataLabelFormatCode = options.showPercent ? '0%' : 'General' }

0 commit comments

Comments
 (0)