LibreOffice Module chart2 (master) 1
VPolarAngleAxis.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
21
22#include "VPolarAngleAxis.hxx"
23#include "VPolarGrid.hxx"
24#include <ShapeFactory.hxx>
25#include <Axis.hxx>
29#include <tools/color.hxx>
30
31#include <memory>
32
33namespace chart
34{
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37
39 , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
40 , sal_Int32 nDimensionCount )
41 : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 0/*nDimensionIndex*/, nDimensionCount )
42{
43}
44
46{
47}
48
51 , EquidistantTickIter& rTickIter
52 , AxisLabelProperties const & rAxisLabelProperties
53 , double fLogicRadius
54 , double fLogicZ )
55{
56 FixedNumberFormatter aFixedNumberFormatter(
57 m_xNumberFormatsSupplier, rAxisLabelProperties.m_nNumberFormatKey );
58
59 //prepare text properties for multipropertyset-interface of shape
61 tAnySequence aPropValues;
62
64 PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false, -1, false, false );
66 , rAxisLabelProperties.m_aFontReferenceSize );
67
68 uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,u"CharColor");
69 Color nColor = COL_AUTO;
70 if(pColorAny)
71 *pColorAny >>= nColor;
72
74
75 //TickInfo* pLastVisibleNeighbourTickInfo = NULL;
76 sal_Int32 nTick = 0;
77
78 for( TickInfo* pTickInfo = rTickIter.firstInfo()
79 ; pTickInfo
80 ; pTickInfo = rTickIter.nextInfo(), nTick++ )
81 {
82 //don't create labels which does not fit into the rhythm
83 if( nTick%rAxisLabelProperties.m_nRhythm != 0)
84 continue;
85
86 //don't create labels for invisible ticks
87 if( !pTickInfo->bPaintIt )
88 continue;
89
90 //if NO OVERLAP -> don't create labels where the
91 //anchor position is the same as for the last label
92 //@todo
93
94 if(!pTickInfo->xTextShape.is())
95 {
96 //create single label
97 bool bHasExtraColor=false;
98 Color nExtraColor;
99
100 OUString aLabel;
101 if(pLabels)
102 {
103 sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
104 if( nIndex>=0 && nIndex<pLabels->getLength() )
105 aLabel = (*pLabels)[nIndex];
106 }
107 else
108 aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor );
109
110 if(pColorAny)
111 *pColorAny <<= bHasExtraColor?nExtraColor:nColor;
112
113 double fLogicAngle = pTickInfo->getUnscaledTickValue();
114
115 LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER);
116 PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper.get(), 2/*nDimensionCount*/, xTarget);
117 sal_Int32 nScreenValueOffsetInRadiusDirection = m_aAxisLabelProperties.m_aMaximumSpaceForLabels.Height/15;
118 awt::Point aAnchorScreenPosition2D( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
119 eLabelAlignment, fLogicAngle, fLogicRadius, fLogicZ, nScreenValueOffsetInRadiusDirection ));
120 LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, eLabelAlignment );
121
122 // #i78696# use mathematically correct rotation now
123 const double fRotationAnglePi(-basegfx::deg2rad(rAxisLabelProperties.m_fRotationAngleDegree));
124
125 uno::Any aATransformation = ShapeFactory::makeTransformation( aAnchorScreenPosition2D, fRotationAnglePi );
126 OUString aStackedLabel = ShapeFactory::getStackedString( aLabel, rAxisLabelProperties.m_bStackCharacters );
127
128 pTickInfo->xTextShape = ShapeFactory::createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation );
129 }
130
131 //if NO OVERLAP -> remove overlapping shapes
132 //@todo
133 }
134}
135
137{
138 if( !prepareShapeCreation() )
139 return;
140
141 createLabels();
142}
143
145{
146 //todo: really only update the positions
147
148 if( !prepareShapeCreation() )
149 return;
150
151 createLabels();
152}
153
155{
156 if( !prepareShapeCreation() )
157 return;
158
159 double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
160
162 return;
163
164 //create tick mark text shapes
165 //@todo: iterate through all tick depth which should be labeled
166
168 updateUnscaledValuesAtTicks( aTickIter );
169
171
172 AxisLabelProperties aAxisLabelProperties( m_aAxisLabelProperties );
173 aAxisLabelProperties.m_bOverlapAllowed = true;
174 double const fLogicZ = 1.0;//as defined
176 , aAxisLabelProperties
177 , fLogicRadius, fLogicZ
178 );
179
180 //no staggering for polar angle axis
181}
182
184{
185 if( !prepareShapeCreation() )
186 return;
187
188 double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
189 double const fLogicZ = 1.0;//as defined
190
191 //create axis main lines
192 drawing::PointSequenceSequence aPoints(1);
196 //because of this name this line will be used for marking the axis
197 ::chart::ShapeFactory::setShapeName( xShape, "MarkHandles" );
198
199 //create labels
200 createLabels();
201}
202
203} //namespace chart
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual TickInfo * nextInfo() override
virtual TickInfo * firstInfo() override
OUString getFormattedString(double fValue, Color &rLabelColor, bool &rbColorChanged) const
static void changeTextAdjustment(tAnySequence &rPropValues, const tNameSequence &rPropNames, LabelAlignment eAlignment)
static void doDynamicFontResize(tAnySequence &rPropValues, const tNameSequence &rPropNames, const css::uno::Reference< css::beans::XPropertySet > &xAxisModelProps, const css::awt::Size &rNewReferenceSize)
css::awt::Point getLabelScreenPositionAndAlignmentForLogicValues(LabelAlignment &rAlignment, double fLogicValueOnAngleAxis, double fLogicValueOnRadiusAxis, double fLogicZ, sal_Int32 nScreenValueOffsetInRadiusDirection) const
static css::uno::Any * getValuePointer(tAnySequence &rPropValues, const tNameSequence &rPropNames, std::u16string_view rPropName)
static void getTextLabelMultiPropertyLists(const css::uno::Reference< css::beans::XPropertySet > &xSourceProp, tNameSequence &rPropNames, tAnySequence &rPropValues, bool bName=true, sal_Int32 nLimitedSpace=-1, bool bLimitedHeight=false, bool bSupportsLabelBorder=true)
static void setShapeName(const rtl::Reference< SvxShape > &xShape, const OUString &rName)
static OUString getStackedString(const OUString &rString, bool bStacked)
static rtl::Reference< SvxShapeText > createText(const rtl::Reference< SvxShapeGroupAnyD > &xTarget2D, const OUString &rText, const tNameSequence &rPropNames, const tAnySequence &rPropValues, const css::uno::Any &rATransformation)
static rtl::Reference< SvxShapePolyPolygon > createLine2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::drawing::PointSequenceSequence &rPoints, const VLineProperties *pLineProperties=nullptr)
static css::uno::Any makeTransformation(const css::awt::Point &rScreenPosition2D, double fRotationAnglePi=0.0)
AxisLabelProperties m_aAxisLabelProperties
Definition: VAxisBase.hxx:89
AxisProperties m_aAxisProperties
Definition: VAxisBase.hxx:88
css::uno::Sequence< OUString > m_aTextLabels
Definition: VAxisBase.hxx:90
virtual bool prepareShapeCreation()
Definition: VAxisBase.cxx:166
css::uno::Reference< css::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier
Definition: VAxisBase.hxx:87
void removeTextShapesFromTicks()
Definition: VAxisBase.cxx:214
void updateUnscaledValuesAtTicks(TickIter &rIter)
Definition: VAxisBase.cxx:232
rtl::Reference< SvxShapeGroupAnyD > m_xTextTarget
Definition: VAxisBase.hxx:94
rtl::Reference< SvxShapeGroupAnyD > m_xGroupShape_Shapes
Definition: VAxisBase.hxx:93
TickInfoArraysType m_aAllTickInfos
This typically consists of 2 TickInfo vectors (i.e.
Definition: VAxisBase.hxx:108
ExplicitScaleData m_aScale
ExplicitIncrementData m_aIncrement
virtual ~VPolarAngleAxis() override
virtual void createMaximumLabels() override
VPolarAngleAxis(const AxisProperties &rAxisProperties, const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier, sal_Int32 nDimensionCount)
void createTextShapes_ForAngleAxis(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, EquidistantTickIter &rTickIter, AxisLabelProperties const &rAxisLabelProperties, double fLogicRadius, double fLogicZ)
virtual void createLabels() override
virtual void updatePositions() override
virtual void createShapes() override
std::unique_ptr< PolarPlottingPositionHelper > m_pPosHelper
Definition: VPolarAxis.hxx:48
static void createLinePointSequence_ForAngleAxis(css::drawing::PointSequenceSequence &rPoints, TickInfoArraysType &rAllTickInfos, const ExplicitIncrementData &rIncrement, const ExplicitScaleData &rScale, PolarPlottingPositionHelper const *pPosHelper, double fLogicRadius, double fLogicZ)
Definition: VPolarGrid.cxx:66
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
float u
Reference< XInterface > xTarget
sal_Int32 nIndex
double getLength(const B2DPolygon &rCandidate)
constexpr double deg2rad(double v)
css::uno::Sequence< OUString > tNameSequence
@ LABEL_ALIGN_CENTER
css::uno::Sequence< css::uno::Any > tAnySequence
std::unique_ptr< uint8_t[]> pLabels
const PropertyStruct aPropNames[]
css::awt::Size m_aFontReferenceSize
css::awt::Rectangle m_aMaximumSpaceForLabels
VLineProperties m_aLineProperties
rtl::Reference<::chart::Axis > m_xAxisModel
OUString aLabel