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 2 : 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 2 : , m_bArea(!bNoArea)
59 : , m_bLine(bNoArea)
60 : , m_xSeriesTarget(0)
61 4 : , m_xTextTarget(0)
62 : {
63 : // we only support 2D Net charts
64 : assert(nDimensionCount == 2);
65 :
66 2 : m_pMainPosHelper->AllowShiftXAxisPos(true);
67 2 : m_pMainPosHelper->AllowShiftZAxisPos(true);
68 :
69 2 : PlotterBase::m_pPosHelper = m_pMainPosHelper.get();
70 2 : VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper.get();
71 2 : }
72 :
73 4 : NetChart::~NetChart()
74 : {
75 4 : }
76 :
77 4 : double NetChart::getMaximumX()
78 : {
79 4 : double fMax = VSeriesPlotter::getMaximumX() + 1.0;
80 4 : return fMax;
81 : }
82 :
83 8 : bool NetChart::isExpandIfValuesCloseToBorder( sal_Int32 )
84 : {
85 8 : return false;
86 : }
87 :
88 16 : bool NetChart::isSeparateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex*/ )
89 : {
90 : // no separate stacking in all types of line/area charts
91 16 : return false;
92 : }
93 :
94 6 : LegendSymbolStyle NetChart::getLegendSymbolStyle()
95 : {
96 6 : if( m_bArea )
97 6 : return LegendSymbolStyle_BOX;
98 0 : return LegendSymbolStyle_LINE;
99 : }
100 :
101 4 : uno::Any NetChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex )
102 : {
103 4 : uno::Any aRet;
104 :
105 4 : Symbol* pSymbolProperties = rSeries.getSymbolProperties( nPointIndex );
106 4 : if( pSymbolProperties )
107 : {
108 4 : aRet = uno::makeAny(*pSymbolProperties);
109 : }
110 :
111 4 : return aRet;
112 : }
113 :
114 2 : drawing::Direction3D NetChart::getPreferredDiagramAspectRatio() const
115 : {
116 2 : return drawing::Direction3D(1,1,1);
117 : }
118 :
119 0 : bool NetChart::keepAspectRatio() const
120 : {
121 0 : return true;
122 : }
123 :
124 4 : void NetChart::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot )
125 : {
126 4 : VSeriesPlotter::addSeries( pSeries, zSlot, xSlot, ySlot );
127 4 : }
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 : 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 4 : 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 4 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeBackChild(pSeries, m_xSeriesTarget);
190 4 : double zValue = pSeries->m_fLogicZPos;
191 :
192 8 : drawing::PolyPolygonShape3D aPoly( *pSeriesPoly );
193 : //add second part to the polygon (grounding points or previous series points)
194 4 : if( !AbstractShapeFactory::isPolygonEmptyOrSinglePoint(*pSeriesPoly) )
195 : {
196 4 : 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 4 : AbstractShapeFactory::closePolygon(aPoly);
225 :
226 : //apply clipping
227 : {
228 4 : drawing::PolyPolygonShape3D aClippedPoly;
229 4 : Clipping::clipPolygonAtRectangle( aPoly, pPosHelper->getScaledLogicClipDoubleRect(), aClippedPoly, false );
230 4 : AbstractShapeFactory::closePolygon(aClippedPoly); //again necessary after clipping
231 4 : aPoly = aClippedPoly;
232 : }
233 :
234 4 : if(!AbstractShapeFactory::hasPolygonAnyLines(aPoly))
235 0 : return false;
236 :
237 : //transformation 3) -> 4)
238 4 : pPosHelper->transformScaledLogicToScene( aPoly );
239 :
240 : //create area:
241 : uno::Reference< drawing::XShape >
242 : xShape = m_pShapeFactory->createArea2D( xSeriesGroupShape_Shapes
243 8 : , aPoly );
244 : setMappedProperties( xShape
245 : , pSeries->getPropertiesOfSeries()
246 4 : , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() );
247 : //because of this name this line will be used for marking
248 4 : ::chart::AbstractShapeFactory::setShapeName(xShape, "MarkHandles");
249 8 : return true;
250 : }
251 :
252 2 : 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 2 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
258 2 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
259 6 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
260 : {
261 4 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
262 4 : const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
263 :
264 12 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
265 : {
266 8 : ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
267 :
268 8 : ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
269 8 : const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
270 :
271 8 : std::map< sal_Int32, drawing::PolyPolygonShape3D* > aPreviousSeriesPolyMap;//a PreviousSeriesPoly for each different nAttachedAxisIndex
272 8 : drawing::PolyPolygonShape3D* pSeriesPoly = NULL;
273 :
274 : //iterate through all series
275 12 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
276 : {
277 4 : sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
278 4 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
279 4 : if(!pPosHelper)
280 0 : pPosHelper = m_pMainPosHelper.get();
281 4 : PlotterBase::m_pPosHelper = pPosHelper;
282 :
283 4 : pSeriesPoly = &(*aSeriesIter)->m_aPolyPolygonShape3D;
284 4 : if( m_bArea )
285 : {
286 4 : if( !impl_createArea( *aSeriesIter, pSeriesPoly, aPreviousSeriesPolyMap[nAttachedAxisIndex], pPosHelper ) )
287 0 : continue;
288 : }
289 4 : if( m_bLine )
290 : {
291 0 : if( !impl_createLine( *aSeriesIter, pSeriesPoly, pPosHelper ) )
292 0 : continue;
293 : }
294 4 : aPreviousSeriesPolyMap[nAttachedAxisIndex] = pSeriesPoly;
295 : }//next series in x slot (next y slot)
296 8 : }//next x slot
297 : }//next z slot
298 2 : }
299 :
300 : namespace
301 : {
302 :
303 2 : void lcl_reorderSeries( ::std::vector< ::std::vector< VDataSeriesGroup > >& rZSlots )
304 : {
305 2 : ::std::vector< ::std::vector< VDataSeriesGroup > > aRet( rZSlots.size() );
306 :
307 2 : ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZIt( rZSlots.rbegin() );
308 2 : ::std::vector< ::std::vector< VDataSeriesGroup > >::reverse_iterator aZEnd( rZSlots.rend() );
309 4 : for( ; aZIt != aZEnd; ++aZIt )
310 : {
311 2 : ::std::vector< VDataSeriesGroup > aXSlot( aZIt->size() );
312 :
313 2 : ::std::vector< VDataSeriesGroup >::reverse_iterator aXIt( aZIt->rbegin() );
314 2 : ::std::vector< VDataSeriesGroup >::reverse_iterator aXEnd( aZIt->rend() );
315 6 : for( ; aXIt != aXEnd; ++aXIt )
316 4 : aXSlot.push_back(*aXIt);
317 :
318 2 : aRet.push_back(aXSlot);
319 2 : }
320 :
321 2 : rZSlots.clear();
322 2 : rZSlots = aRet;
323 2 : }
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 2 : void NetChart::createShapes()
346 : {
347 2 : if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
348 0 : return;
349 :
350 2 : if( m_bArea )
351 2 : lcl_reorderSeries( m_aZSlots );
352 :
353 : OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"NetChart is not proper initialized");
354 2 : 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 2 : m_xSeriesTarget = createGroupShape( m_xLogicTarget,OUString() );
363 2 : 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 2 : double fLogicZ = 1.0;//as defined
369 :
370 2 : sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale
371 2 : sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
372 2 : if(nEndIndex<=0)
373 0 : nEndIndex=1;
374 :
375 : //better performance for big data
376 2 : std::map< VDataSeries*, FormerPoint > aSeriesFormerPointMap;
377 2 : m_bPointsWereSkipped = false;
378 2 : sal_Int32 nSkippedPoints = 0;
379 2 : sal_Int32 nCreatedPoints = 0;
380 :
381 2 : bool bDateCategory = (m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis());
382 :
383 : //iterate through all x values per indices
384 12 : for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
385 : {
386 10 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
387 10 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
388 :
389 10 : std::map< sal_Int32, double > aLogicYSumMap;//one for each different nAttachedAxisIndex
390 30 : for( ; aZSlotIter != aZSlotEnd; ++aZSlotIter )
391 : {
392 20 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
393 20 : const ::std::vector< VDataSeriesGroup >::iterator aXSlotEnd = aZSlotIter->end();
394 :
395 : //iterate through all x slots in this category to get 100percent sum
396 60 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
397 : {
398 40 : std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
399 40 : std::vector<VDataSeries*>::iterator aSeriesIter = rSeriesList.begin();
400 40 : std::vector<VDataSeries*>::iterator aSeriesEnd = rSeriesList.end();
401 :
402 60 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
403 : {
404 20 : VDataSeries* pSeries( *aSeriesIter );
405 20 : if(!pSeries)
406 0 : continue;
407 :
408 20 : if (bDateCategory)
409 0 : pSeries->doSortByXValues();
410 :
411 20 : sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
412 20 : if( aLogicYSumMap.find(nAttachedAxisIndex)==aLogicYSumMap.end() )
413 10 : aLogicYSumMap[nAttachedAxisIndex]=0.0;
414 :
415 20 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
416 20 : if(!pPosHelper)
417 0 : pPosHelper = m_pMainPosHelper.get();
418 20 : PlotterBase::m_pPosHelper = pPosHelper;
419 :
420 20 : double fAdd = pSeries->getYValue( nIndex );
421 20 : if( !::rtl::math::isNan(fAdd) && !::rtl::math::isInf(fAdd) )
422 20 : aLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd );
423 : }
424 : }
425 : }
426 :
427 10 : aZSlotIter = m_aZSlots.begin();
428 30 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, ++nZ )
429 : {
430 20 : ::std::vector< VDataSeriesGroup >::const_iterator aXSlotIter = aZSlotIter->begin();
431 20 : ::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 60 : for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, ++nX )
436 : {
437 40 : const std::vector<VDataSeries*>& rSeriesList = aXSlotIter->m_aSeriesVector;
438 40 : std::vector<VDataSeries*>::const_iterator aSeriesIter = rSeriesList.begin();
439 40 : const std::vector<VDataSeries*>::const_iterator aSeriesEnd = rSeriesList.end();
440 :
441 40 : std::map< sal_Int32, double > aLogicYForNextSeriesMap;//one for each different nAttachedAxisIndex
442 : //iterate through all series
443 60 : for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; ++aSeriesIter, ++nSeriesIndex )
444 : {
445 20 : VDataSeries* pSeries( *aSeriesIter );
446 20 : 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 20 : if( m_bArea && (rSeriesList.size() == 1) && (nIndex >= (*aSeriesIter)->getTotalPointCount()) )
453 0 : continue;
454 :
455 20 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(*aSeriesIter, m_xSeriesTarget);
456 :
457 20 : sal_Int32 nAttachedAxisIndex = (*aSeriesIter)->getAttachedAxisIndex();
458 20 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
459 20 : if(!pPosHelper)
460 0 : pPosHelper = m_pMainPosHelper.get();
461 20 : PlotterBase::m_pPosHelper = pPosHelper;
462 :
463 20 : (*aSeriesIter)->m_fLogicZPos = fLogicZ;
464 :
465 : //collect data point information (logic coordinates, style ):
466 20 : double fLogicX = (*aSeriesIter)->getXValue(nIndex);
467 20 : if (bDateCategory)
468 0 : fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution );
469 20 : double fLogicY = (*aSeriesIter)->getYValue(nIndex);
470 :
471 20 : 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 20 : if( pPosHelper->isPercentY() && !::rtl::math::approxEqual( aLogicYSumMap[nAttachedAxisIndex], 0.0 ) )
487 : {
488 0 : fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex];
489 : }
490 :
491 60 : if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
492 20 : || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY)
493 40 : || ::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 20 : if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
509 20 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
510 :
511 20 : double fLogicValueForLabeDisplay = fLogicY;
512 :
513 20 : fLogicY += aLogicYForNextSeriesMap[nAttachedAxisIndex];
514 20 : aLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
515 :
516 20 : 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 20 : double& rfMinX = (*aSeriesIter)->m_fLogicMinX;
522 20 : if(!nIndex||fLogicX<rfMinX)
523 4 : rfMinX=fLogicX;
524 20 : double& rfMaxX = (*aSeriesIter)->m_fLogicMaxX;
525 20 : if(!nIndex||fLogicX>rfMaxX)
526 20 : rfMaxX=fLogicX;
527 : }
528 :
529 20 : drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
530 20 : drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
531 20 : pPosHelper->doLogicScaling( aScaledLogicPosition );
532 :
533 : //transformation 3) -> 4)
534 20 : drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
535 :
536 : //better performance for big data
537 20 : FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
538 20 : pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
539 40 : if( !pSeries->isAttributedDataPoint(nIndex)
540 40 : &&
541 : pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
542 20 : , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
543 : {
544 0 : ++nSkippedPoints;
545 0 : m_bPointsWereSkipped = true;
546 0 : continue;
547 : }
548 20 : 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 20 : if( isValidPosition(aScaledLogicPosition) )
553 : {
554 20 : AddPointToPoly( (*aSeriesIter)->m_aPolyPolygonShape3D, aScaledLogicPosition, (*aSeriesIter)->m_nPolygonIndex );
555 :
556 : //prepare clipping for filled net charts
557 20 : 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 20 : if( !bIsVisible )
572 0 : continue;
573 :
574 20 : Symbol* pSymbolProperties = (*aSeriesIter)->getSymbolProperties( nIndex );
575 20 : bool bCreateSymbol = pSymbolProperties && (pSymbolProperties->Style != SymbolStyle_NONE);
576 :
577 20 : 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 40 : (*aSeriesIter)->getPointCID_Stub(), nIndex );
583 : uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
584 40 : createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
585 : uno::Reference<drawing::XShape> xPointGroupShape_Shape =
586 40 : uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
587 :
588 : {
589 20 : nCreatedPoints++;
590 :
591 : //create data point
592 20 : drawing::Direction3D aSymbolSize(0,0,0);
593 20 : 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 20 : if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
624 : {
625 20 : LabelAlignment eAlignment = LABEL_ALIGN_TOP;
626 : drawing::Position3D aScenePosition3D( aScenePosition.PositionX
627 : , aScenePosition.PositionY
628 20 : , aScenePosition.PositionZ+this->getTransformedDepth() );
629 :
630 20 : sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
631 :
632 20 : 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 20 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
657 20 : eAlignment = LABEL_ALIGN_TOP;
658 20 : break;
659 : }
660 :
661 20 : awt::Point aScreenPosition2D;//get the screen position for the labels
662 20 : sal_Int32 nOffset = 100; //todo maybe calculate this font height dependent
663 20 : if( nLabelPlacement == ::com::sun::star::chart::DataLabelPlacement::OUTSIDE )
664 : {
665 20 : PolarPlottingPositionHelper* pPolarPosHelper = dynamic_cast<PolarPlottingPositionHelper*>(pPosHelper);
666 20 : if( pPolarPosHelper )
667 : {
668 20 : PolarLabelPositionHelper aPolarLabelPositionHelper(pPolarPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
669 : aScreenPosition2D = awt::Point( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
670 20 : 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 20 : createDataLabel( m_xTextTarget, **aSeriesIter, nIndex
682 : , fLogicValueForLabeDisplay
683 40 : , aLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset );
684 : }
685 : }
686 :
687 : //remove PointGroupShape if empty
688 20 : if(!xPointGroupShape_Shapes->getCount())
689 20 : xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
690 :
691 20 : }//next series in x slot (next y slot)
692 40 : }//next x slot
693 : }//next z slot
694 10 : }//next category
695 :
696 2 : impl_createSeriesShapes();
697 :
698 : }
699 :
700 : } //namespace chart
701 :
702 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|