Branch data 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 : :
20 : :
21 : : #include "CategoryPositionHelper.hxx"
22 : :
23 : : //.............................................................................
24 : : namespace chart
25 : : {
26 : : //.............................................................................
27 : :
28 : 892 : CategoryPositionHelper::CategoryPositionHelper( double fSeriesCount, double fCategoryWidth )
29 : : : m_fSeriesCount(fSeriesCount)
30 : : , m_fCategoryWidth(fCategoryWidth)
31 : : , m_fInnerDistance(0.0)
32 : 892 : , m_fOuterDistance(1.0)
33 : : {
34 : 892 : }
35 : :
36 : 0 : CategoryPositionHelper::CategoryPositionHelper( const CategoryPositionHelper& rSource )
37 : : : m_fSeriesCount( rSource.m_fSeriesCount )
38 : : , m_fCategoryWidth( rSource.m_fCategoryWidth )
39 : : , m_fInnerDistance( rSource.m_fInnerDistance )
40 : 0 : , m_fOuterDistance( rSource.m_fOuterDistance )
41 : : {
42 : 0 : }
43 : :
44 : 892 : CategoryPositionHelper::~CategoryPositionHelper()
45 : : {
46 [ - + ]: 892 : }
47 : :
48 : 33564 : double CategoryPositionHelper::getScaledSlotWidth() const
49 : : {
50 : : double fWidth = m_fCategoryWidth /
51 : : ( m_fSeriesCount
52 : : + m_fOuterDistance
53 : 33564 : + m_fInnerDistance*( m_fSeriesCount - 1.0) );
54 : 33564 : return fWidth;
55 : : }
56 : :
57 : 11187 : double CategoryPositionHelper::getScaledSlotPos( double fScaledXPos, double fSeriesNumber ) const
58 : : {
59 : : //the returned position is in the middle of the rect
60 : : //fSeriesNumber 0...n-1
61 : : double fPos = fScaledXPos
62 : : - (m_fCategoryWidth/2.0)
63 : 11187 : + (m_fOuterDistance/2.0 + fSeriesNumber*(1.0+m_fInnerDistance)) * getScaledSlotWidth()
64 : 11187 : + getScaledSlotWidth()/2.0;
65 : 11187 : return fPos;
66 : : }
67 : :
68 : 11130 : void CategoryPositionHelper::setInnerDistance( double fInnerDistance )
69 : : {
70 [ - + ]: 11130 : if( fInnerDistance < -1.0 )
71 : 0 : fInnerDistance = -1.0;
72 [ - + ]: 11130 : if( fInnerDistance > 1.0 )
73 : 0 : fInnerDistance = 1.0;
74 : 11130 : m_fInnerDistance = fInnerDistance;
75 : 11130 : }
76 : :
77 : 11130 : void CategoryPositionHelper::setOuterDistance( double fOuterDistance )
78 : : {
79 [ - + ]: 11130 : if( fOuterDistance < 0.0 )
80 : 0 : fOuterDistance = 0.0;
81 [ - + ]: 11130 : if( fOuterDistance > 6.0 )
82 : 0 : fOuterDistance = 6.0;
83 : 11130 : m_fOuterDistance = fOuterDistance;
84 : 11130 : }
85 : :
86 : 11142 : void CategoryPositionHelper::setCategoryWidth( double fCategoryWidth )
87 : : {
88 : 11142 : m_fCategoryWidth = fCategoryWidth;
89 : 11142 : }
90 : :
91 : : //.............................................................................
92 : : } //namespace chart
93 : : //.............................................................................
94 : :
95 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|