summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2007-05-22 17:53:11 +0000
committerVladimir Glazounov <vg@openoffice.org>2007-05-22 17:53:11 +0000
commit4c2701d4cc8b27eed56172b4188b61efb8783c55 (patch)
treec2c6527acd9ed97c1dd84535f5d351d430a8f827 /chart2
parenta8471048c29a839823b156186c884ff698ccf168 (diff)
INTEGRATION: CWS chart2mst3 (1.1.4); FILE ADDED
2007/02/08 21:25:40 iha 1.1.4.17: resync m195 -> m202 2006/12/12 16:13:04 iha 1.1.4.16: #i67784# data disappear while selecting 'XY (Scatter)' having only one sequence 2006/04/28 13:41:19 bm 1.1.4.15: #i64618# reinterpretDataSeries: leave Categories in passed aInterpretedData to leave it stored at the scale 2006/04/22 11:09:48 iha 1.1.4.14: park unused categories in scale with AxisType not being CATEGORY 2005/12/21 21:29:24 iha 1.1.4.13: remove identifiers from model objects and create an index based CID protocol instead for selection purposes 2005/10/11 09:20:48 bm 1.1.4.12: license header change 2005/08/03 16:36:25 bm 1.1.4.11: algohelper.hxx split up into CommonFunctors.hxx ContainerHelper.hxx CloneHelper.hxx 2005/08/01 09:39:38 bm 1.1.4.10: use base method HasCategories to determine the existence of categories 2005/07/29 13:30:16 bm 1.1.4.9: keep unused data at the diagram, resetStyles, and other small improvements of template handling 2005/07/19 11:17:48 bm 1.1.4.8: shift data if it contains categories 2005/05/09 09:51:31 bm 1.1.4.7: moved parts of API to data namespace 2004/05/07 13:40:25 bm 1.1.4.6: context added in CTOR 2004/04/15 17:26:54 bm 1.1.4.5: cloning for data sequences 2004/03/24 10:43:41 bm 1.1.4.4: check for interface validity 2004/03/19 14:33:00 bm 1.1.4.3: XDataSource now contains XLabeledDataSources 2004/03/03 14:06:07 bm 1.1.4.2: don't recycle categories as x-values 2004/02/13 16:51:46 bm 1.1.4.1: join from changes on branch bm_post_chart01
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/model/template/XYDataInterpreter.cxx294
1 files changed, 294 insertions, 0 deletions
diff --git a/chart2/source/model/template/XYDataInterpreter.cxx b/chart2/source/model/template/XYDataInterpreter.cxx
new file mode 100644
index 000000000000..0d9f5b7fddb7
--- /dev/null
+++ b/chart2/source/model/template/XYDataInterpreter.cxx
@@ -0,0 +1,294 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: XYDataInterpreter.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: vg $ $Date: 2007-05-22 18:53:11 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_chart2.hxx"
+
+#include "XYDataInterpreter.hxx"
+#include "DataSeries.hxx"
+#include "macros.hxx"
+#include "DataSeriesHelper.hxx"
+#include "CommonConverters.hxx"
+#include "ContainerHelper.hxx"
+
+#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
+#include <com/sun/star/beans/XPropertySet.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_CHART2_DATA_XDATASINK_HPP_
+#include <com/sun/star/chart2/data/XDataSink.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UTIL_XCLONEABLE_HPP_
+#include <com/sun/star/util/XCloneable.hpp>
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::chart2;
+using namespace ::std;
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::rtl::OUString;
+
+namespace chart
+{
+
+XYDataInterpreter::XYDataInterpreter(
+ const uno::Reference< uno::XComponentContext > & xContext ) :
+ DataInterpreter( xContext )
+{
+}
+
+XYDataInterpreter::~XYDataInterpreter()
+{
+}
+
+// ____ XDataInterpreter ____
+chart2::InterpretedData SAL_CALL XYDataInterpreter::interpretDataSource(
+ const Reference< chart2::data::XDataSource >& xSource,
+ const Sequence< beans::PropertyValue >& aArguments,
+ const Sequence< Reference< XDataSeries > >& aSeriesToReUse )
+ throw (uno::RuntimeException)
+{
+ if( ! xSource.is())
+ return InterpretedData();
+
+ Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() );
+
+ Reference< data::XLabeledDataSequence > xValuesX;
+ vector< Reference< data::XLabeledDataSequence > > aSequencesVec;
+
+ Reference< data::XLabeledDataSequence > xCategories;
+ // check for categories. If true, the the categories bet parked in the axis scale, but not used via setting the Axistype to Not CATEGORY
+ bool bHasCategories = HasCategories( aArguments, aData );
+
+ // parse data
+ Sequence< Reference< data::XLabeledDataSequence > > aUnusedData;
+
+ bool bCategoriesUsed = false;
+ for( sal_Int32 nDataIdx= 0; nDataIdx < aData.getLength(); ++nDataIdx )
+ {
+ try
+ {
+ if( bHasCategories && ! bCategoriesUsed )
+ {
+ xCategories.set( aData[nDataIdx] );
+ if( xCategories.is())
+ SetRole( xCategories->getValues(), C2U("categories"));
+ bCategoriesUsed = true;
+ }
+ else if( !xValuesX.is() && (aData.getLength()>(bCategoriesUsed?2:1)) )
+ {
+ xValuesX.set( aData[nDataIdx] );
+ if( xValuesX.is())
+ SetRole( xValuesX->getValues(), C2U("values-x"));
+ }
+ else
+ {
+ aSequencesVec.push_back( aData[nDataIdx] );
+ if( aData[nDataIdx].is())
+ SetRole( aData[nDataIdx]->getValues(), C2U("values-y"));
+ }
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
+ }
+
+ // create DataSeries
+ vector< Reference< data::XLabeledDataSequence > >::const_iterator
+ aSequencesVecIt = aSequencesVec.begin();
+
+ sal_Int32 nSeriesIndex = 0;
+ vector< Reference< XDataSeries > > aSeriesVec;
+ aSeriesVec.reserve( aSequencesVec.size());
+
+ Reference< data::XLabeledDataSequence > xClonedXValues = xValuesX;
+ Reference< util::XCloneable > xCloneable( xValuesX, uno::UNO_QUERY );
+
+ for( ;aSequencesVecIt != aSequencesVec.end(); ++aSequencesVecIt, ++nSeriesIndex )
+ {
+ Sequence< Reference< data::XLabeledDataSequence > > aNewData(xValuesX.is()?2:1);
+ if( aSequencesVecIt != aSequencesVec.begin() &&
+ xCloneable.is() )
+ {
+ xClonedXValues.set( xCloneable->createClone(), uno::UNO_QUERY );
+ }
+
+ if( xValuesX.is() )
+ {
+ aNewData[0] = xClonedXValues;
+ aNewData[1] = (*aSequencesVecIt);
+ }
+ else
+ {
+ aNewData[0] = (*aSequencesVecIt);
+ }
+
+ Reference< XDataSeries > xSeries;
+ if( nSeriesIndex < aSeriesToReUse.getLength())
+ xSeries.set( aSeriesToReUse[nSeriesIndex] );
+ else
+ xSeries.set( new DataSeries( GetComponentContext() ) );
+ OSL_ASSERT( xSeries.is() );
+ Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY );
+ OSL_ASSERT( xSink.is() );
+ xSink->setData( aNewData );
+
+ aSeriesVec.push_back( xSeries );
+ }
+
+ Sequence< Sequence< Reference< XDataSeries > > > aSeries(1);
+ aSeries[0] = ContainerHelper::ContainerToSequence( aSeriesVec );
+ return InterpretedData( aSeries, xCategories, aUnusedData );
+}
+
+chart2::InterpretedData SAL_CALL XYDataInterpreter::reinterpretDataSeries(
+ const chart2::InterpretedData& aInterpretedData )
+ throw (uno::RuntimeException)
+{
+ InterpretedData aResult( aInterpretedData );
+ vector< Reference< data::XLabeledDataSequence > > aUnused(
+ ContainerHelper::SequenceToVector( aInterpretedData.UnusedData ));
+
+ sal_Int32 i=0;
+ Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series ));
+ const sal_Int32 nCount = aSeries.getLength();
+ for( ; i<nCount; ++i )
+ {
+ try
+ {
+ Reference< data::XDataSource > xSeriesSource( aSeries[i], uno::UNO_QUERY_THROW );
+ Sequence< Reference< data::XLabeledDataSequence > > aNewSequences;
+
+ // values-y
+ Reference< data::XLabeledDataSequence > xValuesY(
+ DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-y"), false ));
+ Reference< data::XLabeledDataSequence > xValuesX(
+ DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-x"), false ));
+ // re-use values-... as values-x/values-y
+ if( ! xValuesX.is() ||
+ ! xValuesY.is())
+ {
+ vector< Reference< data::XLabeledDataSequence > > aValueSeqVec(
+ DataSeriesHelper::getAllDataSequencesByRole(
+ xSeriesSource->getDataSequences(), C2U("values"), true ));
+ if( xValuesX.is())
+ aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesX ));
+ if( xValuesY.is())
+ aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesY ));
+
+ size_t nIndex = 0;
+ if( ! xValuesY.is() &&
+ aValueSeqVec.size() > nIndex )
+ {
+ xValuesY.set( aValueSeqVec[nIndex++] );
+ if( xValuesY.is())
+ SetRole( xValuesY->getValues(), C2U("values-y"));
+ }
+
+ if( ! xValuesX.is() &&
+ aValueSeqVec.size() > nIndex )
+ {
+ xValuesX.set( aValueSeqVec[nIndex++] );
+ if( xValuesX.is())
+ SetRole( xValuesY->getValues(), C2U("values-x"));
+ }
+ }
+ if( xValuesY.is())
+ {
+ if( xValuesX.is())
+ {
+ aNewSequences.realloc(2);
+ aNewSequences[0] = xValuesX;
+ aNewSequences[1] = xValuesY;
+ }
+ else
+ {
+ aNewSequences.realloc(1);
+ aNewSequences[0] = xValuesY;
+ }
+ }
+
+ Sequence< Reference< data::XLabeledDataSequence > > aSeqs( xSeriesSource->getDataSequences());
+ if( aSeqs.getLength() != aNewSequences.getLength() )
+ {
+ sal_Int32 j=0;
+ for( ; j<aSeqs.getLength(); ++j )
+ {
+ if( aSeqs[j] != xValuesY &&
+ aSeqs[j] != xValuesX )
+ aUnused.push_back( aSeqs[j] );
+ }
+ Reference< data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY_THROW );
+ xSink->setData( aNewSequences );
+ aResult.UnusedData = ContainerHelper::ContainerToSequence( aUnused );
+ }
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
+ }
+
+ return aResult;
+}
+
+// criterion: all series must have exactly two data::XLabeledDataSequences
+sal_Bool SAL_CALL XYDataInterpreter::isDataCompatible(
+ const chart2::InterpretedData& aInterpretedData )
+ throw (uno::RuntimeException)
+{
+ Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series ));
+ for( sal_Int32 i=0; i<aSeries.getLength(); ++i )
+ {
+ try
+ {
+ Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW );
+ Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences());
+ if( aSeq.getLength() != 2 )
+ return sal_False;
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
+ }
+
+ return sal_True;
+}
+
+} // namespace chart