tdf#134247 Chart OOXML import: fix order of legend entries

The order of legend entries was reversed in stacked column,
line and area charts.

Change-Id: Ia4a439aa6cee0619ad323c3fb728ff358cf28537
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96941
Tested-by: Jenkins
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
Tünde Tóth 2020-06-23 13:52:39 +02:00 committed by László Németh
parent 9294b76982
commit b3057b7944
6 changed files with 30 additions and 18 deletions

View File

@ -2394,7 +2394,7 @@ bool VSeriesPlotter::shouldSnapRectToUsedArea()
std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries(
const awt::Size& rEntryKeyAspectRatio
, css::chart::ChartLegendExpansion eLegendExpansion
, LegendPosition eLegendPosition
, const Reference< beans::XPropertySet >& xTextProperties
, const Reference< drawing::XShapes >& xTarget
, const Reference< lang::XMultiServiceFactory >& xShapeFactory
@ -2450,25 +2450,20 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries(
bBreak = true;
bFirstSeries = false;
// add entries reverse if chart is stacked in y-direction and the legend is not wide.
// If the legend is wide and we have a stacked bar-chart the normal order
// add entries reverse if chart is stacked in y-direction and the legend position is right or left.
// If the legend is top or bottom and we have a stacked bar-chart the normal order
// is the correct one, unless the chart type is horizontal bar-chart.
bool bReverse = false;
if( eLegendExpansion != css::chart::ChartLegendExpansion_WIDE )
{
StackingDirection eStackingDirection( pSeries->getStackingDirection() );
bReverse = ( eStackingDirection == StackingDirection_Y_STACKING );
if( bSwapXAndY )
{
bReverse = !bReverse;
}
}
else if( bSwapXAndY )
if ( bSwapXAndY )
{
StackingDirection eStackingDirection( pSeries->getStackingDirection() );
bReverse = ( eStackingDirection != StackingDirection_Y_STACKING );
}
else if ( eLegendPosition == LegendPosition_LINE_START || eLegendPosition == LegendPosition_LINE_END )
{
StackingDirection eStackingDirection( pSeries->getStackingDirection() );
bReverse = ( eStackingDirection == StackingDirection_Y_STACKING );
}
if (bReverse)
aResult.insert( aResult.begin(), aSeriesEntries.begin(), aSeriesEntries.end() );

View File

@ -19,7 +19,7 @@
#ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_LEGENDENTRYPROVIDER_HXX
#define INCLUDED_CHART2_SOURCE_VIEW_INC_LEGENDENTRYPROVIDER_HXX
#include <com/sun/star/chart/ChartLegendExpansion.hpp>
#include <com/sun/star/chart2/LegendPosition.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.h>
@ -72,7 +72,7 @@ public:
virtual std::vector< ViewLegendEntry > createLegendEntries(
const css::awt::Size& rEntryKeyAspectRatio,
css::chart::ChartLegendExpansion eLegendExpansion,
css::chart2::LegendPosition eLegendPosition,
const css::uno::Reference< css::beans::XPropertySet >& xTextProperties,
const css::uno::Reference< css::drawing::XShapes >& xTarget,
const css::uno::Reference< css::lang::XMultiServiceFactory >& xShapeFactory,

View File

@ -182,7 +182,7 @@ public:
virtual std::vector< ViewLegendEntry > createLegendEntries(
const css::awt::Size& rEntryKeyAspectRatio,
css::chart::ChartLegendExpansion eLegendExpansion,
css::chart2::LegendPosition eLegendPosition,
const css::uno::Reference< css::beans::XPropertySet >& xTextProperties,
const css::uno::Reference< css::drawing::XShapes >& xTarget,
const css::uno::Reference< css::lang::XMultiServiceFactory >& xShapeFactory,

View File

@ -954,7 +954,7 @@ void VLegend::createShapes(
if (pLegendEntryProvider)
{
std::vector<ViewLegendEntry> aNewEntries = pLegendEntryProvider->createLegendEntries(
aMaxSymbolExtent, eExpansion, xLegendProp,
aMaxSymbolExtent, eLegendPosition, xLegendProp,
xLegendContainer, m_xShapeFactory, m_xContext, mrModel);
if (aNewEntries.size() == 0)
return;

Binary file not shown.

View File

@ -2324,6 +2324,23 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf125335)
// This failed, if the legend first label is not "Data3". The legend position is bottom.
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf134247)
{
SwDoc* pDoc = createDoc("legend-itemorder-min.docx");
SwDocShell* pShell = pDoc->GetDocShell();
// Dump the rendering of the first page as an XML file.
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump dumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
CPPUNIT_ASSERT(pXmlDoc);
assertXPathContent(pXmlDoc,
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/textarray[14]/text",
"1. adatsor");
// This failed, if the legend first label is not "1. adatsor".
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf75659)
{
SwDoc* pDoc = createDoc("tdf75659.docx");