1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "StockChartTypeTemplate.hxx"
21 #include "ColumnChartType.hxx"
22 #include "CandleStickChartType.hxx"
23 #include "LineChartType.hxx"
24 #include <DataSeries.hxx>
25 #include <DataSeriesHelper.hxx>
26 #include "StockDataInterpreter.hxx"
27 #include <Diagram.hxx>
28 #include <BaseCoordinateSystem.hxx>
29 #include <servicenames_charttypes.hxx>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <PropertyHelper.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/drawing/LineStyle.hpp>
34 #include <comphelper/diagnose_ex.hxx>
39 using namespace ::com::sun::star
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::com::sun::star::beans::Property
;
50 PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
,
51 PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
,
52 PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH
,
53 PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
56 void lcl_AddPropertiesToVector(
57 std::vector
< Property
> & rOutProperties
)
59 rOutProperties
.emplace_back( "Volume",
60 PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
,
61 cppu::UnoType
<bool>::get(),
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEDEFAULT
);
64 rOutProperties
.emplace_back( "Open",
65 PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
,
66 cppu::UnoType
<bool>::get(),
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEDEFAULT
);
69 rOutProperties
.emplace_back( "LowHigh",
70 PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH
,
71 cppu::UnoType
<bool>::get(),
72 beans::PropertyAttribute::BOUND
73 | beans::PropertyAttribute::MAYBEDEFAULT
);
74 rOutProperties
.emplace_back( "Japanese",
75 PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
,
76 cppu::UnoType
<bool>::get(),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::MAYBEDEFAULT
);
81 ::chart::tPropertyValueMap
& GetStaticStockChartTypeTemplateDefaults()
83 static ::chart::tPropertyValueMap aStaticDefaults
=
85 ::chart::tPropertyValueMap aTmp
;
86 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
, false );
87 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
, false );
88 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH
, true );
89 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
, false );
92 return aStaticDefaults
;
95 ::cppu::OPropertyArrayHelper
& GetStaticStockChartTypeTemplateInfoHelper()
97 static ::cppu::OPropertyArrayHelper aPropHelper
=
99 std::vector
< css::beans::Property
> aProperties
;
100 lcl_AddPropertiesToVector( aProperties
);
102 std::sort( aProperties
.begin(), aProperties
.end(),
103 ::chart::PropertyNameLess() );
105 return comphelper::containerToSequence( aProperties
);
111 uno::Reference
< beans::XPropertySetInfo
>& GetStaticStockChartTypeTemplateInfo()
113 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
114 ::cppu::OPropertySetHelper::createPropertySetInfo(GetStaticStockChartTypeTemplateInfoHelper() ) );
115 return xPropertySetInfo
;
118 } // anonymous namespace
123 StockChartTypeTemplate::StockChartTypeTemplate(
125 uno::XComponentContext
> const & xContext
,
126 const OUString
& rServiceName
,
127 StockVariant eVariant
,
128 bool bJapaneseStyle
) :
129 ChartTypeTemplate( xContext
, rServiceName
),
130 m_eStockVariant( eVariant
)
132 setFastPropertyValue_NoBroadcast(
133 PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
,
134 uno::Any( ( eVariant
== StockVariant::Open
||
135 eVariant
== StockVariant::VolumeOpen
)));
136 setFastPropertyValue_NoBroadcast(
137 PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
,
138 uno::Any( ( eVariant
== StockVariant::Volume
||
139 eVariant
== StockVariant::VolumeOpen
)));
140 setFastPropertyValue_NoBroadcast(
141 PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
,
142 uno::Any( bJapaneseStyle
));
145 StockChartTypeTemplate::~StockChartTypeTemplate()
148 // ____ OPropertySet ____
149 void StockChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
151 const tPropertyValueMap
& rStaticDefaults
= GetStaticStockChartTypeTemplateDefaults();
152 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
153 if( aFound
== rStaticDefaults
.end() )
156 rAny
= (*aFound
).second
;
159 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockChartTypeTemplate::getInfoHelper()
161 return GetStaticStockChartTypeTemplateInfoHelper();
164 // ____ XPropertySet ____
165 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
StockChartTypeTemplate::getPropertySetInfo()
167 return GetStaticStockChartTypeTemplateInfo();
170 sal_Int32
StockChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension
)
173 if( nDimension
<= 0 )
176 if( nDimension
>= 2 )
179 // one or two y-axes depending on volume
180 OSL_ASSERT( nDimension
== 1 );
181 bool bHasVolume
= false;
182 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
) >>= bHasVolume
;
183 return bHasVolume
? 2 : 1;
186 void StockChartTypeTemplate::applyStyle2(
187 const rtl::Reference
< DataSeries
>& xSeries
,
188 ::sal_Int32 nChartTypeIndex
,
189 ::sal_Int32 nSeriesIndex
,
190 ::sal_Int32 nSeriesCount
)
192 ChartTypeTemplate::applyStyle2( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
195 sal_Int32 nNewAxisIndex
= 0;
197 bool bHasVolume
= false;
198 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
) >>= bHasVolume
;
199 if( bHasVolume
&& nChartTypeIndex
!= 0 )
202 xSeries
->setPropertyValue( u
"AttachedAxisIndex"_ustr
, uno::Any( nNewAxisIndex
) );
204 if( bHasVolume
&& nChartTypeIndex
==0 )
206 //switch lines off for volume bars
207 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, u
"BorderStyle"_ustr
, uno::Any( drawing::LineStyle_NONE
) );
211 //ensure that lines are on
212 drawing::LineStyle eStyle
= drawing::LineStyle_NONE
;
213 xSeries
->getPropertyValue( u
"LineStyle"_ustr
) >>= eStyle
;
214 if( eStyle
== drawing::LineStyle_NONE
)
215 xSeries
->setPropertyValue( u
"LineStyle"_ustr
, uno::Any( drawing::LineStyle_SOLID
));
219 catch( const uno::Exception
& )
221 DBG_UNHANDLED_EXCEPTION("chart2");
225 void StockChartTypeTemplate::resetStyles2(
226 const rtl::Reference
< ::chart::Diagram
>& xDiagram
)
228 ChartTypeTemplate::resetStyles2( xDiagram
);
229 if( getDimension() == 3 )
231 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVec
=
232 xDiagram
->getDataSeries();
233 for (auto const& series
: aSeriesVec
)
235 series
->setPropertyValue( u
"AttachedAxisIndex"_ustr
, uno::Any( sal_Int32(0) ) );
239 xDiagram
->setVertical( false );
242 rtl::Reference
< ChartType
> StockChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex
)
244 rtl::Reference
< ChartType
> xCT
;
245 bool bHasVolume
= false;
246 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
) >>= bHasVolume
;
249 if( nChartTypeIndex
== 0 )
250 xCT
= new ColumnChartType();
251 else if( nChartTypeIndex
== 1 )
252 xCT
= new CandleStickChartType();
254 xCT
= new LineChartType();
258 if( nChartTypeIndex
== 0 )
259 xCT
= new CandleStickChartType();
261 xCT
= new LineChartType();
266 void StockChartTypeTemplate::createChartTypes(
267 const std::vector
< std::vector
< rtl::Reference
< DataSeries
> > > & aSeriesSeq
,
268 const std::vector
< rtl::Reference
< BaseCoordinateSystem
> > & rCoordSys
,
269 const std::vector
< rtl::Reference
< ChartType
> >& /* aOldChartTypesSeq */ )
271 if( rCoordSys
.empty() )
276 bool bHasVolume
= false;
277 bool bShowFirst
= false;
278 bool bJapaneseStyle
= false;
279 bool bShowHighLow
= true;
281 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
) >>= bHasVolume
;
282 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
) >>= bShowFirst
;
283 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
) >>= bJapaneseStyle
;
284 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH
) >>= bShowHighLow
;
286 std::size_t nSeriesIndex
= 0;
288 std::vector
< rtl::Reference
< ChartType
> > aChartTypeVec
;
293 rtl::Reference
< ChartType
> xCT
= new ColumnChartType();
294 aChartTypeVec
.push_back( xCT
);
296 if( aSeriesSeq
.size() > nSeriesIndex
&&
297 !aSeriesSeq
[nSeriesIndex
].empty() )
299 xCT
->setDataSeries( aSeriesSeq
[ nSeriesIndex
] );
304 rtl::Reference
< ChartType
> xCT
= new CandleStickChartType();
305 aChartTypeVec
.push_back( xCT
);
307 xCT
->setPropertyValue( u
"Japanese"_ustr
, uno::Any( bJapaneseStyle
));
308 xCT
->setPropertyValue( u
"ShowFirst"_ustr
, uno::Any( bShowFirst
));
309 xCT
->setPropertyValue( u
"ShowHighLow"_ustr
, uno::Any( bShowHighLow
));
311 if( aSeriesSeq
.size() > nSeriesIndex
&&
312 !aSeriesSeq
[ nSeriesIndex
].empty() )
314 xCT
->setDataSeries( aSeriesSeq
[ nSeriesIndex
] );
318 // Lines (remaining series)
319 if( aSeriesSeq
.size() > nSeriesIndex
&&
320 !aSeriesSeq
[ nSeriesIndex
].empty() )
322 xCT
= new LineChartType();
323 aChartTypeVec
.push_back( xCT
);
325 xCT
->setDataSeries( aSeriesSeq
[ nSeriesIndex
] );
328 rCoordSys
[ 0 ]->setChartTypes( aChartTypeVec
);
330 catch( const uno::Exception
& )
332 DBG_UNHANDLED_EXCEPTION("chart2");
336 // ____ ChartTypeTemplate ____
337 bool StockChartTypeTemplate::matchesTemplate2(
338 const rtl::Reference
< ::chart::Diagram
>& xDiagram
,
339 bool /* bAdaptProperties */ )
341 bool bResult
= false;
348 bool bHasVolume
= false, bHasOpenValue
= false, bHasJapaneseStyle
= false;
350 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME
) >>= bHasVolume
;
351 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN
) >>= bHasOpenValue
;
352 getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
) >>= bHasJapaneseStyle
;
354 rtl::Reference
< ChartType
> xVolumeChartType
;
355 rtl::Reference
< ChartType
> xCandleStickChartType
;
356 rtl::Reference
< ChartType
> xLineChartType
;
357 sal_Int32 nNumberOfChartTypes
= 0;
359 for( rtl::Reference
< BaseCoordinateSystem
> const & coords
: xDiagram
->getBaseCoordinateSystems() )
361 for( rtl::Reference
< ChartType
> const & chartType
: coords
->getChartTypes2() )
363 ++nNumberOfChartTypes
;
364 if( nNumberOfChartTypes
> 3 )
366 OUString aCTService
= chartType
->getChartType();
367 if( aCTService
== CHART2_SERVICE_NAME_CHARTTYPE_COLUMN
)
368 xVolumeChartType
= chartType
;
369 else if( aCTService
== CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
370 xCandleStickChartType
= chartType
;
371 else if( aCTService
== CHART2_SERVICE_NAME_CHARTTYPE_LINE
)
372 xLineChartType
= chartType
;
374 if( nNumberOfChartTypes
> 3 )
378 if (xCandleStickChartType
.is() && bHasVolume
== xVolumeChartType
.is())
382 // check for japanese style
383 bool bJapaneseProp
= false;
384 xCandleStickChartType
->getPropertyValue( u
"Japanese"_ustr
) >>= bJapaneseProp
;
385 bResult
= bResult
&& ( bHasJapaneseStyle
== bJapaneseProp
);
387 // in old chart japanese == showFirst
388 bool bShowFirstProp
= false;
389 xCandleStickChartType
->getPropertyValue( u
"ShowFirst"_ustr
) >>= bShowFirstProp
;
390 bResult
= bResult
&& ( bHasOpenValue
== bShowFirstProp
);
393 catch( const uno::Exception
& )
395 DBG_UNHANDLED_EXCEPTION("chart2");
401 rtl::Reference
< ChartType
> StockChartTypeTemplate::getChartTypeForNewSeries2(
402 const std::vector
< rtl::Reference
< ChartType
> >& aFormerlyUsedChartTypes
)
404 rtl::Reference
< ChartType
> xResult
;
408 xResult
= new LineChartType();
409 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes
, xResult
);
411 catch( const uno::Exception
& )
413 DBG_UNHANDLED_EXCEPTION("chart2");
419 rtl::Reference
< DataInterpreter
> StockChartTypeTemplate::getDataInterpreter2()
421 if( ! m_xDataInterpreter
.is())
422 m_xDataInterpreter
.set( new StockDataInterpreter( m_eStockVariant
) );
424 return m_xDataInterpreter
;
427 IMPLEMENT_FORWARD_XINTERFACE2( StockChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
428 IMPLEMENT_FORWARD_XTYPEPROVIDER2( StockChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */