tdf#127393 OOXML chart import: fix X axis position setting "CrossBetween"

Set ShiftedCategoryPosition according to OOXML value CrossBetween.

Change-Id: I6445c94507de83f84b08fd3380cbbf03886b5aa3
Reviewed-on: https://gerrit.libreoffice.org/79142
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
Balazs Varga 2019-09-19 15:15:58 +02:00 committed by László Németh
parent 9f1352381e
commit 830e539547
6 changed files with 39 additions and 7 deletions

View file

@ -129,6 +129,7 @@ public:
void testTdf114179();
void testTdf124243();
void testTdf127393();
void testDeletedDataLabel();
void testDataPointInheritedColorDOCX();
void testExternalStrRefsXLSX();
@ -218,6 +219,7 @@ public:
CPPUNIT_TEST(testTdf114179);
CPPUNIT_TEST(testTdf124243);
CPPUNIT_TEST(testTdf127393);
CPPUNIT_TEST(testDeletedDataLabel);
CPPUNIT_TEST(testDataPointInheritedColorDOCX);
CPPUNIT_TEST(testExternalStrRefsXLSX);
@ -1929,6 +1931,33 @@ void Chart2ImportTest::testTdf124243()
CPPUNIT_ASSERT(!bShow);
}
void Chart2ImportTest::testTdf127393()
{
load("/chart2/qa/extras/data/pptx/", "tdf127393.pptx");
// 1st chart
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData1 = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData1.Categories.is());
CPPUNIT_ASSERT(aScaleData1.ShiftedCategoryPosition);
// 2nd chart
xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
xAxis.set(getAxisFromDoc(xChartDoc, 0, 0, 0));
CPPUNIT_ASSERT(xAxis.is());
chart2::ScaleData aScaleData2 = xAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData2.Categories.is());
CPPUNIT_ASSERT(!aScaleData2.ShiftedCategoryPosition);
}
namespace {
void checkDataLabelProperties(const Reference<chart2::XDataSeries>& xDataSeries, sal_Int32 nDataPointIndex, bool bValueVisible)

Binary file not shown.

View file

@ -325,7 +325,7 @@ public:
void AdaptScaleOfYAxisWithoutAttachedSeries( ChartModel& rModel );
bool isCategoryPositionShifted(
const chart2::ScaleData& rSourceScale, bool bHasComplexCategories ) const;
const chart2::ScaleData& rSourceScale, bool bHasComplexCategories, bool bShiftedCategoryPosition) const;
private:
/** A vector of series plotters.
@ -631,12 +631,12 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(
}
bool SeriesPlotterContainer::isCategoryPositionShifted(
const chart2::ScaleData& rSourceScale, bool bHasComplexCategories ) const
const chart2::ScaleData& rSourceScale, bool bHasComplexCategories, bool bShiftedCategoryPosition) const
{
if (rSourceScale.AxisType == AxisType::CATEGORY && m_bChartTypeUsesShiftedCategoryPositionPerDefault)
if (rSourceScale.AxisType == AxisType::CATEGORY && (m_bChartTypeUsesShiftedCategoryPositionPerDefault || bShiftedCategoryPosition))
return true;
if (rSourceScale.AxisType==AxisType::CATEGORY && bHasComplexCategories)
if (rSourceScale.AxisType == AxisType::CATEGORY && bHasComplexCategories)
return true;
if (rSourceScale.AxisType == AxisType::DATE)
@ -683,7 +683,9 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate)
AxisHelper::checkDateAxis( aSourceScale, pCatProvider, bDateAxisAllowed );
bool bHasComplexCat = pCatProvider && pCatProvider->hasComplexCategories();
aSourceScale.ShiftedCategoryPosition = isCategoryPositionShifted(aSourceScale, bHasComplexCat);
// Come from CrossBetween OOXML tag
bool bShiftedCategoryPosition = aSourceScale.ShiftedCategoryPosition;
aSourceScale.ShiftedCategoryPosition = isCategoryPositionShifted(aSourceScale, bHasComplexCat, bShiftedCategoryPosition);
m_aAxisUsageList[xAxis].aAutoScaling = ScaleAutomatism(aSourceScale, rNullDate);
}

View file

@ -281,7 +281,7 @@ ContextHandlerRef ValAxisContext::onCreateContext( sal_Int32 nElement, const Att
if( isRootElement() ) switch( nElement )
{
case C_TOKEN( crossBetween ):
mrModel.mnCrossBetween = rAttribs.getToken( XML_val, XML_between );
mrModel.mnCrossBetween = rAttribs.getToken( XML_val, -1 );
return nullptr;
case C_TOKEN( dispUnits ):
return new AxisDispUnitsContext( *this, mrModel.mxDispUnits.create() );

View file

@ -213,6 +213,7 @@ void AxisConverter::convertFromModel(
aScaleData.AxisType = (bDateAxis && !mrModel.mbAuto) ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
aScaleData.AutoDateAxis = mrModel.mbAuto;
aScaleData.Categories = rTypeGroups.front()->createCategorySequence();
aScaleData.ShiftedCategoryPosition = pCrossingAxis->mnCrossBetween == XML_between;
}
else
{

View file

@ -36,7 +36,7 @@ AxisModel::AxisModel( sal_Int32 nTypeId, bool bMSO2007Doc ) :
mnAxisId( -1 ),
mnAxisPos( XML_TOKEN_INVALID ),
mnCrossAxisId( -1 ),
mnCrossBetween( XML_between ),
mnCrossBetween( -1 ),
mnCrossMode( XML_autoZero ),
mnLabelAlign( XML_ctr ),
mnLabelOffset( 100 ),