chart2/source/view/axes/VCartesianAxis.cxx |   34 ++++++++++++++++++++---------
 chart2/source/view/axes/VCartesianAxis.hxx |    7 -----
 2 files changed, 24 insertions(+), 17 deletions(-)

New commits:
commit 99226f343e4ad9ebcbb4e31c17d3fb706153e18b
Author: Jochen Nitschke <j.nitschke+loger...@ok.de>
Date:   Sun Jun 5 22:45:43 2016 +0200

    try auto rotate tick labels only when useful tdf#99883
    
    By default we try to fit as many tick labels as possible on an axis.
    One way is (auto) rotating the labels at 45 degrees.
    
    But rotating only works for horizontal axes with horizontal text or
    vertical axes with vertical text, else rotated tick labels need more space.
    
    Join the check for this prerequisite with isAutoStaggeringOfLabelsAllowed.
    
    while here make isAutoStaggeringOfLabelsAllowed local
    and wrap stuff in anonymous namespaces
    
    Change-Id: I5784d0e5aa42ff90927e19d0bd2c6fed488d39f4
    Reviewed-on: https://gerrit.libreoffice.org/25792
    Reviewed-by: Jochen Nitschke <j.nitschke+loger...@ok.de>
    Tested-by: Jochen Nitschke <j.nitschke+loger...@ok.de>

diff --git a/chart2/source/view/axes/VCartesianAxis.cxx 
b/chart2/source/view/axes/VCartesianAxis.cxx
index 59a4972..97912a5 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -497,20 +497,21 @@ bool VCartesianAxis::isBreakOfLabelsAllowed(
     //break only for horizontal axis
     return bIsHorizontalAxis;
 }
+namespace{
 
-bool VCartesianAxis::isAutoStaggeringOfLabelsAllowed(
-    const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis, 
bool bIsVerticalAxis )
+bool canAutoAdjustLabelPlacement(
+    const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis, 
bool bIsVerticalAxis)
 {
-    if( rAxisLabelProperties.eStaggering != STAGGER_AUTO )
-        return false;
+    // joined prerequisite checks for auto rotate and auto stagger
     if( rAxisLabelProperties.bOverlapAllowed )
         return false;
-    if( rAxisLabelProperties.bLineBreakAllowed ) //auto line break or auto 
staggering, doing both automatisms they may conflict...
+    if( rAxisLabelProperties.bLineBreakAllowed ) // auto line break may 
conflict with...
         return false;
     if( !::rtl::math::approxEqual( rAxisLabelProperties.fRotationAngleDegree, 
0.0 ) )
         return false;
-    //automatic staggering only for horizontal axis with horizontal text
-    //or vertical axis with vertical text
+    // automatic adjusting labels only works for
+    // horizontal axis with horizontal text
+    // or vertical axis with vertical text
     if( bIsHorizontalAxis )
         return !rAxisLabelProperties.bStackCharacters;
     if( bIsVerticalAxis )
@@ -518,6 +519,18 @@ bool VCartesianAxis::isAutoStaggeringOfLabelsAllowed(
     return false;
 }
 
+bool isAutoStaggeringOfLabelsAllowed(
+    const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis, 
bool bIsVerticalAxis )
+{
+    if( rAxisLabelProperties.eStaggering != STAGGER_AUTO )
+        return false;
+    return canAutoAdjustLabelPlacement(rAxisLabelProperties, 
bIsHorizontalAxis, bIsVerticalAxis);
+}
+
+// make clear that we check for auto rotation prerequisites
+const auto& isAutoRotatingOfLabelsAllowed = canAutoAdjustLabelPlacement;
+
+} // namespace
 void VCartesianAxis::createAllTickInfosFromComplexCategories( 
TickInfoArraysType& rAllTickInfos, bool bShiftedPosition )
 {
     //no minor tickmarks will be generated!
@@ -827,7 +840,8 @@ bool VCartesianAxis::createTextShapes(
                 {
                     // Compatibility option: starting from LibreOffice 5.1 the 
rotated
                     // layout is preferred to staggering for axis labels.
-                    if( m_aAxisProperties.m_bTryStaggeringFirst || 
!(::rtl::math::approxEqual( rAxisLabelProperties.fRotationAngleDegree, 0.0 ) ) )
+                    if( !isAutoRotatingOfLabelsAllowed(rAxisLabelProperties, 
bIsHorizontalAxis, bIsVerticalAxis)
+                        || m_aAxisProperties.m_bTryStaggeringFirst )
                     {
                         bIsStaggered = true;
                         rAxisLabelProperties.eStaggering = STAGGER_EVEN;
@@ -844,7 +858,7 @@ bool VCartesianAxis::createTextShapes(
                 if (bOverlapsAfterAutoStagger)
                 {
                     // Staggering didn't solve the overlap.
-                    if( !rAxisLabelProperties.bOverlapAllowed && 
::rtl::math::approxEqual( rAxisLabelProperties.fRotationAngleDegree, 0.0 ) )
+                    if( isAutoRotatingOfLabelsAllowed(rAxisLabelProperties, 
bIsHorizontalAxis, bIsVerticalAxis) )
                     {
                         // Try auto-rotating the labels at 45 degrees and
                         // start over.  This rotation angle will be stored for
@@ -986,7 +1000,7 @@ bool VCartesianAxis::createTextShapesSimple(
             if( doesOverlap( pLastVisibleNeighbourTickInfo->xTextShape, 
pTickInfo->xTextShape, rAxisLabelProperties.fRotationAngleDegree ) )
             {
                 // It overlaps.
-                if( !rAxisLabelProperties.bOverlapAllowed && 
::rtl::math::approxEqual( rAxisLabelProperties.fRotationAngleDegree, 0.0 ) )
+                if( isAutoRotatingOfLabelsAllowed(rAxisLabelProperties, 
bIsHorizontalAxis, bIsVerticalAxis) )
                 {
                     // Try auto-rotating the labels at 45 degrees and
                     // start over.  This rotation angle will be stored for
diff --git a/chart2/source/view/axes/VCartesianAxis.hxx 
b/chart2/source/view/axes/VCartesianAxis.hxx
index 8ba89a4..61c14d4 100644
--- a/chart2/source/view/axes/VCartesianAxis.hxx
+++ b/chart2/source/view/axes/VCartesianAxis.hxx
@@ -147,13 +147,6 @@ private: //methods
                             , TickFactory2D* pTickFactory2D );
 
     /**
-     * @return true if we can try to stagger labels in order to avoid
-     *         overlaps, otherwise false.
-     */
-    static bool isAutoStaggeringOfLabelsAllowed(
-        const AxisLabelProperties& rAxisLabelProperties, bool 
bIsHorizontalAxis, bool bIsVerticalAxis );
-
-    /**
      * @return true if we can break a single line label text into multiple
      *         lines for better fitting, otherwise false.
      */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to