LibreOffice Module chart2 (master) 1
Scaling.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 <Scaling.hxx>
21#include <com/sun/star/uno/RuntimeException.hpp>
23
24#include <cmath>
25#include <limits>
26
27namespace com::sun::star::uno { class XComponentContext; }
28
29namespace
30{
31
32constexpr OUStringLiteral lcl_aServiceName_Logarithmic = u"com.sun.star.chart2.LogarithmicScaling";
33constexpr OUStringLiteral lcl_aServiceName_Exponential = u"com.sun.star.chart2.ExponentialScaling";
34constexpr OUStringLiteral lcl_aServiceName_Linear = u"com.sun.star.chart2.LinearScaling";
35constexpr OUStringLiteral lcl_aServiceName_Power = u"com.sun.star.chart2.PowerScaling";
36
37}
38
39namespace chart
40{
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::chart2;
43
45 m_fBase( 10.0 ),
46 m_fLogOfBase( log( 10.0 ) )
47{
48}
49
51 m_fBase( fBase ),
52 m_fLogOfBase( log( fBase ) )
53{
54}
55
57{
58}
59
60double SAL_CALL LogarithmicScaling::doScaling( double value )
61{
62 if( std::isnan( value ) || std::isinf( value ) )
63 return std::numeric_limits<double>::quiet_NaN();
64 return std::log( value ) / m_fLogOfBase;
65}
66
68{
69 return new ExponentialScaling( m_fBase );
70}
71
73{
74 return lcl_aServiceName_Logarithmic;
75}
76
78{
79 return lcl_aServiceName_Logarithmic;
80}
81
82sal_Bool SAL_CALL LogarithmicScaling::supportsService( const OUString& rServiceName )
83{
84 return cppu::supportsService(this, rServiceName);
85}
86
87css::uno::Sequence< OUString > SAL_CALL LogarithmicScaling::getSupportedServiceNames()
88{
89 return { lcl_aServiceName_Logarithmic };
90}
91
93 m_fBase( 10.0 )
94{
95}
96
98 m_fBase( fBase )
99{
100}
101
103{
104}
105
106double SAL_CALL ExponentialScaling::doScaling( double value )
107{
108 if( std::isnan( value ) || std::isinf( value ) )
109 return std::numeric_limits<double>::quiet_NaN();
110 return std::pow( m_fBase, value );
111}
112
114{
115 return new LogarithmicScaling( m_fBase );
116}
117
119{
120 return lcl_aServiceName_Exponential;
121}
122
124{
125 return lcl_aServiceName_Exponential;
126}
127
128sal_Bool SAL_CALL ExponentialScaling::supportsService( const OUString& rServiceName )
129{
130 return cppu::supportsService(this, rServiceName);
131}
132
133css::uno::Sequence< OUString > SAL_CALL ExponentialScaling::getSupportedServiceNames()
134{
135 return { lcl_aServiceName_Exponential };
136}
137
139 m_fSlope( 1.0 ),
140 m_fOffset( 0.0 )
141{}
142
143LinearScaling::LinearScaling( double fSlope, double fOffset ) :
144 m_fSlope( fSlope ),
145 m_fOffset( fOffset )
146{}
147
149{}
150
151double SAL_CALL LinearScaling::doScaling( double value )
152{
153 if( std::isnan( value ) || std::isinf( value ) )
154 return std::numeric_limits<double>::quiet_NaN();
155 return m_fOffset + m_fSlope * value;
156}
157
160{
161 // ToDo: ApproxEqual ?
162 if( m_fSlope == 0 )
163 throw uno::RuntimeException("Divide by zero exception");
164
165 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
166}
167
169{
170 return lcl_aServiceName_Linear;
171}
172
174{
175 return lcl_aServiceName_Linear ;
176}
177
178sal_Bool SAL_CALL LinearScaling::supportsService( const OUString& rServiceName )
179{
180 return cppu::supportsService(this, rServiceName);
181}
182
183css::uno::Sequence< OUString > SAL_CALL LinearScaling::getSupportedServiceNames()
184{
185 return { lcl_aServiceName_Linear };
186}
187
189 m_fExponent( 10.0 )
190{}
191
192PowerScaling::PowerScaling( double fExponent ) :
193 m_fExponent( fExponent )
194{}
195
197{}
198
199double SAL_CALL PowerScaling::doScaling( double value )
200{
201 if( std::isnan( value ) || std::isinf( value ) )
202 return std::numeric_limits<double>::quiet_NaN();
203 return std::pow( value, m_fExponent );
204}
205
208{
209 // ToDo: ApproxEqual ?
210 if( m_fExponent == 0 )
211 throw uno::RuntimeException("Divide by zero exception");
212
213 return new PowerScaling( 1.0 / m_fExponent );
214}
215
216 OUString SAL_CALL
218{
219 return lcl_aServiceName_Power;
220}
221
223{
224 return lcl_aServiceName_Power;
225}
226
227sal_Bool SAL_CALL PowerScaling::supportsService( const OUString& rServiceName )
228{
229 return cppu::supportsService(this, rServiceName);
230}
231
232css::uno::Sequence< OUString > SAL_CALL PowerScaling::getSupportedServiceNames()
233{
234 return { lcl_aServiceName_Power };
235}
236
237} //namespace chart
238
239extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
241 css::uno::Sequence<css::uno::Any> const &)
242{
243 return cppu::acquire(new chart::LinearScaling );
244}
245
246extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
248 css::uno::Sequence<css::uno::Any> const &)
249{
250 return cppu::acquire(new chart::ExponentialScaling );
251}
252
253extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
255 css::uno::Sequence<css::uno::Any> const &)
256{
257 return cppu::acquire(new chart::LogarithmicScaling );
258}
259
260extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
262 css::uno::Sequence<css::uno::Any> const &)
263{
264 return cppu::acquire(new chart::PowerScaling );
265}
266
267/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_chart2_LinearScaling_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Scaling.cxx:240
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_chart2_LogarithmicScaling_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Scaling.cxx:254
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_chart2_ExponentialScaling_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Scaling.cxx:247
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_chart2_PowerScaling_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Scaling.cxx:261
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Scaling.cxx:128
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
Definition: Scaling.cxx:113
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
Definition: Scaling.cxx:123
virtual double SAL_CALL doScaling(double value) override
Definition: Scaling.cxx:106
virtual ~ExponentialScaling() override
Definition: Scaling.cxx:102
const double m_fBase
Definition: Scaling.hxx:91
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Scaling.cxx:133
virtual OUString SAL_CALL getServiceName() override
Definition: Scaling.cxx:118
ExponentialScaling()
base is 10.0
Definition: Scaling.cxx:92
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
Definition: Scaling.cxx:173
virtual double SAL_CALL doScaling(double value) override
Definition: Scaling.cxx:151
const double m_fOffset
Definition: Scaling.hxx:123
virtual ~LinearScaling() override
Definition: Scaling.cxx:148
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Scaling.cxx:178
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Scaling.cxx:183
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
Definition: Scaling.cxx:159
virtual OUString SAL_CALL getServiceName() override
Definition: Scaling.cxx:168
const double m_fSlope
Definition: Scaling.hxx:122
LinearScaling()
y(x) = x
Definition: Scaling.cxx:138
const double m_fLogOfBase
Definition: Scaling.hxx:59
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
Definition: Scaling.cxx:67
LogarithmicScaling()
base is 10.0
Definition: Scaling.cxx:44
virtual ~LogarithmicScaling() override
Definition: Scaling.cxx:56
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Scaling.cxx:87
virtual double SAL_CALL doScaling(double value) override
Definition: Scaling.cxx:60
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Scaling.cxx:82
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
Definition: Scaling.cxx:77
const double m_fBase
Definition: Scaling.hxx:58
virtual OUString SAL_CALL getServiceName() override
Definition: Scaling.cxx:72
PowerScaling()
exponent 10.0
Definition: Scaling.cxx:188
virtual ~PowerScaling() override
Definition: Scaling.cxx:196
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
Definition: Scaling.cxx:207
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
Definition: Scaling.cxx:222
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Scaling.cxx:227
const double m_fExponent
Definition: Scaling.hxx:154
virtual OUString SAL_CALL getServiceName() override
Definition: Scaling.cxx:217
virtual double SAL_CALL doScaling(double value) override
Definition: Scaling.cxx:199
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Scaling.cxx:232
Any value
float u
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
log
unsigned char sal_Bool