[Libreoffice-commits] core.git: chart2/qa include/xmloff schema/libreoffice xmloff/source
Balazs Varga (via logerrit)
logerrit at kemper.freedesktop.org
Thu Feb 27 15:56:59 UTC 2020
chart2/qa/extras/chart2export.cxx | 40 +++++++---
chart2/qa/extras/data/docx/testTdf108110.docx |binary
include/xmloff/xmltoken.hxx | 2
schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng | 12 +++
xmloff/source/chart/SchXMLExport.cxx | 44 +++++++++++-
xmloff/source/chart/SchXMLPlotAreaContext.cxx | 8 ++
xmloff/source/chart/SchXMLSeries2Context.cxx | 9 ++
xmloff/source/chart/transporttypes.hxx | 1
xmloff/source/core/xmltoken.cxx | 2
xmloff/source/token/tokens.txt | 2
10 files changed, 108 insertions(+), 12 deletions(-)
New commits:
commit 2a00d51150d410110602c953b3c3895debfcaa98
Author: Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Tue Feb 25 12:48:08 2020 +0100
Commit: László Németh <nemeth at numbertext.org>
CommitDate: Thu Feb 27 16:56:23 2020 +0100
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 4223ff2be69f03e571464b0b09ad0d278918631b
(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 at numbertext.org>
Reviewed-by: László Németh <nemeth at numbertext.org>
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 469e25618b5f..90b20d363b80 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -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);
-
- // 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);
+ {
+ xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ // 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()
diff --git a/chart2/qa/extras/data/docx/testTdf108110.docx b/chart2/qa/extras/data/docx/testTdf108110.docx
new file mode 100644
index 000000000000..769360c15203
Binary files /dev/null and b/chart2/qa/extras/data/docx/testTdf108110.docx differ
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index d0896bd8507c..3089bb6e9e72 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -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,
diff --git a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng
index 11a01c8e8300..e44c01bd8d06 100644
--- a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng
+++ b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng
@@ -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>
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index b2339ab46622..6319585bc36a 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -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(
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index dc32a9e900a0..471478a824ae 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -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();
+ }
}
}
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index a571430c28d0..38ec7c084d2b 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -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 & )
{
diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx
index 04fbe70ecdd0..cc7dce95ef06 100644
--- a/xmloff/source/chart/transporttypes.hxx
+++ b/xmloff/source/chart/transporttypes.hxx
@@ -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;
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 96115303c31b..9be73cdae89f 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -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 ),
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index abd7dadcd260..78a0adbf9d85 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -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
More information about the Libreoffice-commits
mailing list