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