Skip to content

Commit

Permalink
[FIX] charts: fix combo chart export
Browse files Browse the repository at this point in the history
Task Description

Since the chart customization PR, there is an issue in the combo chart
export where there is a mismatch between the vertical left and right
axes, leading to an wrong axis definition when exporting a combo chart
and a removed chart when loading it to excel.
This commits aims to fix this issue.

Related Task

closes #5018

Task: 4092078
X-original-commit: fbdcb2b
Signed-off-by: Rémi Rahir (rar) <[email protected]>
Signed-off-by: Hendrickx Anthony (anhe) <[email protected]>
  • Loading branch information
anhe-odoo committed Sep 24, 2024
1 parent f1a7866 commit de00e5f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
36 changes: 19 additions & 17 deletions src/xlsx/functions/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ interface LineAttributes {
* The value does not matter, it can be hardcoded.
*/
const catAxId = 17781237;
const secondaryCatAxId = 17781238;
const valAxId = 88853993;
const secondaryValAxId = 88853994;

export function createChart(
chart: FigureData<ExcelChartDefinition>,
Expand Down Expand Up @@ -398,8 +400,8 @@ function addComboChart(chart: ExcelChartDefinition): XMLString {
<!-- each data marker in the series does not have a different color -->
<c:varyColors val="0"/>
${barDataSetNode}
<c:axId val="${catAxId + (useRightAxisForBarSerie ? 1 : 0)}" />
<c:axId val="${valAxId + (useRightAxisForBarSerie ? 1 : 0)}" />
<c:axId val="${useRightAxisForBarSerie ? secondaryCatAxId : catAxId}" />
<c:axId val="${useRightAxisForBarSerie ? secondaryValAxId : valAxId}" />
</c:barChart>
${
leftDataSetsNodes.length
Expand All @@ -423,8 +425,8 @@ function addComboChart(chart: ExcelChartDefinition): XMLString {
<!-- each data marker in the series does not have a different color -->
<c:varyColors val="0"/>
${joinXmlNodes(rightDataSetsNodes)}
<c:axId val="${catAxId + 1}" />
<c:axId val="${valAxId + 1}" />
<c:axId val="${secondaryCatAxId}" />
<c:axId val="${secondaryValAxId}" />
</c:lineChart>
`
: ""
Expand All @@ -435,20 +437,13 @@ function addComboChart(chart: ExcelChartDefinition): XMLString {
${addAx(
"b",
"c:catAx",
catAxId + 1,
valAxId + 1,
catAxId,
valAxId,
chart.axesDesign?.x?.title,
chart.fontColor,
leftDataSetsNodes.length ? 1 : 0
)}
${addAx(
"r",
"c:valAx",
valAxId + 1,
catAxId + 1,
chart.axesDesign?.y1?.title,
chart.fontColor
)}
${addAx("l", "c:valAx", valAxId, catAxId, chart.axesDesign?.y?.title, chart.fontColor)}
`
: ""
}
Expand All @@ -458,13 +453,20 @@ function addComboChart(chart: ExcelChartDefinition): XMLString {
${addAx(
"b",
"c:catAx",
catAxId,
valAxId,
secondaryCatAxId,
secondaryValAxId,
chart.axesDesign?.x?.title,
chart.fontColor,
leftDataSetsNodes.length || !useRightAxisForBarSerie ? 1 : 0
)}
${addAx("l", "c:valAx", valAxId, catAxId, chart.axesDesign?.y?.title, chart.fontColor)}
${addAx(
"r",
"c:valAx",
secondaryValAxId,
secondaryCatAxId,
chart.axesDesign?.y1?.title,
chart.fontColor
)}
`
: ""
}
Expand Down
64 changes: 32 additions & 32 deletions tests/xlsx/__snapshots__/xlsx_export.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8557,8 +8557,8 @@ exports[`Test XLSX export Charts simple combo chart with customized axis 1`] = `
<c:axId val="88853994"/>
</c:barChart>
<c:catAx>
<c:axId val="17781237"/>
<c:crossAx val="88853993"/>
<c:axId val="17781238"/>
<c:crossAx val="88853994"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:delete val="0"/>
Expand Down Expand Up @@ -8621,16 +8621,16 @@ exports[`Test XLSX export Charts simple combo chart with customized axis 1`] = `
</c:catAx>
<!-- <tickLblPos/> omitted -->
<c:valAx>
<c:axId val="88853993"/>
<c:crossAx val="17781237"/>
<c:axId val="88853994"/>
<c:crossAx val="17781238"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:crosses val="max"/>
<c:delete val="0"/>
<!-- by default, axis are not displayed -->
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:axPos val="l"/>
<c:axPos val="r"/>
<c:majorGridlines>
<c:spPr>
<a:ln cmpd="sng">
Expand All @@ -8652,7 +8652,7 @@ exports[`Test XLSX export Charts simple combo chart with customized axis 1`] = `
<a:pPr lvl="0">
<a:defRPr b="1" i="1">
<a:solidFill>
<a:srgbClr val="00FF00"/>
<a:srgbClr val="0000FF"/>
</a:solidFill>
<a:latin typeface="+mn-lt"/>
</a:defRPr>
Expand All @@ -8661,7 +8661,7 @@ exports[`Test XLSX export Charts simple combo chart with customized axis 1`] = `
<!-- Runs -->
<a:rPr b="1" i="1" sz="1000"/>
<a:t>
Coucou 2
Coucou 3
</a:t>
</a:r>
</a:p>
Expand Down Expand Up @@ -9124,8 +9124,8 @@ exports[`Test XLSX export Charts simple combo chart with customized dataset 1`]
<c:axId val="88853993"/>
</c:barChart>
<c:catAx>
<c:axId val="17781238"/>
<c:crossAx val="88853994"/>
<c:axId val="17781237"/>
<c:crossAx val="88853993"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:delete val="0"/>
Expand Down Expand Up @@ -9186,16 +9186,16 @@ exports[`Test XLSX export Charts simple combo chart with customized dataset 1`]
</c:catAx>
<!-- <tickLblPos/> omitted -->
<c:valAx>
<c:axId val="88853994"/>
<c:crossAx val="17781238"/>
<c:axId val="88853993"/>
<c:crossAx val="17781237"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="max"/>
<c:crosses val="min"/>
<c:delete val="0"/>
<!-- by default, axis are not displayed -->
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:axPos val="r"/>
<c:axPos val="l"/>
<c:majorGridlines>
<c:spPr>
<a:ln cmpd="sng">
Expand Down Expand Up @@ -9689,8 +9689,8 @@ exports[`Test XLSX export Charts simple combo chart with customized title 1`] =
<c:axId val="88853993"/>
</c:barChart>
<c:catAx>
<c:axId val="17781238"/>
<c:crossAx val="88853994"/>
<c:axId val="17781237"/>
<c:crossAx val="88853993"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:delete val="0"/>
Expand Down Expand Up @@ -9751,16 +9751,16 @@ exports[`Test XLSX export Charts simple combo chart with customized title 1`] =
</c:catAx>
<!-- <tickLblPos/> omitted -->
<c:valAx>
<c:axId val="88853994"/>
<c:crossAx val="17781238"/>
<c:axId val="88853993"/>
<c:crossAx val="17781237"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="max"/>
<c:crosses val="min"/>
<c:delete val="0"/>
<!-- by default, axis are not displayed -->
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:axPos val="r"/>
<c:axPos val="l"/>
<c:majorGridlines>
<c:spPr>
<a:ln cmpd="sng">
Expand Down Expand Up @@ -10254,8 +10254,8 @@ exports[`Test XLSX export Charts simple combo chart with dataset [ [Object] ] 1`
<c:axId val="88853993"/>
</c:barChart>
<c:catAx>
<c:axId val="17781238"/>
<c:crossAx val="88853994"/>
<c:axId val="17781237"/>
<c:crossAx val="88853993"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:delete val="0"/>
Expand Down Expand Up @@ -10316,16 +10316,16 @@ exports[`Test XLSX export Charts simple combo chart with dataset [ [Object] ] 1`
</c:catAx>
<!-- <tickLblPos/> omitted -->
<c:valAx>
<c:axId val="88853994"/>
<c:crossAx val="17781238"/>
<c:axId val="88853993"/>
<c:crossAx val="17781237"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="max"/>
<c:crosses val="min"/>
<c:delete val="0"/>
<!-- by default, axis are not displayed -->
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:axPos val="r"/>
<c:axPos val="l"/>
<c:majorGridlines>
<c:spPr>
<a:ln cmpd="sng">
Expand Down Expand Up @@ -10878,8 +10878,8 @@ exports[`Test XLSX export Charts simple combo chart with dataset [ [Object], [Ob
<c:axId val="88853993"/>
</c:lineChart>
<c:catAx>
<c:axId val="17781238"/>
<c:crossAx val="88853994"/>
<c:axId val="17781237"/>
<c:crossAx val="88853993"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="min"/>
<c:delete val="1"/>
Expand Down Expand Up @@ -10940,16 +10940,16 @@ exports[`Test XLSX export Charts simple combo chart with dataset [ [Object], [Ob
</c:catAx>
<!-- <tickLblPos/> omitted -->
<c:valAx>
<c:axId val="88853994"/>
<c:crossAx val="17781238"/>
<c:axId val="88853993"/>
<c:crossAx val="17781237"/>
<!-- reference to the other axe of the chart -->
<c:crosses val="max"/>
<c:crosses val="min"/>
<c:delete val="0"/>
<!-- by default, axis are not displayed -->
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:axPos val="r"/>
<c:axPos val="l"/>
<c:majorGridlines>
<c:spPr>
<a:ln cmpd="sng">
Expand Down

0 comments on commit de00e5f

Please sign in to comment.