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

Single data set with a custom color should not create legends for each category #821

Merged
merged 9 commits into from
Jan 3, 2021
Merged
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
12 changes: 8 additions & 4 deletions demos/common/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ function genSlides_Chart(pptx) {

var arrDataHighVals = [
{
name : 'TEST: getExcelColName',
name : 'Single Data Set',
labels: LETTERS.concat(['AA','AB','AC','AD']),
values: [-5,-3,0,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ]
}
Expand All @@ -1159,7 +1159,8 @@ function genSlides_Chart(pptx) {
catAxisTitleColor: "4286f4",
catAxisTitleFontSize: 14,

chartColors: ['EE1122'],
showLegend: true,
chartColors: ['154384'],
invertedColors: ['0088CC'],

showValAxisTitle: true,
Expand All @@ -1183,7 +1184,7 @@ function genSlides_Chart(pptx) {
pptx.charts.BAR,
[
{
name : 'Labels are Excel Date Values',
name : 'Excel Date Values',
labels: [37987,38018,38047,38078,38108,38139],
values: [20, 30, 10, 25, 15, 5]
}
Expand Down Expand Up @@ -1775,13 +1776,16 @@ function genSlides_Chart(pptx) {
fill: 'f2f9fc',
//catAxisOrientation: 'maxMin',
//valAxisOrientation: 'maxMin',
showLegend: true,
chartColors: ['FF0000','0088CC'],

showValAxisTitle: false,
lineSize: 0,

catAxisTitle : "Data Point Labels",
catAxisTitleColor : "0088CC",
catAxisTitleFontSize: 14,
showCatAxisTitle : true,
showCatAxisTitle : false,

// Data Labels
showLabel : true, // Must be set to true or labels will not be shown
Expand Down
1 change: 0 additions & 1 deletion src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,6 @@ export interface IChartPropsChartBar {
barGapDepthPct?: number
barGapWidthPct?: number
barGrouping?: string
valueBarColors?: string[]
}
export interface IChartPropsChartDoughnut {
dataNoEffects?: boolean
Expand Down
18 changes: 12 additions & 6 deletions src/gen-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,15 @@ function makeChartType(chartType: CHART_NAME, data: OptsChartData[], opts: IChar
strXml += '</c:marker>'
}

// Color chart bars various colors
// Allow users with a single data set to pass their own array of colors (check for this using != ours)
if ((chartType === CHART_TYPE.BAR || chartType === CHART_TYPE.BAR3D) && (data.length === 1 || opts.valueBarColors) && opts.chartColors !== BARCHART_COLORS) {
// Color chart bars various colors when >1 color
// NOTE: `<c:dPt>` created with various colors will change PPT legend by design so each dataPt/color is an legend item!
if (
(chartType === CHART_TYPE.BAR || chartType === CHART_TYPE.BAR3D) &&
data.length === 1 &&
opts.chartColors !== BARCHART_COLORS &&
opts.chartColors.length > 1
) {
// Series Data Point colors
obj.values.forEach((value, index) => {
let arrColors = value < 0 ? opts.invertedColors || opts.chartColors || BARCHART_COLORS : opts.chartColors || []
Expand Down Expand Up @@ -1132,10 +1138,10 @@ function makeChartType(chartType: CHART_NAME, data: OptsChartData[], opts: IChar

// Color bar chart bars various colors
// Allow users with a single data set to pass their own array of colors (check for this using != ours)
if ((data.length === 1 || opts.valueBarColors) && opts.chartColors !== BARCHART_COLORS) {
if (data.length === 1 && opts.chartColors !== BARCHART_COLORS) {
// Series Data Point colors
obj.values.forEach((value, index) => {
let arrColors = value < 0 ? opts.invertedColors || BARCHART_COLORS : opts.chartColors || []
let arrColors = value < 0 ? opts.invertedColors || opts.chartColors || BARCHART_COLORS : opts.chartColors || []

strXml += ' <c:dPt>'
strXml += ' <c:idx val="' + index + '"/>'
Expand Down Expand Up @@ -1591,7 +1597,7 @@ function makeCatAxis(opts: IChartOptsLib, axisId: string, valAxisId: string): st
strXml += ' <c:spPr>'
strXml += ' <a:ln w="' + (opts.catAxisLineSize ? valToPts(opts.catAxisLineSize) : ONEPT) + '" cap="flat">'
strXml += opts.catAxisLineShow === false ? '<a:noFill/>' : '<a:solidFill><a:srgbClr val="' + (opts.catAxisLineColor || DEF_CHART_GRIDLINE.color) + '"/></a:solidFill>'
strXml += ' <a:prstDash val="' + (opts.catAxisLineStyle || "solid") + '"/>'
strXml += ' <a:prstDash val="' + (opts.catAxisLineStyle || 'solid') + '"/>'
strXml += ' <a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
Expand Down Expand Up @@ -1693,7 +1699,7 @@ function makeValAxis(opts: IChartOptsLib, valAxisId: string): string {
strXml += ' <c:spPr>'
strXml += ' <a:ln w="' + (opts.valAxisLineSize ? valToPts(opts.valAxisLineSize) : ONEPT) + '" cap="flat">'
strXml += opts.valAxisLineShow === false ? '<a:noFill/>' : '<a:solidFill><a:srgbClr val="' + (opts.valAxisLineColor || DEF_CHART_GRIDLINE.color) + '"/></a:solidFill>'
strXml += ' <a:prstDash val="' + (opts.valAxisLineStyle || "solid") + '"/>'
strXml += ' <a:prstDash val="' + (opts.valAxisLineStyle || 'solid') + '"/>'
strXml += ' <a:round/>'
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
Expand Down
1 change: 0 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,6 @@ declare namespace PptxGenJS {
barGapDepthPct?: number
barGapWidthPct?: number
barGrouping?: string
valueBarColors?: string[]
}
export interface IChartPropsChartDoughnut {
dataNoEffects?: boolean
Expand Down