1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "AxisHelper.hxx"
28cdf0e10cSrcweir #include "DiagramHelper.hxx"
29cdf0e10cSrcweir #include "ChartTypeHelper.hxx"
30cdf0e10cSrcweir #include "macros.hxx"
31cdf0e10cSrcweir #include "AxisIndexDefines.hxx"
32cdf0e10cSrcweir #include "LineProperties.hxx"
33cdf0e10cSrcweir #include "ContainerHelper.hxx"
34cdf0e10cSrcweir #include "servicenames_coosystems.hxx"
35cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
36cdf0e10cSrcweir #include "Scaling.hxx"
37cdf0e10cSrcweir #include "ChartModelHelper.hxx"
38cdf0e10cSrcweir #include "DataSourceHelper.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <tools/debug.hxx>
41cdf0e10cSrcweir #include <unotools/saveopt.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisPosition.hpp>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
46cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
48cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSource.hpp>
49cdf0e10cSrcweir
50cdf0e10cSrcweir // header for class OUStringBuffer
51cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
52cdf0e10cSrcweir #include <rtl/math.hxx>
53cdf0e10cSrcweir
54cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
55cdf0e10cSrcweir #include <com/sun/star/lang/XServiceName.hpp>
56cdf0e10cSrcweir
57cdf0e10cSrcweir #include <map>
58cdf0e10cSrcweir
59cdf0e10cSrcweir //.............................................................................
60cdf0e10cSrcweir namespace chart
61cdf0e10cSrcweir {
62cdf0e10cSrcweir //.............................................................................
63cdf0e10cSrcweir using namespace ::com::sun::star;
64cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
65cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
66cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
67cdf0e10cSrcweir
createLinearScaling()68cdf0e10cSrcweir Reference< chart2::XScaling > AxisHelper::createLinearScaling()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir return new LinearScaling( 1.0, 0.0 );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
createLogarithmicScaling(double fBase)73cdf0e10cSrcweir Reference< chart2::XScaling > AxisHelper::createLogarithmicScaling( double fBase )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir return new LogarithmicScaling( fBase );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
createDefaultScale()78cdf0e10cSrcweir ScaleData AxisHelper::createDefaultScale()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir ScaleData aScaleData;
81cdf0e10cSrcweir aScaleData.AxisType = chart2::AxisType::REALNUMBER;
82cdf0e10cSrcweir aScaleData.AutoDateAxis = true;
83cdf0e10cSrcweir aScaleData.ShiftedCategoryPosition = false;//this is adapted in the view code currently
84cdf0e10cSrcweir Sequence< SubIncrement > aSubIncrements(1);
85cdf0e10cSrcweir aSubIncrements[0] = SubIncrement();
86cdf0e10cSrcweir aScaleData.IncrementData.SubIncrements = aSubIncrements;
87cdf0e10cSrcweir return aScaleData;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
removeExplicitScaling(ScaleData & rScaleData)90cdf0e10cSrcweir void AxisHelper::removeExplicitScaling( ScaleData& rScaleData )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir uno::Any aEmpty;
93cdf0e10cSrcweir rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty;
94cdf0e10cSrcweir rScaleData.Scaling = 0;
95cdf0e10cSrcweir ScaleData aDefaultScale( createDefaultScale() );
96cdf0e10cSrcweir rScaleData.IncrementData = aDefaultScale.IncrementData;
97cdf0e10cSrcweir rScaleData.TimeIncrement = aDefaultScale.TimeIncrement;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
isLogarithmic(const Reference<XScaling> & xScaling)100cdf0e10cSrcweir bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir bool bReturn = false;
103cdf0e10cSrcweir Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
104cdf0e10cSrcweir bReturn =( xServiceName.is() && (xServiceName->getServiceName()).equals(
105cdf0e10cSrcweir C2U( "com.sun.star.chart2.LogarithmicScaling" )));
106cdf0e10cSrcweir return bReturn;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
getDateCheckedScale(const Reference<chart2::XAxis> & xAxis,const Reference<frame::XModel> & xChartModel)109cdf0e10cSrcweir chart2::ScaleData AxisHelper::getDateCheckedScale( const Reference< chart2::XAxis >& xAxis, const Reference< frame::XModel >& xChartModel )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir DBG_ASSERT(xChartModel.is(),"missing chart model");
112cdf0e10cSrcweir ScaleData aScale = xAxis->getScaleData();
113cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
114cdf0e10cSrcweir if( aScale.AutoDateAxis && aScale.AxisType == AxisType::CATEGORY )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
117cdf0e10cSrcweir AxisHelper::getIndicesForAxis(xAxis, xCooSys, nDimensionIndex, nAxisIndex );
118cdf0e10cSrcweir bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex );
119cdf0e10cSrcweir if( bChartTypeAllowsDateAxis )
120cdf0e10cSrcweir aScale.AxisType = AxisType::DATE;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir if( aScale.AxisType == AxisType::DATE )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys,xChartModel );
125cdf0e10cSrcweir if( !aExplicitCategoriesProvider.isDateAxis() )
126cdf0e10cSrcweir aScale.AxisType = AxisType::CATEGORY;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir return aScale;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
checkDateAxis(chart2::ScaleData & rScale,ExplicitCategoriesProvider * pExplicitCategoriesProvider,bool bChartTypeAllowsDateAxis)131cdf0e10cSrcweir void AxisHelper::checkDateAxis( chart2::ScaleData& rScale, ExplicitCategoriesProvider* pExplicitCategoriesProvider, bool bChartTypeAllowsDateAxis )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir if( rScale.AutoDateAxis && rScale.AxisType == AxisType::CATEGORY && bChartTypeAllowsDateAxis )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir rScale.AxisType = AxisType::DATE;
136cdf0e10cSrcweir removeExplicitScaling( rScale );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir if( rScale.AxisType == AxisType::DATE && (!pExplicitCategoriesProvider || !pExplicitCategoriesProvider->isDateAxis()) )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir rScale.AxisType = AxisType::CATEGORY;
141cdf0e10cSrcweir removeExplicitScaling( rScale );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
getExplicitNumberFormatKeyForAxis(const Reference<chart2::XAxis> & xAxis,const Reference<chart2::XCoordinateSystem> & xCorrespondingCoordinateSystem,const Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier,bool bSearchForParallelAxisIfNothingIsFound)145cdf0e10cSrcweir sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis(
146cdf0e10cSrcweir const Reference< chart2::XAxis >& xAxis
147cdf0e10cSrcweir , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem
148cdf0e10cSrcweir , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
149cdf0e10cSrcweir , bool bSearchForParallelAxisIfNothingIsFound )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir sal_Int32 nNumberFormatKey(0);
152cdf0e10cSrcweir bool bNumberFormatKeyFoundViaAttachedData = false;
153cdf0e10cSrcweir sal_Int32 nAxisIndex = 0;
154cdf0e10cSrcweir sal_Int32 nDimensionIndex = 1;
155cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex );
156cdf0e10cSrcweir Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY );
157cdf0e10cSrcweir
158cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
159cdf0e10cSrcweir if( xProp.is() && !( xProp->getPropertyValue( C2U( "NumberFormat" ) ) >>= nNumberFormatKey ) )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir bool bFormatSet = false;
162cdf0e10cSrcweir //check wether we have a percent scale -> use percent format
163cdf0e10cSrcweir if( xNumberFormatsSupplier.is() )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ScaleData aData = AxisHelper::getDateCheckedScale( xAxis, Reference< frame::XModel >( xNumberFormatsSupplier, uno::UNO_QUERY ) );
166cdf0e10cSrcweir if( aData.AxisType==AxisType::PERCENT )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir sal_Int32 nPercentFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier );
169cdf0e10cSrcweir if( nPercentFormat != -1 )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir nNumberFormatKey = nPercentFormat;
172cdf0e10cSrcweir bFormatSet = true;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir else if( aData.AxisType==AxisType::DATE )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir if( aData.Categories.is() )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( aData.Categories->getValues());
180cdf0e10cSrcweir if( xSeq.is() && !( xChartDoc.is() && xChartDoc->hasInternalDataProvider()) )
181cdf0e10cSrcweir nNumberFormatKey = xSeq->getNumberFormatKeyByIndex( -1 );
182cdf0e10cSrcweir else
183cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
184cdf0e10cSrcweir bFormatSet = true;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir }
187cdf0e10cSrcweir else if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() && nDimensionIndex == 0 ) //maybe date axis
188cdf0e10cSrcweir {
189cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram() );
190cdf0e10cSrcweir if( DiagramHelper::isSupportingDateAxis( xDiagram ) )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir else
195cdf0e10cSrcweir {
196cdf0e10cSrcweir Reference< data::XDataSource > xSource( DataSourceHelper::getUsedData( xChartDoc ) );
197cdf0e10cSrcweir if( xSource.is() )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aXValues(
200cdf0e10cSrcweir DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), C2U("values-x"), true ) );
201cdf0e10cSrcweir if( aXValues.empty() )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
204cdf0e10cSrcweir if( xCategories.is() )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xCategories->getValues());
207cdf0e10cSrcweir if( xSeq.is() )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir bool bHasValidDoubles = false;
210cdf0e10cSrcweir double fTest=0.0;
211cdf0e10cSrcweir Sequence< uno::Any > aCats( xSeq->getData() );
212cdf0e10cSrcweir sal_Int32 nCount = aCats.getLength();
213cdf0e10cSrcweir for( sal_Int32 i = 0; i < nCount; ++i )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir if( (aCats[i]>>=fTest) && !::rtl::math::isNan(fTest) )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir bHasValidDoubles=true;
218cdf0e10cSrcweir break;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir }
221cdf0e10cSrcweir if( bHasValidDoubles )
222cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir bFormatSet = true;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir if( !bFormatSet )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency;
235cdf0e10cSrcweir tNumberformatFrequency aKeyMap;
236cdf0e10cSrcweir
237cdf0e10cSrcweir try
238cdf0e10cSrcweir {
239cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW );
240cdf0e10cSrcweir if( xCTCnt.is() )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir ::rtl::OUString aRoleToMatch;
243cdf0e10cSrcweir if( nDimensionIndex == 0 )
244cdf0e10cSrcweir aRoleToMatch = C2U("values-x");
245cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes());
246cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir if( nDimensionIndex != 0 )
249cdf0e10cSrcweir aRoleToMatch = ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( aChartTypes[nCTIdx] );
250cdf0e10cSrcweir Reference< XDataSeriesContainer > xDSCnt( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW );
251cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aDataSeriesSeq( xDSCnt->getDataSeries());
252cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aDataSeriesSeq.getLength(); ++nSeriesIdx )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir Reference< chart2::XDataSeries > xDataSeries(aDataSeriesSeq[nSeriesIdx]);
255cdf0e10cSrcweir Reference< data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY_THROW );
256cdf0e10cSrcweir
257cdf0e10cSrcweir if( nDimensionIndex == 1 )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir //only take those series into accoutn that are attached to this axis
260cdf0e10cSrcweir sal_Int32 nAttachedAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
261cdf0e10cSrcweir if( nAttachedAxisIndex != nAxisIndex )
262cdf0e10cSrcweir continue;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
265cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xLabeledSeq(
266cdf0e10cSrcweir DataSeriesHelper::getDataSequenceByRole( xSource, aRoleToMatch ) );
267cdf0e10cSrcweir
268cdf0e10cSrcweir if( !xLabeledSeq.is() && nDimensionIndex==0 )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir ScaleData aData = xAxis->getScaleData();
271cdf0e10cSrcweir xLabeledSeq = aData.Categories;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir if( xLabeledSeq.is() )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xLabeledSeq->getValues());
277cdf0e10cSrcweir if( xSeq.is() )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 );
280cdf0e10cSrcweir // initialize the value
281cdf0e10cSrcweir if( aKeyMap.find( nKey ) == aKeyMap.end())
282cdf0e10cSrcweir aKeyMap[ nKey ] = 0;
283cdf0e10cSrcweir // increase frequency
284cdf0e10cSrcweir aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1);
285cdf0e10cSrcweir }
286cdf0e10cSrcweir }
287cdf0e10cSrcweir }
288cdf0e10cSrcweir }
289cdf0e10cSrcweir }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir catch( const uno::Exception & ex )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir if( ! aKeyMap.empty())
297cdf0e10cSrcweir {
298cdf0e10cSrcweir sal_Int32 nMaxFreq = 0;
299cdf0e10cSrcweir // find most frequent key
300cdf0e10cSrcweir for( tNumberformatFrequency::const_iterator aIt = aKeyMap.begin();
301cdf0e10cSrcweir aIt != aKeyMap.end(); ++aIt )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir OSL_TRACE( "NumberFormatKey %d appears %d times", (*aIt).first, (*aIt).second );
304cdf0e10cSrcweir // all values must at least be 1
305cdf0e10cSrcweir if( (*aIt).second > nMaxFreq )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir nNumberFormatKey = (*aIt).first;
308cdf0e10cSrcweir bNumberFormatKeyFoundViaAttachedData = true;
309cdf0e10cSrcweir nMaxFreq = (*aIt).second;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314cdf0e10cSrcweir if( bSearchForParallelAxisIfNothingIsFound )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir //no format is set to this axis and no data is set to this axis
317cdf0e10cSrcweir //--> try to obtain the format from the parallel y-axis
318cdf0e10cSrcweir if( !bNumberFormatKeyFoundViaAttachedData && nDimensionIndex == 1 )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
321cdf0e10cSrcweir Reference< XAxis > xParallelAxis( AxisHelper::getAxis( 1, nParallelAxisIndex, xCorrespondingCoordinateSystem ) );
322cdf0e10cSrcweir nNumberFormatKey = AxisHelper::getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false );
323cdf0e10cSrcweir }
324cdf0e10cSrcweir }
325cdf0e10cSrcweir }
326cdf0e10cSrcweir }
327cdf0e10cSrcweir return nNumberFormatKey;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir
createAxis(sal_Int32 nDimensionIndex,sal_Int32 nAxisIndex,const Reference<XCoordinateSystem> & xCooSys,const Reference<uno::XComponentContext> & xContext,ReferenceSizeProvider * pRefSizeProvider)330cdf0e10cSrcweir Reference< XAxis > AxisHelper::createAxis(
331cdf0e10cSrcweir sal_Int32 nDimensionIndex
332cdf0e10cSrcweir , sal_Int32 nAxisIndex // 0==main or 1==secondary axis
333cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys
334cdf0e10cSrcweir , const Reference< uno::XComponentContext > & xContext
335cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir if( !xContext.is() || !xCooSys.is() )
338cdf0e10cSrcweir return NULL;
339cdf0e10cSrcweir if( nDimensionIndex >= xCooSys->getDimension() )
340cdf0e10cSrcweir return NULL;
341cdf0e10cSrcweir
342cdf0e10cSrcweir Reference< XAxis > xAxis( xContext->getServiceManager()->createInstanceWithContext(
343cdf0e10cSrcweir C2U( "com.sun.star.chart2.Axis" ), xContext ), uno::UNO_QUERY );
344cdf0e10cSrcweir
345cdf0e10cSrcweir OSL_ASSERT( xAxis.is());
346cdf0e10cSrcweir if( xAxis.is())
347cdf0e10cSrcweir {
348cdf0e10cSrcweir xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
349cdf0e10cSrcweir
350cdf0e10cSrcweir if( nAxisIndex>0 )//when inserting secondary axes copy some things from the main axis
351cdf0e10cSrcweir {
352cdf0e10cSrcweir ::com::sun::star::chart::ChartAxisPosition eNewAxisPos( ::com::sun::star::chart::ChartAxisPosition_END );
353cdf0e10cSrcweir
354cdf0e10cSrcweir Reference< XAxis > xMainAxis( xCooSys->getAxisByDimension( nDimensionIndex, 0 ) );
355cdf0e10cSrcweir if( xMainAxis.is() )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir ScaleData aScale = xAxis->getScaleData();
358cdf0e10cSrcweir ScaleData aMainScale = xMainAxis->getScaleData();
359cdf0e10cSrcweir
360cdf0e10cSrcweir aScale.AxisType = aMainScale.AxisType;
361cdf0e10cSrcweir aScale.AutoDateAxis = aMainScale.AutoDateAxis;
362cdf0e10cSrcweir aScale.Categories = aMainScale.Categories;
363cdf0e10cSrcweir aScale.Orientation = aMainScale.Orientation;
364cdf0e10cSrcweir
365cdf0e10cSrcweir xAxis->setScaleData( aScale );
366cdf0e10cSrcweir
367cdf0e10cSrcweir //ensure that the second axis is not placed on the main axis
368cdf0e10cSrcweir Reference< beans::XPropertySet > xMainProp( xMainAxis, uno::UNO_QUERY );
369cdf0e10cSrcweir if( xMainProp.is() )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir ::com::sun::star::chart::ChartAxisPosition eMainAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
372cdf0e10cSrcweir xMainProp->getPropertyValue(C2U( "CrossoverPosition" )) >>= eMainAxisPos;
373cdf0e10cSrcweir if( ::com::sun::star::chart::ChartAxisPosition_END == eMainAxisPos )
374cdf0e10cSrcweir eNewAxisPos = ::com::sun::star::chart::ChartAxisPosition_START;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir
378cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
379cdf0e10cSrcweir if( xProp.is() )
380cdf0e10cSrcweir xProp->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos) );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
383cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
384cdf0e10cSrcweir if( xProp.is() ) try
385cdf0e10cSrcweir {
386cdf0e10cSrcweir // set correct initial AutoScale
387cdf0e10cSrcweir if( pRefSizeProvider )
388cdf0e10cSrcweir pRefSizeProvider->setValuesAtPropertySet( xProp );
389cdf0e10cSrcweir }
390cdf0e10cSrcweir catch( uno::Exception& e )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir ASSERT_EXCEPTION( e );
393cdf0e10cSrcweir }
394cdf0e10cSrcweir }
395cdf0e10cSrcweir return xAxis;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
createAxis(sal_Int32 nDimensionIndex,bool bMainAxis,const Reference<chart2::XDiagram> & xDiagram,const Reference<uno::XComponentContext> & xContext,ReferenceSizeProvider * pRefSizeProvider)398cdf0e10cSrcweir Reference< XAxis > AxisHelper::createAxis( sal_Int32 nDimensionIndex, bool bMainAxis
399cdf0e10cSrcweir , const Reference< chart2::XDiagram >& xDiagram
400cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext
401cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir OSL_ENSURE( xContext.is(), "need a context to create an axis" );
404cdf0e10cSrcweir if( !xContext.is() )
405cdf0e10cSrcweir return NULL;
406cdf0e10cSrcweir
407cdf0e10cSrcweir sal_Int32 nAxisIndex = bMainAxis ? MAIN_AXIS_INDEX : SECONDARY_AXIS_INDEX;
408cdf0e10cSrcweir sal_Int32 nCooSysIndex = 0;
409cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
410cdf0e10cSrcweir
411cdf0e10cSrcweir // create axis
412cdf0e10cSrcweir return AxisHelper::createAxis(
413cdf0e10cSrcweir nDimensionIndex, nAxisIndex, xCooSys, xContext, pRefSizeProvider );
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
showAxis(sal_Int32 nDimensionIndex,bool bMainAxis,const Reference<chart2::XDiagram> & xDiagram,const Reference<uno::XComponentContext> & xContext,ReferenceSizeProvider * pRefSizeProvider)416cdf0e10cSrcweir void AxisHelper::showAxis( sal_Int32 nDimensionIndex, bool bMainAxis
417cdf0e10cSrcweir , const Reference< chart2::XDiagram >& xDiagram
418cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext
419cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir if( !xDiagram.is() )
422cdf0e10cSrcweir return;
423cdf0e10cSrcweir
424cdf0e10cSrcweir bool bNewAxisCreated = false;
425cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
426cdf0e10cSrcweir if( !xAxis.is() && xContext.is() )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir // create axis
429cdf0e10cSrcweir bNewAxisCreated = true;
430cdf0e10cSrcweir xAxis.set( AxisHelper::createAxis( nDimensionIndex, bMainAxis, xDiagram, xContext, pRefSizeProvider ) );
431cdf0e10cSrcweir }
432cdf0e10cSrcweir
433cdf0e10cSrcweir OSL_ASSERT( xAxis.is());
434cdf0e10cSrcweir if( !bNewAxisCreated ) //default is true already if created
435cdf0e10cSrcweir AxisHelper::makeAxisVisible( xAxis );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
showGrid(sal_Int32 nDimensionIndex,sal_Int32 nCooSysIndex,bool bMainGrid,const Reference<XDiagram> & xDiagram,const Reference<uno::XComponentContext> &)438cdf0e10cSrcweir void AxisHelper::showGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
439cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram
440cdf0e10cSrcweir , const Reference< uno::XComponentContext >& /*xContext*/ )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir if( !xDiagram.is() )
443cdf0e10cSrcweir return;
444cdf0e10cSrcweir
445cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
446cdf0e10cSrcweir if(!xCooSys.is())
447cdf0e10cSrcweir return;
448cdf0e10cSrcweir
449cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
450cdf0e10cSrcweir if(!xAxis.is())
451cdf0e10cSrcweir {
452cdf0e10cSrcweir //hhhh todo create axis without axis visibility
453cdf0e10cSrcweir }
454cdf0e10cSrcweir if(!xAxis.is())
455cdf0e10cSrcweir return;
456cdf0e10cSrcweir
457cdf0e10cSrcweir if( bMainGrid )
458cdf0e10cSrcweir AxisHelper::makeGridVisible( xAxis->getGridProperties() );
459cdf0e10cSrcweir else
460cdf0e10cSrcweir {
461cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
462cdf0e10cSrcweir for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
463cdf0e10cSrcweir AxisHelper::makeGridVisible( aSubGrids[nN] );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
makeAxisVisible(const Reference<XAxis> & xAxis)467cdf0e10cSrcweir void AxisHelper::makeAxisVisible( const Reference< XAxis >& xAxis )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
470cdf0e10cSrcweir if( xProps.is() )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
473cdf0e10cSrcweir LineProperties::SetLineVisible( xProps );
474cdf0e10cSrcweir xProps->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True ) );
475cdf0e10cSrcweir }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
makeGridVisible(const Reference<beans::XPropertySet> & xGridProperties)478cdf0e10cSrcweir void AxisHelper::makeGridVisible( const Reference< beans::XPropertySet >& xGridProperties )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir if( xGridProperties.is() )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
483cdf0e10cSrcweir LineProperties::SetLineVisible( xGridProperties );
484cdf0e10cSrcweir }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
hideAxis(sal_Int32 nDimensionIndex,bool bMainAxis,const Reference<XDiagram> & xDiagram)487cdf0e10cSrcweir void AxisHelper::hideAxis( sal_Int32 nDimensionIndex, bool bMainAxis
488cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
491cdf0e10cSrcweir }
492cdf0e10cSrcweir
makeAxisInvisible(const Reference<XAxis> & xAxis)493cdf0e10cSrcweir void AxisHelper::makeAxisInvisible( const Reference< XAxis >& xAxis )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
496cdf0e10cSrcweir if( xProps.is() )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
499cdf0e10cSrcweir }
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
hideAxisIfNoDataIsAttached(const Reference<XAxis> & xAxis,const Reference<XDiagram> & xDiagram)502cdf0e10cSrcweir void AxisHelper::hideAxisIfNoDataIsAttached( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir //axis is hidden if no data is attached anymore but data is available
505cdf0e10cSrcweir bool bOtherSeriesAttachedToThisAxis = false;
506cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
507cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = aSeriesVector.begin();
508cdf0e10cSrcweir for( ; aIt != aSeriesVector.end(); ++aIt)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir uno::Reference< chart2::XAxis > xCurrentAxis( DiagramHelper::getAttachedAxis( *aIt, xDiagram ), uno::UNO_QUERY );
511cdf0e10cSrcweir if( xCurrentAxis==xAxis )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir bOtherSeriesAttachedToThisAxis = true;
514cdf0e10cSrcweir break;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir }
517cdf0e10cSrcweir if(!bOtherSeriesAttachedToThisAxis && !aSeriesVector.empty() )
518cdf0e10cSrcweir AxisHelper::makeAxisInvisible( xAxis );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
hideGrid(sal_Int32 nDimensionIndex,sal_Int32 nCooSysIndex,bool bMainGrid,const Reference<XDiagram> & xDiagram)521cdf0e10cSrcweir void AxisHelper::hideGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
522cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir if( !xDiagram.is() )
525cdf0e10cSrcweir return;
526cdf0e10cSrcweir
527cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
528cdf0e10cSrcweir if(!xCooSys.is())
529cdf0e10cSrcweir return;
530cdf0e10cSrcweir
531cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
532cdf0e10cSrcweir if(!xAxis.is())
533cdf0e10cSrcweir return;
534cdf0e10cSrcweir
535cdf0e10cSrcweir if( bMainGrid )
536cdf0e10cSrcweir AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
537cdf0e10cSrcweir else
538cdf0e10cSrcweir {
539cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
540cdf0e10cSrcweir for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
541cdf0e10cSrcweir AxisHelper::makeGridInvisible( aSubGrids[nN] );
542cdf0e10cSrcweir }
543cdf0e10cSrcweir }
544cdf0e10cSrcweir
makeGridInvisible(const Reference<beans::XPropertySet> & xGridProperties)545cdf0e10cSrcweir void AxisHelper::makeGridInvisible( const Reference< beans::XPropertySet >& xGridProperties )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir if( xGridProperties.is() )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
550cdf0e10cSrcweir }
551cdf0e10cSrcweir }
552cdf0e10cSrcweir
isGridShown(sal_Int32 nDimensionIndex,sal_Int32 nCooSysIndex,bool bMainGrid,const Reference<::com::sun::star::chart2::XDiagram> & xDiagram)553cdf0e10cSrcweir sal_Bool AxisHelper::isGridShown( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
554cdf0e10cSrcweir , const Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir sal_Bool bRet = false;
557cdf0e10cSrcweir
558cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
559cdf0e10cSrcweir if(!xCooSys.is())
560cdf0e10cSrcweir return bRet;
561cdf0e10cSrcweir
562cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
563cdf0e10cSrcweir if(!xAxis.is())
564cdf0e10cSrcweir return bRet;
565cdf0e10cSrcweir
566cdf0e10cSrcweir if( bMainGrid )
567cdf0e10cSrcweir bRet = AxisHelper::isGridVisible( xAxis->getGridProperties() );
568cdf0e10cSrcweir else
569cdf0e10cSrcweir {
570cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
571cdf0e10cSrcweir if( aSubGrids.getLength() )
572cdf0e10cSrcweir bRet = AxisHelper::isGridVisible( aSubGrids[0] );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir
575cdf0e10cSrcweir return bRet;
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
getCoordinateSystemByIndex(const Reference<XDiagram> & xDiagram,sal_Int32 nIndex)578cdf0e10cSrcweir Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemByIndex(
579cdf0e10cSrcweir const Reference< XDiagram >& xDiagram, sal_Int32 nIndex )
580cdf0e10cSrcweir {
581cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
582cdf0e10cSrcweir if(!xCooSysContainer.is())
583cdf0e10cSrcweir return NULL;
584cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
585cdf0e10cSrcweir if(0<=nIndex && nIndex<aCooSysList.getLength())
586cdf0e10cSrcweir return aCooSysList[nIndex];
587cdf0e10cSrcweir return NULL;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir
getAxis(sal_Int32 nDimensionIndex,bool bMainAxis,const Reference<XDiagram> & xDiagram)590cdf0e10cSrcweir Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, bool bMainAxis
591cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir Reference< XAxis > xRet;
594cdf0e10cSrcweir try
595cdf0e10cSrcweir {
596cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 );
597cdf0e10cSrcweir xRet.set( AxisHelper::getAxis( nDimensionIndex, bMainAxis ? 0 : 1, xCooSys ) );
598cdf0e10cSrcweir }
599cdf0e10cSrcweir catch( const uno::Exception & )
600cdf0e10cSrcweir {
601cdf0e10cSrcweir }
602cdf0e10cSrcweir return xRet;
603cdf0e10cSrcweir }
604cdf0e10cSrcweir
getAxis(sal_Int32 nDimensionIndex,sal_Int32 nAxisIndex,const Reference<XCoordinateSystem> & xCooSys)605cdf0e10cSrcweir Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex
606cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir Reference< XAxis > xRet;
609cdf0e10cSrcweir try
610cdf0e10cSrcweir {
611cdf0e10cSrcweir if( xCooSys.is() )
612cdf0e10cSrcweir xRet.set( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir catch( const uno::Exception & )
615cdf0e10cSrcweir {
616cdf0e10cSrcweir }
617cdf0e10cSrcweir return xRet;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir
getCrossingMainAxis(const Reference<XAxis> & xAxis,const Reference<XCoordinateSystem> & xCooSys)620cdf0e10cSrcweir Reference< XAxis > AxisHelper::getCrossingMainAxis( const Reference< XAxis >& xAxis
621cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys )
622cdf0e10cSrcweir {
623cdf0e10cSrcweir sal_Int32 nDimensionIndex = 0;
624cdf0e10cSrcweir sal_Int32 nAxisIndex = 0;
625cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex );
626cdf0e10cSrcweir if( 2==nDimensionIndex )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir nDimensionIndex=1;
629cdf0e10cSrcweir bool bSwapXY = false;
630cdf0e10cSrcweir Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
631cdf0e10cSrcweir if( xCooSysProp.is() && (xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY) && bSwapXY )
632cdf0e10cSrcweir nDimensionIndex=0;
633cdf0e10cSrcweir }
634cdf0e10cSrcweir else if( 1==nDimensionIndex )
635cdf0e10cSrcweir nDimensionIndex=0;
636cdf0e10cSrcweir else
637cdf0e10cSrcweir nDimensionIndex=1;
638cdf0e10cSrcweir return AxisHelper::getAxis( nDimensionIndex, 0, xCooSys );
639cdf0e10cSrcweir }
640cdf0e10cSrcweir
getParallelAxis(const Reference<XAxis> & xAxis,const Reference<XDiagram> & xDiagram)641cdf0e10cSrcweir Reference< XAxis > AxisHelper::getParallelAxis( const Reference< XAxis >& xAxis
642cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
643cdf0e10cSrcweir {
644cdf0e10cSrcweir try
645cdf0e10cSrcweir {
646cdf0e10cSrcweir sal_Int32 nCooSysIndex=-1;
647cdf0e10cSrcweir sal_Int32 nDimensionIndex=-1;
648cdf0e10cSrcweir sal_Int32 nAxisIndex=-1;
649cdf0e10cSrcweir if( getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ) )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
652cdf0e10cSrcweir return getAxis( nDimensionIndex, nParallelAxisIndex, getCoordinateSystemByIndex( xDiagram, nCooSysIndex ) );
653cdf0e10cSrcweir }
654cdf0e10cSrcweir }
655cdf0e10cSrcweir catch( uno::RuntimeException& )
656cdf0e10cSrcweir {
657cdf0e10cSrcweir }
658cdf0e10cSrcweir return 0;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir
isAxisShown(sal_Int32 nDimensionIndex,bool bMainAxis,const Reference<XDiagram> & xDiagram)661cdf0e10cSrcweir sal_Bool AxisHelper::isAxisShown( sal_Int32 nDimensionIndex, bool bMainAxis
662cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
665cdf0e10cSrcweir }
666cdf0e10cSrcweir
isAxisVisible(const Reference<XAxis> & xAxis)667cdf0e10cSrcweir sal_Bool AxisHelper::isAxisVisible( const Reference< XAxis >& xAxis )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir sal_Bool bRet = false;
670cdf0e10cSrcweir
671cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
672cdf0e10cSrcweir if( xProps.is() )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir xProps->getPropertyValue( C2U( "Show" ) ) >>= bRet;
675cdf0e10cSrcweir bRet = bRet && ( LineProperties::IsLineVisible( xProps )
676cdf0e10cSrcweir || areAxisLabelsVisible( xProps ) );
677cdf0e10cSrcweir }
678cdf0e10cSrcweir
679cdf0e10cSrcweir return bRet;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir
areAxisLabelsVisible(const Reference<beans::XPropertySet> & xAxisProperties)682cdf0e10cSrcweir sal_Bool AxisHelper::areAxisLabelsVisible( const Reference< beans::XPropertySet >& xAxisProperties )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir sal_Bool bRet = false;
685cdf0e10cSrcweir if( xAxisProperties.is() )
686cdf0e10cSrcweir {
687cdf0e10cSrcweir xAxisProperties->getPropertyValue( C2U( "DisplayLabels" ) ) >>= bRet;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir return bRet;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir
isGridVisible(const Reference<beans::XPropertySet> & xGridProperies)692cdf0e10cSrcweir sal_Bool AxisHelper::isGridVisible( const Reference< beans::XPropertySet >& xGridProperies )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir sal_Bool bRet = false;
695cdf0e10cSrcweir
696cdf0e10cSrcweir if( xGridProperies.is() )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir xGridProperies->getPropertyValue( C2U( "Show" ) ) >>= bRet;
699cdf0e10cSrcweir bRet = bRet && LineProperties::IsLineVisible( xGridProperies );
700cdf0e10cSrcweir }
701cdf0e10cSrcweir
702cdf0e10cSrcweir return bRet;
703cdf0e10cSrcweir }
704cdf0e10cSrcweir
getGridProperties(const Reference<XCoordinateSystem> & xCooSys,sal_Int32 nDimensionIndex,sal_Int32 nAxisIndex,sal_Int32 nSubGridIndex)705cdf0e10cSrcweir Reference< beans::XPropertySet > AxisHelper::getGridProperties(
706cdf0e10cSrcweir const Reference< XCoordinateSystem >& xCooSys
707cdf0e10cSrcweir , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex, sal_Int32 nSubGridIndex )
708cdf0e10cSrcweir {
709cdf0e10cSrcweir Reference< beans::XPropertySet > xRet;
710cdf0e10cSrcweir
711cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) );
712cdf0e10cSrcweir if( xAxis.is() )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir if( nSubGridIndex<0 )
715cdf0e10cSrcweir xRet.set( xAxis->getGridProperties() );
716cdf0e10cSrcweir else
717cdf0e10cSrcweir {
718cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
719cdf0e10cSrcweir if( nSubGridIndex >= 0 && nSubGridIndex < aSubGrids.getLength() )
720cdf0e10cSrcweir xRet.set( aSubGrids[nSubGridIndex] );
721cdf0e10cSrcweir }
722cdf0e10cSrcweir }
723cdf0e10cSrcweir
724cdf0e10cSrcweir return xRet;
725cdf0e10cSrcweir }
726cdf0e10cSrcweir
getDimensionIndexOfAxis(const Reference<XAxis> & xAxis,const Reference<XDiagram> & xDiagram)727cdf0e10cSrcweir sal_Int32 AxisHelper::getDimensionIndexOfAxis(
728cdf0e10cSrcweir const Reference< XAxis >& xAxis
729cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir sal_Int32 nDimensionIndex = -1;
732cdf0e10cSrcweir sal_Int32 nCooSysIndex = -1;
733cdf0e10cSrcweir sal_Int32 nAxisIndex = -1;
734cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex , nDimensionIndex, nAxisIndex );
735cdf0e10cSrcweir return nDimensionIndex;
736cdf0e10cSrcweir }
737cdf0e10cSrcweir
getIndicesForAxis(const Reference<XAxis> & xAxis,const Reference<XCoordinateSystem> & xCooSys,sal_Int32 & rOutDimensionIndex,sal_Int32 & rOutAxisIndex)738cdf0e10cSrcweir bool AxisHelper::getIndicesForAxis(
739cdf0e10cSrcweir const Reference< XAxis >& xAxis
740cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys
741cdf0e10cSrcweir , sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir //returns true if indices are found
744cdf0e10cSrcweir
745cdf0e10cSrcweir rOutDimensionIndex = -1;
746cdf0e10cSrcweir rOutAxisIndex = -1;
747cdf0e10cSrcweir
748cdf0e10cSrcweir if( xCooSys.is() && xAxis.is() )
749cdf0e10cSrcweir {
750cdf0e10cSrcweir Reference< XAxis > xCurrentAxis;
751cdf0e10cSrcweir sal_Int32 nDimensionCount( xCooSys->getDimension() );
752cdf0e10cSrcweir for( sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
753cdf0e10cSrcweir {
754cdf0e10cSrcweir sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
755cdf0e10cSrcweir for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
756cdf0e10cSrcweir {
757cdf0e10cSrcweir xCurrentAxis = xCooSys->getAxisByDimension(nDimensionIndex,nAxisIndex);
758cdf0e10cSrcweir if( xCurrentAxis == xAxis )
759cdf0e10cSrcweir {
760cdf0e10cSrcweir rOutDimensionIndex = nDimensionIndex;
761cdf0e10cSrcweir rOutAxisIndex = nAxisIndex;
762cdf0e10cSrcweir return true;
763cdf0e10cSrcweir }
764cdf0e10cSrcweir }
765cdf0e10cSrcweir }
766cdf0e10cSrcweir }
767cdf0e10cSrcweir return false;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir
getIndicesForAxis(const Reference<XAxis> & xAxis,const Reference<XDiagram> & xDiagram,sal_Int32 & rOutCooSysIndex,sal_Int32 & rOutDimensionIndex,sal_Int32 & rOutAxisIndex)770cdf0e10cSrcweir bool AxisHelper::getIndicesForAxis( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram
771cdf0e10cSrcweir , sal_Int32& rOutCooSysIndex, sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir //returns true if indices are found
774cdf0e10cSrcweir
775cdf0e10cSrcweir rOutCooSysIndex = -1;
776cdf0e10cSrcweir rOutDimensionIndex = -1;
777cdf0e10cSrcweir rOutAxisIndex = -1;
778cdf0e10cSrcweir
779cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
780cdf0e10cSrcweir if(xCooSysContainer.is())
781cdf0e10cSrcweir {
782cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
783cdf0e10cSrcweir for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC )
784cdf0e10cSrcweir {
785cdf0e10cSrcweir if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], rOutDimensionIndex, rOutAxisIndex ) )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir rOutCooSysIndex = nC;
788cdf0e10cSrcweir return true;
789cdf0e10cSrcweir }
790cdf0e10cSrcweir }
791cdf0e10cSrcweir }
792cdf0e10cSrcweir
793cdf0e10cSrcweir return false;
794cdf0e10cSrcweir }
795cdf0e10cSrcweir
getAllAxesOfCoordinateSystem(const Reference<XCoordinateSystem> & xCooSys,bool bOnlyVisible)796cdf0e10cSrcweir std::vector< Reference< XAxis > > AxisHelper::getAllAxesOfCoordinateSystem(
797cdf0e10cSrcweir const Reference< XCoordinateSystem >& xCooSys
798cdf0e10cSrcweir , bool bOnlyVisible /* = false */ )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxisVector;
801cdf0e10cSrcweir
802cdf0e10cSrcweir if(xCooSys.is())
803cdf0e10cSrcweir {
804cdf0e10cSrcweir sal_Int32 nDimensionIndex = 0;
805cdf0e10cSrcweir sal_Int32 nMaxDimensionIndex = xCooSys->getDimension() -1;
806cdf0e10cSrcweir if( nMaxDimensionIndex>=0 )
807cdf0e10cSrcweir {
808cdf0e10cSrcweir for(nDimensionIndex=0; nDimensionIndex<=nMaxDimensionIndex; ++nDimensionIndex)
809cdf0e10cSrcweir {
810cdf0e10cSrcweir const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
811cdf0e10cSrcweir for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
812cdf0e10cSrcweir {
813cdf0e10cSrcweir try
814cdf0e10cSrcweir {
815cdf0e10cSrcweir Reference< XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
816cdf0e10cSrcweir bool bAddAxis = true;
817cdf0e10cSrcweir if( xAxis.is() )
818cdf0e10cSrcweir {
819cdf0e10cSrcweir if( bOnlyVisible )
820cdf0e10cSrcweir {
821cdf0e10cSrcweir Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY );
822cdf0e10cSrcweir if( !xAxisProp.is() ||
823cdf0e10cSrcweir !(xAxisProp->getPropertyValue( C2U("Show")) >>= bAddAxis) )
824cdf0e10cSrcweir bAddAxis = false;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir if( bAddAxis )
827cdf0e10cSrcweir aAxisVector.push_back( xAxis );
828cdf0e10cSrcweir }
829cdf0e10cSrcweir }
830cdf0e10cSrcweir catch( const uno::Exception & ex )
831cdf0e10cSrcweir {
832cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
833cdf0e10cSrcweir }
834cdf0e10cSrcweir }
835cdf0e10cSrcweir }
836cdf0e10cSrcweir }
837cdf0e10cSrcweir }
838cdf0e10cSrcweir
839cdf0e10cSrcweir return aAxisVector;
840cdf0e10cSrcweir }
841cdf0e10cSrcweir
getAllAxesOfDiagram(const Reference<XDiagram> & xDiagram,bool bOnlyVisible)842cdf0e10cSrcweir Sequence< Reference< XAxis > > AxisHelper::getAllAxesOfDiagram(
843cdf0e10cSrcweir const Reference< XDiagram >& xDiagram
844cdf0e10cSrcweir , bool bOnlyVisible )
845cdf0e10cSrcweir {
846cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxisVector;
847cdf0e10cSrcweir
848cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
849cdf0e10cSrcweir if(xCooSysContainer.is())
850cdf0e10cSrcweir {
851cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
852cdf0e10cSrcweir sal_Int32 nC = 0;
853cdf0e10cSrcweir for( nC=0; nC<aCooSysList.getLength(); ++nC )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxesPerCooSys( AxisHelper::getAllAxesOfCoordinateSystem( aCooSysList[nC], bOnlyVisible ) );
856cdf0e10cSrcweir aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), aAxesPerCooSys.end() );
857cdf0e10cSrcweir }
858cdf0e10cSrcweir }
859cdf0e10cSrcweir
860cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( aAxisVector );
861cdf0e10cSrcweir }
862cdf0e10cSrcweir
getAllGrids(const Reference<XDiagram> & xDiagram)863cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > AxisHelper::getAllGrids( const Reference< XDiagram >& xDiagram )
864cdf0e10cSrcweir {
865cdf0e10cSrcweir Sequence< Reference< XAxis > > aAllAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
866cdf0e10cSrcweir std::vector< Reference< beans::XPropertySet > > aGridVector;
867cdf0e10cSrcweir
868cdf0e10cSrcweir sal_Int32 nA = 0;
869cdf0e10cSrcweir for( nA=0; nA<aAllAxes.getLength(); ++nA )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir Reference< XAxis > xAxis( aAllAxes[nA] );
872cdf0e10cSrcweir if(!xAxis.is())
873cdf0e10cSrcweir continue;
874cdf0e10cSrcweir Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() );
875cdf0e10cSrcweir if( xGridProperties.is() )
876cdf0e10cSrcweir aGridVector.push_back( xGridProperties );
877cdf0e10cSrcweir
878cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );;
879cdf0e10cSrcweir sal_Int32 nSubGrid = 0;
880cdf0e10cSrcweir for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir Reference< beans::XPropertySet > xSubGrid( aSubGrids[nSubGrid] );
883cdf0e10cSrcweir if( xSubGrid.is() )
884cdf0e10cSrcweir aGridVector.push_back( xSubGrid );
885cdf0e10cSrcweir }
886cdf0e10cSrcweir }
887cdf0e10cSrcweir
888cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( aGridVector );
889cdf0e10cSrcweir }
890cdf0e10cSrcweir
getAxisOrGridPossibilities(Sequence<sal_Bool> & rPossibilityList,const Reference<XDiagram> & xDiagram,sal_Bool bAxis)891cdf0e10cSrcweir void AxisHelper::getAxisOrGridPossibilities( Sequence< sal_Bool >& rPossibilityList
892cdf0e10cSrcweir , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
893cdf0e10cSrcweir {
894cdf0e10cSrcweir rPossibilityList.realloc(6);
895cdf0e10cSrcweir
896cdf0e10cSrcweir sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
897cdf0e10cSrcweir
898cdf0e10cSrcweir //set possibilities:
899cdf0e10cSrcweir sal_Int32 nIndex=0;
900cdf0e10cSrcweir Reference< XChartType > xChartType = DiagramHelper::getChartTypeByIndex( xDiagram, 0 );
901cdf0e10cSrcweir for(nIndex=0;nIndex<3;nIndex++)
902cdf0e10cSrcweir rPossibilityList[nIndex]=ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nIndex);
903cdf0e10cSrcweir for(nIndex=3;nIndex<6;nIndex++)
904cdf0e10cSrcweir if( bAxis )
905cdf0e10cSrcweir rPossibilityList[nIndex]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nIndex-3);
906cdf0e10cSrcweir else
907cdf0e10cSrcweir rPossibilityList[nIndex] = rPossibilityList[nIndex-3];
908cdf0e10cSrcweir }
909cdf0e10cSrcweir
isSecondaryYAxisNeeded(const Reference<XCoordinateSystem> & xCooSys)910cdf0e10cSrcweir bool AxisHelper::isSecondaryYAxisNeeded( const Reference< XCoordinateSystem >& xCooSys )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir Reference< chart2::XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
913cdf0e10cSrcweir if( xCTCnt.is() )
914cdf0e10cSrcweir {
915cdf0e10cSrcweir Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes() );
916cdf0e10cSrcweir for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir Reference< XDataSeriesContainer > xSeriesContainer( aChartTypes[i] , uno::UNO_QUERY );
919cdf0e10cSrcweir if( !xSeriesContainer.is() )
920cdf0e10cSrcweir continue;
921cdf0e10cSrcweir
922cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aSeriesList( xSeriesContainer->getDataSeries() );
923cdf0e10cSrcweir for( sal_Int32 nS = aSeriesList.getLength(); nS-- ; )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY );
926cdf0e10cSrcweir if(xProp.is())
927cdf0e10cSrcweir {
928cdf0e10cSrcweir sal_Int32 nAttachedAxisIndex = 0;
929cdf0e10cSrcweir if( ( xProp->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex ) && nAttachedAxisIndex>0 )
930cdf0e10cSrcweir return true;
931cdf0e10cSrcweir }
932cdf0e10cSrcweir }
933cdf0e10cSrcweir }
934cdf0e10cSrcweir }
935cdf0e10cSrcweir return false;
936cdf0e10cSrcweir }
937cdf0e10cSrcweir
shouldAxisBeDisplayed(const Reference<XAxis> & xAxis,const Reference<XCoordinateSystem> & xCooSys)938cdf0e10cSrcweir bool AxisHelper::shouldAxisBeDisplayed( const Reference< XAxis >& xAxis
939cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys )
940cdf0e10cSrcweir {
941cdf0e10cSrcweir bool bRet = false;
942cdf0e10cSrcweir
943cdf0e10cSrcweir if( xAxis.is() && xCooSys.is() )
944cdf0e10cSrcweir {
945cdf0e10cSrcweir sal_Int32 nDimensionIndex=-1;
946cdf0e10cSrcweir sal_Int32 nAxisIndex=-1;
947cdf0e10cSrcweir if( AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ) )
948cdf0e10cSrcweir {
949cdf0e10cSrcweir sal_Int32 nDimensionCount = xCooSys->getDimension();
950cdf0e10cSrcweir Reference< XChartType > xChartType( AxisHelper::getChartTypeByIndex( xCooSys, 0 ) );
951cdf0e10cSrcweir
952cdf0e10cSrcweir bool bMainAxis = (nAxisIndex==MAIN_AXIS_INDEX);
953cdf0e10cSrcweir if( bMainAxis )
954cdf0e10cSrcweir bRet = ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nDimensionIndex);
955cdf0e10cSrcweir else
956cdf0e10cSrcweir bRet = ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nDimensionIndex);
957cdf0e10cSrcweir }
958cdf0e10cSrcweir }
959cdf0e10cSrcweir
960cdf0e10cSrcweir return bRet;
961cdf0e10cSrcweir }
962cdf0e10cSrcweir
getAxisOrGridExcistence(Sequence<sal_Bool> & rExistenceList,const Reference<XDiagram> & xDiagram,sal_Bool bAxis)963cdf0e10cSrcweir void AxisHelper::getAxisOrGridExcistence( Sequence< sal_Bool >& rExistenceList
964cdf0e10cSrcweir , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir rExistenceList.realloc(6);
967cdf0e10cSrcweir
968cdf0e10cSrcweir if(bAxis)
969cdf0e10cSrcweir {
970cdf0e10cSrcweir sal_Int32 nN;
971cdf0e10cSrcweir Reference< XAxis > xAxis;
972cdf0e10cSrcweir for(nN=0;nN<3;nN++)
973cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isAxisShown( nN, true, xDiagram );
974cdf0e10cSrcweir for(nN=3;nN<6;nN++)
975cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isAxisShown( nN%3, false, xDiagram );
976cdf0e10cSrcweir }
977cdf0e10cSrcweir else
978cdf0e10cSrcweir {
979cdf0e10cSrcweir sal_Int32 nN;
980cdf0e10cSrcweir
981cdf0e10cSrcweir for(nN=0;nN<3;nN++)
982cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isGridShown( nN, 0, true, xDiagram );
983cdf0e10cSrcweir for(nN=3;nN<6;nN++)
984cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isGridShown( nN%3, 0, false, xDiagram );
985cdf0e10cSrcweir }
986cdf0e10cSrcweir }
987cdf0e10cSrcweir
changeVisibilityOfAxes(const Reference<XDiagram> & xDiagram,const Sequence<sal_Bool> & rOldExistenceList,const Sequence<sal_Bool> & rNewExistenceList,const Reference<uno::XComponentContext> & xContext,ReferenceSizeProvider * pRefSizeProvider)988cdf0e10cSrcweir bool AxisHelper::changeVisibilityOfAxes( const Reference< XDiagram >& xDiagram
989cdf0e10cSrcweir , const Sequence< sal_Bool >& rOldExistenceList
990cdf0e10cSrcweir , const Sequence< sal_Bool >& rNewExistenceList
991cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext
992cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider )
993cdf0e10cSrcweir {
994cdf0e10cSrcweir bool bChanged = false;
995cdf0e10cSrcweir for(sal_Int32 nN=0;nN<6;nN++)
996cdf0e10cSrcweir {
997cdf0e10cSrcweir if(rOldExistenceList[nN]!=rNewExistenceList[nN])
998cdf0e10cSrcweir {
999cdf0e10cSrcweir bChanged = true;
1000cdf0e10cSrcweir if(rNewExistenceList[nN])
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir AxisHelper::showAxis( nN%3, nN<3, xDiagram, xContext, pRefSizeProvider );
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir else
1005cdf0e10cSrcweir AxisHelper::hideAxis( nN%3, nN<3, xDiagram );
1006cdf0e10cSrcweir }
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir return bChanged;
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir
changeVisibilityOfGrids(const Reference<XDiagram> & xDiagram,const Sequence<sal_Bool> & rOldExistenceList,const Sequence<sal_Bool> & rNewExistenceList,const Reference<uno::XComponentContext> & xContext)1011cdf0e10cSrcweir bool AxisHelper::changeVisibilityOfGrids( const Reference< XDiagram >& xDiagram
1012cdf0e10cSrcweir , const Sequence< sal_Bool >& rOldExistenceList
1013cdf0e10cSrcweir , const Sequence< sal_Bool >& rNewExistenceList
1014cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext )
1015cdf0e10cSrcweir {
1016cdf0e10cSrcweir bool bChanged = false;
1017cdf0e10cSrcweir for(sal_Int32 nN=0;nN<6;nN++)
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir if(rOldExistenceList[nN]!=rNewExistenceList[nN])
1020cdf0e10cSrcweir {
1021cdf0e10cSrcweir bChanged = true;
1022cdf0e10cSrcweir if(rNewExistenceList[nN])
1023cdf0e10cSrcweir AxisHelper::showGrid( nN%3, 0, nN<3, xDiagram, xContext );
1024cdf0e10cSrcweir else
1025cdf0e10cSrcweir AxisHelper::hideGrid( nN%3, 0, nN<3, xDiagram );
1026cdf0e10cSrcweir }
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir return bChanged;
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir
getCoordinateSystemOfAxis(const Reference<XAxis> & xAxis,const Reference<XDiagram> & xDiagram)1031cdf0e10cSrcweir Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemOfAxis(
1032cdf0e10cSrcweir const Reference< XAxis >& xAxis
1033cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram )
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir Reference< XCoordinateSystem > xRet;
1036cdf0e10cSrcweir
1037cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
1038cdf0e10cSrcweir if( xCooSysContainer.is() )
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys;
1041cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
1042cdf0e10cSrcweir for( sal_Int32 nCooSysIndex = 0; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex )
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir xCooSys = aCooSysList[nCooSysIndex];
1045cdf0e10cSrcweir std::vector< Reference< XAxis > > aAllAxis( AxisHelper::getAllAxesOfCoordinateSystem( xCooSys ) );
1046cdf0e10cSrcweir
1047cdf0e10cSrcweir ::std::vector< Reference< XAxis > >::iterator aFound =
1048cdf0e10cSrcweir ::std::find( aAllAxis.begin(), aAllAxis.end(), xAxis );
1049cdf0e10cSrcweir if( aFound != aAllAxis.end())
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir xRet.set( xCooSys );
1052cdf0e10cSrcweir break;
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir return xRet;
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
getChartTypeByIndex(const Reference<XCoordinateSystem> & xCooSys,sal_Int32 nIndex)1059cdf0e10cSrcweir Reference< XChartType > AxisHelper::getChartTypeByIndex( const Reference< XCoordinateSystem >& xCooSys, sal_Int32 nIndex )
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir Reference< XChartType > xChartType;
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
1064cdf0e10cSrcweir if( xChartTypeContainer.is() )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
1067cdf0e10cSrcweir if( nIndex >= 0 && nIndex < aChartTypeList.getLength() )
1068cdf0e10cSrcweir xChartType.set( aChartTypeList[nIndex] );
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir return xChartType;
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir
setRTLAxisLayout(const Reference<XCoordinateSystem> & xCooSys)1074cdf0e10cSrcweir void AxisHelper::setRTLAxisLayout( const Reference< XCoordinateSystem >& xCooSys )
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir if( xCooSys.is() )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir bool bCartesian = xCooSys->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME );
1079cdf0e10cSrcweir if( bCartesian )
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir bool bVertical = false;
1082cdf0e10cSrcweir Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
1083cdf0e10cSrcweir if( xCooSysProp.is() )
1084cdf0e10cSrcweir xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bVertical;
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir sal_Int32 nHorizontalAxisDimension = bVertical ? 1 : 0;
1087cdf0e10cSrcweir sal_Int32 nVerticalAxisDimension = bVertical ? 0 : 1;
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir try
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir //reverse direction for horizontal main axis
1092cdf0e10cSrcweir Reference< chart2::XAxis > xHorizontalMainAxis( AxisHelper::getAxis( nHorizontalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
1093cdf0e10cSrcweir if( xHorizontalMainAxis.is() )
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir chart2::ScaleData aScale = xHorizontalMainAxis->getScaleData();
1096cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_REVERSE;
1097cdf0e10cSrcweir xHorizontalMainAxis->setScaleData(aScale);
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir //mathematical direction for vertical main axis
1101cdf0e10cSrcweir Reference< chart2::XAxis > xVerticalMainAxis( AxisHelper::getAxis( nVerticalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
1102cdf0e10cSrcweir if( xVerticalMainAxis.is() )
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir chart2::ScaleData aScale = xVerticalMainAxis->getScaleData();
1105cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
1106cdf0e10cSrcweir xVerticalMainAxis->setScaleData(aScale);
1107cdf0e10cSrcweir }
1108cdf0e10cSrcweir }
1109cdf0e10cSrcweir catch( uno::Exception & ex )
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir try
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir //reverse direction for horizontal secondary axis
1117cdf0e10cSrcweir Reference< chart2::XAxis > xHorizontalSecondaryAxis( AxisHelper::getAxis( nHorizontalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
1118cdf0e10cSrcweir if( xHorizontalSecondaryAxis.is() )
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir chart2::ScaleData aScale = xHorizontalSecondaryAxis->getScaleData();
1121cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_REVERSE;
1122cdf0e10cSrcweir xHorizontalSecondaryAxis->setScaleData(aScale);
1123cdf0e10cSrcweir }
1124cdf0e10cSrcweir
1125cdf0e10cSrcweir //mathematical direction for vertical secondary axis
1126cdf0e10cSrcweir Reference< chart2::XAxis > xVerticalSecondaryAxis( AxisHelper::getAxis( nVerticalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
1127cdf0e10cSrcweir if( xVerticalSecondaryAxis.is() )
1128cdf0e10cSrcweir {
1129cdf0e10cSrcweir chart2::ScaleData aScale = xVerticalSecondaryAxis->getScaleData();
1130cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
1131cdf0e10cSrcweir xVerticalSecondaryAxis->setScaleData(aScale);
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir catch( uno::Exception & ex )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir }
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir
getFirstChartTypeWithSeriesAttachedToAxisIndex(const Reference<chart2::XDiagram> & xDiagram,const sal_Int32 nAttachedAxisIndex)1142cdf0e10cSrcweir Reference< XChartType > AxisHelper::getFirstChartTypeWithSeriesAttachedToAxisIndex( const Reference< chart2::XDiagram >& xDiagram, const sal_Int32 nAttachedAxisIndex )
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir Reference< XChartType > xChartType;
1145cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
1146cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > >::const_iterator aIter = aSeriesVector.begin();
1147cdf0e10cSrcweir for( ; aIter != aSeriesVector.end(); aIter++ )
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir sal_Int32 nCurrentIndex = DataSeriesHelper::getAttachedAxisIndex( *aIter );
1150cdf0e10cSrcweir if( nAttachedAxisIndex == nCurrentIndex )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir xChartType = DiagramHelper::getChartTypeOfSeries( xDiagram, *aIter );
1153cdf0e10cSrcweir if(xChartType.is())
1154cdf0e10cSrcweir break;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir return xChartType;
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir
isAxisPositioningEnabled()1160cdf0e10cSrcweir bool AxisHelper::isAxisPositioningEnabled()
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
1163cdf0e10cSrcweir return nCurrentVersion >= SvtSaveOptions::ODFVER_012;
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir //.............................................................................
1167cdf0e10cSrcweir } //namespace chart
1168cdf0e10cSrcweir //.............................................................................
1169