1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_SCALEAUTOMATISM_HXX
20 #define INCLUDED_CHART2_SOURCE_VIEW_INC_SCALEAUTOMATISM_HXX
22 #include <com/sun/star/chart2/ScaleData.hpp>
24 #include <tools/date.hxx>
26 namespace chart
{ struct ExplicitIncrementData
; }
27 namespace chart
{ struct ExplicitScaleData
; }
32 /** This class implements the calculation of automatic axis limits.
34 * This class is used for calculating axis scales and increments in the form
35 * of instances of `ExplicitScaleData` and `ExplicitIncrementData` classes.
36 * When a `ScaleAutomatism` instance is created a `ScaleData` object is passed
37 * to the constructor. Objects of `ScaleData` type are initialized by
38 * the `createCoordinateSystem` method of some chart type (e.g.
39 * the `PieChartType` class) and belong to some `Axis` object, they can be
40 * accessed through the `XAxis` interface (`XAxis::getScaleData`).
45 explicit ScaleAutomatism(
46 const css::chart2::ScaleData
& rSourceScale
, const Date
& rNullDate
);
48 /** Expands own value range with the passed minimum and maximum.
50 * It allows to set up the `m_fValueMinimum` and the `m_fValueMaximum`
51 * parameters which are used by the `calculateExplicitScaleAndIncrement`
52 * method for initializing the `Minimum` and `Maximum` properties of the
53 * explicit scale when the same properties of the `ScaleData` object are
54 * undefined (that is empty `uno::Any` objects).
56 void expandValueRange( double fMinimum
, double fMaximum
);
57 void resetValueRange();
59 /** Sets additional auto scaling options.
60 @param bExpandBorderToIncrementRhythm If true, expands automatic
61 borders to the fixed or calculated increment rhythm.
62 @param bExpandIfValuesCloseToBorder If true, expands automatic borders
63 if values are too close (closer than 1/21 of visible area).
64 @param bExpandWideValuesToZero If true, expands automatic border to
65 zero, if source values are positive only or negative only, and if
66 the absolute values are wide spread (at least one value is less
67 than 5/6 of absolute maximum), or if all values are equal.
68 @param bExpandNarrowValuesTowardZero If true, expands automatic border
69 toward zero (50% of the visible range), if source values are
70 positive only or negative only, and if the absolute values are
71 close to the absolute maximum (no value is less than 5/6 of
73 void setAutoScalingOptions(
74 bool bExpandBorderToIncrementRhythm
,
75 bool bExpandIfValuesCloseToBorder
,
76 bool bExpandWideValuesToZero
,
77 bool bExpandNarrowValuesTowardZero
);
79 /** Sets the maximum allowed number of automatic main increments.
80 @descr The number of main increments may be limited e.g. by the length
81 of the axis and the font size of the axis caption text. */
82 void setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount
);
84 /** Sets the time resolution to be used in case it is not set explicitly within the scale
86 void setAutomaticTimeResolution( sal_Int32 nTimeResolution
);
88 /** Fills the passed scale data and increment data according to the own settings.
90 * It performs the initialization of the passed explicit scale and
91 * explicit increment parameters, mainly the initialization is achieved by
92 * using the `ScaleData` object as data source. However other parameters
93 * which affect the behavior of this method can be set through
94 * the `setAutoScalingOptions` and the `expandValueRange` methods.
96 void calculateExplicitScaleAndIncrement(
97 ExplicitScaleData
& rExplicitScale
,
98 ExplicitIncrementData
& rExplicitIncrement
) const;
100 const css::chart2::ScaleData
& getScale() const { return m_aSourceScale
;}
101 const Date
& getNullDate() const { return m_aNullDate
;}
104 /** Fills the passed scale data and increment data for category scaling. */
105 void calculateExplicitIncrementAndScaleForCategory(
106 ExplicitScaleData
& rExplicitScale
,
107 ExplicitIncrementData
& rExplicitIncrement
,
108 bool bAutoMinimum
, bool bAutoMaximum
) const;
110 /** Fills the passed scale data and increment data for logarithmic scaling. */
111 void calculateExplicitIncrementAndScaleForLogarithmic(
112 ExplicitScaleData
& rExplicitScale
,
113 ExplicitIncrementData
& rExplicitIncrement
,
114 bool bAutoMinimum
, bool bAutoMaximum
) const;
116 /** Fills the passed scale data and increment data for linear scaling. */
117 void calculateExplicitIncrementAndScaleForLinear(
118 ExplicitScaleData
& rExplicitScale
,
119 ExplicitIncrementData
& rExplicitIncrement
,
120 bool bAutoMinimum
, bool bAutoMaximum
) const;
122 /** Fills the passed scale data and increment data for date-time axis. */
123 void calculateExplicitIncrementAndScaleForDateTimeAxis(
124 ExplicitScaleData
& rExplicitScale
,
125 ExplicitIncrementData
& rExplicitIncrement
,
126 bool bAutoMinimum
, bool bAutoMaximum
) const;
129 css::chart2::ScaleData m_aSourceScale
;
131 double m_fValueMinimum
; /// Minimum of all source values.
132 double m_fValueMaximum
; /// Maximum of all source values.
133 sal_Int32 m_nMaximumAutoMainIncrementCount
; /// Maximum number of automatic main increments.
134 bool m_bExpandBorderToIncrementRhythm
; /// true = Expand to main increments.
135 bool m_bExpandIfValuesCloseToBorder
; /// true = Expand if values are too close to the borders.
136 bool m_bExpandWideValuesToZero
; /// true = Expand wide spread values to zero.
137 bool m_bExpandNarrowValuesTowardZero
; /// true = Expand narrow range toward zero (add half of range).
138 sal_Int32 m_nTimeResolution
;// a constant out of css::chart::TimeUnit
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */