Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_SCALEAUTOMATISM_HXX
20 : #define INCLUDED_CHART2_SOURCE_VIEW_INC_SCALEAUTOMATISM_HXX
21 :
22 : #include "chartview/ExplicitScaleValues.hxx"
23 : #include <com/sun/star/chart2/ScaleData.hpp>
24 :
25 : #include <tools/date.hxx>
26 :
27 : namespace chart
28 : {
29 :
30 : /** This class implements the calculation of automatic axis limits.
31 : *
32 : * This class is used for calculating axis scales and increments in the form
33 : * of instances of `ExplicitScaleData` and `ExplicitIncrementData` classes.
34 : * When a `ScaleAutomatism` instance is created a `ScaleData` object is passed
35 : * to the constructor. Objects of `ScaleData` type are initialized by
36 : * the `createCoordinateSystem` method of some chart type (e.g.
37 : * the `PieChartType` class) and belong to some `Axis` object, they can be
38 : * accessed through the `XAxis` interface (`XAxis::getScaleData`).
39 : */
40 2209 : class ScaleAutomatism
41 : {
42 : public:
43 : explicit ScaleAutomatism(
44 : const ::com::sun::star::chart2::ScaleData& rSourceScale, const Date& rNullDate );
45 : virtual ~ScaleAutomatism();
46 :
47 : /** Expands own value range with the passed minimum and maximum.
48 : *
49 : * It allows to set up the `m_fValueMinimum` and the `m_fValueMaximum`
50 : * parameters which are used by the `calculateExplicitScaleAndIncrement`
51 : * method for initializing the `Minimum` and `Maximum` properties of the
52 : * explicit scale when the same properties of the `ScaleData` object are
53 : * undefined (that is empty `uno::Any` objects).
54 : */
55 : void expandValueRange( double fMinimum, double fMaximum );
56 :
57 : /** Sets additional auto scaling options.
58 : @param bExpandBorderToIncrementRhythm If true, expands automatic
59 : borders to the fixed or calculated increment rhythm.
60 : @param bExpandIfValuesCloseToBorder If true, expands automatic borders
61 : if values are too close (closer than 1/21 of visible area).
62 : @param bExpandWideValuesToZero If true, expands automatic border to
63 : zero, if source values are positive only or negative only, and if
64 : the absolute values are wide spread (at least one value is less
65 : than 5/6 of absolute maximum), or if all values are equal.
66 : @param bExpandNarrowValuesTowardZero If true, expands automatic border
67 : toward zero (50% of the visible range), if source values are
68 : positive only or negative only, and if the absolute values are
69 : close to the absolute maximum (no value is less than 5/6 of
70 : absolute maximum). */
71 : void setAutoScalingOptions(
72 : bool bExpandBorderToIncrementRhythm,
73 : bool bExpandIfValuesCloseToBorder,
74 : bool bExpandWideValuesToZero,
75 : bool bExpandNarrowValuesTowardZero );
76 :
77 : /** Sets the maximum allowed number of automatic main increments.
78 : @descr The number of main increments may be limited e.g. by the length
79 : of the axis and the font size of the axis caption text. */
80 : void setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount );
81 :
82 : /** Sets the time resolution to be used in case it is not set explicitly within the scale
83 : */
84 : void setAutomaticTimeResolution( sal_Int32 nTimeResolution );
85 :
86 : /** Fills the passed scale data and increment data according to the own settings.
87 : *
88 : * It performs the initialization of the passed explicit scale and
89 : * explicit increment parameters, mainly the initialization is achieved by
90 : * using the `ScaleData` object as data source. However other parameters
91 : * which affect the behavior of this method can be set through
92 : * the `setAutoScalingOptions` and the `expandValueRange` methods.
93 : */
94 : void calculateExplicitScaleAndIncrement(
95 : ExplicitScaleData& rExplicitScale,
96 : ExplicitIncrementData& rExplicitIncrement ) const;
97 :
98 4346 : ::com::sun::star::chart2::ScaleData getScale() const { return m_aSourceScale;}
99 0 : Date getNullDate() const { return m_aNullDate;}
100 :
101 : private:
102 : /** Fills the passed scale data and increment data for category scaling. */
103 : void calculateExplicitIncrementAndScaleForCategory(
104 : ExplicitScaleData& rExplicitScale,
105 : ExplicitIncrementData& rExplicitIncrement,
106 : bool bAutoMinimum, bool bAutoMaximum ) const;
107 :
108 : /** Fills the passed scale data and increment data for logarithmic scaling. */
109 : void calculateExplicitIncrementAndScaleForLogarithmic(
110 : ExplicitScaleData& rExplicitScale,
111 : ExplicitIncrementData& rExplicitIncrement,
112 : bool bAutoMinimum, bool bAutoMaximum ) const;
113 :
114 : /** Fills the passed scale data and increment data for linear scaling. */
115 : void calculateExplicitIncrementAndScaleForLinear(
116 : ExplicitScaleData& rExplicitScale,
117 : ExplicitIncrementData& rExplicitIncrement,
118 : bool bAutoMinimum, bool bAutoMaximum ) const;
119 :
120 : /** Fills the passed scale data and increment data for date-time axis. */
121 : void calculateExplicitIncrementAndScaleForDateTimeAxis(
122 : ExplicitScaleData& rExplicitScale,
123 : ExplicitIncrementData& rExplicitIncrement,
124 : bool bAutoMinimum, bool bAutoMaximum ) const;
125 :
126 : private:
127 : ::com::sun::star::chart2::ScaleData m_aSourceScale;
128 :
129 : double m_fValueMinimum; /// Minimum of all source values.
130 : double m_fValueMaximum; /// Maximum of all source values.
131 : sal_Int32 m_nMaximumAutoMainIncrementCount; /// Maximum number of automatic main increments.
132 : bool m_bExpandBorderToIncrementRhythm; /// true = Expand to main increments.
133 : bool m_bExpandIfValuesCloseToBorder; /// true = Expand if values are too close to the borders.
134 : bool m_bExpandWideValuesToZero; /// true = Expand wide spread values to zero.
135 : bool m_bExpandNarrowValuesTowardZero; /// true = Expand narrow range toward zero (add half of range).
136 : sal_Int32 m_nTimeResolution;// a constant out of ::com::sun::star::chart::TimeUnit
137 :
138 : Date m_aNullDate;
139 : };
140 :
141 : } //namespace chart
142 : #endif
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|