/src/libreoffice/chart2/source/view/axes/VPolarAngleAxis.cxx
Line | Count | Source |
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 <basegfx/numeric/ftools.hxx> |
21 | | |
22 | | #include "VPolarAngleAxis.hxx" |
23 | | #include "VPolarGrid.hxx" |
24 | | #include <ShapeFactory.hxx> |
25 | | #include <Axis.hxx> |
26 | | #include <NumberFormatterWrapper.hxx> |
27 | | #include <PolarLabelPositionHelper.hxx> |
28 | | #include <PlottingPositionHelper.hxx> |
29 | | #include <tools/color.hxx> |
30 | | |
31 | | namespace chart |
32 | | { |
33 | | using namespace ::com::sun::star; |
34 | | |
35 | | VPolarAngleAxis::VPolarAngleAxis( const AxisProperties& rAxisProperties |
36 | | , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier |
37 | | , sal_Int32 nDimensionCount ) |
38 | 0 | : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 0/*nDimensionIndex*/, nDimensionCount ) |
39 | 0 | { |
40 | 0 | } |
41 | | |
42 | | VPolarAngleAxis::~VPolarAngleAxis() |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | void VPolarAngleAxis::createTextShapes_ForAngleAxis( |
47 | | const rtl::Reference<SvxShapeGroupAnyD>& xTarget |
48 | | , EquidistantTickIter& rTickIter |
49 | | , AxisLabelProperties const & rAxisLabelProperties |
50 | | , double fLogicRadius |
51 | | , double fLogicZ ) |
52 | 0 | { |
53 | 0 | FixedNumberFormatter aFixedNumberFormatter( |
54 | 0 | m_xNumberFormatsSupplier, rAxisLabelProperties.m_nNumberFormatKey ); |
55 | | |
56 | | //prepare text properties for multipropertyset-interface of shape |
57 | 0 | tNameSequence aPropNames; |
58 | 0 | tAnySequence aPropValues; |
59 | |
|
60 | 0 | rtl::Reference< ::chart::Axis > xProps( m_aAxisProperties.m_xAxisModel ); |
61 | 0 | PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false, -1, false, false ); |
62 | 0 | LabelPositionHelper::doDynamicFontResize( aPropValues, aPropNames, xProps |
63 | 0 | , rAxisLabelProperties.m_aFontReferenceSize ); |
64 | |
|
65 | 0 | uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,u"CharColor"); |
66 | 0 | Color nColor = COL_AUTO; |
67 | 0 | if(pColorAny) |
68 | 0 | *pColorAny >>= nColor; |
69 | |
|
70 | 0 | const uno::Sequence< OUString >* pLabels = m_bUseTextLabels? &m_aTextLabels : nullptr; |
71 | | |
72 | | //TickInfo* pLastVisibleNeighbourTickInfo = NULL; |
73 | 0 | sal_Int32 nTick = 0; |
74 | |
|
75 | 0 | for( TickInfo* pTickInfo = rTickIter.firstInfo() |
76 | 0 | ; pTickInfo |
77 | 0 | ; pTickInfo = rTickIter.nextInfo(), nTick++ ) |
78 | 0 | { |
79 | | //don't create labels which does not fit into the rhythm |
80 | 0 | if( nTick%rAxisLabelProperties.m_nRhythm != 0) |
81 | 0 | continue; |
82 | | |
83 | | //don't create labels for invisible ticks |
84 | 0 | if( !pTickInfo->bPaintIt ) |
85 | 0 | continue; |
86 | | |
87 | | //if NO OVERLAP -> don't create labels where the |
88 | | //anchor position is the same as for the last label |
89 | | //@todo |
90 | | |
91 | 0 | if(!pTickInfo->xTextShape.is()) |
92 | 0 | { |
93 | | //create single label |
94 | 0 | bool bHasExtraColor=false; |
95 | 0 | Color nExtraColor; |
96 | |
|
97 | 0 | OUString aLabel; |
98 | 0 | if(pLabels) |
99 | 0 | { |
100 | 0 | sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0 |
101 | 0 | if( nIndex>=0 && nIndex<pLabels->getLength() ) |
102 | 0 | aLabel = (*pLabels)[nIndex]; |
103 | 0 | } |
104 | 0 | else |
105 | 0 | aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor ); |
106 | |
|
107 | 0 | if(pColorAny) |
108 | 0 | *pColorAny <<= bHasExtraColor?nExtraColor:nColor; |
109 | |
|
110 | 0 | double fLogicAngle = pTickInfo->getUnscaledTickValue(); |
111 | |
|
112 | 0 | LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER); |
113 | 0 | PolarLabelPositionHelper aPolarLabelPositionHelper(&m_aPosHelper, 2/*nDimensionCount*/, xTarget); |
114 | 0 | sal_Int32 nScreenValueOffsetInRadiusDirection = m_aAxisLabelProperties.m_aMaximumSpaceForLabels.Height/15; |
115 | 0 | awt::Point aAnchorScreenPosition2D( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues( |
116 | 0 | eLabelAlignment, fLogicAngle, fLogicRadius, fLogicZ, nScreenValueOffsetInRadiusDirection )); |
117 | 0 | LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, eLabelAlignment ); |
118 | | |
119 | | // #i78696# use mathematically correct rotation now |
120 | 0 | const double fRotationAnglePi(-basegfx::deg2rad(rAxisLabelProperties.m_fRotationAngleDegree)); |
121 | |
|
122 | 0 | uno::Any aATransformation = ShapeFactory::makeTransformation( aAnchorScreenPosition2D, fRotationAnglePi ); |
123 | 0 | OUString aStackedLabel = ShapeFactory::getStackedString( aLabel, rAxisLabelProperties.m_bStackCharacters ); |
124 | |
|
125 | 0 | pTickInfo->xTextShape = ShapeFactory::createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation ); |
126 | 0 | } |
127 | | |
128 | | //if NO OVERLAP -> remove overlapping shapes |
129 | | //@todo |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | void VPolarAngleAxis::createMaximumLabels() |
134 | 0 | { |
135 | 0 | if( !prepareShapeCreation() ) |
136 | 0 | return; |
137 | | |
138 | 0 | createLabels(); |
139 | 0 | } |
140 | | |
141 | | void VPolarAngleAxis::updatePositions() |
142 | 0 | { |
143 | | //todo: really only update the positions |
144 | |
|
145 | 0 | if( !prepareShapeCreation() ) |
146 | 0 | return; |
147 | | |
148 | 0 | createLabels(); |
149 | 0 | } |
150 | | |
151 | | void VPolarAngleAxis::createLabels() |
152 | 0 | { |
153 | 0 | if( !prepareShapeCreation() ) |
154 | 0 | return; |
155 | | |
156 | 0 | double fLogicRadius = m_aPosHelper.getOuterLogicRadius(); |
157 | |
|
158 | 0 | if( !m_aAxisProperties.m_bDisplayLabels ) |
159 | 0 | return; |
160 | | |
161 | | //create tick mark text shapes |
162 | | //@todo: iterate through all tick depth which should be labeled |
163 | | |
164 | 0 | EquidistantTickIter aTickIter( m_aAllTickInfos, m_aIncrement, 0 ); |
165 | 0 | updateUnscaledValuesAtTicks( aTickIter ); |
166 | |
|
167 | 0 | removeTextShapesFromTicks(); |
168 | |
|
169 | 0 | AxisLabelProperties aAxisLabelProperties( m_aAxisLabelProperties ); |
170 | 0 | aAxisLabelProperties.m_bOverlapAllowed = true; |
171 | 0 | double const fLogicZ = 1.0;//as defined |
172 | 0 | createTextShapes_ForAngleAxis( m_xTextTarget, aTickIter |
173 | 0 | , aAxisLabelProperties |
174 | 0 | , fLogicRadius, fLogicZ |
175 | 0 | ); |
176 | | |
177 | | //no staggering for polar angle axis |
178 | 0 | } |
179 | | |
180 | | void VPolarAngleAxis::createShapes() |
181 | 0 | { |
182 | 0 | if( !prepareShapeCreation() ) |
183 | 0 | return; |
184 | | |
185 | 0 | double fLogicRadius = m_aPosHelper.getOuterLogicRadius(); |
186 | 0 | double const fLogicZ = 1.0;//as defined |
187 | | |
188 | | //create axis main lines |
189 | 0 | drawing::PointSequenceSequence aPoints(1); |
190 | 0 | VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, m_aAllTickInfos, m_aIncrement, m_aScale, &m_aPosHelper, fLogicRadius, fLogicZ ); |
191 | 0 | rtl::Reference<SvxShapePolyPolygon> xShape = ShapeFactory::createLine2D( |
192 | 0 | m_xGroupShape_Shapes, aPoints, &m_aAxisProperties.m_aLineProperties ); |
193 | | //because of this name this line will be used for marking the axis |
194 | 0 | ::chart::ShapeFactory::setShapeName( xShape, u"MarkHandles"_ustr ); |
195 | | |
196 | | //create labels |
197 | 0 | createLabels(); |
198 | 0 | } |
199 | | |
200 | | } //namespace chart |
201 | | |
202 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |