fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / main / PlottingPositionHelper.cxx
blob1fab030248249d63bfcf1081350d8f4e7aba1736
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "PlottingPositionHelper.hxx"
21 #include "CommonConverters.hxx"
22 #include "ViewDefines.hxx"
23 #include "Linear3DTransformation.hxx"
24 #include "VPolarTransformation.hxx"
25 #include "AbstractShapeFactory.hxx"
26 #include "PropertyMapper.hxx"
27 #include "DateHelper.hxx"
28 #include "defines.hxx"
30 #include <com/sun/star/chart/TimeUnit.hpp>
31 #include <com/sun/star/chart2/AxisType.hpp>
32 #include <com/sun/star/drawing/DoubleSequence.hpp>
33 #include <com/sun/star/drawing/Position3D.hpp>
35 #include <rtl/math.hxx>
37 namespace chart
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::chart2;
42 PlottingPositionHelper::PlottingPositionHelper()
43 : m_aScales()
44 , m_aMatrixScreenToScene()
45 , m_xTransformationLogicToScene(NULL)
46 , m_bSwapXAndY( false )
47 , m_nXResolution( 1000 )
48 , m_nYResolution( 1000 )
49 , m_nZResolution( 1000 )
50 , m_bMaySkipPointsInRegressionCalculation( true )
51 , m_bDateAxis(false)
52 , m_nTimeResolution( ::com::sun::star::chart::TimeUnit::DAY )
53 , m_aNullDate(30,12,1899)
54 , m_fScaledCategoryWidth(1.0)
55 , m_bAllowShiftXAxisPos(false)
56 , m_bAllowShiftZAxisPos(false)
59 PlottingPositionHelper::PlottingPositionHelper( const PlottingPositionHelper& rSource )
60 : m_aScales( rSource.m_aScales )
61 , m_aMatrixScreenToScene( rSource.m_aMatrixScreenToScene )
62 , m_xTransformationLogicToScene( NULL ) //should be recalculated
63 , m_bSwapXAndY( rSource.m_bSwapXAndY )
64 , m_nXResolution( rSource.m_nXResolution )
65 , m_nYResolution( rSource.m_nYResolution )
66 , m_nZResolution( rSource.m_nZResolution )
67 , m_bMaySkipPointsInRegressionCalculation( rSource.m_bMaySkipPointsInRegressionCalculation )
68 , m_bDateAxis( rSource.m_bDateAxis )
69 , m_nTimeResolution( rSource.m_nTimeResolution )
70 , m_aNullDate( rSource.m_aNullDate )
71 , m_fScaledCategoryWidth( rSource.m_fScaledCategoryWidth )
72 , m_bAllowShiftXAxisPos( rSource.m_bAllowShiftXAxisPos )
73 , m_bAllowShiftZAxisPos( rSource.m_bAllowShiftZAxisPos )
77 PlottingPositionHelper::~PlottingPositionHelper()
82 PlottingPositionHelper* PlottingPositionHelper::clone() const
84 PlottingPositionHelper* pRet = new PlottingPositionHelper(*this);
85 return pRet;
88 PlottingPositionHelper* PlottingPositionHelper::createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale )
90 PlottingPositionHelper* pRet = this->clone();
91 pRet->m_aScales[1]=rSecondaryScale;
92 return pRet;
95 void PlottingPositionHelper::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
97 m_aMatrixScreenToScene = HomogenMatrixToB3DHomMatrix(rMatrix);
98 m_xTransformationLogicToScene = NULL;
101 void PlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
103 m_aScales = rScales;
104 m_bSwapXAndY = bSwapXAndYAxis;
105 m_xTransformationLogicToScene = NULL;
108 uno::Reference< XTransformation > PlottingPositionHelper::getTransformationScaledLogicToScene() const
110 //this is a standard transformation for a cartesian coordinate system
112 //transformation from 2) to 4) //@todo 2) and 4) need a ink to a document
114 //we need to apply this transformation to each geometric object because of a bug/problem
115 //of the old drawing layer (the UNO_NAME_3D_EXTRUDE_DEPTH is an integer value instead of an double )
116 if(!m_xTransformationLogicToScene.is())
118 ::basegfx::B3DHomMatrix aMatrix;
119 double MinX = getLogicMinX();
120 double MinY = getLogicMinY();
121 double MinZ = getLogicMinZ();
122 double MaxX = getLogicMaxX();
123 double MaxY = getLogicMaxY();
124 double MaxZ = getLogicMaxZ();
126 AxisOrientation nXAxisOrientation = m_aScales[0].Orientation;
127 AxisOrientation nYAxisOrientation = m_aScales[1].Orientation;
128 AxisOrientation nZAxisOrientation = m_aScales[2].Orientation;
130 //apply scaling
131 doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
132 doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
134 if(m_bSwapXAndY)
136 std::swap(MinX,MinY);
137 std::swap(MaxX,MaxY);
138 std::swap(nXAxisOrientation,nYAxisOrientation);
141 double fWidthX = MaxX - MinX;
142 double fWidthY = MaxY - MinY;
143 double fWidthZ = MaxZ - MinZ;
145 double fScaleDirectionX = AxisOrientation_MATHEMATICAL==nXAxisOrientation ? 1.0 : -1.0;
146 double fScaleDirectionY = AxisOrientation_MATHEMATICAL==nYAxisOrientation ? 1.0 : -1.0;
147 double fScaleDirectionZ = AxisOrientation_MATHEMATICAL==nZAxisOrientation ? -1.0 : 1.0;
149 double fScaleX = fScaleDirectionX*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthX;
150 double fScaleY = fScaleDirectionY*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthY;
151 double fScaleZ = fScaleDirectionZ*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthZ;
153 aMatrix.scale(fScaleX, fScaleY, fScaleZ);
155 if( AxisOrientation_MATHEMATICAL==nXAxisOrientation )
156 aMatrix.translate(-MinX*fScaleX, 0.0, 0.0);
157 else
158 aMatrix.translate(-MaxX*fScaleX, 0.0, 0.0);
159 if( AxisOrientation_MATHEMATICAL==nYAxisOrientation )
160 aMatrix.translate(0.0, -MinY*fScaleY, 0.0);
161 else
162 aMatrix.translate(0.0, -MaxY*fScaleY, 0.0);
163 if( AxisOrientation_MATHEMATICAL==nZAxisOrientation )
164 aMatrix.translate(0.0, 0.0, -MaxZ*fScaleZ);//z direction in draw is reverse mathematical direction
165 else
166 aMatrix.translate(0.0, 0.0, -MinZ*fScaleZ);
168 aMatrix = m_aMatrixScreenToScene*aMatrix;
170 m_xTransformationLogicToScene = new Linear3DTransformation(B3DHomMatrixToHomogenMatrix( aMatrix ),m_bSwapXAndY);
172 return m_xTransformationLogicToScene;
175 drawing::Position3D PlottingPositionHelper::transformLogicToScene(
176 double fX, double fY, double fZ, bool bClip ) const
178 this->doLogicScaling( &fX,&fY,&fZ );
179 if(bClip)
180 this->clipScaledLogicValues( &fX,&fY,&fZ );
182 return this->transformScaledLogicToScene( fX, fY, fZ, false );
185 drawing::Position3D PlottingPositionHelper::transformScaledLogicToScene(
186 double fX, double fY, double fZ, bool bClip ) const
188 if( bClip )
189 this->clipScaledLogicValues( &fX,&fY,&fZ );
191 drawing::Position3D aPos( fX, fY, fZ);
193 uno::Reference< XTransformation > xTransformation =
194 this->getTransformationScaledLogicToScene();
195 uno::Sequence< double > aSeq =
196 xTransformation->transform( Position3DToSequence(aPos) );
197 return SequenceToPosition3D(aSeq);
200 awt::Point PlottingPositionHelper::transformSceneToScreenPosition( const drawing::Position3D& rScenePosition3D
201 , const uno::Reference< drawing::XShapes >& xSceneTarget
202 , AbstractShapeFactory* pShapeFactory
203 , sal_Int32 nDimensionCount )
205 //@todo would like to have a cheaper method to do this transformation
206 awt::Point aScreenPoint( static_cast<sal_Int32>(rScenePosition3D.PositionX), static_cast<sal_Int32>(rScenePosition3D.PositionY) );
208 //transformation from scene to screen (only necessary for 3D):
209 if(3==nDimensionCount)
211 //create 3D anchor shape
212 tPropertyNameMap aDummyPropertyNameMap;
213 uno::Reference< drawing::XShape > xShape3DAnchor = pShapeFactory->createCube( xSceneTarget
214 , rScenePosition3D,drawing::Direction3D(1,1,1)
215 , 0, 0, aDummyPropertyNameMap);
216 //get 2D position from xShape3DAnchor
217 aScreenPoint = xShape3DAnchor->getPosition();
218 xSceneTarget->remove(xShape3DAnchor);
220 return aScreenPoint;
223 void PlottingPositionHelper::transformScaledLogicToScene( drawing::PolyPolygonShape3D& rPolygon ) const
225 drawing::Position3D aScenePosition;
226 for( sal_Int32 nS = rPolygon.SequenceX.getLength(); nS--;)
228 drawing::DoubleSequence& xValues = rPolygon.SequenceX[nS];
229 drawing::DoubleSequence& yValues = rPolygon.SequenceY[nS];
230 drawing::DoubleSequence& zValues = rPolygon.SequenceZ[nS];
231 for( sal_Int32 nP = xValues.getLength(); nP--; )
233 double& fX = xValues[nP];
234 double& fY = yValues[nP];
235 double& fZ = zValues[nP];
236 aScenePosition = this->transformScaledLogicToScene( fX,fY,fZ,true );
237 fX = aScenePosition.PositionX;
238 fY = aScenePosition.PositionY;
239 fZ = aScenePosition.PositionZ;
244 void PlottingPositionHelper::clipScaledLogicValues( double* pX, double* pY, double* pZ ) const
246 //get logic clip values:
247 double MinX = getLogicMinX();
248 double MinY = getLogicMinY();
249 double MinZ = getLogicMinZ();
250 double MaxX = getLogicMaxX();
251 double MaxY = getLogicMaxY();
252 double MaxZ = getLogicMaxZ();
254 //apply scaling
255 doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
256 doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
258 if(pX)
260 if( *pX < MinX )
261 *pX = MinX;
262 else if( *pX > MaxX )
263 *pX = MaxX;
265 if(pY)
267 if( *pY < MinY )
268 *pY = MinY;
269 else if( *pY > MaxY )
270 *pY = MaxY;
272 if(pZ)
274 if( *pZ < MinZ )
275 *pZ = MinZ;
276 else if( *pZ > MaxZ )
277 *pZ = MaxZ;
281 basegfx::B2DRectangle PlottingPositionHelper::getScaledLogicClipDoubleRect() const
283 //get logic clip values:
284 double MinX = getLogicMinX();
285 double MinY = getLogicMinY();
286 double MinZ = getLogicMinZ();
287 double MaxX = getLogicMaxX();
288 double MaxY = getLogicMaxY();
289 double MaxZ = getLogicMaxZ();
291 //apply scaling
292 doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
293 doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
295 basegfx::B2DRectangle aRet( MinX, MaxY, MaxX, MinY );
296 return aRet;
299 drawing::Direction3D PlottingPositionHelper::getScaledLogicWidth() const
301 drawing::Direction3D aRet;
303 double MinX = getLogicMinX();
304 double MinY = getLogicMinY();
305 double MinZ = getLogicMinZ();
306 double MaxX = getLogicMaxX();
307 double MaxY = getLogicMaxY();
308 double MaxZ = getLogicMaxZ();
310 doLogicScaling( &MinX, &MinY, &MinZ );
311 doLogicScaling( &MaxX, &MaxY, &MaxZ);
313 aRet.DirectionX = MaxX - MinX;
314 aRet.DirectionY = MaxY - MinY;
315 aRet.DirectionZ = MaxZ - MinZ;
316 return aRet;
319 PolarPlottingPositionHelper::PolarPlottingPositionHelper( NormalAxis eNormalAxis )
320 : m_fRadiusOffset(0.0)
321 , m_fAngleDegreeOffset(90.0)
322 , m_aUnitCartesianToScene()
323 , m_eNormalAxis(eNormalAxis)
325 m_bMaySkipPointsInRegressionCalculation = false;
328 PolarPlottingPositionHelper::PolarPlottingPositionHelper( const PolarPlottingPositionHelper& rSource )
329 : PlottingPositionHelper(rSource)
330 , m_fRadiusOffset( rSource.m_fRadiusOffset )
331 , m_fAngleDegreeOffset( rSource.m_fAngleDegreeOffset )
332 , m_aUnitCartesianToScene( rSource.m_aUnitCartesianToScene )
333 , m_eNormalAxis( rSource.m_eNormalAxis )
337 PolarPlottingPositionHelper::~PolarPlottingPositionHelper()
341 PlottingPositionHelper* PolarPlottingPositionHelper::clone() const
343 PolarPlottingPositionHelper* pRet = new PolarPlottingPositionHelper(*this);
344 return pRet;
347 void PolarPlottingPositionHelper::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
349 PlottingPositionHelper::setTransformationSceneToScreen( rMatrix);
350 m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene );
352 void PolarPlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
354 PlottingPositionHelper::setScales( rScales, bSwapXAndYAxis );
355 m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene );
358 ::basegfx::B3DHomMatrix PolarPlottingPositionHelper::impl_calculateMatrixUnitCartesianToScene( const ::basegfx::B3DHomMatrix& rMatrixScreenToScene ) const
360 ::basegfx::B3DHomMatrix aRet;
362 if( m_aScales.empty() )
363 return aRet;
365 double fTranslate =1.0;
366 double fScale =FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0;
368 double fTranslateLogicZ =fTranslate;
369 double fScaleLogicZ =fScale;
371 double fScaleDirectionZ = AxisOrientation_MATHEMATICAL==m_aScales[2].Orientation ? 1.0 : -1.0;
372 double MinZ = getLogicMinZ();
373 double MaxZ = getLogicMaxZ();
374 doLogicScaling( 0, 0, &MinZ );
375 doLogicScaling( 0, 0, &MaxZ );
376 double fWidthZ = MaxZ - MinZ;
378 if( AxisOrientation_MATHEMATICAL==m_aScales[2].Orientation )
379 fTranslateLogicZ=MinZ;
380 else
381 fTranslateLogicZ=MaxZ;
382 fScaleLogicZ = fScaleDirectionZ*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthZ;
385 double fTranslateX = fTranslate;
386 double fTranslateY = fTranslate;
387 double fTranslateZ = fTranslate;
389 double fScaleX = fScale;
390 double fScaleY = fScale;
391 double fScaleZ = fScale;
393 switch(m_eNormalAxis)
395 case NormalAxis_X:
397 fTranslateX = fTranslateLogicZ;
398 fScaleX = fScaleLogicZ;
400 break;
401 case NormalAxis_Y:
403 fTranslateY = fTranslateLogicZ;
404 fScaleY = fScaleLogicZ;
406 break;
407 default: //NormalAxis_Z:
409 fTranslateZ = fTranslateLogicZ;
410 fScaleZ = fScaleLogicZ;
412 break;
415 aRet.translate(fTranslateX, fTranslateY, fTranslateZ);//x first
416 aRet.scale(fScaleX, fScaleY, fScaleZ);//x first
418 aRet = rMatrixScreenToScene * aRet;
419 return aRet;
422 uno::Reference< XTransformation > PolarPlottingPositionHelper::getTransformationScaledLogicToScene() const
424 if( !m_xTransformationLogicToScene.is() )
425 m_xTransformationLogicToScene = new VPolarTransformation(*this);
426 return m_xTransformationLogicToScene;
429 double PolarPlottingPositionHelper::getWidthAngleDegree( double& fStartLogicValueOnAngleAxis, double& fEndLogicValueOnAngleAxis ) const
431 const ExplicitScaleData& rAngleScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[0];
432 if( AxisOrientation_MATHEMATICAL != rAngleScale.Orientation )
434 double fHelp = fEndLogicValueOnAngleAxis;
435 fEndLogicValueOnAngleAxis = fStartLogicValueOnAngleAxis;
436 fStartLogicValueOnAngleAxis = fHelp;
439 double fStartAngleDegree = this->transformToAngleDegree( fStartLogicValueOnAngleAxis );
440 double fEndAngleDegree = this->transformToAngleDegree( fEndLogicValueOnAngleAxis );
441 double fWidthAngleDegree = fEndAngleDegree - fStartAngleDegree;
443 if( ::rtl::math::approxEqual( fStartAngleDegree, fEndAngleDegree )
444 && !::rtl::math::approxEqual( fStartLogicValueOnAngleAxis, fEndLogicValueOnAngleAxis ) )
445 fWidthAngleDegree = 360.0;
447 while(fWidthAngleDegree<0.0)
448 fWidthAngleDegree+=360.0;
449 while(fWidthAngleDegree>360.0)
450 fWidthAngleDegree-=360.0;
452 return fWidthAngleDegree;
455 //This method does a lot of computation for understanding which scale to
456 //utilize and if reverse orientation should be used. Indeed, for a pie or donut,
457 //the final result is as simple as multiplying by 360 and adding
458 //`m_fAngleDegreeOffset`.
459 double PolarPlottingPositionHelper::transformToAngleDegree( double fLogicValueOnAngleAxis, bool bDoScaling ) const
461 double fRet=0.0;
463 double fAxisAngleScaleDirection = 1.0;
465 const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[0];
466 if(AxisOrientation_MATHEMATICAL != rScale.Orientation)
467 fAxisAngleScaleDirection *= -1.0;
470 double MinAngleValue = 0.0;
471 double MaxAngleValue = 0.0;
473 double MinX = getLogicMinX();
474 double MinY = getLogicMinY();
475 double MaxX = getLogicMaxX();
476 double MaxY = getLogicMaxY();
477 double MinZ = getLogicMinZ();
478 double MaxZ = getLogicMaxZ();
480 doLogicScaling( &MinX, &MinY, &MinZ );
481 doLogicScaling( &MaxX, &MaxY, &MaxZ);
483 MinAngleValue = m_bSwapXAndY ? MinY : MinX;
484 MaxAngleValue = m_bSwapXAndY ? MaxY : MaxX;
487 double fScaledLogicAngleValue = 0.0;
488 if(bDoScaling)
490 double fX = m_bSwapXAndY ? getLogicMaxX() : fLogicValueOnAngleAxis;
491 double fY = m_bSwapXAndY ? fLogicValueOnAngleAxis : getLogicMaxY();
492 double fZ = getLogicMaxZ();
493 clipLogicValues( &fX, &fY, &fZ );
494 doLogicScaling( &fX, &fY, &fZ );
495 fScaledLogicAngleValue = m_bSwapXAndY ? fY : fX;
497 else
498 fScaledLogicAngleValue = fLogicValueOnAngleAxis;
500 fRet = m_fAngleDegreeOffset
501 + fAxisAngleScaleDirection*(fScaledLogicAngleValue-MinAngleValue)*360.0
502 /fabs(MaxAngleValue-MinAngleValue);
503 while(fRet>360.0)
504 fRet-=360.0;
505 while(fRet<0)
506 fRet+=360.0;
507 return fRet;
511 * Given a value in the radius axis scale range, it returns, in the simplest
512 * case (that is when `m_fRadiusOffset` is zero), the normalized value; when
513 * `m_fRadiusOffset` is not zero (e.g. as in the case of a donut), the interval
514 * used for normalization is extended by `m_fRadiusOffset`: if the axis
515 * orientation is not reversed the new interval becomes
516 * [scale.Minimum - m_fRadiusOffset, scale.Maximum] else it becomes
517 * [scale.Minimum, scale.Maximum + m_fRadiusOffset].
518 * Pay attention here! For the latter case, since the axis orientation is
519 * reversed, the normalization is reversed too. Indeed, we have
520 * `transformToRadius(scale.Maximum + m_fRadiusOffset) = 0` and
521 * `transformToRadius(scale.Minimum) = 1`.
523 * For a pie chart the radius axis scale range is initialized by the
524 * `getMinimum` and `getMaximum` methods of the `PieChart` object (see notes
525 * for `VCoordinateSystem::prepareAutomaticAxisScaling`).
526 * So we have scale.Minimum = 0.5 (always constant!) and
527 * scale.Maximum = 0.5 + number_of_rings + max_offset
528 * (see notes for `PieChart::getMaxOffset`).
529 * Hence we get the following general formulas for computing normalized inner
530 * and outer radius:
532 * 1- transformToRadius(inner_radius) =
533 * (number_of_rings - (ring_index + 1) + m_fRadiusOffset)
534 * / (number_of_rings + max_offset + m_fRadiusOffset)
536 * 2- transformToRadius(outer_radius) =
537 * (1 + number_of_rings - (ring_index + 1) + m_fRadiusOffset)
538 * / (number_of_rings + max_offset + m_fRadiusOffset).
540 * Here you have to take into account that values for inner and outer radius
541 * are swapped since the radius axis is reversed (See notes for
542 * `PiePositionHelper::getInnerAndOuterRadius`). So indeed inner_radius is
543 * the outer and outer_radius is the inner. Anyway still because of the reverse
544 * orientation, the normalization performed by `transformToRadius` is reversed
545 * too, as we have seen above. Hence `transformToRadius(inner_radius)` is
546 * really the normalized inner radius and `transformToRadius(outer_radius)` is
547 * really the normalized outer radius.
549 * Some basic examples where we apply the above formulas:
550 * 1- For a non-exploded pie chart we have:
551 * `transformToRadius(inner_radius) = 0`,
552 * `transformToRadius(outer_radius) = 1`.
553 * 2- For a non-exploded donut with a single ring we have:
554 * `transformToRadius(inner_radius) =
555 * m_fRadiusOffset/(1 + m_fRadiusOffset)`,
556 * `transformToRadius(outer_radius) =
557 * (1 + m_fRadiusOffset)/(1 + m_fRadiusOffset) = 1`.
558 * 3- For an exploded pie chart we have:
559 * `transformToRadius(inner_radius) = 0/(1 + max_offset) = 0`,
560 * `transformToRadius(outer_radius) = 1/(1 + max_offset)`.
562 * The third example needs some remark. Both the logical inner and outer
563 * radius passed to `transformToRadius` are offset by `max_offset`.
564 * However the returned normalized values do not contain any (normalized)
565 * offset term at all, otherwise the returned values would be
566 * `max_offset/(1 + max_offset)` and `1`. Hence, for exploded pie/donut,
567 * `transformToRadius` returns the normalized value of radii without any
568 * offset term. These values are smaller than in the non-exploded case by an
569 * amount equals to the value of the normalized maximum offset
570 * (`max_offset/(1 + max_offset)` in the example above). That is due to the
571 * fact that the normalization keeps into account the space needed for the
572 * offset. This is the correct behavior, in fact the offset for the current
573 * slice could be different from the maximum offset.
574 * These remarks should clarify why the `PieChart::createDataPoint` and
575 * `PieChart::createTextLabelShape` methods add the normalized offset (for the
576 * current slice) to the normalized radii in order to achieve the correct
577 * placement of slice and text shapes.
579 double PolarPlottingPositionHelper::transformToRadius( double fLogicValueOnRadiusAxis, bool bDoScaling ) const
581 double fNormalRadius = 0.0;
583 double fScaledLogicRadiusValue = 0.0;
584 double fX = m_bSwapXAndY ? fLogicValueOnRadiusAxis: getLogicMaxX();
585 double fY = m_bSwapXAndY ? getLogicMaxY() : fLogicValueOnRadiusAxis;
586 if(bDoScaling)
587 doLogicScaling( &fX, &fY, 0 );
589 fScaledLogicRadiusValue = m_bSwapXAndY ? fX : fY;
591 bool bMinIsInnerRadius = true;
592 const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1];
593 if(AxisOrientation_MATHEMATICAL != rScale.Orientation)
594 bMinIsInnerRadius = false;
596 double fInnerScaledLogicRadius=0.0;
597 double fOuterScaledLogicRadius=0.0;
599 double MinX = getLogicMinX();
600 double MinY = getLogicMinY();
601 doLogicScaling( &MinX, &MinY, 0 );
602 double MaxX = getLogicMaxX();
603 double MaxY = getLogicMaxY();
604 doLogicScaling( &MaxX, &MaxY, 0 );
606 double fMin = m_bSwapXAndY ? MinX : MinY;
607 double fMax = m_bSwapXAndY ? MaxX : MaxY;
609 fInnerScaledLogicRadius = bMinIsInnerRadius ? fMin : fMax;
610 fOuterScaledLogicRadius = bMinIsInnerRadius ? fMax : fMin;
613 if( bMinIsInnerRadius )
614 fInnerScaledLogicRadius -= fabs(m_fRadiusOffset);
615 else
616 fInnerScaledLogicRadius += fabs(m_fRadiusOffset);
617 fNormalRadius = (fScaledLogicRadiusValue-fInnerScaledLogicRadius)/(fOuterScaledLogicRadius-fInnerScaledLogicRadius);
619 return fNormalRadius;
622 drawing::Position3D PolarPlottingPositionHelper::transformLogicToScene( double fX, double fY, double fZ, bool bClip ) const
624 if(bClip)
625 this->clipLogicValues( &fX,&fY,&fZ );
626 double fLogicValueOnAngleAxis = m_bSwapXAndY ? fY : fX;
627 double fLogicValueOnRadiusAxis = m_bSwapXAndY ? fX : fY;
628 return this->transformAngleRadiusToScene( fLogicValueOnAngleAxis, fLogicValueOnRadiusAxis, fZ, true );
631 drawing::Position3D PolarPlottingPositionHelper::transformScaledLogicToScene( double fX, double fY, double fZ, bool bClip ) const
633 if(bClip)
634 this->clipScaledLogicValues( &fX,&fY,&fZ );
635 double fLogicValueOnAngleAxis = m_bSwapXAndY ? fY : fX;
636 double fLogicValueOnRadiusAxis = m_bSwapXAndY ? fX : fY;
637 return this->transformAngleRadiusToScene( fLogicValueOnAngleAxis, fLogicValueOnRadiusAxis, fZ, false );
639 drawing::Position3D PolarPlottingPositionHelper::transformUnitCircleToScene( double fUnitAngleDegree, double fUnitRadius
640 , double fLogicZ, bool /* bDoScaling */ ) const
642 double fAnglePi = fUnitAngleDegree*F_PI/180.0;
644 double fX=fUnitRadius*rtl::math::cos(fAnglePi);
645 double fY=fUnitRadius*rtl::math::sin(fAnglePi);
646 double fZ=fLogicZ;
648 switch(m_eNormalAxis)
650 case NormalAxis_X:
651 std::swap(fX,fZ);
652 break;
653 case NormalAxis_Y:
654 std::swap(fY,fZ);
655 fZ*=-1;
656 break;
657 default: //NormalAxis_Z
658 break;
661 //!! applying matrix to vector does ignore translation, so it is important to use a B3DPoint here instead of B3DVector
662 ::basegfx::B3DPoint aPoint(fX,fY,fZ);
663 ::basegfx::B3DPoint aRet = m_aUnitCartesianToScene * aPoint;
664 return B3DPointToPosition3D(aRet);
667 drawing::Position3D PolarPlottingPositionHelper::transformAngleRadiusToScene( double fLogicValueOnAngleAxis, double fLogicValueOnRadiusAxis, double fLogicZ, bool bDoScaling ) const
669 double fUnitAngleDegree = this->transformToAngleDegree(fLogicValueOnAngleAxis,bDoScaling);
670 double fUnitRadius = this->transformToRadius(fLogicValueOnRadiusAxis,bDoScaling);
672 return transformUnitCircleToScene( fUnitAngleDegree, fUnitRadius, fLogicZ, bDoScaling );
675 double PolarPlottingPositionHelper::getOuterLogicRadius() const
677 const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1];
678 if( AxisOrientation_MATHEMATICAL==rScale.Orientation )
679 return rScale.Maximum;
680 else
681 return rScale.Minimum;
684 bool PlottingPositionHelper::isPercentY() const
686 return m_aScales[1].AxisType==AxisType::PERCENT;
689 double PlottingPositionHelper::getBaseValueY() const
691 return m_aScales[1].Origin;
694 void PlottingPositionHelper::setTimeResolution( long nTimeResolution, const Date& rNullDate )
696 m_nTimeResolution = nTimeResolution;
697 m_aNullDate = rNullDate;
699 //adapt category width
700 double fCategoryWidth = 1.0;
701 if( !m_aScales.empty() )
703 if( m_aScales[0].AxisType == ::com::sun::star::chart2::AxisType::DATE )
705 m_bDateAxis = true;
706 if( nTimeResolution == ::com::sun::star::chart::TimeUnit::YEAR )
708 const double fMonthCount = 12.0;//todo: this depends on the DateScaling and must be adjusted in case we use more generic calendars in future
709 fCategoryWidth = fMonthCount;
713 setScaledCategoryWidth(fCategoryWidth);
716 void PlottingPositionHelper::setScaledCategoryWidth( double fScaledCategoryWidth )
718 m_fScaledCategoryWidth = fScaledCategoryWidth;
720 void PlottingPositionHelper::AllowShiftXAxisPos( bool bAllowShift )
722 m_bAllowShiftXAxisPos = bAllowShift;
724 void PlottingPositionHelper::AllowShiftZAxisPos( bool bAllowShift )
726 m_bAllowShiftZAxisPos = bAllowShift;
731 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */