Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/view/main/AxisUsage.hxx
Line
Count
Source
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 <map>
24
25
#include <VCoordinateSystem.hxx>
26
#include <AxisHelper.hxx>
27
#include <ScaleAutomatism.hxx>
28
29
namespace chart
30
{
31
//first index is the dimension, second index is the axis index that indicates whether this is a main or secondary axis
32
typedef std::pair<sal_Int32, sal_Int32> tFullAxisIndex;
33
typedef std::map<VCoordinateSystem*, tFullAxisIndex> tCoordinateSystemMap;
34
35
/** This class handles a collection of coordinate systems and is used for
36
 *  executing some action on all coordinate systems such as
37
 *  "prepareAutomaticAxisScaling" and "setExplicitScaleAndIncrement".
38
 *  Moreover it contains the "aAutoScaling" object that is an instance of
39
 *  the "ScaleAutomatism" class. The initialization of "aAutoScaling" is
40
 *  performed in the "SeriesPlotterContainer::initAxisUsageList" method and is
41
 *  used in the "SeriesPlotterContainer::doAutoScaling" for calculating explicit
42
 *  scale and increment objects (see "SeriesPlotterContainer::doAutoScaling").
43
 */
44
class AxisUsage
45
{
46
public:
47
    AxisUsage()
48
0
        : aAutoScaling(AxisHelper::createDefaultScale(), Date(Date::SYSTEM))
49
0
    {
50
0
    }
51
52
    void addCoordinateSystem(VCoordinateSystem* pCooSys, sal_Int32 nDimensionIndex,
53
                             sal_Int32 nAxisIndex)
54
0
    {
55
0
        if (!pCooSys)
56
0
            return;
57
58
0
        tFullAxisIndex aFullAxisIndex(nDimensionIndex, nAxisIndex);
59
0
        tCoordinateSystemMap::const_iterator aFound(aCoordinateSystems.find(pCooSys));
60
61
        //use one scale only once for each coordinate system
62
        //main axis are preferred over secondary axis
63
        //value scales are preferred
64
0
        if (aFound != aCoordinateSystems.end())
65
0
        {
66
0
            sal_Int32 nFoundAxisIndex = aFound->second.second;
67
0
            if (nFoundAxisIndex < nAxisIndex)
68
0
                return;
69
0
            sal_Int32 nFoundDimension = aFound->second.first;
70
0
            if (nFoundDimension == 1)
71
0
                return;
72
0
            if (nFoundDimension < nDimensionIndex)
73
0
                return;
74
0
        }
75
0
        aCoordinateSystems[pCooSys] = std::move(aFullAxisIndex);
76
77
        //set maximum scale index
78
0
        auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
79
0
        if (aIter != aMaxIndexPerDimension.end())
80
0
        {
81
0
            sal_Int32 nCurrentMaxIndex = aIter->second;
82
0
            if (nCurrentMaxIndex < nAxisIndex)
83
0
                aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
84
0
        }
85
0
        else
86
0
            aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
87
0
    }
88
89
    std::vector<VCoordinateSystem*> getCoordinateSystems(sal_Int32 nDimensionIndex,
90
                                                         sal_Int32 nAxisIndex)
91
0
    {
92
0
        std::vector<VCoordinateSystem*> aRet;
93
94
0
        for (auto const& coordinateSystem : aCoordinateSystems)
95
0
        {
96
0
            if (coordinateSystem.second.first != nDimensionIndex)
97
0
                continue;
98
0
            if (coordinateSystem.second.second != nAxisIndex)
99
0
                continue;
100
0
            aRet.push_back(coordinateSystem.first);
101
0
        }
102
103
0
        return aRet;
104
0
    }
105
106
    sal_Int32 getMaxAxisIndexForDimension(sal_Int32 nDimensionIndex)
107
0
    {
108
0
        sal_Int32 nRet = -1;
109
0
        auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
110
0
        if (aIter != aMaxIndexPerDimension.end())
111
0
            nRet = aIter->second;
112
0
        return nRet;
113
0
    }
114
115
    void prepareAutomaticAxisScaling(ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex,
116
                                     sal_Int32 nAxisIndex)
117
0
    {
118
0
        std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
119
0
        for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
120
0
            pVCoordinateSystem->prepareAutomaticAxisScaling(rScaleAutomatism, nDimIndex,
121
0
                                                            nAxisIndex);
122
0
    }
123
124
    void setExplicitScaleAndIncrement(sal_Int32 nDimIndex, sal_Int32 nAxisIndex,
125
                                      const ExplicitScaleData& rScale,
126
                                      const ExplicitIncrementData& rInc)
127
0
    {
128
0
        std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
129
0
        for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
130
0
            pVCoordinateSystem->setExplicitScaleAndIncrement(nDimIndex, nAxisIndex, rScale, rInc);
131
0
    }
132
133
    ScaleAutomatism aAutoScaling;
134
135
private:
136
    tCoordinateSystemMap aCoordinateSystems;
137
    std::map<sal_Int32, sal_Int32> aMaxIndexPerDimension;
138
};
139
140
} //end chart2 namespace
141
142
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */