LibreOffice Module chart2 (master) 1
ScatterChartType.cxx
Go to the documentation of this file.
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 "ScatterChartType.hxx"
21#include <PropertyHelper.hxx>
24#include <Axis.hxx>
25#include <AxisHelper.hxx>
26#include <AxisIndexDefines.hxx>
27#include <unonames.hxx>
29
30#include <com/sun/star/beans/PropertyAttribute.hpp>
31#include <com/sun/star/chart2/AxisType.hpp>
32#include <com/sun/star/chart2/CurveStyle.hpp>
33
34using namespace ::com::sun::star;
35
36using ::com::sun::star::beans::Property;
37using ::com::sun::star::uno::Sequence;
38using ::com::sun::star::uno::Reference;
39
40namespace
41{
42
43enum
44{
45 PROP_SCATTERCHARTTYPE_CURVE_STYLE,
46 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
47 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
48};
49
50::chart::tPropertyValueMap& StaticScatterChartTypeDefaults()
51{
52 static ::chart::tPropertyValueMap aStaticDefaults =
53 []()
54 {
56 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_SCATTERCHARTTYPE_CURVE_STYLE, chart2::CurveStyle_LINES );
57 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, 20 );
58
59 // todo: check whether order 3 means polygons of order 3 or 2. (see
60 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
61 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, PROP_SCATTERCHARTTYPE_SPLINE_ORDER, 3 );
62 return aOutMap;
63 }();
64 return aStaticDefaults;
65}
66
67::cppu::OPropertyArrayHelper& StaticScatterChartTypeInfoHelper()
68{
69 static ::cppu::OPropertyArrayHelper aPropHelper(
70 []()
71 {
72 std::vector< css::beans::Property > aProperties {
74 PROP_SCATTERCHARTTYPE_CURVE_STYLE,
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT },
79 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
81 beans::PropertyAttribute::BOUND
82 | beans::PropertyAttribute::MAYBEDEFAULT },
84 PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT } };
88 std::sort( aProperties.begin(), aProperties.end(),
90 return comphelper::containerToSequence( aProperties );
91 }() );
92 return aPropHelper;
93}
94
95const uno::Reference< beans::XPropertySetInfo >& StaticScatterChartTypeInfo()
96{
97 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
98 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticScatterChartTypeInfoHelper() ) );
99 return xPropertySetInfo;
100}
101
102} // anonymous namespace
103
104namespace chart
105{
106
108{
109}
110
112 ChartType( rOther )
113{
114}
115
117{}
118
119// ____ XCloneable ____
121{
123}
124
126{
127 return new ScatterChartType( *this );
128}
129
130// ____ XChartType ____
133{
135 new CartesianCoordinateSystem( DimensionCount );
136
137 for( sal_Int32 i=0; i<DimensionCount; ++i )
138 {
139 rtl::Reference< Axis > xAxis = xResult->getAxisByDimension2( i, MAIN_AXIS_INDEX );
140 if( !xAxis.is() )
141 {
142 OSL_FAIL("a created coordinate system should have an axis for each dimension");
143 continue;
144 }
145
146 chart2::ScaleData aScaleData = xAxis->getScaleData();
147 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
148 aScaleData.Scaling = AxisHelper::createLinearScaling();
149
150 if( i == 2 )
151 aScaleData.AxisType = chart2::AxisType::SERIES;
152 else
153 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
154
155 xAxis->setScaleData( aScaleData );
156 }
157
158 return xResult;
159}
160
162{
164}
165
167{
168 return { "label", "values-x", "values-y" };
169}
170
171// ____ OPropertySet ____
172void ScatterChartType::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
173{
174 const tPropertyValueMap& rStaticDefaults = StaticScatterChartTypeDefaults();
175 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
176 if( aFound == rStaticDefaults.end() )
177 rAny.clear();
178 else
179 rAny = (*aFound).second;
180}
181
182// ____ OPropertySet ____
184{
185 return StaticScatterChartTypeInfoHelper();
186}
187
188// ____ XPropertySet ____
190{
191 return StaticScatterChartTypeInfo();
192}
193
195{
196 return "com.sun.star.comp.chart.ScatterChartType";
197}
198
199sal_Bool SAL_CALL ScatterChartType::supportsService( const OUString& rServiceName )
200{
201 return cppu::supportsService(this, rServiceName);
202}
203
204css::uno::Sequence< OUString > SAL_CALL ScatterChartType::getSupportedServiceNames()
205{
206 return {
208 "com.sun.star.chart2.ChartType",
209 "com.sun.star.beans.PropertySet" };
210}
211
212} // namespace chart
213
214extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
215com_sun_star_comp_chart_ScatterChartType_get_implementation(css::uno::XComponentContext * /*context*/,
216 css::uno::Sequence<css::uno::Any> const &)
217{
218 return cppu::acquire(new ::chart::ScatterChartType);
219}
220
221/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart_ScatterChartType_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
PropertiesInfo aProperties
static css::uno::Reference< css::chart2::XScaling > createLinearScaling()
Definition: AxisHelper.cxx:65
virtual rtl::Reference< ::chart::BaseCoordinateSystem > createCoordinateSystem2(sal_Int32 DimensionCount) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getChartType() override
virtual ~ScatterChartType() override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual rtl::Reference< ChartType > cloneChartType() const override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedMandatoryRoles() override
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
css::uno::Type const & get()
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
const sal_Int32 MAIN_AXIS_INDEX
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
sal_Int32 nHandle
constexpr OUStringLiteral CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
unsigned char sal_Bool
constexpr OUStringLiteral CHART_UNONAME_SPLINE_ORDER
Definition: unonames.hxx:16
constexpr OUStringLiteral CHART_UNONAME_CURVE_STYLE
Definition: unonames.hxx:18
constexpr OUStringLiteral CHART_UNONAME_CURVE_RESOLUTION
Definition: unonames.hxx:19