summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2020-01-30 23:58:57 +0100
committerLászló Németh <nemeth@numbertext.org>2020-01-31 10:43:22 +0100
commitdff7a46fb46d1fa2a3ad674ee493ae2d59150fe3 (patch)
treea20c2913d75c8173ed24064c877bb14568359700
parent84b396a235671ea77f1a9fa0d131cb56d7662737 (diff)
tdf#130032 Chart OOXML Import: fix data label custom position
in case of all chart types except pie chart. Clean up commit 4223ff2be69f03e571464b0b09ad0d278918631b (tdf#48436 Chart: add CustomLabelPosition UNO API property). Note: use the correct default OOXML label placement in case of radar charts. Change-Id: I9a8f509304b3c70d879c8c6a95bc91d15ac28521 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87759 Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--chart2/qa/extras/chart2import.cxx25
-rw-r--r--chart2/qa/extras/data/xlsx/testTdf130032.xlsxbin0 -> 14208 bytes
-rw-r--r--chart2/source/view/main/VDataSeries.cxx12
-rw-r--r--offapi/com/sun/star/chart/DataLabelPlacement.idl2
-rw-r--r--offapi/com/sun/star/chart2/DataPointProperties.idl2
-rw-r--r--oox/source/drawingml/chart/seriesconverter.cxx53
-rw-r--r--oox/source/drawingml/chart/typegroupconverter.cxx4
7 files changed, 40 insertions, 58 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 47b2e0354d51..054b04209db2 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -153,6 +153,7 @@ public:
void testTdf123206CustomLabelField();
void testTdf125444PercentageCustomLabel();
void testDataPointLabelCustomPos();
+ void testTdf130032();
CPPUNIT_TEST_SUITE(Chart2ImportTest);
CPPUNIT_TEST(Fdo60083);
@@ -254,6 +255,7 @@ public:
CPPUNIT_TEST(testTdf123206CustomLabelField);
CPPUNIT_TEST(testTdf125444PercentageCustomLabel);
CPPUNIT_TEST(testDataPointLabelCustomPos);
+ CPPUNIT_TEST(testTdf130032);
CPPUNIT_TEST_SUITE_END();
@@ -2353,6 +2355,7 @@ void Chart2ImportTest::testTdf125444PercentageCustomLabel()
void Chart2ImportTest::testDataPointLabelCustomPos()
{
+ // test CustomLabelPosition on Bar chart
load("/chart2/qa/extras/data/xlsx/", "testDataPointLabelCustomPos.xlsx");
uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet(0, mxComponent);
CPPUNIT_ASSERT(xChartDoc.is());
@@ -2372,6 +2375,28 @@ void Chart2ImportTest::testDataPointLabelCustomPos()
CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::OUTSIDE, aPlacement);
}
+void Chart2ImportTest::testTdf130032()
+{
+ // test CustomLabelPosition on Line chart
+ load("/chart2/qa/extras/data/xlsx/", "testTdf130032.xlsx");
+ uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet(0, mxComponent);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
+ CPPUNIT_ASSERT(xDataSeries.is());
+
+ uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(1), uno::UNO_SET_THROW);
+ CPPUNIT_ASSERT(xPropertySet.is());
+
+ chart2::RelativePosition aCustomLabelPosition;
+ xPropertySet->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Primary, -0.0438333333333334, 1e-7);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aCustomLabelPosition.Secondary, 0.086794050743657, 1e-7);
+
+ sal_Int32 aPlacement;
+ xPropertySet->getPropertyValue("LabelPlacement") >>= aPlacement;
+ CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::RIGHT, aPlacement);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/xlsx/testTdf130032.xlsx b/chart2/qa/extras/data/xlsx/testTdf130032.xlsx
new file mode 100644
index 000000000000..03a3dbf403c3
--- /dev/null
+++ b/chart2/qa/extras/data/xlsx/testTdf130032.xlsx
Binary files differ
diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx
index 33bf9bee481d..f64cb151a2d8 100644
--- a/chart2/source/view/main/VDataSeries.cxx
+++ b/chart2/source/view/main/VDataSeries.cxx
@@ -641,8 +641,10 @@ awt::Point VDataSeries::getLabelPosition( awt::Point aTextShapePos, sal_Int32 nP
aPos.Y = static_cast<sal_Int32>(aCustomLabelPosition.Secondary * m_aReferenceSize.Height) + aTextShapePos.Y;
}
}
- catch (const uno::Exception&) {}
-
+ catch (const uno::Exception&)
+ {
+ TOOLS_WARN_EXCEPTION("chart2", "");
+ }
return aPos;
}
@@ -659,8 +661,10 @@ bool VDataSeries::isLabelCustomPos(sal_Int32 nPointIndex) const
bCustom = true;
}
}
- catch (const uno::Exception&) {}
-
+ catch (const uno::Exception&)
+ {
+ TOOLS_WARN_EXCEPTION("chart2", "");
+ }
return bCustom;
}
diff --git a/offapi/com/sun/star/chart/DataLabelPlacement.idl b/offapi/com/sun/star/chart/DataLabelPlacement.idl
index fbdc19fcce8f..f8e50effeaea 100644
--- a/offapi/com/sun/star/chart/DataLabelPlacement.idl
+++ b/offapi/com/sun/star/chart/DataLabelPlacement.idl
@@ -41,7 +41,7 @@ published constants DataLabelPlacement
const long INSIDE = 10;
const long OUTSIDE = 11;
const long NEAR_ORIGIN = 12;
- const long CUSTOM = 13;
+ /** @since LibreOffice 7.0 */ const long CUSTOM = 13;
};
diff --git a/offapi/com/sun/star/chart2/DataPointProperties.idl b/offapi/com/sun/star/chart2/DataPointProperties.idl
index a8725651c00a..4588b5bb9f10 100644
--- a/offapi/com/sun/star/chart2/DataPointProperties.idl
+++ b/offapi/com/sun/star/chart2/DataPointProperties.idl
@@ -331,7 +331,7 @@ service DataPointProperties
/** Custom position on the page associated to the CUSTOM label placement.
- @since LibreOffice 6.5
+ @since LibreOffice 7.0
*/
[optional, maybevoid, property] ::com::sun::star::chart2::RelativePosition CustomLabelPosition;
};
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index d47d897c5a91..c190fa6a1b6d 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -62,32 +62,6 @@ using namespace ::com::sun::star::uno;
namespace {
-/** Function to get vertical position of label from chart height factor.
- Value can be negative, prefer top placement.
- */
-int lclGetPositionY( double nVal )
-{
- if( nVal <= 0.1 )
- return -1;
- else if( nVal <= 0.6 )
- return 0;
- else
- return 1;
-}
-
-/** Function to get horizontal position of label from chart width factor.
- Value can be negative, prefer center placement.
-*/
-int lclGetPositionX( double nVal )
-{
- if( nVal <= -0.2 )
- return -1;
- else if( nVal <= 0.2 )
- return 0;
- else
- return 1;
-}
-
Reference< XLabeledDataSequence > lclCreateLabeledDataSequence(
const ConverterRoot& rParent,
DataSourceModel* pValues, const OUString& rRole,
@@ -275,31 +249,10 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
bool bIsPie = rTypeInfo.meTypeCategory == TYPECATEGORY_PIE;
- if( mrModel.mxLayout && !mrModel.mxLayout->mbAutoLayout )
+ if( mrModel.mxLayout && !mrModel.mxLayout->mbAutoLayout && !bIsPie )
{
- if( rTypeInfo.meTypeCategory == TYPECATEGORY_BAR )
- {
- // It is only works for BAR Chart, yet!!!
- RelativePosition aPos(mrModel.mxLayout->mfX, mrModel.mxLayout->mfY, css::drawing::Alignment_TOP_LEFT);
- aPropSet.setProperty(PROP_CustomLabelPosition, aPos);
- }
- else if( !bIsPie )
- {
- // bnc#694340 - nasty hack - chart2 cannot individually
- // place data labels, let's try to find a useful
- // compromise instead
- namespace csscd = ::com::sun::star::chart::DataLabelPlacement;
- const sal_Int32 aPositionsLookupTable[] =
- {
- csscd::TOP_LEFT, csscd::TOP, csscd::TOP_RIGHT,
- csscd::LEFT, csscd::CENTER, csscd::RIGHT,
- csscd::BOTTOM_LEFT, csscd::BOTTOM, csscd::BOTTOM_RIGHT
- };
- const int simplifiedX = lclGetPositionX(mrModel.mxLayout->mfX);
- const int simplifiedY = lclGetPositionY(mrModel.mxLayout->mfY);
- aPropSet.setProperty(PROP_LabelPlacement,
- aPositionsLookupTable[simplifiedX + 1 + 3 * (simplifiedY + 1)]);
- }
+ RelativePosition aPos(mrModel.mxLayout->mfX, mrModel.mxLayout->mfY, css::drawing::Alignment_TOP_LEFT);
+ aPropSet.setProperty(PROP_CustomLabelPosition, aPos);
}
if (mrModel.mxShapeProp)
diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx
index 37a5390a189f..7ce8adc3ffdf 100644
--- a/oox/source/drawingml/chart/typegroupconverter.cxx
+++ b/oox/source/drawingml/chart/typegroupconverter.cxx
@@ -74,8 +74,8 @@ static const TypeGroupInfo spTypeInfos[] =
{ TYPEID_LINE, TYPECATEGORY_LINE, SERVICE_CHART2_LINE, VARPOINTMODE_SINGLE, csscd::RIGHT, false, false, false, true, false, true, false, false },
{ TYPEID_AREA, TYPECATEGORY_LINE, SERVICE_CHART2_AREA, VARPOINTMODE_NONE, csscd::CENTER, false, true, false, true, false, true, true, false },
{ TYPEID_STOCK, TYPECATEGORY_LINE, SERVICE_CHART2_CANDLE, VARPOINTMODE_NONE, csscd::RIGHT, false, false, false, true, false, true, false, false },
- { TYPEID_RADARLINE, TYPECATEGORY_RADAR, SERVICE_CHART2_NET, VARPOINTMODE_SINGLE, csscd::TOP, true, false, false, true, false, false, false, false },
- { TYPEID_RADARAREA, TYPECATEGORY_RADAR, SERVICE_CHART2_FILLEDNET, VARPOINTMODE_NONE, csscd::TOP, true, true, false, true, false, false, true, false },
+ { TYPEID_RADARLINE, TYPECATEGORY_RADAR, SERVICE_CHART2_NET, VARPOINTMODE_SINGLE, csscd::OUTSIDE, true, false, false, true, false, false, false, false },
+ { TYPEID_RADARAREA, TYPECATEGORY_RADAR, SERVICE_CHART2_FILLEDNET, VARPOINTMODE_NONE, csscd::OUTSIDE, true, true, false, true, false, false, true, false },
{ TYPEID_PIE, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, true, true, false, false, false, false },
{ TYPEID_DOUGHNUT, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, false, true, false, false, false, false },
{ TYPEID_OFPIE, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, true, true, false, false, false, false },