1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScatterChartType.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ScatterChartType.hxx"
34 #include "PropertyHelper.hxx"
36 #include "servicenames_charttypes.hxx"
37 #include "ContainerHelper.hxx"
38 #include "CartesianCoordinateSystem.hxx"
39 #include "AxisHelper.hxx"
40 #include "AxisIndexDefines.hxx"
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/chart2/AxisType.hpp>
43 #include <com/sun/star/chart2/CurveStyle.hpp>
45 using namespace ::com::sun::star
;
47 using ::rtl::OUString
;
48 using ::com::sun::star::beans::Property
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::uno::Reference
;
51 using ::com::sun::star::uno::Any
;
52 using ::osl::MutexGuard
;
59 PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
60 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
61 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
64 void lcl_AddPropertiesToVector(
65 ::std::vector
< Property
> & rOutProperties
)
67 rOutProperties
.push_back(
68 Property( C2U( "CurveStyle" ),
69 PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
70 ::getCppuType( reinterpret_cast< const chart2::CurveStyle
* >(0)),
71 beans::PropertyAttribute::BOUND
72 | beans::PropertyAttribute::MAYBEDEFAULT
));
74 rOutProperties
.push_back(
75 Property( C2U( "CurveResolution" ),
76 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
77 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEDEFAULT
));
80 rOutProperties
.push_back(
81 Property( C2U( "SplineOrder" ),
82 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
,
83 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEDEFAULT
));
88 void lcl_AddDefaultsToMap(
89 ::chart::tPropertyValueMap
& rOutMap
)
91 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_SCATTERCHARTTYPE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
92 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
, 20 );
94 // todo: check whether order 3 means polygons of order 3 or 2. (see
95 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
96 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_SPLINE_ORDER
, 3 );
99 const Sequence
< Property
> & lcl_GetPropertySequence()
101 static Sequence
< Property
> aPropSeq
;
104 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
105 if( 0 == aPropSeq
.getLength() )
108 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
109 lcl_AddPropertiesToVector( aProperties
);
111 // and sort them for access via bsearch
112 ::std::sort( aProperties
.begin(), aProperties
.end(),
113 ::chart::PropertyNameLess() );
115 // transfer result to static Sequence
116 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
122 } // anonymous namespace
127 ScatterChartType::ScatterChartType(
128 const uno::Reference
< uno::XComponentContext
> & xContext
,
129 chart2::CurveStyle eCurveStyle
/* chart2::CurveStyle_LINES */ ,
130 sal_Int32 nResolution
/* = 20 */,
131 sal_Int32 nOrder
/* = 3 */ ) :
132 ChartType( xContext
)
134 if( eCurveStyle
!= chart2::CurveStyle_LINES
)
135 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
136 uno::makeAny( eCurveStyle
));
137 if( nResolution
!= 20 )
138 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
139 uno::makeAny( nResolution
));
141 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER
,
142 uno::makeAny( nOrder
));
145 ScatterChartType::ScatterChartType( const ScatterChartType
& rOther
) :
150 ScatterChartType::~ScatterChartType()
153 // ____ XCloneable ____
154 uno::Reference
< util::XCloneable
> SAL_CALL
ScatterChartType::createClone()
155 throw (uno::RuntimeException
)
157 return uno::Reference
< util::XCloneable
>( new ScatterChartType( *this ));
160 // ____ XChartType ____
161 // ____ XChartType ____
162 Reference
< chart2::XCoordinateSystem
> SAL_CALL
163 ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount
)
164 throw (lang::IllegalArgumentException
,
165 uno::RuntimeException
)
167 Reference
< chart2::XCoordinateSystem
> xResult(
168 new CartesianCoordinateSystem(
169 GetComponentContext(), DimensionCount
, /* bSwapXAndYAxis */ sal_False
));
171 for( sal_Int32 i
=0; i
<DimensionCount
; ++i
)
173 Reference
< chart2::XAxis
> xAxis( xResult
->getAxisByDimension( i
, MAIN_AXIS_INDEX
) );
176 OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
180 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
181 aScaleData
.Orientation
= chart2::AxisOrientation_MATHEMATICAL
;
182 aScaleData
.Scaling
= AxisHelper::createLinearScaling();
185 aScaleData
.AxisType
= chart2::AxisType::SERIES
;
187 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
189 xAxis
->setScaleData( aScaleData
);
195 ::rtl::OUString SAL_CALL
ScatterChartType::getChartType()
196 throw (uno::RuntimeException
)
198 return CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
;
201 uno::Sequence
< ::rtl::OUString
> SAL_CALL
ScatterChartType::getSupportedMandatoryRoles()
202 throw (uno::RuntimeException
)
204 static uno::Sequence
< ::rtl::OUString
> aMandRolesSeq
;
206 if( aMandRolesSeq
.getLength() == 0 )
208 aMandRolesSeq
.realloc( 3 );
209 aMandRolesSeq
[0] = C2U( "label" );
210 aMandRolesSeq
[1] = C2U( "values-x" );
211 aMandRolesSeq
[2] = C2U( "values-y" );
214 return aMandRolesSeq
;
217 uno::Sequence
< ::rtl::OUString
> SAL_CALL
ScatterChartType::getSupportedOptionalRoles()
218 throw (uno::RuntimeException
)
220 static uno::Sequence
< ::rtl::OUString
> aOptRolesSeq
;
222 // if( aOptRolesSeq.getLength() == 0 )
224 // aOptRolesSeq.realloc( 2 );
225 // aOptRolesSeq[0] = C2U( "error-bars-x" );
226 // aOptRolesSeq[1] = C2U( "error-bars-y" );
233 // ____ OPropertySet ____
234 uno::Any
ScatterChartType::GetDefaultValue( sal_Int32 nHandle
) const
235 throw(beans::UnknownPropertyException
)
237 static tPropertyValueMap aStaticDefaults
;
240 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
241 if( 0 == aStaticDefaults
.size() )
243 // initialize defaults
244 lcl_AddDefaultsToMap( aStaticDefaults
);
247 tPropertyValueMap::const_iterator
aFound(
248 aStaticDefaults
.find( nHandle
));
250 if( aFound
== aStaticDefaults
.end())
253 return (*aFound
).second
;
257 // ____ OPropertySet ____
258 ::cppu::IPropertyArrayHelper
& SAL_CALL
ScatterChartType::getInfoHelper()
260 static ::cppu::OPropertyArrayHelper
aArrayHelper( lcl_GetPropertySequence(),
261 /* bSorted = */ sal_True
);
267 // ____ XPropertySet ____
268 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
269 ScatterChartType::getPropertySetInfo()
270 throw (uno::RuntimeException
)
272 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
275 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
278 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
286 uno::Sequence
< ::rtl::OUString
> ScatterChartType::getSupportedServiceNames_Static()
288 uno::Sequence
< ::rtl::OUString
> aServices( 3 );
289 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
;
290 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
291 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
295 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
296 APPHELPER_XSERVICEINFO_IMPL( ScatterChartType
,
297 C2U( "com.sun.star.comp.chart.ScatterChartType" ));