From a07cce8d066a9804c2642d1e7a7c98bb814f2c3a Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Mon, 30 Dec 2013 08:39:19 +0100 Subject: [PATCH] remaining chart work for time based charting Change-Id: Iac33c81df199a942ddf073f9eb1b34e147a34f3c --- chart2/inc/ChartModel.hxx | 2 + chart2/inc/ChartView.hxx | 8 ++-- chart2/source/model/main/ChartModel.cxx | 9 +++++ chart2/source/view/inc/VDataSeries.hxx | 12 +++--- chart2/source/view/inc/VSeriesPlotter.hxx | 3 -- chart2/source/view/main/ChartView.cxx | 49 ++++++++++++++++++++--- chart2/source/view/main/VDataSeries.cxx | 29 ++++++++++++++ 7 files changed, 95 insertions(+), 17 deletions(-) diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx index af0d6988f15d..158e4d1f8a69 100644 --- a/chart2/inc/ChartModel.hxx +++ b/chart2/inc/ChartModel.hxx @@ -584,6 +584,8 @@ public: bool isTimeBased() const; void setTimeBased(bool bTimeBased); + + void getNextTimePoint(); }; } // namespace chart diff --git a/chart2/inc/ChartView.hxx b/chart2/inc/ChartView.hxx index 80f0d27c571b..66925ab89c16 100644 --- a/chart2/inc/ChartView.hxx +++ b/chart2/inc/ChartView.hxx @@ -43,6 +43,7 @@ #include #include +#include class SdrPage; @@ -51,20 +52,19 @@ namespace chart { class VCoordinateSystem; class DrawModelWrapper; class SeriesPlotterContainer; -class VDataSeriesGroup; +class VDataSeries; struct TimeBasedInfo { TimeBasedInfo(): bTimeBased(false), - nFrame(0), - m_pZSlots(NULL) {} + nFrame(0) {} bool bTimeBased; size_t nFrame; // only valid when we are in the time based mode - ::std::vector< ::std::vector< VDataSeriesGroup > >* m_pZSlots; + ::std::vector< std::vector< VDataSeries* > > m_aDataSeriesList; }; /** diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index 842501fee785..4e6d245e5766 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -58,6 +58,7 @@ #include #include #include +#include // header for class SvNumberFormatter #include @@ -1356,6 +1357,14 @@ void ChartModel::setTimeBased(bool bTimeBased) mbTimeBased = bTimeBased; } +void ChartModel::getNextTimePoint() +{ + uno::Reference< chart2::XTimeBased > xTimeBased(getUsedData(), uno::UNO_QUERY); + SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting"); + if(xTimeBased.is()) + xTimeBased->switchToNext(); +} + } // namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/inc/VDataSeries.hxx b/chart2/source/view/inc/VDataSeries.hxx index 94827d154aa9..7989b3e996eb 100644 --- a/chart2/source/view/inc/VDataSeries.hxx +++ b/chart2/source/view/inc/VDataSeries.hxx @@ -40,7 +40,7 @@ namespace chart { -class VDataSequence : boost::noncopyable +class VDataSequence { public: void init( const ::com::sun::star::uno::Reference< @@ -62,10 +62,6 @@ class VDataSeries SAL_FINAL : boost::noncopyable public: VDataSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xDataSeries ); - // for time based charting - VDataSeries( const ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XDataSeries >& xDataSeries, - VDataSeries* pOldSeries, double nPercent); ~VDataSeries(); @@ -176,11 +172,17 @@ public: void setMissingValueTreatment( sal_Int32 nMissingValueTreatment ); sal_Int32 getMissingValueTreatment() const; + void setOldTimeBased( VDataSeries* pOldSeries, double nPercent ); + VDataSeries* createCopyForTimeBased() const; + private: //methods ::com::sun::star::chart2::DataPointLabel* getDataPointLabel( sal_Int32 index ) const; void adaptPointCache( sal_Int32 nNewPointIndex ) const; + // for copies for time based charting + VDataSeries(); + public: //member ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > m_xGroupShape; ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > m_xLabelsGroupShape; diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 7c20ee54a9a3..2cdbe6e60b1e 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -384,9 +384,6 @@ protected: VDataSeries* getFirstSeries() const; - // ugly hack to cache the data for the next turn - const std::vector< std::vector< VDataSeriesGroup > >& getData(); - protected: PlottingPositionHelper* m_pMainPosHelper; diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index d32b9cebd312..a01bffdd20eb 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -2444,6 +2444,25 @@ void ChartView::createShapes() SeriesPlotterContainer aSeriesPlotterContainer( m_aVCooSysList ); aSeriesPlotterContainer.initializeCooSysAndSeriesPlotter( mrChartModel ); + if(maTimeBased.bTimeBased) + { + std::vector& rSeriesPlotter = + aSeriesPlotterContainer.getSeriesPlotterList(); + size_t n = rSeriesPlotter.size(); + for(size_t i = 0; i < n; ++i) + { + std::vector< VDataSeries* > aAllNewDataSeries = + rSeriesPlotter[i]->getAllSeries(); + std::vector< VDataSeries* >& rAllOldDataSeries = + maTimeBased.m_aDataSeriesList[i]; + size_t m = std::min(aAllNewDataSeries.size(), rAllOldDataSeries.size()); + for(size_t j = 0; j < m; ++j) + { + aAllNewDataSeries[j]->setOldTimeBased( + rAllOldDataSeries[j], (maTimeBased.nFrame % 60)/60.0); + } + } + } lcl_createLegend( LegendHelper::getLegend( mrChartModel ), mxRootShape, m_xShapeFactory, m_xCC , aRemainingSpace, aPageSize, mrChartModel, aSeriesPlotterContainer.getLegendEntryProviderList() @@ -2529,6 +2548,31 @@ void ChartView::createShapes() //cleanup: remove all empty group shapes to avoid grey border lines: lcl_removeEmptyGroupShapes( mxRootShape ); + + if(maTimeBased.bTimeBased && maTimeBased.nFrame % 60 == 0) + { + // create copy of the data for next frame + std::vector& rSeriesPlotter = + aSeriesPlotterContainer.getSeriesPlotterList(); + size_t n = rSeriesPlotter.size(); + maTimeBased.m_aDataSeriesList.clear(); + maTimeBased.m_aDataSeriesList.resize(n); + for(size_t i = 0; i < n; ++i) + { + std::vector< VDataSeries* > aAllNewDataSeries = + rSeriesPlotter[i]->getAllSeries(); + std::vector< VDataSeries* >& rAllOldDataSeries = + maTimeBased.m_aDataSeriesList[i]; + size_t m = std::min(aAllNewDataSeries.size(), rAllOldDataSeries.size()); + for(size_t j = 0; j < m; ++j) + { + rAllOldDataSeries.push_back( aAllNewDataSeries[j]-> + createCopyForTimeBased() ); + } + } + + mrChartModel.getNextTimePoint(); + } } // #i12587# support for shapes in chart @@ -2540,11 +2584,6 @@ void ChartView::createShapes() pShapeFactory->render( mxRootShape ); - if(maTimeBased.bTimeBased && maTimeBased.nFrame % 60 == 0) - { - // create copy of the data for next frame - - } if(maTimeBased.bTimeBased) { maTimeBased.nFrame++; diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx index 2f170ebae9ce..981d832d211a 100644 --- a/chart2/source/view/main/VDataSeries.cxx +++ b/chart2/source/view/main/VDataSeries.cxx @@ -182,6 +182,8 @@ VDataSeries::VDataSeries( const uno::Reference< XDataSeries >& xDataSeries ) , m_nCurrentAttributedPoint(-1) , m_nMissingValueTreatment(::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP) , m_bAllowPercentValueInDataLabel(false) + , mpOldSeries(NULL) + , mnPercent(0.0) { ::rtl::math::setNan( & m_fXMeanValue ); ::rtl::math::setNan( & m_fYMeanValue ); @@ -1053,6 +1055,33 @@ sal_Int32 VDataSeries::getMissingValueTreatment() const return m_nMissingValueTreatment; } +VDataSeries::VDataSeries() +{ +} + +void VDataSeries::setOldTimeBased( VDataSeries* pOldSeries, double nPercent ) +{ + mnPercent = nPercent; + mpOldSeries = pOldSeries; +} + +VDataSeries* VDataSeries::createCopyForTimeBased() const +{ + VDataSeries* pNew = new VDataSeries(); + pNew->m_aValues_X = m_aValues_X; + pNew->m_aValues_Y = m_aValues_Y; + pNew->m_aValues_Z = m_aValues_Z; + pNew->m_aValues_Y_Min = m_aValues_Y_Min; + pNew->m_aValues_Y_Max = m_aValues_Y_Max; + pNew->m_aValues_Y_First = m_aValues_Y_First; + pNew->m_aValues_Y_Last = m_aValues_Y_Last; + pNew->m_aValues_Bubble_Size = m_aValues_Bubble_Size; + + pNew->m_nPointCount = m_nPointCount; + + return pNew; +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */