From 38bf5f69663f64434a3a0a74e02c1a23f876b677 Mon Sep 17 00:00:00 2001 From: Jochen Nitschke Date: Tue, 6 Jun 2017 11:19:50 +0200 Subject: tdf#108031 Area chart labels not rotated This fixes recognition of x-axis or y-axis when the coordinate system is rotated (3D-view). So the labels are rotated correctly. Change-Id: Iaacfec943f3885c58e99a55585714a79f1d0d9d5 Reviewed-on: https://gerrit.libreoffice.org/38355 Reviewed-by: Jochen Nitschke Tested-by: Jochen Nitschke --- chart2/source/view/axes/Tickmarks.cxx | 21 ++++++++++++++++++--- chart2/source/view/axes/VCartesianAxis.cxx | 26 +++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'chart2') diff --git a/chart2/source/view/axes/Tickmarks.cxx b/chart2/source/view/axes/Tickmarks.cxx index 95f967b3b215..3d6d25a044bf 100644 --- a/chart2/source/view/axes/Tickmarks.cxx +++ b/chart2/source/view/axes/Tickmarks.cxx @@ -172,13 +172,28 @@ TickFactory2D::~TickFactory2D() bool TickFactory2D::isHorizontalAxis() const { - return ( m_aAxisStartScreenPosition2D.getY() == m_aAxisEndScreenPosition2D.getY() ); + // check trivial cases: + if ( m_aAxisStartScreenPosition2D.getY() == m_aAxisEndScreenPosition2D.getY() ) + return true; + if ( m_aAxisStartScreenPosition2D.getX() == m_aAxisEndScreenPosition2D.getX() ) + return false; + + // for skew axes compare angle with horizontal vector + double fInclination = std::abs(B2DVector(m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D).angle(B2DVector(1.0, 0.0))); + return fInclination < F_PI4 || fInclination > (F_PI-F_PI4); } bool TickFactory2D::isVerticalAxis() const { - return ( m_aAxisStartScreenPosition2D.getX() == m_aAxisEndScreenPosition2D.getX() ); + // check trivial cases: + if ( m_aAxisStartScreenPosition2D.getX() == m_aAxisEndScreenPosition2D.getX() ) + return true; + if ( m_aAxisStartScreenPosition2D.getY() == m_aAxisEndScreenPosition2D.getY() ) + return false; + + // for skew axes compare angle with vertical vector + double fInclination = std::abs(B2DVector(m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D).angle(B2DVector(0.0, -1.0))); + return fInclination < F_PI4 || fInclination > (F_PI-F_PI4); } - //static sal_Int32 TickFactory2D::getTickScreenDistance( TickIter& rIter ) { diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index c53f890a07a6..9493102a93c4 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -104,25 +104,13 @@ Reference< drawing::XShape > createSingleLabel( bool lcl_doesShapeOverlapWithTickmark( const Reference< drawing::XShape >& xShape , double fRotationAngleDegree - , const basegfx::B2DVector& rTickScreenPosition - , bool bIsHorizontalAxis, bool bIsVerticalAxis ) + , const basegfx::B2DVector& rTickScreenPosition ) { if(!xShape.is()) return false; ::basegfx::B2IRectangle aShapeRect = BaseGFXHelper::makeRectangle(xShape->getPosition(),AbstractShapeFactory::getSizeAfterRotation( xShape, fRotationAngleDegree )); - if( bIsVerticalAxis ) - { - return ( (rTickScreenPosition.getY() >= aShapeRect.getMinY()) - && (rTickScreenPosition.getY() <= aShapeRect.getMaxY()) ); - } - if( bIsHorizontalAxis ) - { - return ( (rTickScreenPosition.getX() >= aShapeRect.getMinX()) - && (rTickScreenPosition.getX() <= aShapeRect.getMaxX()) ); - } - basegfx::B2IVector aPosition( static_cast( rTickScreenPosition.getX() ) , static_cast( rTickScreenPosition.getY() ) ); @@ -744,8 +732,7 @@ bool VCartesianAxis::createTextShapes( if( lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape , rAxisLabelProperties.fRotationAngleDegree - , pTickInfo->aTickScreenPosition - , bIsHorizontalAxis, bIsVerticalAxis ) ) + , pTickInfo->aTickScreenPosition ) ) { // This tick overlaps with its neighbor. Try to stagger (if // auto staggering is allowed) to avoid overlapping. @@ -759,8 +746,7 @@ bool VCartesianAxis::createTextShapes( if( !pLastVisibleNeighbourTickInfo || !lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape , rAxisLabelProperties.fRotationAngleDegree - , pTickInfo->aTickScreenPosition - , bIsHorizontalAxis, bIsVerticalAxis ) ) + , pTickInfo->aTickScreenPosition ) ) bOverlapsAfterAutoStagger = false; } @@ -841,8 +827,7 @@ bool VCartesianAxis::createTextShapes( if( !pLastVisibleNeighbourTickInfo || !lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape , rAxisLabelProperties.fRotationAngleDegree - , pTickInfo->aTickScreenPosition - , bIsHorizontalAxis, bIsVerticalAxis ) ) + , pTickInfo->aTickScreenPosition ) ) bOverlapsAfterAutoStagger = false; } } @@ -933,8 +918,7 @@ bool VCartesianAxis::createTextShapesSimple( if( lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape , rAxisLabelProperties.fRotationAngleDegree - , pTickInfo->aTickScreenPosition - , bIsHorizontalAxis, bIsVerticalAxis ) ) + , pTickInfo->aTickScreenPosition ) ) { // This tick overlaps with its neighbor. Increment the visible // tick intervals (if that's allowed) and start over. -- cgit