1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "VPolarCoordinateSystem.hxx"
21 #include "VPolarGrid.hxx"
22 #include "VPolarAxis.hxx"
23 #include <BaseCoordinateSystem.hxx>
24 #include <AxisIndexDefines.hxx>
26 #include <AxisHelper.hxx>
27 #include <Diagram.hxx>
28 #include <DataTable.hxx>
29 #include <ChartModel.hxx>
30 #include <GridProperties.hxx>
34 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
37 VPolarCoordinateSystem::VPolarCoordinateSystem( const rtl::Reference
< BaseCoordinateSystem
>& xCooSys
)
38 : VCoordinateSystem(xCooSys
)
42 VPolarCoordinateSystem::~VPolarCoordinateSystem()
46 //better performance for big data
47 uno::Sequence
< sal_Int32
> VPolarCoordinateSystem::getCoordinateSystemResolution(
48 const awt::Size
& rPageSize
, const awt::Size
& rPageResolution
)
50 uno::Sequence
< sal_Int32
> aResolution( VCoordinateSystem::getCoordinateSystemResolution( rPageSize
, rPageResolution
) );
52 if( aResolution
.getLength() >= 2 )
54 auto pResolution
= aResolution
.getArray();
55 if( getPropertySwapXAndYAxis() )
57 pResolution
[0]/=2;//radius
58 pResolution
[1]*=4;//outer circle resolution
62 pResolution
[0]*=4;//outer circle resolution
63 pResolution
[1]/=2;//radius
70 void VPolarCoordinateSystem::createVAxisList(
71 const rtl::Reference
<::chart::ChartModel
> & xChartDoc
,
72 const awt::Size
& rFontReferenceSize
,
73 const awt::Rectangle
& rMaximumSpaceForLabels
,
74 bool /*bLimitSpaceForLabels*/,
75 std::vector
<std::unique_ptr
<VSeriesPlotter
>>& /*rSeriesPlotterList*/,
76 css::uno::Reference
<css::uno::XComponentContext
> const& /*rComponentContext*/)
78 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
79 // a leak from VPolarAxis due to cyclic reference
80 uno::Reference
<util::XNumberFormatsSupplier
> const xNumberFormatsSupplier(
81 xChartDoc
->getNumberFormatsSupplier());
84 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
85 sal_Int32 nDimensionIndex
= 0;
87 //create angle axis (dimension index 0)
88 for( nDimensionIndex
= 0; nDimensionIndex
< nDimensionCount
; nDimensionIndex
++ )
90 sal_Int32 nMaxAxisIndex
= m_xCooSysModel
->getMaximumAxisIndexByDimension(nDimensionIndex
);
91 for( sal_Int32 nAxisIndex
= 0; nAxisIndex
<= nMaxAxisIndex
; nAxisIndex
++ )
93 rtl::Reference
< Axis
> xAxis
= getAxisByDimension(nDimensionIndex
,nAxisIndex
);
94 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
97 rtl::Reference
<Diagram
> xDiagram(xChartDoc
->getFirstChartDiagram());
98 AxisProperties
aAxisProperties(xAxis
,getExplicitCategoriesProvider(), xDiagram
->getDataTableRef());
99 aAxisProperties
.init();
100 if(aAxisProperties
.m_bDisplayLabels
)
101 aAxisProperties
.m_nNumberFormatKey
= getNumberFormatKeyForAxis(xAxis
, xChartDoc
);
103 std::shared_ptr
< VAxisBase
> apVAxis( VPolarAxis::createAxis( aAxisProperties
,xNumberFormatsSupplier
,nDimensionIndex
,nDimensionCount
) );
104 tFullAxisIndex
aFullAxisIndex( nDimensionIndex
, nAxisIndex
);
105 m_aAxisMap
[aFullAxisIndex
] = apVAxis
;
107 apVAxis
->initAxisLabelProperties(rFontReferenceSize
,rMaximumSpaceForLabels
);
112 void VPolarCoordinateSystem::initVAxisInList()
114 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
117 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
118 bool bSwapXAndY
= getPropertySwapXAndYAxis();
120 for (auto const& elem
: m_aAxisMap
)
122 VAxisBase
* pVAxis
= elem
.second
.get();
125 sal_Int32 nDimensionIndex
= elem
.first
.first
;
126 sal_Int32 nAxisIndex
= elem
.first
.second
;
127 pVAxis
->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex
, nAxisIndex
), getExplicitIncrement(nDimensionIndex
, nAxisIndex
) );
128 pVAxis
->initPlotter(m_xLogicTargetForAxes
,m_xFinalTarget
129 , createCIDForAxis( nDimensionIndex
, nAxisIndex
) );
130 VPolarAxis
* pVPolarAxis
= dynamic_cast< VPolarAxis
* >( pVAxis
);
132 pVPolarAxis
->setIncrements( getExplicitIncrements( nDimensionIndex
, nAxisIndex
) );
133 if(nDimensionCount
==2)
134 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
135 pVAxis
->setScales( getExplicitScales( nDimensionIndex
, nAxisIndex
), bSwapXAndY
);
140 void VPolarCoordinateSystem::updateScalesAndIncrementsOnAxes()
142 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
145 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
146 bool bSwapXAndY
= getPropertySwapXAndYAxis();
148 for (auto const& elem
: m_aAxisMap
)
150 VAxisBase
* pVAxis
= elem
.second
.get();
153 sal_Int32 nDimensionIndex
= elem
.first
.first
;
154 sal_Int32 nAxisIndex
= elem
.first
.second
;
155 pVAxis
->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex
, nAxisIndex
), getExplicitIncrement(nDimensionIndex
, nAxisIndex
) );
156 VPolarAxis
* pVPolarAxis
= dynamic_cast< VPolarAxis
* >( pVAxis
);
158 pVPolarAxis
->setIncrements( getExplicitIncrements( nDimensionIndex
, nAxisIndex
) );
159 if(nDimensionCount
==2)
160 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
161 pVAxis
->setScales( getExplicitScales( nDimensionIndex
, nAxisIndex
), bSwapXAndY
);
166 void VPolarCoordinateSystem::createGridShapes()
168 if(!m_xLogicTargetForGrids
.is() || !m_xFinalTarget
.is() )
171 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
172 bool bSwapXAndY
= getPropertySwapXAndYAxis();
174 for( sal_Int32 nDimensionIndex
=0; nDimensionIndex
<3; nDimensionIndex
++)
176 sal_Int32 nAxisIndex
= MAIN_AXIS_INDEX
;
178 rtl::Reference
< Axis
> xAxis
= AxisHelper::getAxis( nDimensionIndex
, nAxisIndex
, m_xCooSysModel
);
179 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
182 VPolarGrid
aGrid(nDimensionIndex
,nDimensionCount
,getGridListFromAxis( xAxis
));
183 aGrid
.setIncrements( getExplicitIncrements( nDimensionIndex
, nAxisIndex
) );
184 aGrid
.initPlotter(m_xLogicTargetForGrids
,m_xFinalTarget
185 , createCIDForGrid( nDimensionIndex
, nAxisIndex
) );
186 if(nDimensionCount
==2)
187 aGrid
.setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
188 aGrid
.setScales( getExplicitScales( nDimensionIndex
, nAxisIndex
), bSwapXAndY
);
189 aGrid
.createShapes();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */