summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-04-18 19:37:17 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-04-19 07:40:41 +0200
commitb79409008d2725a53e45904dadf6d168b4d3879d (patch)
treeae1f94b49f9a98cbd2144365c9db4c2b8b3f913d
parentchart2: use a constant instead of a function for a contant value (diff)
downloadcore-b79409008d2725a53e45904dadf6d168b4d3879d.tar.gz
core-b79409008d2725a53e45904dadf6d168b4d3879d.zip
chart2: extract AxisUsage from ChartView into AxisUsage.hxx
Change-Id: I680196af9c349c37312f177ab84051f0b68deae2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133120 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 45cdc2e83ff4a6464de4618c22dc2a402442d524) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133158 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--chart2/source/view/main/AxisUsage.hxx143
-rw-r--r--chart2/source/view/main/ChartView.cxx118
2 files changed, 144 insertions, 117 deletions
diff --git a/chart2/source/view/main/AxisUsage.hxx b/chart2/source/view/main/AxisUsage.hxx
new file mode 100644
index 000000000000..83451870755f
--- /dev/null
+++ b/chart2/source/view/main/AxisUsage.hxx
@@ -0,0 +1,143 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <memory>
+#include <map>
+
+#include <VCoordinateSystem.hxx>
+#include <AxisHelper.hxx>
+#include <ScaleAutomatism.hxx>
+
+namespace chart
+{
+//first index is the dimension, second index is the axis index that indicates whether this is a main or secondary axis
+typedef std::pair<sal_Int32, sal_Int32> tFullAxisIndex;
+typedef std::map<VCoordinateSystem*, tFullAxisIndex> tCoordinateSystemMap;
+
+/** This class handles a collection of coordinate systems and is used for
+ * executing some action on all coordinate systems such as
+ * "prepareAutomaticAxisScaling" and "setExplicitScaleAndIncrement".
+ * Moreover it contains the "aAutoScaling" object that is an instance of
+ * the "ScaleAutomatism" class. The initialization of "aAutoScaling" is
+ * performed in the "SeriesPlotterContainer::initAxisUsageList" method and is
+ * used in the "SeriesPlotterContainer::doAutoScaling" for calculating explicit
+ * scale and increment objects (see "SeriesPlotterContainer::doAutoScaling").
+ */
+class AxisUsage
+{
+public:
+ AxisUsage()
+ : aAutoScaling(AxisHelper::createDefaultScale(), Date(Date::SYSTEM))
+ {
+ }
+
+ void addCoordinateSystem(VCoordinateSystem* pCooSys, sal_Int32 nDimensionIndex,
+ sal_Int32 nAxisIndex)
+ {
+ if (!pCooSys)
+ return;
+
+ tFullAxisIndex aFullAxisIndex(nDimensionIndex, nAxisIndex);
+ tCoordinateSystemMap::const_iterator aFound(aCoordinateSystems.find(pCooSys));
+
+ //use one scale only once for each coordinate system
+ //main axis are preferred over secondary axis
+ //value scales are preferred
+ if (aFound != aCoordinateSystems.end())
+ {
+ sal_Int32 nFoundAxisIndex = aFound->second.second;
+ if (nFoundAxisIndex < nAxisIndex)
+ return;
+ sal_Int32 nFoundDimension = aFound->second.first;
+ if (nFoundDimension == 1)
+ return;
+ if (nFoundDimension < nDimensionIndex)
+ return;
+ }
+ aCoordinateSystems[pCooSys] = aFullAxisIndex;
+
+ //set maximum scale index
+ auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
+ if (aIter != aMaxIndexPerDimension.end())
+ {
+ sal_Int32 nCurrentMaxIndex = aIter->second;
+ if (nCurrentMaxIndex < nAxisIndex)
+ aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
+ }
+ else
+ aMaxIndexPerDimension[nDimensionIndex] = nAxisIndex;
+ }
+
+ std::vector<VCoordinateSystem*> getCoordinateSystems(sal_Int32 nDimensionIndex,
+ sal_Int32 nAxisIndex)
+ {
+ std::vector<VCoordinateSystem*> aRet;
+
+ for (auto const& coordinateSystem : aCoordinateSystems)
+ {
+ if (coordinateSystem.second.first != nDimensionIndex)
+ continue;
+ if (coordinateSystem.second.second != nAxisIndex)
+ continue;
+ aRet.push_back(coordinateSystem.first);
+ }
+
+ return aRet;
+ }
+
+ sal_Int32 getMaxAxisIndexForDimension(sal_Int32 nDimensionIndex)
+ {
+ sal_Int32 nRet = -1;
+ auto aIter = aMaxIndexPerDimension.find(nDimensionIndex);
+ if (aIter != aMaxIndexPerDimension.end())
+ nRet = aIter->second;
+ return nRet;
+ }
+
+ void prepareAutomaticAxisScaling(ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex,
+ sal_Int32 nAxisIndex)
+ {
+ std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
+ for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
+ pVCoordinateSystem->prepareAutomaticAxisScaling(rScaleAutomatism, nDimIndex,
+ nAxisIndex);
+ }
+
+ void setExplicitScaleAndIncrement(sal_Int32 nDimIndex, sal_Int32 nAxisIndex,
+ const ExplicitScaleData& rScale,
+ const ExplicitIncrementData& rInc)
+ {
+ std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
+ for (VCoordinateSystem* pVCoordinateSystem : aVCooSysList)
+ pVCoordinateSystem->setExplicitScaleAndIncrement(nDimIndex, nAxisIndex, rScale, rInc);
+ }
+
+ ScaleAutomatism aAutoScaling;
+
+private:
+ tCoordinateSystemMap aCoordinateSystems;
+ std::map<sal_Int32, sal_Int32> aMaxIndexPerDimension;
+};
+
+} //end chart2 namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 666ea63fd213..04eb2193cdd6 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -41,6 +41,7 @@
#include <RelativePositionHelper.hxx>
#include <servicenames.hxx>
#include <AxisHelper.hxx>
+#include "AxisUsage.hxx"
#include <AxisIndexDefines.hxx>
#include <BaseGFXHelper.hxx>
#include <DataSeriesHelper.hxx>
@@ -118,123 +119,6 @@ using ::com::sun::star::uno::Any;
namespace {
-typedef std::pair< sal_Int32, sal_Int32 > tFullAxisIndex; //first index is the dimension, second index is the axis index that indicates whether this is a main or secondary axis
-typedef std::map< VCoordinateSystem*, tFullAxisIndex > tCoordinateSystemMap;
-
-/** This class handles a collection of coordinate systems and is used for
- * executing some action on all coordinate systems such as
- * `prepareAutomaticAxisScaling` and `setExplicitScaleAndIncrement`.
- * Moreover it contains the `aAutoScaling` object that is an instance of
- * the `ScaleAutomatism` class. The initialization of `aAutoScaling` is
- * performed in the `SeriesPlotterContainer::initAxisUsageList` method and is
- * used in the `SeriesPlotterContainer::doAutoScaling` for calculating explicit
- * scale and increment objects (see `SeriesPlotterContainer::doAutoScaling`).
- */
-struct AxisUsage
-{
- AxisUsage();
- ~AxisUsage();
-
- void addCoordinateSystem( VCoordinateSystem* pCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
- std::vector< VCoordinateSystem* > getCoordinateSystems( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
- sal_Int32 getMaxAxisIndexForDimension( sal_Int32 nDimensionIndex );
-
- void prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex );
- void setExplicitScaleAndIncrement( sal_Int32 nDimIndex, sal_Int32 nAxisIndex, const ExplicitScaleData& rScale, const ExplicitIncrementData& rInc );
-
- ScaleAutomatism aAutoScaling;
-
-private:
- tCoordinateSystemMap aCoordinateSystems;
- std::map< sal_Int32, sal_Int32 > aMaxIndexPerDimension;
-};
-
-AxisUsage::AxisUsage()
- : aAutoScaling(AxisHelper::createDefaultScale(), Date(Date::SYSTEM))
-{
-}
-
-AxisUsage::~AxisUsage()
-{
- aCoordinateSystems.clear();
-}
-
-void AxisUsage::addCoordinateSystem( VCoordinateSystem* pCooSys, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
-{
- if(!pCooSys)
- return;
-
- tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
- tCoordinateSystemMap::const_iterator aFound( aCoordinateSystems.find(pCooSys) );
-
- //use one scale only once for each coordinate system
- //main axis are preferred over secondary axis
- //value scales are preferred
- if(aFound!=aCoordinateSystems.end())
- {
- sal_Int32 nFoundAxisIndex = aFound->second.second;
- if( nFoundAxisIndex < nAxisIndex )
- return;
- sal_Int32 nFoundDimension = aFound->second.first;
- if( nFoundDimension ==1 )
- return;
- if( nFoundDimension < nDimensionIndex )
- return;
- }
- aCoordinateSystems[pCooSys] = aFullAxisIndex;
-
- //set maximum scale index
- std::map< sal_Int32, sal_Int32 >::const_iterator aIter = aMaxIndexPerDimension.find(nDimensionIndex);
- if( aIter != aMaxIndexPerDimension.end() )
- {
- sal_Int32 nCurrentMaxIndex = aIter->second;
- if( nCurrentMaxIndex < nAxisIndex )
- aMaxIndexPerDimension[nDimensionIndex]=nAxisIndex;
- }
- else
- aMaxIndexPerDimension[nDimensionIndex]=nAxisIndex;
-}
-
-std::vector< VCoordinateSystem* > AxisUsage::getCoordinateSystems( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
-{
- std::vector< VCoordinateSystem* > aRet;
-
- for (auto const& coordinateSystem : aCoordinateSystems)
- {
- if( coordinateSystem.second.first != nDimensionIndex )
- continue;
- if( coordinateSystem.second.second != nAxisIndex )
- continue;
- aRet.push_back( coordinateSystem.first );
- }
-
- return aRet;
-}
-
-sal_Int32 AxisUsage::getMaxAxisIndexForDimension( sal_Int32 nDimensionIndex )
-{
- sal_Int32 nRet = -1;
- std::map< sal_Int32, sal_Int32 >::const_iterator aIter = aMaxIndexPerDimension.find(nDimensionIndex);
- if( aIter != aMaxIndexPerDimension.end() )
- nRet = aIter->second;
- return nRet;
-}
-
-void AxisUsage::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex )
-{
- std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
- for (VCoordinateSystem * i : aVCooSysList)
- i->prepareAutomaticAxisScaling(rScaleAutomatism, nDimIndex, nAxisIndex);
-}
-
-void AxisUsage::setExplicitScaleAndIncrement(
- sal_Int32 nDimIndex, sal_Int32 nAxisIndex, const ExplicitScaleData& rScale, const ExplicitIncrementData& rInc )
-{
- std::vector<VCoordinateSystem*> aVCooSysList = getCoordinateSystems(nDimIndex, nAxisIndex);
- for (VCoordinateSystem* i : aVCooSysList)
- i->setExplicitScaleAndIncrement(nDimIndex, nAxisIndex, rScale, rInc);
-}
-
typedef std::vector<std::unique_ptr<VSeriesPlotter> > SeriesPlottersType;
/** This class is a container of `SeriesPlotter` objects (such as `PieChart`