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"
25 #include <VSeriesPlotter.hxx>
26 #include <com/sun/star/chart2/AxisType.hpp>
27 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
29 #include <osl/diagnose.h>
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::chart2
;
37 using ::com::sun::star::uno::Reference
;
39 VAxisBase::VAxisBase( sal_Int32 nDimensionIndex
, sal_Int32 nDimensionCount
40 , const AxisProperties
& rAxisProperties
41 , const uno::Reference
< util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
)
42 : VAxisOrGridBase( nDimensionIndex
, nDimensionCount
)
43 , m_xNumberFormatsSupplier( xNumberFormatsSupplier
)
44 , m_aAxisProperties( rAxisProperties
)
45 , m_bUseTextLabels( false )
46 , m_bReCreateAllTickInfos( true )
47 , m_bRecordMaximumTextSize(false)
48 , m_nMaximumTextWidthSoFar(0)
49 , m_nMaximumTextHeightSoFar(0)
53 VAxisBase::~VAxisBase()
57 void VAxisBase::initAxisLabelProperties( const css::awt::Size
& rFontReferenceSize
58 , const css::awt::Rectangle
& rMaximumSpaceForLabels
)
60 m_aAxisLabelProperties
.m_aFontReferenceSize
= rFontReferenceSize
;
61 m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
= rMaximumSpaceForLabels
;
63 if( !m_aAxisProperties
.m_bDisplayLabels
)
66 if( m_aAxisProperties
.m_nAxisType
==AxisType::SERIES
)
68 if( m_aAxisProperties
.m_xAxisTextProvider
.is() )
69 m_aTextLabels
= m_aAxisProperties
.m_xAxisTextProvider
->getTextualData();
71 m_bUseTextLabels
= true;
72 if( m_aTextLabels
.getLength() == 1 )
74 //don't show a single series name
75 m_aAxisProperties
.m_bDisplayLabels
= false;
79 else if( m_aAxisProperties
.m_nAxisType
==AxisType::CATEGORY
)
81 if( m_aAxisProperties
.m_pExplicitCategoriesProvider
)
82 m_aTextLabels
= m_aAxisProperties
.m_pExplicitCategoriesProvider
->getSimpleCategories();
84 m_bUseTextLabels
= true;
87 m_aAxisLabelProperties
.m_nNumberFormatKey
= m_aAxisProperties
.m_nNumberFormatKey
;
88 m_aAxisLabelProperties
.init(m_aAxisProperties
.m_xAxisModel
);
89 if( m_aAxisProperties
.m_bComplexCategories
&& m_aAxisProperties
.m_nAxisType
== AxisType::CATEGORY
)
90 m_aAxisLabelProperties
.m_eStaggering
= AxisLabelStaggering::SideBySide
;
93 bool VAxisBase::isDateAxis() const
95 return m_aScale
.AxisType
== AxisType::DATE
;
97 bool VAxisBase::isComplexCategoryAxis() const
99 return m_aAxisProperties
.m_bComplexCategories
&& m_bUseTextLabels
;
102 void VAxisBase::recordMaximumTextSize( SvxShape
& xShape
, double fRotationAngleDegree
)
104 if( m_bRecordMaximumTextSize
)
106 awt::Size
aSize( ShapeFactory::getSizeAfterRotation(
107 xShape
, fRotationAngleDegree
) );
109 m_nMaximumTextWidthSoFar
= std::max( m_nMaximumTextWidthSoFar
, aSize
.Width
);
110 m_nMaximumTextHeightSoFar
= std::max( m_nMaximumTextHeightSoFar
, aSize
.Height
);
114 sal_Int32
VAxisBase::estimateMaximumAutoMainIncrementCount()
119 void VAxisBase::setExtraLinePositionAtOtherAxis( double fCrossingAt
)
121 m_aAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
= fCrossingAt
;
124 sal_Int32
VAxisBase::getDimensionCount() const
129 bool VAxisBase::isAnythingToDraw()
131 if( !m_aAxisProperties
.m_xAxisModel
.is() )
134 OSL_ENSURE(m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
135 if(!(m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
138 if( m_aAxisProperties
.m_xAxisModel
.is() )
141 m_aAxisProperties
.m_xAxisModel
->getPropertyValue( u
"Show"_ustr
) >>= bShow
;
148 void VAxisBase::setExplicitScaleAndIncrement(
149 const ExplicitScaleData
& rScale
150 , const ExplicitIncrementData
& rIncrement
)
152 m_bReCreateAllTickInfos
= true;
154 m_aIncrement
= rIncrement
;
157 void VAxisBase::createAllTickInfos( TickInfoArraysType
& rAllTickInfos
)
159 std::unique_ptr
< TickFactory
> apTickFactory( createTickFactory() );
160 if( m_aScale
.m_bShiftedCategoryPosition
)
161 apTickFactory
->getAllTicksShifted( rAllTickInfos
);
163 apTickFactory
->getAllTicks( rAllTickInfos
);
166 bool VAxisBase::prepareShapeCreation()
168 //returns true if all is ready for further shape creation and any shapes need to be created
169 if( !isAnythingToDraw() )
172 if( m_bReCreateAllTickInfos
)
174 //create all scaled tickmark values
175 removeTextShapesFromTicks();
177 createAllTickInfos(m_aAllTickInfos
);
178 m_bReCreateAllTickInfos
= false;
181 if( m_xGroupShape_Shapes
.is() )
184 //create named group shape
185 m_xGroupShape_Shapes
= createGroupShape( m_xLogicTarget
, m_nDimension
==2 ? m_aCID
: u
""_ustr
);
187 if (m_aAxisProperties
.m_bDisplayLabels
)
188 m_xTextTarget
= ShapeFactory::createGroup2D( m_xFinalTarget
, m_aCID
);
189 if (m_aAxisProperties
.m_bDisplayDataTable
)
190 m_xDataTableTarget
= ShapeFactory::createGroup2D(m_xFinalTarget
);
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 );
245 void VAxisBase::createDataTableView(std::vector
<std::unique_ptr
<VSeriesPlotter
>>& /*rSeriesPlotterList*/,
246 uno::Reference
<util::XNumberFormatsSupplier
> const& /*xNumberFormatsSupplier*/,
247 rtl::Reference
<::chart::ChartModel
> const& /*xChartDoc*/,
248 css::uno::Reference
<css::uno::XComponentContext
> const& /*rComponentContext*/)
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */