Branch data 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 : :
21 : : #include "BubbleChart.hxx"
22 : : #include "PlottingPositionHelper.hxx"
23 : : #include "ShapeFactory.hxx"
24 : : #include "CommonConverters.hxx"
25 : : #include "macros.hxx"
26 : : #include "ViewDefines.hxx"
27 : : #include "ObjectIdentifier.hxx"
28 : : #include "Splines.hxx"
29 : : #include "LabelPositionHelper.hxx"
30 : : #include "Clipping.hxx"
31 : : #include "Stripe.hxx"
32 : :
33 : : #include <com/sun/star/chart2/Symbol.hpp>
34 : : #include <com/sun/star/chart/DataLabelPlacement.hpp>
35 : : #include <editeng/unoprnms.hxx>
36 : : #include <rtl/math.hxx>
37 : : #include <com/sun/star/drawing/DoubleSequence.hpp>
38 : : #include <com/sun/star/drawing/NormalsKind.hpp>
39 : : #include <com/sun/star/lang/XServiceName.hpp>
40 : :
41 : : //.............................................................................
42 : : namespace chart
43 : : {
44 : : //.............................................................................
45 : : using namespace ::com::sun::star;
46 : : using namespace ::rtl::math;
47 : : using namespace ::com::sun::star::chart2;
48 : :
49 : : //-----------------------------------------------------------------------------
50 : : //-----------------------------------------------------------------------------
51 : : //-----------------------------------------------------------------------------
52 : :
53 : 0 : BubbleChart::BubbleChart( const uno::Reference<XChartType>& xChartTypeModel
54 : : , sal_Int32 nDimensionCount )
55 : : : VSeriesPlotter( xChartTypeModel, nDimensionCount, false )
56 : : , m_bShowNegativeValues(false)
57 : : , m_bBubbleSizeAsArea(true)
58 : : , m_fBubbleSizeScaling(1.0)
59 : : , m_fMaxLogicBubbleSize( 0.0 )
60 : 0 : , m_fBubbleSizeFactorToScreen( 1.0 )
61 : : {
62 [ # # ]: 0 : if( !m_pMainPosHelper )
63 [ # # ][ # # ]: 0 : m_pMainPosHelper = new PlottingPositionHelper();
64 : 0 : PlotterBase::m_pPosHelper = m_pMainPosHelper;
65 : 0 : VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper;
66 : 0 : }
67 : :
68 : 0 : BubbleChart::~BubbleChart()
69 : : {
70 [ # # ][ # # ]: 0 : delete m_pMainPosHelper;
71 [ # # ]: 0 : }
72 : :
73 : 0 : void BubbleChart::calculateMaximumLogicBubbleSize()
74 : : {
75 : 0 : double fMaxSize = 0.0;
76 : :
77 : 0 : sal_Int32 nStartIndex = 0;
78 : 0 : sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
79 [ # # ]: 0 : for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
80 : : {
81 : 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
82 [ # # ]: 0 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
83 [ # # ][ # # ]: 0 : for( ; aZSlotIter != aZSlotEnd; ++aZSlotIter )
84 : : {
85 : 0 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
86 [ # # ]: 0 : const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
87 [ # # ][ # # ]: 0 : for( ; aXSlotIter != aXSlotEnd; ++aXSlotIter )
88 : : {
89 : 0 : ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
90 [ # # ]: 0 : ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
91 [ # # ]: 0 : const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
92 [ # # ][ # # ]: 0 : for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
93 : : {
94 : 0 : VDataSeries* pSeries( *aSeriesIter );
95 [ # # ]: 0 : if(!pSeries)
96 : 0 : continue;
97 : :
98 [ # # ]: 0 : double fSize = pSeries->getBubble_Size( nIndex );
99 [ # # ]: 0 : if( m_bShowNegativeValues )
100 : 0 : fSize = fabs(fSize);
101 [ # # ]: 0 : if( fSize > fMaxSize )
102 : 0 : fMaxSize = fSize;
103 : : }
104 : : }
105 : : }
106 : : }
107 : :
108 : 0 : m_fMaxLogicBubbleSize = fMaxSize;
109 : 0 : }
110 : :
111 : 0 : void BubbleChart::calculateBubbleSizeScalingFactor()
112 : : {
113 : 0 : double fLogicZ=1.0;
114 [ # # ][ # # ]: 0 : drawing::Position3D aSceneMinPos( m_pMainPosHelper->transformLogicToScene( m_pMainPosHelper->getLogicMinX(),m_pMainPosHelper->getLogicMinY(),fLogicZ, false ) );
[ # # ]
115 [ # # ][ # # ]: 0 : drawing::Position3D aSceneMaxPos( m_pMainPosHelper->transformLogicToScene( m_pMainPosHelper->getLogicMaxX(),m_pMainPosHelper->getLogicMaxY(),fLogicZ, false ) );
[ # # ]
116 : :
117 [ # # ][ # # ]: 0 : awt::Point aScreenMinPos( LabelPositionHelper(m_pMainPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory).transformSceneToScreenPosition( aSceneMinPos ) );
[ # # ]
118 [ # # ][ # # ]: 0 : awt::Point aScreenMaxPos( LabelPositionHelper(m_pMainPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory).transformSceneToScreenPosition( aSceneMaxPos ) );
[ # # ]
119 : :
120 : 0 : sal_Int32 nWidth = abs( aScreenMaxPos.X - aScreenMinPos.X );
121 : 0 : sal_Int32 nHeight = abs( aScreenMaxPos.Y - aScreenMinPos.Y );
122 : :
123 [ # # ]: 0 : sal_Int32 nMinExtend = std::min( nWidth, nHeight );
124 : 0 : m_fBubbleSizeFactorToScreen = nMinExtend * 0.25;//max bubble size is 25 percent of diagram size
125 : 0 : }
126 : :
127 : 0 : drawing::Direction3D BubbleChart::transformToScreenBubbleSize( double fLogicSize )
128 : : {
129 : 0 : drawing::Direction3D aRet(0,0,0);
130 : :
131 [ # # ][ # # ]: 0 : if( ::rtl::math::isNan(fLogicSize) || ::rtl::math::isInf(fLogicSize) )
[ # # ]
132 : 0 : return aRet;
133 : :
134 [ # # ]: 0 : if( m_bShowNegativeValues )
135 : 0 : fLogicSize = fabs(fLogicSize);
136 : :
137 : 0 : double fMaxSize = m_fMaxLogicBubbleSize;
138 : :
139 : 0 : double fMaxRadius = fMaxSize;
140 : 0 : double fRaduis = fLogicSize;
141 [ # # ]: 0 : if( m_bBubbleSizeAsArea )
142 : : {
143 : 0 : fMaxRadius = sqrt( fMaxSize / F_PI );
144 : 0 : fRaduis = sqrt( fLogicSize / F_PI );
145 : : }
146 : :
147 : 0 : aRet.DirectionX = m_fBubbleSizeScaling * m_fBubbleSizeFactorToScreen * fRaduis / fMaxRadius;
148 : 0 : aRet.DirectionY = aRet.DirectionX;
149 : :
150 : 0 : return aRet;
151 : : }
152 : :
153 : 0 : bool BubbleChart::isExpandIfValuesCloseToBorder( sal_Int32 /*nDimensionIndex*/ )
154 : : {
155 : 0 : return true;
156 : : }
157 : :
158 : 0 : bool BubbleChart::isSeperateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex*/ )
159 : : {
160 : 0 : return false;
161 : : }
162 : :
163 : : //-----------------------------------------------------------------
164 : :
165 : 0 : LegendSymbolStyle BubbleChart::getLegendSymbolStyle()
166 : : {
167 : 0 : return LegendSymbolStyle_CIRCLE;
168 : : }
169 : :
170 : 0 : drawing::Direction3D BubbleChart::getPreferredDiagramAspectRatio() const
171 : : {
172 : 0 : return drawing::Direction3D(-1,-1,-1);
173 : : }
174 : :
175 : 0 : void BubbleChart::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot )
176 : : {
177 : 0 : VSeriesPlotter::addSeries( pSeries, zSlot, xSlot, ySlot );
178 : 0 : }
179 : :
180 : : //better performance for big data
181 : : struct FormerPoint
182 : : {
183 : 0 : FormerPoint( double fX, double fY, double fZ )
184 : 0 : : m_fX(fX), m_fY(fY), m_fZ(fZ)
185 : 0 : {}
186 : 0 : FormerPoint()
187 : : {
188 : 0 : ::rtl::math::setNan( &m_fX );
189 : 0 : ::rtl::math::setNan( &m_fY );
190 : 0 : ::rtl::math::setNan( &m_fZ );
191 : 0 : }
192 : :
193 : : double m_fX;
194 : : double m_fY;
195 : : double m_fZ;
196 : : };
197 : :
198 : 0 : void BubbleChart::createShapes()
199 : : {
200 [ # # ][ # # ]: 0 : if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
201 : : return;
202 : :
203 : : OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"BubbleChart is not proper initialized");
204 [ # # ][ # # ]: 0 : if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
[ # # ][ # # ]
205 : : return;
206 : :
207 : : //therefore create an own group for the texts and the error bars to move them to front
208 : : //(because the text group is created after the series group the texts are displayed on top)
209 : : uno::Reference< drawing::XShapes > xSeriesTarget(
210 [ # # ]: 0 : createGroupShape( m_xLogicTarget,rtl::OUString() ));
211 : : uno::Reference< drawing::XShapes > xTextTarget(
212 [ # # ]: 0 : m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() ));
213 : :
214 : : //update/create information for current group
215 : 0 : double fLogicZ = 1.0;//as defined
216 : :
217 : 0 : sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale
218 [ # # ]: 0 : sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
219 [ # # ]: 0 : if(nEndIndex<=0)
220 : 0 : nEndIndex=1;
221 : :
222 : : //better performance for big data
223 [ # # ]: 0 : std::map< VDataSeries*, FormerPoint > aSeriesFormerPointMap;
224 : 0 : m_bPointsWereSkipped = false;
225 : 0 : sal_Int32 nSkippedPoints = 0;
226 : 0 : sal_Int32 nCreatedPoints = 0;
227 : : //
228 : :
229 [ # # ]: 0 : calculateMaximumLogicBubbleSize();
230 [ # # ]: 0 : calculateBubbleSizeScalingFactor();
231 [ # # ][ # # ]: 0 : if( m_fMaxLogicBubbleSize <= 0 || m_fBubbleSizeFactorToScreen <= 0 )
232 : : return;
233 : :
234 : : //=============================================================================
235 : : //iterate through all x values per indices
236 [ # # ]: 0 : for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
237 : : {
238 : 0 : ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin();
239 [ # # ]: 0 : const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end();
240 : :
241 : 0 : aZSlotIter = m_aZSlots.begin();
242 [ # # ][ # # ]: 0 : for( sal_Int32 nZ=1; aZSlotIter != aZSlotEnd; ++aZSlotIter, nZ++ )
243 : : {
244 : 0 : ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin();
245 [ # # ]: 0 : const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
246 : :
247 : 0 : aXSlotIter = aZSlotIter->begin();
248 [ # # ][ # # ]: 0 : for( sal_Int32 nX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, ++nX )
249 : : {
250 : 0 : ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
251 [ # # ]: 0 : ::std::vector< VDataSeries* >::const_iterator aSeriesIter = pSeriesList->begin();
252 [ # # ]: 0 : const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = pSeriesList->end();
253 : :
254 : : //=============================================================================
255 : : //iterate through all series
256 [ # # ][ # # ]: 0 : for( sal_Int32 nSeriesIndex = 0; aSeriesIter != aSeriesEnd; ++aSeriesIter, ++nSeriesIndex )
257 : : {
258 : 0 : VDataSeries* pSeries( *aSeriesIter );
259 [ # # ]: 0 : if(!pSeries)
260 : 0 : continue;
261 : :
262 [ # # ]: 0 : uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShape(*aSeriesIter, xSeriesTarget);
263 : :
264 [ # # ]: 0 : sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
265 [ # # ]: 0 : PlottingPositionHelper* pPosHelper = &(this->getPlottingPositionHelper( nAttachedAxisIndex ));
266 [ # # ]: 0 : if(!pPosHelper)
267 : 0 : pPosHelper = m_pMainPosHelper;
268 : 0 : PlotterBase::m_pPosHelper = pPosHelper;
269 : :
270 [ # # ]: 0 : if(m_nDimension==3)
271 : 0 : fLogicZ = nZ+0.5;
272 : :
273 : : //collect data point information (logic coordinates, style ):
274 [ # # ]: 0 : double fLogicX = pSeries->getXValue(nIndex);
275 [ # # ]: 0 : double fLogicY = pSeries->getYValue(nIndex);
276 [ # # ]: 0 : double fBubbleSize = pSeries->getBubble_Size( nIndex );
277 : :
278 [ # # ][ # # ]: 0 : if( !m_bShowNegativeValues && fBubbleSize<0.0 )
279 : 0 : continue;
280 : :
281 [ # # ][ # # ]: 0 : if( ::rtl::math::approxEqual( fBubbleSize, 0.0 ) || ::rtl::math::isNan(fBubbleSize) )
[ # # ]
282 : 0 : continue;
283 : :
284 [ # # ][ # # : 0 : if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX)
# # # # ]
[ # # ]
285 : 0 : || ::rtl::math::isNan(fLogicY) || ::rtl::math::isInf(fLogicY) )
286 : 0 : continue;
287 : :
288 [ # # ]: 0 : bool bIsVisible = pPosHelper->isLogicVisible( fLogicX, fLogicY, fLogicZ );
289 : :
290 : 0 : drawing::Position3D aUnscaledLogicPosition( fLogicX, fLogicY, fLogicZ );
291 : 0 : drawing::Position3D aScaledLogicPosition(aUnscaledLogicPosition);
292 [ # # ]: 0 : pPosHelper->doLogicScaling( aScaledLogicPosition );
293 : :
294 : : //transformation 3) -> 4)
295 [ # # ]: 0 : drawing::Position3D aScenePosition( pPosHelper->transformLogicToScene( fLogicX,fLogicY,fLogicZ, false ) );
296 : :
297 : : //better performance for big data
298 [ # # ]: 0 : FormerPoint aFormerPoint( aSeriesFormerPointMap[pSeries] );
299 [ # # ]: 0 : pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution );
300 [ # # ][ # # ]: 0 : if( !pSeries->isAttributedDataPoint(nIndex)
[ # # ][ # # ]
301 : : &&
302 : : pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fY, aFormerPoint.m_fZ
303 [ # # ]: 0 : , aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ ) )
304 : : {
305 : 0 : nSkippedPoints++;
306 : 0 : m_bPointsWereSkipped = true;
307 : 0 : continue;
308 : : }
309 [ # # ]: 0 : aSeriesFormerPointMap[pSeries] = FormerPoint(aScaledLogicPosition.PositionX, aScaledLogicPosition.PositionY, aScaledLogicPosition.PositionZ);
310 : :
311 : : //create a single datapoint if point is visible
312 [ # # ]: 0 : if( !bIsVisible )
313 : 0 : continue;
314 : :
315 : : //create a group shape for this point and add to the series shape:
316 : : rtl::OUString aPointCID = ObjectIdentifier::createPointCID(
317 [ # # ][ # # ]: 0 : pSeries->getPointCID_Stub(), nIndex );
318 : : uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(
319 [ # # ]: 0 : createGroupShape(xSeriesGroupShape_Shapes,aPointCID) );
320 : : uno::Reference<drawing::XShape> xPointGroupShape_Shape =
321 [ # # ]: 0 : uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY );
322 : :
323 : : {
324 : 0 : nCreatedPoints++;
325 : :
326 : : //create data point
327 : 0 : drawing::Direction3D aSymbolSize = transformToScreenBubbleSize( fBubbleSize );
328 [ # # ]: 0 : if(m_nDimension!=3)
329 : : {
330 : 0 : uno::Reference<drawing::XShape> xShape;
331 : : xShape = m_pShapeFactory->createCircle2D( xPointGroupShape_Shapes
332 [ # # ][ # # ]: 0 : , aScenePosition, aSymbolSize );
333 : :
334 : : this->setMappedProperties( xShape
335 : : , pSeries->getPropertiesOfPoint( nIndex )
336 [ # # ][ # # ]: 0 : , PropertyMapper::getPropertyNameMapForFilledSeriesProperties() );
[ # # ]
337 : :
338 [ # # ][ # # ]: 0 : m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
339 : : }
340 : :
341 : : //create data point label
342 [ # # ][ # # ]: 0 : if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
343 : : {
344 : 0 : LabelAlignment eAlignment = LABEL_ALIGN_TOP;
345 : : drawing::Position3D aScenePosition3D( aScenePosition.PositionX
346 : : , aScenePosition.PositionY
347 [ # # ]: 0 : , aScenePosition.PositionZ+this->getTransformedDepth() );
348 : :
349 [ # # ]: 0 : sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() );
350 : :
351 [ # # # # : 0 : switch(nLabelPlacement)
# # ]
352 : : {
353 : : case ::com::sun::star::chart::DataLabelPlacement::TOP:
354 : 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
355 : 0 : eAlignment = LABEL_ALIGN_TOP;
356 : 0 : break;
357 : : case ::com::sun::star::chart::DataLabelPlacement::BOTTOM:
358 : 0 : aScenePosition3D.PositionY += (aSymbolSize.DirectionY/2+1);
359 : 0 : eAlignment = LABEL_ALIGN_BOTTOM;
360 : 0 : break;
361 : : case ::com::sun::star::chart::DataLabelPlacement::LEFT:
362 : 0 : aScenePosition3D.PositionX -= (aSymbolSize.DirectionX/2+1);
363 : 0 : eAlignment = LABEL_ALIGN_LEFT;
364 : 0 : break;
365 : : case ::com::sun::star::chart::DataLabelPlacement::RIGHT:
366 : 0 : aScenePosition3D.PositionX += (aSymbolSize.DirectionX/2+1);
367 : 0 : eAlignment = LABEL_ALIGN_RIGHT;
368 : 0 : break;
369 : : case ::com::sun::star::chart::DataLabelPlacement::CENTER:
370 : 0 : eAlignment = LABEL_ALIGN_CENTER;
371 : 0 : break;
372 : : default:
373 : : OSL_FAIL("this label alignment is not implemented yet");
374 : 0 : aScenePosition3D.PositionY -= (aSymbolSize.DirectionY/2+1);
375 : 0 : eAlignment = LABEL_ALIGN_TOP;
376 : 0 : break;
377 : : }
378 : :
379 : :
380 : : awt::Point aScreenPosition2D( LabelPositionHelper(pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory)
381 [ # # ][ # # ]: 0 : .transformSceneToScreenPosition( aScenePosition3D ) );
[ # # ]
382 : 0 : sal_Int32 nOffset = 0;
383 [ # # ]: 0 : if(LABEL_ALIGN_CENTER!=eAlignment)
384 : 0 : nOffset = 100;//add some spacing //@todo maybe get more intelligent values
385 : 0 : this->createDataLabel( xTextTarget, **aSeriesIter, nIndex
386 [ # # ]: 0 : , fBubbleSize, fBubbleSize, aScreenPosition2D, eAlignment, nOffset );
387 : : }
388 : : }
389 : :
390 : : //remove PointGroupShape if empty
391 [ # # ][ # # ]: 0 : if(!xPointGroupShape_Shapes->getCount())
[ # # ]
392 [ # # ][ # # ]: 0 : xSeriesGroupShape_Shapes->remove(xPointGroupShape_Shape);
393 : :
394 [ # # ]: 0 : }//next series in x slot (next y slot)
395 : : }//next x slot
396 : : }//next z slot
397 : : }//next category
398 : : //=============================================================================
399 : : //=============================================================================
400 : : //=============================================================================
401 [ # # ][ # # ]: 0 : OSL_TRACE( "\nPPPPPPPPP<<<<<<<<<<<< area chart :: createShapes():: skipped points: %d created points: %d", nSkippedPoints, nCreatedPoints );
[ # # ]
402 : : }
403 : :
404 : : //.............................................................................
405 : : } //namespace chart
406 : : //.............................................................................
407 : :
408 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|