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 <AbstractShapeFactory.hxx>
25 #include <NumberFormatterWrapper.hxx>
26 #include <PolarLabelPositionHelper.hxx>
27 #include <tools/color.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::chart2
;
35 using namespace ::rtl::math
;
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 bool VPolarAngleAxis::createTextShapes_ForAngleAxis(
49 const uno::Reference
< drawing::XShapes
>& xTarget
50 , EquidistantTickIter
& rTickIter
51 , AxisLabelProperties
const & rAxisLabelProperties
55 AbstractShapeFactory
* pShapeFactory
= AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory
);
57 FixedNumberFormatter
aFixedNumberFormatter(
58 m_xNumberFormatsSupplier
, rAxisLabelProperties
.nNumberFormatKey
);
60 //prepare text properties for multipropertyset-interface of shape
61 tNameSequence aPropNames
;
62 tAnySequence aPropValues
;
64 uno::Reference
< beans::XPropertySet
> xProps( m_aAxisProperties
.m_xAxisModel
, uno::UNO_QUERY
);
65 PropertyMapper::getTextLabelMultiPropertyLists( xProps
, aPropNames
, aPropValues
, false, -1, false, false );
66 LabelPositionHelper::doDynamicFontResize( aPropValues
, aPropNames
, xProps
67 , rAxisLabelProperties
.m_aFontReferenceSize
);
69 uno::Any
* pColorAny
= PropertyMapper::getValuePointer(aPropValues
,aPropNames
,"CharColor");
70 Color nColor
= COL_AUTO
;
72 *pColorAny
>>= nColor
;
74 const uno::Sequence
< OUString
>* pLabels
= m_bUseTextLabels
? &m_aTextLabels
: nullptr;
76 //TickInfo* pLastVisibleNeighbourTickInfo = NULL;
79 for( TickInfo
* pTickInfo
= rTickIter
.firstInfo()
81 ; pTickInfo
= rTickIter
.nextInfo(), nTick
++ )
83 //don't create labels which does not fit into the rhythm
84 if( nTick
%rAxisLabelProperties
.nRhythm
!= 0)
87 //don't create labels for invisible ticks
88 if( !pTickInfo
->bPaintIt
)
91 //if NO OVERLAP -> don't create labels where the
92 //anchor position is the same as for the last label
95 if(!pTickInfo
->xTextShape
.is())
98 bool bHasExtraColor
=false;
104 sal_Int32 nIndex
= static_cast< sal_Int32
>(pTickInfo
->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
105 if( nIndex
>=0 && nIndex
<pLabels
->getLength() )
106 aLabel
= (*pLabels
)[nIndex
];
109 aLabel
= aFixedNumberFormatter
.getFormattedString( pTickInfo
->getUnscaledTickValue(), nExtraColor
, bHasExtraColor
);
112 *pColorAny
<<= bHasExtraColor
?nExtraColor
:nColor
;
114 double fLogicAngle
= pTickInfo
->getUnscaledTickValue();
116 LabelAlignment
eLabelAlignment(LABEL_ALIGN_CENTER
);
117 PolarLabelPositionHelper
aPolarLabelPositionHelper(m_pPosHelper
.get(), 2/*nDimensionCount*/, xTarget
, pShapeFactory
);
118 sal_Int32 nScreenValueOffsetInRadiusDirection
= m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
.Height
/15;
119 awt::Point
aAnchorScreenPosition2D( aPolarLabelPositionHelper
.getLabelScreenPositionAndAlignmentForLogicValues(
120 eLabelAlignment
, fLogicAngle
, fLogicRadius
, fLogicZ
, nScreenValueOffsetInRadiusDirection
));
121 LabelPositionHelper::changeTextAdjustment( aPropValues
, aPropNames
, eLabelAlignment
);
123 // #i78696# use mathematically correct rotation now
124 const double fRotationAnglePi(rAxisLabelProperties
.fRotationAngleDegree
* (F_PI
/ -180.0));
126 uno::Any aATransformation
= AbstractShapeFactory::makeTransformation( aAnchorScreenPosition2D
, fRotationAnglePi
);
127 OUString aStackedLabel
= AbstractShapeFactory::getStackedString( aLabel
, rAxisLabelProperties
.bStackCharacters
);
129 pTickInfo
->xTextShape
= pShapeFactory
->createText( xTarget
, aStackedLabel
, aPropNames
, aPropValues
, aATransformation
);
132 //if NO OVERLAP -> remove overlapping shapes
138 void VPolarAngleAxis::createMaximumLabels()
140 if( !prepareShapeCreation() )
146 void VPolarAngleAxis::updatePositions()
148 //todo: really only update the positions
150 if( !prepareShapeCreation() )
156 void VPolarAngleAxis::createLabels()
158 if( !prepareShapeCreation() )
161 double fLogicRadius
= m_pPosHelper
->getOuterLogicRadius();
163 if( m_aAxisProperties
.m_bDisplayLabels
)
165 //get the transformed screen values for all tickmarks in aAllTickInfos
166 std::unique_ptr
< TickFactory
> apTickFactory( createTickFactory() );
168 //create tick mark text shapes
169 //@todo: iterate through all tick depth which should be labeled
171 EquidistantTickIter
aTickIter( m_aAllTickInfos
, m_aIncrement
, 0 );
172 updateUnscaledValuesAtTicks( aTickIter
);
174 removeTextShapesFromTicks();
176 AxisLabelProperties
aAxisLabelProperties( m_aAxisLabelProperties
);
177 aAxisLabelProperties
.bOverlapAllowed
= true;
178 double const fLogicZ
= 1.0;//as defined
179 while( !createTextShapes_ForAngleAxis( m_xTextTarget
, aTickIter
180 , aAxisLabelProperties
181 , fLogicRadius
, fLogicZ
186 //no staggering for polar angle axis
190 void VPolarAngleAxis::createShapes()
192 if( !prepareShapeCreation() )
195 double fLogicRadius
= m_pPosHelper
->getOuterLogicRadius();
196 double const fLogicZ
= 1.0;//as defined
198 //create axis main lines
199 drawing::PointSequenceSequence
aPoints(1);
200 VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints
, m_aAllTickInfos
, m_aIncrement
, m_aScale
, m_pPosHelper
.get(), fLogicRadius
, fLogicZ
);
201 uno::Reference
< drawing::XShape
> xShape
= m_pShapeFactory
->createLine2D(
202 m_xGroupShape_Shapes
, aPoints
, &m_aAxisProperties
.m_aLineProperties
);
203 //because of this name this line will be used for marking the axis
204 ::chart::AbstractShapeFactory::setShapeName( xShape
, "MarkHandles" );
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */