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