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