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