1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "VAxisBase.hxx"
21 #include <ShapeFactory.hxx>
22 #include <CommonConverters.hxx>
23 #include "Tickmarks.hxx"
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::chart2
;
31 using ::com::sun::star::uno::Reference
;
33 VAxisBase::VAxisBase( sal_Int32 nDimensionIndex
, sal_Int32 nDimensionCount
34 , const AxisProperties
& rAxisProperties
35 , const uno::Reference
< util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
)
36 : VAxisOrGridBase( nDimensionIndex
, nDimensionCount
)
37 , m_xNumberFormatsSupplier( xNumberFormatsSupplier
)
38 , m_aAxisProperties( rAxisProperties
)
39 , m_bUseTextLabels( false )
40 , m_bReCreateAllTickInfos( true )
41 , m_bRecordMaximumTextSize(false)
42 , m_nMaximumTextWidthSoFar(0)
43 , m_nMaximumTextHeightSoFar(0)
47 VAxisBase::~VAxisBase()
51 void VAxisBase::initAxisLabelProperties( const css::awt::Size
& rFontReferenceSize
52 , const css::awt::Rectangle
& rMaximumSpaceForLabels
)
54 m_aAxisLabelProperties
.m_aFontReferenceSize
= rFontReferenceSize
;
55 m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
= rMaximumSpaceForLabels
;
57 if( !m_aAxisProperties
.m_bDisplayLabels
)
60 if( m_aAxisProperties
.m_nAxisType
==AxisType::SERIES
)
62 if( m_aAxisProperties
.m_xAxisTextProvider
.is() )
63 m_aTextLabels
= m_aAxisProperties
.m_xAxisTextProvider
->getTextualData();
65 m_bUseTextLabels
= true;
66 if( m_aTextLabels
.getLength() == 1 )
68 //don't show a single series name
69 m_aAxisProperties
.m_bDisplayLabels
= false;
73 else if( m_aAxisProperties
.m_nAxisType
==AxisType::CATEGORY
)
75 if( m_aAxisProperties
.m_pExplicitCategoriesProvider
)
76 m_aTextLabels
= m_aAxisProperties
.m_pExplicitCategoriesProvider
->getSimpleCategories();
78 m_bUseTextLabels
= true;
81 m_aAxisLabelProperties
.nNumberFormatKey
= m_aAxisProperties
.m_nNumberFormatKey
;
82 m_aAxisLabelProperties
.init(m_aAxisProperties
.m_xAxisModel
);
83 if( m_aAxisProperties
.m_bComplexCategories
&& m_aAxisProperties
.m_nAxisType
== AxisType::CATEGORY
)
84 m_aAxisLabelProperties
.eStaggering
= SIDE_BY_SIDE
;
87 bool VAxisBase::isDateAxis() const
89 return m_aScale
.AxisType
== AxisType::DATE
;
91 bool VAxisBase::isComplexCategoryAxis() const
93 return m_aAxisProperties
.m_bComplexCategories
&& m_bUseTextLabels
;
96 void VAxisBase::recordMaximumTextSize( const Reference
< drawing::XShape
>& xShape
, double fRotationAngleDegree
)
98 if( m_bRecordMaximumTextSize
&& xShape
.is() )
100 awt::Size
aSize( ShapeFactory::getSizeAfterRotation(
101 xShape
, fRotationAngleDegree
) );
103 m_nMaximumTextWidthSoFar
= std::max( m_nMaximumTextWidthSoFar
, aSize
.Width
);
104 m_nMaximumTextHeightSoFar
= std::max( m_nMaximumTextHeightSoFar
, aSize
.Height
);
108 sal_Int32
VAxisBase::estimateMaximumAutoMainIncrementCount()
113 void VAxisBase::setExtraLinePositionAtOtherAxis( double fCrossingAt
)
115 m_aAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
.reset(fCrossingAt
);
118 sal_Int32
VAxisBase::getDimensionCount() const
123 bool VAxisBase::isAnythingToDraw()
125 if( !m_aAxisProperties
.m_xAxisModel
.is() )
128 OSL_ENSURE(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
129 if(!(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
132 uno::Reference
< beans::XPropertySet
> xProps( m_aAxisProperties
.m_xAxisModel
, uno::UNO_QUERY
);
136 xProps
->getPropertyValue( "Show" ) >>= bShow
;
143 void VAxisBase::setExplicitScaleAndIncrement(
144 const ExplicitScaleData
& rScale
145 , const ExplicitIncrementData
& rIncrement
)
147 m_bReCreateAllTickInfos
= true;
149 m_aIncrement
= rIncrement
;
152 void VAxisBase::createAllTickInfos( TickInfoArraysType
& rAllTickInfos
)
154 std::unique_ptr
< TickFactory
> apTickFactory( createTickFactory() );
155 if( m_aScale
.ShiftedCategoryPosition
)
156 apTickFactory
->getAllTicksShifted( rAllTickInfos
);
158 apTickFactory
->getAllTicks( rAllTickInfos
);
161 bool VAxisBase::prepareShapeCreation()
163 //returns true if all is ready for further shape creation and any shapes need to be created
164 if( !isAnythingToDraw() )
167 if( m_bReCreateAllTickInfos
)
169 //create all scaled tickmark values
170 removeTextShapesFromTicks();
172 createAllTickInfos(m_aAllTickInfos
);
173 m_bReCreateAllTickInfos
= false;
176 if( m_xGroupShape_Shapes
.is() )
179 //create named group shape
180 m_xGroupShape_Shapes
= createGroupShape( m_xLogicTarget
, m_nDimension
==2 ? m_aCID
: "");
182 if( m_aAxisProperties
.m_bDisplayLabels
)
183 m_xTextTarget
= m_pShapeFactory
->createGroup2D( m_xFinalTarget
, m_aCID
);
188 size_t VAxisBase::getIndexOfLongestLabel( const uno::Sequence
<OUString
>& rLabels
)
191 sal_Int32 nLength
= 0;
193 for( nN
=0; nN
<rLabels
.getLength(); nN
++ )
195 //todo: get real text width (without creating shape) instead of character count
196 if( rLabels
[nN
].getLength() > nLength
)
198 nLength
= rLabels
[nN
].getLength();
207 void VAxisBase::removeTextShapesFromTicks()
209 if( m_xTextTarget
.is() )
211 for (auto & tickInfos
: m_aAllTickInfos
)
213 for (auto & tickInfo
: tickInfos
)
215 if(tickInfo
.xTextShape
.is())
217 m_xTextTarget
->remove(tickInfo
.xTextShape
);
218 tickInfo
.xTextShape
= nullptr;
225 void VAxisBase::updateUnscaledValuesAtTicks( TickIter
& rIter
)
227 Reference
< XScaling
> xInverseScaling( nullptr );
228 if( m_aScale
.Scaling
.is() )
229 xInverseScaling
= m_aScale
.Scaling
->getInverseScaling();
231 for( TickInfo
* pTickInfo
= rIter
.firstInfo()
232 ; pTickInfo
; pTickInfo
= rIter
.nextInfo() )
234 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */