1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_charttools.hxx"
26 #include "Scaling.hxx"
27 #include <rtl/math.hxx>
28 #include "com/sun/star/uno/RuntimeException.hpp"
29
30 namespace
31 {
32
33 static const ::rtl::OUString lcl_aServiceName_Logarithmic(
34 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
35 static const ::rtl::OUString lcl_aServiceName_Exponential(
36 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ExponentialScaling" ));
37 static const ::rtl::OUString lcl_aServiceName_Linear(
38 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
39 static const ::rtl::OUString lcl_aServiceName_Power(
40 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PowerScaling" ));
41
42 static const ::rtl::OUString lcl_aImplementationName_Logarithmic(
43 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicScaling" ));
44 static const ::rtl::OUString lcl_aImplementationName_Exponential(
45 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialScaling" ));
46 static const ::rtl::OUString lcl_aImplementationName_Linear(
47 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearScaling" ));
48 static const ::rtl::OUString lcl_aImplementationName_Power(
49 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PowerScaling" ));
50 }
51
52 //.............................................................................
53 namespace chart
54 {
55 //.............................................................................
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::chart2;
58
LogarithmicScaling(const uno::Reference<uno::XComponentContext> & xContext)59 LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
60 m_fBase( 10.0 ),
61 m_fLogOfBase( log( 10.0 ) ),
62 m_xContext( xContext )
63 {
64 }
65
LogarithmicScaling(double fBase)66 LogarithmicScaling::LogarithmicScaling( double fBase ) :
67 m_fBase( fBase ),
68 m_fLogOfBase( log( fBase ) )
69 {
70 }
71
~LogarithmicScaling()72 LogarithmicScaling::~LogarithmicScaling()
73 {
74 }
75
76 double SAL_CALL
doScaling(double value)77 LogarithmicScaling::doScaling( double value )
78 {
79 double fResult;
80 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
81 ::rtl::math::setNan( & fResult );
82 else
83 fResult = log( value ) / m_fLogOfBase;
84 return fResult;
85 }
86
87 uno::Reference< XScaling > SAL_CALL
getInverseScaling()88 LogarithmicScaling::getInverseScaling()
89 {
90 return new ExponentialScaling( m_fBase );
91 }
92
93 ::rtl::OUString SAL_CALL
getServiceName()94 LogarithmicScaling::getServiceName()
95 {
96 return lcl_aServiceName_Logarithmic;
97 }
98
getSupportedServiceNames_Static()99 uno::Sequence< ::rtl::OUString > LogarithmicScaling::getSupportedServiceNames_Static()
100 {
101 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Logarithmic, 1 );
102 }
103
104 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
APPHELPER_XSERVICEINFO_IMPL(LogarithmicScaling,lcl_aServiceName_Logarithmic)105 APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
106
107 // ----------------------------------------
108
109 ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
110 m_fBase( 10.0 ),
111 m_xContext( xContext )
112 {
113 }
114
ExponentialScaling(double fBase)115 ExponentialScaling::ExponentialScaling( double fBase ) :
116 m_fBase( fBase )
117 {
118 }
119
~ExponentialScaling()120 ExponentialScaling::~ExponentialScaling()
121 {
122 }
123
124 double SAL_CALL
doScaling(double value)125 ExponentialScaling::doScaling( double value )
126 {
127 double fResult;
128 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
129 ::rtl::math::setNan( & fResult );
130 else
131 fResult = pow( m_fBase, value );
132 return fResult;
133 }
134
135 uno::Reference< XScaling > SAL_CALL
getInverseScaling()136 ExponentialScaling::getInverseScaling()
137 {
138 return new LogarithmicScaling( m_fBase );
139 }
140
141 ::rtl::OUString SAL_CALL
getServiceName()142 ExponentialScaling::getServiceName()
143 {
144 return lcl_aServiceName_Exponential;
145 }
146
getSupportedServiceNames_Static()147 uno::Sequence< ::rtl::OUString > ExponentialScaling::getSupportedServiceNames_Static()
148 {
149 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Exponential, 1 );
150 }
151
152 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
APPHELPER_XSERVICEINFO_IMPL(ExponentialScaling,lcl_aServiceName_Exponential)153 APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
154
155 // ----------------------------------------
156
157 LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
158 m_fSlope( 1.0 ),
159 m_fOffset( 0.0 ),
160 m_xContext( xContext )
161 {}
162
LinearScaling(double fSlope,double fOffset)163 LinearScaling::LinearScaling( double fSlope, double fOffset ) :
164 m_fSlope( fSlope ),
165 m_fOffset( fOffset )
166 {}
167
~LinearScaling()168 LinearScaling::~LinearScaling()
169 {}
170
doScaling(double value)171 double SAL_CALL LinearScaling::doScaling( double value )
172 {
173 double fResult;
174 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
175 ::rtl::math::setNan( & fResult );
176 else
177 fResult = m_fOffset + m_fSlope * value;
178 return fResult;
179 }
180
181 uno::Reference< XScaling > SAL_CALL
getInverseScaling()182 LinearScaling::getInverseScaling()
183 {
184 // ToDo: ApproxEqual ?
185 if( m_fSlope == 0 )
186 throw uno::RuntimeException();
187
188 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
189 }
190
191 ::rtl::OUString SAL_CALL
getServiceName()192 LinearScaling::getServiceName()
193 {
194 return lcl_aServiceName_Linear;
195 }
196
getSupportedServiceNames_Static()197 uno::Sequence< ::rtl::OUString > LinearScaling::getSupportedServiceNames_Static()
198 {
199 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Linear, 1 );
200 }
201
202 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
APPHELPER_XSERVICEINFO_IMPL(LinearScaling,lcl_aServiceName_Linear)203 APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
204
205 // ----------------------------------------
206
207 PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
208 m_fExponent( 10.0 ),
209 m_xContext( xContext )
210 {}
211
PowerScaling(double fExponent)212 PowerScaling::PowerScaling( double fExponent ) :
213 m_fExponent( fExponent )
214 {}
215
~PowerScaling()216 PowerScaling::~PowerScaling()
217 {}
218
doScaling(double value)219 double SAL_CALL PowerScaling::doScaling( double value )
220 {
221 double fResult;
222 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
223 ::rtl::math::setNan( & fResult );
224 else
225 fResult = pow( value, m_fExponent );
226 return fResult;
227 }
228
229 uno::Reference< XScaling > SAL_CALL
getInverseScaling()230 PowerScaling::getInverseScaling()
231 {
232 // ToDo: ApproxEqual ?
233 if( m_fExponent == 0 )
234 throw uno::RuntimeException();
235
236 return new PowerScaling( 1.0 / m_fExponent );
237 }
238
239 ::rtl::OUString SAL_CALL
getServiceName()240 PowerScaling::getServiceName()
241 {
242 return lcl_aServiceName_Power;
243 }
244
getSupportedServiceNames_Static()245 uno::Sequence< ::rtl::OUString > PowerScaling::getSupportedServiceNames_Static()
246 {
247 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Power, 1 );
248 }
249
250 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
251 APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
252
253 //.............................................................................
254 } //namespace chart
255 //.............................................................................
256