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

Generated by: LCOV version 1.10