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 #pragma once 20 21 #include <com/sun/star/chart2/ScaleData.hpp> 22 23 #include <tools/date.hxx> 24 25 namespace chart { struct ExplicitIncrementData; } 26 namespace chart { struct ExplicitScaleData; } 27 28 namespace chart 29 { 30 31 /** This class implements the calculation of automatic axis limits. 32 * 33 * This class is used for calculating axis scales and increments in the form 34 * of instances of `ExplicitScaleData` and `ExplicitIncrementData` classes. 35 * When a `ScaleAutomatism` instance is created a `ScaleData` object is passed 36 * to the constructor. Objects of `ScaleData` type are initialized by 37 * the `createCoordinateSystem` method of some chart type (e.g. 38 * the `PieChartType` class) and belong to some `Axis` object, they can be 39 * accessed through the `XAxis` interface (`XAxis::getScaleData`). 40 */ 41 class ScaleAutomatism 42 { 43 public: 44 explicit ScaleAutomatism( 45 const css::chart2::ScaleData& rSourceScale, const Date& rNullDate ); 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 void resetValueRange(); 57 58 /** Sets additional auto scaling options. 59 @param bExpandBorderToIncrementRhythm If true, expands automatic 60 borders to the fixed or calculated increment rhythm. 61 @param bExpandIfValuesCloseToBorder If true, expands automatic borders 62 if values are too close (closer than 1/21 of visible area). 63 @param bExpandWideValuesToZero If true, expands automatic border to 64 zero, if source values are positive only or negative only, and if 65 the absolute values are wide spread (at least one value is less 66 than 5/6 of absolute maximum), or if all values are equal. 67 @param bExpandNarrowValuesTowardZero If true, expands automatic border 68 toward zero (50% of the visible range), if source values are 69 positive only or negative only, and if the absolute values are 70 close to the absolute maximum (no value is less than 5/6 of 71 absolute maximum). */ 72 void setAutoScalingOptions( 73 bool bExpandBorderToIncrementRhythm, 74 bool bExpandIfValuesCloseToBorder, 75 bool bExpandWideValuesToZero, 76 bool bExpandNarrowValuesTowardZero ); 77 78 /** Sets the maximum allowed number of automatic main increments. 79 @descr The number of main increments may be limited e.g. by the length 80 of the axis and the font size of the axis caption text. */ 81 void setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount ); 82 83 /** Sets the time resolution to be used in case it is not set explicitly within the scale 84 */ 85 void setAutomaticTimeResolution( sal_Int32 nTimeResolution ); 86 87 /** Fills the passed scale data and increment data according to the own settings. 88 * 89 * It performs the initialization of the passed explicit scale and 90 * explicit increment parameters, mainly the initialization is achieved by 91 * using the `ScaleData` object as data source. However other parameters 92 * which affect the behavior of this method can be set through 93 * the `setAutoScalingOptions` and the `expandValueRange` methods. 94 */ 95 void calculateExplicitScaleAndIncrement( 96 ExplicitScaleData& rExplicitScale, 97 ExplicitIncrementData& rExplicitIncrement ) const; 98 getScale() const99 const css::chart2::ScaleData& getScale() const { return m_aSourceScale;} getNullDate() const100 const Date& getNullDate() const { return m_aNullDate;} 101 102 private: 103 /** Fills the passed scale data and increment data for category scaling. */ 104 void calculateExplicitIncrementAndScaleForCategory( 105 ExplicitScaleData& rExplicitScale, 106 ExplicitIncrementData& rExplicitIncrement, 107 bool bAutoMinimum, bool bAutoMaximum ) const; 108 109 /** Fills the passed scale data and increment data for logarithmic scaling. */ 110 void calculateExplicitIncrementAndScaleForLogarithmic( 111 ExplicitScaleData& rExplicitScale, 112 ExplicitIncrementData& rExplicitIncrement, 113 bool bAutoMinimum, bool bAutoMaximum ) const; 114 115 /** Fills the passed scale data and increment data for linear scaling. */ 116 void calculateExplicitIncrementAndScaleForLinear( 117 ExplicitScaleData& rExplicitScale, 118 ExplicitIncrementData& rExplicitIncrement, 119 bool bAutoMinimum, bool bAutoMaximum ) const; 120 121 /** Fills the passed scale data and increment data for date-time axis. */ 122 void calculateExplicitIncrementAndScaleForDateTimeAxis( 123 ExplicitScaleData& rExplicitScale, 124 ExplicitIncrementData& rExplicitIncrement, 125 bool bAutoMinimum, bool bAutoMaximum ) const; 126 127 private: 128 css::chart2::ScaleData m_aSourceScale; 129 130 double m_fValueMinimum; /// Minimum of all source values. 131 double m_fValueMaximum; /// Maximum of all source values. 132 sal_Int32 m_nMaximumAutoMainIncrementCount; /// Maximum number of automatic main increments. 133 bool m_bExpandBorderToIncrementRhythm; /// true = Expand to main increments. 134 bool m_bExpandIfValuesCloseToBorder; /// true = Expand if values are too close to the borders. 135 bool m_bExpandWideValuesToZero; /// true = Expand wide spread values to zero. 136 bool m_bExpandNarrowValuesTowardZero; /// true = Expand narrow range toward zero (add half of range). 137 sal_Int32 m_nTimeResolution;// a constant out of css::chart::TimeUnit 138 139 Date m_aNullDate; 140 }; 141 142 } //namespace chart 143 144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 145