1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 27cdf0e10cSrcweir #include "DiagramHelper.hxx" 28cdf0e10cSrcweir #include "DataSource.hxx" 29cdf0e10cSrcweir #include "macros.hxx" 30cdf0e10cSrcweir #include "ContainerHelper.hxx" 31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 32cdf0e10cSrcweir #include <com/sun/star/chart2/DataPointLabel.hpp> 33cdf0e10cSrcweir #include <com/sun/star/chart2/data/XTextualDataSequence.hpp> 34cdf0e10cSrcweir #include <com/sun/star/chart2/StackingDirection.hpp> 35cdf0e10cSrcweir #include <com/sun/star/chart2/data/LabelOrigin.hpp> 36cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp> 37cdf0e10cSrcweir #include <com/sun/star/chart2/SymbolStyle.hpp> 38cdf0e10cSrcweir #include <com/sun/star/chart2/Symbol.hpp> 39cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp> 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> 43cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp> 44cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp> 45cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <functional> 48cdf0e10cSrcweir #include <algorithm> 49cdf0e10cSrcweir #include <iterator> 50cdf0e10cSrcweir #include <vector> 51cdf0e10cSrcweir #include <set> 52cdf0e10cSrcweir 53cdf0e10cSrcweir using namespace ::com::sun::star; 54cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 55cdf0e10cSrcweir 56cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 57cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 58cdf0e10cSrcweir using ::rtl::OUString; 59cdf0e10cSrcweir using ::rtl::OUStringBuffer; 60cdf0e10cSrcweir 61cdf0e10cSrcweir // ---------------------------------------- 62cdf0e10cSrcweir namespace 63cdf0e10cSrcweir { 64cdf0e10cSrcweir 65cdf0e10cSrcweir class lcl_MatchesRole : public ::std::unary_function< Reference< chart2::data::XLabeledDataSequence >, bool > 66cdf0e10cSrcweir { 67cdf0e10cSrcweir public: 68cdf0e10cSrcweir explicit lcl_MatchesRole( const OUString & aRole, bool bMatchPrefix ) : 69cdf0e10cSrcweir m_aRole( aRole ), 70cdf0e10cSrcweir m_bMatchPrefix( bMatchPrefix ) 71cdf0e10cSrcweir {} 72cdf0e10cSrcweir 73cdf0e10cSrcweir bool operator () ( const Reference< chart2::data::XLabeledDataSequence > & xSeq ) const 74cdf0e10cSrcweir { 75cdf0e10cSrcweir if(!xSeq.is()) 76cdf0e10cSrcweir return false; 77cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeq->getValues(), uno::UNO_QUERY ); 78cdf0e10cSrcweir OUString aRole; 79cdf0e10cSrcweir 80cdf0e10cSrcweir if( m_bMatchPrefix ) 81cdf0e10cSrcweir return ( xProp.is() && 82cdf0e10cSrcweir (xProp->getPropertyValue( 83cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )) ) >>= aRole ) && 84cdf0e10cSrcweir aRole.match( m_aRole )); 85cdf0e10cSrcweir 86cdf0e10cSrcweir return ( xProp.is() && 87cdf0e10cSrcweir (xProp->getPropertyValue( 88cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )) ) >>= aRole ) && 89cdf0e10cSrcweir m_aRole.equals( aRole )); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir private: 93cdf0e10cSrcweir OUString m_aRole; 94cdf0e10cSrcweir bool m_bMatchPrefix; 95cdf0e10cSrcweir }; 96cdf0e10cSrcweir 97cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > lcl_findLSequenceWithOnlyLabel( 98cdf0e10cSrcweir const Reference< chart2::data::XDataSource > & xDataSource ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xResult; 101cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences()); 102cdf0e10cSrcweir 103cdf0e10cSrcweir for( sal_Int32 i=0; i<aSequences.getLength(); ++i ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir OSL_ENSURE( aSequences[i].is(), "empty LabeledDataSequence" ); 106cdf0e10cSrcweir // no values are set but a label exists 107cdf0e10cSrcweir if( aSequences[i].is() && 108cdf0e10cSrcweir ( ! aSequences[i]->getValues().is() && 109cdf0e10cSrcweir aSequences[i]->getLabel().is())) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir xResult.set( aSequences[i] ); 112cdf0e10cSrcweir break; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir return xResult; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir void lcl_getCooSysAndChartTypeOfSeries( 120cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 121cdf0e10cSrcweir const Reference< chart2::XDiagram > & xDiagram, 122cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > & xOutCooSys, 123cdf0e10cSrcweir Reference< chart2::XChartType > & xOutChartType ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY ); 126cdf0e10cSrcweir if( xCooSysCnt.is()) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); 129cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW ); 132cdf0e10cSrcweir Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes()); 133cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xSeriesCnt( aChartTypes[nCTIdx], uno::UNO_QUERY ); 136cdf0e10cSrcweir if( xSeriesCnt.is()) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir Sequence< Reference< chart2::XDataSeries > > aSeries( xSeriesCnt->getDataSeries()); 139cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeries.getLength(); ++nSeriesIdx ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if( aSeries[nSeriesIdx] == xSeries ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir xOutCooSys.set( aCooSysSeq[nCooSysIdx] ); 144cdf0e10cSrcweir xOutChartType.set( aChartTypes[nCTIdx] ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir void lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries, bool bInsert ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir try 156cdf0e10cSrcweir { 157cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); 158cdf0e10cSrcweir if( xSeriesProperties.is() ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir DataPointLabel aLabelAtSeries; 161cdf0e10cSrcweir xSeriesProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabelAtSeries; 162cdf0e10cSrcweir aLabelAtSeries.ShowNumber = bInsert; 163cdf0e10cSrcweir if( !bInsert ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir aLabelAtSeries.ShowNumberInPercent = false; 166cdf0e10cSrcweir aLabelAtSeries.ShowCategoryName = false; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir xSeriesProperties->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabelAtSeries ) ); 169cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; 170cdf0e10cSrcweir if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); 175cdf0e10cSrcweir if( xPointProp.is() ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir DataPointLabel aLabel; 178cdf0e10cSrcweir xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; 179cdf0e10cSrcweir aLabel.ShowNumber = bInsert; 180cdf0e10cSrcweir if( !bInsert ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir aLabel.ShowNumberInPercent = false; 183cdf0e10cSrcweir aLabel.ShowCategoryName = false; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch( uno::Exception &e) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir } // anonymous namespace 198cdf0e10cSrcweir // ---------------------------------------- 199cdf0e10cSrcweir 200cdf0e10cSrcweir namespace chart 201cdf0e10cSrcweir { 202cdf0e10cSrcweir 203cdf0e10cSrcweir namespace DataSeriesHelper 204cdf0e10cSrcweir { 205cdf0e10cSrcweir 206cdf0e10cSrcweir OUString GetRole( const uno::Reference< chart2::data::XLabeledDataSequence >& xLabeledDataSequence ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir OUString aRet; 209cdf0e10cSrcweir if( xLabeledDataSequence.is() ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xLabeledDataSequence->getValues(), uno::UNO_QUERY ); 212cdf0e10cSrcweir if( xProp.is() ) 213cdf0e10cSrcweir xProp->getPropertyValue( C2U("Role") ) >>= aRet; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir return aRet; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > 219cdf0e10cSrcweir getDataSequenceByRole( 220cdf0e10cSrcweir const Reference< chart2::data::XDataSource > & xSource, OUString aRole, 221cdf0e10cSrcweir bool bMatchPrefix /* = false */ ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > aNoResult; 224cdf0e10cSrcweir if( ! xSource.is()) 225cdf0e10cSrcweir return aNoResult; 226cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); 227cdf0e10cSrcweir 228cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > * pBegin = aLabeledSeq.getConstArray(); 229cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > * pEnd = pBegin + aLabeledSeq.getLength(); 230cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > * pMatch = 231cdf0e10cSrcweir ::std::find_if( pBegin, pEnd, lcl_MatchesRole( aRole, bMatchPrefix )); 232cdf0e10cSrcweir 233cdf0e10cSrcweir if( pMatch != pEnd ) 234cdf0e10cSrcweir return *pMatch; 235cdf0e10cSrcweir 236cdf0e10cSrcweir return aNoResult; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > 240cdf0e10cSrcweir getAllDataSequencesByRole( const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aDataSequences, 241cdf0e10cSrcweir OUString aRole, bool bMatchPrefix /* = false */ ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVec; 244cdf0e10cSrcweir ::std::remove_copy_if( aDataSequences.getConstArray(), aDataSequences.getConstArray() + aDataSequences.getLength(), 245cdf0e10cSrcweir ::std::back_inserter( aResultVec ), 246cdf0e10cSrcweir ::std::not1( lcl_MatchesRole( aRole, bMatchPrefix ))); 247cdf0e10cSrcweir return aResultVec; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir Reference< chart2::data::XDataSource > 251cdf0e10cSrcweir getDataSource( const Sequence< Reference< chart2::XDataSeries > > & aSeries ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aSeqVec; 254cdf0e10cSrcweir 255cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSeries.getLength(); ++i ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( aSeries[ i ], uno::UNO_QUERY ); 258cdf0e10cSrcweir if( xSource.is()) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences()); 261cdf0e10cSrcweir ::std::copy( aSeq.getConstArray(), aSeq.getConstArray() + aSeq.getLength(), 262cdf0e10cSrcweir ::std::back_inserter( aSeqVec )); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir return Reference< chart2::data::XDataSource >( 267cdf0e10cSrcweir new DataSource( ContainerHelper::ContainerToSequence( aSeqVec ))); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir namespace 271cdf0e10cSrcweir { 272cdf0e10cSrcweir OUString lcl_getDataSequenceLabel( const Reference< chart2::data::XDataSequence > & xSequence ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir OUString aResult; 275cdf0e10cSrcweir 276cdf0e10cSrcweir Reference< chart2::data::XTextualDataSequence > xTextSeq( xSequence, uno::UNO_QUERY ); 277cdf0e10cSrcweir if( xTextSeq.is()) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir Sequence< OUString > aSeq( xTextSeq->getTextualData()); 280cdf0e10cSrcweir 281cdf0e10cSrcweir const sal_Int32 nMax = aSeq.getLength() - 1; 282cdf0e10cSrcweir OUString aVal; 283cdf0e10cSrcweir OUStringBuffer aBuf; 284cdf0e10cSrcweir 285cdf0e10cSrcweir for( sal_Int32 i = 0; i <= nMax; ++i ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir aBuf.append( aSeq[i] ); 288cdf0e10cSrcweir if( i < nMax ) 289cdf0e10cSrcweir aBuf.append( sal_Unicode( ' ' )); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir aResult = aBuf.makeStringAndClear(); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir else if( xSequence.is()) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir Sequence< uno::Any > aSeq( xSequence->getData()); 296cdf0e10cSrcweir 297cdf0e10cSrcweir const sal_Int32 nMax = aSeq.getLength() - 1; 298cdf0e10cSrcweir OUString aVal; 299cdf0e10cSrcweir OUStringBuffer aBuf; 300cdf0e10cSrcweir double fNum = 0; 301cdf0e10cSrcweir 302cdf0e10cSrcweir for( sal_Int32 i = 0; i <= nMax; ++i ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir if( aSeq[i] >>= aVal ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir aBuf.append( aVal ); 307cdf0e10cSrcweir if( i < nMax ) 308cdf0e10cSrcweir aBuf.append( sal_Unicode( ' ' )); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir else if( aSeq[ i ] >>= fNum ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir aBuf.append( fNum ); 313cdf0e10cSrcweir if( i < nMax ) 314cdf0e10cSrcweir aBuf.append( sal_Unicode( ' ' )); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir } 317cdf0e10cSrcweir aResult = aBuf.makeStringAndClear(); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir return aResult; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir OUString getLabelForLabeledDataSequence( 325cdf0e10cSrcweir const Reference< chart2::data::XLabeledDataSequence > & xLabeledSeq ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir OUString aResult; 328cdf0e10cSrcweir if( xLabeledSeq.is()) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); 331cdf0e10cSrcweir if( xSeq.is() ) 332cdf0e10cSrcweir aResult = lcl_getDataSequenceLabel( xSeq ); 333cdf0e10cSrcweir if( !xSeq.is() || !aResult.getLength() ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir // no label set or label content is empty -> use auto-generated one 336cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues() ); 337cdf0e10cSrcweir if( xValueSeq.is() ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir Sequence< OUString > aLabels( xValueSeq->generateLabel( 340cdf0e10cSrcweir chart2::data::LabelOrigin_SHORT_SIDE ) ); 341cdf0e10cSrcweir // no labels returned is interpreted as: auto-generation not 342cdf0e10cSrcweir // supported by sequence 343cdf0e10cSrcweir if( aLabels.getLength() ) 344cdf0e10cSrcweir aResult=aLabels[0]; 345cdf0e10cSrcweir else 346cdf0e10cSrcweir { 347cdf0e10cSrcweir //todo?: maybe use the index of the series as name 348cdf0e10cSrcweir //but as the index may change it would be better to have such a name persistent 349cdf0e10cSrcweir //what is not possible at the moment 350cdf0e10cSrcweir //--> maybe use the identifier as part of the name ... 351cdf0e10cSrcweir aResult = lcl_getDataSequenceLabel( xValueSeq ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir return aResult; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir OUString getDataSeriesLabel( 360cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 361cdf0e10cSrcweir const OUString & rLabelSequenceRole ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir OUString aResult; 364cdf0e10cSrcweir 365cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); 366cdf0e10cSrcweir if( xSource.is()) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( 369cdf0e10cSrcweir ::chart::DataSeriesHelper::getDataSequenceByRole( xSource, rLabelSequenceRole )); 370cdf0e10cSrcweir if( xLabeledSeq.is()) 371cdf0e10cSrcweir aResult = getLabelForLabeledDataSequence( xLabeledSeq ); 372cdf0e10cSrcweir else 373cdf0e10cSrcweir { 374cdf0e10cSrcweir // special case: labeled data series with only a label and no values may 375cdf0e10cSrcweir // serve as label 376cdf0e10cSrcweir xLabeledSeq.set( lcl_findLSequenceWithOnlyLabel( xSource )); 377cdf0e10cSrcweir if( xLabeledSeq.is()) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); 380cdf0e10cSrcweir if( xSeq.is()) 381cdf0e10cSrcweir aResult = lcl_getDataSequenceLabel( xSeq ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir return aResult; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir void setStackModeAtSeries( 391cdf0e10cSrcweir const Sequence< Reference< chart2::XDataSeries > > & aSeries, 392cdf0e10cSrcweir const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, 393cdf0e10cSrcweir StackMode eStackMode ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir if( eStackMode == StackMode_AMBIGUOUS ) 396cdf0e10cSrcweir return; 397cdf0e10cSrcweir 398cdf0e10cSrcweir const OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "StackingDirection" )); 399cdf0e10cSrcweir const uno::Any aPropValue = uno::makeAny( 400cdf0e10cSrcweir ( (eStackMode == StackMode_Y_STACKED) || 401cdf0e10cSrcweir (eStackMode == StackMode_Y_STACKED_PERCENT) ) 402cdf0e10cSrcweir ? chart2::StackingDirection_Y_STACKING 403cdf0e10cSrcweir : (eStackMode == StackMode_Z_STACKED ) 404cdf0e10cSrcweir ? chart2::StackingDirection_Z_STACKING 405cdf0e10cSrcweir : chart2::StackingDirection_NO_STACKING ); 406cdf0e10cSrcweir 407cdf0e10cSrcweir std::set< sal_Int32 > aAxisIndexSet; 408cdf0e10cSrcweir for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir try 411cdf0e10cSrcweir { 412cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( aSeries[i], uno::UNO_QUERY ); 413cdf0e10cSrcweir if( xProp.is() ) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir xProp->setPropertyValue( aPropName, aPropValue ); 416cdf0e10cSrcweir 417cdf0e10cSrcweir sal_Int32 nAxisIndex; 418cdf0e10cSrcweir xProp->getPropertyValue( C2U("AttachedAxisIndex") ) >>= nAxisIndex; 419cdf0e10cSrcweir aAxisIndexSet.insert(nAxisIndex); 420cdf0e10cSrcweir } 421cdf0e10cSrcweir } 422cdf0e10cSrcweir catch( uno::Exception & ex ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir if( xCorrespondingCoordinateSystem.is() && 429cdf0e10cSrcweir 1 < xCorrespondingCoordinateSystem->getDimension() ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir sal_Int32 nAxisIndexCount = aAxisIndexSet.size(); 432cdf0e10cSrcweir if( !nAxisIndexCount ) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir aAxisIndexSet.insert(0); 435cdf0e10cSrcweir nAxisIndexCount = aAxisIndexSet.size(); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir for( ::std::set< sal_Int32 >::const_iterator aIt = aAxisIndexSet.begin(); 439cdf0e10cSrcweir aIt != aAxisIndexSet.end(); ++aIt ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir sal_Int32 nAxisIndex = *aIt; 442cdf0e10cSrcweir Reference< chart2::XAxis > xAxis( 443cdf0e10cSrcweir xCorrespondingCoordinateSystem->getAxisByDimension( 1, nAxisIndex )); 444cdf0e10cSrcweir if( xAxis.is()) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir sal_Bool bPercent = (eStackMode == StackMode_Y_STACKED_PERCENT); 447cdf0e10cSrcweir chart2::ScaleData aScaleData = xAxis->getScaleData(); 448cdf0e10cSrcweir 449cdf0e10cSrcweir if( bPercent != (aScaleData.AxisType==chart2::AxisType::PERCENT) ) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir if( bPercent ) 452cdf0e10cSrcweir aScaleData.AxisType = chart2::AxisType::PERCENT; 453cdf0e10cSrcweir else 454cdf0e10cSrcweir aScaleData.AxisType = chart2::AxisType::REALNUMBER; 455cdf0e10cSrcweir xAxis->setScaleData( aScaleData ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir } 458cdf0e10cSrcweir } 459cdf0e10cSrcweir } 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir sal_Int32 getAttachedAxisIndex( const Reference< chart2::XDataSeries > & xSeries ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir sal_Int32 nRet = 0; 465cdf0e10cSrcweir try 466cdf0e10cSrcweir { 467cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); 468cdf0e10cSrcweir if( xProp.is() ) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir xProp->getPropertyValue( C2U("AttachedAxisIndex") ) >>= nRet; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir } 473cdf0e10cSrcweir catch( uno::Exception & ex ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 476cdf0e10cSrcweir } 477cdf0e10cSrcweir return nRet; 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir sal_Int32 getNumberFormatKeyFromAxis( 481cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 482cdf0e10cSrcweir const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, 483cdf0e10cSrcweir sal_Int32 nDimensionIndex, 484cdf0e10cSrcweir sal_Int32 nAxisIndex /* = -1 */ ) 485cdf0e10cSrcweir { 486cdf0e10cSrcweir sal_Int32 nResult = 0; 487cdf0e10cSrcweir if( nAxisIndex == -1 ) 488cdf0e10cSrcweir nAxisIndex = getAttachedAxisIndex( xSeries ); 489cdf0e10cSrcweir try 490cdf0e10cSrcweir { 491cdf0e10cSrcweir Reference< beans::XPropertySet > xAxisProp( 492cdf0e10cSrcweir xCorrespondingCoordinateSystem->getAxisByDimension( nDimensionIndex, nAxisIndex ), uno::UNO_QUERY ); 493cdf0e10cSrcweir if( xAxisProp.is()) 494cdf0e10cSrcweir xAxisProp->getPropertyValue( C2U("NumberFormat")) >>= nResult; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir catch( const uno::Exception & ex ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir 501cdf0e10cSrcweir return nResult; 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > getCoordinateSystemOfSeries( 505cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 506cdf0e10cSrcweir const Reference< chart2::XDiagram > & xDiagram ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > xResult; 509cdf0e10cSrcweir Reference< chart2::XChartType > xDummy; 510cdf0e10cSrcweir lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xResult, xDummy ); 511cdf0e10cSrcweir 512cdf0e10cSrcweir return xResult; 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir Reference< chart2::XChartType > getChartTypeOfSeries( 516cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 517cdf0e10cSrcweir const Reference< chart2::XDiagram > & xDiagram ) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir Reference< chart2::XChartType > xResult; 520cdf0e10cSrcweir Reference< chart2::XCoordinateSystem > xDummy; 521cdf0e10cSrcweir lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xDummy, xResult ); 522cdf0e10cSrcweir 523cdf0e10cSrcweir return xResult; 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir void deleteSeries( 527cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xSeries, 528cdf0e10cSrcweir const Reference< chart2::XChartType > & xChartType ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir try 531cdf0e10cSrcweir { 532cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY_THROW ); 533cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > > aSeries( 534cdf0e10cSrcweir ContainerHelper::SequenceToVector( xSeriesCnt->getDataSeries())); 535cdf0e10cSrcweir ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt = 536cdf0e10cSrcweir ::std::find( aSeries.begin(), aSeries.end(), xSeries ); 537cdf0e10cSrcweir if( aIt != aSeries.end()) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir aSeries.erase( aIt ); 540cdf0e10cSrcweir xSeriesCnt->setDataSeries( ContainerHelper::ContainerToSequence( aSeries )); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir } 543cdf0e10cSrcweir catch( uno::Exception & ex ) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir void switchSymbolsOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, 550cdf0e10cSrcweir bool bSymbolsOn, sal_Int32 nSeriesIndex ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir if( !xSeriesProperties.is() ) 553cdf0e10cSrcweir return; 554cdf0e10cSrcweir 555cdf0e10cSrcweir chart2::Symbol aSymbProp; 556cdf0e10cSrcweir if( (xSeriesProperties->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp ) ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir if( !bSymbolsOn ) 559cdf0e10cSrcweir aSymbProp.Style = chart2::SymbolStyle_NONE; 560cdf0e10cSrcweir else if( aSymbProp.Style == chart2::SymbolStyle_NONE ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir aSymbProp.Style = chart2::SymbolStyle_STANDARD; 563cdf0e10cSrcweir aSymbProp.StandardSymbol = nSeriesIndex; 564cdf0e10cSrcweir } 565cdf0e10cSrcweir xSeriesProperties->setPropertyValue( C2U( "Symbol" ), uno::makeAny( aSymbProp )); 566cdf0e10cSrcweir } 567cdf0e10cSrcweir //todo: check attributed data points 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir void switchLinesOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, bool bLinesOn ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir if( !xSeriesProperties.is() ) 573cdf0e10cSrcweir return; 574cdf0e10cSrcweir 575cdf0e10cSrcweir if( bLinesOn ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir // keep line-styles that are not NONE 578cdf0e10cSrcweir drawing::LineStyle eLineStyle; 579cdf0e10cSrcweir if( (xSeriesProperties->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle ) && 580cdf0e10cSrcweir eLineStyle == drawing::LineStyle_NONE ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir xSeriesProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID ) ); 583cdf0e10cSrcweir } 584cdf0e10cSrcweir } 585cdf0e10cSrcweir else 586cdf0e10cSrcweir xSeriesProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir void makeLinesThickOrThin( const Reference< beans::XPropertySet > & xSeriesProperties, bool bThick ) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir if( !xSeriesProperties.is() ) 592cdf0e10cSrcweir return; 593cdf0e10cSrcweir 594cdf0e10cSrcweir sal_Int32 nNewValue = bThick ? 80 : 0; 595cdf0e10cSrcweir sal_Int32 nOldValue = 0; 596cdf0e10cSrcweir if( (xSeriesProperties->getPropertyValue( C2U( "LineWidth" )) >>= nOldValue ) && 597cdf0e10cSrcweir nOldValue != nNewValue ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir if( !(bThick && nOldValue>0)) 600cdf0e10cSrcweir xSeriesProperties->setPropertyValue( C2U( "LineWidth" ), uno::makeAny( nNewValue ) ); 601cdf0e10cSrcweir } 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir void setPropertyAlsoToAllAttributedDataPoints( const Reference< chart2::XDataSeries >& xSeries, 605cdf0e10cSrcweir const OUString& rPropertyName, const uno::Any& rPropertyValue ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); 608cdf0e10cSrcweir if( !xSeriesProperties.is() ) 609cdf0e10cSrcweir return; 610cdf0e10cSrcweir 611cdf0e10cSrcweir xSeriesProperties->setPropertyValue( rPropertyName, rPropertyValue ); 612cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; 613cdf0e10cSrcweir if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); 618cdf0e10cSrcweir if(!xPointProp.is()) 619cdf0e10cSrcweir continue; 620cdf0e10cSrcweir xPointProp->setPropertyValue( rPropertyName, rPropertyValue ); 621cdf0e10cSrcweir } 622cdf0e10cSrcweir } 623cdf0e10cSrcweir } 624cdf0e10cSrcweir 625cdf0e10cSrcweir bool hasAttributedDataPointDifferentValue( const Reference< chart2::XDataSeries >& xSeries, 626cdf0e10cSrcweir const OUString& rPropertyName, const uno::Any& rPropertyValue ) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); 629cdf0e10cSrcweir if( !xSeriesProperties.is() ) 630cdf0e10cSrcweir return false; 631cdf0e10cSrcweir 632cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; 633cdf0e10cSrcweir if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) 634cdf0e10cSrcweir { 635cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); 638cdf0e10cSrcweir if(!xPointProp.is()) 639cdf0e10cSrcweir continue; 640cdf0e10cSrcweir uno::Any aPointValue( xPointProp->getPropertyValue( rPropertyName ) ); 641cdf0e10cSrcweir if( !( rPropertyValue==aPointValue ) ) 642cdf0e10cSrcweir return true; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir } 645cdf0e10cSrcweir return false; 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir bool areAllSeriesAttachedToSameAxis( const uno::Reference< chart2::XChartType >& xChartType, sal_Int32 & rOutAxisIndex ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir try 651cdf0e10cSrcweir { 652cdf0e10cSrcweir uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY_THROW ); 653cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesSeq( xDataSeriesContainer->getDataSeries()); 654cdf0e10cSrcweir 655cdf0e10cSrcweir const sal_Int32 nSeriesCount( aSeriesSeq.getLength()); 656cdf0e10cSrcweir // AxisIndex can only be 0 or 1 657cdf0e10cSrcweir sal_Int32 nSeriesAtFirstAxis = 0; 658cdf0e10cSrcweir sal_Int32 nSeriesAtSecondAxis = 0; 659cdf0e10cSrcweir 660cdf0e10cSrcweir for( sal_Int32 nI = 0; nI < nSeriesCount; ++nI ) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir uno::Reference< chart2::XDataSeries > xSeries( aSeriesSeq[nI], uno::UNO_QUERY ); 663cdf0e10cSrcweir sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex( xSeries ); 664cdf0e10cSrcweir if( nAxisIndex == 0 ) 665cdf0e10cSrcweir ++nSeriesAtFirstAxis; 666cdf0e10cSrcweir else if( nAxisIndex == 1 ) 667cdf0e10cSrcweir ++nSeriesAtSecondAxis; 668cdf0e10cSrcweir } 669cdf0e10cSrcweir OSL_ENSURE( nSeriesAtFirstAxis + nSeriesAtSecondAxis == nSeriesCount, "Invalid axis index found" ); 670cdf0e10cSrcweir 671cdf0e10cSrcweir if( nSeriesAtFirstAxis == nSeriesCount ) 672cdf0e10cSrcweir rOutAxisIndex = 0; 673cdf0e10cSrcweir else if( nSeriesAtSecondAxis == nSeriesCount ) 674cdf0e10cSrcweir rOutAxisIndex = 1; 675cdf0e10cSrcweir 676cdf0e10cSrcweir return ( nSeriesAtFirstAxis == nSeriesCount || 677cdf0e10cSrcweir nSeriesAtSecondAxis == nSeriesCount ); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir catch( const uno::Exception & ex ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 682cdf0e10cSrcweir return false; 683cdf0e10cSrcweir } 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir namespace 687cdf0e10cSrcweir { 688cdf0e10cSrcweir 689cdf0e10cSrcweir bool lcl_SequenceHasUnhiddenData( const uno::Reference< chart2::data::XDataSequence >& xDataSequence ) 690cdf0e10cSrcweir { 691cdf0e10cSrcweir if( !xDataSequence.is() ) 692cdf0e10cSrcweir return false; 693cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY ); 694cdf0e10cSrcweir if( xProp.is() ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir uno::Sequence< sal_Int32 > aHiddenValues; 697cdf0e10cSrcweir try 698cdf0e10cSrcweir { 699cdf0e10cSrcweir xProp->getPropertyValue( C2U( "HiddenValues" ) ) >>= aHiddenValues; 700cdf0e10cSrcweir if( !aHiddenValues.getLength() ) 701cdf0e10cSrcweir return true; 702cdf0e10cSrcweir } 703cdf0e10cSrcweir catch( uno::Exception& e ) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir (void)e; // avoid warning 706cdf0e10cSrcweir return true; 707cdf0e10cSrcweir } 708cdf0e10cSrcweir } 709cdf0e10cSrcweir if( xDataSequence->getData().getLength() ) 710cdf0e10cSrcweir return true; 711cdf0e10cSrcweir return false; 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir } 715cdf0e10cSrcweir 716cdf0e10cSrcweir bool hasUnhiddenData( const uno::Reference< chart2::XDataSeries >& xSeries ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource > xDataSource = 719cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource >( xSeries, uno::UNO_QUERY ); 720cdf0e10cSrcweir 721cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aDataSequences = xDataSource->getDataSequences(); 722cdf0e10cSrcweir 723cdf0e10cSrcweir for(sal_Int32 nN = aDataSequences.getLength();nN--;) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir if( !aDataSequences[nN].is() ) 726cdf0e10cSrcweir continue; 727cdf0e10cSrcweir if( lcl_SequenceHasUnhiddenData( aDataSequences[nN]->getValues() ) ) 728cdf0e10cSrcweir return true; 729cdf0e10cSrcweir if( lcl_SequenceHasUnhiddenData( aDataSequences[nN]->getLabel() ) ) 730cdf0e10cSrcweir return true; 731cdf0e10cSrcweir } 732cdf0e10cSrcweir return false; 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir struct lcl_LessIndex 736cdf0e10cSrcweir { 737cdf0e10cSrcweir inline bool operator() ( const sal_Int32& first, const sal_Int32& second ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir return ( first < second ); 740cdf0e10cSrcweir } 741cdf0e10cSrcweir }; 742cdf0e10cSrcweir 743cdf0e10cSrcweir sal_Int32 translateIndexFromHiddenToFullSequence( sal_Int32 nIndex, const Reference< chart2::data::XDataSequence >& xDataSequence, bool bTranslate ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir if( !bTranslate ) 746cdf0e10cSrcweir return nIndex; 747cdf0e10cSrcweir 748cdf0e10cSrcweir try 749cdf0e10cSrcweir { 750cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xProp( xDataSequence, uno::UNO_QUERY ); 751cdf0e10cSrcweir if( xProp.is()) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir Sequence<sal_Int32> aHiddenIndicesSeq; 754cdf0e10cSrcweir xProp->getPropertyValue( C2U("HiddenValues") ) >>= aHiddenIndicesSeq; 755cdf0e10cSrcweir if( aHiddenIndicesSeq.getLength() ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir ::std::vector< sal_Int32 > aHiddenIndices( ContainerHelper::SequenceToVector( aHiddenIndicesSeq ) ); 758cdf0e10cSrcweir ::std::sort( aHiddenIndices.begin(), aHiddenIndices.end(), lcl_LessIndex() ); 759cdf0e10cSrcweir 760cdf0e10cSrcweir sal_Int32 nHiddenCount = static_cast<sal_Int32>(aHiddenIndices.size()); 761cdf0e10cSrcweir for( sal_Int32 nN = 0; nN < nHiddenCount; ++nN) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir if( aHiddenIndices[nN] <= nIndex ) 764cdf0e10cSrcweir nIndex += 1; 765cdf0e10cSrcweir else 766cdf0e10cSrcweir break; 767cdf0e10cSrcweir } 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir } 771cdf0e10cSrcweir catch (const beans::UnknownPropertyException&) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir } 774cdf0e10cSrcweir return nIndex; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir bool hasDataLabelsAtSeries( const Reference< chart2::XDataSeries >& xSeries ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir bool bRet = false; 780cdf0e10cSrcweir try 781cdf0e10cSrcweir { 782cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); 783cdf0e10cSrcweir if( xProp.is() ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir DataPointLabel aLabel; 786cdf0e10cSrcweir if( (xProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) 787cdf0e10cSrcweir bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir } 790cdf0e10cSrcweir catch( uno::Exception &e) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 793cdf0e10cSrcweir } 794cdf0e10cSrcweir return bRet; 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir bool hasDataLabelsAtPoints( const Reference< chart2::XDataSeries >& xSeries ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir bool bRet = false; 800cdf0e10cSrcweir try 801cdf0e10cSrcweir { 802cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); 803cdf0e10cSrcweir if( xSeriesProperties.is() ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; 806cdf0e10cSrcweir if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); 811cdf0e10cSrcweir if( xPointProp.is() ) 812cdf0e10cSrcweir { 813cdf0e10cSrcweir DataPointLabel aLabel; 814cdf0e10cSrcweir if( (xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) 815cdf0e10cSrcweir bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; 816cdf0e10cSrcweir if( bRet ) 817cdf0e10cSrcweir break; 818cdf0e10cSrcweir } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir } 822cdf0e10cSrcweir } 823cdf0e10cSrcweir catch( uno::Exception &e) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir return bRet; 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir bool hasDataLabelAtPoint( const Reference< chart2::XDataSeries >& xSeries, sal_Int32 nPointIndex ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir bool bRet = false; 833cdf0e10cSrcweir try 834cdf0e10cSrcweir { 835cdf0e10cSrcweir Reference< beans::XPropertySet > xProp; 836cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); 837cdf0e10cSrcweir if( xSeriesProperties.is() ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; 840cdf0e10cSrcweir if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir ::std::vector< sal_Int32 > aIndices( ContainerHelper::SequenceToVector( aAttributedDataPointIndexList ) ); 843cdf0e10cSrcweir ::std::vector< sal_Int32 >::iterator aIt = ::std::find( aIndices.begin(), aIndices.end(), nPointIndex ); 844cdf0e10cSrcweir if( aIt != aIndices.end()) 845cdf0e10cSrcweir xProp = xSeries->getDataPointByIndex(nPointIndex); 846cdf0e10cSrcweir else 847cdf0e10cSrcweir xProp = xSeriesProperties; 848cdf0e10cSrcweir } 849cdf0e10cSrcweir if( xProp.is() ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir DataPointLabel aLabel; 852cdf0e10cSrcweir if( (xProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) 853cdf0e10cSrcweir bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir } 856cdf0e10cSrcweir } 857cdf0e10cSrcweir catch( uno::Exception &e) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 860cdf0e10cSrcweir } 861cdf0e10cSrcweir return bRet; 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir void insertDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, true /*bInsert*/ ); 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir void deleteDataLabelsFromSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, false /*bInsert*/ ); 872cdf0e10cSrcweir } 873cdf0e10cSrcweir 874cdf0e10cSrcweir 875cdf0e10cSrcweir void insertDataLabelToPoint( const Reference< beans::XPropertySet >& xPointProp ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir try 878cdf0e10cSrcweir { 879cdf0e10cSrcweir if( xPointProp.is() ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir DataPointLabel aLabel; 882cdf0e10cSrcweir xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; 883cdf0e10cSrcweir aLabel.ShowNumber = true; 884cdf0e10cSrcweir xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); 885cdf0e10cSrcweir } 886cdf0e10cSrcweir } 887cdf0e10cSrcweir catch( uno::Exception &e) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir } 892cdf0e10cSrcweir 893cdf0e10cSrcweir void deleteDataLabelsFromPoint( const Reference< beans::XPropertySet >& xPointProp ) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir try 896cdf0e10cSrcweir { 897cdf0e10cSrcweir if( xPointProp.is() ) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir DataPointLabel aLabel; 900cdf0e10cSrcweir xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; 901cdf0e10cSrcweir aLabel.ShowNumber = false; 902cdf0e10cSrcweir aLabel.ShowNumberInPercent = false; 903cdf0e10cSrcweir aLabel.ShowCategoryName = false; 904cdf0e10cSrcweir xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); 905cdf0e10cSrcweir } 906cdf0e10cSrcweir } 907cdf0e10cSrcweir catch( uno::Exception &e) 908cdf0e10cSrcweir { 909cdf0e10cSrcweir ASSERT_EXCEPTION( e ); 910cdf0e10cSrcweir } 911cdf0e10cSrcweir } 912cdf0e10cSrcweir 913cdf0e10cSrcweir } // namespace DataSeriesHelper 914cdf0e10cSrcweir } // namespace chart 915