tdf#108110 ODF chart: import/export of custom position of data point labels
using new attributes loext:custom-label-pos-x and loext:custom-label-pos-y
of chart:data-point.
This fixes also *import* of DOCX documents with embedded charts, related
to the ODF usage in the background.
Follow-up of commit 4223ff2be6
(tdf#48436 Chart: add CustomLabelPosition UNO API property)
Change-Id: I985ce27cb6ce988948258d9eab0de13d01c72b97
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89446
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
parent
74e3c95b9b
commit
2a00d51150
10 changed files with 107 additions and 11 deletions
|
@ -2180,18 +2180,36 @@ void Chart2ExportTest::testCustomDataLabel()
|
|||
void Chart2ExportTest::testCustomPositionofDataLabel()
|
||||
{
|
||||
load("/chart2/qa/extras/data/xlsx/", "testCustomPosDataLabels.xlsx");
|
||||
xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
|
||||
CPPUNIT_ASSERT(pXmlDoc);
|
||||
{
|
||||
xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
|
||||
CPPUNIT_ASSERT(pXmlDoc);
|
||||
|
||||
// test custom position of data label
|
||||
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:idx", "val", "2");
|
||||
OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:x", "val");
|
||||
double nX = aXVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.11027682973075476, nX, 1e-7);
|
||||
// test custom position of data label (xlsx)
|
||||
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:idx", "val", "2");
|
||||
OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:x", "val");
|
||||
double nX = aXVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.11027682973075476, nX, 1e-7);
|
||||
|
||||
OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:y", "val");
|
||||
double nY = aYVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0742140311063737, nY, 1e-7);
|
||||
OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:layout/c:manualLayout/c:y", "val");
|
||||
double nY = aYVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0742140311063737, nY, 1e-7);
|
||||
}
|
||||
|
||||
load("/chart2/qa/extras/data/docx/", "testTdf108110.docx");
|
||||
{
|
||||
xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
|
||||
CPPUNIT_ASSERT(pXmlDoc);
|
||||
|
||||
// test custom position of data label (docx)
|
||||
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[2]/c:idx", "val", "2");
|
||||
OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[2]/c:layout/c:manualLayout/c:x", "val");
|
||||
double nX = aXVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0227256488772236, nX, 1e-7);
|
||||
|
||||
OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[2]/c:layout/c:manualLayout/c:y", "val");
|
||||
double nY = aYVal.toDouble();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.172648731408574, nY, 1e-7);
|
||||
}
|
||||
}
|
||||
|
||||
void Chart2ExportTest::testCustomDataLabelMultipleSeries()
|
||||
|
|
BIN
chart2/qa/extras/data/docx/testTdf108110.docx
Normal file
BIN
chart2/qa/extras/data/docx/testTdf108110.docx
Normal file
Binary file not shown.
|
@ -539,6 +539,8 @@ namespace xmloff { namespace token {
|
|||
XML_CUSTOM_ICONSET_INDEX,
|
||||
XML_CUSTOM_ICONSET_NAME,
|
||||
XML_CUSTOM_LABEL_FIELD,
|
||||
XML_CUSTOM_LABEL_POS_X,
|
||||
XML_CUSTOM_LABEL_POS_Y,
|
||||
XML_CUT,
|
||||
XML_CUT_OFFS,
|
||||
XML_CUT_OFFS2,
|
||||
|
|
|
@ -2418,4 +2418,16 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
|
|||
</rng:optional>
|
||||
</rng:define>
|
||||
|
||||
<!-- TODO no proposal -->
|
||||
<rng:define name="chart-data-point-attlist" combine="interleave">
|
||||
<rng:optional>
|
||||
<rng:attribute name="loext:custom-label-pos-x">
|
||||
<rng:ref name="double"/>
|
||||
</rng:attribute>
|
||||
<rng:attribute name="loext:custom-label-pos-y">
|
||||
<rng:ref name="double"/>
|
||||
</rng:attribute>
|
||||
</rng:optional>
|
||||
</rng:define>
|
||||
|
||||
</rng:grammar>
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
|
||||
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
|
||||
#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
|
||||
#include <com/sun/star/chart2/RelativePosition.hpp>
|
||||
|
||||
#include <com/sun/star/util/MeasureUnit.hpp>
|
||||
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
|
||||
|
@ -120,6 +121,7 @@ namespace
|
|||
OUString maStyleName;
|
||||
sal_Int32 mnRepeat;
|
||||
CustomLabelSeq mCustomLabelText;
|
||||
chart2::RelativePosition mCustomLabelPos;
|
||||
|
||||
SchXMLDataPointStruct() : mnRepeat( 1 ) {}
|
||||
};
|
||||
|
@ -228,6 +230,7 @@ public:
|
|||
bool bExportContent );
|
||||
|
||||
void exportCustomLabel(const CustomLabelSeq & xCustomLabel);
|
||||
void exportCustomLabelPosition(const chart2::RelativePosition & xCustomLabelPosition);
|
||||
|
||||
void exportRegressionCurve(
|
||||
const css::uno::Reference<css::chart2::XDataSeries>& xSeries,
|
||||
|
@ -299,6 +302,28 @@ CustomLabelSeq lcl_getCustomLabelField(sal_Int32 nDataPointIndex,
|
|||
return CustomLabelSeq();
|
||||
}
|
||||
|
||||
css::chart2::RelativePosition lcl_getCustomLabelPosition(sal_Int32 nDataPointIndex,
|
||||
const uno::Reference< chart2::XDataSeries >& rSeries)
|
||||
{
|
||||
if (!rSeries.is())
|
||||
return chart2::RelativePosition();
|
||||
|
||||
const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(SvtSaveOptions().GetODFDefaultVersion());
|
||||
if (nCurrentODFVersion <= SvtSaveOptions::ODFVER_012)//do not export to ODF 1.2 or older
|
||||
return chart2::RelativePosition();
|
||||
|
||||
if (Reference<beans::XPropertySet> xLabels = rSeries->getDataPointByIndex(nDataPointIndex); xLabels.is())
|
||||
{
|
||||
if (Any aAny = xLabels->getPropertyValue("CustomLabelPosition"); aAny.hasValue())
|
||||
{
|
||||
chart2::RelativePosition aCustomLabelPos;
|
||||
aAny >>= aCustomLabelPos;
|
||||
return aCustomLabelPos;
|
||||
}
|
||||
}
|
||||
return chart2::RelativePosition();
|
||||
}
|
||||
|
||||
class lcl_MatchesRole
|
||||
{
|
||||
public:
|
||||
|
@ -3327,6 +3352,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
|
|||
SchXMLDataPointStruct aPoint;
|
||||
aPoint.maStyleName = maAutoStyleNameQueue.front();
|
||||
aPoint.mCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries);
|
||||
aPoint.mCustomLabelPos = lcl_getCustomLabelPosition(nCurrIndex, xSeries);
|
||||
maAutoStyleNameQueue.pop();
|
||||
|
||||
aDataPointVector.push_back( aPoint );
|
||||
|
@ -3372,7 +3398,8 @@ void SchXMLExportHelper_Impl::exportDataPoints(
|
|||
{
|
||||
aPoint = rPoint;
|
||||
|
||||
if( aPoint.maStyleName == aLastPoint.maStyleName && aLastPoint.mCustomLabelText.getLength() < 1 )
|
||||
if( aPoint.maStyleName == aLastPoint.maStyleName && aLastPoint.mCustomLabelText.getLength() < 1 &&
|
||||
aLastPoint.mCustomLabelPos.Primary == 0.0 && aLastPoint.mCustomLabelPos.Secondary == 0.0 )
|
||||
aPoint.mnRepeat += aLastPoint.mnRepeat;
|
||||
else if( aLastPoint.mnRepeat > 0 )
|
||||
{
|
||||
|
@ -3393,6 +3420,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
|
|||
}
|
||||
}
|
||||
nIndex++;
|
||||
exportCustomLabelPosition(aLastPoint.mCustomLabelPos);
|
||||
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
|
||||
exportCustomLabel(aLastPoint.mCustomLabelText);
|
||||
}
|
||||
|
@ -3417,6 +3445,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
|
|||
}
|
||||
}
|
||||
|
||||
exportCustomLabelPosition(aLastPoint.mCustomLabelPos);
|
||||
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
|
||||
exportCustomLabel(aLastPoint.mCustomLabelText);
|
||||
}
|
||||
|
@ -3437,6 +3466,19 @@ void SchXMLExportHelper_Impl::exportCustomLabel( const CustomLabelSeq & xCustomL
|
|||
}
|
||||
}
|
||||
|
||||
void SchXMLExportHelper_Impl::exportCustomLabelPosition( const chart2::RelativePosition & xCustomLabelPosition)
|
||||
{
|
||||
if( xCustomLabelPosition.Primary == 0.0 && xCustomLabelPosition.Secondary == 0.0 )
|
||||
return; // nothing to export
|
||||
|
||||
OUStringBuffer aCustomLabelPosString;
|
||||
::sax::Converter::convertDouble(aCustomLabelPosString, xCustomLabelPosition.Primary);
|
||||
mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_POS_X, aCustomLabelPosString.makeStringAndClear());
|
||||
|
||||
::sax::Converter::convertDouble(aCustomLabelPosString, xCustomLabelPosition.Secondary);
|
||||
mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_POS_Y, aCustomLabelPosString.makeStringAndClear());
|
||||
}
|
||||
|
||||
void SchXMLExportHelper_Impl::addPosition( const awt::Point & rPosition )
|
||||
{
|
||||
mrExport.GetMM100UnitConverter().convertMeasureToXML(
|
||||
|
|
|
@ -722,6 +722,14 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
|
|||
xSeriesProp->setPropertyValue("DeletedLegendEntries", uno::makeAny(::oox::ContainerHelper::vectorToSequence(deletedLegendEntries)));
|
||||
}
|
||||
}
|
||||
else if( IsXMLToken(aLocalName, XML_CUSTOM_LABEL_POS_X ) )
|
||||
{
|
||||
mDataPoint.mCustomLabelPos[0] = xAttrList->getValueByIndex(i).toDouble();
|
||||
}
|
||||
else if( IsXMLToken(aLocalName, XML_CUSTOM_LABEL_POS_Y) )
|
||||
{
|
||||
mDataPoint.mCustomLabelPos[1] = xAttrList->getValueByIndex(i).toDouble();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
|
||||
#include <com/sun/star/chart2/data/XDataSink.hpp>
|
||||
#include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
|
||||
#include <com/sun/star/chart2/RelativePosition.hpp>
|
||||
|
||||
#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
|
||||
#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
|
||||
|
@ -1101,6 +1102,14 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
|
|||
}
|
||||
xPointProp->setPropertyValue("CustomLabelFields", uno::Any(xLabels));
|
||||
}
|
||||
|
||||
if( seriesStyle.mCustomLabelPos[0] != 0.0 || seriesStyle.mCustomLabelPos[1] != 0.0 )
|
||||
{
|
||||
chart2::RelativePosition aCustomlabelPosition;
|
||||
aCustomlabelPosition.Primary = seriesStyle.mCustomLabelPos[0];
|
||||
aCustomlabelPosition.Secondary = seriesStyle.mCustomLabelPos[1];
|
||||
xPointProp->setPropertyValue("CustomLabelPosition", uno::Any(aCustomlabelPosition));
|
||||
}
|
||||
}
|
||||
catch( const uno::Exception & )
|
||||
{
|
||||
|
|
|
@ -172,6 +172,7 @@ struct DataRowPointStyle
|
|||
sal_Int32 m_nPointRepeat;
|
||||
OUString msStyleName;
|
||||
::std::vector<OUString> mCustomLabels;
|
||||
double mCustomLabelPos[2] = { 0.0, 0.0 };
|
||||
OUString msSeriesStyleNameForDonuts;
|
||||
|
||||
sal_Int32 mnAttachedAxis;
|
||||
|
|
|
@ -540,6 +540,8 @@ namespace xmloff::token {
|
|||
TOKEN( "custom-iconset-index", XML_CUSTOM_ICONSET_INDEX ),
|
||||
TOKEN( "custom-iconset-name", XML_CUSTOM_ICONSET_NAME ),
|
||||
TOKEN( "custom-label-field", XML_CUSTOM_LABEL_FIELD ),
|
||||
TOKEN( "custom-label-pos-x", XML_CUSTOM_LABEL_POS_X ),
|
||||
TOKEN( "custom-label-pos-y", XML_CUSTOM_LABEL_POS_Y ),
|
||||
TOKEN( "cut", XML_CUT ),
|
||||
TOKEN( "cut-offs", XML_CUT_OFFS ),
|
||||
TOKEN( "cut_offs", XML_CUT_OFFS2 ),
|
||||
|
|
|
@ -463,6 +463,8 @@ custom-iconset
|
|||
custom-iconset-index
|
||||
custom-iconset-name
|
||||
custom-label-field
|
||||
custom-label-pos-x
|
||||
custom-label-pos-y
|
||||
cut
|
||||
cut-offs
|
||||
cut_offs
|
||||
|
|
Loading…
Reference in a new issue