LibreOffice Module chart2 (master) 1
AxisUsage.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/types.h>
23#include <memory>
24#include <map>
25
26#include <VCoordinateSystem.hxx>
27#include <AxisHelper.hxx>
28#include <ScaleAutomatism.hxx>
29
30namespace chart
31{
32//first index is the dimension, second index is the axis index that indicates whether this is a main or secondary axis
33typedef std::pair<sal_Int32, sal_Int32> tFullAxisIndex;
34typedef std::map<VCoordinateSystem*, tFullAxisIndex> tCoordinateSystemMap;
35
46{
47public:
49 : aAutoScaling(AxisHelper::createDefaultScale(), Date(Date::SYSTEM))
50 {
51 }
52
53 void addCoordinateSystem(VCoordinateSystem* pCooSys, sal_Int32 nDimensionIndex,
54 sal_Int32 nAxisIndex)
55 {
56 if (!pCooSys)
57 return;
58
59 tFullAxisIndex aFullAxisIndex(nDimensionIndex, nAxisIndex);
60 tCoordinateSystemMap::const_iterator aFound(aCoordinateSystems.find(pCooSys));
61
62 //use one scale only once for each coordinate system
63 //main axis are preferred over secondary axis
64 //value scales are preferred
65 if (aFound != aCoordinateSystems.end())
66 {
67 sal_Int32 nFoundAxisIndex = aFound->second.second;
68 if (nFoundAxisIndex < nAxisIndex)
69 return;
70 sal_Int32 nFoundDimension = aFound->second.first;
71 if (nFoundDimension == 1)
72 return;
73 if (nFoundDimension < nDimensionIndex)
74 return;
75 }
76 aCoordinateSystems[pCooSys] = aFullAxisIndex;
77
78 //set maximum scale index
79 auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
80 if (aIter != aMaxIndexPerDimension.end())
81 {
82 sal_Int32 nCurrentMaxIndex = aIter->second;
83 if (nCurrentMaxIndex < nAxisIndex)
84 aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
85 }
86 else
87 aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
88 }
89
90 std::vector<VCoordinateSystem*> getCoordinateSystems(sal_Int32 nDimensionIndex,
91 sal_Int32 nAxisIndex)
92 {
93 std::vector<VCoordinateSystem*> aRet;
94
95 for (auto const& coordinateSystem : aCoordinateSystems)
96 {
97 if (coordinateSystem.second.first != nDimensionIndex)
98 continue;
99 if (coordinateSystem.second.second != nAxisIndex)
100 continue;
101 aRet.push_back(coordinateSystem.first);
102 }
103
104 return aRet;
105 }
106
107 sal_Int32 getMaxAxisIndexForDimension(sal_Int32 nDimensionIndex)
108 {
109 sal_Int32 nRet = -1;
110 auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
111 if (aIter != aMaxIndexPerDimension.end())
112 nRet = aIter->second;
113 return nRet;
114 }
115
116 void prepareAutomaticAxisScaling(ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex,
117 sal_Int32 nAxisIndex)
118 {
119 std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
120 for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
121 pVCoordinateSystem->prepareAutomaticAxisScaling(rScaleAutomatism, nDimIndex,
122 nAxisIndex);
123 }
124
125 void setExplicitScaleAndIncrement(sal_Int32 nDimIndex, sal_Int32 nAxisIndex,
126 const ExplicitScaleData& rScale,
127 const ExplicitIncrementData& rInc)
128 {
129 std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
130 for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
131 pVCoordinateSystem->setExplicitScaleAndIncrement(nDimIndex, nAxisIndex, rScale, rInc);
132 }
133
135
136private:
138 std::map<sal_Int32, sal_Int32> aMaxIndexPerDimension;
139};
140
141} //end chart2 namespace
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class handles a collection of coordinate systems and is used for executing some action on all co...
Definition: AxisUsage.hxx:46
std::vector< VCoordinateSystem * > getCoordinateSystems(sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex)
Definition: AxisUsage.hxx:90
void setExplicitScaleAndIncrement(sal_Int32 nDimIndex, sal_Int32 nAxisIndex, const ExplicitScaleData &rScale, const ExplicitIncrementData &rInc)
Definition: AxisUsage.hxx:125
std::map< sal_Int32, sal_Int32 > aMaxIndexPerDimension
Definition: AxisUsage.hxx:138
void addCoordinateSystem(VCoordinateSystem *pCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex)
Definition: AxisUsage.hxx:53
ScaleAutomatism aAutoScaling
Definition: AxisUsage.hxx:134
tCoordinateSystemMap aCoordinateSystems
Definition: AxisUsage.hxx:137
sal_Int32 getMaxAxisIndexForDimension(sal_Int32 nDimensionIndex)
Definition: AxisUsage.hxx:107
void prepareAutomaticAxisScaling(ScaleAutomatism &rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex)
Definition: AxisUsage.hxx:116
This class implements the calculation of automatic axis limits.
std::pair< sal_Int32, sal_Int32 > tFullAxisIndex
Definition: AxisUsage.hxx:33
std::map< VCoordinateSystem *, tFullAxisIndex > tCoordinateSystemMap
Definition: AxisUsage.hxx:34
describes how tickmarks are positioned on the scale of an axis.
This structure contains the explicit values for a scale like Minimum and Maximum.