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