1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "VAxisBase.hxx" 32*cdf0e10cSrcweir #include "ShapeFactory.hxx" 33*cdf0e10cSrcweir #include "CommonConverters.hxx" 34*cdf0e10cSrcweir #include "Tickmarks.hxx" 35*cdf0e10cSrcweir #include "macros.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // header for define DBG_ASSERT 38*cdf0e10cSrcweir #include <tools/debug.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <memory> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //............................................................................. 43*cdf0e10cSrcweir namespace chart 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir //............................................................................. 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 48*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir VAxisBase::VAxisBase( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount 51*cdf0e10cSrcweir , const AxisProperties& rAxisProperties 52*cdf0e10cSrcweir , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier ) 53*cdf0e10cSrcweir : VAxisOrGridBase( nDimensionIndex, nDimensionCount ) 54*cdf0e10cSrcweir , m_xNumberFormatsSupplier( xNumberFormatsSupplier ) 55*cdf0e10cSrcweir , m_aAxisProperties( rAxisProperties ) 56*cdf0e10cSrcweir , m_bUseTextLabels( false ) 57*cdf0e10cSrcweir , m_bReCreateAllTickInfos( true ) 58*cdf0e10cSrcweir , m_bRecordMaximumTextSize(false) 59*cdf0e10cSrcweir , m_nMaximumTextWidthSoFar(0) 60*cdf0e10cSrcweir , m_nMaximumTextHeightSoFar(0) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir VAxisBase::~VAxisBase() 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir sal_Int32 VAxisBase::getDimensionCount() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir return m_nDimension; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize 74*cdf0e10cSrcweir , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize; 77*cdf0e10cSrcweir m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if( !m_aAxisProperties.m_bDisplayLabels ) 80*cdf0e10cSrcweir return; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir if( AxisType::SERIES==m_aAxisProperties.m_nAxisType ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir if( m_aAxisProperties.m_xAxisTextProvider.is() ) 85*cdf0e10cSrcweir m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData(); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir m_bUseTextLabels = true; 88*cdf0e10cSrcweir if( m_aTextLabels.getLength() == 1 ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir //don't show a single series name 91*cdf0e10cSrcweir m_aAxisProperties.m_bDisplayLabels = false; 92*cdf0e10cSrcweir return; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir if( m_aAxisProperties.m_pExplicitCategoriesProvider ) 98*cdf0e10cSrcweir m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories(); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir m_bUseTextLabels = true; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey; 104*cdf0e10cSrcweir m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel); 105*cdf0e10cSrcweir if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType ) 106*cdf0e10cSrcweir m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir bool VAxisBase::isDateAxis() const 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir return AxisType::DATE == m_aScale.AxisType; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir bool VAxisBase::isComplexCategoryAxis() const 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir if( m_bRecordMaximumTextSize && xShape.is() ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir awt::Size aSize( ShapeFactory::getSizeAfterRotation( 123*cdf0e10cSrcweir xShape, fRotationAngleDegree ) ); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width ); 126*cdf0e10cSrcweir m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount() 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir return 10; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis ) 138*cdf0e10cSrcweir delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis; 139*cdf0e10cSrcweir m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir sal_Bool VAxisBase::isAnythingToDraw() 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if( !m_aAxisProperties.m_xAxisModel.is() ) 145*cdf0e10cSrcweir return false; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized"); 148*cdf0e10cSrcweir if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is())) 149*cdf0e10cSrcweir return false; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY ); 152*cdf0e10cSrcweir if( xProps.is() ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir sal_Bool bShow = sal_False; 155*cdf0e10cSrcweir xProps->getPropertyValue( C2U( "Show" ) ) >>= bShow; 156*cdf0e10cSrcweir if( !bShow ) 157*cdf0e10cSrcweir return false; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir return true; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir void VAxisBase::setExplicitScaleAndIncrement( 163*cdf0e10cSrcweir const ExplicitScaleData& rScale 164*cdf0e10cSrcweir , const ExplicitIncrementData& rIncrement ) 165*cdf0e10cSrcweir throw (uno::RuntimeException) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir m_bReCreateAllTickInfos = true; 168*cdf0e10cSrcweir m_aScale = rScale; 169*cdf0e10cSrcweir m_aIncrement = rIncrement; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() ); 175*cdf0e10cSrcweir if( m_aScale.ShiftedCategoryPosition ) 176*cdf0e10cSrcweir apTickFactory->getAllTicksShifted( rAllTickInfos ); 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir apTickFactory->getAllTicks( rAllTickInfos ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir bool VAxisBase::prepareShapeCreation() 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir //returns true if all is ready for further shape creation and any shapes need to be created 184*cdf0e10cSrcweir if( !isAnythingToDraw() ) 185*cdf0e10cSrcweir return false; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if( m_bReCreateAllTickInfos ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir //----------------------------------------- 190*cdf0e10cSrcweir //create all scaled tickmark values 191*cdf0e10cSrcweir removeTextShapesFromTicks(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir createAllTickInfos(m_aAllTickInfos); 194*cdf0e10cSrcweir m_bReCreateAllTickInfos = false; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir if( m_xGroupShape_Shapes.is() ) 198*cdf0e10cSrcweir return true; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //----------------------------------------- 201*cdf0e10cSrcweir //create named group shape 202*cdf0e10cSrcweir m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : C2U("")); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir if( m_aAxisProperties.m_bDisplayLabels ) 205*cdf0e10cSrcweir m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir return true; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< rtl::OUString >& rLabels ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir sal_Int32 nRet = 0; 213*cdf0e10cSrcweir sal_Int32 nLength = 0; 214*cdf0e10cSrcweir sal_Int32 nN = 0; 215*cdf0e10cSrcweir for( nN=0; nN<rLabels.getLength(); nN++ ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir //todo: get real text width (without creating shape) instead of character count 218*cdf0e10cSrcweir if( rLabels[nN].getLength() > nLength ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir nLength = rLabels[nN].getLength(); 221*cdf0e10cSrcweir nRet = nN; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir return nRet; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void VAxisBase::removeTextShapesFromTicks() 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir if( m_xTextTarget.is() ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin(); 232*cdf0e10cSrcweir const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = m_aAllTickInfos.end(); 233*cdf0e10cSrcweir for( ; aDepthIter != aDepthEnd; aDepthIter++ ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin(); 236*cdf0e10cSrcweir const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); 237*cdf0e10cSrcweir for( ; aTickIter != aTickEnd; aTickIter++ ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir TickInfo& rTickInfo = (*aTickIter); 240*cdf0e10cSrcweir if(rTickInfo.xTextShape.is()) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir m_xTextTarget->remove(rTickInfo.xTextShape); 243*cdf0e10cSrcweir rTickInfo.xTextShape = NULL; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir Reference< XScaling > xInverseScaling( NULL ); 253*cdf0e10cSrcweir if( m_aScale.Scaling.is() ) 254*cdf0e10cSrcweir xInverseScaling = m_aScale.Scaling->getInverseScaling(); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir for( TickInfo* pTickInfo = rIter.firstInfo() 257*cdf0e10cSrcweir ; pTickInfo; pTickInfo = rIter.nextInfo() ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir //............................................................................. 264*cdf0e10cSrcweir } //namespace chart 265*cdf0e10cSrcweir //............................................................................. 266