LibreOffice Module chart2 (master) 1
VAxisBase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "VAxisBase.hxx"
21#include <ShapeFactory.hxx>
23#include "Tickmarks.hxx"
24#include <Axis.hxx>
25#include <VSeriesPlotter.hxx>
26#include <com/sun/star/chart2/AxisType.hpp>
27#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
28
29#include <osl/diagnose.h>
30
31#include <memory>
32
33namespace chart
34{
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37using ::com::sun::star::uno::Reference;
38
39VAxisBase::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)
50{
51}
52
54{
55}
56
57void VAxisBase::initAxisLabelProperties( const css::awt::Size& rFontReferenceSize
58 , const css::awt::Rectangle& rMaximumSpaceForLabels )
59{
61 m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
62
64 return;
65
66 if( m_aAxisProperties.m_nAxisType==AxisType::SERIES )
67 {
70
71 m_bUseTextLabels = true;
72 if( m_aTextLabels.getLength() == 1 )
73 {
74 //don't show a single series name
76 return;
77 }
78 }
79 else if( m_aAxisProperties.m_nAxisType==AxisType::CATEGORY )
80 {
83
84 m_bUseTextLabels = true;
85 }
86
91}
92
94{
95 return m_aScale.AxisType == AxisType::DATE;
96}
98{
100}
101
102void VAxisBase::recordMaximumTextSize( SvxShape& xShape, double fRotationAngleDegree )
103{
105 {
106 awt::Size aSize( ShapeFactory::getSizeAfterRotation(
107 xShape, fRotationAngleDegree ) );
108
109 m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
110 m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
111 }
112}
113
115{
116 return 10;
117}
118
120{
122}
123
125{
126 return m_nDimension;
127}
128
130{
132 return false;
133
134 OSL_ENSURE(m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
135 if(!(m_xLogicTarget.is()&&m_xFinalTarget.is()))
136 return false;
137
139 {
140 bool bShow = false;
141 m_aAxisProperties.m_xAxisModel->getPropertyValue( "Show" ) >>= bShow;
142 if( !bShow )
143 return false;
144 }
145 return true;
146}
147
149 const ExplicitScaleData& rScale
150 , const ExplicitIncrementData& rIncrement )
151{
153 m_aScale = rScale;
154 m_aIncrement = rIncrement;
155}
156
158{
159 std::unique_ptr< TickFactory > apTickFactory( createTickFactory() );
161 apTickFactory->getAllTicksShifted( rAllTickInfos );
162 else
163 apTickFactory->getAllTicks( rAllTickInfos );
164}
165
167{
168 //returns true if all is ready for further shape creation and any shapes need to be created
169 if( !isAnythingToDraw() )
170 return false;
171
173 {
174 //create all scaled tickmark values
176
179 }
180
181 if( m_xGroupShape_Shapes.is() )
182 return true;
183
184 //create named group shape
186
191
192 return true;
193}
194
196{
197 sal_Int32 nRet = 0;
198 sal_Int32 nLength = 0;
199 sal_Int32 nN = 0;
200 for( nN=0; nN<rLabels.getLength(); nN++ )
201 {
202 //todo: get real text width (without creating shape) instead of character count
203 if( rLabels[nN].getLength() > nLength )
204 {
205 nLength = rLabels[nN].getLength();
206 nRet = nN;
207 }
208 }
209
210 assert(nRet >= 0);
211 return nRet;
212}
213
215{
216 if( !m_xTextTarget.is() )
217 return;
218
219 for (auto & tickInfos : m_aAllTickInfos)
220 {
221 for (auto & tickInfo : tickInfos)
222 {
223 if(tickInfo.xTextShape.is())
224 {
225 m_xTextTarget->remove(tickInfo.xTextShape);
226 tickInfo.xTextShape = nullptr;
227 }
228 }
229 }
230}
231
233{
234 Reference< XScaling > xInverseScaling;
235 if( m_aScale.Scaling.is() )
236 xInverseScaling = m_aScale.Scaling->getInverseScaling();
237
238 for( TickInfo* pTickInfo = rIter.firstInfo()
239 ; pTickInfo; pTickInfo = rIter.nextInfo() )
240 {
241 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
242 }
243}
244
245void 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*/)
249{
250}
251
252} //namespace chart
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< OUString > const & getSimpleCategories()
rtl::Reference< SvxShapeGroupAnyD > m_xLogicTarget
Definition: PlotterBase.hxx:69
rtl::Reference< SvxShapeGroupAnyD > m_xFinalTarget
Definition: PlotterBase.hxx:70
const sal_Int32 m_nDimension
Definition: PlotterBase.hxx:73
rtl::Reference< SvxShapeGroupAnyD > createGroupShape(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const OUString &rName=OUString())
Definition: PlotterBase.cxx:71
static css::awt::Size getSizeAfterRotation(SvxShape &rShape, double fRotationAngleDegree)
static rtl::Reference< SvxShapeGroup > createGroup2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const OUString &aName=OUString())
virtual TickInfo * nextInfo()=0
virtual TickInfo * firstInfo()=0
static size_t getIndexOfLongestLabel(const css::uno::Sequence< OUString > &rLabels)
Definition: VAxisBase.cxx:195
AxisLabelProperties m_aAxisLabelProperties
Definition: VAxisBase.hxx:89
virtual sal_Int32 estimateMaximumAutoMainIncrementCount()
Definition: VAxisBase.cxx:114
bool isDateAxis() const
Definition: VAxisBase.cxx:93
virtual void initAxisLabelProperties(const css::awt::Size &rFontReferenceSize, const css::awt::Rectangle &rMaximumSpaceForLabels)
Definition: VAxisBase.cxx:57
virtual void setExplicitScaleAndIncrement(const ExplicitScaleData &rScale, const ExplicitIncrementData &rIncrement) override
Definition: VAxisBase.cxx:148
virtual void createDataTableView(std::vector< std::unique_ptr< VSeriesPlotter > > &rSeriesPlotterList, css::uno::Reference< css::util::XNumberFormatsSupplier > const &xNumberFormatsSupplier, rtl::Reference<::chart::ChartModel > const &xChartDoc, css::uno::Reference< css::uno::XComponentContext > const &rComponentContext)
Definition: VAxisBase.cxx:245
sal_Int32 m_nMaximumTextWidthSoFar
Definition: VAxisBase.hxx:112
AxisProperties m_aAxisProperties
Definition: VAxisBase.hxx:88
css::uno::Sequence< OUString > m_aTextLabels
Definition: VAxisBase.hxx:90
VAxisBase(sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount, const AxisProperties &rAxisProperties, const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier)
Definition: VAxisBase.cxx:39
rtl::Reference< SvxShapeGroupAnyD > m_xDataTableTarget
Definition: VAxisBase.hxx:95
virtual ~VAxisBase() override
Definition: VAxisBase.cxx:53
virtual bool prepareShapeCreation()
Definition: VAxisBase.cxx:166
void recordMaximumTextSize(SvxShape &xShape, double fRotationAngleDegree)
Definition: VAxisBase.cxx:102
void removeTextShapesFromTicks()
Definition: VAxisBase.cxx:214
bool m_bRecordMaximumTextSize
Definition: VAxisBase.hxx:111
bool isComplexCategoryAxis() const
Definition: VAxisBase.cxx:97
void updateUnscaledValuesAtTicks(TickIter &rIter)
Definition: VAxisBase.cxx:232
rtl::Reference< SvxShapeGroupAnyD > m_xTextTarget
Definition: VAxisBase.hxx:94
sal_Int32 getDimensionCount() const
Return the number of dimensions the diagram has.
Definition: VAxisBase.cxx:124
rtl::Reference< SvxShapeGroupAnyD > m_xGroupShape_Shapes
Definition: VAxisBase.hxx:93
sal_Int32 m_nMaximumTextHeightSoFar
Definition: VAxisBase.hxx:113
virtual bool isAnythingToDraw()
Definition: VAxisBase.cxx:129
virtual void createAllTickInfos(TickInfoArraysType &rAllTickInfos)
Definition: VAxisBase.cxx:157
TickInfoArraysType m_aAllTickInfos
This typically consists of 2 TickInfo vectors (i.e.
Definition: VAxisBase.hxx:108
bool m_bReCreateAllTickInfos
Definition: VAxisBase.hxx:109
void setExtraLinePositionAtOtherAxis(double fCrossingAt)
Definition: VAxisBase.cxx:119
ExplicitScaleData m_aScale
virtual TickFactory * createTickFactory()
ExplicitIncrementData m_aIncrement
double getLength(const B2DPolygon &rCandidate)
std::vector< TickInfoArrayType > TickInfoArraysType
Definition: Tickmarks.hxx:59
css::awt::Size m_aFontReferenceSize
AxisLabelStaggering m_eStaggering
void init(const rtl::Reference< ::chart::Axis > &xAxisModel)
css::awt::Rectangle m_aMaximumSpaceForLabels
std::optional< double > m_pfExrtaLinePositionAtOtherAxis
css::uno::Reference< css::chart2::data::XTextualDataSequence > m_xAxisTextProvider
ExplicitCategoriesProvider * m_pExplicitCategoriesProvider
rtl::Reference<::chart::Axis > m_xAxisModel
describes how tickmarks are positioned on the scale of an axis.
This structure contains the explicit values for a scale like Minimum and Maximum.
css::uno::Reference< css::chart2::XScaling > Scaling
sal_Int32 nLength