summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2018-03-02 10:39:33 +0100
committerAndras Timar <andras.timar@collabora.com>2018-03-22 10:29:52 +0100
commit7b80e54640e20657402656614228998e0544a842 (patch)
tree0ecd6ab353d53fc6002a0615d77b83af526183f3 /chart2
parent2d8d36713790584b4ab7f5c94179bad05754b2ec (diff)
tdf#116163: Limit label height in chart if needed
Change-Id: Ia84fd0c3b76886bc6124dc3b59035465aa31b020 Reviewed-on: https://gerrit.libreoffice.org/50700 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/50913 Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2export.cxx11
-rw-r--r--chart2/qa/extras/data/pptx/tdf116163.pptxbin0 -> 47591 bytes
-rw-r--r--chart2/source/view/axes/VAxisProperties.cxx2
-rw-r--r--chart2/source/view/axes/VAxisProperties.hxx2
-rw-r--r--chart2/source/view/axes/VCartesianAxis.cxx50
-rw-r--r--chart2/source/view/axes/VCartesianCoordinateSystem.cxx2
-rw-r--r--chart2/source/view/axes/VCartesianCoordinateSystem.hxx3
-rw-r--r--chart2/source/view/axes/VCoordinateSystem.cxx1
-rw-r--r--chart2/source/view/axes/VPolarCoordinateSystem.cxx1
-rw-r--r--chart2/source/view/axes/VPolarCoordinateSystem.hxx3
-rw-r--r--chart2/source/view/inc/VCoordinateSystem.hxx3
-rw-r--r--chart2/source/view/main/ChartView.cxx2
12 files changed, 76 insertions, 4 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index bb90d5201167..9eca3309fac4 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -102,6 +102,7 @@ public:
void testAxisTitleRotationXLSX();
void testAxisCrossBetweenXSLX();
void testNumberFormatExportPPTX();
+ void testTdf116163();
CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(testErrorBarXLSX);
@@ -168,6 +169,7 @@ public:
CPPUNIT_TEST(testAxisTitleRotationXLSX);
CPPUNIT_TEST(testAxisCrossBetweenXSLX);
CPPUNIT_TEST(testNumberFormatExportPPTX);
+ CPPUNIT_TEST(testTdf116163);
CPPUNIT_TEST_SUITE_END();
protected:
@@ -1574,6 +1576,15 @@ void Chart2ExportTest::testNumberFormatExportPPTX()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:numFmt", "sourceLinked", "0");
}
+void Chart2ExportTest::testTdf116163()
+{
+ load("/chart2/qa/extras/data/pptx/", "tdf116163.pptx");
+ xmlDocPtr pXmlDoc = parseExport("ppt/charts/chart", "Impress MS PowerPoint 2007 XML");
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:bodyPr", "rot", "-5400000");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/pptx/tdf116163.pptx b/chart2/qa/extras/data/pptx/tdf116163.pptx
new file mode 100644
index 000000000000..5fbee8304a52
--- /dev/null
+++ b/chart2/qa/extras/data/pptx/tdf116163.pptx
Binary files differ
diff --git a/chart2/source/view/axes/VAxisProperties.cxx b/chart2/source/view/axes/VAxisProperties.cxx
index 786e8a3d73aa..89f933b0a2a9 100644
--- a/chart2/source/view/axes/VAxisProperties.cxx
+++ b/chart2/source/view/axes/VAxisProperties.cxx
@@ -175,6 +175,7 @@ AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel
, m_bComplexCategories(false)
, m_pExplicitCategoriesProvider(pExplicitCategoriesProvider)
, m_xAxisTextProvider(nullptr)
+ , m_bLimitSpaceForLabels(false)
{
}
@@ -201,6 +202,7 @@ AxisProperties::AxisProperties( const AxisProperties& rAxisProperties )
, m_bComplexCategories( rAxisProperties.m_bComplexCategories )
, m_pExplicitCategoriesProvider( rAxisProperties.m_pExplicitCategoriesProvider )
, m_xAxisTextProvider( rAxisProperties.m_xAxisTextProvider )
+ , m_bLimitSpaceForLabels( rAxisProperties.m_bLimitSpaceForLabels )
{
if( rAxisProperties.m_pfMainLinePositionAtOtherAxis )
m_pfMainLinePositionAtOtherAxis.reset(*rAxisProperties.m_pfMainLinePositionAtOtherAxis);
diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx
index 8948a91fe073..2ebbf3967450 100644
--- a/chart2/source/view/axes/VAxisProperties.hxx
+++ b/chart2/source/view/axes/VAxisProperties.hxx
@@ -137,6 +137,8 @@ struct AxisProperties final
css::uno::Reference<css::chart2::data::XTextualDataSequence> m_xAxisTextProvider; //for categories or series names
//<- category axes
+ bool m_bLimitSpaceForLabels;
+
//methods:
AxisProperties( const css::uno::Reference< css::chart2::XAxis >& xAxisModel
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx
index 89bd3536d2ce..156d764a6c28 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -75,6 +75,53 @@ VCartesianAxis::~VCartesianAxis()
m_pPosHelper = nullptr;
}
+void lcl_ResizeTextShapeToFitAvailableSpace( Reference< drawing::XShape >& xShape2DText,
+ const AxisLabelProperties& rAxisLabelProperties,
+ const OUString& rLabel,
+ const tNameSequence& rPropNames,
+ const tAnySequence& rPropValues )
+{
+ uno::Reference< text::XTextRange > xTextRange( xShape2DText, uno::UNO_QUERY );
+
+ if( !xTextRange.is() )
+ return;
+
+ const sal_Int32 nFullHeight = rAxisLabelProperties.m_aFontReferenceSize.Height;
+
+ if( !nFullHeight || !rLabel.getLength() )
+ return;
+
+ sal_Int32 nMaxLabelsHeight = nFullHeight - rAxisLabelProperties.m_aMaximumSpaceForLabels.Height - rAxisLabelProperties.m_aMaximumSpaceForLabels.Y;
+ const sal_Int32 nAvgCharWidth = xShape2DText->getSize().Width / rLabel.getLength();
+ const sal_Int32 nTextSize = AbstractShapeFactory::getSizeAfterRotation( xShape2DText,
+ rAxisLabelProperties.fRotationAngleDegree ).Height;
+
+ if( !nAvgCharWidth )
+ return;
+
+ const OUString sDots = "...";
+ const sal_Int32 nCharsToRemove = ( nTextSize - nMaxLabelsHeight ) / nAvgCharWidth + 1;
+ sal_Int32 nNewLen = rLabel.getLength() - nCharsToRemove - sDots.getLength();
+ // Prevent from showing only dots
+ if (nNewLen < 0)
+ nNewLen = ( rLabel.getLength() >= sDots.getLength() ) ? sDots.getLength() : rLabel.getLength();
+
+ bool bCrop = nCharsToRemove > 0;
+ if( bCrop )
+ {
+ OUString aNewLabel = rLabel.copy( 0, nNewLen );
+ if( nNewLen > sDots.getLength() )
+ aNewLabel += sDots;
+ xTextRange->setString( aNewLabel );
+
+ uno::Reference< beans::XPropertySet > xProp( xTextRange, uno::UNO_QUERY );
+ if( xProp.is() )
+ {
+ PropertyMapper::setMultiProperties( rPropNames, rPropValues, xProp );
+ }
+ }
+}
+
Reference< drawing::XShape > createSingleLabel(
const Reference< lang::XMultiServiceFactory>& xShapeFactory
, const Reference< drawing::XShapes >& xTarget
@@ -97,6 +144,9 @@ Reference< drawing::XShape > createSingleLabel(
Reference< drawing::XShape > xShape2DText = AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory)
->createText( xTarget, aLabel, rPropNames, rPropValues, aATransformation );
+ if( rAxisProperties.m_bLimitSpaceForLabels )
+ lcl_ResizeTextShapeToFitAvailableSpace(xShape2DText, rAxisLabelProperties, aLabel, rPropNames, rPropValues);
+
LabelPositionHelper::correctPositionForRotation( xShape2DText
, rAxisProperties.maLabelAlignment.meAlignment, rAxisLabelProperties.fRotationAngleDegree, rAxisProperties.m_bComplexCategories );
diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
index 934d17046ea3..aeab22fefea0 100644
--- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
@@ -94,6 +94,7 @@ void VCartesianCoordinateSystem::createVAxisList(
const uno::Reference<chart2::XChartDocument> & xChartDoc
, const awt::Size& rFontReferenceSize
, const awt::Rectangle& rMaximumSpaceForLabels
+ , bool bLimitSpaceForLabels
)
{
// note: using xChartDoc itself as XNumberFormatsSupplier would cause
@@ -126,6 +127,7 @@ void VCartesianCoordinateSystem::createVAxisList(
aAxisProperties.m_nDimensionIndex = nDimensionIndex;
aAxisProperties.m_bSwapXAndY = bSwapXAndY;
aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
+ aAxisProperties.m_bLimitSpaceForLabels = bLimitSpaceForLabels;
Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
if( xCrossingMainAxis.is() )
{
diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
index a7da0e2579a9..e4784badb9fd 100644
--- a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
+++ b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
@@ -34,7 +34,8 @@ public:
virtual void createVAxisList(
const css::uno::Reference< css::chart2::XChartDocument> &ChartDoc
, const css::awt::Size& rFontReferenceSize
- , const css::awt::Rectangle& rMaximumSpaceForLabels ) override;
+ , const css::awt::Rectangle& rMaximumSpaceForLabels
+ , bool bLimitSpaceForLabels ) override;
virtual void initVAxisInList() override;
virtual void updateScalesAndIncrementsOnAxes() override;
diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx
index 0cafa1560f5e..31051e354815 100644
--- a/chart2/source/view/axes/VCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCoordinateSystem.cxx
@@ -344,6 +344,7 @@ void VCoordinateSystem::createVAxisList(
const uno::Reference<chart2::XChartDocument> & /* xChartDoc */
, const awt::Size& /* rFontReferenceSize */
, const awt::Rectangle& /* rMaximumSpaceForLabels */
+ , bool /* bLimitSpaceForLabels */
)
{
}
diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.cxx b/chart2/source/view/axes/VPolarCoordinateSystem.cxx
index f0e20c47d898..7bac25f7d1af 100644
--- a/chart2/source/view/axes/VPolarCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VPolarCoordinateSystem.cxx
@@ -65,6 +65,7 @@ void VPolarCoordinateSystem::createVAxisList(
const uno::Reference<chart2::XChartDocument> & xChartDoc
, const awt::Size& rFontReferenceSize
, const awt::Rectangle& rMaximumSpaceForLabels
+ , bool //bLimitSpaceForLabels
)
{
// note: using xChartDoc itself as XNumberFormatsSupplier would cause
diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.hxx b/chart2/source/view/axes/VPolarCoordinateSystem.hxx
index bc93c717d017..7ab535b30e08 100644
--- a/chart2/source/view/axes/VPolarCoordinateSystem.hxx
+++ b/chart2/source/view/axes/VPolarCoordinateSystem.hxx
@@ -38,7 +38,8 @@ public:
virtual void createVAxisList(
const css::uno::Reference< css::chart2::XChartDocument> & xChartDoc
, const css::awt::Size& rFontReferenceSize
- , const css::awt::Rectangle& rMaximumSpaceForLabels ) override;
+ , const css::awt::Rectangle& rMaximumSpaceForLabels
+ , bool bLimitSpaceForLabels ) override;
virtual void initVAxisInList() override;
virtual void updateScalesAndIncrementsOnAxes() override;
diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx
index 9ce1c9a57f58..c6d8c33dcbb9 100644
--- a/chart2/source/view/inc/VCoordinateSystem.hxx
+++ b/chart2/source/view/inc/VCoordinateSystem.hxx
@@ -111,7 +111,8 @@ public:
virtual void createVAxisList(
const css::uno::Reference< css::chart2::XChartDocument> & xChartDoc
, const css::awt::Size& rFontReferenceSize
- , const css::awt::Rectangle& rMaximumSpaceForLabels );
+ , const css::awt::Rectangle& rMaximumSpaceForLabels
+ , bool bLimitSpaceForLabels );
virtual void initVAxisInList();
virtual void updateScalesAndIncrementsOnAxes();
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 67ad6e497e90..515c610bdd5c 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1602,7 +1602,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
pVCooSys->set3DWallPositions( eLeftWallPos, eBackWallPos, eBottomPos );
}
- pVCooSys->createVAxisList(xChartDoc, rPageSize, rParam.maRemainingSpace);
+ pVCooSys->createVAxisList(xChartDoc, rPageSize, rParam.maRemainingSpace, rParam.mbUseFixedInnerSize);
}
// - prepare list of all axis and how they are used