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 <basegfx/numeric/ftools.hxx>
22 #include "VPolarAngleAxis.hxx"
23 #include "VPolarGrid.hxx"
24 #include <ShapeFactory.hxx>
26 #include <NumberFormatterWrapper.hxx>
27 #include <PolarLabelPositionHelper.hxx>
28 #include <PlottingPositionHelper.hxx>
29 #include <tools/color.hxx>
35 using namespace ::com::sun::star
;
37 VPolarAngleAxis::VPolarAngleAxis( const AxisProperties
& rAxisProperties
38 , const uno::Reference
< util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
39 , sal_Int32 nDimensionCount
)
40 : VPolarAxis( rAxisProperties
, xNumberFormatsSupplier
, 0/*nDimensionIndex*/, nDimensionCount
)
44 VPolarAngleAxis::~VPolarAngleAxis()
48 void VPolarAngleAxis::createTextShapes_ForAngleAxis(
49 const rtl::Reference
<SvxShapeGroupAnyD
>& xTarget
50 , EquidistantTickIter
& rTickIter
51 , AxisLabelProperties
const & rAxisLabelProperties
55 FixedNumberFormatter
aFixedNumberFormatter(
56 m_xNumberFormatsSupplier
, rAxisLabelProperties
.m_nNumberFormatKey
);
58 //prepare text properties for multipropertyset-interface of shape
59 tNameSequence aPropNames
;
60 tAnySequence aPropValues
;
62 uno::Reference
< beans::XPropertySet
> xProps( m_aAxisProperties
.m_xAxisModel
);
63 PropertyMapper::getTextLabelMultiPropertyLists( xProps
, aPropNames
, aPropValues
, false, -1, false, false );
64 LabelPositionHelper::doDynamicFontResize( aPropValues
, aPropNames
, xProps
65 , rAxisLabelProperties
.m_aFontReferenceSize
);
67 uno::Any
* pColorAny
= PropertyMapper::getValuePointer(aPropValues
,aPropNames
,u
"CharColor");
68 Color nColor
= COL_AUTO
;
70 *pColorAny
>>= nColor
;
72 const uno::Sequence
< OUString
>* pLabels
= m_bUseTextLabels
? &m_aTextLabels
: nullptr;
74 //TickInfo* pLastVisibleNeighbourTickInfo = NULL;
77 for( TickInfo
* pTickInfo
= rTickIter
.firstInfo()
79 ; pTickInfo
= rTickIter
.nextInfo(), nTick
++ )
81 //don't create labels which does not fit into the rhythm
82 if( nTick
%rAxisLabelProperties
.m_nRhythm
!= 0)
85 //don't create labels for invisible ticks
86 if( !pTickInfo
->bPaintIt
)
89 //if NO OVERLAP -> don't create labels where the
90 //anchor position is the same as for the last label
93 if(!pTickInfo
->xTextShape
.is())
96 bool bHasExtraColor
=false;
102 sal_Int32 nIndex
= static_cast< sal_Int32
>(pTickInfo
->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
103 if( nIndex
>=0 && nIndex
<pLabels
->getLength() )
104 aLabel
= (*pLabels
)[nIndex
];
107 aLabel
= aFixedNumberFormatter
.getFormattedString( pTickInfo
->getUnscaledTickValue(), nExtraColor
, bHasExtraColor
);
110 *pColorAny
<<= bHasExtraColor
?nExtraColor
:nColor
;
112 double fLogicAngle
= pTickInfo
->getUnscaledTickValue();
114 LabelAlignment
eLabelAlignment(LABEL_ALIGN_CENTER
);
115 PolarLabelPositionHelper
aPolarLabelPositionHelper(&m_aPosHelper
, 2/*nDimensionCount*/, xTarget
);
116 sal_Int32 nScreenValueOffsetInRadiusDirection
= m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
.Height
/15;
117 awt::Point
aAnchorScreenPosition2D( aPolarLabelPositionHelper
.getLabelScreenPositionAndAlignmentForLogicValues(
118 eLabelAlignment
, fLogicAngle
, fLogicRadius
, fLogicZ
, nScreenValueOffsetInRadiusDirection
));
119 LabelPositionHelper::changeTextAdjustment( aPropValues
, aPropNames
, eLabelAlignment
);
121 // #i78696# use mathematically correct rotation now
122 const double fRotationAnglePi(-basegfx::deg2rad(rAxisLabelProperties
.m_fRotationAngleDegree
));
124 uno::Any aATransformation
= ShapeFactory::makeTransformation( aAnchorScreenPosition2D
, fRotationAnglePi
);
125 OUString aStackedLabel
= ShapeFactory::getStackedString( aLabel
, rAxisLabelProperties
.m_bStackCharacters
);
127 pTickInfo
->xTextShape
= ShapeFactory::createText( xTarget
, aStackedLabel
, aPropNames
, aPropValues
, aATransformation
);
130 //if NO OVERLAP -> remove overlapping shapes
135 void VPolarAngleAxis::createMaximumLabels()
137 if( !prepareShapeCreation() )
143 void VPolarAngleAxis::updatePositions()
145 //todo: really only update the positions
147 if( !prepareShapeCreation() )
153 void VPolarAngleAxis::createLabels()
155 if( !prepareShapeCreation() )
158 double fLogicRadius
= m_aPosHelper
.getOuterLogicRadius();
160 if( !m_aAxisProperties
.m_bDisplayLabels
)
163 //create tick mark text shapes
164 //@todo: iterate through all tick depth which should be labeled
166 EquidistantTickIter
aTickIter( m_aAllTickInfos
, m_aIncrement
, 0 );
167 updateUnscaledValuesAtTicks( aTickIter
);
169 removeTextShapesFromTicks();
171 AxisLabelProperties
aAxisLabelProperties( m_aAxisLabelProperties
);
172 aAxisLabelProperties
.m_bOverlapAllowed
= true;
173 double const fLogicZ
= 1.0;//as defined
174 createTextShapes_ForAngleAxis( m_xTextTarget
, aTickIter
175 , aAxisLabelProperties
176 , fLogicRadius
, fLogicZ
179 //no staggering for polar angle axis
182 void VPolarAngleAxis::createShapes()
184 if( !prepareShapeCreation() )
187 double fLogicRadius
= m_aPosHelper
.getOuterLogicRadius();
188 double const fLogicZ
= 1.0;//as defined
190 //create axis main lines
191 drawing::PointSequenceSequence
aPoints(1);
192 VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints
, m_aAllTickInfos
, m_aIncrement
, m_aScale
, &m_aPosHelper
, fLogicRadius
, fLogicZ
);
193 rtl::Reference
<SvxShapePolyPolygon
> xShape
= ShapeFactory::createLine2D(
194 m_xGroupShape_Shapes
, aPoints
, &m_aAxisProperties
.m_aLineProperties
);
195 //because of this name this line will be used for marking the axis
196 ::chart::ShapeFactory::setShapeName( xShape
, u
"MarkHandles"_ustr
);
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */