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 41 : CategoryPositionHelper::CategoryPositionHelper( double fSeriesCount, double fCategoryWidth )
29 : : m_fSeriesCount(fSeriesCount)
30 : , m_fCategoryWidth(fCategoryWidth)
31 : , m_fInnerDistance(0.0)
32 41 : , m_fOuterDistance(1.0)
33 : {
34 41 : }
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 41 : CategoryPositionHelper::~CategoryPositionHelper()
45 : {
46 41 : }
47 :
48 1476 : double CategoryPositionHelper::getScaledSlotWidth() const
49 : {
50 : double fWidth = m_fCategoryWidth /
51 : ( m_fSeriesCount
52 : + m_fOuterDistance
53 1476 : + m_fInnerDistance*( m_fSeriesCount - 1.0) );
54 1476 : return fWidth;
55 : }
56 :
57 492 : 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 492 : + (m_fOuterDistance/2.0 + fSeriesNumber*(1.0+m_fInnerDistance)) * getScaledSlotWidth()
64 984 : + getScaledSlotWidth()/2.0;
65 492 : return fPos;
66 : }
67 :
68 492 : void CategoryPositionHelper::setInnerDistance( double fInnerDistance )
69 : {
70 492 : if( fInnerDistance < -1.0 )
71 0 : fInnerDistance = -1.0;
72 492 : if( fInnerDistance > 1.0 )
73 0 : fInnerDistance = 1.0;
74 492 : m_fInnerDistance = fInnerDistance;
75 492 : }
76 :
77 492 : void CategoryPositionHelper::setOuterDistance( double fOuterDistance )
78 : {
79 492 : if( fOuterDistance < 0.0 )
80 0 : fOuterDistance = 0.0;
81 492 : if( fOuterDistance > 6.0 )
82 0 : fOuterDistance = 6.0;
83 492 : m_fOuterDistance = fOuterDistance;
84 492 : }
85 :
86 492 : void CategoryPositionHelper::setCategoryWidth( double fCategoryWidth )
87 : {
88 492 : m_fCategoryWidth = fCategoryWidth;
89 492 : }
90 :
91 : //.............................................................................
92 : } //namespace chart
93 : //.............................................................................
94 :
95 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|