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