Skip to content

Commit

Permalink
fixed dataLabelPosition (Issue #644)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbrent committed Jan 17, 2020
1 parent fd72bb8 commit bae7329
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
17 changes: 10 additions & 7 deletions demos/common/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -1635,9 +1635,9 @@ function genSlides_Chart(pptx) {
slide.addTable( [ [{ text:'Chart Examples: XY Scatter Chart', options:gOptsTextL },gOptsTextR] ], gOptsTabOpts );

var arrDataScatter1 = [
{ name:'X-Axis', values:[0,1,2,3,4,5,6,7,8,9] },
{ name:'Y-Value 1', values:[13, 20, 21, 25] },
{ name:'Y-Value 2', values:[21, 22, 25, 49] }
{ name:'X-Axis', values:[0,1,2,3,4,5] },
{ name:'Y-Value 1', values:[90, 80, 70, 85, 75, 92], labels:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] },
{ name:'Y-Value 2', values:[21, 32, 40, 49, 31, 29], labels:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] },
];
var arrDataScatter2 = [
{ name:'X-Axis', values:[1, 2, 3, 4, 5, 6] },
Expand All @@ -1647,8 +1647,8 @@ function genSlides_Chart(pptx) {
];
var arrDataScatterLabels = [
{ name:'X-Axis', values:[1, 10, 20, 30, 40, 50] },
{ name:'Y-Value 1', values:[11, 23, 31, 45], labels:['Red 1', 'Red 2', 'Red 3', 'Red 4'] },
{ name:'Y-Value 2', values:[21, 38, 47, 59], labels:['Blue 1', 'Blue 2', 'Blue 3', 'Blue 4'] }
{ name:'Y-Value 1', values:[11, 23, 31, 45, 47, 35], labels:['Red 1', 'Red 2', 'Red 3', 'Red 4', 'Red 5', 'Red 6'] },
{ name:'Y-Value 2', values:[21, 38, 47, 59, 51, 25], labels:['Blue 1', 'Blue 2', 'Blue 3', 'Blue 4', 'Blue 5', 'Blue 6'] }
];

// TOP-LEFT
Expand All @@ -1658,10 +1658,12 @@ function genSlides_Chart(pptx) {
valAxisTitleFontSize: 14,
showValAxisTitle : true,
lineSize: 0,
catAxisTitle : "Last 10 Months",
catAxisTitle : "Last 6 Months",
catAxisTitleColor : "428442",
catAxisTitleFontSize: 14,
showCatAxisTitle : true
showCatAxisTitle : true,
showLabel : true, // Must be set to true or labels will not be shown
dataLabelPosition : 'b', // Options: 't'|'b'|'l'|'r'|'ctr'
};
slide.addChart( pptx.charts.SCATTER, arrDataScatter1, optsChartScat1 );

Expand Down Expand Up @@ -1696,6 +1698,7 @@ function genSlides_Chart(pptx) {

// Data Labels
showLabel : true, // Must be set to true or labels will not be shown
dataLabelPosition : 'r', // Options: 't'|'b'|'l'|'r'|'ctr'
dataLabelFormatScatter: 'custom', // Can be set to `custom` (default), `customXY`, or `XY`.
};
slide.addChart( pptx.charts.SCATTER, arrDataScatterLabels, optsChartScat3 );
Expand Down
23 changes: 11 additions & 12 deletions src/gen-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' </c:txPr>'
// Setting dLblPos tag for bar3D seems to break the generated chart
if (chartType !== CHART_TYPES.AREA && chartType !== CHART_TYPES.BAR3D) {
strXml += '<c:dLblPos val="' + (opts.dataLabelPosition || 'outEnd') + '"/>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
}
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
Expand Down Expand Up @@ -882,7 +882,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
// NOTE: Throwing an error while creating a multi type chart which contains area chart as the below line appears for the other chart type.
// Either the given change can be made or the below line can be removed to stop the slide containing multi type chart with area to crash.
if (opts.type !== CHART_TYPES.AREA && opts.type !== CHART_TYPES.RADAR && !isMultiTypeChart)
strXml += '<c:dLblPos val="' + (opts.dataLabelPosition || 'outEnd') + '"/>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="0"/>'
Expand Down Expand Up @@ -1059,18 +1059,16 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' </a:ln>'
strXml += ' <a:effectLst/>'
strXml += ' </c:spPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="0"/>'
strXml += ' <c:showCatName val="0"/>'
strXml += ' <c:showSerName val="0"/>'
strXml += ' <c:showPercent val="0"/>'
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' <c:showLeaderLines val="1"/>'
strXml += ' <c:showLeaderLines val="1"/>'
strXml += ' <c:extLst>'
strXml += ' <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">'
strXml += ' <c15:dlblFieldTable/>'
strXml += ' <c15:showDataLabelsRange val="0"/>'
strXml += ' </c:ext>'
strXml += ' <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"/>'
strXml += ' <c:ext uri="{C3380CC4-5D6E-409C-BE32-E72D297353CC}" xmlns:c16="http://schemas.microsoft.com/office/drawing/2014/chart">'
strXml += ' <c16:uniqueId val="{' + '00000000'.substring(0, 8 - (idx + 1).toString().length).toString() + (idx + 1) + chartUuid + '}"/>'
strXml += ' </c:ext>'
Expand Down Expand Up @@ -1101,6 +1099,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' <a:endParaRPr lang="en-US"/>'
strXml += ' </a:p>'
strXml += ' </c:txPr>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ` <c:showVal val="${opts.showLabel ? '1' : '0'}"/>`
strXml += ` <c:showCatName val="${opts.showLabel ? '1' : '0'}"/>`
Expand Down Expand Up @@ -1194,7 +1193,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' </a:defRPr>'
strXml += ' </a:pPr></a:p>'
strXml += ' </c:txPr>'
strXml += ' <c:dLblPos val="' + (opts.dataLabelPosition || 'outEnd') + '"/>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="0"/>'
Expand Down Expand Up @@ -1348,7 +1347,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' </a:defRPr>'
strXml += ' </a:pPr></a:p>'
strXml += ' </c:txPr>'
strXml += ' <c:dLblPos val="ctr"/>'
if (opts.dataLabelPosition) strXml += ' <c:dLblPos val="' + opts.dataLabelPosition + '"/>'
strXml += ' <c:showLegendKey val="0"/>'
strXml += ' <c:showVal val="' + (opts.showValue ? '1' : '0') + '"/>'
strXml += ' <c:showCatName val="0"/>'
Expand Down Expand Up @@ -1442,7 +1441,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
obj.labels.forEach((_label, idx) => {
strXml += '<c:dLbl>'
strXml += ' <c:idx val="' + idx + '"/>'
strXml += ` <c:numFmt formatCode="${opts.dataLabelFormatCode||'General'}" sourceLinked="0"/>`
strXml += ` <c:numFmt formatCode="${opts.dataLabelFormatCode || 'General'}" sourceLinked="0"/>`
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/><a:lstStyle/>'
strXml += ' <a:p><a:pPr>'
Expand All @@ -1464,7 +1463,7 @@ function makeChartType(chartType: CHART_TYPE_NAMES, data: OptsChartData[], opts:
strXml += ' <c:showBubbleSize val="0"/>'
strXml += ' </c:dLbl>'
})
strXml += ` <c:numFmt formatCode="${opts.dataLabelFormatCode||'General'}" sourceLinked="0"/>`
strXml += ` <c:numFmt formatCode="${opts.dataLabelFormatCode || 'General'}" sourceLinked="0"/>`
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr/>'
strXml += ' <a:lstStyle/>'
Expand Down Expand Up @@ -1587,7 +1586,7 @@ function makeCatAxis(opts: IChartOpts, axisId: string, valAxisId: string): strin
strXml += ' </a:ln>'
strXml += ' </c:spPr>'
strXml += ' <c:txPr>'
strXml += ' <a:bodyPr ' + (opts.catAxisLabelRotate ? 'rot="' + convertRotationDegrees(opts.catAxisLabelRotate) + '"' : '') + '/>' // don't specify rot 0 so we get the auto behavior
strXml += ' <a:bodyPr' + (opts.catAxisLabelRotate ? ' rot="' + convertRotationDegrees(opts.catAxisLabelRotate) + '"' : '') + '/>' // don't specify rot 0 so we get the auto behavior
strXml += ' <a:lstStyle/>'
strXml += ' <a:p>'
strXml += ' <a:pPr>'
Expand Down

0 comments on commit bae7329

Please sign in to comment.