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
24
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_chart2.hxx"
27 #include "CategoryPositionHelper.hxx"
28
29 //.............................................................................
30 namespace chart
31 {
32 //.............................................................................
33 //using namespace ::com::sun::star;
34 //using namespace ::com::sun::star::chart2;
35
CategoryPositionHelper(double fSeriesCount,double fCategoryWidth)36 CategoryPositionHelper::CategoryPositionHelper( double fSeriesCount, double fCategoryWidth )
37 : m_fSeriesCount(fSeriesCount)
38 , m_fCategoryWidth(fCategoryWidth)
39 , m_fInnerDistance(0.0)
40 , m_fOuterDistance(1.0)
41 {
42 }
43
CategoryPositionHelper(const CategoryPositionHelper & rSource)44 CategoryPositionHelper::CategoryPositionHelper( const CategoryPositionHelper& rSource )
45 : m_fSeriesCount( rSource.m_fSeriesCount )
46 , m_fCategoryWidth( rSource.m_fCategoryWidth )
47 , m_fInnerDistance( rSource.m_fInnerDistance )
48 , m_fOuterDistance( rSource.m_fOuterDistance )
49 {
50 }
51
~CategoryPositionHelper()52 CategoryPositionHelper::~CategoryPositionHelper()
53 {
54 }
55
getScaledSlotWidth() const56 double CategoryPositionHelper::getScaledSlotWidth() const
57 {
58 double fWidth = m_fCategoryWidth /
59 ( m_fSeriesCount
60 + m_fOuterDistance
61 + m_fInnerDistance*( m_fSeriesCount - 1.0) );
62 return fWidth;
63 }
64
getScaledSlotPos(double fScaledXPos,double fSeriesNumber) const65 double CategoryPositionHelper::getScaledSlotPos( double fScaledXPos, double fSeriesNumber ) const
66 {
67 //the returned position is in the middle of the rect
68 //fSeriesNumber 0...n-1
69 double fPos = fScaledXPos
70 - (m_fCategoryWidth/2.0)
71 + (m_fOuterDistance/2.0 + fSeriesNumber*(1.0+m_fInnerDistance)) * getScaledSlotWidth()
72 + getScaledSlotWidth()/2.0;
73 return fPos;
74 }
75
setInnerDistance(double fInnerDistance)76 void CategoryPositionHelper::setInnerDistance( double fInnerDistance )
77 {
78 if( fInnerDistance < -1.0 )
79 fInnerDistance = -1.0;
80 if( fInnerDistance > 1.0 )
81 fInnerDistance = 1.0;
82 m_fInnerDistance = fInnerDistance;
83 }
84
setOuterDistance(double fOuterDistance)85 void CategoryPositionHelper::setOuterDistance( double fOuterDistance )
86 {
87 if( fOuterDistance < 0.0 )
88 fOuterDistance = 0.0;
89 if( fOuterDistance > 6.0 )
90 fOuterDistance = 6.0;
91 m_fOuterDistance = fOuterDistance;
92 }
93
setCategoryWidth(double fCategoryWidth)94 void CategoryPositionHelper::setCategoryWidth( double fCategoryWidth )
95 {
96 m_fCategoryWidth = fCategoryWidth;
97 }
98
99 //.............................................................................
100 } //namespace chart
101 //.............................................................................
102