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 "AxisHelper.hxx" 32*cdf0e10cSrcweir #include "DiagramHelper.hxx" 33*cdf0e10cSrcweir #include "ChartTypeHelper.hxx" 34*cdf0e10cSrcweir #include "macros.hxx" 35*cdf0e10cSrcweir #include "AxisIndexDefines.hxx" 36*cdf0e10cSrcweir #include "LineProperties.hxx" 37*cdf0e10cSrcweir #include "ContainerHelper.hxx" 38*cdf0e10cSrcweir #include "servicenames_coosystems.hxx" 39*cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 40*cdf0e10cSrcweir #include "Scaling.hxx" 41*cdf0e10cSrcweir #include "ChartModelHelper.hxx" 42*cdf0e10cSrcweir #include "DataSourceHelper.hxx" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <tools/debug.hxx> 45*cdf0e10cSrcweir #include <unotools/saveopt.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <com/sun/star/chart/ChartAxisPosition.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSource.hpp> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // header for class OUStringBuffer 55*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 56*cdf0e10cSrcweir #include <rtl/math.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceName.hpp> 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir #include <map> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //............................................................................. 64*cdf0e10cSrcweir namespace chart 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir //............................................................................. 67*cdf0e10cSrcweir using namespace ::com::sun::star; 68*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 69*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 70*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir Reference< chart2::XScaling > AxisHelper::createLinearScaling() 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir return new LinearScaling( 1.0, 0.0 ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir Reference< chart2::XScaling > AxisHelper::createLogarithmicScaling( double fBase ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir return new LogarithmicScaling( fBase ); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir ScaleData AxisHelper::createDefaultScale() 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir ScaleData aScaleData; 85*cdf0e10cSrcweir aScaleData.AxisType = chart2::AxisType::REALNUMBER; 86*cdf0e10cSrcweir aScaleData.AutoDateAxis = true; 87*cdf0e10cSrcweir aScaleData.ShiftedCategoryPosition = false;//this is adapted in the view code currently 88*cdf0e10cSrcweir Sequence< SubIncrement > aSubIncrements(1); 89*cdf0e10cSrcweir aSubIncrements[0] = SubIncrement(); 90*cdf0e10cSrcweir aScaleData.IncrementData.SubIncrements = aSubIncrements; 91*cdf0e10cSrcweir return aScaleData; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir void AxisHelper::removeExplicitScaling( ScaleData& rScaleData ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir uno::Any aEmpty; 97*cdf0e10cSrcweir rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty; 98*cdf0e10cSrcweir rScaleData.Scaling = 0; 99*cdf0e10cSrcweir ScaleData aDefaultScale( createDefaultScale() ); 100*cdf0e10cSrcweir rScaleData.IncrementData = aDefaultScale.IncrementData; 101*cdf0e10cSrcweir rScaleData.TimeIncrement = aDefaultScale.TimeIncrement; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir bool bReturn = false; 107*cdf0e10cSrcweir Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY ); 108*cdf0e10cSrcweir bReturn =( xServiceName.is() && (xServiceName->getServiceName()).equals( 109*cdf0e10cSrcweir C2U( "com.sun.star.chart2.LogarithmicScaling" ))); 110*cdf0e10cSrcweir return bReturn; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir chart2::ScaleData AxisHelper::getDateCheckedScale( const Reference< chart2::XAxis >& xAxis, const Reference< frame::XModel >& xChartModel ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir DBG_ASSERT(xChartModel.is(),"missing chart model"); 116*cdf0e10cSrcweir ScaleData aScale = xAxis->getScaleData(); 117*cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) ); 118*cdf0e10cSrcweir if( aScale.AutoDateAxis && aScale.AxisType == AxisType::CATEGORY ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0; 121*cdf0e10cSrcweir AxisHelper::getIndicesForAxis(xAxis, xCooSys, nDimensionIndex, nAxisIndex ); 122*cdf0e10cSrcweir bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex ); 123*cdf0e10cSrcweir if( bChartTypeAllowsDateAxis ) 124*cdf0e10cSrcweir aScale.AxisType = AxisType::DATE; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir if( aScale.AxisType == AxisType::DATE ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys,xChartModel ); 129*cdf0e10cSrcweir if( !aExplicitCategoriesProvider.isDateAxis() ) 130*cdf0e10cSrcweir aScale.AxisType = AxisType::CATEGORY; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir return aScale; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void AxisHelper::checkDateAxis( chart2::ScaleData& rScale, ExplicitCategoriesProvider* pExplicitCategoriesProvider, bool bChartTypeAllowsDateAxis ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir if( rScale.AutoDateAxis && rScale.AxisType == AxisType::CATEGORY && bChartTypeAllowsDateAxis ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir rScale.AxisType = AxisType::DATE; 140*cdf0e10cSrcweir removeExplicitScaling( rScale ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir if( rScale.AxisType == AxisType::DATE && (!pExplicitCategoriesProvider || !pExplicitCategoriesProvider->isDateAxis()) ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir rScale.AxisType = AxisType::CATEGORY; 145*cdf0e10cSrcweir removeExplicitScaling( rScale ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis( 150*cdf0e10cSrcweir const Reference< chart2::XAxis >& xAxis 151*cdf0e10cSrcweir , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem 152*cdf0e10cSrcweir , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier 153*cdf0e10cSrcweir , bool bSearchForParallelAxisIfNothingIsFound ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir sal_Int32 nNumberFormatKey(0); 156*cdf0e10cSrcweir bool bNumberFormatKeyFoundViaAttachedData = false; 157*cdf0e10cSrcweir sal_Int32 nAxisIndex = 0; 158*cdf0e10cSrcweir sal_Int32 nDimensionIndex = 1; 159*cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex ); 160*cdf0e10cSrcweir Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); 163*cdf0e10cSrcweir if( xProp.is() && !( xProp->getPropertyValue( C2U( "NumberFormat" ) ) >>= nNumberFormatKey ) ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir bool bFormatSet = false; 166*cdf0e10cSrcweir //check wether we have a percent scale -> use percent format 167*cdf0e10cSrcweir if( xNumberFormatsSupplier.is() ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir ScaleData aData = AxisHelper::getDateCheckedScale( xAxis, Reference< frame::XModel >( xNumberFormatsSupplier, uno::UNO_QUERY ) ); 170*cdf0e10cSrcweir if( aData.AxisType==AxisType::PERCENT ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir sal_Int32 nPercentFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier ); 173*cdf0e10cSrcweir if( nPercentFormat != -1 ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir nNumberFormatKey = nPercentFormat; 176*cdf0e10cSrcweir bFormatSet = true; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir else if( aData.AxisType==AxisType::DATE ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir if( aData.Categories.is() ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( aData.Categories->getValues()); 184*cdf0e10cSrcweir if( xSeq.is() && !( xChartDoc.is() && xChartDoc->hasInternalDataProvider()) ) 185*cdf0e10cSrcweir nNumberFormatKey = xSeq->getNumberFormatKeyByIndex( -1 ); 186*cdf0e10cSrcweir else 187*cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier ); 188*cdf0e10cSrcweir bFormatSet = true; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir else if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() && nDimensionIndex == 0 ) //maybe date axis 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram() ); 194*cdf0e10cSrcweir if( DiagramHelper::isSupportingDateAxis( xDiagram ) ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir else 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir Reference< data::XDataSource > xSource( DataSourceHelper::getUsedData( xChartDoc ) ); 201*cdf0e10cSrcweir if( xSource.is() ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aXValues( 204*cdf0e10cSrcweir DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), C2U("values-x"), true ) ); 205*cdf0e10cSrcweir if( aXValues.empty() ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) ); 208*cdf0e10cSrcweir if( xCategories.is() ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xCategories->getValues()); 211*cdf0e10cSrcweir if( xSeq.is() ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir bool bHasValidDoubles = false; 214*cdf0e10cSrcweir double fTest=0.0; 215*cdf0e10cSrcweir Sequence< uno::Any > aCats( xSeq->getData() ); 216*cdf0e10cSrcweir sal_Int32 nCount = aCats.getLength(); 217*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nCount; ++i ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if( (aCats[i]>>=fTest) && !::rtl::math::isNan(fTest) ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir bHasValidDoubles=true; 222*cdf0e10cSrcweir break; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir if( bHasValidDoubles ) 226*cdf0e10cSrcweir nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir bFormatSet = true; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir if( !bFormatSet ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency; 239*cdf0e10cSrcweir tNumberformatFrequency aKeyMap; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir try 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW ); 244*cdf0e10cSrcweir if( xCTCnt.is() ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir ::rtl::OUString aRoleToMatch; 247*cdf0e10cSrcweir if( nDimensionIndex == 0 ) 248*cdf0e10cSrcweir aRoleToMatch = C2U("values-x"); 249*cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes()); 250*cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir if( nDimensionIndex != 0 ) 253*cdf0e10cSrcweir aRoleToMatch = ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( aChartTypes[nCTIdx] ); 254*cdf0e10cSrcweir Reference< XDataSeriesContainer > xDSCnt( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW ); 255*cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aDataSeriesSeq( xDSCnt->getDataSeries()); 256*cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aDataSeriesSeq.getLength(); ++nSeriesIdx ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir Reference< chart2::XDataSeries > xDataSeries(aDataSeriesSeq[nSeriesIdx]); 259*cdf0e10cSrcweir Reference< data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY_THROW ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if( nDimensionIndex == 1 ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir //only take those series into accoutn that are attached to this axis 264*cdf0e10cSrcweir sal_Int32 nAttachedAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries); 265*cdf0e10cSrcweir if( nAttachedAxisIndex != nAxisIndex ) 266*cdf0e10cSrcweir continue; 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xLabeledSeq( 270*cdf0e10cSrcweir DataSeriesHelper::getDataSequenceByRole( xSource, aRoleToMatch ) ); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if( !xLabeledSeq.is() && nDimensionIndex==0 ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir ScaleData aData = xAxis->getScaleData(); 275*cdf0e10cSrcweir xLabeledSeq = aData.Categories; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if( xLabeledSeq.is() ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir Reference< data::XDataSequence > xSeq( xLabeledSeq->getValues()); 281*cdf0e10cSrcweir if( xSeq.is() ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 ); 284*cdf0e10cSrcweir // initialize the value 285*cdf0e10cSrcweir if( aKeyMap.find( nKey ) == aKeyMap.end()) 286*cdf0e10cSrcweir aKeyMap[ nKey ] = 0; 287*cdf0e10cSrcweir // increase frequency 288*cdf0e10cSrcweir aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir catch( const uno::Exception & ex ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir if( ! aKeyMap.empty()) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir sal_Int32 nMaxFreq = 0; 303*cdf0e10cSrcweir // find most frequent key 304*cdf0e10cSrcweir for( tNumberformatFrequency::const_iterator aIt = aKeyMap.begin(); 305*cdf0e10cSrcweir aIt != aKeyMap.end(); ++aIt ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir OSL_TRACE( "NumberFormatKey %d appears %d times", (*aIt).first, (*aIt).second ); 308*cdf0e10cSrcweir // all values must at least be 1 309*cdf0e10cSrcweir if( (*aIt).second > nMaxFreq ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir nNumberFormatKey = (*aIt).first; 312*cdf0e10cSrcweir bNumberFormatKeyFoundViaAttachedData = true; 313*cdf0e10cSrcweir nMaxFreq = (*aIt).second; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if( bSearchForParallelAxisIfNothingIsFound ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir //no format is set to this axis and no data is set to this axis 321*cdf0e10cSrcweir //--> try to obtain the format from the parallel y-axis 322*cdf0e10cSrcweir if( !bNumberFormatKeyFoundViaAttachedData && nDimensionIndex == 1 ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1; 325*cdf0e10cSrcweir Reference< XAxis > xParallelAxis( AxisHelper::getAxis( 1, nParallelAxisIndex, xCorrespondingCoordinateSystem ) ); 326*cdf0e10cSrcweir nNumberFormatKey = AxisHelper::getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false ); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir return nNumberFormatKey; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir Reference< XAxis > AxisHelper::createAxis( 335*cdf0e10cSrcweir sal_Int32 nDimensionIndex 336*cdf0e10cSrcweir , sal_Int32 nAxisIndex // 0==main or 1==secondary axis 337*cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys 338*cdf0e10cSrcweir , const Reference< uno::XComponentContext > & xContext 339*cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir if( !xContext.is() || !xCooSys.is() ) 342*cdf0e10cSrcweir return NULL; 343*cdf0e10cSrcweir if( nDimensionIndex >= xCooSys->getDimension() ) 344*cdf0e10cSrcweir return NULL; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir Reference< XAxis > xAxis( xContext->getServiceManager()->createInstanceWithContext( 347*cdf0e10cSrcweir C2U( "com.sun.star.chart2.Axis" ), xContext ), uno::UNO_QUERY ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir OSL_ASSERT( xAxis.is()); 350*cdf0e10cSrcweir if( xAxis.is()) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex ); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir if( nAxisIndex>0 )//when inserting secondary axes copy some things from the main axis 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir ::com::sun::star::chart::ChartAxisPosition eNewAxisPos( ::com::sun::star::chart::ChartAxisPosition_END ); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir Reference< XAxis > xMainAxis( xCooSys->getAxisByDimension( nDimensionIndex, 0 ) ); 359*cdf0e10cSrcweir if( xMainAxis.is() ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir ScaleData aScale = xAxis->getScaleData(); 362*cdf0e10cSrcweir ScaleData aMainScale = xMainAxis->getScaleData(); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir aScale.AxisType = aMainScale.AxisType; 365*cdf0e10cSrcweir aScale.AutoDateAxis = aMainScale.AutoDateAxis; 366*cdf0e10cSrcweir aScale.Categories = aMainScale.Categories; 367*cdf0e10cSrcweir aScale.Orientation = aMainScale.Orientation; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir xAxis->setScaleData( aScale ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir //ensure that the second axis is not placed on the main axis 372*cdf0e10cSrcweir Reference< beans::XPropertySet > xMainProp( xMainAxis, uno::UNO_QUERY ); 373*cdf0e10cSrcweir if( xMainProp.is() ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir ::com::sun::star::chart::ChartAxisPosition eMainAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO ); 376*cdf0e10cSrcweir xMainProp->getPropertyValue(C2U( "CrossoverPosition" )) >>= eMainAxisPos; 377*cdf0e10cSrcweir if( ::com::sun::star::chart::ChartAxisPosition_END == eMainAxisPos ) 378*cdf0e10cSrcweir eNewAxisPos = ::com::sun::star::chart::ChartAxisPosition_START; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); 383*cdf0e10cSrcweir if( xProp.is() ) 384*cdf0e10cSrcweir xProp->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos) ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); 388*cdf0e10cSrcweir if( xProp.is() ) try 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // set correct initial AutoScale 391*cdf0e10cSrcweir if( pRefSizeProvider ) 392*cdf0e10cSrcweir pRefSizeProvider->setValuesAtPropertySet( xProp ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir catch( uno::Exception& e ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir return xAxis; 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir Reference< XAxis > AxisHelper::createAxis( sal_Int32 nDimensionIndex, bool bMainAxis 403*cdf0e10cSrcweir , const Reference< chart2::XDiagram >& xDiagram 404*cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext 405*cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir OSL_ENSURE( xContext.is(), "need a context to create an axis" ); 408*cdf0e10cSrcweir if( !xContext.is() ) 409*cdf0e10cSrcweir return NULL; 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir sal_Int32 nAxisIndex = bMainAxis ? MAIN_AXIS_INDEX : SECONDARY_AXIS_INDEX; 412*cdf0e10cSrcweir sal_Int32 nCooSysIndex = 0; 413*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex ); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir // create axis 416*cdf0e10cSrcweir return AxisHelper::createAxis( 417*cdf0e10cSrcweir nDimensionIndex, nAxisIndex, xCooSys, xContext, pRefSizeProvider ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void AxisHelper::showAxis( sal_Int32 nDimensionIndex, bool bMainAxis 421*cdf0e10cSrcweir , const Reference< chart2::XDiagram >& xDiagram 422*cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext 423*cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir if( !xDiagram.is() ) 426*cdf0e10cSrcweir return; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir bool bNewAxisCreated = false; 429*cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) ); 430*cdf0e10cSrcweir if( !xAxis.is() && xContext.is() ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // create axis 433*cdf0e10cSrcweir bNewAxisCreated = true; 434*cdf0e10cSrcweir xAxis.set( AxisHelper::createAxis( nDimensionIndex, bMainAxis, xDiagram, xContext, pRefSizeProvider ) ); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir OSL_ASSERT( xAxis.is()); 438*cdf0e10cSrcweir if( !bNewAxisCreated ) //default is true already if created 439*cdf0e10cSrcweir AxisHelper::makeAxisVisible( xAxis ); 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir void AxisHelper::showGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid 443*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram 444*cdf0e10cSrcweir , const Reference< uno::XComponentContext >& /*xContext*/ ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir if( !xDiagram.is() ) 447*cdf0e10cSrcweir return; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex ); 450*cdf0e10cSrcweir if(!xCooSys.is()) 451*cdf0e10cSrcweir return; 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) ); 454*cdf0e10cSrcweir if(!xAxis.is()) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir //hhhh todo create axis without axis visibility 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir if(!xAxis.is()) 459*cdf0e10cSrcweir return; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir if( bMainGrid ) 462*cdf0e10cSrcweir AxisHelper::makeGridVisible( xAxis->getGridProperties() ); 463*cdf0e10cSrcweir else 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); 466*cdf0e10cSrcweir for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++) 467*cdf0e10cSrcweir AxisHelper::makeGridVisible( aSubGrids[nN] ); 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir void AxisHelper::makeAxisVisible( const Reference< XAxis >& xAxis ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY ); 474*cdf0e10cSrcweir if( xProps.is() ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) ); 477*cdf0e10cSrcweir LineProperties::SetLineVisible( xProps ); 478*cdf0e10cSrcweir xProps->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True ) ); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir void AxisHelper::makeGridVisible( const Reference< beans::XPropertySet >& xGridProperties ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir if( xGridProperties.is() ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) ); 487*cdf0e10cSrcweir LineProperties::SetLineVisible( xGridProperties ); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir void AxisHelper::hideAxis( sal_Int32 nDimensionIndex, bool bMainAxis 492*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) ); 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir void AxisHelper::makeAxisInvisible( const Reference< XAxis >& xAxis ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY ); 500*cdf0e10cSrcweir if( xProps.is() ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) ); 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir void AxisHelper::hideAxisIfNoDataIsAttached( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir //axis is hidden if no data is attached anymore but data is available 509*cdf0e10cSrcweir bool bOtherSeriesAttachedToThisAxis = false; 510*cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 511*cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = aSeriesVector.begin(); 512*cdf0e10cSrcweir for( ; aIt != aSeriesVector.end(); ++aIt) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir uno::Reference< chart2::XAxis > xCurrentAxis( DiagramHelper::getAttachedAxis( *aIt, xDiagram ), uno::UNO_QUERY ); 515*cdf0e10cSrcweir if( xCurrentAxis==xAxis ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir bOtherSeriesAttachedToThisAxis = true; 518*cdf0e10cSrcweir break; 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir if(!bOtherSeriesAttachedToThisAxis && !aSeriesVector.empty() ) 522*cdf0e10cSrcweir AxisHelper::makeAxisInvisible( xAxis ); 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir void AxisHelper::hideGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid 526*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir if( !xDiagram.is() ) 529*cdf0e10cSrcweir return; 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex ); 532*cdf0e10cSrcweir if(!xCooSys.is()) 533*cdf0e10cSrcweir return; 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) ); 536*cdf0e10cSrcweir if(!xAxis.is()) 537*cdf0e10cSrcweir return; 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir if( bMainGrid ) 540*cdf0e10cSrcweir AxisHelper::makeGridInvisible( xAxis->getGridProperties() ); 541*cdf0e10cSrcweir else 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); 544*cdf0e10cSrcweir for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++) 545*cdf0e10cSrcweir AxisHelper::makeGridInvisible( aSubGrids[nN] ); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir void AxisHelper::makeGridInvisible( const Reference< beans::XPropertySet >& xGridProperties ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir if( xGridProperties.is() ) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) ); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir sal_Bool AxisHelper::isGridShown( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid 558*cdf0e10cSrcweir , const Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir sal_Bool bRet = false; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex ); 563*cdf0e10cSrcweir if(!xCooSys.is()) 564*cdf0e10cSrcweir return bRet; 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) ); 567*cdf0e10cSrcweir if(!xAxis.is()) 568*cdf0e10cSrcweir return bRet; 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir if( bMainGrid ) 571*cdf0e10cSrcweir bRet = AxisHelper::isGridVisible( xAxis->getGridProperties() ); 572*cdf0e10cSrcweir else 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); 575*cdf0e10cSrcweir if( aSubGrids.getLength() ) 576*cdf0e10cSrcweir bRet = AxisHelper::isGridVisible( aSubGrids[0] ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir return bRet; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemByIndex( 583*cdf0e10cSrcweir const Reference< XDiagram >& xDiagram, sal_Int32 nIndex ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); 586*cdf0e10cSrcweir if(!xCooSysContainer.is()) 587*cdf0e10cSrcweir return NULL; 588*cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems(); 589*cdf0e10cSrcweir if(0<=nIndex && nIndex<aCooSysList.getLength()) 590*cdf0e10cSrcweir return aCooSysList[nIndex]; 591*cdf0e10cSrcweir return NULL; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, bool bMainAxis 595*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir Reference< XAxis > xRet; 598*cdf0e10cSrcweir try 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ); 601*cdf0e10cSrcweir xRet.set( AxisHelper::getAxis( nDimensionIndex, bMainAxis ? 0 : 1, xCooSys ) ); 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir catch( const uno::Exception & ) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir return xRet; 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex 610*cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys ) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir Reference< XAxis > xRet; 613*cdf0e10cSrcweir try 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir if( xCooSys.is() ) 616*cdf0e10cSrcweir xRet.set( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) ); 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir catch( const uno::Exception & ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir return xRet; 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir Reference< XAxis > AxisHelper::getCrossingMainAxis( const Reference< XAxis >& xAxis 625*cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir sal_Int32 nDimensionIndex = 0; 628*cdf0e10cSrcweir sal_Int32 nAxisIndex = 0; 629*cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ); 630*cdf0e10cSrcweir if( 2==nDimensionIndex ) 631*cdf0e10cSrcweir { 632*cdf0e10cSrcweir nDimensionIndex=1; 633*cdf0e10cSrcweir bool bSwapXY = false; 634*cdf0e10cSrcweir Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY ); 635*cdf0e10cSrcweir if( xCooSysProp.is() && (xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY) && bSwapXY ) 636*cdf0e10cSrcweir nDimensionIndex=0; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir else if( 1==nDimensionIndex ) 639*cdf0e10cSrcweir nDimensionIndex=0; 640*cdf0e10cSrcweir else 641*cdf0e10cSrcweir nDimensionIndex=1; 642*cdf0e10cSrcweir return AxisHelper::getAxis( nDimensionIndex, 0, xCooSys ); 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir Reference< XAxis > AxisHelper::getParallelAxis( const Reference< XAxis >& xAxis 646*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir try 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir sal_Int32 nCooSysIndex=-1; 651*cdf0e10cSrcweir sal_Int32 nDimensionIndex=-1; 652*cdf0e10cSrcweir sal_Int32 nAxisIndex=-1; 653*cdf0e10cSrcweir if( getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ) ) 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1; 656*cdf0e10cSrcweir return getAxis( nDimensionIndex, nParallelAxisIndex, getCoordinateSystemByIndex( xDiagram, nCooSysIndex ) ); 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir catch( uno::RuntimeException& ) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir return 0; 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir sal_Bool AxisHelper::isAxisShown( sal_Int32 nDimensionIndex, bool bMainAxis 666*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) ); 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir sal_Bool AxisHelper::isAxisVisible( const Reference< XAxis >& xAxis ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir sal_Bool bRet = false; 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY ); 676*cdf0e10cSrcweir if( xProps.is() ) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir xProps->getPropertyValue( C2U( "Show" ) ) >>= bRet; 679*cdf0e10cSrcweir bRet = bRet && ( LineProperties::IsLineVisible( xProps ) 680*cdf0e10cSrcweir || areAxisLabelsVisible( xProps ) ); 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir return bRet; 684*cdf0e10cSrcweir } 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir sal_Bool AxisHelper::areAxisLabelsVisible( const Reference< beans::XPropertySet >& xAxisProperties ) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir sal_Bool bRet = false; 689*cdf0e10cSrcweir if( xAxisProperties.is() ) 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir xAxisProperties->getPropertyValue( C2U( "DisplayLabels" ) ) >>= bRet; 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir return bRet; 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir sal_Bool AxisHelper::isGridVisible( const Reference< beans::XPropertySet >& xGridProperies ) 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir sal_Bool bRet = false; 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir if( xGridProperies.is() ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir xGridProperies->getPropertyValue( C2U( "Show" ) ) >>= bRet; 703*cdf0e10cSrcweir bRet = bRet && LineProperties::IsLineVisible( xGridProperies ); 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir return bRet; 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir Reference< beans::XPropertySet > AxisHelper::getGridProperties( 710*cdf0e10cSrcweir const Reference< XCoordinateSystem >& xCooSys 711*cdf0e10cSrcweir , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex, sal_Int32 nSubGridIndex ) 712*cdf0e10cSrcweir { 713*cdf0e10cSrcweir Reference< beans::XPropertySet > xRet; 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) ); 716*cdf0e10cSrcweir if( xAxis.is() ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir if( nSubGridIndex<0 ) 719*cdf0e10cSrcweir xRet.set( xAxis->getGridProperties() ); 720*cdf0e10cSrcweir else 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); 723*cdf0e10cSrcweir if( nSubGridIndex >= 0 && nSubGridIndex < aSubGrids.getLength() ) 724*cdf0e10cSrcweir xRet.set( aSubGrids[nSubGridIndex] ); 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir return xRet; 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir sal_Int32 AxisHelper::getDimensionIndexOfAxis( 732*cdf0e10cSrcweir const Reference< XAxis >& xAxis 733*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir sal_Int32 nDimensionIndex = -1; 736*cdf0e10cSrcweir sal_Int32 nCooSysIndex = -1; 737*cdf0e10cSrcweir sal_Int32 nAxisIndex = -1; 738*cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex , nDimensionIndex, nAxisIndex ); 739*cdf0e10cSrcweir return nDimensionIndex; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir bool AxisHelper::getIndicesForAxis( 743*cdf0e10cSrcweir const Reference< XAxis >& xAxis 744*cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys 745*cdf0e10cSrcweir , sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex ) 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir //returns true if indices are found 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir rOutDimensionIndex = -1; 750*cdf0e10cSrcweir rOutAxisIndex = -1; 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir if( xCooSys.is() && xAxis.is() ) 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir Reference< XAxis > xCurrentAxis; 755*cdf0e10cSrcweir sal_Int32 nDimensionCount( xCooSys->getDimension() ); 756*cdf0e10cSrcweir for( sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ ) 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); 759*cdf0e10cSrcweir for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ ) 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir xCurrentAxis = xCooSys->getAxisByDimension(nDimensionIndex,nAxisIndex); 762*cdf0e10cSrcweir if( xCurrentAxis == xAxis ) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir rOutDimensionIndex = nDimensionIndex; 765*cdf0e10cSrcweir rOutAxisIndex = nAxisIndex; 766*cdf0e10cSrcweir return true; 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir return false; 772*cdf0e10cSrcweir } 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir bool AxisHelper::getIndicesForAxis( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram 775*cdf0e10cSrcweir , sal_Int32& rOutCooSysIndex, sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex ) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir //returns true if indices are found 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir rOutCooSysIndex = -1; 780*cdf0e10cSrcweir rOutDimensionIndex = -1; 781*cdf0e10cSrcweir rOutAxisIndex = -1; 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); 784*cdf0e10cSrcweir if(xCooSysContainer.is()) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems(); 787*cdf0e10cSrcweir for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC ) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], rOutDimensionIndex, rOutAxisIndex ) ) 790*cdf0e10cSrcweir { 791*cdf0e10cSrcweir rOutCooSysIndex = nC; 792*cdf0e10cSrcweir return true; 793*cdf0e10cSrcweir } 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir return false; 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir std::vector< Reference< XAxis > > AxisHelper::getAllAxesOfCoordinateSystem( 801*cdf0e10cSrcweir const Reference< XCoordinateSystem >& xCooSys 802*cdf0e10cSrcweir , bool bOnlyVisible /* = false */ ) 803*cdf0e10cSrcweir { 804*cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxisVector; 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir if(xCooSys.is()) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir sal_Int32 nDimensionIndex = 0; 809*cdf0e10cSrcweir sal_Int32 nMaxDimensionIndex = xCooSys->getDimension() -1; 810*cdf0e10cSrcweir if( nMaxDimensionIndex>=0 ) 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir for(nDimensionIndex=0; nDimensionIndex<=nMaxDimensionIndex; ++nDimensionIndex) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); 815*cdf0e10cSrcweir for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir try 818*cdf0e10cSrcweir { 819*cdf0e10cSrcweir Reference< XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) ); 820*cdf0e10cSrcweir bool bAddAxis = true; 821*cdf0e10cSrcweir if( xAxis.is() ) 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir if( bOnlyVisible ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY ); 826*cdf0e10cSrcweir if( !xAxisProp.is() || 827*cdf0e10cSrcweir !(xAxisProp->getPropertyValue( C2U("Show")) >>= bAddAxis) ) 828*cdf0e10cSrcweir bAddAxis = false; 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir if( bAddAxis ) 831*cdf0e10cSrcweir aAxisVector.push_back( xAxis ); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir catch( const uno::Exception & ex ) 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir return aAxisVector; 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir Sequence< Reference< XAxis > > AxisHelper::getAllAxesOfDiagram( 847*cdf0e10cSrcweir const Reference< XDiagram >& xDiagram 848*cdf0e10cSrcweir , bool bOnlyVisible ) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxisVector; 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); 853*cdf0e10cSrcweir if(xCooSysContainer.is()) 854*cdf0e10cSrcweir { 855*cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems(); 856*cdf0e10cSrcweir sal_Int32 nC = 0; 857*cdf0e10cSrcweir for( nC=0; nC<aCooSysList.getLength(); ++nC ) 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir std::vector< Reference< XAxis > > aAxesPerCooSys( AxisHelper::getAllAxesOfCoordinateSystem( aCooSysList[nC], bOnlyVisible ) ); 860*cdf0e10cSrcweir aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), aAxesPerCooSys.end() ); 861*cdf0e10cSrcweir } 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( aAxisVector ); 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > AxisHelper::getAllGrids( const Reference< XDiagram >& xDiagram ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir Sequence< Reference< XAxis > > aAllAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) ); 870*cdf0e10cSrcweir std::vector< Reference< beans::XPropertySet > > aGridVector; 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir sal_Int32 nA = 0; 873*cdf0e10cSrcweir for( nA=0; nA<aAllAxes.getLength(); ++nA ) 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir Reference< XAxis > xAxis( aAllAxes[nA] ); 876*cdf0e10cSrcweir if(!xAxis.is()) 877*cdf0e10cSrcweir continue; 878*cdf0e10cSrcweir Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() ); 879*cdf0e10cSrcweir if( xGridProperties.is() ) 880*cdf0e10cSrcweir aGridVector.push_back( xGridProperties ); 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );; 883*cdf0e10cSrcweir sal_Int32 nSubGrid = 0; 884*cdf0e10cSrcweir for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid ) 885*cdf0e10cSrcweir { 886*cdf0e10cSrcweir Reference< beans::XPropertySet > xSubGrid( aSubGrids[nSubGrid] ); 887*cdf0e10cSrcweir if( xSubGrid.is() ) 888*cdf0e10cSrcweir aGridVector.push_back( xSubGrid ); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir } 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir return ContainerHelper::ContainerToSequence( aGridVector ); 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir void AxisHelper::getAxisOrGridPossibilities( Sequence< sal_Bool >& rPossibilityList 896*cdf0e10cSrcweir , const Reference< XDiagram>& xDiagram, sal_Bool bAxis ) 897*cdf0e10cSrcweir { 898*cdf0e10cSrcweir rPossibilityList.realloc(6); 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram ); 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir //set possibilities: 903*cdf0e10cSrcweir sal_Int32 nIndex=0; 904*cdf0e10cSrcweir Reference< XChartType > xChartType = DiagramHelper::getChartTypeByIndex( xDiagram, 0 ); 905*cdf0e10cSrcweir for(nIndex=0;nIndex<3;nIndex++) 906*cdf0e10cSrcweir rPossibilityList[nIndex]=ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nIndex); 907*cdf0e10cSrcweir for(nIndex=3;nIndex<6;nIndex++) 908*cdf0e10cSrcweir if( bAxis ) 909*cdf0e10cSrcweir rPossibilityList[nIndex]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nIndex-3); 910*cdf0e10cSrcweir else 911*cdf0e10cSrcweir rPossibilityList[nIndex] = rPossibilityList[nIndex-3]; 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir bool AxisHelper::isSecondaryYAxisNeeded( const Reference< XCoordinateSystem >& xCooSys ) 915*cdf0e10cSrcweir { 916*cdf0e10cSrcweir Reference< chart2::XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY ); 917*cdf0e10cSrcweir if( xCTCnt.is() ) 918*cdf0e10cSrcweir { 919*cdf0e10cSrcweir Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes() ); 920*cdf0e10cSrcweir for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i ) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir Reference< XDataSeriesContainer > xSeriesContainer( aChartTypes[i] , uno::UNO_QUERY ); 923*cdf0e10cSrcweir if( !xSeriesContainer.is() ) 924*cdf0e10cSrcweir continue; 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aSeriesList( xSeriesContainer->getDataSeries() ); 927*cdf0e10cSrcweir for( sal_Int32 nS = aSeriesList.getLength(); nS-- ; ) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY ); 930*cdf0e10cSrcweir if(xProp.is()) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir sal_Int32 nAttachedAxisIndex = 0; 933*cdf0e10cSrcweir if( ( xProp->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex ) && nAttachedAxisIndex>0 ) 934*cdf0e10cSrcweir return true; 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir } 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir } 939*cdf0e10cSrcweir return false; 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir bool AxisHelper::shouldAxisBeDisplayed( const Reference< XAxis >& xAxis 943*cdf0e10cSrcweir , const Reference< XCoordinateSystem >& xCooSys ) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir bool bRet = false; 946*cdf0e10cSrcweir 947*cdf0e10cSrcweir if( xAxis.is() && xCooSys.is() ) 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir sal_Int32 nDimensionIndex=-1; 950*cdf0e10cSrcweir sal_Int32 nAxisIndex=-1; 951*cdf0e10cSrcweir if( AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ) ) 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir sal_Int32 nDimensionCount = xCooSys->getDimension(); 954*cdf0e10cSrcweir Reference< XChartType > xChartType( AxisHelper::getChartTypeByIndex( xCooSys, 0 ) ); 955*cdf0e10cSrcweir 956*cdf0e10cSrcweir bool bMainAxis = (nAxisIndex==MAIN_AXIS_INDEX); 957*cdf0e10cSrcweir if( bMainAxis ) 958*cdf0e10cSrcweir bRet = ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nDimensionIndex); 959*cdf0e10cSrcweir else 960*cdf0e10cSrcweir bRet = ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nDimensionIndex); 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir } 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir return bRet; 965*cdf0e10cSrcweir } 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir void AxisHelper::getAxisOrGridExcistence( Sequence< sal_Bool >& rExistenceList 968*cdf0e10cSrcweir , const Reference< XDiagram>& xDiagram, sal_Bool bAxis ) 969*cdf0e10cSrcweir { 970*cdf0e10cSrcweir rExistenceList.realloc(6); 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir if(bAxis) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir sal_Int32 nN; 975*cdf0e10cSrcweir Reference< XAxis > xAxis; 976*cdf0e10cSrcweir for(nN=0;nN<3;nN++) 977*cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isAxisShown( nN, true, xDiagram ); 978*cdf0e10cSrcweir for(nN=3;nN<6;nN++) 979*cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isAxisShown( nN%3, false, xDiagram ); 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir else 982*cdf0e10cSrcweir { 983*cdf0e10cSrcweir sal_Int32 nN; 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir for(nN=0;nN<3;nN++) 986*cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isGridShown( nN, 0, true, xDiagram ); 987*cdf0e10cSrcweir for(nN=3;nN<6;nN++) 988*cdf0e10cSrcweir rExistenceList[nN] = AxisHelper::isGridShown( nN%3, 0, false, xDiagram ); 989*cdf0e10cSrcweir } 990*cdf0e10cSrcweir } 991*cdf0e10cSrcweir 992*cdf0e10cSrcweir bool AxisHelper::changeVisibilityOfAxes( const Reference< XDiagram >& xDiagram 993*cdf0e10cSrcweir , const Sequence< sal_Bool >& rOldExistenceList 994*cdf0e10cSrcweir , const Sequence< sal_Bool >& rNewExistenceList 995*cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext 996*cdf0e10cSrcweir , ReferenceSizeProvider * pRefSizeProvider ) 997*cdf0e10cSrcweir { 998*cdf0e10cSrcweir bool bChanged = false; 999*cdf0e10cSrcweir for(sal_Int32 nN=0;nN<6;nN++) 1000*cdf0e10cSrcweir { 1001*cdf0e10cSrcweir if(rOldExistenceList[nN]!=rNewExistenceList[nN]) 1002*cdf0e10cSrcweir { 1003*cdf0e10cSrcweir bChanged = true; 1004*cdf0e10cSrcweir if(rNewExistenceList[nN]) 1005*cdf0e10cSrcweir { 1006*cdf0e10cSrcweir AxisHelper::showAxis( nN%3, nN<3, xDiagram, xContext, pRefSizeProvider ); 1007*cdf0e10cSrcweir } 1008*cdf0e10cSrcweir else 1009*cdf0e10cSrcweir AxisHelper::hideAxis( nN%3, nN<3, xDiagram ); 1010*cdf0e10cSrcweir } 1011*cdf0e10cSrcweir } 1012*cdf0e10cSrcweir return bChanged; 1013*cdf0e10cSrcweir } 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir bool AxisHelper::changeVisibilityOfGrids( const Reference< XDiagram >& xDiagram 1016*cdf0e10cSrcweir , const Sequence< sal_Bool >& rOldExistenceList 1017*cdf0e10cSrcweir , const Sequence< sal_Bool >& rNewExistenceList 1018*cdf0e10cSrcweir , const Reference< uno::XComponentContext >& xContext ) 1019*cdf0e10cSrcweir { 1020*cdf0e10cSrcweir bool bChanged = false; 1021*cdf0e10cSrcweir for(sal_Int32 nN=0;nN<6;nN++) 1022*cdf0e10cSrcweir { 1023*cdf0e10cSrcweir if(rOldExistenceList[nN]!=rNewExistenceList[nN]) 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir bChanged = true; 1026*cdf0e10cSrcweir if(rNewExistenceList[nN]) 1027*cdf0e10cSrcweir AxisHelper::showGrid( nN%3, 0, nN<3, xDiagram, xContext ); 1028*cdf0e10cSrcweir else 1029*cdf0e10cSrcweir AxisHelper::hideGrid( nN%3, 0, nN<3, xDiagram ); 1030*cdf0e10cSrcweir } 1031*cdf0e10cSrcweir } 1032*cdf0e10cSrcweir return bChanged; 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemOfAxis( 1036*cdf0e10cSrcweir const Reference< XAxis >& xAxis 1037*cdf0e10cSrcweir , const Reference< XDiagram >& xDiagram ) 1038*cdf0e10cSrcweir { 1039*cdf0e10cSrcweir Reference< XCoordinateSystem > xRet; 1040*cdf0e10cSrcweir 1041*cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); 1042*cdf0e10cSrcweir if( xCooSysContainer.is() ) 1043*cdf0e10cSrcweir { 1044*cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys; 1045*cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); 1046*cdf0e10cSrcweir for( sal_Int32 nCooSysIndex = 0; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex ) 1047*cdf0e10cSrcweir { 1048*cdf0e10cSrcweir xCooSys = aCooSysList[nCooSysIndex]; 1049*cdf0e10cSrcweir std::vector< Reference< XAxis > > aAllAxis( AxisHelper::getAllAxesOfCoordinateSystem( xCooSys ) ); 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir ::std::vector< Reference< XAxis > >::iterator aFound = 1052*cdf0e10cSrcweir ::std::find( aAllAxis.begin(), aAllAxis.end(), xAxis ); 1053*cdf0e10cSrcweir if( aFound != aAllAxis.end()) 1054*cdf0e10cSrcweir { 1055*cdf0e10cSrcweir xRet.set( xCooSys ); 1056*cdf0e10cSrcweir break; 1057*cdf0e10cSrcweir } 1058*cdf0e10cSrcweir } 1059*cdf0e10cSrcweir } 1060*cdf0e10cSrcweir return xRet; 1061*cdf0e10cSrcweir } 1062*cdf0e10cSrcweir 1063*cdf0e10cSrcweir Reference< XChartType > AxisHelper::getChartTypeByIndex( const Reference< XCoordinateSystem >& xCooSys, sal_Int32 nIndex ) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir Reference< XChartType > xChartType; 1066*cdf0e10cSrcweir 1067*cdf0e10cSrcweir Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY ); 1068*cdf0e10cSrcweir if( xChartTypeContainer.is() ) 1069*cdf0e10cSrcweir { 1070*cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() ); 1071*cdf0e10cSrcweir if( nIndex >= 0 && nIndex < aChartTypeList.getLength() ) 1072*cdf0e10cSrcweir xChartType.set( aChartTypeList[nIndex] ); 1073*cdf0e10cSrcweir } 1074*cdf0e10cSrcweir 1075*cdf0e10cSrcweir return xChartType; 1076*cdf0e10cSrcweir } 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir void AxisHelper::setRTLAxisLayout( const Reference< XCoordinateSystem >& xCooSys ) 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir if( xCooSys.is() ) 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir bool bCartesian = xCooSys->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME ); 1083*cdf0e10cSrcweir if( bCartesian ) 1084*cdf0e10cSrcweir { 1085*cdf0e10cSrcweir bool bVertical = false; 1086*cdf0e10cSrcweir Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY ); 1087*cdf0e10cSrcweir if( xCooSysProp.is() ) 1088*cdf0e10cSrcweir xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bVertical; 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir sal_Int32 nHorizontalAxisDimension = bVertical ? 1 : 0; 1091*cdf0e10cSrcweir sal_Int32 nVerticalAxisDimension = bVertical ? 0 : 1; 1092*cdf0e10cSrcweir 1093*cdf0e10cSrcweir try 1094*cdf0e10cSrcweir { 1095*cdf0e10cSrcweir //reverse direction for horizontal main axis 1096*cdf0e10cSrcweir Reference< chart2::XAxis > xHorizontalMainAxis( AxisHelper::getAxis( nHorizontalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) ); 1097*cdf0e10cSrcweir if( xHorizontalMainAxis.is() ) 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir chart2::ScaleData aScale = xHorizontalMainAxis->getScaleData(); 1100*cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_REVERSE; 1101*cdf0e10cSrcweir xHorizontalMainAxis->setScaleData(aScale); 1102*cdf0e10cSrcweir } 1103*cdf0e10cSrcweir 1104*cdf0e10cSrcweir //mathematical direction for vertical main axis 1105*cdf0e10cSrcweir Reference< chart2::XAxis > xVerticalMainAxis( AxisHelper::getAxis( nVerticalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) ); 1106*cdf0e10cSrcweir if( xVerticalMainAxis.is() ) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir chart2::ScaleData aScale = xVerticalMainAxis->getScaleData(); 1109*cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL; 1110*cdf0e10cSrcweir xVerticalMainAxis->setScaleData(aScale); 1111*cdf0e10cSrcweir } 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir catch( uno::Exception & ex ) 1114*cdf0e10cSrcweir { 1115*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir 1118*cdf0e10cSrcweir try 1119*cdf0e10cSrcweir { 1120*cdf0e10cSrcweir //reverse direction for horizontal secondary axis 1121*cdf0e10cSrcweir Reference< chart2::XAxis > xHorizontalSecondaryAxis( AxisHelper::getAxis( nHorizontalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) ); 1122*cdf0e10cSrcweir if( xHorizontalSecondaryAxis.is() ) 1123*cdf0e10cSrcweir { 1124*cdf0e10cSrcweir chart2::ScaleData aScale = xHorizontalSecondaryAxis->getScaleData(); 1125*cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_REVERSE; 1126*cdf0e10cSrcweir xHorizontalSecondaryAxis->setScaleData(aScale); 1127*cdf0e10cSrcweir } 1128*cdf0e10cSrcweir 1129*cdf0e10cSrcweir //mathematical direction for vertical secondary axis 1130*cdf0e10cSrcweir Reference< chart2::XAxis > xVerticalSecondaryAxis( AxisHelper::getAxis( nVerticalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) ); 1131*cdf0e10cSrcweir if( xVerticalSecondaryAxis.is() ) 1132*cdf0e10cSrcweir { 1133*cdf0e10cSrcweir chart2::ScaleData aScale = xVerticalSecondaryAxis->getScaleData(); 1134*cdf0e10cSrcweir aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL; 1135*cdf0e10cSrcweir xVerticalSecondaryAxis->setScaleData(aScale); 1136*cdf0e10cSrcweir } 1137*cdf0e10cSrcweir } 1138*cdf0e10cSrcweir catch( uno::Exception & ex ) 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 1141*cdf0e10cSrcweir } 1142*cdf0e10cSrcweir } 1143*cdf0e10cSrcweir } 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir Reference< XChartType > AxisHelper::getFirstChartTypeWithSeriesAttachedToAxisIndex( const Reference< chart2::XDiagram >& xDiagram, const sal_Int32 nAttachedAxisIndex ) 1147*cdf0e10cSrcweir { 1148*cdf0e10cSrcweir Reference< XChartType > xChartType; 1149*cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) ); 1150*cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > >::const_iterator aIter = aSeriesVector.begin(); 1151*cdf0e10cSrcweir for( ; aIter != aSeriesVector.end(); aIter++ ) 1152*cdf0e10cSrcweir { 1153*cdf0e10cSrcweir sal_Int32 nCurrentIndex = DataSeriesHelper::getAttachedAxisIndex( *aIter ); 1154*cdf0e10cSrcweir if( nAttachedAxisIndex == nCurrentIndex ) 1155*cdf0e10cSrcweir { 1156*cdf0e10cSrcweir xChartType = DiagramHelper::getChartTypeOfSeries( xDiagram, *aIter ); 1157*cdf0e10cSrcweir if(xChartType.is()) 1158*cdf0e10cSrcweir break; 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir } 1161*cdf0e10cSrcweir return xChartType; 1162*cdf0e10cSrcweir } 1163*cdf0e10cSrcweir 1164*cdf0e10cSrcweir bool AxisHelper::isAxisPositioningEnabled() 1165*cdf0e10cSrcweir { 1166*cdf0e10cSrcweir const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() ); 1167*cdf0e10cSrcweir return nCurrentVersion >= SvtSaveOptions::ODFVER_012; 1168*cdf0e10cSrcweir } 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir //............................................................................. 1171*cdf0e10cSrcweir } //namespace chart 1172*cdf0e10cSrcweir //............................................................................. 1173