Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "NetChart.hxx"
21 : #include "PlottingPositionHelper.hxx"
22 : #include "AbstractShapeFactory.hxx"
23 : #include "CommonConverters.hxx"
24 : #include "macros.hxx"
25 : #include "ViewDefines.hxx"
26 : #include "ObjectIdentifier.hxx"
27 : #include "ChartTypeHelper.hxx"
28 : #include "LabelPositionHelper.hxx"
29 : #include "Clipping.hxx"
30 : #include "Stripe.hxx"
31 : #include "PolarLabelPositionHelper.hxx"
32 : #include "DateHelper.hxx"
33 :
34 : #include <com/sun/star/chart2/Symbol.hpp>
35 : #include <com/sun/star/chart/DataLabelPlacement.hpp>
36 : #include <com/sun/star/chart/MissingValueTreatment.hpp>
37 :
38 : #include <editeng/unoprnms.hxx>
39 : #include <rtl/math.hxx>
40 :
41 : #include <com/sun/star/drawing/DoubleSequence.hpp>
42 : #include <com/sun/star/drawing/NormalsKind.hpp>
43 : #include <com/sun/star/lang/XServiceName.hpp>
44 :
45 : namespace chart
46 : {
47 : using namespace ::com::sun::star;
48 : using namespace ::rtl::math;
49 : using namespace ::com::sun::star::chart2;
50 :
51 0 : NetChart::NetChart( const uno::Reference<XChartType>& xChartTypeModel
52 : , sal_Int32 nDimensionCount
53 : , bool bNoArea
54 : , PlottingPositionHelper* pPlottingPositionHelper
55 : )
56 : : VSeriesPlotter( xChartTypeModel, nDimensionCount, true )
57 : , m_pMainPosHelper(pPlottingPositionHelper)
58 0 : , m_bArea(!bNoArea)
59 : , m_bLine(bNoArea)
60 : , m_xSeriesTarget(0)
61 0 : , m_xTextTarget(0)
62 : {
63 : // we only support 2D Net charts
64 : assert(nDimensionCount == 2);
65 :
66 0 : m_pMainPosHelper->AllowShiftXAxisPos(true);
67 0 : m_pMainPosHelper->AllowShiftZAxisPos(true);
68 :
69 0 : PlotterBase::m_pPosHelper = m_pMainPosHelper.get();
70 0 : VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper.get();
71 0 : }
72 :
73 0 : NetChart::~NetChart()
74 : {
75 0 : }
76 :
77 0 : double NetChart::getMaximumX()
78 : {
79 0 : double fMax = VSeriesPlotter::getMaximumX() + 1.0;
80 0 : return fMax;
81 : }
82 :
83 0 : bool NetChart::isExpandIfValuesCloseToBorder( sal_Int32 )
84 : {
85 0 : return false;
86 : }
87 :
88 0 : bool NetChart::isSeparateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex*/ )
89 : {
90 : // no separate stacking in all types of line/area charts
91 0 : return false;
92 : }
93 :
94 0 : LegendSymbolStyle NetChart::getLegendSymbolStyle()
95 : {
96 0 : if( m_bArea )
97 0 : return LegendSymbolStyle_BOX;
98 0 : return LegendSymbolStyle_LINE;
99 : }
100 :
101 0 : uno::Any NetChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex )
102 : {
103 0 : uno::Any aRet;
104 :
105 0 : Symbol* pSymbolProperties = rSeries.getSymbolProperties( nPointIndex );
106 0 : if( pSymbolProperties )
107 : {
108 0 : aRet = uno::makeAny(*pSymbolProperties);
109 : }
110 :
111 0 : return aRet;
112 : }
113 :
114 0 : drawing::Direction3D NetChart::getPreferredDiagramAspectRatio() const
115 : {
116 0 : return drawing::Direction3D(1,1,1);
117 : }
118 :
119 0 : bool NetChart::keepAspectRatio() const
120 : {
121 0 : return true;
122 : }
123 :
124 0 : void NetChart::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot )
125 : {
126 0 : VSeriesPlotter::addSeries( pSeries, zSlot, xSlot, ySlot );
127 0 : }
128 :
129 0 : bool NetChart::impl_createLine( VDataSeries* pSeries
130 : , drawing::PolyPolygonShape3D* pSeriesPoly
131 : , PlottingPositionHelper* pPosHelper )
132 : {
133 : //return true if a line was created successfully
134 0 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
135 :
136 0 : drawing::PolyPolygonShape3D aPoly;
137 : {
138 0 : bool bIsClipped = false;
139 0 : if( !AbstractShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
140 : {
141 : // do NOT connect last and first point, if one is NAN, and NAN handling is NAN_AS_GAP
142 0 : double fFirstY = pSeries->getYValue( 0 );
143 0 : double fLastY = pSeries->getYValue( VSeriesPlotter::getPointCount() - 1 );
144 0 : if( (pSeries->getMissingValueTreatment() != ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
145 0 : || (::rtl::math::isFinite( fFirstY ) && ::rtl::math::isFinite( fLastY )) )
146 : {
147 : // connect last point in last polygon with first point in first polygon
148 0 : ::basegfx::B2DRectangle aScaledLogicClipDoubleRect( pPosHelper->getScaledLogicClipDoubleRect() );
149 0 : drawing::PolyPolygonShape3D aTmpPoly(*pSeriesPoly);
150 0 : drawing::Position3D aLast(aScaledLogicClipDoubleRect.getMaxX(),aTmpPoly.SequenceY[0][0],aTmpPoly.SequenceZ[0][0]);
151 : // add connector line to last polygon
152 0 : AddPointToPoly( aTmpPoly, aLast, pSeriesPoly->SequenceX.getLength() - 1 );
153 0 : Clipping::clipPolygonAtRectangle( aTmpPoly, aScaledLogicClipDoubleRect, aPoly );
154 0 : bIsClipped = true;
155 : }
156 : }
157 :
158 0 : if( !bIsClipped )
159 0 : Clipping::clipPolygonAtRectangle( *pSeriesPoly, pPosHelper->getScaledLogicClipDoubleRect(), aPoly );
160 : }
161 :
162 0 : if(!AbstractShapeFactory::hasPolygonAnyLines(aPoly))
163 0 : return false;
164 :
165 : //transformation 3) -> 4)
166 0 : pPosHelper->transformScaledLogicToScene( aPoly );
167 :
168 : //create line:
169 0 : uno::Reference< drawing::XShape > xShape(NULL);
170 : {
171 0 : xShape = m_pShapeFactory->createLine2D( xSeriesGroupShape_Shapes
172 0 : , PolyToPointSequence( aPoly ) );
173 : this->setMappedProperties( xShape
174 : , pSeries->getPropertiesOfSeries()
175 0 : , PropertyMapper::getPropertyNameMapForLineSeriesProperties() );
176 : //because of this name this line will be used for marking
177 0 : ::chart::AbstractShapeFactory::setShapeName(xShape, "MarkHandles");
178 : }
179 0 : return true;
180 : }
181 :
182 0 : bool NetChart::impl_createArea( VDataSeries* pSeries
183 : , drawing::PolyPolygonShape3D* pSeriesPoly
184 : , drawing::PolyPolygonShape3D* pPreviousSeriesPoly
185 : , PlottingPositionHelper* pPosHelper )
186 : {
187 : //return true if an area was created successfully
188 :
189 0 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
190 0 : double zValue = pSeries->m_fLogicZPos;
191 :
192 0 : drawing::PolyPolygonShape3D aPoly( *pSeriesPoly );
193 : //add second part to the polygon (grounding points or previous series points)
194 0 : if( !AbstractShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
195 : {
196 0 : if( pPreviousSeriesPoly )
197 0 : addPolygon( aPoly, *pPreviousSeriesPoly );
198 : }
199 0 : else if(!pPreviousSeriesPoly)
200 : {
201 0 : double fMinX = pSeries->m_fLogicMinX;
202 0 : double fMaxX = pSeries->m_fLogicMaxX;
203 0 : double fY = pPosHelper->getBaseValueY();//logic grounding
204 :
205 : //clip to scale
206 0 : if(fMaxX<pPosHelper->getLogicMinX() || fMinX>pPosHelper->getLogicMaxX())
207 0 : return false;//no visible shape needed
208 0 : pPosHelper->clipLogicValues( &fMinX, &fY, 0 );
209 0 : pPosHelper->clipLogicValues( &fMaxX, 0, 0 );
210 :
211 : //apply scaling
212 : {
213 0 : pPosHelper->doLogicScaling( &fMinX, &fY, &zValue );
214 0 : pPosHelper->doLogicScaling( &fMaxX, 0, 0 );
215 : }
216 :
217 0 : AddPointToPoly( aPoly, drawing::Position3D( fMaxX,fY,zValue) );
218 0 : AddPointToPoly( aPoly, drawing::Position3D( fMinX,fY,zValue) );
219 : }
220 : else
221 : {
222 0 : appendPoly( aPoly, *pPreviousSeriesPoly );
223 : }
224 0 : AbstractShapeFactory::closePolygon(aPoly);
225 :
226 : //apply clipping
227 : {
228 0 : drawing::PolyPolygonShape3D aClippedPoly;
229 0 : Clipping::clipPolygonAtRectangle( aPoly, pPosHelper->getScaledLogicClipDoubleRect(), aClippedPoly, false );
230 0 : AbstractShapeFactory::closePolygon(aClippedPoly); //again necessary after clipping
231 0 : aPoly = aClippedPoly;
232 : }
233 :
234 0 : if(!AbstractShapeFactory::hasPolygonAnyLines(aPoly))
235 0 : return false;
236 :
237 : //transformation 3) -> 4)
238 0 : pPosHelper->transformScaledLogicToScene( aPoly );
239 :
240 : //create area:
241 : uno::Reference< drawing::XShape >
242 : xShape = m_pShapeFactory->createArea2D( xSeriesGroupShape_Shapes
243 0 : , aPoly );
244 : this->setMappedProperties( xShape
245 : , pSeries->getPropertiesOfSeries()
246 0 : , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() );
247 : //because of this name this line will be used for marking
248 0 : ::chart::AbstractShapeFactory::setShapeName(xShape, "MarkHandles");
249 0 : return true;
250 : }
251 :
252 0 : void NetChart::impl_createSeriesShapes()
253 : {
254 : //the polygon shapes for each series need to be created before
255 :
256 : //iterate through all series again to create the series shapes
257 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
258 0 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
259 0 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
260 : {
261 0 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
262 0 : const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
263 :
264 0 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
265 : {
266 0 : ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
267 :
268 0 : ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
269 0 : const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
270 :
271 0 : std::map< sal_Int32, drawing::PolyPolygonShape3D* > aPreviousSeriesPolyMap;//a PreviousSeriesPoly for each different nAttachedAxisIndex
272 0 : drawing::PolyPolygonShape3D* pSeriesPoly = NULL;
273 :
274 : //iterate through all series
275 0 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
276 : {
277 0 : sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
278 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
279 0 : if(!pPosHelper)
280 0 : pPosHelper = m_pMainPosHelper.get();
281 0 : PlotterBase::m_pPosHelper = pPosHelper;
282 :
283 0 : pSeriesPoly = &(*aSeriesIter)->m_aPolyPolygonShape3D;
284 0 : if( m_bArea )
285 : {
286 0 : if( !impl_createArea( *aSeriesIter, pSeriesPoly, aPreviousSeriesPolyMap[nAttachedAxisIndex], pPosHelper ) )
287 0 : continue;
288 : }
289 0 : if( m_bLine )
290 : {
291 0 : if( !impl_createLine( *aSeriesIter, pSeriesPoly, pPosHelper ) )
292 0 : continue;
293 : }
294 0 : aPreviousSeriesPolyMap[nAttachedAxisIndex] = pSeriesPoly;
295 : }//next series in x slot (next y slot)
296 0 : }//next x slot
297 : }//next z slot
298 0 : }
299 :
300 : namespace
301 : {
302 :
303 0 : void lcl_reorderSeries( ::std::vector< ::std::vector< VDataSeriesGroup > >& rZSlots )
304 : {
305 0 : ::std::vector< ::std::vector< VDataSeriesGroup > > aRet( rZSlots.size() );
306 :
307 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZIt( rZSlots.rbegin() );
308 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZEnd( rZSlots.rend() );
309 0 : for( ; aZIt != aZEnd; ++aZIt )
310 : {
311 0 : ::std::vector< VDataSeriesGroup > aXSlot( aZIt->size() );
312 :
313 0 : ::std::vector< VDataSeriesGroup >::reverse_iterator aXIt( aZIt->rbegin() );
314 0 : ::std::vector< VDataSeriesGroup >::reverse_iterator aXEnd( aZIt->rend() );
315 0 : for( ; aXIt != aXEnd; ++aXIt )
316 0 : aXSlot.push_back(*aXIt);
317 :
318 0 : aRet.push_back(aXSlot);
319 0 : }
320 :
321 0 : rZSlots.clear();
322 0 : rZSlots = aRet;
323 0 : }
324 :
325 : }//anonymous namespace
326 :
327 : //better performance for big data
328 : struct FormerPoint
329 : {
330 0 : FormerPoint( double fX, double fY, double fZ )
331 0 : : m_fX(fX), m_fY(fY), m_fZ(fZ)
332 0 : {}
333 0 : FormerPoint()
334 : {
335 0 : ::rtl::math::setNan( &m_fX );
336 0 : ::rtl::math::setNan( &m_fY );
337 0 : ::rtl::math::setNan( &m_fZ );
338 0 : }
339 :
340 : double m_fX;
341 : double m_fY;
342 : double m_fZ;
343 : };
344 :
345 0 : void NetChart::createShapes()
346 : {
347 0 : if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
348 0 : return;
349 :
350 0 : if( m_bArea )
351 0 : lcl_reorderSeries( m_aZSlots );
352 :
353 : OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"NetChart is not proper initialized");
354 0 : if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
355 0 : return;
356 :
357 : //the text labels should be always on top of the other series shapes
358 : //for area chart the error bars should be always on top of the other series shapes
359 :
360 : //therefore create an own group for the texts and the error bars to move them to front
361 : //(because the text group is created after the series group the texts are displayed on top)
362 0 : m_xSeriesTarget = createGroupShape( m_xLogicTarget,OUString() );
363 0 : m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget,OUString() );
364 :
365 : //check necessary here that different Y axis can not be stacked in the same group? ... hm?
366 :
367 : //update/create information for current group
368 0 : double fLogicZ = 1.0;//as defined
369 :
370 0 : sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale
371 0 : sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
372 0 : if(nEndIndex<=0)
373 0 : nEndIndex=1;
374 :
375 : //better performance for big data
376 0 : std::map< VDataSeries*, FormerPoint > aSeriesFormerPointMap;
377 0 : m_bPointsWereSkipped = false;
378 0 : sal_Int32 nSkippedPoints = 0;
379 0 : sal_Int32 nCreatedPoints = 0;
380 :
381 0 : bool bDateCategory = (m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis());
382 :
383 : //iterate through all x values per indices
384 0 : for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
385 : {
386 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
387 0 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
388 :
389 0 : std::map< sal_Int32, double > aLogicYSumMap;//one for each different nAttachedAxisIndex
390 0 : for( ; aZSlotIter != aZSlotEnd; ++aZSlotIter )
391 : {
392 0 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
393 0 : const ::std::vector< VDataSeriesGroup >::iterator aXSlotEnd = aZSlotIter->end();
394 :
395 : //iterate through all x slots in this category to get 100percent sum
396 0 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
397 : {
398 0 : std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
399 0 : std::vector<VDataSeries*>::iterator aSeriesIter = rSeriesList.begin();
400 0 : std::vector<VDataSeries*>::iterator aSeriesEnd = rSeriesList.end();
401 :
402 0 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
403 : {
404 0 : VDataSeries* pSeries( *aSeriesIter );
405 0 : if(!pSeries)
406 0 : continue;
407 :
408 0 : if (bDateCategory)
409 0 : pSeries->doSortByXValues();
410 :
411 0 : sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
412 0 : if( aLogicYSumMap.find(nAttachedAxisIndex)==aLogicYSumMap.end() )
413 0 : aLogicYSumMap[nAttachedAxisIndex]=0.0;
414 :
415 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
416 0 : if(!pPosHelper)
417 0 : pPosHelper = m_pMainPosHelper.get();
418 0 : PlotterBase::m_pPosHelper = pPosHelper;
419 :
420 0 : double fAdd = pSeries->getYValue( nIndex );
421 0 : if( !::rtl::math::isNan(fAdd) && !::rtl::math::isInf(fAdd) )
422 0 : aLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd );
423 : }
424 : }
425 : }
426 :
427 0 : aZSlotIter = m_aZSlots.begin();
428 0 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
429 : {
430 0 : ::std::vector< VDataSeriesGroup >::const_iterator aXSlotIter = aZSlotIter->begin();
431 0 : ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
432 :
433 : //for the area chart there should be at most one x slot (no side by side stacking available)
434 : //attention different: xSlots are always interpreted as independent areas one behind the other: @todo this doesn't work why not???
435 0 : for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, ++nX )
436 : {
437 0 : const std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
438 0 : std::vector<VDataSeries*>::const_iterator aSeriesIter = rSeriesList.begin();
439 0 : const std::vector<VDataSeries*>::const_iterator aSeriesEnd = rSeriesList.end();
440 :
441 0 : std::map< sal_Int32, double > aLogicYForNextSeriesMap;//one for each different nAttachedAxisIndex
442 : //iterate through all series
443 0 : for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; ++aSeriesIter, ++nSeriesIndex )
444 : {
445 0 : VDataSeries* pSeries( *aSeriesIter );
446 0 : if(!pSeries)
447 0 : continue;
448 :
449 : /* #i70133# ignore points outside of series length in standard area
450 : charts. Stacked area charts will use missing points as zeros. In
451 : standard charts, pSeriesList contains only one series. */
452 0 : if( m_bArea && (rSeriesList.size() == 1) && (nIndex >= (*aSeriesIter)->getTotalPointCount()) )
453 0 : continue;
454 :
455 0 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(*aSeriesIter, m_xSeriesTarget);
456 :
457 0 : sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
458 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
459 0 : if(!pPosHelper)
460 0 : pPosHelper = m_pMainPosHelper.get();
461 0 : PlotterBase::m_pPosHelper = pPosHelper;
462 :
463 0 : (*aSeriesIter)->m_fLogicZPos = fLogicZ;
464 :
465 : //collect data point information (logic coordinates, style ):
466 0 : double fLogicX = (*aSeriesIter)->getXValue(nIndex);
467 0 : if (bDateCategory)
468 0 : fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution );
469 0 : double fLogicY = (*aSeriesIter)->getYValue(nIndex);
470 :
471 0 : if( m_bArea && ( ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY) ) )
472 : {
473 0 : if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
474 : {
475 0 : if( rSeriesList.size() == 1 || nSeriesIndex == 0 )
476 : {
477 0 : fLogicY = pPosHelper->getLogicMinY();
478 0 : if( !pPosHelper->isMathematicalOrientationY() )
479 0 : fLogicY = pPosHelper->getLogicMaxY();
480 : }
481 : else
482 0 : fLogicY = 0.0;
483 : }
484 : }
485 :
486 0 : if( pPosHelper->isPercentY() && !::rtl::math::approxEqual( aLogicYSumMap[nAttachedAxisIndex], 0.0 ) )
487 : {
488 0 : fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex];
489 : }
490 :
491 0 : if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
492 0 : || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY)
493 0 : || ::rtl::math::isNan(fLogicZ) || ::rtl::math::isInf(fLogicZ) )
494 : {
495 0 : if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
496 : {
497 0 : drawing::PolyPolygonShape3D& rPolygon = (*aSeriesIter)->m_aPolyPolygonShape3D;
498 0 : sal_Int32& rIndex = (*aSeriesIter)->m_nPolygonIndex;
499 0 : if( 0<= rIndex && rIndex < rPolygon.SequenceX.getLength() )
500 : {
501 0 : if( rPolygon.SequenceX[ rIndex ].getLength() )
502 0 : rIndex++; //start a new polygon for the next point if the current poly is not empty
503 : }
504 : }
505 0 : continue;
506 : }
507 :
508 0 : if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
509 0 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
510 :
511 0 : double fLogicValueForLabeDisplay = fLogicY;
512 :
513 0 : fLogicY += aLogicYForNextSeriesMap[nAttachedAxisIndex];
514 0 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
515 :
516 0 : bool bIsVisible = pPosHelper->isLogicVisible( fLogicX, fLogicY, fLogicZ );
517 :
518 : //remind minimal and maximal x values for area 'grounding' points
519 : //only for filled area
520 : {
521 0 : double& rfMinX = (*aSeriesIter)->m_fLogicMinX;
522 0 : if(!nIndex||fLogicX<rfMinX)
523 0 : rfMinX=fLogicX;
524 0 : double& rfMaxX = (*aSeriesIter)->m_fLogicMaxX;
525 0 : if(!nIndex||fLogicX>rfMaxX)
526 0 : rfMaxX=fLogicX;
527 : }
528 :
529 0 : drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
530 0 : drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
531 0 : pPosHelper->doLogicScaling( aScaledLogicPosition );
532 :
533 : //transformation 3) -> 4)
534 0 : drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
535 :
536 : //better performance for big data
537 0 : FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
538 0 : pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
539 0 : if( !pSeries->isAttributedDataPoint(nIndex)
540 0 : &&
541 : pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
542 0 : , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
543 : {
544 0 : ++nSkippedPoints;
545 0 : m_bPointsWereSkipped = true;
546 0 : continue;
547 : }
548 0 : aSeriesFormerPointMap[pSeries] = FormerPoint(aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ);
549 :
550 : //store point information for series polygon
551 : //for area and/or line (symbols only do not need this)
552 0 : if( isValidPosition(aScaledLogicPosition) )
553 : {
554 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
555 :
556 : //prepare clipping for filled net charts
557 0 : if( !bIsVisible && m_bArea )
558 : {
559 0 : drawing::Position3D aClippedPos(aScaledLogicPosition);
560 0 : pPosHelper->clipScaledLogicValues( 0, &aClippedPos.PositionY, 0 );
561 0 : if( pPosHelper->isLogicVisible( aClippedPos.PositionX, aClippedPos.PositionY, aClippedPos.PositionZ ) )
562 : {
563 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aClippedPos, (*aSeriesIter)->m_nPolygonIndex );
564 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
565 : }
566 : }
567 : }
568 :
569 : //create a single datapoint if point is visible
570 : //apply clipping:
571 0 : if( !bIsVisible )
572 0 : continue;
573 :
574 0 : Symbol* pSymbolProperties = (*aSeriesIter)->getSymbolProperties( nIndex );
575 0 : bool bCreateSymbol = pSymbolProperties && (pSymbolProperties->Style != SymbolStyle_NONE);
576 :
577 0 : if( !bCreateSymbol && !pSeries->getDataPointLabelIfLabel(nIndex) )
578 0 : continue;
579 :
580 : //create a group shape for this point and add to the series shape:
581 : OUString aPointCID = ObjectIdentifier::createPointCID(
582 0 : (*aSeriesIter)->getPointCID_Stub(), nIndex );
583 : uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
584 0 : createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
585 : uno::Reference<drawing::XShape> xPointGroupShape_Shape =
586 0 : uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
587 :
588 : {
589 0 : nCreatedPoints++;
590 :
591 : //create data point
592 0 : drawing::Direction3D aSymbolSize(0,0,0);
593 0 : if( bCreateSymbol )
594 : {
595 0 : if( pSymbolProperties )
596 : {
597 0 : if( pSymbolProperties->Style != SymbolStyle_NONE )
598 : {
599 0 : aSymbolSize.DirectionX = pSymbolProperties->Size.Width;
600 0 : aSymbolSize.DirectionY = pSymbolProperties->Size.Height;
601 : }
602 :
603 0 : if( pSymbolProperties->Style == SymbolStyle_STANDARD )
604 : {
605 0 : sal_Int32 nSymbol = pSymbolProperties->StandardSymbol;
606 : m_pShapeFactory->createSymbol2D( xPointGroupShape_Shapes
607 : , aScenePosition, aSymbolSize
608 : , nSymbol
609 : , pSymbolProperties->BorderColor
610 0 : , pSymbolProperties->FillColor );
611 : }
612 0 : else if( pSymbolProperties->Style == SymbolStyle_GRAPHIC )
613 : {
614 : m_pShapeFactory->createGraphic2D( xPointGroupShape_Shapes
615 : , aScenePosition , aSymbolSize
616 0 : , pSymbolProperties->Graphic );
617 : }
618 : //@todo other symbol styles
619 : }
620 : }
621 :
622 : //create data point label
623 0 : if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
624 : {
625 0 : LabelAlignment eAlignment = LABEL_ALIGN_TOP;
626 : drawing::Position3D aScenePosition3D( aScenePosition.PositionX
627 : , aScenePosition.PositionY
628 0 : , aScenePosition.PositionZ+this->getTransformedDepth() );
629 :
630 0 : sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
631 :
632 0 : switch(nLabelPlacement)
633 : {
634 : case ::com::sun::star::chart::DataLabelPlacement::TOP:
635 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
636 0 : eAlignment = LABEL_ALIGN_TOP;
637 0 : break;
638 : case ::com::sun::star::chart::DataLabelPlacement::BOTTOM:
639 0 : aScenePosition3D.PositionY += (aSymbolSize.DirectionY/2+1);
640 0 : eAlignment = LABEL_ALIGN_BOTTOM;
641 0 : break;
642 : case ::com::sun::star::chart::DataLabelPlacement::LEFT:
643 0 : aScenePosition3D.PositionX -= (aSymbolSize.DirectionX/2+1);
644 0 : eAlignment = LABEL_ALIGN_LEFT;
645 0 : break;
646 : case ::com::sun::star::chart::DataLabelPlacement::RIGHT:
647 0 : aScenePosition3D.PositionX += (aSymbolSize.DirectionX/2+1);
648 0 : eAlignment = LABEL_ALIGN_RIGHT;
649 0 : break;
650 : case ::com::sun::star::chart::DataLabelPlacement::CENTER:
651 0 : eAlignment = LABEL_ALIGN_CENTER;
652 : //todo implement this different for area charts
653 0 : break;
654 : default:
655 : OSL_FAIL("this label alignment is not implemented yet");
656 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
657 0 : eAlignment = LABEL_ALIGN_TOP;
658 0 : break;
659 : }
660 :
661 0 : awt::Point aScreenPosition2D;//get the screen position for the labels
662 0 : sal_Int32 nOffset = 100; //todo maybe calculate this font height dependent
663 0 : if( nLabelPlacement == ::com::sun::star::chart::DataLabelPlacement::OUTSIDE )
664 : {
665 0 : PolarPlottingPositionHelper* pPolarPosHelper = dynamic_cast<PolarPlottingPositionHelper*>(pPosHelper);
666 0 : if( pPolarPosHelper )
667 : {
668 0 : PolarLabelPositionHelper aPolarLabelPositionHelper(pPolarPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
669 : aScreenPosition2D = awt::Point( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
670 0 : eAlignment, fLogicX, fLogicY, fLogicZ, nOffset ));
671 : }
672 : }
673 : else
674 : {
675 0 : if(LABEL_ALIGN_CENTER==eAlignment )
676 0 : nOffset = 0;
677 : aScreenPosition2D = awt::Point( LabelPositionHelper(pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory)
678 0 : .transformSceneToScreenPosition( aScenePosition3D ) );
679 : }
680 :
681 0 : createDataLabel( m_xTextTarget, **aSeriesIter, nIndex
682 : , fLogicValueForLabeDisplay
683 0 : , aLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset );
684 : }
685 : }
686 :
687 : //remove PointGroupShape if empty
688 0 : if(!xPointGroupShape_Shapes->getCount())
689 0 : xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
690 :
691 0 : }//next series in x slot (next y slot)
692 0 : }//next x slot
693 : }//next z slot
694 0 : }//next category
695 :
696 0 : impl_createSeriesShapes();
697 :
698 : }
699 :
700 108 : } //namespace chart
701 :
702 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|