LCOV - code coverage report
Current view: top level - chart2/source/view/charttypes - CandleStickChart.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 143 165 86.7 %
Date: 2014-04-11 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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 "CandleStickChart.hxx"
      21             : #include "ShapeFactory.hxx"
      22             : #include "CommonConverters.hxx"
      23             : #include "ObjectIdentifier.hxx"
      24             : #include "LabelPositionHelper.hxx"
      25             : #include "BarPositionHelper.hxx"
      26             : #include "macros.hxx"
      27             : #include "VLegendSymbolFactory.hxx"
      28             : #include "FormattedStringHelper.hxx"
      29             : #include "DataSeriesHelper.hxx"
      30             : #include "DateHelper.hxx"
      31             : #include <rtl/math.hxx>
      32             : #include <editeng/unoprnms.hxx>
      33             : 
      34             : namespace chart
      35             : {
      36             : using namespace ::com::sun::star;
      37             : using namespace ::rtl::math;
      38             : using namespace ::com::sun::star::chart2;
      39             : using ::com::sun::star::uno::Reference;
      40             : 
      41           3 : CandleStickChart::CandleStickChart( const uno::Reference<XChartType>& xChartTypeModel
      42             :                                     , sal_Int32 nDimensionCount )
      43             :         : VSeriesPlotter( xChartTypeModel, nDimensionCount )
      44           3 :         , m_pMainPosHelper( new BarPositionHelper() )
      45             : {
      46           3 :     PlotterBase::m_pPosHelper = m_pMainPosHelper;
      47           3 :     VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper;
      48           3 : }
      49             : 
      50           9 : CandleStickChart::~CandleStickChart()
      51             : {
      52           3 :     delete m_pMainPosHelper;
      53           6 : }
      54             : 
      55             : // MinimumAndMaximumSupplier
      56             : 
      57          48 : bool CandleStickChart::isSeparateStackingForDifferentSigns( sal_Int32 /* nDimensionIndex */ )
      58             : {
      59          48 :     return false;
      60             : }
      61             : 
      62          14 : LegendSymbolStyle CandleStickChart::getLegendSymbolStyle()
      63             : {
      64          14 :     return LegendSymbolStyle_LINE;
      65             : }
      66             : 
      67           3 : drawing::Direction3D CandleStickChart::getPreferredDiagramAspectRatio() const
      68             : {
      69           3 :     return drawing::Direction3D(-1,-1,-1);
      70             : }
      71             : 
      72          11 : void CandleStickChart::addSeries( VDataSeries* pSeries, sal_Int32 /* zSlot */, sal_Int32 xSlot, sal_Int32 ySlot )
      73             : {
      74             :     //ignore y stacking for candle stick chart
      75          11 :     VSeriesPlotter::addSeries( pSeries, 0, xSlot, ySlot );
      76          11 : }
      77             : 
      78           3 : void CandleStickChart::createShapes()
      79             : {
      80           3 :     if( m_aZSlots.begin() == m_aZSlots.end() ) //no series
      81           0 :         return;
      82             : 
      83           3 :     if( m_nDimension!=2 )
      84           0 :         return;
      85             : 
      86             :     OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"CandleStickChart is not proper initialized");
      87           3 :     if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
      88           0 :         return;
      89             : 
      90             :     //the text labels should be always on top of the other series shapes
      91             :     //therefore create an own group for the texts to move them to front
      92             :     //(because the text group is created after the series group the texts are displayed on top)
      93             : 
      94             :     uno::Reference< drawing::XShapes > xSeriesTarget(
      95           3 :         createGroupShape( m_xLogicTarget,OUString() ));
      96             :     uno::Reference< drawing::XShapes > xLossTarget(
      97             :         createGroupShape( m_xLogicTarget, ObjectIdentifier::createClassifiedIdentifier(
      98           6 :             OBJECTTYPE_DATA_STOCK_LOSS, OUString() )));
      99             :     uno::Reference< drawing::XShapes > xGainTarget(
     100             :         createGroupShape( m_xLogicTarget, ObjectIdentifier::createClassifiedIdentifier(
     101           6 :             OBJECTTYPE_DATA_STOCK_GAIN, OUString() )));
     102             :     uno::Reference< drawing::XShapes > xTextTarget(
     103           6 :         m_pShapeFactory->createGroup2D( m_xFinalTarget,OUString() ));
     104             : 
     105             :     //check necessary here that different Y axis can not be stacked in the same group? ... hm?
     106             : 
     107           3 :     bool bJapaneseStyle=true;//@todo is this the correct default?
     108           3 :     bool bShowFirst = true;//is only important if bJapaneseStyle == false
     109           6 :     tNameSequence aWhiteBox_Names, aBlackBox_Names;
     110           6 :     tAnySequence  aWhiteBox_Values, aBlackBox_Values;
     111             :     try
     112             :     {
     113           3 :         if( m_xChartTypeModelProps.is() )
     114             :         {
     115           3 :             m_xChartTypeModelProps->getPropertyValue( "ShowFirst" ) >>= bShowFirst;
     116             : 
     117           3 :             uno::Reference< beans::XPropertySet > xWhiteDayProps(0);
     118           6 :             uno::Reference< beans::XPropertySet > xBlackDayProps(0);
     119           3 :             m_xChartTypeModelProps->getPropertyValue( "Japanese" ) >>= bJapaneseStyle;
     120           3 :             m_xChartTypeModelProps->getPropertyValue( "WhiteDay" ) >>= xWhiteDayProps;
     121           3 :             m_xChartTypeModelProps->getPropertyValue( "BlackDay" ) >>= xBlackDayProps;
     122             : 
     123           6 :             tPropertyNameValueMap aWhiteBox_Map;
     124           3 :             PropertyMapper::getValueMap( aWhiteBox_Map, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), xWhiteDayProps );
     125           3 :             PropertyMapper::getMultiPropertyListsFromValueMap( aWhiteBox_Names, aWhiteBox_Values, aWhiteBox_Map );
     126             : 
     127           6 :             tPropertyNameValueMap aBlackBox_Map;
     128           3 :             PropertyMapper::getValueMap( aBlackBox_Map, PropertyMapper::getPropertyNameMapForFillAndLineProperties(), xBlackDayProps );
     129           6 :             PropertyMapper::getMultiPropertyListsFromValueMap( aBlackBox_Names, aBlackBox_Values, aBlackBox_Map );
     130             :         }
     131             :     }
     132           0 :     catch( const uno::Exception& e )
     133             :     {
     134             :         ASSERT_EXCEPTION( e );
     135             :     }
     136             : 
     137             :     //(@todo maybe different iteration for breaks in axis ?)
     138           3 :     sal_Int32 nStartIndex = 0;
     139           3 :     sal_Int32 nEndIndex = VSeriesPlotter::getPointCount();
     140           3 :     double fLogicZ = 1.5;//as defined
     141             :     //iterate through all x values per indices
     142          14 :     for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ )
     143             :     {
     144          11 :         ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator             aZSlotIter = m_aZSlots.begin();
     145          11 :         const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator  aZSlotEnd = m_aZSlots.end();
     146          22 :         for( sal_Int32 nZ=0; aZSlotIter != aZSlotEnd; ++aZSlotIter, nZ++ )
     147             :         {
     148          11 :             ::std::vector< VDataSeriesGroup >::iterator             aXSlotIter = aZSlotIter->begin();
     149          11 :             const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end();
     150             : 
     151          11 :             sal_Int32 nAttachedAxisIndex = 0;
     152          11 :             BarPositionHelper* pPosHelper = m_pMainPosHelper;
     153          11 :             if( aXSlotIter != aXSlotEnd )
     154             :             {
     155          11 :                 nAttachedAxisIndex = aXSlotIter->getAttachedAxisIndexForFirstSeries();
     156             :                 //2ND_AXIS_IN_BARS so far one can assume to have the same plotter for each z slot
     157          11 :                 pPosHelper = dynamic_cast<BarPositionHelper*>(&( this->getPlottingPositionHelper( nAttachedAxisIndex ) ) );
     158          11 :                 if(!pPosHelper)
     159           0 :                     pPosHelper = m_pMainPosHelper;
     160             :             }
     161          11 :             PlotterBase::m_pPosHelper = pPosHelper;
     162             : 
     163             :             //update/create information for current group
     164          11 :             pPosHelper->updateSeriesCount( aZSlotIter->size() );
     165             :             //iterate through all x slots in this category
     166          46 :             for( double fSlotX=0; aXSlotIter != aXSlotEnd; ++aXSlotIter, fSlotX+=1.0 )
     167             :             {
     168          35 :                 ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
     169             : 
     170          35 :                 ::std::vector< VDataSeries* >::const_iterator       aSeriesIter = pSeriesList->begin();
     171          35 :                 const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd  = pSeriesList->end();
     172             :                 //iterate through all series in this x slot
     173          70 :                 for( ; aSeriesIter != aSeriesEnd; ++aSeriesIter )
     174             :                 {
     175             :                     //collect data point information (logic coordinates, style ):
     176          35 :                     double fUnscaledX = (*aSeriesIter)->getXValue( nIndex );
     177          35 :                     if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() )
     178           0 :                         fUnscaledX = DateHelper::RasterizeDateValue( fUnscaledX, m_aNullDate, m_nTimeResolution );
     179          35 :                     if(fUnscaledX<pPosHelper->getLogicMinX() || fUnscaledX>pPosHelper->getLogicMaxX())
     180           0 :                         continue;//point not visible
     181          35 :                     double fScaledX = pPosHelper->getScaledSlotPos( fUnscaledX, fSlotX );
     182             : 
     183          35 :                     double fUnscaledY_First = (*aSeriesIter)->getY_First( nIndex );
     184          35 :                     double fUnscaledY_Last = (*aSeriesIter)->getY_Last( nIndex );
     185          35 :                     double fUnscaledY_Min = (*aSeriesIter)->getY_Min( nIndex );
     186          35 :                     double fUnscaledY_Max = (*aSeriesIter)->getY_Max( nIndex );
     187             : 
     188          35 :                     bool bBlack=false;
     189          35 :                     if(fUnscaledY_Last<=fUnscaledY_First)
     190             :                     {
     191           2 :                         std::swap(fUnscaledY_First,fUnscaledY_Last);
     192           2 :                         bBlack=true;
     193             :                     }
     194          35 :                     if(fUnscaledY_Max<fUnscaledY_Min)
     195          15 :                         std::swap(fUnscaledY_Min,fUnscaledY_Max);
     196             :                     //transformation 3) -> 4)
     197          35 :                     double fHalfScaledWidth = pPosHelper->getScaledSlotWidth()/2.0;
     198             : 
     199          35 :                     double fScaledY_First(fUnscaledY_First);
     200          35 :                     double fScaledY_Last(fUnscaledY_Last);
     201          35 :                     double fScaledY_Min(fUnscaledY_Min);
     202          35 :                     double fScaledY_Max(fUnscaledY_Max);
     203          35 :                     pPosHelper->clipLogicValues( 0,&fScaledY_First,0 );
     204          35 :                     pPosHelper->clipLogicValues( 0,&fScaledY_Last,0 );
     205          35 :                     pPosHelper->clipLogicValues( 0,&fScaledY_Min,0 );
     206          35 :                     pPosHelper->clipLogicValues( 0,&fScaledY_Max,0 );
     207          35 :                     pPosHelper->doLogicScaling( 0,&fScaledY_First,0 );
     208          35 :                     pPosHelper->doLogicScaling( 0,&fScaledY_Last,0 );
     209          35 :                     pPosHelper->doLogicScaling( 0,&fScaledY_Min,0 );
     210          35 :                     pPosHelper->doLogicScaling( 0,&fScaledY_Max,0 );
     211             : 
     212          35 :                     drawing::Position3D aPosLeftFirst( pPosHelper->transformScaledLogicToScene( fScaledX-fHalfScaledWidth, fScaledY_First ,0 ,true ) );
     213          35 :                     drawing::Position3D aPosRightLast( pPosHelper->transformScaledLogicToScene( fScaledX+fHalfScaledWidth, fScaledY_Last  ,0 ,true ) );
     214          35 :                     drawing::Position3D aPosMiddleFirst( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_First ,0 ,true ) );
     215          35 :                     drawing::Position3D aPosMiddleLast( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Last  ,0 ,true ) );
     216          35 :                     drawing::Position3D aPosMiddleMinimum( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Min ,0 ,true ) );
     217          35 :                     drawing::Position3D aPosMiddleMaximum( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Max ,0 ,true ) );
     218             : 
     219          35 :                     uno::Reference< drawing::XShapes > xLossGainTarget( xGainTarget );
     220          35 :                     if(bBlack)
     221           2 :                         xLossGainTarget = xLossTarget;
     222             : 
     223          70 :                     uno::Reference< beans::XPropertySet > xPointProp( (*aSeriesIter)->getPropertiesOfPoint( nIndex ));
     224          70 :                     uno::Reference< drawing::XShapes > xPointGroupShape_Shapes(0);
     225             :                     {
     226          35 :                         OUString aPointCID = ObjectIdentifier::createPointCID( (*aSeriesIter)->getPointCID_Stub(), nIndex );
     227          70 :                         uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes( getSeriesGroupShape(*aSeriesIter, xSeriesTarget) );
     228          70 :                         xPointGroupShape_Shapes = createGroupShape(xSeriesGroupShape_Shapes,aPointCID);
     229             :                     }
     230             : 
     231             :                     //create min-max line
     232          35 :                     if( isValidPosition(aPosMiddleMinimum) && isValidPosition(aPosMiddleMaximum) )
     233             :                     {
     234          29 :                         drawing::PolyPolygonShape3D aPoly;
     235          29 :                         sal_Int32 nLineIndex =0;
     236          29 :                         AddPointToPoly( aPoly, aPosMiddleMinimum, nLineIndex);
     237          29 :                         AddPointToPoly( aPoly, aPosMiddleMaximum, nLineIndex);
     238             : 
     239             :                         uno::Reference< drawing::XShape > xShape =
     240             :                             m_pShapeFactory->createLine2D( xPointGroupShape_Shapes,
     241          58 :                                     PolyToPointSequence(aPoly), NULL);
     242          58 :                         this->setMappedProperties( xShape, xPointProp, PropertyMapper::getPropertyNameMapForLineSeriesProperties() );
     243             :                     }
     244             : 
     245             :                     //create first-last shape
     246          35 :                     if(bJapaneseStyle && isValidPosition(aPosLeftFirst) && isValidPosition(aPosRightLast) )
     247             :                     {
     248           5 :                         drawing::Direction3D aDiff = aPosRightLast-aPosLeftFirst;
     249           5 :                         awt::Size aAWTSize( Direction3DToAWTSize( aDiff ));
     250             :                         // workaround for bug in drawing: if height is 0 the box gets infinitely large
     251           5 :                         if( aAWTSize.Height == 0 )
     252           0 :                             aAWTSize.Height = 1;
     253             : 
     254           5 :                         tNameSequence aNames;
     255          10 :                         tAnySequence aValues;
     256             : 
     257             :                         uno::Reference< drawing::XShape > xShape =
     258             :                             m_pShapeFactory->createRectangle( xLossGainTarget,
     259             :                                     aAWTSize, Position3DToAWTPoint( aPosLeftFirst ),
     260          10 :                                     aNames, aValues);
     261             : 
     262          10 :                         uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY );
     263           5 :                         if(xProp.is())
     264             :                         {
     265           5 :                             if(bBlack)
     266           2 :                                 PropertyMapper::setMultiProperties( aBlackBox_Names, aBlackBox_Values, xProp );
     267             :                             else
     268           3 :                                 PropertyMapper::setMultiProperties( aWhiteBox_Names, aWhiteBox_Values, xProp );
     269           5 :                         }
     270             :                     }
     271             :                     else
     272             :                     {
     273          30 :                         drawing::PolyPolygonShape3D aPoly;
     274             : 
     275          30 :                         sal_Int32 nLineIndex = 0;
     276          30 :                         if( bShowFirst &&  pPosHelper->isLogicVisible( fUnscaledX, fUnscaledY_First ,fLogicZ )
     277          30 :                             && isValidPosition(aPosLeftFirst) && isValidPosition(aPosMiddleFirst) )
     278             :                         {
     279           0 :                             AddPointToPoly( aPoly, aPosLeftFirst, nLineIndex );
     280           0 :                             AddPointToPoly( aPoly, aPosMiddleFirst, nLineIndex++ );
     281             :                         }
     282          60 :                         if( pPosHelper->isLogicVisible( fUnscaledX, fUnscaledY_Last ,fLogicZ )
     283          30 :                             && isValidPosition(aPosMiddleLast) && isValidPosition(aPosRightLast) )
     284             :                         {
     285          24 :                             AddPointToPoly( aPoly, aPosMiddleLast, nLineIndex );
     286          24 :                             AddPointToPoly( aPoly, aPosRightLast, nLineIndex );
     287             :                         }
     288             : 
     289          30 :                         if( aPoly.SequenceX.getLength() )
     290             :                         {
     291             :                             uno::Reference< drawing::XShape > xShape =
     292             :                                 m_pShapeFactory->createLine2D( xPointGroupShape_Shapes,
     293          24 :                                         PolyToPointSequence(aPoly), NULL );
     294          48 :                             uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY );
     295          24 :                             if(xProp.is())
     296             :                             {
     297          24 :                                 this->setMappedProperties( xShape, xPointProp, PropertyMapper::getPropertyNameMapForLineSeriesProperties() );
     298          24 :                             }
     299          30 :                         }
     300             :                     }
     301             : 
     302             :                     //create data point label
     303          35 :                     if( (**aSeriesIter).getDataPointLabelIfLabel(nIndex) )
     304             :                     {
     305           0 :                         if(isValidPosition(aPosMiddleFirst))
     306           0 :                             this->createDataLabel( xTextTarget, **aSeriesIter, nIndex
     307           0 :                                         , fUnscaledY_First, 1.0, Position3DToAWTPoint(aPosMiddleFirst), LABEL_ALIGN_LEFT_BOTTOM );
     308           0 :                         if(isValidPosition(aPosMiddleLast))
     309           0 :                             this->createDataLabel( xTextTarget, **aSeriesIter, nIndex
     310           0 :                                         , fUnscaledY_Last, 1.0, Position3DToAWTPoint(aPosMiddleLast), LABEL_ALIGN_RIGHT_TOP );
     311           0 :                         if(isValidPosition(aPosMiddleMinimum))
     312           0 :                             this->createDataLabel( xTextTarget, **aSeriesIter, nIndex
     313           0 :                                         , fUnscaledY_Min, 1.0, Position3DToAWTPoint(aPosMiddleMinimum), LABEL_ALIGN_BOTTOM );
     314           0 :                         if(isValidPosition(aPosMiddleMaximum))
     315           0 :                             this->createDataLabel( xTextTarget, **aSeriesIter, nIndex
     316           0 :                                         , fUnscaledY_Max, 1.0, Position3DToAWTPoint(aPosMiddleMaximum), LABEL_ALIGN_TOP );
     317             :                     }
     318          35 :                 }//next series in x slot (next y slot)
     319             :             }//next x slot
     320             :         }//next z slot
     321           3 :     }//next category
     322             :     /* @todo remove series shapes if empty
     323             :     //remove and delete point-group-shape if empty
     324             :     if(!xSeriesGroupShape_Shapes->getCount())
     325             :     {
     326             :         (*aSeriesIter)->m_xShape.set(NULL);
     327             :         m_xLogicTarget->remove(xSeriesGroupShape_Shape);
     328             :     }
     329             :     */
     330             : 
     331             :     //remove and delete series-group-shape if empty
     332             : 
     333             :     //... todo
     334             : }
     335             : 
     336             : } //namespace chart
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10