Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow modified color theme #1270

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demos/browser/js/pptxgen.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/browser/js/pptxgen.bundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/pptxgen.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pptxgen.bundle.js.map

Large diffs are not rendered by default.

63 changes: 55 additions & 8 deletions dist/pptxgen.cjs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PptxGenJS 3.13.0-beta.0 @ 2023-05-17T03:15:58.384Z */
/* PptxGenJS 3.13.0-beta.2 @ 2023-07-06T07:25:35.514Z */
'use strict';

var JSZip = require('jszip');
Expand Down Expand Up @@ -774,6 +774,49 @@ function componentToHex(c) {
function rgbToHex(r, g, b) {
return (componentToHex(r) + componentToHex(g) + componentToHex(b)).toUpperCase();
}
var percentColorModifiers = [
'alpha',
'alphaMod',
'alphaOff',
'blue',
'blueMod',
'blueOff',
'green',
'greenMod',
'greenOff',
'red',
'redMod',
'redOff',
'hue',
'hueMod',
'hueOff',
'lum',
'lumMod',
'lumOff',
'sat',
'satMod',
'satOff',
'shade',
'tint',
];
var flagColorModifiers = ['comp', 'gray', 'inv', 'gamma'];
function handleModifiedColorProps(color) {
var output = '';
for (var _i = 0, percentColorModifiers_1 = percentColorModifiers; _i < percentColorModifiers_1.length; _i++) {
var modifier = percentColorModifiers_1[_i];
var modifierValue = color[modifier];
if (modifierValue !== undefined) {
output += "<a:".concat(modifier, " val=\"").concat(Math.round(modifierValue * 1000), "\"/>");
}
}
for (var _a = 0, flagColorModifiers_1 = flagColorModifiers; _a < flagColorModifiers_1.length; _a++) {
var modifier = flagColorModifiers_1[_a];
if (color[modifier]) {
output += "<a:".concat(modifier, "/>");
}
}
return output;
}
/** TODO: FUTURE: TODO-4.0:
* @date 2022-04-10
* @tldr this s/b a private method with all current calls switched to `genXmlColorSelection()`
Expand All @@ -787,8 +830,12 @@ function rgbToHex(r, g, b) {
* @param {string} innerElements - additional elements that adjust the color and are enclosed by the color element
* @returns {string} XML string
*/
function createColorElement(colorStr, innerElements) {
function createColorElement(colorInput, innerElements) {
var colorStr = typeof colorInput === 'object' ? colorInput.baseColor : colorInput;
var colorVal = (colorStr || '').replace('#', '');
if (typeof colorInput == 'object') {
innerElements = (innerElements || '') + handleModifiedColorProps(colorInput);
}
if (!REGEX_HEX_COLOR.test(colorVal) &&
colorVal !== SchemeColor.background1 &&
colorVal !== SchemeColor.background2 &&
Expand Down Expand Up @@ -838,6 +885,10 @@ function genXmlColorSelection(props) {
if (props) {
if (typeof props === 'string')
colorVal = props;
else if ('baseColor' in props) {
internalElements = handleModifiedColorProps(props);
colorVal = props.baseColor;
}
else {
if (props.type)
fillType = props.type;
Expand Down Expand Up @@ -3816,15 +3867,11 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC
strXml += '<a:ln><a:noFill/></a:ln>';
}
else if (chartType === CHART_TYPE.BAR) {
strXml += '<a:solidFill>';
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>';
strXml += '</a:solidFill>';
strXml += "<a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), "</a:solidFill>");
}
else {
strXml += '<a:ln>';
strXml += ' <a:solidFill>';
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>';
strXml += ' </a:solidFill>';
strXml += " <a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), " </a:solidFill>");
strXml += '</a:ln>';
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW);
Expand Down
63 changes: 55 additions & 8 deletions dist/pptxgen.es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PptxGenJS 3.13.0-beta.0 @ 2023-05-17T03:15:58.392Z */
/* PptxGenJS 3.13.0-beta.2 @ 2023-07-06T07:25:35.517Z */
import JSZip from 'jszip';

/******************************************************************************
Expand Down Expand Up @@ -768,6 +768,49 @@ function componentToHex(c) {
function rgbToHex(r, g, b) {
return (componentToHex(r) + componentToHex(g) + componentToHex(b)).toUpperCase();
}
var percentColorModifiers = [
'alpha',
'alphaMod',
'alphaOff',
'blue',
'blueMod',
'blueOff',
'green',
'greenMod',
'greenOff',
'red',
'redMod',
'redOff',
'hue',
'hueMod',
'hueOff',
'lum',
'lumMod',
'lumOff',
'sat',
'satMod',
'satOff',
'shade',
'tint',
];
var flagColorModifiers = ['comp', 'gray', 'inv', 'gamma'];
function handleModifiedColorProps(color) {
var output = '';
for (var _i = 0, percentColorModifiers_1 = percentColorModifiers; _i < percentColorModifiers_1.length; _i++) {
var modifier = percentColorModifiers_1[_i];
var modifierValue = color[modifier];
if (modifierValue !== undefined) {
output += "<a:".concat(modifier, " val=\"").concat(Math.round(modifierValue * 1000), "\"/>");
}
}
for (var _a = 0, flagColorModifiers_1 = flagColorModifiers; _a < flagColorModifiers_1.length; _a++) {
var modifier = flagColorModifiers_1[_a];
if (color[modifier]) {
output += "<a:".concat(modifier, "/>");
}
}
return output;
}
/** TODO: FUTURE: TODO-4.0:
* @date 2022-04-10
* @tldr this s/b a private method with all current calls switched to `genXmlColorSelection()`
Expand All @@ -781,8 +824,12 @@ function rgbToHex(r, g, b) {
* @param {string} innerElements - additional elements that adjust the color and are enclosed by the color element
* @returns {string} XML string
*/
function createColorElement(colorStr, innerElements) {
function createColorElement(colorInput, innerElements) {
var colorStr = typeof colorInput === 'object' ? colorInput.baseColor : colorInput;
var colorVal = (colorStr || '').replace('#', '');
if (typeof colorInput == 'object') {
innerElements = (innerElements || '') + handleModifiedColorProps(colorInput);
}
if (!REGEX_HEX_COLOR.test(colorVal) &&
colorVal !== SchemeColor.background1 &&
colorVal !== SchemeColor.background2 &&
Expand Down Expand Up @@ -832,6 +879,10 @@ function genXmlColorSelection(props) {
if (props) {
if (typeof props === 'string')
colorVal = props;
else if ('baseColor' in props) {
internalElements = handleModifiedColorProps(props);
colorVal = props.baseColor;
}
else {
if (props.type)
fillType = props.type;
Expand Down Expand Up @@ -3810,15 +3861,11 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC
strXml += '<a:ln><a:noFill/></a:ln>';
}
else if (chartType === CHART_TYPE.BAR) {
strXml += '<a:solidFill>';
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>';
strXml += '</a:solidFill>';
strXml += "<a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), "</a:solidFill>");
}
else {
strXml += '<a:ln>';
strXml += ' <a:solidFill>';
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>';
strXml += ' </a:solidFill>';
strXml += " <a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), " </a:solidFill>");
strXml += '</a:ln>';
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW);
Expand Down
4 changes: 2 additions & 2 deletions dist/pptxgen.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pptxgen.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pptxgenjs",
"version": "3.13.0-beta.1",
"version": "3.13.0-beta.2",
"author": {
"name": "Brent Ely",
"url": "https://github.com/gitbrent/"
Expand Down
48 changes: 41 additions & 7 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface BackgroundProps extends DataOrPathProps, ShapeFillProps {
* Color (hex format)
* @deprecated v3.6.0 - use `ShapeFillProps` instead
*/
fill?: HexColor
fill?: Color

/**
* source URL
Expand All @@ -84,11 +84,45 @@ export interface BackgroundProps extends DataOrPathProps, ShapeFillProps {
*/
export type HexColor = string
export type ThemeColor = 'tx1' | 'tx2' | 'bg1' | 'bg2' | 'accent1' | 'accent2' | 'accent3' | 'accent4' | 'accent5' | 'accent6'
export type Color = HexColor | ThemeColor
export type Color = HexColor | ThemeColor | ModifiedThemeColor
export type Margin = number | [number, number, number, number]
export type HAlign = 'left' | 'center' | 'right' | 'justify'
export type VAlign = 'top' | 'middle' | 'bottom'

export interface ModifiedThemeColor {
baseColor: HexColor | ThemeColor
/**
* - number 0-100
*/
alpha?: number
alphaMod?: number
alphaOff?: number
blue?: number
blueMod?: number
blueOff?: number
green?: number
greenMod?: number
greenOff?: number
red?: number
redMod?: number
redOff?: number
hue?: number
hueMod?: number
hueOff?: number
lum?: number
lumMod?: number
lumOff?: number
sat?: number
satMod?: number
satOff?: number
shade?: number
tint?: number
comp?: boolean
gray?: boolean
inv?: boolean
gamma?: boolean
}

// used by charts, shape, text
export interface BorderProps {
/**
Expand Down Expand Up @@ -1193,7 +1227,7 @@ export interface OptsChartGridLine {
* Gridline color (hex)
* @example 'FF3399'
*/
color?: HexColor
color?: Color
/**
* Gridline size (points)
*/
Expand Down Expand Up @@ -1237,15 +1271,15 @@ export interface IChartPropsBase {
* Axis position
*/
axisPos?: 'b' | 'l' | 'r' | 't'
chartColors?: HexColor[]
chartColors?: Color[]
/**
* opacity (0 - 100)
* @example 50 // 50% opaque
*/
chartColorsOpacity?: number
dataBorder?: BorderProps
displayBlanksAs?: string
invertedColors?: HexColor[]
invertedColors?: Color[]
lang?: string
layout?: PositionProps
shadow?: ShadowProps
Expand Down Expand Up @@ -1320,7 +1354,7 @@ export interface IChartPropsBase {
/**
* @deprecated v3.11.0 - use `plotArea.fill`
*/
fill?: HexColor
fill?: Color
}
export interface IChartPropsAxisCat {
/**
Expand Down Expand Up @@ -1830,7 +1864,7 @@ export interface PresSlide extends SlideBaseProps {
* @example 'FF3399'
* @default '000000' (DEF_FONT_COLOR)
*/
color?: HexColor
color?: Color
/**
* Whether slide is hidden
* @default false
Expand Down
9 changes: 3 additions & 6 deletions src/gen-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,11 @@ function makeChartType (chartType: CHART_NAME, data: IOptsChartData[], opts: ICh
if (opts.lineSize === 0) {
strXml += '<a:ln><a:noFill/></a:ln>'
} else if (chartType === CHART_TYPE.BAR) {
strXml += '<a:solidFill>'
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>'
strXml += '</a:solidFill>'
strXml += "<a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), "</a:solidFill>");

} else {
strXml += '<a:ln>'
strXml += ' <a:solidFill>'
strXml += ' <a:srgbClr val="' + arrColors[index % arrColors.length] + '"/>'
strXml += ' </a:solidFill>'
strXml += " <a:solidFill>".concat(createColorElement(arrColors[index % arrColors.length]), " </a:solidFill>");
strXml += '</a:ln>'
}
strXml += createShadowElement(opts.shadow, DEF_SHAPE_SHADOW)
Expand Down
Loading