LCOV - code coverage report
Current view: top level - oox/source/drawingml/chart - typegroupconverter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 252 0.0 %
Date: 2014-04-14 Functions: 0 28 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             : #include "oox/drawingml/chart/typegroupconverter.hxx"
      21             : 
      22             : #include <com/sun/star/chart/DataLabelPlacement.hpp>
      23             : #include <com/sun/star/chart2/CartesianCoordinateSystem2d.hpp>
      24             : #include <com/sun/star/chart2/CartesianCoordinateSystem3d.hpp>
      25             : #include <com/sun/star/chart2/PolarCoordinateSystem2d.hpp>
      26             : #include <com/sun/star/chart2/PolarCoordinateSystem3d.hpp>
      27             : #include <com/sun/star/chart2/CurveStyle.hpp>
      28             : #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
      29             : #include <com/sun/star/chart2/StackingDirection.hpp>
      30             : #include <com/sun/star/chart2/Symbol.hpp>
      31             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      32             : #include <com/sun/star/chart2/XCoordinateSystem.hpp>
      33             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      34             : #include <com/sun/star/chart2/data/XDataSink.hpp>
      35             : #include <com/sun/star/drawing/LineStyle.hpp>
      36             : #include "oox/drawingml/lineproperties.hxx"
      37             : #include "oox/drawingml/chart/seriesconverter.hxx"
      38             : #include "oox/drawingml/chart/typegroupmodel.hxx"
      39             : #include "oox/helper/containerhelper.hxx"
      40             : 
      41             : namespace oox {
      42             : namespace drawingml {
      43             : namespace chart {
      44             : 
      45             : 
      46             : 
      47             : using namespace ::com::sun::star::beans;
      48             : using namespace ::com::sun::star::chart2;
      49             : using namespace ::com::sun::star::chart2::data;
      50             : using namespace ::com::sun::star::uno;
      51             : 
      52             : 
      53             : 
      54             : namespace {
      55             : 
      56             : // chart type service names
      57             : const sal_Char SERVICE_CHART2_AREA[]      = "com.sun.star.chart2.AreaChartType";
      58             : const sal_Char SERVICE_CHART2_CANDLE[]    = "com.sun.star.chart2.CandleStickChartType";
      59             : const sal_Char SERVICE_CHART2_COLUMN[]    = "com.sun.star.chart2.ColumnChartType";
      60             : const sal_Char SERVICE_CHART2_LINE[]      = "com.sun.star.chart2.LineChartType";
      61             : const sal_Char SERVICE_CHART2_NET[]       = "com.sun.star.chart2.NetChartType";
      62             : const sal_Char SERVICE_CHART2_FILLEDNET[] = "com.sun.star.chart2.FilledNetChartType";
      63             : const sal_Char SERVICE_CHART2_PIE[]       = "com.sun.star.chart2.PieChartType";
      64             : const sal_Char SERVICE_CHART2_SCATTER[]   = "com.sun.star.chart2.ScatterChartType";
      65             : const sal_Char SERVICE_CHART2_BUBBLE[]    = "com.sun.star.chart2.BubbleChartType";
      66             : const sal_Char SERVICE_CHART2_SURFACE[]   = "com.sun.star.chart2.ColumnChartType";    // Todo
      67             : 
      68             : namespace csscd = ::com::sun::star::chart::DataLabelPlacement;
      69             : 
      70             : static const TypeGroupInfo spTypeInfos[] =
      71             : {
      72             :     // type-id          type-category         service                   varied-point-color   default label pos     comb2d supp3d polar  area2d 1stvis xcateg swap   stack  revers betw   picopt
      73             :     { TYPEID_BAR,       TYPECATEGORY_BAR,     SERVICE_CHART2_COLUMN,    VARPOINTMODE_SINGLE, csscd::OUTSIDE,       true,  true,  false, true,  false, true,  false, true,  false, true,  true  },
      74             :     { TYPEID_HORBAR,    TYPECATEGORY_BAR,     SERVICE_CHART2_COLUMN,    VARPOINTMODE_SINGLE, csscd::OUTSIDE,       false, true,  false, true,  false, true,  true,  true,  false, true,  true  },
      75             :     { TYPEID_LINE,      TYPECATEGORY_LINE,    SERVICE_CHART2_LINE,      VARPOINTMODE_SINGLE, csscd::RIGHT,         true,  true,  false, false, false, true,  false, true,  false, true,  false },
      76             :     { TYPEID_AREA,      TYPECATEGORY_LINE,    SERVICE_CHART2_AREA,      VARPOINTMODE_NONE,   csscd::CENTER,        true,  true,  false, true,  false, true,  false, true,  true,  false, false },
      77             :     { TYPEID_STOCK,     TYPECATEGORY_LINE,    SERVICE_CHART2_CANDLE,    VARPOINTMODE_NONE,   csscd::RIGHT,         true,  false, false, false, false, true,  false, true,  false, true,  false },
      78             :     { TYPEID_RADARLINE, TYPECATEGORY_RADAR,   SERVICE_CHART2_NET,       VARPOINTMODE_SINGLE, csscd::TOP,           false, false, true,  false, false, true,  false, false, false, false, false },
      79             :     { TYPEID_RADARAREA, TYPECATEGORY_RADAR,   SERVICE_CHART2_FILLEDNET, VARPOINTMODE_NONE,   csscd::TOP,           false, false, true,  true,  false, true,  false, false, true,  false, false },
      80             :     { TYPEID_PIE,       TYPECATEGORY_PIE,     SERVICE_CHART2_PIE,       VARPOINTMODE_MULTI,  csscd::AVOID_OVERLAP, false, true,  true,  true,  true,  true,  false, false, false, false, false },
      81             :     { TYPEID_DOUGHNUT,  TYPECATEGORY_PIE,     SERVICE_CHART2_PIE,       VARPOINTMODE_MULTI,  csscd::AVOID_OVERLAP, false, true,  true,  true,  false, true,  false, false, false, false, false },
      82             :     { TYPEID_OFPIE,     TYPECATEGORY_PIE,     SERVICE_CHART2_PIE,       VARPOINTMODE_MULTI,  csscd::AVOID_OVERLAP, false, true,  true,  true,  true,  true,  false, false, false, false, false },
      83             :     { TYPEID_SCATTER,   TYPECATEGORY_SCATTER, SERVICE_CHART2_SCATTER,   VARPOINTMODE_SINGLE, csscd::RIGHT,         true,  true,  false, false, false, false, false, false, false, false, false },
      84             :     { TYPEID_BUBBLE,    TYPECATEGORY_SCATTER, SERVICE_CHART2_BUBBLE,    VARPOINTMODE_SINGLE, csscd::RIGHT,         false, false, false, true,  false, false, false, false, false, false, false },
      85             :     { TYPEID_SURFACE,   TYPECATEGORY_SURFACE, SERVICE_CHART2_SURFACE,   VARPOINTMODE_NONE,   csscd::RIGHT,         false, true,  false, true,  false, true,  false, false, false, false, false }
      86             : };
      87             : 
      88             : static const TypeGroupInfo saUnknownTypeInfo =
      89             :     { TYPEID_UNKNOWN,   TYPECATEGORY_BAR,     SERVICE_CHART2_COLUMN,  VARPOINTMODE_SINGLE, csscd::OUTSIDE,       true,  true,  false, true,  false, true,  false, true,  false, true,  true  };
      90             : 
      91           0 : const TypeGroupInfo& lclGetTypeInfoFromTypeId( TypeId eTypeId )
      92             : {
      93           0 :     const TypeGroupInfo* pEnd = STATIC_ARRAY_END( spTypeInfos );
      94           0 :     for( const TypeGroupInfo* pIt = spTypeInfos; pIt != pEnd; ++pIt )
      95           0 :         if( pIt->meTypeId == eTypeId )
      96           0 :             return *pIt;
      97             :     OSL_ENSURE( eTypeId == TYPEID_UNKNOWN, "lclGetTypeInfoFromTypeId - unexpected chart type identifier" );
      98           0 :     return saUnknownTypeInfo;
      99             : }
     100             : 
     101             : } // namespace
     102             : 
     103             : 
     104             : 
     105           0 : UpDownBarsConverter::UpDownBarsConverter( const ConverterRoot& rParent, UpDownBarsModel& rModel ) :
     106           0 :     ConverterBase< UpDownBarsModel >( rParent, rModel )
     107             : {
     108           0 : }
     109             : 
     110           0 : UpDownBarsConverter::~UpDownBarsConverter()
     111             : {
     112           0 : }
     113             : 
     114           0 : void UpDownBarsConverter::convertFromModel( const Reference< XChartType >& rxChartType )
     115             : {
     116           0 :     PropertySet aTypeProp( rxChartType );
     117             : 
     118             :     // upbar format
     119           0 :     Reference< XPropertySet > xWhitePropSet;
     120           0 :     if( aTypeProp.getProperty( xWhitePropSet, PROP_WhiteDay ) )
     121             :     {
     122           0 :         PropertySet aPropSet( xWhitePropSet );
     123           0 :         getFormatter().convertFrameFormatting( aPropSet, mrModel.mxUpBars, OBJECTTYPE_UPBAR );
     124             :     }
     125             : 
     126             :     // downbar format
     127           0 :     Reference< XPropertySet > xBlackPropSet;
     128           0 :     if( aTypeProp.getProperty( xBlackPropSet, PROP_BlackDay ) )
     129             :     {
     130           0 :         PropertySet aPropSet( xBlackPropSet );
     131           0 :         getFormatter().convertFrameFormatting( aPropSet, mrModel.mxDownBars, OBJECTTYPE_DOWNBAR );
     132           0 :     }
     133           0 : }
     134             : 
     135             : 
     136             : 
     137           0 : TypeGroupConverter::TypeGroupConverter( const ConverterRoot& rParent, TypeGroupModel& rModel ) :
     138             :     ConverterBase< TypeGroupModel >( rParent, rModel ),
     139           0 :     mb3dChart( false )
     140             : {
     141           0 :     TypeId eTypeId = TYPEID_UNKNOWN;
     142           0 :     switch( mrModel.mnTypeId )
     143             :     {
     144             : #define ENSURE_AXESCOUNT( min, max ) OSL_ENSURE( (min <= (int)mrModel.maAxisIds.size()) && ((int)mrModel.maAxisIds.size() <= max), "TypeGroupConverter::TypeGroupConverter - invalid axes count" )
     145           0 :         case C_TOKEN( area3DChart ):    ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_AREA;      mb3dChart = true;   break;
     146           0 :         case C_TOKEN( areaChart ):      ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_AREA;      mb3dChart = false;  break;
     147           0 :         case C_TOKEN( bar3DChart ):     ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_BAR;       mb3dChart = true;   break;
     148           0 :         case C_TOKEN( barChart ):       ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_BAR;       mb3dChart = false;  break;
     149           0 :         case C_TOKEN( bubbleChart ):    ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_BUBBLE;    mb3dChart = false;  break;
     150           0 :         case C_TOKEN( doughnutChart ):  ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_DOUGHNUT;  mb3dChart = false;  break;
     151           0 :         case C_TOKEN( line3DChart ):    ENSURE_AXESCOUNT( 3, 3 ); eTypeId = TYPEID_LINE;      mb3dChart = true;   break;
     152           0 :         case C_TOKEN( lineChart ):      ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_LINE;      mb3dChart = false;  break;
     153           0 :         case C_TOKEN( ofPieChart ):     ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_OFPIE;     mb3dChart = false;  break;
     154           0 :         case C_TOKEN( pie3DChart ):     ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_PIE;       mb3dChart = true;   break;
     155           0 :         case C_TOKEN( pieChart ):       ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_PIE;       mb3dChart = false;  break;
     156           0 :         case C_TOKEN( radarChart ):     ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_RADARLINE; mb3dChart = false;  break;
     157           0 :         case C_TOKEN( scatterChart ):   ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_SCATTER;   mb3dChart = false;  break;
     158           0 :         case C_TOKEN( stockChart ):     ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_STOCK;     mb3dChart = false;  break;
     159           0 :         case C_TOKEN( surface3DChart ): ENSURE_AXESCOUNT( 3, 3 ); eTypeId = TYPEID_SURFACE;   mb3dChart = true;   break;
     160           0 :         case C_TOKEN( surfaceChart ):   ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_SURFACE;   mb3dChart = true;   break;    // 3D bar chart from all surface charts
     161             :         default:    OSL_FAIL( "TypeGroupConverter::TypeGroupConverter - unknown chart type" );
     162             : #undef ENSURE_AXESCOUNT
     163             :     }
     164             : 
     165             :     // special handling for some chart types
     166           0 :     switch( eTypeId )
     167             :     {
     168             :         case TYPEID_BAR:
     169           0 :             if( mrModel.mnBarDir == XML_bar )
     170           0 :                 eTypeId = TYPEID_HORBAR;
     171           0 :         break;
     172             :         case TYPEID_RADARLINE:
     173           0 :             if( mrModel.mnRadarStyle == XML_filled )
     174           0 :                 eTypeId = TYPEID_RADARAREA;
     175           0 :         break;
     176             :         case TYPEID_SURFACE:
     177             :             // create a deep 3D bar chart from surface charts
     178           0 :             mrModel.mnGrouping = XML_standard;
     179           0 :         break;
     180             :         default:;
     181             :     }
     182             : 
     183             :     // set the chart type info struct for the current chart type
     184           0 :     maTypeInfo = lclGetTypeInfoFromTypeId( eTypeId );
     185           0 : }
     186             : 
     187           0 : TypeGroupConverter::~TypeGroupConverter()
     188             : {
     189           0 : }
     190             : 
     191           0 : bool TypeGroupConverter::isStacked() const
     192             : {
     193           0 :     return maTypeInfo.mbSupportsStacking && (mrModel.mnGrouping == XML_stacked);
     194             : }
     195             : 
     196           0 : bool TypeGroupConverter::isPercent() const
     197             : {
     198           0 :     return maTypeInfo.mbSupportsStacking && (mrModel.mnGrouping == XML_percentStacked);
     199             : }
     200             : 
     201           0 : bool TypeGroupConverter::is3dChart() const
     202             : {
     203           0 :     return mb3dChart;
     204             : }
     205             : 
     206           0 : bool TypeGroupConverter::isWall3dChart() const
     207             : {
     208           0 :     return mb3dChart && (maTypeInfo.meTypeCategory != TYPECATEGORY_PIE);
     209             : }
     210             : 
     211           0 : bool TypeGroupConverter::isDeep3dChart() const
     212             : {
     213           0 :     return isWall3dChart() && (mrModel.mnGrouping == XML_standard);
     214             : }
     215             : 
     216           0 : bool TypeGroupConverter::isSeriesFrameFormat() const
     217             : {
     218           0 :     return mb3dChart || maTypeInfo.mbSeriesIsFrame2d;
     219             : }
     220             : 
     221           0 : ObjectType TypeGroupConverter::getSeriesObjectType() const
     222             : {
     223             :     return mb3dChart ? OBJECTTYPE_FILLEDSERIES3D :
     224           0 :         (maTypeInfo.mbSeriesIsFrame2d ? OBJECTTYPE_FILLEDSERIES2D : OBJECTTYPE_LINEARSERIES2D);
     225             : }
     226             : 
     227           0 : bool TypeGroupConverter::isReverseSeries() const
     228             : {
     229           0 :     return maTypeInfo.mbReverseSeries && !mb3dChart && !isStacked() && !isPercent();
     230             : }
     231             : 
     232           0 : OUString TypeGroupConverter::getSingleSeriesTitle() const
     233             : {
     234           0 :     OUString aSeriesTitle;
     235           0 :     if( !mrModel.maSeries.empty() && (maTypeInfo.mbSingleSeriesVis || (mrModel.maSeries.size() == 1)) )
     236           0 :         if( const TextModel* pText = mrModel.maSeries.front()->mxText.get() )
     237           0 :             if( const DataSequenceModel* pDataSeq = pText->mxDataSeq.get() )
     238           0 :                 if( !pDataSeq->maData.empty() )
     239           0 :                     pDataSeq->maData.begin()->second >>= aSeriesTitle;
     240           0 :     return aSeriesTitle;
     241             : }
     242             : 
     243           0 : Reference< XCoordinateSystem > TypeGroupConverter::createCoordinateSystem()
     244             : {
     245             :     // create the coordinate system object
     246           0 :     Reference< css::uno::XComponentContext > xContext = getComponentContext();
     247           0 :     Reference< XCoordinateSystem > xCoordSystem;
     248           0 :     if( maTypeInfo.mbPolarCoordSystem )
     249             :     {
     250           0 :         if( mb3dChart )
     251           0 :             xCoordSystem = css::chart2::PolarCoordinateSystem3d::create(xContext);
     252             :         else
     253           0 :             xCoordSystem = css::chart2::PolarCoordinateSystem2d::create(xContext);
     254             :     }
     255             :     else
     256             :     {
     257           0 :         if( mb3dChart )
     258           0 :             xCoordSystem = css::chart2::CartesianCoordinateSystem3d::create(xContext);
     259             :         else
     260           0 :             xCoordSystem = css::chart2::CartesianCoordinateSystem2d::create(xContext);
     261             :     }
     262             : 
     263             :     // swap X and Y axis
     264           0 :     if( maTypeInfo.mbSwappedAxesSet )
     265             :     {
     266           0 :         PropertySet aPropSet( xCoordSystem );
     267           0 :         aPropSet.setProperty( PROP_SwapXAndYAxis, true );
     268             :     }
     269             : 
     270           0 :     return xCoordSystem;
     271             : }
     272             : 
     273           0 : Reference< XLabeledDataSequence > TypeGroupConverter::createCategorySequence()
     274             : {
     275           0 :     sal_Int32 nMaxValues = 0;
     276           0 :     Reference< XLabeledDataSequence > xLabeledSeq;
     277             :     /*  Find first existing category sequence. The bahaviour of Excel 2007 is
     278             :         different to Excel 2003, which always used the category sequence of the
     279             :         first series, even if it was empty. */
     280           0 :     for( TypeGroupModel::SeriesVector::iterator aIt = mrModel.maSeries.begin(), aEnd = mrModel.maSeries.end(); !xLabeledSeq.is() && (aIt != aEnd); ++aIt )
     281             :     {
     282           0 :         if( (*aIt)->maSources.has( SeriesModel::CATEGORIES ) )
     283             :         {
     284           0 :             SeriesConverter aSeriesConv( *this, **aIt );
     285           0 :             xLabeledSeq = aSeriesConv.createCategorySequence( "categories" );
     286             :         }
     287           0 :         else if( nMaxValues <= 0 && (*aIt)->maSources.has( SeriesModel::VALUES ) )
     288             :         {
     289           0 :             DataSourceModel *pValues = (*aIt)->maSources.get( SeriesModel::VALUES ).get();
     290           0 :             if( pValues->mxDataSeq.is() )
     291           0 :                 nMaxValues = pValues->mxDataSeq.get()->maData.size();
     292             :         }
     293             :     }
     294             :     /* n#839727 Create Category Sequence when none are found */
     295           0 :     if( !xLabeledSeq.is() && mrModel.maSeries.size() > 0 ) {
     296           0 :         if( nMaxValues < 0 )
     297           0 :             nMaxValues = 2;
     298           0 :         SeriesModel &aModel = mrModel.maSeries.create();
     299           0 :         DataSourceModel &aSrc = aModel.maSources.create( SeriesModel::CATEGORIES );
     300           0 :         DataSequenceModel &aSeq = aSrc.mxDataSeq.create();
     301           0 :         for( sal_Int32 i = 0; i < nMaxValues; i++ )
     302           0 :             aSeq.maData[ i ] <<= OUString::number( i + 1 );
     303           0 :         SeriesConverter aSeriesConv( *this,  aModel );
     304           0 :         xLabeledSeq = aSeriesConv.createCategorySequence( "categories" );
     305             :     }
     306           0 :     return xLabeledSeq;
     307             : }
     308             : 
     309           0 : void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagram,
     310             :         const Reference< XCoordinateSystem >& rxCoordSystem,
     311             :         sal_Int32 nAxesSetIdx, bool bSupportsVaryColorsByPoint )
     312             : {
     313             :     try
     314             :     {
     315             :         // create the chart type object
     316           0 :         OUString aService = OUString::createFromAscii( maTypeInfo.mpcServiceName );
     317           0 :         Reference< XChartType > xChartType( createInstance( aService ), UNO_QUERY_THROW );
     318             : 
     319             :         // additional properties
     320           0 :         PropertySet aDiaProp( rxDiagram );
     321           0 :         PropertySet aTypeProp( xChartType );
     322           0 :         switch( maTypeInfo.meTypeCategory )
     323             :         {
     324             :             case TYPECATEGORY_BAR:
     325             :             {
     326           0 :                 Sequence< sal_Int32 > aInt32Seq( 2 );
     327           0 :                 aInt32Seq[ 0 ] = aInt32Seq[ 1 ] = mrModel.mnOverlap;
     328           0 :                 aTypeProp.setProperty( PROP_OverlapSequence, aInt32Seq );
     329           0 :                 aInt32Seq[ 0 ] = aInt32Seq[ 1 ] = mrModel.mnGapWidth;
     330           0 :                 aTypeProp.setProperty( PROP_GapwidthSequence, aInt32Seq );
     331             :             }
     332           0 :             break;
     333             :             case TYPECATEGORY_PIE:
     334             :             {
     335           0 :                 aTypeProp.setProperty( PROP_UseRings, maTypeInfo.meTypeId == TYPEID_DOUGHNUT );
     336             :                 /*  #i85166# starting angle of first pie slice. 3D pie charts
     337             :                     use Y rotation setting in view3D element. Of-pie charts do
     338             :                     not support pie rotation. */
     339           0 :                 if( !is3dChart() && (maTypeInfo.meTypeId != TYPEID_OFPIE) )
     340           0 :                     convertPieRotation( aDiaProp, mrModel.mnFirstAngle );
     341             :             }
     342           0 :             break;
     343             :             default:;
     344             :         }
     345             : 
     346             :         // create converter objects for all series models
     347             :         typedef RefVector< SeriesConverter > SeriesConvVector;
     348           0 :         SeriesConvVector aSeries;
     349           0 :         for( TypeGroupModel::SeriesVector::iterator aIt = mrModel.maSeries.begin(), aEnd = mrModel.maSeries.end(); aIt != aEnd; ++aIt )
     350           0 :             aSeries.push_back( SeriesConvVector::value_type( new SeriesConverter( *this, **aIt ) ) );
     351             : 
     352             :         // reverse series order for some unstacked 2D chart types
     353           0 :         if( isReverseSeries() )
     354           0 :             ::std::reverse( aSeries.begin(), aSeries.end() );
     355             : 
     356             :         // decide whether to use varying colors for each data point
     357           0 :         bool bVaryColorsByPoint = bSupportsVaryColorsByPoint && mrModel.mbVaryColors;
     358           0 :         switch( maTypeInfo.meVarPointMode )
     359             :         {
     360           0 :             case VARPOINTMODE_NONE:     bVaryColorsByPoint = false;                             break;
     361           0 :             case VARPOINTMODE_SINGLE:   bVaryColorsByPoint &= (mrModel.maSeries.size() == 1);   break;
     362           0 :             case VARPOINTMODE_MULTI:                                                            break;
     363             :         }
     364             : 
     365             :         /*  Stock chart needs special processing. Create one 'big' series with
     366             :             data sequences of different roles. */
     367           0 :         if( maTypeInfo.meTypeId == TYPEID_STOCK )
     368             :         {
     369             :             // create the data series object
     370           0 :             Reference< XDataSeries > xDataSeries( createInstance( "com.sun.star.chart2.DataSeries" ), UNO_QUERY );
     371           0 :             Reference< XDataSink > xDataSink( xDataSeries, UNO_QUERY );
     372           0 :             if( xDataSink.is() )
     373             :             {
     374             :                 // create a list of data sequences from all series
     375           0 :                 ::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec;
     376             :                 OSL_ENSURE( aSeries.size() >= 3, "TypeGroupConverter::convertFromModel - too few stock chart series" );
     377           0 :                 int nRoleIdx = (aSeries.size() == 3) ? 1 : 0;
     378           0 :                 for( SeriesConvVector::iterator aIt = aSeries.begin(), aEnd = aSeries.end(); (nRoleIdx < 4) && (aIt != aEnd); ++nRoleIdx, ++aIt )
     379             :                 {
     380             :                     // create a data sequence with a specific role
     381           0 :                     OUString aRole;
     382           0 :                     switch( nRoleIdx )
     383             :                     {
     384           0 :                         case 0: aRole = "values-first";  break;
     385           0 :                         case 1: aRole = "values-max";    break;
     386           0 :                         case 2: aRole = "values-min";    break;
     387           0 :                         case 3: aRole = "values-last";   break;
     388             :                     }
     389           0 :                     Reference< XLabeledDataSequence > xDataSeq = (*aIt)->createValueSequence( aRole );
     390           0 :                     if( xDataSeq.is() )
     391           0 :                         aLabeledSeqVec.push_back( xDataSeq );
     392           0 :                 }
     393             : 
     394             :                 // attach labeled data sequences to series and insert series into chart type
     395           0 :                 xDataSink->setData( ContainerHelper::vectorToSequence( aLabeledSeqVec ) );
     396             : 
     397             :                 // formatting of high/low lines
     398           0 :                 aTypeProp.setProperty( PROP_ShowHighLow, true );
     399           0 :                 PropertySet aSeriesProp( xDataSeries );
     400           0 :                 if( mrModel.mxHiLowLines.is() )
     401           0 :                     getFormatter().convertFrameFormatting( aSeriesProp, mrModel.mxHiLowLines, OBJECTTYPE_HILOLINE );
     402             :                 else
     403             :                     // hi/low-lines cannot be switched off via "ShowHighLow" property (?)
     404           0 :                     aSeriesProp.setProperty( PROP_LineStyle, ::com::sun::star::drawing::LineStyle_NONE );
     405             : 
     406             :                 // formatting of up/down bars
     407           0 :                 bool bUpDownBars = mrModel.mxUpDownBars.is();
     408           0 :                 aTypeProp.setProperty( PROP_Japanese, bUpDownBars );
     409           0 :                 aTypeProp.setProperty( PROP_ShowFirst, bUpDownBars );
     410           0 :                 if( bUpDownBars )
     411             :                 {
     412           0 :                     UpDownBarsConverter aUpDownConv( *this, *mrModel.mxUpDownBars );
     413           0 :                     aUpDownConv.convertFromModel( xChartType );
     414             :                 }
     415             : 
     416             :                 // insert the series into the chart type object
     417           0 :                 insertDataSeries( xChartType, xDataSeries, nAxesSetIdx );
     418           0 :             }
     419             :         }
     420             :         else
     421             :         {
     422           0 :             for( SeriesConvVector::iterator aIt = aSeries.begin(), aEnd = aSeries.end(); aIt != aEnd; ++aIt )
     423             :             {
     424           0 :                 SeriesConverter& rSeriesConv = **aIt;
     425           0 :                 Reference< XDataSeries > xDataSeries = rSeriesConv.createDataSeries( *this, bVaryColorsByPoint );
     426           0 :                 insertDataSeries( xChartType, xDataSeries, nAxesSetIdx );
     427             : 
     428             :                 /*  Excel does not use the value of the c:smooth element of the
     429             :                     chart type to set a default line smoothing for the data
     430             :                     series. Line smoothing is always controlled by the c:smooth
     431             :                     element of the respective data series. If the element in the
     432             :                     data series is missing, line smoothing is off, regardless of
     433             :                     the c:smooth element of the chart type. */
     434             : #if !OOX_CHART_SMOOTHED_PER_SERIES
     435           0 :                 if( rSeriesConv.getModel().mbSmooth )
     436           0 :                     convertLineSmooth( aTypeProp, true );
     437             : #endif
     438           0 :             }
     439             :         }
     440             : 
     441             :         // add chart type object to coordinate system
     442           0 :         Reference< XChartTypeContainer > xChartTypeCont( rxCoordSystem, UNO_QUERY_THROW );
     443           0 :         xChartTypeCont->addChartType( xChartType );
     444             : 
     445             :         // set existence of bar connector lines at diagram (only in stacked 2D bar charts)
     446           0 :         if( mrModel.mxSerLines.is() && !mb3dChart && (maTypeInfo.meTypeCategory == TYPECATEGORY_BAR) && (isStacked() || isPercent()) )
     447           0 :             aDiaProp.setProperty( PROP_ConnectBars, true );
     448             :     }
     449           0 :     catch( Exception& )
     450             :     {
     451             :         OSL_FAIL( "TypeGroupConverter::convertFromModel - cannot add chart type" );
     452             :     }
     453           0 : }
     454             : 
     455           0 : void TypeGroupConverter::convertMarker( PropertySet& rPropSet, sal_Int32 nOoxSymbol, sal_Int32 nOoxSize,
     456             :        ModelRef< Shape > xShapeProps ) const
     457             : {
     458           0 :     if( !isSeriesFrameFormat() )
     459             :     {
     460             :         namespace cssc = ::com::sun::star::chart2;
     461             : 
     462             :         // symbol style
     463           0 :         cssc::Symbol aSymbol;
     464           0 :         aSymbol.Style = cssc::SymbolStyle_STANDARD;
     465           0 :         switch( nOoxSymbol ) // compare with XclChPropSetHelper::WriteMarkerProperties in xlchart.cxx
     466             :         {
     467           0 :             case XML_auto:      aSymbol.Style = cssc::SymbolStyle_AUTO; break;
     468           0 :             case XML_none:      aSymbol.Style = cssc::SymbolStyle_NONE; break;
     469           0 :             case XML_square:    aSymbol.StandardSymbol = 0;             break;  // square
     470           0 :             case XML_diamond:   aSymbol.StandardSymbol = 1;             break;  // diamond
     471           0 :             case XML_triangle:  aSymbol.StandardSymbol = 3;             break;  // arrow up
     472           0 :             case XML_x:         aSymbol.StandardSymbol = 10;            break;  // X, legacy bow tie
     473           0 :             case XML_star:      aSymbol.StandardSymbol = 12;            break;  // asterisk, legacy sand glass
     474           0 :             case XML_dot:       aSymbol.StandardSymbol = 4;             break;  // arrow right
     475           0 :             case XML_dash:      aSymbol.StandardSymbol = 13;            break;  // horizontal bar, legacy arrow down
     476           0 :             case XML_circle:    aSymbol.StandardSymbol = 8;             break;  // circle, legacy arrow right
     477           0 :             case XML_plus:      aSymbol.StandardSymbol = 11;            break;  // plus, legacy arrow left
     478             :         }
     479             : 
     480             :         // symbol size (points in OOXML, 1/100 mm in Chart2)
     481           0 :         sal_Int32 nSize = static_cast< sal_Int32 >( nOoxSize * (2540.0 / 72.0) + 0.5 );
     482           0 :         aSymbol.Size.Width = aSymbol.Size.Height = nSize;
     483             : 
     484           0 :         if(xShapeProps.is())
     485             :         {
     486           0 :             Color aFillColor = xShapeProps->getFillProperties().maFillColor;
     487           0 :             aSymbol.FillColor = aFillColor.getColor(getFilter().getGraphicHelper());
     488             :         }
     489             : 
     490             :         // set the property
     491           0 :         rPropSet.setProperty( PROP_Symbol, aSymbol );
     492             :     }
     493           0 : }
     494             : 
     495           0 : void TypeGroupConverter::convertLineSmooth( PropertySet& rPropSet, bool bOoxSmooth ) const
     496             : {
     497           0 :     if( !isSeriesFrameFormat() && (maTypeInfo.meTypeCategory != TYPECATEGORY_RADAR) )
     498             :     {
     499             :         namespace cssc = ::com::sun::star::chart2;
     500           0 :         cssc::CurveStyle eCurveStyle = bOoxSmooth ? cssc::CurveStyle_CUBIC_SPLINES : cssc::CurveStyle_LINES;
     501           0 :         rPropSet.setProperty( PROP_CurveStyle, eCurveStyle );
     502             :     }
     503           0 : }
     504             : 
     505           0 : void TypeGroupConverter::convertBarGeometry( PropertySet& rPropSet, sal_Int32 nOoxShape ) const
     506             : {
     507           0 :     if( mb3dChart && (maTypeInfo.meTypeCategory == TYPECATEGORY_BAR) )
     508             :     {
     509             :         namespace cssc = ::com::sun::star::chart2;
     510             : 
     511           0 :         sal_Int32 nGeom3d = cssc::DataPointGeometry3D::CUBOID;
     512           0 :         switch( nOoxShape )
     513             :         {
     514           0 :             case XML_box:           nGeom3d = cssc::DataPointGeometry3D::CUBOID;    break;
     515           0 :             case XML_cone:          nGeom3d = cssc::DataPointGeometry3D::CONE;      break;
     516           0 :             case XML_coneToMax:     nGeom3d = cssc::DataPointGeometry3D::CONE;      break;
     517           0 :             case XML_cylinder:      nGeom3d = cssc::DataPointGeometry3D::CYLINDER;  break;
     518           0 :             case XML_pyramid:       nGeom3d = cssc::DataPointGeometry3D::PYRAMID;   break;
     519           0 :             case XML_pyramidToMax:  nGeom3d = cssc::DataPointGeometry3D::PYRAMID;   break;
     520             :             default:                OSL_FAIL( "TypeGroupConverter::convertBarGeometry - unknown 3D bar shape type" );
     521             :         }
     522           0 :         rPropSet.setProperty( PROP_Geometry3D, nGeom3d );
     523             :     }
     524           0 : }
     525             : 
     526           0 : void TypeGroupConverter::convertPieRotation( PropertySet& rPropSet, sal_Int32 nOoxAngle ) const
     527             : {
     528           0 :     if( maTypeInfo.meTypeCategory == TYPECATEGORY_PIE )
     529             :     {
     530             :         // map OOXML [0,360] clockwise (0deg top) to Chart2 counterclockwise (0deg left)
     531           0 :         sal_Int32 nAngle = (450 - nOoxAngle) % 360;
     532           0 :         rPropSet.setProperty( PROP_StartingAngle, nAngle );
     533             :     }
     534           0 : }
     535             : 
     536           0 : void TypeGroupConverter::convertPieExplosion( PropertySet& rPropSet, sal_Int32 nOoxExplosion ) const
     537             : {
     538           0 :     if( maTypeInfo.meTypeCategory == TYPECATEGORY_PIE )
     539             :     {
     540             :         // pie explosion restricted to 100% in Chart2, set as double in range [0,1]
     541           0 :         double fOffset = getLimitedValue< double >( nOoxExplosion / 100.0, 0.0, 1.0 );
     542           0 :         rPropSet.setProperty( PROP_Offset, fOffset );
     543             :     }
     544           0 : }
     545             : 
     546             : // private --------------------------------------------------------------------
     547             : 
     548           0 : void TypeGroupConverter::insertDataSeries( const Reference< XChartType >& rxChartType, const Reference< XDataSeries >& rxSeries, sal_Int32 nAxesSetIdx )
     549             : {
     550           0 :     if( rxSeries.is() )
     551             :     {
     552           0 :         PropertySet aSeriesProp( rxSeries );
     553             : 
     554             :         // series stacking mode
     555             :         namespace cssc = ::com::sun::star::chart2;
     556           0 :         cssc::StackingDirection eStacking = cssc::StackingDirection_NO_STACKING;
     557             :         // stacked overrides deep-3d
     558           0 :         if( isStacked() || isPercent() )
     559           0 :             eStacking = cssc::StackingDirection_Y_STACKING;
     560           0 :         else if( isDeep3dChart() )
     561           0 :             eStacking = cssc::StackingDirection_Z_STACKING;
     562           0 :         aSeriesProp.setProperty( PROP_StackingDirection, eStacking );
     563             : 
     564             :         // additional series properties
     565           0 :         aSeriesProp.setProperty( PROP_AttachedAxisIndex, nAxesSetIdx );
     566             : 
     567             :         // insert series into container
     568             :         try
     569             :         {
     570           0 :             Reference< XDataSeriesContainer > xSeriesCont( rxChartType, UNO_QUERY_THROW );
     571           0 :             xSeriesCont->addDataSeries( rxSeries );
     572             :         }
     573           0 :         catch( Exception& )
     574             :         {
     575             :             OSL_FAIL( "TypeGroupConverter::insertDataSeries - cannot add data series" );
     576           0 :         }
     577             :     }
     578           0 : }
     579             : 
     580             : 
     581             : 
     582             : } // namespace chart
     583             : } // namespace drawingml
     584           0 : } // namespace oox
     585             : 
     586             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10