LibreOffice Module chart2 (master) 1
VPolarCoordinateSystem.cxx
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
21#include "VPolarGrid.hxx"
22#include "VPolarAxis.hxx"
24#include <AxisIndexDefines.hxx>
25#include <Axis.hxx>
26#include <AxisHelper.hxx>
27#include <Diagram.hxx>
28#include <DataTable.hxx>
29#include <ChartModel.hxx>
30#include <GridProperties.hxx>
31
32namespace chart
33{
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::chart2;
36using ::com::sun::star::uno::Reference;
37
39 : VCoordinateSystem(xCooSys)
40{
41}
42
43VPolarCoordinateSystem::~VPolarCoordinateSystem()
44{
45}
46
47//better performance for big data
48uno::Sequence< sal_Int32 > VPolarCoordinateSystem::getCoordinateSystemResolution(
49 const awt::Size& rPageSize, const awt::Size& rPageResolution )
50{
51 uno::Sequence< sal_Int32 > aResolution( VCoordinateSystem::getCoordinateSystemResolution( rPageSize, rPageResolution) );
52
53 if( aResolution.getLength() >= 2 )
54 {
55 auto pResolution = aResolution.getArray();
56 if( getPropertySwapXAndYAxis() )
57 {
58 pResolution[0]/=2;//radius
59 pResolution[1]*=4;//outer circle resolution
60 }
61 else
62 {
63 pResolution[0]*=4;//outer circle resolution
64 pResolution[1]/=2;//radius
65 }
66 }
67
68 return aResolution;
69}
70
71void VPolarCoordinateSystem::createVAxisList(
73 const awt::Size& rFontReferenceSize,
74 const awt::Rectangle& rMaximumSpaceForLabels,
75 bool /*bLimitSpaceForLabels*/,
76 std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/,
77 css::uno::Reference<css::uno::XComponentContext> const& /*rComponentContext*/)
78{
79 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
80 // a leak from VPolarAxis due to cyclic reference
81 uno::Reference<util::XNumberFormatsSupplier> const xNumberFormatsSupplier(
82 xChartDoc->getNumberFormatsSupplier());
83
84 m_aAxisMap.clear();
85 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
86 sal_Int32 nDimensionIndex = 0;
87
88 //create angle axis (dimension index 0)
89 for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
90 {
91 sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
92 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
93 {
94 rtl::Reference< Axis > xAxis = getAxisByDimension(nDimensionIndex,nAxisIndex);
95 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
96 continue;
97
98 rtl::Reference<Diagram> xDiagram(xChartDoc->getFirstChartDiagram());
99 AxisProperties aAxisProperties(xAxis,getExplicitCategoriesProvider(), xDiagram->getDataTableRef());
100 aAxisProperties.init();
101 if(aAxisProperties.m_bDisplayLabels)
102 aAxisProperties.m_nNumberFormatKey = getNumberFormatKeyForAxis(xAxis, xChartDoc);
103
104 std::shared_ptr< VAxisBase > apVAxis( VPolarAxis::createAxis( aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
105 tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
106 m_aAxisMap[aFullAxisIndex] = apVAxis;
107
108 apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
109 }
110 }
111}
112
113void VPolarCoordinateSystem::initVAxisInList()
114{
115 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
116 return;
117
118 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
119 bool bSwapXAndY = getPropertySwapXAndYAxis();
120
121 for (auto const& elem : m_aAxisMap)
122 {
123 VAxisBase* pVAxis = elem.second.get();
124 if( pVAxis )
125 {
126 sal_Int32 nDimensionIndex = elem.first.first;
127 sal_Int32 nAxisIndex = elem.first.second;
128 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement(nDimensionIndex, nAxisIndex) );
129 pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget
130 , createCIDForAxis( nDimensionIndex, nAxisIndex ) );
131 VPolarAxis* pVPolarAxis = dynamic_cast< VPolarAxis* >( pVAxis );
132 if( pVPolarAxis )
133 pVPolarAxis->setIncrements( getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
134 if(nDimensionCount==2)
135 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
136 pVAxis->setScales( getExplicitScales( nDimensionIndex, nAxisIndex ), bSwapXAndY );
137 }
138 }
139}
140
141void VPolarCoordinateSystem::updateScalesAndIncrementsOnAxes()
142{
143 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
144 return;
145
146 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
147 bool bSwapXAndY = getPropertySwapXAndYAxis();
148
149 for (auto const& elem : m_aAxisMap)
150 {
151 VAxisBase* pVAxis = elem.second.get();
152 if( pVAxis )
153 {
154 sal_Int32 nDimensionIndex = elem.first.first;
155 sal_Int32 nAxisIndex = elem.first.second;
156 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement(nDimensionIndex, nAxisIndex) );
157 VPolarAxis* pVPolarAxis = dynamic_cast< VPolarAxis* >( pVAxis );
158 if( pVPolarAxis )
159 pVPolarAxis->setIncrements( getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
160 if(nDimensionCount==2)
161 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
162 pVAxis->setScales( getExplicitScales( nDimensionIndex, nAxisIndex ), bSwapXAndY );
163 }
164 }
165}
166
167void VPolarCoordinateSystem::createGridShapes()
168{
169 if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
170 return;
171
172 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
173 bool bSwapXAndY = getPropertySwapXAndYAxis();
174
175 for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
176 {
177 sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
178
179 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel );
180 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
181 continue;
182
183 VPolarGrid aGrid(nDimensionIndex,nDimensionCount,getGridListFromAxis( xAxis ));
184 aGrid.setIncrements( getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
185 aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget
186 , createCIDForGrid( nDimensionIndex, nAxisIndex ) );
187 if(nDimensionCount==2)
188 aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
189 aGrid.setScales( getExplicitScales( nDimensionIndex, nAxisIndex), bSwapXAndY );
190 aGrid.createShapes();
191 }
192}
193
194} //namespace chart
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void setScales(std::vector< ExplicitScaleData > &&rScales, bool bSwapXAndYAxis)
Definition: PlotterBase.cxx:51
virtual void initPlotter(const rtl::Reference< SvxShapeGroupAnyD > &xLogicTarget, const rtl::Reference< SvxShapeGroupAnyD > &xFinalTarget, const OUString &rCID)
Definition: PlotterBase.cxx:36
virtual void setExplicitScaleAndIncrement(const ExplicitScaleData &rScale, const ExplicitIncrementData &rIncrement) override
Definition: VAxisBase.cxx:148
virtual void setTransformationSceneToScreen(const css::drawing::HomogenMatrix &rMatrix) override
std::pair< sal_Int32, sal_Int32 > tFullAxisIndex
void setIncrements(std::vector< ExplicitIncrementData > &&rIncrements)
Definition: VPolarAxis.cxx:52
void setIncrements(std::vector< ExplicitIncrementData > &&rIncrements)
Definition: VPolarGrid.cxx:54
virtual void createShapes() override
Definition: VPolarGrid.cxx:219
const sal_Int32 MAIN_AXIS_INDEX
void init(bool bCartesian=false)