1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CHART2_SCALEAUTOMATISM_HXX
28 #define _CHART2_SCALEAUTOMATISM_HXX
29 
30 #include "chartview/ExplicitScaleValues.hxx"
31 #include <com/sun/star/chart2/ScaleData.hpp>
32 
33 #include <tools/date.hxx>
34 
35 //.............................................................................
36 namespace chart
37 {
38 //.............................................................................
39 
40 //-----------------------------------------------------------------------------
41 
42 /** This class implements the calculation of automatic axis limits.
43 */
44 class ScaleAutomatism
45 {
46 public:
47     explicit            ScaleAutomatism(
48                             const ::com::sun::star::chart2::ScaleData& rSourceScale, const Date& rNullDate );
49     virtual             ~ScaleAutomatism();
50 
51     /** Expands own value range with the passed minimum and maximum. */
52     void                expandValueRange( double fMinimum, double fMaximum );
53 
54     /** Sets additional auto scaling options.
55         @param bExpandBorderToIncrementRhythm  If true, expands automatic
56             borders to the fixed or calculated increment rhythm.
57         @param bExpandIfValuesCloseToBorder  If true, expands automatic borders
58             if values are too close (closer than 1/21 of visible area).
59         @param bExpandWideValuesToZero  If true, expands automatic border to
60             zero, if source values are positive only or negative only, and if
61             the absolute values are wide spread (at least one value is less
62             than 5/6 of absolute maximum), or if all values are equal.
63         @param bExpandNarrowValuesTowardZero  If true, expands automatic border
64             toward zero (50% of the visible range), if source values are
65             positive only or negative only, and if the absolute values are
66             close to the absolute maximum (no value is less than 5/6 of
67             absolute maximum). */
68     void                setAutoScalingOptions(
69                             bool bExpandBorderToIncrementRhythm,
70                             bool bExpandIfValuesCloseToBorder,
71                             bool bExpandWideValuesToZero,
72                             bool bExpandNarrowValuesTowardZero );
73 
74     /** Sets the maximum allowed number of automatic main increments.
75         @descr  The number of main increments may be limited e.g. by the length
76                 of the axis and the font size of the axis caption text. */
77     void                setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount );
78 
79     /** Sets the time resolution to be used in case it is not set explicitly within the scale
80     */
81     void setAutomaticTimeResolution( sal_Int32 nTimeResolution );
82 
83     /** Fills the passed scale data and increment data according to the own settings. */
84     void                calculateExplicitScaleAndIncrement(
85                             ExplicitScaleData& rExplicitScale,
86                             ExplicitIncrementData& rExplicitIncrement ) const;
87 
88     ::com::sun::star::chart2::ScaleData getScale() const;
89     Date getNullDate() const;
90 
91 private:
92     /** Fills the passed scale data and increment data for category scaling. */
93     void                calculateExplicitIncrementAndScaleForCategory(
94                             ExplicitScaleData& rExplicitScale,
95                             ExplicitIncrementData& rExplicitIncrement,
96                             bool bAutoMinimum, bool bAutoMaximum ) const;
97 
98     /** Fills the passed scale data and increment data for logarithmic scaling. */
99     void                calculateExplicitIncrementAndScaleForLogarithmic(
100                             ExplicitScaleData& rExplicitScale,
101                             ExplicitIncrementData& rExplicitIncrement,
102                             bool bAutoMinimum, bool bAutoMaximum ) const;
103 
104     /** Fills the passed scale data and increment data for linear scaling. */
105     void                calculateExplicitIncrementAndScaleForLinear(
106                             ExplicitScaleData& rExplicitScale,
107                             ExplicitIncrementData& rExplicitIncrement,
108                             bool bAutoMinimum, bool bAutoMaximum ) const;
109 
110     /** Fills the passed scale data and increment data for date-time axis. */
111     void                calculateExplicitIncrementAndScaleForDateTimeAxis(
112                             ExplicitScaleData& rExplicitScale,
113                             ExplicitIncrementData& rExplicitIncrement,
114                             bool bAutoMinimum, bool bAutoMaximum ) const;
115 
116 private:
117     ::com::sun::star::chart2::ScaleData             m_aSourceScale;
118 
119     double              m_fValueMinimum;                    /// Minimum of all source values.
120     double              m_fValueMaximum;                    /// Maximum of all source values.
121     sal_Int32           m_nMaximumAutoMainIncrementCount;   /// Maximum number of automatic main increments.
122     bool                m_bExpandBorderToIncrementRhythm;   /// true = Expand to main increments.
123     bool                m_bExpandIfValuesCloseToBorder;     /// true = Expand if values are too close to the borders.
124     bool                m_bExpandWideValuesToZero;          /// true = Expand wide spread values to zero.
125     bool                m_bExpandNarrowValuesTowardZero;    /// true = Expand narrow range toward zero (add half of range).
126     sal_Int32           m_nTimeResolution;// a constant out of ::com::sun::star::chart::TimeUnit
127 
128     Date                m_aNullDate;
129 };
130 
131 //.............................................................................
132 } //namespace chart
133 //.............................................................................
134 #endif
135