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 : m_pShapeFactory->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 : m_pShapeFactory->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 :
382 0 : bool bDateCategory = (m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis());
383 :
384 : //iterate through all x values per indices
385 0 : for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
386 : {
387 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
388 0 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
389 :
390 0 : std::map< sal_Int32, double > aLogicYSumMap;//one for each different nAttachedAxisIndex
391 0 : for( ; aZSlotIter != aZSlotEnd; ++aZSlotIter )
392 : {
393 0 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
394 0 : const ::std::vector< VDataSeriesGroup >::iterator aXSlotEnd = aZSlotIter->end();
395 :
396 : //iterate through all x slots in this category to get 100percent sum
397 0 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
398 : {
399 0 : std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
400 0 : std::vector<VDataSeries*>::iterator aSeriesIter = rSeriesList.begin();
401 0 : std::vector<VDataSeries*>::iterator aSeriesEnd = rSeriesList.end();
402 :
403 0 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
404 : {
405 0 : VDataSeries* pSeries( *aSeriesIter );
406 0 : if(!pSeries)
407 0 : continue;
408 :
409 0 : if (bDateCategory)
410 0 : pSeries->doSortByXValues();
411 :
412 0 : sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
413 0 : if( aLogicYSumMap.find(nAttachedAxisIndex)==aLogicYSumMap.end() )
414 0 : aLogicYSumMap[nAttachedAxisIndex]=0.0;
415 :
416 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
417 0 : if(!pPosHelper)
418 0 : pPosHelper = m_pMainPosHelper.get();
419 0 : PlotterBase::m_pPosHelper = pPosHelper;
420 :
421 0 : double fAdd = pSeries->getYValue( nIndex );
422 0 : if( !::rtl::math::isNan(fAdd) && !::rtl::math::isInf(fAdd) )
423 0 : aLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd );
424 : }
425 : }
426 : }
427 :
428 0 : aZSlotIter = m_aZSlots.begin();
429 0 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
430 : {
431 0 : ::std::vector< VDataSeriesGroup >::const_iterator aXSlotIter = aZSlotIter->begin();
432 0 : ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
433 :
434 : //for the area chart there should be at most one x slot (no side by side stacking available)
435 : //attention different: xSlots are always interpreted as independent areas one behind the other: @todo this doesn't work why not???
436 0 : for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, ++nX )
437 : {
438 0 : const std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
439 0 : std::vector<VDataSeries*>::const_iterator aSeriesIter = rSeriesList.begin();
440 0 : const std::vector<VDataSeries*>::const_iterator aSeriesEnd = rSeriesList.end();
441 :
442 0 : std::map< sal_Int32, double > aLogicYForNextSeriesMap;//one for each different nAttachedAxisIndex
443 : //iterate through all series
444 0 : for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; ++aSeriesIter, ++nSeriesIndex )
445 : {
446 0 : VDataSeries* pSeries( *aSeriesIter );
447 0 : if(!pSeries)
448 0 : continue;
449 :
450 : /* #i70133# ignore points outside of series length in standard area
451 : charts. Stacked area charts will use missing points as zeros. In
452 : standard charts, pSeriesList contains only one series. */
453 0 : if( m_bArea && (rSeriesList.size() == 1) && (nIndex >= (*aSeriesIter)->getTotalPointCount()) )
454 0 : continue;
455 :
456 0 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(*aSeriesIter, m_xSeriesTarget);
457 :
458 0 : sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
459 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
460 0 : if(!pPosHelper)
461 0 : pPosHelper = m_pMainPosHelper.get();
462 0 : PlotterBase::m_pPosHelper = pPosHelper;
463 :
464 0 : (*aSeriesIter)->m_fLogicZPos = fLogicZ;
465 :
466 : //collect data point information (logic coordinates, style ):
467 0 : double fLogicX = (*aSeriesIter)->getXValue(nIndex);
468 0 : if (bDateCategory)
469 0 : fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution );
470 0 : double fLogicY = (*aSeriesIter)->getYValue(nIndex);
471 :
472 0 : if( m_bArea && ( ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY) ) )
473 : {
474 0 : if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
475 : {
476 0 : if( rSeriesList.size() == 1 || nSeriesIndex == 0 )
477 : {
478 0 : fLogicY = pPosHelper->getLogicMinY();
479 0 : if( !pPosHelper->isMathematicalOrientationY() )
480 0 : fLogicY = pPosHelper->getLogicMaxY();
481 : }
482 : else
483 0 : fLogicY = 0.0;
484 : }
485 : }
486 :
487 0 : if( pPosHelper->isPercentY() && !::rtl::math::approxEqual( aLogicYSumMap[nAttachedAxisIndex], 0.0 ) )
488 : {
489 0 : fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex];
490 : }
491 :
492 0 : if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
493 0 : || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY)
494 0 : || ::rtl::math::isNan(fLogicZ) || ::rtl::math::isInf(fLogicZ) )
495 : {
496 0 : if( (*aSeriesIter)->getMissingValueTreatment() == ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP )
497 : {
498 0 : drawing::PolyPolygonShape3D& rPolygon = (*aSeriesIter)->m_aPolyPolygonShape3D;
499 0 : sal_Int32& rIndex = (*aSeriesIter)->m_nPolygonIndex;
500 0 : if( 0<= rIndex && rIndex < rPolygon.SequenceX.getLength() )
501 : {
502 0 : if( rPolygon.SequenceX[ rIndex ].getLength() )
503 0 : rIndex++; //start a new polygon for the next point if the current poly is not empty
504 : }
505 : }
506 0 : continue;
507 : }
508 :
509 0 : if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
510 0 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
511 :
512 0 : double fLogicValueForLabeDisplay = fLogicY;
513 :
514 0 : fLogicY += aLogicYForNextSeriesMap[nAttachedAxisIndex];
515 0 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
516 :
517 0 : bool bIsVisible = pPosHelper->isLogicVisible( fLogicX, fLogicY, fLogicZ );
518 :
519 : //remind minimal and maximal x values for area 'grounding' points
520 : //only for filled area
521 : {
522 0 : double& rfMinX = (*aSeriesIter)->m_fLogicMinX;
523 0 : if(!nIndex||fLogicX<rfMinX)
524 0 : rfMinX=fLogicX;
525 0 : double& rfMaxX = (*aSeriesIter)->m_fLogicMaxX;
526 0 : if(!nIndex||fLogicX>rfMaxX)
527 0 : rfMaxX=fLogicX;
528 : }
529 :
530 0 : drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
531 0 : drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
532 0 : pPosHelper->doLogicScaling( aScaledLogicPosition );
533 :
534 : //transformation 3) -> 4)
535 0 : drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
536 :
537 : //better performance for big data
538 0 : FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
539 0 : pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
540 0 : if( !pSeries->isAttributedDataPoint(nIndex)
541 0 : &&
542 : pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
543 0 : , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
544 : {
545 0 : ++nSkippedPoints;
546 0 : m_bPointsWereSkipped = true;
547 0 : continue;
548 : }
549 0 : aSeriesFormerPointMap[pSeries] = FormerPoint(aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ);
550 :
551 :
552 : //store point information for series polygon
553 : //for area and/or line (symbols only do not need this)
554 0 : if( isValidPosition(aScaledLogicPosition) )
555 : {
556 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
557 :
558 : //prepare clipping for filled net charts
559 0 : if( !bIsVisible && m_bArea )
560 : {
561 0 : drawing::Position3D aClippedPos(aScaledLogicPosition);
562 0 : pPosHelper->clipScaledLogicValues( 0, &aClippedPos.PositionY, 0 );
563 0 : if( pPosHelper->isLogicVisible( aClippedPos.PositionX, aClippedPos.PositionY, aClippedPos.PositionZ ) )
564 : {
565 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aClippedPos, (*aSeriesIter)->m_nPolygonIndex );
566 0 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
567 : }
568 : }
569 : }
570 :
571 : //create a single datapoint if point is visible
572 : //apply clipping:
573 0 : if( !bIsVisible )
574 0 : continue;
575 :
576 0 : Symbol* pSymbolProperties = (*aSeriesIter)->getSymbolProperties( nIndex );
577 0 : bool bCreateSymbol = pSymbolProperties && (pSymbolProperties->Style != SymbolStyle_NONE);
578 :
579 0 : if( !bCreateSymbol && !pSeries->getDataPointLabelIfLabel(nIndex) )
580 0 : continue;
581 :
582 : //create a group shape for this point and add to the series shape:
583 : OUString aPointCID = ObjectIdentifier::createPointCID(
584 0 : (*aSeriesIter)->getPointCID_Stub(), nIndex );
585 : uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
586 0 : createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
587 : uno::Reference<drawing::XShape> xPointGroupShape_Shape =
588 0 : uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
589 :
590 : {
591 0 : nCreatedPoints++;
592 :
593 : //create data point
594 0 : drawing::Direction3D aSymbolSize(0,0,0);
595 0 : if( bCreateSymbol )
596 : {
597 0 : if( pSymbolProperties )
598 : {
599 0 : if( pSymbolProperties->Style != SymbolStyle_NONE )
600 : {
601 0 : aSymbolSize.DirectionX = pSymbolProperties->Size.Width;
602 0 : aSymbolSize.DirectionY = pSymbolProperties->Size.Height;
603 : }
604 :
605 0 : if( pSymbolProperties->Style == SymbolStyle_STANDARD )
606 : {
607 0 : sal_Int32 nSymbol = pSymbolProperties->StandardSymbol;
608 : m_pShapeFactory->createSymbol2D( xPointGroupShape_Shapes
609 : , aScenePosition, aSymbolSize
610 : , nSymbol
611 : , pSymbolProperties->BorderColor
612 0 : , pSymbolProperties->FillColor );
613 : }
614 0 : else if( pSymbolProperties->Style == SymbolStyle_GRAPHIC )
615 : {
616 : m_pShapeFactory->createGraphic2D( xPointGroupShape_Shapes
617 : , aScenePosition , aSymbolSize
618 0 : , pSymbolProperties->Graphic );
619 : }
620 : //@todo other symbol styles
621 : }
622 : }
623 :
624 : //create data point label
625 0 : if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
626 : {
627 0 : LabelAlignment eAlignment = LABEL_ALIGN_TOP;
628 : drawing::Position3D aScenePosition3D( aScenePosition.PositionX
629 : , aScenePosition.PositionY
630 0 : , aScenePosition.PositionZ+this->getTransformedDepth() );
631 :
632 0 : sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
633 :
634 0 : switch(nLabelPlacement)
635 : {
636 : case ::com::sun::star::chart::DataLabelPlacement::TOP:
637 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
638 0 : eAlignment = LABEL_ALIGN_TOP;
639 0 : break;
640 : case ::com::sun::star::chart::DataLabelPlacement::BOTTOM:
641 0 : aScenePosition3D.PositionY += (aSymbolSize.DirectionY/2+1);
642 0 : eAlignment = LABEL_ALIGN_BOTTOM;
643 0 : break;
644 : case ::com::sun::star::chart::DataLabelPlacement::LEFT:
645 0 : aScenePosition3D.PositionX -= (aSymbolSize.DirectionX/2+1);
646 0 : eAlignment = LABEL_ALIGN_LEFT;
647 0 : break;
648 : case ::com::sun::star::chart::DataLabelPlacement::RIGHT:
649 0 : aScenePosition3D.PositionX += (aSymbolSize.DirectionX/2+1);
650 0 : eAlignment = LABEL_ALIGN_RIGHT;
651 0 : break;
652 : case ::com::sun::star::chart::DataLabelPlacement::CENTER:
653 0 : eAlignment = LABEL_ALIGN_CENTER;
654 : //todo implement this different for area charts
655 0 : break;
656 : default:
657 : OSL_FAIL("this label alignment is not implemented yet");
658 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
659 0 : eAlignment = LABEL_ALIGN_TOP;
660 0 : break;
661 : }
662 :
663 0 : awt::Point aScreenPosition2D;//get the screen position for the labels
664 0 : sal_Int32 nOffset = 100; //todo maybe calculate this font height dependent
665 0 : if( nLabelPlacement == ::com::sun::star::chart::DataLabelPlacement::OUTSIDE )
666 : {
667 0 : PolarPlottingPositionHelper* pPolarPosHelper = dynamic_cast<PolarPlottingPositionHelper*>(pPosHelper);
668 0 : if( pPolarPosHelper )
669 : {
670 0 : PolarLabelPositionHelper aPolarLabelPositionHelper(pPolarPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
671 : aScreenPosition2D = awt::Point( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
672 0 : eAlignment, fLogicX, fLogicY, fLogicZ, nOffset ));
673 : }
674 : }
675 : else
676 : {
677 0 : if(LABEL_ALIGN_CENTER==eAlignment )
678 0 : nOffset = 0;
679 : aScreenPosition2D = awt::Point( LabelPositionHelper(pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory)
680 0 : .transformSceneToScreenPosition( aScenePosition3D ) );
681 : }
682 :
683 0 : this->createDataLabel( m_xTextTarget, **aSeriesIter, nIndex
684 : , fLogicValueForLabeDisplay
685 0 : , aLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset );
686 : }
687 : }
688 :
689 : //remove PointGroupShape if empty
690 0 : if(!xPointGroupShape_Shapes->getCount())
691 0 : xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
692 :
693 0 : }//next series in x slot (next y slot)
694 0 : }//next x slot
695 : }//next z slot
696 0 : }//next category
697 :
698 0 : impl_createSeriesShapes();
699 :
700 : }
701 :
702 : } //namespace chart
703 :
704 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|