summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-02-11 14:05:37 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-02-12 06:31:49 +0100
commit92da88582ae8d5ddbd786f9936e1b2b46eaddf2c (patch)
treef41632caea12f6ceeb6256ff652e8d190afa85ca /chart2
parent0bf0feb40ae5c394a14cdfe4f94fb98dd9053597 (diff)
chart2: crop x-axis label if it's too long on fixed size charts
If the label text is too long on a fixed size chart area, crop it as we can't resize the chart area to accomodate for text breaking into multiple lines. The algorithm to determine if cropping is needed has assumed that we need this in case the x-axis label is vertical, so there was no check to actually make sure the text is horizontal or vertical and in case it was horizontal, it has taken height into account and not width, so nothing got cropped. Change-Id: I8e73027fc51722280418c9e0be34ce487c41171e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129813 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import.cxx73
-rw-r--r--chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odpbin0 -> 13293 bytes
-rw-r--r--chart2/source/view/axes/VCartesianAxis.cxx21
3 files changed, 76 insertions, 18 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 0b4f6d89303e..76fa05a57028 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -123,20 +123,15 @@ public:
void testTdf90510(); // Pie chart label placement settings(XLS)
void testTdf109858(); // Pie chart label placement settings(XLSX)
void testTdf130105();
-
void testTdf111173();
void testTdf122226();
-
void testInternalDataProvider();
-
void testTdf115107(); // import complex data point labels
void testTdf115107_2(); // import complex data point labels in cobo charts with multiple data series
-
void testTdf116163();
-
void testTdf48041();
-
void testTdf121205();
+ void testFixedSizeBarChartVeryLongLabel();
CPPUNIT_TEST_SUITE(Chart2ImportTest);
CPPUNIT_TEST(Fdo60083);
@@ -213,17 +208,13 @@ public:
CPPUNIT_TEST(testTdf130105);
CPPUNIT_TEST(testTdf111173);
CPPUNIT_TEST(testTdf122226);
-
CPPUNIT_TEST(testInternalDataProvider);
-
CPPUNIT_TEST(testTdf115107);
CPPUNIT_TEST(testTdf115107_2);
-
CPPUNIT_TEST(testTdf116163);
-
CPPUNIT_TEST(testTdf48041);
-
CPPUNIT_TEST(testTdf121205);
+ CPPUNIT_TEST(testFixedSizeBarChartVeryLongLabel);
CPPUNIT_TEST_SUITE_END();
};
@@ -2103,6 +2094,66 @@ void Chart2ImportTest::testTdf121205()
CPPUNIT_ASSERT_EQUAL(OUString("Firstline\nSecondline\nThirdline"), aTitle);
}
+void Chart2ImportTest::testFixedSizeBarChartVeryLongLabel()
+{
+ // Bar chart area size is fixed (not automatic) so we can't resize
+ // the chart area to let the label break into multiple lines. In this
+ // case the best course of action is to just crop the label text. This
+ // test checks that the rendered text is actually cropped.
+
+ load(u"/chart2/qa/extras/data/odp/", "FixedSizeBarChartVeryLongLabel.odp");
+
+ Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ Reference<chart2::XAxis> xHAxis = getAxisFromDoc(xChartDoc, 0, 0, 0);
+ CPPUNIT_ASSERT(xHAxis.is());
+
+ chart2::ScaleData aScaleData = xHAxis->getScaleData();
+ CPPUNIT_ASSERT(aScaleData.Categories.is());
+
+ Reference<chart2::data::XLabeledDataSequence> xLabeledDataSequence = aScaleData.Categories;
+ CPPUNIT_ASSERT(xLabeledDataSequence.is());
+
+ Reference<chart2::data::XDataSequence> xDataSequence = xLabeledDataSequence->getValues();
+ CPPUNIT_ASSERT(xDataSequence.is());
+
+ Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xDataSequence, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xTextualDataSequence.is());
+
+ std::vector<OUString> aCategories;
+ const Sequence<OUString> aTextData(xTextualDataSequence->getTextualData());
+ ::std::copy(aTextData.begin(), aTextData.end(),
+ ::std::back_inserter(aCategories));
+
+ // Check that we have a very very long label text
+ CPPUNIT_ASSERT_EQUAL(OUString("Very very very very very very very very very very very loooooooooooong label"), aCategories[0]);
+
+ // Check visible text
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xShapes.is());
+
+ uno::Reference<drawing::XShape> xXAxis = getShapeByName(xShapes, "CID/D=0:CS=0:Axis=0,0",
+ // Axis occurs twice in chart xshape representation so need to get the one related to labels
+ [](const uno::Reference<drawing::XShape>& rXShape) -> bool
+ {
+ uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xAxisShapes.is());
+ uno::Reference<drawing::XShape> xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xChildShape, uno::UNO_QUERY_THROW);
+ return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape");
+ });
+ CPPUNIT_ASSERT(xXAxis.is());
+
+ uno::Reference<container::XIndexAccess> xIndexAccess(xXAxis, UNO_QUERY_THROW);
+
+ // Check text is actually cropped
+ uno::Reference<text::XTextRange> xLabel(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("Very very very very..."), xLabel->getString());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp b/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp
new file mode 100644
index 000000000000..18869b638d1e
--- /dev/null
+++ b/chart2/qa/extras/data/odp/FixedSizeBarChartVeryLongLabel.odp
Binary files differ
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx
index cb053a7ce986..d42c811ae092 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -81,15 +81,20 @@ static void lcl_ResizeTextShapeToFitAvailableSpace( SvxShapeText& rShape2DText,
const tAnySequence& rPropValues,
const bool bIsHorizontalAxis )
{
- const sal_Int32 nFullSize = bIsHorizontalAxis ? rAxisLabelProperties.m_aFontReferenceSize.Height : rAxisLabelProperties.m_aFontReferenceSize.Width;
+ bool bTextHorizontal = rAxisLabelProperties.m_fRotationAngleDegree != 0.0;
+ bool bIsDirectionVertical = bIsHorizontalAxis && bTextHorizontal;
+ const sal_Int32 nFullSize = bIsDirectionVertical ? rAxisLabelProperties.m_aFontReferenceSize.Height : rAxisLabelProperties.m_aFontReferenceSize.Width;
if( !nFullSize || !rLabel.getLength() )
return;
- sal_Int32 nMaxLabelsSize = bIsHorizontalAxis ? rAxisLabelProperties.m_aMaximumSpaceForLabels.Height : rAxisLabelProperties.m_aMaximumSpaceForLabels.Width;
const sal_Int32 nAvgCharWidth = rShape2DText.getSize().Width / rLabel.getLength();
- const sal_Int32 nTextSize = bIsHorizontalAxis ? ShapeFactory::getSizeAfterRotation(rShape2DText, rAxisLabelProperties.m_fRotationAngleDegree).Height :
- ShapeFactory::getSizeAfterRotation(rShape2DText, rAxisLabelProperties.m_fRotationAngleDegree).Width;
+
+ sal_Int32 nMaxLabelsSize = bIsDirectionVertical ? rAxisLabelProperties.m_aMaximumSpaceForLabels.Height : rAxisLabelProperties.m_aMaximumSpaceForLabels.Width;
+
+ awt::Size aSizeAfterRotation = ShapeFactory::getSizeAfterRotation(rShape2DText, rAxisLabelProperties.m_fRotationAngleDegree);
+
+ const sal_Int32 nTextSize = bIsDirectionVertical ? aSizeAfterRotation.Height : aSizeAfterRotation.Width;
if( !nAvgCharWidth )
return;
@@ -857,10 +862,12 @@ bool VCartesianAxis::createTextShapes(
//create single label
if(!pTickInfo->xTextShape.is())
+ {
pTickInfo->xTextShape = createSingleLabel( xTarget
, aAnchorScreenPosition2D, aLabel
, rAxisLabelProperties, m_aAxisProperties
, aPropNames, aPropValues, bIsHorizontalAxis );
+ }
if(!pTickInfo->xTextShape.is())
continue;
@@ -1836,12 +1843,12 @@ void VCartesianAxis::createShapes()
if( !prepareShapeCreation() )
return;
- std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure
- TickFactory2D* pTickFactory2D = apTickFactory2D.get();
-
//create line shapes
if(m_nDimension==2)
{
+ std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure
+ TickFactory2D* pTickFactory2D = apTickFactory2D.get();
+
//create extra long ticks to separate complex categories (create them only there where the labels are)
if( isComplexCategoryAxis() )
{