1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _CHART2_SCALEAUTOMATISM_HXX 24 #define _CHART2_SCALEAUTOMATISM_HXX 25 26 #include "chartview/ExplicitScaleValues.hxx" 27 #include <com/sun/star/chart2/ScaleData.hpp> 28 29 #include <tools/date.hxx> 30 31 //............................................................................. 32 namespace chart 33 { 34 //............................................................................. 35 36 //----------------------------------------------------------------------------- 37 38 /** This class implements the calculation of automatic axis limits. 39 */ 40 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 void expandValueRange( double fMinimum, double fMaximum ); 49 50 /** Sets additional auto scaling options. 51 @param bExpandBorderToIncrementRhythm If true, expands automatic 52 borders to the fixed or calculated increment rhythm. 53 @param bExpandIfValuesCloseToBorder If true, expands automatic borders 54 if values are too close (closer than 1/21 of visible area). 55 @param bExpandWideValuesToZero If true, expands automatic border to 56 zero, if source values are positive only or negative only, and if 57 the absolute values are wide spread (at least one value is less 58 than 5/6 of absolute maximum), or if all values are equal. 59 @param bExpandNarrowValuesTowardZero If true, expands automatic border 60 toward zero (50% of the visible range), if source values are 61 positive only or negative only, and if the absolute values are 62 close to the absolute maximum (no value is less than 5/6 of 63 absolute maximum). */ 64 void setAutoScalingOptions( 65 bool bExpandBorderToIncrementRhythm, 66 bool bExpandIfValuesCloseToBorder, 67 bool bExpandWideValuesToZero, 68 bool bExpandNarrowValuesTowardZero ); 69 70 /** Sets the maximum allowed number of automatic main increments. 71 @descr The number of main increments may be limited e.g. by the length 72 of the axis and the font size of the axis caption text. */ 73 void setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount ); 74 75 /** Sets the time resolution to be used in case it is not set explicitly within the scale 76 */ 77 void setAutomaticTimeResolution( sal_Int32 nTimeResolution ); 78 79 /** Fills the passed scale data and increment data according to the own settings. */ 80 void calculateExplicitScaleAndIncrement( 81 ExplicitScaleData& rExplicitScale, 82 ExplicitIncrementData& rExplicitIncrement ) const; 83 84 ::com::sun::star::chart2::ScaleData getScale() const; 85 Date getNullDate() const; 86 87 private: 88 /** Fills the passed scale data and increment data for category scaling. */ 89 void calculateExplicitIncrementAndScaleForCategory( 90 ExplicitScaleData& rExplicitScale, 91 ExplicitIncrementData& rExplicitIncrement, 92 bool bAutoMinimum, bool bAutoMaximum ) const; 93 94 /** Fills the passed scale data and increment data for logarithmic scaling. */ 95 void calculateExplicitIncrementAndScaleForLogarithmic( 96 ExplicitScaleData& rExplicitScale, 97 ExplicitIncrementData& rExplicitIncrement, 98 bool bAutoMinimum, bool bAutoMaximum ) const; 99 100 /** Fills the passed scale data and increment data for linear scaling. */ 101 void calculateExplicitIncrementAndScaleForLinear( 102 ExplicitScaleData& rExplicitScale, 103 ExplicitIncrementData& rExplicitIncrement, 104 bool bAutoMinimum, bool bAutoMaximum ) const; 105 106 /** Fills the passed scale data and increment data for date-time axis. */ 107 void calculateExplicitIncrementAndScaleForDateTimeAxis( 108 ExplicitScaleData& rExplicitScale, 109 ExplicitIncrementData& rExplicitIncrement, 110 bool bAutoMinimum, bool bAutoMaximum ) const; 111 112 private: 113 ::com::sun::star::chart2::ScaleData m_aSourceScale; 114 115 double m_fValueMinimum; /// Minimum of all source values. 116 double m_fValueMaximum; /// Maximum of all source values. 117 sal_Int32 m_nMaximumAutoMainIncrementCount; /// Maximum number of automatic main increments. 118 bool m_bExpandBorderToIncrementRhythm; /// true = Expand to main increments. 119 bool m_bExpandIfValuesCloseToBorder; /// true = Expand if values are too close to the borders. 120 bool m_bExpandWideValuesToZero; /// true = Expand wide spread values to zero. 121 bool m_bExpandNarrowValuesTowardZero; /// true = Expand narrow range toward zero (add half of range). 122 sal_Int32 m_nTimeResolution;// a constant out of ::com::sun::star::chart::TimeUnit 123 124 Date m_aNullDate; 125 }; 126 127 //............................................................................. 128 } //namespace chart 129 //............................................................................. 130 #endif 131