Update ooo320-m1
[ooovba.git] / chart2 / source / view / charttypes / AreaChart.cxx
blob159f6655c57d9cc09f332113ed8f9cc0096b085d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AreaChart.cxx,v $
10 * $Revision: 1.53.42.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_chart2.hxx"
35 #include "AreaChart.hxx"
36 #include "PlottingPositionHelper.hxx"
37 #include "ShapeFactory.hxx"
38 //#include "chartview/servicenames_charttypes.hxx"
39 #include "CommonConverters.hxx"
40 #include "macros.hxx"
41 #include "ViewDefines.hxx"
42 #include "ObjectIdentifier.hxx"
43 #include "Splines.hxx"
44 #include "ChartTypeHelper.hxx"
45 #include "LabelPositionHelper.hxx"
46 #include "Clipping.hxx"
47 #include "Stripe.hxx"
48 #include "PolarLabelPositionHelper.hxx"
50 #include <com/sun/star/chart2/Symbol.hpp>
51 #include <com/sun/star/chart/DataLabelPlacement.hpp>
52 #include <com/sun/star/chart/MissingValueTreatment.hpp>
53 #include <tools/debug.hxx>
54 #include <svx/unoprnms.hxx>
55 #include <rtl/math.hxx>
56 #include <com/sun/star/drawing/DoubleSequence.hpp>
57 #include <com/sun/star/drawing/NormalsKind.hpp>
58 #include <com/sun/star/lang/XServiceName.hpp>
60 //.............................................................................
61 namespace chart
63 //.............................................................................
64 using namespace ::com::sun::star;
65 using namespace ::rtl::math;
66 using namespace ::com::sun::star::chart2;
68 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 AreaChart::AreaChart( const uno::Reference<XChartType>& xChartTypeModel
73 , sal_Int32 nDimensionCount
74 , bool bCategoryXAxis
75 , bool bNoArea
76 , PlottingPositionHelper* pPlottingPositionHelper
77 , bool bConnectLastToFirstPoint
78 , bool bAddOneToXMax
79 , bool bExpandIfValuesCloseToBorder
80 , sal_Int32 nKeepAspectRatio
81 , const drawing::Direction3D& rAspectRatio
83 : VSeriesPlotter( xChartTypeModel, nDimensionCount, bCategoryXAxis )
84 , m_pMainPosHelper(pPlottingPositionHelper)
85 , m_bArea(!bNoArea)
86 , m_bLine(bNoArea)
87 , m_bSymbol( ChartTypeHelper::isSupportingSymbolProperties(xChartTypeModel,nDimensionCount) )
88 , m_bIsPolarCooSys( bConnectLastToFirstPoint )
89 , m_bConnectLastToFirstPoint( bConnectLastToFirstPoint )
90 , m_bAddOneToXMax(bAddOneToXMax)
91 , m_bExpandIfValuesCloseToBorder( bExpandIfValuesCloseToBorder )
92 , m_nKeepAspectRatio(nKeepAspectRatio)
93 , m_aGivenAspectRatio(rAspectRatio)
94 , m_eCurveStyle(CurveStyle_LINES)
95 , m_nCurveResolution(20)
96 , m_nSplineOrder(3)
97 , m_xSeriesTarget(0)
98 , m_xErrorBarTarget(0)
99 , m_xTextTarget(0)
100 , m_xRegressionCurveEquationTarget(0)
102 if( !m_pMainPosHelper )
103 m_pMainPosHelper = new PlottingPositionHelper();
104 PlotterBase::m_pPosHelper = m_pMainPosHelper;
105 VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper;
109 if( m_xChartTypeModelProps.is() )
111 m_xChartTypeModelProps->getPropertyValue( C2U( "CurveStyle" ) ) >>= m_eCurveStyle;
112 m_xChartTypeModelProps->getPropertyValue( C2U( "CurveResolution" ) ) >>= m_nCurveResolution;
113 m_xChartTypeModelProps->getPropertyValue( C2U( "SplineOrder" ) ) >>= m_nSplineOrder;
116 catch( uno::Exception& e )
118 //the above properties are not supported by all charttypes supported by this class (e.g. area or net chart)
119 //in that cases this exception is ok
120 e.Context.is();//to have debug information without compilation warnings
124 AreaChart::~AreaChart()
126 delete m_pMainPosHelper;
129 double AreaChart::getMaximumX()
131 if( m_bAddOneToXMax )
133 //return category count
134 sal_Int32 nPointCount = getPointCount();
135 return nPointCount+1;
137 return VSeriesPlotter::getMaximumX();
140 bool AreaChart::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex )
142 return m_bExpandIfValuesCloseToBorder &&
143 VSeriesPlotter::isExpandIfValuesCloseToBorder( nDimensionIndex );
146 bool AreaChart::isSeperateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex*/ )
148 // no separate stacking in all types of line/area charts
149 return false;
152 //-----------------------------------------------------------------
154 LegendSymbolStyle AreaChart::getLegendSymbolStyle()
156 if( m_bArea || m_nDimension == 3 )
157 return chart2::LegendSymbolStyle_BOX;
158 return chart2::LegendSymbolStyle_LINE_WITH_SYMBOL;
161 uno::Any AreaChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex )
163 uno::Any aRet;
165 Symbol* pSymbolProperties = rSeries.getSymbolProperties( nPointIndex );
166 if( pSymbolProperties )
168 aRet = uno::makeAny(*pSymbolProperties);
171 return aRet;
174 //-----------------------------------------------------------------
175 // lang::XServiceInfo
176 //-----------------------------------------------------------------
178 APPHELPER_XSERVICEINFO_IMPL(AreaChart,CHART2_VIEW_AREACHART_SERVICE_IMPLEMENTATION_NAME)
180 uno::Sequence< rtl::OUString > AreaChart
181 ::getSupportedServiceNames_Static()
183 uno::Sequence< rtl::OUString > aSNS( 1 );
184 aSNS.getArray()[ 0 ] = CHART2_VIEW_AREACHART_SERVICE_NAME;
185 return aSNS;
189 //-----------------------------------------------------------------
190 // chart2::XPlotter
191 //-----------------------------------------------------------------
193 ::rtl::OUString SAL_CALL AreaChart
194 ::getCoordinateSystemTypeID()
195 throw (uno::RuntimeException)
197 return CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME;
200 drawing::Direction3D AreaChart::getPreferredDiagramAspectRatio() const
202 if( m_nKeepAspectRatio == 1 )
203 return m_aGivenAspectRatio;
204 drawing::Direction3D aRet(1,-1,1);
205 if( m_nDimension == 2 )
206 aRet = drawing::Direction3D(-1,-1,-1);
207 else
209 drawing::Direction3D aScale( m_pPosHelper->getScaledLogicWidth() );
210 aRet.DirectionZ = aScale.DirectionZ*0.2;
211 if(aRet.DirectionZ>1.0)
212 aRet.DirectionZ=1.0;
213 if(aRet.DirectionZ>10)
214 aRet.DirectionZ=10;
216 return aRet;
219 bool AreaChart::keepAspectRatio() const
221 if( m_nKeepAspectRatio == 0 )
222 return false;
223 if( m_nKeepAspectRatio == 1 )
224 return true;
225 if( m_nDimension == 2 )
227 if( !m_bSymbol )
228 return false;
230 return true;
233 void AreaChart::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot )
235 if( m_bArea && !m_bIsPolarCooSys && pSeries )
237 sal_Int32 nMissingValueTreatment = pSeries->getMissingValueTreatment();
238 if( nMissingValueTreatment == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
239 pSeries->setMissingValueTreatment( ::com::sun::star::chart::MissingValueTreatment::USE_ZERO );
241 if( m_nDimension == 3 && !m_bCategoryXAxis )
243 //3D xy always deep
244 DBG_ASSERT( zSlot==-1,"3D xy charts should be deep stacked in model also" );
245 zSlot=-1;
246 xSlot=0;
247 ySlot=0;
249 VSeriesPlotter::addSeries( pSeries, zSlot, xSlot, ySlot );
252 void lcl_removeDuplicatePoints( drawing::PolyPolygonShape3D& rPolyPoly, PlottingPositionHelper& rPosHelper )
254 sal_Int32 nPolyCount = rPolyPoly.SequenceX.getLength();
255 if(!nPolyCount)
256 return;
258 drawing::PolyPolygonShape3D aTmp;
259 aTmp.SequenceX.realloc(nPolyCount);
260 aTmp.SequenceY.realloc(nPolyCount);
261 aTmp.SequenceZ.realloc(nPolyCount);
263 for( sal_Int32 nPolygonIndex = 0; nPolygonIndex<nPolyCount; nPolygonIndex++ )
265 drawing::DoubleSequence* pOuterSourceX = &rPolyPoly.SequenceX.getArray()[nPolygonIndex];
266 drawing::DoubleSequence* pOuterSourceY = &rPolyPoly.SequenceY.getArray()[nPolygonIndex];
267 drawing::DoubleSequence* pOuterSourceZ = &rPolyPoly.SequenceZ.getArray()[nPolygonIndex];
269 drawing::DoubleSequence* pOuterTargetX = &aTmp.SequenceX.getArray()[nPolygonIndex];
270 drawing::DoubleSequence* pOuterTargetY = &aTmp.SequenceY.getArray()[nPolygonIndex];
271 drawing::DoubleSequence* pOuterTargetZ = &aTmp.SequenceZ.getArray()[nPolygonIndex];
273 sal_Int32 nPointCount = pOuterSourceX->getLength();
274 if( !nPointCount )
275 continue;
277 pOuterTargetX->realloc(nPointCount);
278 pOuterTargetY->realloc(nPointCount);
279 pOuterTargetZ->realloc(nPointCount);
281 double* pSourceX = pOuterSourceX->getArray();
282 double* pSourceY = pOuterSourceY->getArray();
283 double* pSourceZ = pOuterSourceZ->getArray();
285 double* pTargetX = pOuterTargetX->getArray();
286 double* pTargetY = pOuterTargetY->getArray();
287 double* pTargetZ = pOuterTargetZ->getArray();
289 //copy first point
290 *pTargetX=*pSourceX++;
291 *pTargetY=*pSourceY++;
292 *pTargetZ=*pSourceZ++;
293 sal_Int32 nTargetPointCount=1;
295 for( sal_Int32 nSource=1; nSource<nPointCount; nSource++ )
297 if( !rPosHelper.isSameForGivenResolution( *pTargetX, *pTargetY, *pTargetZ
298 , *pSourceX, *pSourceY, *pSourceZ ) )
300 pTargetX++; pTargetY++; pTargetZ++;
301 *pTargetX=*pSourceX;
302 *pTargetY=*pSourceY;
303 *pTargetZ=*pSourceZ;
304 nTargetPointCount++;
306 pSourceX++; pSourceY++; pSourceZ++;
309 //free unused space
310 if( nTargetPointCount<nPointCount )
312 pOuterTargetX->realloc(nTargetPointCount);
313 pOuterTargetY->realloc(nTargetPointCount);
314 pOuterTargetZ->realloc(nTargetPointCount);
317 pOuterSourceX->realloc(0);
318 pOuterSourceY->realloc(0);
319 pOuterSourceZ->realloc(0);
322 //free space
323 rPolyPoly.SequenceX.realloc(nPolyCount);
324 rPolyPoly.SequenceY.realloc(nPolyCount);
325 rPolyPoly.SequenceZ.realloc(nPolyCount);
327 rPolyPoly=aTmp;
330 bool AreaChart::impl_createLine( VDataSeries* pSeries
331 , drawing::PolyPolygonShape3D* pSeriesPoly
332 , PlottingPositionHelper* pPosHelper )
334 //return true if a line was created successfully
335 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
337 drawing::PolyPolygonShape3D aPoly;
338 if(CurveStyle_CUBIC_SPLINES==m_eCurveStyle)
340 drawing::PolyPolygonShape3D aSplinePoly;
341 SplineCalculater::CalculateCubicSplines( *pSeriesPoly, aSplinePoly, m_nCurveResolution );
342 lcl_removeDuplicatePoints( aSplinePoly, *pPosHelper );
343 Clipping::clipPolygonAtRectangle( aSplinePoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
345 else if(CurveStyle_B_SPLINES==m_eCurveStyle)
347 drawing::PolyPolygonShape3D aSplinePoly;
348 SplineCalculater::CalculateBSplines( *pSeriesPoly, aSplinePoly, m_nCurveResolution, m_nSplineOrder );
349 lcl_removeDuplicatePoints( aSplinePoly, *pPosHelper );
350 Clipping::clipPolygonAtRectangle( aSplinePoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
352 else
354 bool bIsClipped = false;
355 if( m_bConnectLastToFirstPoint && !ShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
357 // do NOT connect last and first point, if one is NAN, and NAN handling is NAN_AS_GAP
358 double fFirstY = pSeries->getYValue( 0 );
359 double fLastY = pSeries->getYValue( VSeriesPlotter::getPointCount() - 1 );
360 if( (pSeries->getMissingValueTreatment() != ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
361 || (::rtl::math::isFinite( fFirstY ) && ::rtl::math::isFinite( fLastY )) )
363 // connect last point in last polygon with first point in first polygon
364 ::basegfx::B2DRectangle aScaledLogicClipDoubleRect( pPosHelper->getScaledLogicClipDoubleRect() );
365 drawing::PolyPolygonShape3D aTmpPoly(*pSeriesPoly);
366 drawing::Position3D aLast(aScaledLogicClipDoubleRect.getMaxX(),aTmpPoly.SequenceY[0][0],aTmpPoly.SequenceZ[0][0]);
367 // add connector line to last polygon
368 AddPointToPoly( aTmpPoly, aLast, pSeriesPoly->SequenceX.getLength() - 1 );
369 Clipping::clipPolygonAtRectangle( aTmpPoly, aScaledLogicClipDoubleRect, aPoly );
370 bIsClipped = true;
374 if( !bIsClipped )
375 Clipping::clipPolygonAtRectangle( *pSeriesPoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
378 if(!ShapeFactory::hasPolygonAnyLines(aPoly))
379 return false;
381 //transformation 3) -> 4)
382 pPosHelper->transformScaledLogicToScene( aPoly );
384 //create line:
385 uno::Reference< drawing::XShape > xShape(NULL);
386 if(m_nDimension==3)
388 double fDepth = this->getTransformedDepth();
389 sal_Int32 nPolyCount = aPoly.SequenceX.getLength();
390 for(sal_Int32 nPoly=0;nPoly<nPolyCount;nPoly++)
392 sal_Int32 nPointCount = aPoly.SequenceX[nPoly].getLength();
393 for(sal_Int32 nPoint=0;nPoint<nPointCount-1;nPoint++)
395 drawing::Position3D aPoint1, aPoint2;
396 aPoint1.PositionX = aPoly.SequenceX[nPoly][nPoint+1];
397 aPoint1.PositionY = aPoly.SequenceY[nPoly][nPoint+1];
398 aPoint1.PositionZ = aPoly.SequenceZ[nPoly][nPoint+1];
400 aPoint2.PositionX = aPoly.SequenceX[nPoly][nPoint];
401 aPoint2.PositionY = aPoly.SequenceY[nPoly][nPoint];
402 aPoint2.PositionZ = aPoly.SequenceZ[nPoly][nPoint];
404 Stripe aStripe( aPoint1, aPoint2, fDepth );
406 m_pShapeFactory->createStripe(xSeriesGroupShape_Shapes
407 , Stripe( aPoint1, aPoint2, fDepth )
408 , pSeries->getPropertiesOfSeries(), PropertyMapper::getPropertyNameMapForFilledSeriesProperties(), true );
412 else //m_nDimension!=3
414 xShape = m_pShapeFactory->createLine2D( xSeriesGroupShape_Shapes
415 , PolyToPointSequence( aPoly ) );
416 this->setMappedProperties( xShape
417 , pSeries->getPropertiesOfSeries()
418 , PropertyMapper::getPropertyNameMapForLineSeriesProperties() );
419 //because of this name this line will be used for marking
420 m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
422 return true;
425 bool AreaChart::impl_createArea( VDataSeries* pSeries
426 , drawing::PolyPolygonShape3D* pSeriesPoly
427 , drawing::PolyPolygonShape3D* pPreviousSeriesPoly
428 , PlottingPositionHelper* pPosHelper )
430 //return true if an area was created successfully
432 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
433 double zValue = pSeries->m_fLogicZPos;
435 drawing::PolyPolygonShape3D aPoly( *pSeriesPoly );
436 //add second part to the polygon (grounding points or previous series points)
437 if( m_bConnectLastToFirstPoint && !ShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
439 if( pPreviousSeriesPoly )
440 addPolygon( aPoly, *pPreviousSeriesPoly );
442 else if(!pPreviousSeriesPoly)
444 double fMinX = pSeries->m_fLogicMinX;
445 double fMaxX = pSeries->m_fLogicMaxX;
446 double fY = pPosHelper->getBaseValueY();//logic grounding
447 if( m_nDimension==3 )
448 fY = pPosHelper->getLogicMinY();
450 //clip to scale
451 if(fMaxX<pPosHelper->getLogicMinX() || fMinX>pPosHelper->getLogicMaxX())
452 return false;//no visible shape needed
453 pPosHelper->clipLogicValues( &fMinX, &fY, 0 );
454 pPosHelper->clipLogicValues( &fMaxX, 0, 0 );
456 //apply scaling
458 pPosHelper->doLogicScaling( &fMinX, &fY, &zValue );
459 pPosHelper->doLogicScaling( &fMaxX, 0, 0 );
462 AddPointToPoly( aPoly, drawing::Position3D( fMaxX,fY,zValue) );
463 AddPointToPoly( aPoly, drawing::Position3D( fMinX,fY,zValue) );
465 else
467 appendPoly( aPoly, *pPreviousSeriesPoly );
469 ShapeFactory::closePolygon(aPoly);
471 //apply clipping
473 drawing::PolyPolygonShape3D aClippedPoly;
474 Clipping::clipPolygonAtRectangle( aPoly, pPosHelper->getScaledLogicClipDoubleRect(), aClippedPoly, false );
475 ShapeFactory::closePolygon(aClippedPoly); //again necessary after clipping
476 aPoly = aClippedPoly;
479 if(!ShapeFactory::hasPolygonAnyLines(aPoly))
480 return false;
482 //transformation 3) -> 4)
483 pPosHelper->transformScaledLogicToScene( aPoly );
485 //create area:
486 uno::Reference< drawing::XShape > xShape(NULL);
487 if(m_nDimension==3)
489 xShape = m_pShapeFactory->createArea3D( xSeriesGroupShape_Shapes
490 , aPoly, this->getTransformedDepth() );
492 else //m_nDimension!=3
494 xShape = m_pShapeFactory->createArea2D( xSeriesGroupShape_Shapes
495 , aPoly );
497 this->setMappedProperties( xShape
498 , pSeries->getPropertiesOfSeries()
499 , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() );
500 //because of this name this line will be used for marking
501 m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
502 return true;
505 void AreaChart::impl_createSeriesShapes()
507 //the polygon shapes for each series need to be created before
509 //iterate through all series again to create the series shapes
510 ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
511 const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
512 //=============================================================================
513 for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; aZSlotIter++, nZ++ )
515 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
516 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
518 //=============================================================================
519 for( ; aXSlotIter != aXSlotEnd; aXSlotIter++ )
521 ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
523 ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
524 const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
525 //=============================================================================
527 std::map< sal_Int32, drawing::PolyPolygonShape3D* > aPreviousSeriesPolyMap;//a PreviousSeriesPoly for each different nAttachedAxisIndex
528 drawing::PolyPolygonShape3D* pSeriesPoly = NULL;
530 //iterate through all series
531 for( ; aSeriesIter != aSeriesEnd; aSeriesIter++ )
533 sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
534 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
535 if(!pPosHelper)
536 pPosHelper = m_pMainPosHelper;
537 PlotterBase::m_pPosHelper = pPosHelper;
539 createRegressionCurvesShapes( **aSeriesIter, m_xErrorBarTarget, m_xRegressionCurveEquationTarget,
540 m_pPosHelper->maySkipPointsInRegressionCalculation());
542 pSeriesPoly = &(*aSeriesIter)->m_aPolyPolygonShape3D;
543 if( m_bArea )
545 if( !impl_createArea( *aSeriesIter, pSeriesPoly, aPreviousSeriesPolyMap[nAttachedAxisIndex], pPosHelper ) )
546 continue;
548 if( m_bLine )
550 if( !impl_createLine( *aSeriesIter, pSeriesPoly, pPosHelper ) )
551 continue;
553 aPreviousSeriesPolyMap[nAttachedAxisIndex] = pSeriesPoly;
554 }//next series in x slot (next y slot)
555 }//next x slot
556 }//next z slot
559 namespace
562 void lcl_reorderSeries( ::std::vector< ::std::vector< VDataSeriesGroup > >& rZSlots )
564 ::std::vector< ::std::vector< VDataSeriesGroup > > aRet( rZSlots.size() );
566 ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZIt( rZSlots.rbegin() );
567 ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZEnd( rZSlots.rend() );
568 for( ; aZIt != aZEnd; ++aZIt )
570 ::std::vector< VDataSeriesGroup > aXSlot( aZIt->size() );
572 ::std::vector< VDataSeriesGroup >::reverse_iterator aXIt( aZIt->rbegin() );
573 ::std::vector< VDataSeriesGroup >::reverse_iterator aXEnd( aZIt->rend() );
574 for( ; aXIt != aXEnd; ++aXIt )
575 aXSlot.push_back(*aXIt);
577 aRet.push_back(aXSlot);
580 rZSlots.clear();
581 rZSlots = aRet;
584 }//anonymous namespace
586 //better performance for big data
587 struct FormerPoint
589 FormerPoint( double fX, double fY, double fZ )
590 : m_fX(fX), m_fY(fY), m_fZ(fZ)
592 FormerPoint()
594 ::rtl::math::setNan( &m_fX );
595 ::rtl::math::setNan( &m_fY );
596 ::rtl::math::setNan( &m_fZ );
599 double m_fX;
600 double m_fY;
601 double m_fZ;
604 void AreaChart::createShapes()
606 sal_Bool bPercent = sal_False;
607 uno::Reference< beans::XPropertySet > xPropSet(m_xChartTypeModel, uno::UNO_QUERY);
608 if (xPropSet.is())
612 xPropSet->getPropertyValue(C2U("Percent")) >>= bPercent;
614 catch (const beans::UnknownPropertyException&)
619 if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
620 return;
622 if( m_nDimension == 2 && ( m_bArea || !m_bCategoryXAxis ) )
623 lcl_reorderSeries( m_aZSlots );
625 DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"AreaChart is not proper initialized");
626 if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
627 return;
629 //the text labels should be always on top of the other series shapes
630 //for area chart the error bars should be always on top of the other series shapes
632 //therefore create an own group for the texts and the error bars to move them to front
633 //(because the text group is created after the series group the texts are displayed on top)
634 m_xSeriesTarget = createGroupShape( m_xLogicTarget,rtl::OUString() );
635 if( m_bArea )
636 m_xErrorBarTarget = createGroupShape( m_xLogicTarget,rtl::OUString() );
637 else
638 m_xErrorBarTarget = m_xSeriesTarget;
639 m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() );
640 m_xRegressionCurveEquationTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() );
642 //---------------------------------------------
643 //check necessary here that different Y axis can not be stacked in the same group? ... hm?
645 //update/create information for current group
646 double fLogicZ = 0.5;//as defined
648 sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale
649 sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
650 if(nEndIndex<=0)
651 nEndIndex=1;
653 //better performance for big data
654 std::map< VDataSeries*, FormerPoint > aSeriesFormerPointMap;
655 m_bPointsWereSkipped = false;
656 sal_Int32 nSkippedPoints = 0;
657 sal_Int32 nCreatedPoints = 0;
660 //=============================================================================
661 //iterate through all x values per indices
662 for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
664 ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
665 const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
667 std::map< sal_Int32, double > aLogicYSumMap;//one for each different nAttachedAxisIndex
668 for( ; aZSlotIter != aZSlotEnd; aZSlotIter++ )
670 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
671 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
673 //iterate through all x slots in this category to get 100percent sum
674 for( ; aXSlotIter != aXSlotEnd; aXSlotIter++ )
676 ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
677 ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
678 const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
680 for( ; aSeriesIter != aSeriesEnd; aSeriesIter++ )
682 VDataSeries* pSeries( *aSeriesIter );
683 if(!pSeries)
684 continue;
686 sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
687 if( aLogicYSumMap.find(nAttachedAxisIndex)==aLogicYSumMap.end() )
688 aLogicYSumMap[nAttachedAxisIndex]=0.0;
690 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
691 if(!pPosHelper)
692 pPosHelper = m_pMainPosHelper;
693 PlotterBase::m_pPosHelper = pPosHelper;
695 double fAdd = pSeries->getYValue( nIndex );
696 if( !::rtl::math::isNan(fAdd) && !::rtl::math::isInf(fAdd) )
697 aLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd );
702 //=============================================================================
703 aZSlotIter = m_aZSlots.begin();
704 for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; aZSlotIter++, nZ++ )
706 ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
707 const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
709 //for the area chart there should be at most one x slot (no side by side stacking available)
710 //attention different: xSlots are always interpreted as independent areas one behind the other: @todo this doesn't work why not???
711 aXSlotIter = aZSlotIter->begin();
712 for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; aXSlotIter++, nX++ )
714 ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
715 ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
716 const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
718 std::map< sal_Int32, double > aLogicYForNextSeriesMap;//one for each different nAttachedAxisIndex
719 //=============================================================================
720 //iterate through all series
721 for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; aSeriesIter++, nSeriesIndex++ )
723 VDataSeries* pSeries( *aSeriesIter );
724 if(!pSeries)
725 continue;
727 /* #i70133# ignore points outside of series length in standard area
728 charts. Stacked area charts will use missing points as zeros. In
729 standard charts, pSeriesList contains only one series. */
730 if( m_bArea && (pSeriesList->size() == 1) && (nIndex >= (*aSeriesIter)->getTotalPointCount()) )
731 continue;
733 uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(*aSeriesIter, m_xSeriesTarget);
735 sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
736 PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
737 if(!pPosHelper)
738 pPosHelper = m_pMainPosHelper;
739 PlotterBase::m_pPosHelper = pPosHelper;
741 if(m_nDimension==3)
742 fLogicZ = nZ+0.5;
743 (*aSeriesIter)->m_fLogicZPos = fLogicZ;
745 //collect data point information (logic coordinates, style ):
746 double fLogicX = (*aSeriesIter)->getXValue(nIndex);
747 double fLogicY = (*aSeriesIter)->getYValue(nIndex);
749 if( m_bIsPolarCooSys && m_bArea &&
750 ( ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY) ) )
752 if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
754 if( pSeriesList->size() == 1 || nSeriesIndex == 0 )
756 fLogicY = pPosHelper->getLogicMinY();
757 if( !pPosHelper->isMathematicalOrientationY() )
758 fLogicY = pPosHelper->getLogicMaxY();
760 else
761 fLogicY = 0.0;
765 if( m_nDimension==3 && m_bArea && pSeriesList->size()!=1 )
766 fLogicY = fabs( fLogicY );
768 if (bPercent)
770 // This data series is percent-stacked.
772 if (::rtl::math::approxEqual(aLogicYSumMap[nAttachedAxisIndex], 0.0))
773 fLogicY = 0.0;
774 else
775 fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex];
777 if (!pPosHelper->isPercentY())
779 // When the axis itself is not percent-stacked,
780 // their internal range value is 0 - 100. So we
781 // need to adjust the data point values
782 // accordingly.
783 fLogicY *= 100.0;
786 else if (pPosHelper->isPercentY())
788 // The data series is not percent-stacked, but the
789 // axis itself is. In this case, the axis' internal
790 // range is 0 to 1. Adjust the data point values.
791 fLogicY /= 100.0;
794 if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
795 || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY)
796 || ::rtl::math::isNan(fLogicZ) || ::rtl::math::isInf(fLogicZ) )
798 if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
800 drawing::PolyPolygonShape3D& rPolygon = (*aSeriesIter)->m_aPolyPolygonShape3D;
801 sal_Int32& rIndex = (*aSeriesIter)->m_nPolygonIndex;
802 if( 0<= rIndex && rIndex < rPolygon.SequenceX.getLength() )
804 if( rPolygon.SequenceX[ rIndex ].getLength() )
805 rIndex++; //start a new polygon for the next point if the current poly is not empty
808 continue;
811 if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
812 aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
814 double fLogicValueForLabeDisplay = fLogicY;
816 fLogicY += aLogicYForNextSeriesMap[nAttachedAxisIndex];
817 aLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
819 bool bIsVisible = pPosHelper->isLogicVisible( fLogicX, fLogicY, fLogicZ );
821 //remind minimal and maximal x values for area 'grounding' points
822 //only for filled area
824 double& rfMinX = (*aSeriesIter)->m_fLogicMinX;
825 if(!nIndex||fLogicX<rfMinX)
826 rfMinX=fLogicX;
827 double& rfMaxX = (*aSeriesIter)->m_fLogicMaxX;
828 if(!nIndex||fLogicX>rfMaxX)
829 rfMaxX=fLogicX;
832 drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
833 drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
834 pPosHelper->doLogicScaling( aScaledLogicPosition );
836 //transformation 3) -> 4)
837 drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
839 //better performance for big data
840 FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
841 pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
842 if( !pSeries->isAttributedDataPoint(nIndex)
844 pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
845 , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
847 nSkippedPoints++;
848 m_bPointsWereSkipped = true;
849 continue;
851 aSeriesFormerPointMap[pSeries] = FormerPoint(aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ);
854 //store point information for series polygon
855 //for area and/or line (symbols only do not need this)
856 if( isValidPosition(aScaledLogicPosition) )
858 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
860 //prepare clipping for filled net charts
861 if( !bIsVisible && m_bIsPolarCooSys && m_bArea )
863 drawing::Position3D aClippedPos(aScaledLogicPosition);
864 pPosHelper->clipScaledLogicValues( 0, &aClippedPos.PositionY, 0 );
865 if( pPosHelper->isLogicVisible( aClippedPos.PositionX, aClippedPos.PositionY, aClippedPos.PositionZ ) )
867 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aClippedPos, (*aSeriesIter)->m_nPolygonIndex );
868 AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
873 //create a single datapoint if point is visible
874 //apply clipping:
875 if( !bIsVisible )
876 continue;
878 bool bCreateErrorBar = false;
880 uno::Reference< beans::XPropertySet > xErrorBarProp(pSeries->getYErrorBarProperties(nIndex));
881 if( xErrorBarProp.is() )
883 bool bShowPositive = false;
884 bool bShowNegative = false;
885 xErrorBarProp->getPropertyValue( C2U( "ShowPositiveError" )) >>= bShowPositive;
886 xErrorBarProp->getPropertyValue( C2U( "ShowNegativeError" )) >>= bShowNegative;
887 bCreateErrorBar = bShowPositive || bShowNegative;
891 Symbol* pSymbolProperties = m_bSymbol ? (*aSeriesIter)->getSymbolProperties( nIndex ) : 0;
892 bool bCreateSymbol = pSymbolProperties && (pSymbolProperties->Style != SymbolStyle_NONE);
894 if( !bCreateSymbol && !bCreateErrorBar && !pSeries->getDataPointLabelIfLabel(nIndex) )
895 continue;
897 //create a group shape for this point and add to the series shape:
898 rtl::OUString aPointCID = ObjectIdentifier::createPointCID(
899 (*aSeriesIter)->getPointCID_Stub(), nIndex );
900 uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
901 createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
902 uno::Reference<drawing::XShape> xPointGroupShape_Shape =
903 uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
906 nCreatedPoints++;
908 //create data point
909 drawing::Direction3D aSymbolSize(0,0,0);
910 if( bCreateSymbol )
912 if(m_nDimension!=3)
914 if( pSymbolProperties )
916 if( pSymbolProperties->Style != SymbolStyle_NONE )
918 aSymbolSize.DirectionX = pSymbolProperties->Size.Width;
919 aSymbolSize.DirectionY = pSymbolProperties->Size.Height;
922 if( pSymbolProperties->Style == SymbolStyle_STANDARD )
924 sal_Int32 nSymbol = pSymbolProperties->StandardSymbol;
925 m_pShapeFactory->createSymbol2D( xPointGroupShape_Shapes
926 , aScenePosition, aSymbolSize
927 , nSymbol
928 , pSymbolProperties->BorderColor
929 , pSymbolProperties->FillColor );
931 else if( pSymbolProperties->Style == SymbolStyle_GRAPHIC )
933 m_pShapeFactory->createGraphic2D( xPointGroupShape_Shapes
934 , aScenePosition , aSymbolSize
935 , pSymbolProperties->Graphic );
937 //@todo other symbol styles
941 //create error bar
942 createErrorBar_Y( aUnscaledLogicPosition, **aSeriesIter, nIndex, m_xErrorBarTarget );
944 //create data point label
945 if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
947 LabelAlignment eAlignment = LABEL_ALIGN_TOP;
948 drawing::Position3D aScenePosition3D( aScenePosition.PositionX
949 , aScenePosition.PositionY
950 , aScenePosition.PositionZ+this->getTransformedDepth() );
952 sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
954 switch(nLabelPlacement)
956 case ::com::sun::star::chart::DataLabelPlacement::TOP:
957 aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
958 eAlignment = LABEL_ALIGN_TOP;
959 break;
960 case ::com::sun::star::chart::DataLabelPlacement::BOTTOM:
961 aScenePosition3D.PositionY += (aSymbolSize.DirectionY/2+1);
962 eAlignment = LABEL_ALIGN_BOTTOM;
963 break;
964 case ::com::sun::star::chart::DataLabelPlacement::LEFT:
965 aScenePosition3D.PositionX -= (aSymbolSize.DirectionX/2+1);
966 eAlignment = LABEL_ALIGN_LEFT;
967 break;
968 case ::com::sun::star::chart::DataLabelPlacement::RIGHT:
969 aScenePosition3D.PositionX += (aSymbolSize.DirectionX/2+1);
970 eAlignment = LABEL_ALIGN_RIGHT;
971 break;
972 case ::com::sun::star::chart::DataLabelPlacement::CENTER:
973 eAlignment = LABEL_ALIGN_CENTER;
974 //todo implement this different for area charts
975 break;
976 default:
977 DBG_ERROR("this label alignment is not implemented yet");
978 aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
979 eAlignment = LABEL_ALIGN_TOP;
980 break;
983 awt::Point aScreenPosition2D;//get the screen position for the labels
984 sal_Int32 nOffset = 100; //todo maybe calculate this font height dependent
985 if( m_bIsPolarCooSys && nLabelPlacement == ::com::sun::star::chart::DataLabelPlacement::OUTSIDE )
987 PolarPlottingPositionHelper* pPolarPosHelper = dynamic_cast<PolarPlottingPositionHelper*>(pPosHelper);
988 if( pPolarPosHelper )
990 PolarLabelPositionHelper aPolarLabelPositionHelper(pPolarPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
991 aScreenPosition2D = awt::Point( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
992 eAlignment, fLogicX, fLogicY, fLogicZ, nOffset ));
995 else
997 if(LABEL_ALIGN_CENTER==eAlignment || m_nDimension == 3 )
998 nOffset = 0;
999 aScreenPosition2D = awt::Point( LabelPositionHelper(pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory)
1000 .transformSceneToScreenPosition( aScenePosition3D ) );
1003 this->createDataLabel( m_xTextTarget, **aSeriesIter, nIndex
1004 , fLogicValueForLabeDisplay
1005 , aLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset );
1009 //remove PointGroupShape if empty
1010 if(!xPointGroupShape_Shapes->getCount())
1011 xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
1013 }//next series in x slot (next y slot)
1014 }//next x slot
1015 }//next z slot
1016 }//next category
1017 //=============================================================================
1018 //=============================================================================
1019 //=============================================================================
1021 impl_createSeriesShapes();
1023 /* @todo remove series shapes if empty
1024 //remove and delete point-group-shape if empty
1025 if(!xSeriesGroupShape_Shapes->getCount())
1027 (*aSeriesIter)->m_xShape.set(NULL);
1028 m_xLogicTarget->remove(xSeriesGroupShape_Shape);
1032 //remove and delete series-group-shape if empty
1034 //... todo
1036 OSL_TRACE( "\nPPPPPPPPP<<<<<<<<<<<< area chart :: createShapes():: skipped points: %d created points: %d", nSkippedPoints, nCreatedPoints );
1039 //.............................................................................
1040 } //namespace chart
1041 //.............................................................................