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 "VCartesianCoordinateSystem.hxx"
21 #include "VCartesianGrid.hxx"
22 #include "VCartesianAxis.hxx"
24 #include "AxisIndexDefines.hxx"
25 #include "AxisHelper.hxx"
26 #include "ChartTypeHelper.hxx"
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::chart2
;
32 using ::com::sun::star::uno::Reference
;
34 class TextualDataProvider
: public ::cppu::WeakImplHelper1
<
35 ::com::sun::star::chart2::data::XTextualDataSequence
39 TextualDataProvider( const uno::Sequence
< OUString
>& rTextSequence
)
40 : m_aTextSequence( rTextSequence
)
43 virtual ~TextualDataProvider()
47 //XTextualDataSequence
48 virtual uno::Sequence
< OUString
> SAL_CALL
getTextualData()
49 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
51 return m_aTextSequence
;
55 uno::Sequence
< OUString
> m_aTextSequence
;
58 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference
< XCoordinateSystem
>& xCooSys
)
59 : VCoordinateSystem(xCooSys
)
63 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
67 void VCartesianCoordinateSystem::createGridShapes()
69 if(!m_xLogicTargetForGrids
.is() || !m_xFinalTarget
.is() )
72 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
73 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
75 for( sal_Int32 nDimensionIndex
=0; nDimensionIndex
<3; nDimensionIndex
++)
77 sal_Int32 nAxisIndex
= MAIN_AXIS_INDEX
;
78 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, nAxisIndex
, m_xCooSysModel
) );
79 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
82 VCartesianGrid
aGrid(nDimensionIndex
,nDimensionCount
, getGridListFromAxis( xAxis
));
83 aGrid
.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex
,nAxisIndex
)
84 , this->getExplicitIncrement(nDimensionIndex
,nAxisIndex
) );
85 aGrid
.set3DWallPositions( m_eLeftWallPos
, m_eBackWallPos
, m_eBottomPos
);
87 aGrid
.initPlotter(m_xLogicTargetForGrids
,m_xFinalTarget
,m_xShapeFactory
88 , this->createCIDForGrid( xAxis
,nDimensionIndex
,nAxisIndex
) );
89 if(2==nDimensionCount
)
90 aGrid
.setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
91 aGrid
.setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
96 void VCartesianCoordinateSystem::createVAxisList(
97 const uno::Reference
<chart2::XChartDocument
> & xChartDoc
98 , const awt::Size
& rFontReferenceSize
99 , const awt::Rectangle
& rMaximumSpaceForLabels
102 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
103 // a leak from VCartesianAxis due to cyclic reference
104 uno::Reference
<util::XNumberFormatsSupplier
> const xNumberFormatsSupplier(
105 dynamic_cast<ChartModel
&>(*xChartDoc
.get()).getNumberFormatsSupplier());
109 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
110 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
112 if(nDimensionCount
<=0)
115 sal_Int32 nDimensionIndex
= 0;
117 // dimension index -> x, y or z axis.
118 for( nDimensionIndex
= 0; nDimensionIndex
< nDimensionCount
; nDimensionIndex
++ )
120 // axis index -> primary or secondary axis.
121 sal_Int32 nMaxAxisIndex
= m_xCooSysModel
->getMaximumAxisIndexByDimension(nDimensionIndex
);
122 for( sal_Int32 nAxisIndex
= 0; nAxisIndex
<= nMaxAxisIndex
; nAxisIndex
++ )
124 Reference
< XAxis
> xAxis
= this->getAxisByDimension(nDimensionIndex
,nAxisIndex
);
125 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
128 AxisProperties
aAxisProperties(xAxis
,this->getExplicitCategoriesProvider());
129 aAxisProperties
.m_nDimensionIndex
= nDimensionIndex
;
130 aAxisProperties
.m_bSwapXAndY
= bSwapXAndY
;
131 aAxisProperties
.m_bIsMainAxis
= (nAxisIndex
==0);
132 Reference
< XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis
, m_xCooSysModel
) );
133 if( xCrossingMainAxis
.is() )
135 ScaleData
aCrossingScale( xCrossingMainAxis
->getScaleData() );
136 aAxisProperties
.m_bCrossingAxisHasReverseDirection
= (AxisOrientation_REVERSE
==aCrossingScale
.Orientation
);
138 if( aCrossingScale
.AxisType
== AxisType::CATEGORY
)
139 aAxisProperties
.m_bCrossingAxisIsCategoryAxes
= true;
142 if( nDimensionIndex
== 2 )
144 aAxisProperties
.m_xAxisTextProvider
= new TextualDataProvider( m_aSeriesNamesForZAxis
);
146 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
147 Reference
< XAxis
> xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis
, m_xCooSysModel
) );
148 aAxisProperties
.initAxisPositioning( Reference
< beans::XPropertySet
>( xSisterAxis
, uno::UNO_QUERY
) );
150 aAxisProperties
.init(true);
151 if(aAxisProperties
.m_bDisplayLabels
)
152 aAxisProperties
.m_nNumberFormatKey
= this->getNumberFormatKeyForAxis(xAxis
, xChartDoc
);
154 ::boost::shared_ptr
< VAxisBase
> apVAxis( new VCartesianAxis(aAxisProperties
,xNumberFormatsSupplier
,nDimensionIndex
,nDimensionCount
) );
155 tFullAxisIndex
aFullAxisIndex( nDimensionIndex
, nAxisIndex
);
156 m_aAxisMap
[aFullAxisIndex
] = apVAxis
;
157 apVAxis
->set3DWallPositions( m_eLeftWallPos
, m_eBackWallPos
, m_eBottomPos
);
159 apVAxis
->initAxisLabelProperties(rFontReferenceSize
,rMaximumSpaceForLabels
);
164 void VCartesianCoordinateSystem::initVAxisInList()
166 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
169 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
170 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
172 tVAxisMap::iterator
aIt( m_aAxisMap
.begin() );
173 tVAxisMap::const_iterator
aEnd( m_aAxisMap
.end() );
174 for( ; aIt
!= aEnd
; ++aIt
)
176 VAxisBase
* pVAxis
= aIt
->second
.get();
179 sal_Int32 nDimensionIndex
= aIt
->first
.first
;
180 sal_Int32 nAxisIndex
= aIt
->first
.second
;
181 pVAxis
->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex
, nAxisIndex
), this->getExplicitIncrement( nDimensionIndex
, nAxisIndex
) );
182 pVAxis
->initPlotter(m_xLogicTargetForAxes
,m_xFinalTarget
,m_xShapeFactory
183 , this->createCIDForAxis( getAxisByDimension( nDimensionIndex
, nAxisIndex
), nDimensionIndex
, nAxisIndex
) );
184 if(2==nDimensionCount
)
185 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
186 pVAxis
->setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
191 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
193 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
196 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
197 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
199 tVAxisMap::iterator
aIt( m_aAxisMap
.begin() );
200 tVAxisMap::const_iterator
aEnd( m_aAxisMap
.end() );
201 for( ; aIt
!= aEnd
; ++aIt
)
203 VAxisBase
* pVAxis
= aIt
->second
.get();
206 sal_Int32 nDimensionIndex
= aIt
->first
.first
;
207 sal_Int32 nAxisIndex
= aIt
->first
.second
;
208 pVAxis
->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex
, nAxisIndex
), this->getExplicitIncrement( nDimensionIndex
, nAxisIndex
) );
209 if(2==nDimensionCount
)
210 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
211 pVAxis
->setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */