Kaydet (Commit) 11473832 authored tarafından Balazs Varga's avatar Balazs Varga Kaydeden (comit) László Németh

tdf#114181 XLSX combined chart: fix swapped primary and secondary axes etc.

In combined charts, now X category axis crosses the Y axis at the right
place, all data series are attached to the right Y axis, and the
Y major grid isn't lost.

Note: Let's check which axis is attached to the first charttype
(in case of combined chart, the first one is a column chart) and create
that axis first. In OOXML standard, the first CT_valAx tag contains the
axID of the primary axis and the second CT_valAx tag contains the axID
of the secondary axis. 


Change-Id: Ib123f95ec41ef5dbbf0599efd7a646f4640a9b70
Reviewed-on: https://gerrit.libreoffice.org/70464Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
Tested-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst e21bc326
......@@ -102,6 +102,7 @@ public:
void testAxisTitleDefaultRotationXLSX();
void testSecondaryAxisTitleDefaultRotationXLSX();
void testAxisTitleRotationXLSX();
void testCombinedChartAttachedAxisXLSX();
void testTdf90510(); // Pie chart label placement settings(XLS)
void testTdf109858(); // Pie chart label placement settings(XLSX)
......@@ -182,6 +183,7 @@ public:
CPPUNIT_TEST(testAxisTitleDefaultRotationXLSX);
CPPUNIT_TEST(testSecondaryAxisTitleDefaultRotationXLSX);
CPPUNIT_TEST(testAxisTitleRotationXLSX);
CPPUNIT_TEST(testCombinedChartAttachedAxisXLSX);
CPPUNIT_TEST(testTdf90510);
CPPUNIT_TEST(testTdf109858);
CPPUNIT_TEST(testTdf111173);
......@@ -1399,6 +1401,32 @@ void Chart2ImportTest::testAxisTitleRotationXLSX()
}
void Chart2ImportTest::testCombinedChartAttachedAxisXLSX()
{
load("/chart2/qa/extras/data/xlsx/", "testCombinedChartAxis.xlsx");
Reference< chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
// First series
Reference<chart2::XDataSeries> xSeries = getDataSeriesFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT(xSeries.is());
Reference<beans::XPropertySet> xPropSet(xSeries, uno::UNO_QUERY_THROW);
sal_Int32 nAxisIndex = -1;
// First series (column chart) should be attached to secondary axis!
uno::Any aAny = xPropSet->getPropertyValue("AttachedAxisIndex");
CPPUNIT_ASSERT(aAny >>= nAxisIndex);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nAxisIndex);
// Second series
xSeries = getDataSeriesFromDoc(xChartDoc, 0, 1);
CPPUNIT_ASSERT(xSeries.is());
xPropSet.set(xSeries, uno::UNO_QUERY_THROW);
// Second series (line chart) should be attached to primary axis!
aAny = xPropSet->getPropertyValue("AttachedAxisIndex");
CPPUNIT_ASSERT(aAny >>= nAxisIndex);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAxisIndex);
}
void Chart2ImportTest::testInternalDataProvider() {
uno::Reference< chart2::XChartDocument > xChartDoc(getChartDocFromImpress("/chart2/qa/extras/data/odp/", "chart.odp"), uno::UNO_QUERY_THROW);
const uno::Reference< chart2::data::XDataProvider >& rxDataProvider = xChartDoc->getDataProvider();
......
......@@ -335,12 +335,36 @@ void PlotAreaConverter::convertFromModel( View3DModel& rView3DModel )
// store all axis models in a map, keyed by axis identifier
typedef ModelMap< sal_Int32, AxisModel > AxisMap;
AxisMap aAxisMap;
std::vector<sal_Int32>rValAxisIds;
std::vector<sal_Int32>rRealValAxisIds;
for (auto const& atypeGroup : mrModel.maTypeGroups)
{
if (atypeGroup->maAxisIds.size() > 1)
{
// let's collect which axId belongs to the Y Axis according to maTypeGroups
rRealValAxisIds.push_back(atypeGroup->maAxisIds[1]);
}
}
for (auto const& axis : mrModel.maAxes)
{
OSL_ENSURE( axis->mnAxisId >= 0, "PlotAreaConverter::convertFromModel - invalid axis identifier" );
OSL_ENSURE( !aAxisMap.has( axis->mnAxisId ), "PlotAreaConverter::convertFromModel - axis identifiers not unique" );
if( axis->mnAxisId != -1 )
aAxisMap[ axis->mnAxisId ] = axis;
if ( axis->mnAxisId != -1 && axis->mnTypeId == C_TOKEN(valAx) )
{
for (size_t i = 0; i < rRealValAxisIds.size(); i++)
{
if (axis->mnAxisId == rRealValAxisIds[i])
{
// let's collect which axId belongs to the Y Axis according to maAxes
rValAxisIds.push_back(axis->mnAxisId);
}
}
}
}
// group the type group models into different axes sets
......@@ -390,13 +414,15 @@ void PlotAreaConverter::convertFromModel( View3DModel& rView3DModel )
// varying point colors only for single series in single chart type
bool bSupportsVaryColorsByPoint = mrModel.maTypeGroups.size() == 1;
// convert all axes sets
sal_Int32 nAxesSetIdx = 0;
// convert all axes sets, and check which axis is attached to the first maTypeGroups
sal_Int32 nStartAxesSetIdx = (rValAxisIds.size() > 1 && aAxesSets[0]->maAxes[1]->mnAxisId != rValAxisIds[0] ) ? 1 : 0;
sal_Int32 nAxesSetIdx = nStartAxesSetIdx;
for (auto const& axesSet : aAxesSets)
{
AxesSetConverter aAxesSetConv(*this, *axesSet);
aAxesSetConv.convertFromModel( xDiagram, rView3DModel, nAxesSetIdx, bSupportsVaryColorsByPoint );
if( nAxesSetIdx == 0 )
if(nAxesSetIdx == nStartAxesSetIdx)
{
maAutoTitle = aAxesSetConv.getAutomaticTitle();
mb3dChart = aAxesSetConv.is3dChart();
......@@ -407,7 +433,7 @@ void PlotAreaConverter::convertFromModel( View3DModel& rView3DModel )
{
maAutoTitle.clear();
}
++nAxesSetIdx;
nAxesSetIdx = 1 - nAxesSetIdx;
}
DataTableConverter dataTableConverter (*this, mrModel.mxDataTable.getOrCreate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment