1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/chart/axisconverter.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
27cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
28cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
29cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisPosition.hpp>
30cdf0e10cSrcweir #include <com/sun/star/chart/TimeInterval.hpp>
31cdf0e10cSrcweir #include <com/sun/star/chart/TimeUnit.hpp>
32cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp>
33cdf0e10cSrcweir #include <com/sun/star/chart2/TickmarkStyle.hpp>
34cdf0e10cSrcweir #include <com/sun/star/chart2/XAxis.hpp>
35cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystem.hpp>
36cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
37cdf0e10cSrcweir #include "oox/drawingml/chart/axismodel.hxx"
38cdf0e10cSrcweir #include "oox/drawingml/chart/titleconverter.hxx"
39cdf0e10cSrcweir #include "oox/drawingml/chart/typegroupconverter.hxx"
40cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace oox {
43cdf0e10cSrcweir namespace drawingml {
44cdf0e10cSrcweir namespace chart {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ============================================================================
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
50cdf0e10cSrcweir using namespace ::com::sun::star::uno;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir using ::rtl::OUString;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // ============================================================================
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace {
57cdf0e10cSrcweir 
lclSetValueOrClearAny(Any & orAny,const OptValue<double> & rofValue)58cdf0e10cSrcweir inline void lclSetValueOrClearAny( Any& orAny, const OptValue< double >& rofValue )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     if( rofValue.has() ) orAny <<= rofValue.get(); else orAny.clear();
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
lclIsLogarithmicScale(const AxisModel & rAxisModel)63cdf0e10cSrcweir bool lclIsLogarithmicScale( const AxisModel& rAxisModel )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     return rAxisModel.mofLogBase.has() && (2.0 <= rAxisModel.mofLogBase.get()) && (rAxisModel.mofLogBase.get() <= 1000.0);
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
lclGetApiTimeUnit(sal_Int32 nTimeUnit)68cdf0e10cSrcweir sal_Int32 lclGetApiTimeUnit( sal_Int32 nTimeUnit )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     using namespace ::com::sun::star::chart;
71cdf0e10cSrcweir     switch( nTimeUnit )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         case XML_days:      return TimeUnit::DAY;
74cdf0e10cSrcweir         case XML_months:    return TimeUnit::MONTH;
75cdf0e10cSrcweir         case XML_years:     return TimeUnit::YEAR;
76cdf0e10cSrcweir         default:            OSL_ENSURE( false, "lclGetApiTimeUnit - unexpected time unit" );
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir     return TimeUnit::DAY;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
lclConvertTimeInterval(Any & orInterval,const OptValue<double> & rofUnit,sal_Int32 nTimeUnit)81cdf0e10cSrcweir void lclConvertTimeInterval( Any& orInterval, const OptValue< double >& rofUnit, sal_Int32 nTimeUnit )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     if( rofUnit.has() && (1.0 <= rofUnit.get()) && (rofUnit.get() <= SAL_MAX_INT32) )
84cdf0e10cSrcweir         orInterval <<= ::com::sun::star::chart::TimeInterval( static_cast< sal_Int32 >( rofUnit.get() ), lclGetApiTimeUnit( nTimeUnit ) );
85cdf0e10cSrcweir     else
86cdf0e10cSrcweir         orInterval.clear();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
lclGetLabelPosition(sal_Int32 nToken)89cdf0e10cSrcweir ::com::sun::star::chart::ChartAxisLabelPosition lclGetLabelPosition( sal_Int32 nToken )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     using namespace ::com::sun::star::chart;
92cdf0e10cSrcweir     switch( nToken )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         case XML_high:      return ChartAxisLabelPosition_OUTSIDE_END;
95cdf0e10cSrcweir         case XML_low:       return ChartAxisLabelPosition_OUTSIDE_START;
96cdf0e10cSrcweir         case XML_nextTo:    return ChartAxisLabelPosition_NEAR_AXIS;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     return ChartAxisLabelPosition_NEAR_AXIS;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
lclGetTickMark(sal_Int32 nToken)101cdf0e10cSrcweir sal_Int32 lclGetTickMark( sal_Int32 nToken )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     using namespace ::com::sun::star::chart2::TickmarkStyle;
104cdf0e10cSrcweir     switch( nToken )
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         case XML_in:    return INNER;
107cdf0e10cSrcweir         case XML_out:   return OUTER;
108cdf0e10cSrcweir         case XML_cross: return INNER | OUTER;
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir     return NONE;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir } // namespace
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // ============================================================================
116cdf0e10cSrcweir 
AxisConverter(const ConverterRoot & rParent,AxisModel & rModel)117cdf0e10cSrcweir AxisConverter::AxisConverter( const ConverterRoot& rParent, AxisModel& rModel ) :
118cdf0e10cSrcweir     ConverterBase< AxisModel >( rParent, rModel )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
~AxisConverter()122cdf0e10cSrcweir AxisConverter::~AxisConverter()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
convertFromModel(const Reference<XCoordinateSystem> & rxCoordSystem,TypeGroupConverter & rTypeGroup,const AxisModel * pCrossingAxis,sal_Int32 nAxesSetIdx,sal_Int32 nAxisIdx)126cdf0e10cSrcweir void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCoordSystem,
127cdf0e10cSrcweir         TypeGroupConverter& rTypeGroup, const AxisModel* pCrossingAxis, sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     Reference< XAxis > xAxis;
130cdf0e10cSrcweir     try
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         namespace cssc = ::com::sun::star::chart;
133cdf0e10cSrcweir         namespace cssc2 = ::com::sun::star::chart2;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
136cdf0e10cSrcweir         ObjectFormatter& rFormatter = getFormatter();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         // create the axis object (always)
139cdf0e10cSrcweir         xAxis.set( createInstance( CREATE_OUSTRING( "com.sun.star.chart2.Axis" ) ), UNO_QUERY_THROW );
140cdf0e10cSrcweir         PropertySet aAxisProp( xAxis );
141cdf0e10cSrcweir         // #i58688# axis enabled
142cdf0e10cSrcweir         aAxisProp.setProperty( PROP_Show, !mrModel.mbDeleted );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         // axis line, tick, and gridline properties ---------------------------
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         // show axis labels
147cdf0e10cSrcweir         aAxisProp.setProperty( PROP_DisplayLabels, mrModel.mnTickLabelPos != XML_none );
148cdf0e10cSrcweir         aAxisProp.setProperty( PROP_LabelPosition, lclGetLabelPosition( mrModel.mnTickLabelPos ) );
149cdf0e10cSrcweir         // no X axis line in radar charts
150cdf0e10cSrcweir         if( (nAxisIdx == API_X_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_RADAR) )
151cdf0e10cSrcweir             mrModel.mxShapeProp.getOrCreate().getLineProperties().maLineFill.moFillType = XML_noFill;
152cdf0e10cSrcweir         // axis line and tick label formatting
153cdf0e10cSrcweir         rFormatter.convertFormatting( aAxisProp, mrModel.mxShapeProp, mrModel.mxTextProp, OBJECTTYPE_AXIS );
154cdf0e10cSrcweir         // tick label rotation
155cdf0e10cSrcweir         rFormatter.convertTextRotation( aAxisProp, mrModel.mxTextProp, true );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         // tick mark style
158cdf0e10cSrcweir         aAxisProp.setProperty( PROP_MajorTickmarks, lclGetTickMark( mrModel.mnMajorTickMark ) );
159cdf0e10cSrcweir         aAxisProp.setProperty( PROP_MinorTickmarks, lclGetTickMark( mrModel.mnMinorTickMark ) );
160cdf0e10cSrcweir         aAxisProp.setProperty( PROP_MarkPosition, cssc::ChartAxisMarkPosition_AT_AXIS );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         // main grid
163cdf0e10cSrcweir         PropertySet aGridProp( xAxis->getGridProperties() );
164cdf0e10cSrcweir         aGridProp.setProperty( PROP_Show, mrModel.mxMajorGridLines.is() );
165cdf0e10cSrcweir         if( mrModel.mxMajorGridLines.is() )
166cdf0e10cSrcweir             rFormatter.convertFrameFormatting( aGridProp, mrModel.mxMajorGridLines, OBJECTTYPE_MAJORGRIDLINE );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // sub grid
169cdf0e10cSrcweir         Sequence< Reference< XPropertySet > > aSubGridPropSeq = xAxis->getSubGridProperties();
170cdf0e10cSrcweir         if( aSubGridPropSeq.hasElements() )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             PropertySet aSubGridProp( aSubGridPropSeq[ 0 ] );
173cdf0e10cSrcweir             aSubGridProp.setProperty( PROP_Show, mrModel.mxMinorGridLines.is() );
174cdf0e10cSrcweir             if( mrModel.mxMinorGridLines.is() )
175cdf0e10cSrcweir                 rFormatter.convertFrameFormatting( aSubGridProp, mrModel.mxMinorGridLines, OBJECTTYPE_MINORGRIDLINE );
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         // axis type and X axis categories ------------------------------------
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         ScaleData aScaleData = xAxis->getScaleData();
181cdf0e10cSrcweir         // set axis type
182cdf0e10cSrcweir         switch( nAxisIdx )
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             case API_X_AXIS:
185cdf0e10cSrcweir                 if( rTypeInfo.mbCategoryAxis )
186cdf0e10cSrcweir                 {
187cdf0e10cSrcweir                     OSL_ENSURE( (mrModel.mnTypeId == C_TOKEN( catAx )) || (mrModel.mnTypeId == C_TOKEN( dateAx )),
188cdf0e10cSrcweir                         "AxisConverter::convertFromModel - unexpected axis model type (must: c:catAx or c:dateAx)" );
189cdf0e10cSrcweir                     bool bDateAxis = mrModel.mnTypeId == C_TOKEN( dateAx );
190cdf0e10cSrcweir                     /*  Chart2 requires axis type CATEGORY for automatic
191cdf0e10cSrcweir                         category/date axis (even if it is a date axis
192cdf0e10cSrcweir                         currently). */
193cdf0e10cSrcweir                     aScaleData.AxisType = (bDateAxis && !mrModel.mbAuto) ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
194cdf0e10cSrcweir                     aScaleData.AutoDateAxis = mrModel.mbAuto;
195cdf0e10cSrcweir                     aScaleData.Categories = rTypeGroup.createCategorySequence();
196cdf0e10cSrcweir                 }
197cdf0e10cSrcweir                 else
198cdf0e10cSrcweir                 {
199cdf0e10cSrcweir                     OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( valAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" );
200cdf0e10cSrcweir                     aScaleData.AxisType = cssc2::AxisType::REALNUMBER;
201cdf0e10cSrcweir                 }
202cdf0e10cSrcweir             break;
203cdf0e10cSrcweir             case API_Y_AXIS:
204cdf0e10cSrcweir                 OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( valAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" );
205cdf0e10cSrcweir                 aScaleData.AxisType = rTypeGroup.isPercent() ? cssc2::AxisType::PERCENT : cssc2::AxisType::REALNUMBER;
206cdf0e10cSrcweir             break;
207cdf0e10cSrcweir             case API_Z_AXIS:
208cdf0e10cSrcweir                 OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( serAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:serAx)" );
209cdf0e10cSrcweir                 OSL_ENSURE( rTypeGroup.isDeep3dChart(), "AxisConverter::convertFromModel - series axis not supported by this chart type" );
210cdf0e10cSrcweir                 aScaleData.AxisType = cssc2::AxisType::SERIES;
211cdf0e10cSrcweir             break;
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         // axis scaling and increment -----------------------------------------
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         switch( aScaleData.AxisType )
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             case cssc2::AxisType::CATEGORY:
219cdf0e10cSrcweir             case cssc2::AxisType::SERIES:
220cdf0e10cSrcweir             case cssc2::AxisType::DATE:
221cdf0e10cSrcweir             {
222cdf0e10cSrcweir                 /*  Determine date axis type from XML type identifier, and not
223cdf0e10cSrcweir                     via aScaleData.AxisType, as this value sticks to CATEGORY
224cdf0e10cSrcweir                     for automatic category/date axes). */
225cdf0e10cSrcweir                 if( mrModel.mnTypeId == C_TOKEN( dateAx ) )
226cdf0e10cSrcweir                 {
227cdf0e10cSrcweir                     // scaling algorithm
228cdf0e10cSrcweir                     aScaleData.Scaling.set( createInstance( CREATE_OUSTRING( "com.sun.star.chart2.LinearScaling" ) ), UNO_QUERY );
229cdf0e10cSrcweir                     // min/max
230cdf0e10cSrcweir                     lclSetValueOrClearAny( aScaleData.Minimum, mrModel.mofMin );
231cdf0e10cSrcweir                     lclSetValueOrClearAny( aScaleData.Maximum, mrModel.mofMax );
232cdf0e10cSrcweir                     // major/minor increment
233cdf0e10cSrcweir                     lclConvertTimeInterval( aScaleData.TimeIncrement.MajorTimeInterval, mrModel.mofMajorUnit, mrModel.mnMajorTimeUnit );
234cdf0e10cSrcweir                     lclConvertTimeInterval( aScaleData.TimeIncrement.MinorTimeInterval, mrModel.mofMinorUnit, mrModel.mnMinorTimeUnit );
235cdf0e10cSrcweir                     // base time unit
236cdf0e10cSrcweir                     if( mrModel.monBaseTimeUnit.has() )
237cdf0e10cSrcweir                         aScaleData.TimeIncrement.TimeResolution <<= lclGetApiTimeUnit( mrModel.monBaseTimeUnit.get() );
238cdf0e10cSrcweir                     else
239cdf0e10cSrcweir                         aScaleData.TimeIncrement.TimeResolution.clear();
240cdf0e10cSrcweir                 }
241cdf0e10cSrcweir                 else
242cdf0e10cSrcweir                 {
243cdf0e10cSrcweir                     // do not overlap text unless all labels are visible
244cdf0e10cSrcweir                     aAxisProp.setProperty( PROP_TextOverlap, mrModel.mnTickLabelSkip == 1 );
245cdf0e10cSrcweir                     // do not break text into several lines
246cdf0e10cSrcweir                     aAxisProp.setProperty( PROP_TextBreak, false );
247cdf0e10cSrcweir                     // do not stagger labels in two lines
248cdf0e10cSrcweir                     aAxisProp.setProperty( PROP_ArrangeOrder, cssc::ChartAxisArrangeOrderType_SIDE_BY_SIDE );
249cdf0e10cSrcweir                     //! TODO #i58731# show n-th category
250cdf0e10cSrcweir                 }
251cdf0e10cSrcweir             }
252cdf0e10cSrcweir             break;
253cdf0e10cSrcweir             case cssc2::AxisType::REALNUMBER:
254cdf0e10cSrcweir             case cssc2::AxisType::PERCENT:
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 // scaling algorithm
257cdf0e10cSrcweir                 bool bLogScale = lclIsLogarithmicScale( mrModel );
258cdf0e10cSrcweir                 OUString aScalingService = bLogScale ?
259cdf0e10cSrcweir                     CREATE_OUSTRING( "com.sun.star.chart2.LogarithmicScaling" ) :
260cdf0e10cSrcweir                     CREATE_OUSTRING( "com.sun.star.chart2.LinearScaling" );
261cdf0e10cSrcweir                 aScaleData.Scaling.set( createInstance( aScalingService ), UNO_QUERY );
262cdf0e10cSrcweir                 // min/max
263cdf0e10cSrcweir                 lclSetValueOrClearAny( aScaleData.Minimum, mrModel.mofMin );
264cdf0e10cSrcweir                 lclSetValueOrClearAny( aScaleData.Maximum, mrModel.mofMax );
265cdf0e10cSrcweir                 // major increment
266cdf0e10cSrcweir                 IncrementData& rIncrementData = aScaleData.IncrementData;
267cdf0e10cSrcweir                 if( mrModel.mofMajorUnit.has() && aScaleData.Scaling.is() )
268cdf0e10cSrcweir                     rIncrementData.Distance <<= aScaleData.Scaling->doScaling( mrModel.mofMajorUnit.get() );
269cdf0e10cSrcweir                 else
270cdf0e10cSrcweir                     lclSetValueOrClearAny( rIncrementData.Distance, mrModel.mofMajorUnit );
271cdf0e10cSrcweir                 // minor increment
272cdf0e10cSrcweir                 Sequence< SubIncrement >& rSubIncrementSeq = rIncrementData.SubIncrements;
273cdf0e10cSrcweir                 rSubIncrementSeq.realloc( 1 );
274cdf0e10cSrcweir                 Any& rIntervalCount = rSubIncrementSeq[ 0 ].IntervalCount;
275cdf0e10cSrcweir                 rIntervalCount.clear();
276cdf0e10cSrcweir                 if( bLogScale )
277cdf0e10cSrcweir                 {
278cdf0e10cSrcweir                     if( mrModel.mofMinorUnit.has() )
279cdf0e10cSrcweir                         rIntervalCount <<= sal_Int32( 9 );
280cdf0e10cSrcweir                 }
281cdf0e10cSrcweir                 else if( mrModel.mofMajorUnit.has() && mrModel.mofMinorUnit.has() && (0.0 < mrModel.mofMinorUnit.get()) && (mrModel.mofMinorUnit.get() <= mrModel.mofMajorUnit.get()) )
282cdf0e10cSrcweir                 {
283cdf0e10cSrcweir                     double fCount = mrModel.mofMajorUnit.get() / mrModel.mofMinorUnit.get() + 0.5;
284cdf0e10cSrcweir                     if( (1.0 <= fCount) && (fCount < 1001.0) )
285cdf0e10cSrcweir                         rIntervalCount <<= static_cast< sal_Int32 >( fCount );
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir             break;
289cdf0e10cSrcweir             default:
290cdf0e10cSrcweir                 OSL_ENSURE( false, "AxisConverter::convertFromModel - unknown axis type" );
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         /*  Do not set a value to the Origin member anymore (already done via
294cdf0e10cSrcweir             new axis properties 'CrossoverPosition' and 'CrossoverValue'). */
295cdf0e10cSrcweir         aScaleData.Origin.clear();
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         // axis orientation ---------------------------------------------------
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         // #i85167# pie/donut charts need opposite direction at Y axis
300cdf0e10cSrcweir         // #i87747# radar charts need opposite direction at X axis
301cdf0e10cSrcweir         bool bMirrorDirection =
302cdf0e10cSrcweir             ((nAxisIdx == API_Y_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_PIE)) ||
303cdf0e10cSrcweir             ((nAxisIdx == API_X_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_RADAR));
304cdf0e10cSrcweir         bool bReverse = (mrModel.mnOrientation == XML_maxMin) != bMirrorDirection;
305cdf0e10cSrcweir         aScaleData.Orientation = bReverse ? cssc2::AxisOrientation_REVERSE : cssc2::AxisOrientation_MATHEMATICAL;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir         // write back scaling data
308cdf0e10cSrcweir         xAxis->setScaleData( aScaleData );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir         // number format ------------------------------------------------------
311cdf0e10cSrcweir 
312cdf0e10cSrcweir         if( (aScaleData.AxisType == cssc2::AxisType::REALNUMBER) || (aScaleData.AxisType == cssc2::AxisType::PERCENT) )
313cdf0e10cSrcweir             getFormatter().convertNumberFormat( aAxisProp, mrModel.maNumberFormat );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir         // position of crossing axis ------------------------------------------
316cdf0e10cSrcweir 
317cdf0e10cSrcweir         bool bManualCrossing = mrModel.mofCrossesAt.has();
318cdf0e10cSrcweir         cssc::ChartAxisPosition eAxisPos = cssc::ChartAxisPosition_VALUE;
319cdf0e10cSrcweir         if( !bManualCrossing ) switch( mrModel.mnCrossMode )
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             case XML_min:       eAxisPos = cssc::ChartAxisPosition_START;   break;
322cdf0e10cSrcweir             case XML_max:       eAxisPos = cssc::ChartAxisPosition_END;     break;
323cdf0e10cSrcweir             case XML_autoZero:  eAxisPos = cssc::ChartAxisPosition_VALUE;   break;
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir         aAxisProp.setProperty( PROP_CrossoverPosition, eAxisPos );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir         // calculate automatic origin depending on scaling mode of crossing axis
328cdf0e10cSrcweir         bool bCrossingLogScale = pCrossingAxis && lclIsLogarithmicScale( *pCrossingAxis );
329cdf0e10cSrcweir         double fCrossingPos = bManualCrossing ? mrModel.mofCrossesAt.get() : (bCrossingLogScale ? 1.0 : 0.0);
330cdf0e10cSrcweir         aAxisProp.setProperty( PROP_CrossoverValue, fCrossingPos );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         // axis title ---------------------------------------------------------
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         // in radar charts, title objects may exist, but are not shown
335cdf0e10cSrcweir         if( mrModel.mxTitle.is() && (rTypeGroup.getTypeInfo().meTypeCategory != TYPECATEGORY_RADAR) )
336cdf0e10cSrcweir         {
337cdf0e10cSrcweir             Reference< XTitled > xTitled( xAxis, UNO_QUERY_THROW );
338cdf0e10cSrcweir             TitleConverter aTitleConv( *this, *mrModel.mxTitle );
339cdf0e10cSrcweir             aTitleConv.convertFromModel( xTitled, CREATE_OUSTRING( "Axis Title" ), OBJECTTYPE_AXISTITLE, nAxesSetIdx, nAxisIdx );
340cdf0e10cSrcweir         }
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir     catch( Exception& )
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir     }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     if( xAxis.is() && rxCoordSystem.is() ) try
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         // insert axis into coordinate system
349cdf0e10cSrcweir         rxCoordSystem->setAxisByDimension( nAxisIdx, xAxis, nAxesSetIdx );
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir     catch( Exception& )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         OSL_ENSURE( false, "AxisConverter::convertFromModel - cannot insert axis into coordinate system" );
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir // ============================================================================
358cdf0e10cSrcweir 
359cdf0e10cSrcweir } // namespace chart
360cdf0e10cSrcweir } // namespace drawingml
361cdf0e10cSrcweir } // namespace oox
362