Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / chart2 / source / view / charttypes / AreaChart.cxx
blobfa0ec3dd185767bd01121ae6cd22a843b1caee84
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 "AreaChart.hxx"
21 #include "PlottingPositionHelper.hxx"
22 #include "ShapeFactory.hxx"
23 #include "CommonConverters.hxx"
24 #include "macros.hxx"
25 #include "ViewDefines.hxx"
26 #include "ObjectIdentifier.hxx"
27 #include "Splines.hxx"
28 #include "ChartTypeHelper.hxx"
29 #include "LabelPositionHelper.hxx"
30 #include "Clipping.hxx"
31 #include "Stripe.hxx"
32 #include "PolarLabelPositionHelper.hxx"
33 #include "DateHelper.hxx"
35 #include <com/sun/star/chart2/Symbol.hpp>
36 #include <com/sun/star/chart/DataLabelPlacement.hpp>
37 #include <com/sun/star/chart/MissingValueTreatment.hpp>
39 #include <editeng/unoprnms.hxx>
40 #include <rtl/math.hxx>
42 #include <com/sun/star/drawing/DoubleSequence.hpp>
43 #include <com/sun/star/drawing/NormalsKind.hpp>
44 #include <com/sun/star/lang/XServiceName.hpp>
46 //.............................................................................
47 namespace chart
49 //.............................................................................
50 using namespace ::com::sun::star;
51 using namespace ::rtl::math;
52 using namespace ::com::sun::star::chart2;
54 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 AreaChart::AreaChart( const uno::Reference<XChartType>& xChartTypeModel
59 , sal_Int32 nDimensionCount
60 , bool bCategoryXAxis
61 , bool bNoArea
62 , PlottingPositionHelper* pPlottingPositionHelper
63 , bool bConnectLastToFirstPoint
64 , bool bExpandIfValuesCloseToBorder
65 , sal_Int32 nKeepAspectRatio
66 , const drawing::Direction3D& rAspectRatio
68 : VSeriesPlotter( xChartTypeModel, nDimensionCount, bCategoryXAxis )
69 , m_pMainPosHelper(pPlottingPositionHelper)
70 , m_bArea(!bNoArea)
71 , m_bLine(bNoArea)
72 , m_bSymbol( ChartTypeHelper::isSupportingSymbolProperties(xChartTypeModel,nDimensionCount) )
73 , m_bIsPolarCooSys( bConnectLastToFirstPoint )
74 , m_bConnectLastToFirstPoint( bConnectLastToFirstPoint )
75 , m_bExpandIfValuesCloseToBorder( bExpandIfValuesCloseToBorder )
76 , m_nKeepAspectRatio(nKeepAspectRatio)
77 , m_aGivenAspectRatio(rAspectRatio)
78 , m_eCurveStyle(CurveStyle_LINES)
79 , m_nCurveResolution(20)
80 , m_nSplineOrder(3)
81 , m_xSeriesTarget(0)
82 , m_xErrorBarTarget(0)
83 , m_xTextTarget(0)
84 , m_xRegressionCurveEquationTarget(0)
86 if( !m_pMainPosHelper )
87 m_pMainPosHelper = new PlottingPositionHelper();
88 if( m_pMainPosHelper )
90 m_pMainPosHelper->AllowShiftXAxisPos(true);
91 m_pMainPosHelper->AllowShiftZAxisPos(true);
93 PlotterBase::m_pPosHelper = m_pMainPosHelper;
94 VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper;
96 try
98 if( m_xChartTypeModelProps.is() )
100 m_xChartTypeModelProps->getPropertyValue( C2U( "CurveStyle" ) ) >>= m_eCurveStyle;
101 m_xChartTypeModelProps->getPropertyValue( C2U( "CurveResolution" ) ) >>= m_nCurveResolution;
102 m_xChartTypeModelProps->getPropertyValue( C2U( "SplineOrder" ) ) >>= m_nSplineOrder;
105 catch( uno::Exception& e )
107 //the above properties are not supported by all charttypes supported by this class (e.g. area or net chart)
108 //in that cases this exception is ok
109 e.Context.is();//to have debug information without compilation warnings
113 AreaChart::~AreaChart()
115 delete m_pMainPosHelper;
118 double AreaChart::getMaximumX()
120 double fMax = VSeriesPlotter::getMaximumX();
121 if( m_bCategoryXAxis && m_bIsPolarCooSys )//the angle axis in net charts needs a different autoscaling
122 fMax += 1.0;
123 return fMax;
126 bool AreaChart::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex )
128 return m_bExpandIfValuesCloseToBorder &&
129 VSeriesPlotter::isExpandIfValuesCloseToBorder( nDimensionIndex );
132 bool AreaChart::isSeperateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex*/ )
134 // no separate stacking in all types of line/area charts
135 return false;
138 //-----------------------------------------------------------------
140 LegendSymbolStyle AreaChart::getLegendSymbolStyle()
142 if( m_bArea || m_nDimension == 3 )
143 return LegendSymbolStyle_BOX;
144 return LegendSymbolStyle_LINE;
147 uno::Any AreaChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex )
149 uno::Any aRet;
151 Symbol* pSymbolProperties = rSeries.getSymbolProperties( nPointIndex );
152 if( pSymbolProperties )
154 aRet = uno::makeAny(*pSymbolProperties);
157 return aRet;
160 drawing::Direction3D AreaChart::getPreferredDiagramAspectRatio() const
162 if( m_nKeepAspectRatio == 1 )
163 return m_aGivenAspectRatio;
164 drawing::Direction3D aRet(1,-1,1);
165 if( m_nDimension == 2 )
166 aRet = drawing::Direction3D(-1,-1,-1);
167 else
169 drawing::Direction3D aScale( m_pPosHelper->getScaledLogicWidth() );
170 aRet.DirectionZ = aScale.DirectionZ*0.2;
171 if(aRet.DirectionZ>1.0)
172 aRet.DirectionZ=1.0;
173 if(aRet.DirectionZ>10)
174 aRet.DirectionZ=10;
176 return aRet;
179 bool AreaChart::keepAspectRatio() const
181 if( m_nKeepAspectRatio == 0 )
182 return false;
183 if( m_nKeepAspectRatio == 1 )
184 return true;
185 if( m_nDimension == 2 )
187 if( !m_bSymbol )
188 return false;
190 return true;
193 void AreaChart::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot )
195 if( m_bArea && !m_bIsPolarCooSys && pSeries )
197 sal_Int32 nMissingValueTreatment = pSeries->getMissingValueTreatment();
198 if( nMissingValueTreatment == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
199 pSeries->setMissingValueTreatment( ::com::sun::star::chart::MissingValueTreatment::USE_ZERO );
201 if( m_nDimension == 3 && !m_bCategoryXAxis )
203 //3D xy always deep
204 OSL_ENSURE( zSlot==-1,"3D xy charts should be deep stacked in model also" );
205 zSlot=-1;
206 xSlot=0;
207 ySlot=0;
209 VSeriesPlotter::addSeries( pSeries, zSlot, xSlot, ySlot );
212 void lcl_removeDuplicatePoints( drawing::PolyPolygonShape3D& rPolyPoly, PlottingPositionHelper& rPosHelper )
214 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
215 if(!nPolyCount)
216 return;
218 drawing::PolyPolygonShape3D aTmp;
219 aTmp.SequenceX.realloc(nPolyCount);
220 aTmp.SequenceY.realloc(nPolyCount);
221 aTmp.SequenceZ.realloc(nPolyCount);
223 for( sal_Int32 nPolygonIndex = 0; nPolygonIndex<nPolyCount; nPolygonIndex++ )
225 drawing::DoubleSequence* pOuterSourceX = &rPolyPoly.SequenceX.getArray()[nPolygonIndex];
226 drawing::DoubleSequence* pOuterSourceY = &rPolyPoly.SequenceY.getArray()[nPolygonIndex];
227 drawing::DoubleSequence* pOuterSourceZ = &rPolyPoly.SequenceZ.getArray()[nPolygonIndex];
229 drawing::DoubleSequence* pOuterTargetX = &aTmp.SequenceX.getArray()[nPolygonIndex];
230 drawing::DoubleSequence* pOuterTargetY = &aTmp.SequenceY.getArray()[nPolygonIndex];
231 drawing::DoubleSequence* pOuterTargetZ = &aTmp.SequenceZ.getArray()[nPolygonIndex];
233 sal_Int32 nPointCount = pOuterSourceX->getLength();
234 if( !nPointCount )
235 continue;
237 pOuterTargetX->realloc(nPointCount);
238 pOuterTargetY->realloc(nPointCount);
239 pOuterTargetZ->realloc(nPointCount);
241 double* pSourceX = pOuterSourceX->getArray();
242 double* pSourceY = pOuterSourceY->getArray();
243 double* pSourceZ = pOuterSourceZ->getArray();
245 double* pTargetX = pOuterTargetX->getArray();
246 double* pTargetY = pOuterTargetY->getArray();
247 double* pTargetZ = pOuterTargetZ->getArray();
249 //copy first point
250 *pTargetX=*pSourceX++;
251 *pTargetY=*pSourceY++;
252 *pTargetZ=*pSourceZ++;
253 sal_Int32 nTargetPointCount=1;
255 for( sal_Int32 nSource=1; nSource<nPointCount; nSource++ )
257 if( !rPosHelper.isSameForGivenResolution( *pTargetX, *pTargetY, *pTargetZ
258 , *pSourceX, *pSourceY, *pSourceZ ) )
260 pTargetX++; pTargetY++; pTargetZ++;
261 *pTargetX=*pSourceX;
262 *pTargetY=*pSourceY;
263 *pTargetZ=*pSourceZ;
264 nTargetPointCount++;
266 pSourceX++; pSourceY++; pSourceZ++;
269 //free unused space
270 if( nTargetPointCount<nPointCount )
272 pOuterTargetX->realloc(nTargetPointCount);
273 pOuterTargetY->realloc(nTargetPointCount);
274 pOuterTargetZ->realloc(nTargetPointCount);
277 pOuterSourceX->realloc(0);
278 pOuterSourceY->realloc(0);
279 pOuterSourceZ->realloc(0);
282 //free space
283 rPolyPoly.SequenceX.realloc(nPolyCount);
284 rPolyPoly.SequenceY.realloc(nPolyCount);
285 rPolyPoly.SequenceZ.realloc(nPolyCount);
287 rPolyPoly=aTmp;
290 bool AreaChart::impl_createLine( VDataSeries* pSeries
291 , drawing::PolyPolygonShape3D* pSeriesPoly
292 , PlottingPositionHelper* pPosHelper )
294 //return true if a line was created successfully
295 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
297 drawing::PolyPolygonShape3D aPoly;
298 if(CurveStyle_CUBIC_SPLINES==m_eCurveStyle)
300 drawing::PolyPolygonShape3D aSplinePoly;
301 SplineCalculater::CalculateCubicSplines( *pSeriesPoly, aSplinePoly, m_nCurveResolution );
302 lcl_removeDuplicatePoints( aSplinePoly, *pPosHelper );
303 Clipping::clipPolygonAtRectangle( aSplinePoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
305 else if(CurveStyle_B_SPLINES==m_eCurveStyle)
307 drawing::PolyPolygonShape3D aSplinePoly;
308 SplineCalculater::CalculateBSplines( *pSeriesPoly, aSplinePoly, m_nCurveResolution, m_nSplineOrder );
309 lcl_removeDuplicatePoints( aSplinePoly, *pPosHelper );
310 Clipping::clipPolygonAtRectangle( aSplinePoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
312 else
314 bool bIsClipped = false;
315 if( m_bConnectLastToFirstPoint && !ShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
317 // do NOT connect last and first point, if one is NAN, and NAN handling is NAN_AS_GAP
318 double fFirstY = pSeries->getYValue( 0 );
319 double fLastY = pSeries->getYValue( VSeriesPlotter::getPointCount() - 1 );
320 if( (pSeries->getMissingValueTreatment() != ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
321 || (::rtl::math::isFinite( fFirstY ) && ::rtl::math::isFinite( fLastY )) )
323 // connect last point in last polygon with first point in first polygon
324 ::basegfx::B2DRectangle aScaledLogicClipDoubleRect( pPosHelper->getScaledLogicClipDoubleRect() );
325 drawing::PolyPolygonShape3D aTmpPoly(*pSeriesPoly);
326 drawing::Position3D aLast(aScaledLogicClipDoubleRect.getMaxX(),aTmpPoly.SequenceY[0][0],aTmpPoly.SequenceZ[0][0]);
327 // add connector line to last polygon
328 AddPointToPoly( aTmpPoly, aLast, pSeriesPoly->SequenceX.getLength() - 1 );
329 Clipping::clipPolygonAtRectangle( aTmpPoly, aScaledLogicClipDoubleRect, aPoly );
330 bIsClipped = true;
334 if( !bIsClipped )
335 Clipping::clipPolygonAtRectangle( *pSeriesPoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
338 if(!ShapeFactory::hasPolygonAnyLines(aPoly))
339 return false;
341 //transformation 3) -> 4)
342 pPosHelper->transformScaledLogicToScene( aPoly );
344 //create line:
345 uno::Reference< drawing::XShape > xShape(NULL);
346 if(m_nDimension==3)
348 double fDepth = this->getTransformedDepth();
349 sal_Int32 nPolyCount = aPoly.SequenceX.getLength();
350 for(sal_Int32 nPoly=0;nPoly<nPolyCount;nPoly++)
352 sal_Int32 nPointCount = aPoly.SequenceX[nPoly].getLength();
353 for(sal_Int32 nPoint=0;nPoint<nPointCount-1;nPoint++)
355 drawing::Position3D aPoint1, aPoint2;
356 aPoint1.PositionX = aPoly.SequenceX[nPoly][nPoint+1];
357 aPoint1.PositionY = aPoly.SequenceY[nPoly][nPoint+1];
358 aPoint1.PositionZ = aPoly.SequenceZ[nPoly][nPoint+1];
360 aPoint2.PositionX = aPoly.SequenceX[nPoly][nPoint];
361 aPoint2.PositionY = aPoly.SequenceY[nPoly][nPoint];
362 aPoint2.PositionZ = aPoly.SequenceZ[nPoly][nPoint];
364 Stripe aStripe( aPoint1, aPoint2, fDepth );
366 m_pShapeFactory->createStripe(xSeriesGroupShape_Shapes
367 , Stripe( aPoint1, aPoint2, fDepth )
368 , pSeries->getPropertiesOfSeries(), PropertyMapper::getPropertyNameMapForFilledSeriesProperties(), true, 1 );
372 else //m_nDimension!=3
374 xShape = m_pShapeFactory->createLine2D( xSeriesGroupShape_Shapes
375 , PolyToPointSequence( aPoly ) );
376 this->setMappedProperties( xShape
377 , pSeries->getPropertiesOfSeries()
378 , PropertyMapper::getPropertyNameMapForLineSeriesProperties() );
379 //because of this name this line will be used for marking
380 m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
382 return true;
385 bool AreaChart::impl_createArea( VDataSeries* pSeries
386 , drawing::PolyPolygonShape3D* pSeriesPoly
387 , drawing::PolyPolygonShape3D* pPreviousSeriesPoly
388 , PlottingPositionHelper* pPosHelper )
390 //return true if an area was created successfully
392 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
393 double zValue = pSeries->m_fLogicZPos;
395 drawing::PolyPolygonShape3D aPoly( *pSeriesPoly );
396 //add second part to the polygon (grounding points or previous series points)
397 if( m_bConnectLastToFirstPoint && !ShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
399 if( pPreviousSeriesPoly )
400 addPolygon( aPoly, *pPreviousSeriesPoly );
402 else if(!pPreviousSeriesPoly)
404 double fMinX = pSeries->m_fLogicMinX;
405 double fMaxX = pSeries->m_fLogicMaxX;
406 double fY = pPosHelper->getBaseValueY();//logic grounding
407 if( m_nDimension==3 )
408 fY = pPosHelper->getLogicMinY();
410 //clip to scale
411 if(fMaxX<pPosHelper->getLogicMinX() || fMinX>pPosHelper->getLogicMaxX())
412 return false;//no visible shape needed
413 pPosHelper->clipLogicValues( &fMinX, &fY, 0 );
414 pPosHelper->clipLogicValues( &fMaxX, 0, 0 );
416 //apply scaling
418 pPosHelper->doLogicScaling( &fMinX, &fY, &zValue );
419 pPosHelper->doLogicScaling( &fMaxX, 0, 0 );
422 AddPointToPoly( aPoly, drawing::Position3D( fMaxX,fY,zValue) );
423 AddPointToPoly( aPoly, drawing::Position3D( fMinX,fY,zValue) );
425 else
427 appendPoly( aPoly, *pPreviousSeriesPoly );
429 ShapeFactory::closePolygon(aPoly);
431 //apply clipping
433 drawing::PolyPolygonShape3D aClippedPoly;
434 Clipping::clipPolygonAtRectangle( aPoly, pPosHelper->getScaledLogicClipDoubleRect(), aClippedPoly, false );
435 ShapeFactory::closePolygon(aClippedPoly); //again necessary after clipping
436 aPoly = aClippedPoly;
439 if(!ShapeFactory::hasPolygonAnyLines(aPoly))
440 return false;
442 //transformation 3) -> 4)
443 pPosHelper->transformScaledLogicToScene( aPoly );
445 //create area:
446 uno::Reference< drawing::XShape > xShape(NULL);
447 if(m_nDimension==3)
449 xShape = m_pShapeFactory->createArea3D( xSeriesGroupShape_Shapes
450 , aPoly, this->getTransformedDepth() );
452 else //m_nDimension!=3
454 xShape = m_pShapeFactory->createArea2D( xSeriesGroupShape_Shapes
455 , aPoly );
457 this->setMappedProperties( xShape
458 , pSeries->getPropertiesOfSeries()
459 , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() );
460 //because of this name this line will be used for marking
461 m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
462 return true;
465 void AreaChart::impl_createSeriesShapes()
467 //the polygon shapes for each series need to be created before
469 //iterate through all series again to create the series shapes
470 ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
471 const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
472 //=============================================================================
473 for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
475 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
476 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
478 //=============================================================================
479 for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
481 ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
483 ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
484 const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
485 //=============================================================================
487 std::map< sal_Int32, drawing::PolyPolygonShape3D* > aPreviousSeriesPolyMap;//a PreviousSeriesPoly for each different nAttachedAxisIndex
488 drawing::PolyPolygonShape3D* pSeriesPoly = NULL;
490 //iterate through all series
491 for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
493 sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
494 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
495 if(!pPosHelper)
496 pPosHelper = m_pMainPosHelper;
497 PlotterBase::m_pPosHelper = pPosHelper;
499 createRegressionCurvesShapes( **aSeriesIter, m_xErrorBarTarget, m_xRegressionCurveEquationTarget,
500 m_pPosHelper->maySkipPointsInRegressionCalculation());
502 pSeriesPoly = &(*aSeriesIter)->m_aPolyPolygonShape3D;
503 if( m_bArea )
505 if( !impl_createArea( *aSeriesIter, pSeriesPoly, aPreviousSeriesPolyMap[nAttachedAxisIndex], pPosHelper ) )
506 continue;
508 if( m_bLine )
510 if( !impl_createLine( *aSeriesIter, pSeriesPoly, pPosHelper ) )
511 continue;
513 aPreviousSeriesPolyMap[nAttachedAxisIndex] = pSeriesPoly;
514 }//next series in x slot (next y slot)
515 }//next x slot
516 }//next z slot
519 namespace
522 void lcl_reorderSeries( ::std::vector< ::std::vector< VDataSeriesGroup > >& rZSlots )
524 ::std::vector< ::std::vector< VDataSeriesGroup > > aRet( rZSlots.size() );
526 ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZIt( rZSlots.rbegin() );
527 ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZEnd( rZSlots.rend() );
528 for( ; aZIt != aZEnd; ++aZIt )
530 ::std::vector< VDataSeriesGroup > aXSlot( aZIt->size() );
532 ::std::vector< VDataSeriesGroup >::reverse_iterator aXIt( aZIt->rbegin() );
533 ::std::vector< VDataSeriesGroup >::reverse_iterator aXEnd( aZIt->rend() );
534 for( ; aXIt != aXEnd; ++aXIt )
535 aXSlot.push_back(*aXIt);
537 aRet.push_back(aXSlot);
540 rZSlots.clear();
541 rZSlots = aRet;
544 }//anonymous namespace
546 //better performance for big data
547 struct FormerPoint
549 FormerPoint( double fX, double fY, double fZ )
550 : m_fX(fX), m_fY(fY), m_fZ(fZ)
552 FormerPoint()
554 ::rtl::math::setNan( &m_fX );
555 ::rtl::math::setNan( &m_fY );
556 ::rtl::math::setNan( &m_fZ );
559 double m_fX;
560 double m_fY;
561 double m_fZ;
564 void AreaChart::createShapes()
566 if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
567 return;
569 if( m_nDimension == 2 && ( m_bArea || !m_bCategoryXAxis ) )
570 lcl_reorderSeries( m_aZSlots );
572 OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"AreaChart is not proper initialized");
573 if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
574 return;
576 //the text labels should be always on top of the other series shapes
577 //for area chart the error bars should be always on top of the other series shapes
579 //therefore create an own group for the texts and the error bars to move them to front
580 //(because the text group is created after the series group the texts are displayed on top)
581 m_xSeriesTarget = createGroupShape( m_xLogicTarget,rtl::OUString() );
582 if( m_bArea )
583 m_xErrorBarTarget = createGroupShape( m_xLogicTarget,rtl::OUString() );
584 else
585 m_xErrorBarTarget = m_xSeriesTarget;
586 m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() );
587 m_xRegressionCurveEquationTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() );
589 //---------------------------------------------
590 //check necessary here that different Y axis can not be stacked in the same group? ... hm?
592 //update/create information for current group
593 double fLogicZ = 1.0;//as defined
595 sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale
596 sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
597 if(nEndIndex<=0)
598 nEndIndex=1;
600 //better performance for big data
601 std::map< VDataSeries*, FormerPoint > aSeriesFormerPointMap;
602 m_bPointsWereSkipped = false;
603 sal_Int32 nSkippedPoints = 0;
604 sal_Int32 nCreatedPoints = 0;
607 bool bDateCategory = (m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis());
609 //=============================================================================
610 //iterate through all x values per indices
611 for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
613 ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
614 const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
616 std::map< sal_Int32, double > aLogicYSumMap;//one for each different nAttachedAxisIndex
617 for( ; aZSlotIter != aZSlotEnd; ++aZSlotIter )
619 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
620 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
622 //iterate through all x slots in this category to get 100percent sum
623 for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
625 std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
626 std::vector<VDataSeries*>::iterator aSeriesIter = rSeriesList.begin();
627 const std::vector<VDataSeries*>::iterator aSeriesEnd = rSeriesList.end();
629 for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
631 VDataSeries* pSeries( *aSeriesIter );
632 if(!pSeries)
633 continue;
635 if (bDateCategory)
636 pSeries->doSortByXValues();
638 sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
639 if( aLogicYSumMap.find(nAttachedAxisIndex)==aLogicYSumMap.end() )
640 aLogicYSumMap[nAttachedAxisIndex]=0.0;
642 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
643 if(!pPosHelper)
644 pPosHelper = m_pMainPosHelper;
645 PlotterBase::m_pPosHelper = pPosHelper;
647 double fAdd = pSeries->getYValue( nIndex );
648 if( !::rtl::math::isNan(fAdd) && !::rtl::math::isInf(fAdd) )
649 aLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd );
654 //=============================================================================
655 aZSlotIter = m_aZSlots.begin();
656 for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
658 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
659 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
661 //for the area chart there should be at most one x slot (no side by side stacking available)
662 //attention different: xSlots are always interpreted as independent areas one behind the other: @todo this doesn't work why not???
663 for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, ++nX )
665 std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
666 std::vector<VDataSeries*>::const_iterator aSeriesIter = rSeriesList.begin();
667 const std::vector<VDataSeries*>::const_iterator aSeriesEnd = rSeriesList.end();
669 std::map< sal_Int32, double > aLogicYForNextSeriesMap;//one for each different nAttachedAxisIndex
670 //=============================================================================
671 //iterate through all series
672 for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; ++aSeriesIter, ++nSeriesIndex )
674 VDataSeries* pSeries( *aSeriesIter );
675 if(!pSeries)
676 continue;
678 /* #i70133# ignore points outside of series length in standard area
679 charts. Stacked area charts will use missing points as zeros. In
680 standard charts, pSeriesList contains only one series. */
681 if( m_bArea && (rSeriesList.size() == 1) && (nIndex >= (*aSeriesIter)->getTotalPointCount()) )
682 continue;
684 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(*aSeriesIter, m_xSeriesTarget);
686 sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
687 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
688 if(!pPosHelper)
689 pPosHelper = m_pMainPosHelper;
690 PlotterBase::m_pPosHelper = pPosHelper;
692 if(m_nDimension==3)
693 fLogicZ = nZ+0.5;
694 (*aSeriesIter)->m_fLogicZPos = fLogicZ;
696 //collect data point information (logic coordinates, style ):
697 double fLogicX = (*aSeriesIter)->getXValue(nIndex);
698 if (bDateCategory)
699 fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution );
700 double fLogicY = (*aSeriesIter)->getYValue(nIndex);
702 if( m_bIsPolarCooSys && m_bArea &&
703 ( ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY) ) )
705 if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
707 if( rSeriesList.size() == 1 || nSeriesIndex == 0 )
709 fLogicY = pPosHelper->getLogicMinY();
710 if( !pPosHelper->isMathematicalOrientationY() )
711 fLogicY = pPosHelper->getLogicMaxY();
713 else
714 fLogicY = 0.0;
718 if( m_nDimension==3 && m_bArea && rSeriesList.size()!=1 )
719 fLogicY = fabs( fLogicY );
721 if( pPosHelper->isPercentY() && !::rtl::math::approxEqual( aLogicYSumMap[nAttachedAxisIndex], 0.0 ) )
723 fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex];
726 if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
727 || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY)
728 || ::rtl::math::isNan(fLogicZ) || ::rtl::math::isInf(fLogicZ) )
730 if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
732 drawing::PolyPolygonShape3D& rPolygon = (*aSeriesIter)->m_aPolyPolygonShape3D;
733 sal_Int32& rIndex = (*aSeriesIter)->m_nPolygonIndex;
734 if( 0<= rIndex && rIndex < rPolygon.SequenceX.getLength() )
736 if( rPolygon.SequenceX[ rIndex ].getLength() )
737 rIndex++; //start a new polygon for the next point if the current poly is not empty
740 continue;
743 if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
744 aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
746 double fLogicValueForLabeDisplay = fLogicY;
748 fLogicY += aLogicYForNextSeriesMap[nAttachedAxisIndex];
749 aLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
751 bool bIsVisible = pPosHelper->isLogicVisible( fLogicX, fLogicY, fLogicZ );
753 //remind minimal and maximal x values for area 'grounding' points
754 //only for filled area
756 double& rfMinX = (*aSeriesIter)->m_fLogicMinX;
757 if(!nIndex||fLogicX<rfMinX)
758 rfMinX=fLogicX;
759 double& rfMaxX = (*aSeriesIter)->m_fLogicMaxX;
760 if(!nIndex||fLogicX>rfMaxX)
761 rfMaxX=fLogicX;
764 drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
765 drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
766 pPosHelper->doLogicScaling( aScaledLogicPosition );
768 //transformation 3) -> 4)
769 drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
771 //better performance for big data
772 FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
773 pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
774 if( !pSeries->isAttributedDataPoint(nIndex)
776 pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
777 , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
779 ++nSkippedPoints;
780 m_bPointsWereSkipped = true;
781 continue;
783 aSeriesFormerPointMap[pSeries] = FormerPoint(aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ);
786 //store point information for series polygon
787 //for area and/or line (symbols only do not need this)
788 if( isValidPosition(aScaledLogicPosition) )
790 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
792 //prepare clipping for filled net charts
793 if( !bIsVisible && m_bIsPolarCooSys && m_bArea )
795 drawing::Position3D aClippedPos(aScaledLogicPosition);
796 pPosHelper->clipScaledLogicValues( 0, &aClippedPos.PositionY, 0 );
797 if( pPosHelper->isLogicVisible( aClippedPos.PositionX, aClippedPos.PositionY, aClippedPos.PositionZ ) )
799 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aClippedPos, (*aSeriesIter)->m_nPolygonIndex );
800 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
805 //create a single datapoint if point is visible
806 //apply clipping:
807 if( !bIsVisible )
808 continue;
810 bool bCreateYErrorBar = false, bCreateXErrorBar = false;
812 uno::Reference< beans::XPropertySet > xErrorBarProp(pSeries->getYErrorBarProperties(nIndex));
813 if( xErrorBarProp.is() )
815 bool bShowPositive = false;
816 bool bShowNegative = false;
817 xErrorBarProp->getPropertyValue( C2U( "ShowPositiveError" )) >>= bShowPositive;
818 xErrorBarProp->getPropertyValue( C2U( "ShowNegativeError" )) >>= bShowNegative;
819 bCreateYErrorBar = bShowPositive || bShowNegative;
822 xErrorBarProp = pSeries->getXErrorBarProperties(nIndex);
823 if ( xErrorBarProp.is() )
825 bool bShowPositive = false;
826 bool bShowNegative = false;
827 xErrorBarProp->getPropertyValue( C2U( "ShowPositiveError" )) >>= bShowPositive;
828 xErrorBarProp->getPropertyValue( C2U( "ShowNegativeError" )) >>= bShowNegative;
829 bCreateXErrorBar = bShowPositive || bShowNegative;
833 Symbol* pSymbolProperties = m_bSymbol ? (*aSeriesIter)->getSymbolProperties( nIndex ) : 0;
834 bool bCreateSymbol = pSymbolProperties && (pSymbolProperties->Style != SymbolStyle_NONE);
836 if( !bCreateSymbol && !bCreateYErrorBar &&
837 !bCreateXErrorBar && !pSeries->getDataPointLabelIfLabel(nIndex) )
838 continue;
840 //create a group shape for this point and add to the series shape:
841 rtl::OUString aPointCID = ObjectIdentifier::createPointCID(
842 (*aSeriesIter)->getPointCID_Stub(), nIndex );
843 uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
844 createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
845 uno::Reference<drawing::XShape> xPointGroupShape_Shape =
846 uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
849 nCreatedPoints++;
851 //create data point
852 drawing::Direction3D aSymbolSize(0,0,0);
853 if( bCreateSymbol )
855 if(m_nDimension!=3)
857 if( pSymbolProperties )
859 if( pSymbolProperties->Style != SymbolStyle_NONE )
861 aSymbolSize.DirectionX = pSymbolProperties->Size.Width;
862 aSymbolSize.DirectionY = pSymbolProperties->Size.Height;
865 if( pSymbolProperties->Style == SymbolStyle_STANDARD )
867 sal_Int32 nSymbol = pSymbolProperties->StandardSymbol;
868 m_pShapeFactory->createSymbol2D( xPointGroupShape_Shapes
869 , aScenePosition, aSymbolSize
870 , nSymbol
871 , pSymbolProperties->BorderColor
872 , pSymbolProperties->FillColor );
874 else if( pSymbolProperties->Style == SymbolStyle_GRAPHIC )
876 m_pShapeFactory->createGraphic2D( xPointGroupShape_Shapes
877 , aScenePosition , aSymbolSize
878 , pSymbolProperties->Graphic );
880 //@todo other symbol styles
884 //create error bars
885 if (bCreateXErrorBar)
886 createErrorBar_X( aUnscaledLogicPosition, **aSeriesIter, nIndex, m_xErrorBarTarget );
888 if (bCreateYErrorBar)
889 createErrorBar_Y( aUnscaledLogicPosition, **aSeriesIter, nIndex, m_xErrorBarTarget );
891 //create data point label
892 if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
894 LabelAlignment eAlignment = LABEL_ALIGN_TOP;
895 drawing::Position3D aScenePosition3D( aScenePosition.PositionX
896 , aScenePosition.PositionY
897 , aScenePosition.PositionZ+this->getTransformedDepth() );
899 sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
901 switch(nLabelPlacement)
903 case ::com::sun::star::chart::DataLabelPlacement::TOP:
904 aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
905 eAlignment = LABEL_ALIGN_TOP;
906 break;
907 case ::com::sun::star::chart::DataLabelPlacement::BOTTOM:
908 aScenePosition3D.PositionY += (aSymbolSize.DirectionY/2+1);
909 eAlignment = LABEL_ALIGN_BOTTOM;
910 break;
911 case ::com::sun::star::chart::DataLabelPlacement::LEFT:
912 aScenePosition3D.PositionX -= (aSymbolSize.DirectionX/2+1);
913 eAlignment = LABEL_ALIGN_LEFT;
914 break;
915 case ::com::sun::star::chart::DataLabelPlacement::RIGHT:
916 aScenePosition3D.PositionX += (aSymbolSize.DirectionX/2+1);
917 eAlignment = LABEL_ALIGN_RIGHT;
918 break;
919 case ::com::sun::star::chart::DataLabelPlacement::CENTER:
920 eAlignment = LABEL_ALIGN_CENTER;
921 //todo implement this different for area charts
922 break;
923 default:
924 OSL_FAIL("this label alignment is not implemented yet");
925 aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
926 eAlignment = LABEL_ALIGN_TOP;
927 break;
930 awt::Point aScreenPosition2D;//get the screen position for the labels
931 sal_Int32 nOffset = 100; //todo maybe calculate this font height dependent
932 if( m_bIsPolarCooSys && nLabelPlacement == ::com::sun::star::chart::DataLabelPlacement::OUTSIDE )
934 PolarPlottingPositionHelper* pPolarPosHelper = dynamic_cast<PolarPlottingPositionHelper*>(pPosHelper);
935 if( pPolarPosHelper )
937 PolarLabelPositionHelper aPolarLabelPositionHelper(pPolarPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
938 aScreenPosition2D = awt::Point( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
939 eAlignment, fLogicX, fLogicY, fLogicZ, nOffset ));
942 else
944 if(LABEL_ALIGN_CENTER==eAlignment || m_nDimension == 3 )
945 nOffset = 0;
946 aScreenPosition2D = awt::Point( LabelPositionHelper(pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory)
947 .transformSceneToScreenPosition( aScenePosition3D ) );
950 this->createDataLabel( m_xTextTarget, **aSeriesIter, nIndex
951 , fLogicValueForLabeDisplay
952 , aLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset );
956 //remove PointGroupShape if empty
957 if(!xPointGroupShape_Shapes->getCount())
958 xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
960 }//next series in x slot (next y slot)
961 }//next x slot
962 }//next z slot
963 }//next category
964 //=============================================================================
965 //=============================================================================
966 //=============================================================================
968 impl_createSeriesShapes();
970 /* @todo remove series shapes if empty
971 //remove and delete point-group-shape if empty
972 if(!xSeriesGroupShape_Shapes->getCount())
974 (*aSeriesIter)->m_xShape.set(NULL);
975 m_xLogicTarget->remove(xSeriesGroupShape_Shape);
979 //remove and delete series-group-shape if empty
981 //... todo
983 OSL_TRACE( "\nPPPPPPPPP<<<<<<<<<<<< area chart :: createShapes():: skipped points: %d created points: %d", nSkippedPoints, nCreatedPoints );
986 //.............................................................................
987 } //namespace chart
988 //.............................................................................
990 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */