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 <ExplicitCategoriesProvider.hxx>
23 #include "Tickmarks.hxx"
24 #include <com/sun/star/drawing/XShapes.hpp>
25 #include <com/sun/star/chart2/AxisType.hpp>
26 #include <com/sun/star/chart2/XAxis.hpp>
27 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <osl/diagnose.h>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::chart2
;
38 using ::com::sun::star::uno::Reference
;
40 VAxisBase::VAxisBase( sal_Int32 nDimensionIndex
, sal_Int32 nDimensionCount
41 , const AxisProperties
& rAxisProperties
42 , const uno::Reference
< util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
)
43 : VAxisOrGridBase( nDimensionIndex
, nDimensionCount
)
44 , m_xNumberFormatsSupplier( xNumberFormatsSupplier
)
45 , m_aAxisProperties( rAxisProperties
)
46 , m_bUseTextLabels( false )
47 , m_bReCreateAllTickInfos( true )
48 , m_bRecordMaximumTextSize(false)
49 , m_nMaximumTextWidthSoFar(0)
50 , m_nMaximumTextHeightSoFar(0)
54 VAxisBase::~VAxisBase()
58 void VAxisBase::initAxisLabelProperties( const css::awt::Size
& rFontReferenceSize
59 , const css::awt::Rectangle
& rMaximumSpaceForLabels
)
61 m_aAxisLabelProperties
.m_aFontReferenceSize
= rFontReferenceSize
;
62 m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
= rMaximumSpaceForLabels
;
64 if( !m_aAxisProperties
.m_bDisplayLabels
)
67 if( m_aAxisProperties
.m_nAxisType
==AxisType::SERIES
)
69 if( m_aAxisProperties
.m_xAxisTextProvider
.is() )
70 m_aTextLabels
= m_aAxisProperties
.m_xAxisTextProvider
->getTextualData();
72 m_bUseTextLabels
= true;
73 if( m_aTextLabels
.getLength() == 1 )
75 //don't show a single series name
76 m_aAxisProperties
.m_bDisplayLabels
= false;
80 else if( m_aAxisProperties
.m_nAxisType
==AxisType::CATEGORY
)
82 if( m_aAxisProperties
.m_pExplicitCategoriesProvider
)
83 m_aTextLabels
= m_aAxisProperties
.m_pExplicitCategoriesProvider
->getSimpleCategories();
85 m_bUseTextLabels
= true;
88 m_aAxisLabelProperties
.nNumberFormatKey
= m_aAxisProperties
.m_nNumberFormatKey
;
89 m_aAxisLabelProperties
.init(m_aAxisProperties
.m_xAxisModel
);
90 if( m_aAxisProperties
.m_bComplexCategories
&& m_aAxisProperties
.m_nAxisType
== AxisType::CATEGORY
)
91 m_aAxisLabelProperties
.eStaggering
= AxisLabelStaggering::SideBySide
;
94 bool VAxisBase::isDateAxis() const
96 return m_aScale
.AxisType
== AxisType::DATE
;
98 bool VAxisBase::isComplexCategoryAxis() const
100 return m_aAxisProperties
.m_bComplexCategories
&& m_bUseTextLabels
;
103 void VAxisBase::recordMaximumTextSize( const Reference
< drawing::XShape
>& xShape
, double fRotationAngleDegree
)
105 if( m_bRecordMaximumTextSize
&& xShape
.is() )
107 awt::Size
aSize( ShapeFactory::getSizeAfterRotation(
108 xShape
, fRotationAngleDegree
) );
110 m_nMaximumTextWidthSoFar
= std::max( m_nMaximumTextWidthSoFar
, aSize
.Width
);
111 m_nMaximumTextHeightSoFar
= std::max( m_nMaximumTextHeightSoFar
, aSize
.Height
);
115 sal_Int32
VAxisBase::estimateMaximumAutoMainIncrementCount()
120 void VAxisBase::setExtraLinePositionAtOtherAxis( double fCrossingAt
)
122 m_aAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
= fCrossingAt
;
125 sal_Int32
VAxisBase::getDimensionCount() const
130 bool VAxisBase::isAnythingToDraw()
132 if( !m_aAxisProperties
.m_xAxisModel
.is() )
135 OSL_ENSURE(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
136 if(!(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
139 uno::Reference
< beans::XPropertySet
> xProps( m_aAxisProperties
.m_xAxisModel
, uno::UNO_QUERY
);
143 xProps
->getPropertyValue( "Show" ) >>= bShow
;
150 void VAxisBase::setExplicitScaleAndIncrement(
151 const ExplicitScaleData
& rScale
152 , const ExplicitIncrementData
& rIncrement
)
154 m_bReCreateAllTickInfos
= true;
156 m_aIncrement
= rIncrement
;
159 void VAxisBase::createAllTickInfos( TickInfoArraysType
& rAllTickInfos
)
161 std::unique_ptr
< TickFactory
> apTickFactory( createTickFactory() );
162 if( m_aScale
.ShiftedCategoryPosition
)
163 apTickFactory
->getAllTicksShifted( rAllTickInfos
);
165 apTickFactory
->getAllTicks( rAllTickInfos
);
168 bool VAxisBase::prepareShapeCreation()
170 //returns true if all is ready for further shape creation and any shapes need to be created
171 if( !isAnythingToDraw() )
174 if( m_bReCreateAllTickInfos
)
176 //create all scaled tickmark values
177 removeTextShapesFromTicks();
179 createAllTickInfos(m_aAllTickInfos
);
180 m_bReCreateAllTickInfos
= false;
183 if( m_xGroupShape_Shapes
.is() )
186 //create named group shape
187 m_xGroupShape_Shapes
= createGroupShape( m_xLogicTarget
, m_nDimension
==2 ? m_aCID
: "");
189 if( m_aAxisProperties
.m_bDisplayLabels
)
190 m_xTextTarget
= m_pShapeFactory
->createGroup2D( m_xFinalTarget
, m_aCID
);
195 size_t VAxisBase::getIndexOfLongestLabel( const uno::Sequence
<OUString
>& rLabels
)
198 sal_Int32 nLength
= 0;
200 for( nN
=0; nN
<rLabels
.getLength(); nN
++ )
202 //todo: get real text width (without creating shape) instead of character count
203 if( rLabels
[nN
].getLength() > nLength
)
205 nLength
= rLabels
[nN
].getLength();
214 void VAxisBase::removeTextShapesFromTicks()
216 if( !m_xTextTarget
.is() )
219 for (auto & tickInfos
: m_aAllTickInfos
)
221 for (auto & tickInfo
: tickInfos
)
223 if(tickInfo
.xTextShape
.is())
225 m_xTextTarget
->remove(tickInfo
.xTextShape
);
226 tickInfo
.xTextShape
= nullptr;
232 void VAxisBase::updateUnscaledValuesAtTicks( TickIter
& rIter
)
234 Reference
< XScaling
> xInverseScaling
;
235 if( m_aScale
.Scaling
.is() )
236 xInverseScaling
= m_aScale
.Scaling
->getInverseScaling();
238 for( TickInfo
* pTickInfo
= rIter
.firstInfo()
239 ; pTickInfo
; pTickInfo
= rIter
.nextInfo() )
241 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */