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
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
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.
19*cde9e8dcSAndrew Rist *
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 "ChartTypeTemplate.hxx"
27cdf0e10cSrcweir #include "PropertyHelper.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
30cdf0e10cSrcweir #include "DataInterpreter.hxx"
31cdf0e10cSrcweir #include "CommonConverters.hxx"
32cdf0e10cSrcweir #include "ContainerHelper.hxx"
33cdf0e10cSrcweir #include "ChartTypeHelper.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "CartesianCoordinateSystem.hxx"
36cdf0e10cSrcweir #include "AxisHelper.hxx"
37cdf0e10cSrcweir #include "LegendHelper.hxx"
38cdf0e10cSrcweir #include "DiagramHelper.hxx"
39cdf0e10cSrcweir #include "ChartDebugTrace.hxx"
40cdf0e10cSrcweir #include "AxisIndexDefines.hxx"
41cdf0e10cSrcweir #include <cppuhelper/component_context.hxx>
42cdf0e10cSrcweir #include <com/sun/star/chart/ChartSolidType.hpp>
43cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp>
44cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
45cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
46cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <algorithm>
49cdf0e10cSrcweir #include <iterator>
50cdf0e10cSrcweir
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
53cdf0e10cSrcweir
54cdf0e10cSrcweir using ::rtl::OUString;
55cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
56cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
57cdf0e10cSrcweir using ::com::sun::star::uno::Any;
58cdf0e10cSrcweir
59cdf0e10cSrcweir // ======================================================================
60cdf0e10cSrcweir
61cdf0e10cSrcweir namespace
62cdf0e10cSrcweir {
63cdf0e10cSrcweir
lcl_applyDefaultStyle(const Reference<XDataSeries> & xSeries,sal_Int32 nIndex,const Reference<XDiagram> & xDiagram)64cdf0e10cSrcweir void lcl_applyDefaultStyle(
65cdf0e10cSrcweir const Reference< XDataSeries > & xSeries,
66cdf0e10cSrcweir sal_Int32 nIndex,
67cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir // @deprecated: correct default color should be found by view without
70cdf0e10cSrcweir // setting color as hard attribute
71cdf0e10cSrcweir if( xSeries.is() && xDiagram.is())
72cdf0e10cSrcweir {
73cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
74cdf0e10cSrcweir Reference< chart2::XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme());
75cdf0e10cSrcweir if( xSeriesProp.is() && xColorScheme.is() )
76cdf0e10cSrcweir xSeriesProp->setPropertyValue(
77cdf0e10cSrcweir C2U("Color"),
78cdf0e10cSrcweir uno::makeAny( xColorScheme->getColorByIndex( nIndex )));
79cdf0e10cSrcweir }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
lcl_ensureCorrectLabelPlacement(const Reference<beans::XPropertySet> & xProp,const uno::Sequence<sal_Int32> & rAvailablePlacements)82cdf0e10cSrcweir void lcl_ensureCorrectLabelPlacement( const Reference< beans::XPropertySet >& xProp, const uno::Sequence < sal_Int32 >& rAvailablePlacements )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir sal_Int32 nLabelPlacement=0;
85cdf0e10cSrcweir if( xProp.is() && (xProp->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nLabelPlacement) )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir bool bValid = false;
88cdf0e10cSrcweir for( sal_Int32 nN = 0; nN < rAvailablePlacements.getLength(); nN++ )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir if( rAvailablePlacements[nN] == nLabelPlacement )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir bValid = true;
93cdf0e10cSrcweir break;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir }
96cdf0e10cSrcweir if( !bValid )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir uno::Any aNewValue;
99cdf0e10cSrcweir //otherwise use the first supported one
100cdf0e10cSrcweir if( rAvailablePlacements.getLength() )
101cdf0e10cSrcweir aNewValue <<=rAvailablePlacements[0];
102cdf0e10cSrcweir xProp->setPropertyValue( C2U("LabelPlacement"), aNewValue );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
lcl_resetLabelPlacementIfDefault(const Reference<beans::XPropertySet> & xProp,sal_Int32 nDefaultPlacement)107cdf0e10cSrcweir void lcl_resetLabelPlacementIfDefault( const Reference< beans::XPropertySet >& xProp, sal_Int32 nDefaultPlacement )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir
110cdf0e10cSrcweir sal_Int32 nLabelPlacement=0;
111cdf0e10cSrcweir if( xProp.is() && (xProp->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nLabelPlacement) )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir if( nDefaultPlacement == nLabelPlacement )
114cdf0e10cSrcweir xProp->setPropertyValue( C2U("LabelPlacement"), uno::Any() );
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
lcl_ensureCorrectMissingValueTreatment(const Reference<chart2::XDiagram> & xDiagram,const Reference<XChartType> & xChartType)118cdf0e10cSrcweir void lcl_ensureCorrectMissingValueTreatment( const Reference< chart2::XDiagram >& xDiagram, const Reference< XChartType >& xChartType )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY );
121cdf0e10cSrcweir if( xDiaProp.is() )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir uno::Sequence < sal_Int32 > aAvailableMissingValueTreatment(
124cdf0e10cSrcweir ::chart::ChartTypeHelper::getSupportedMissingValueTreatments( xChartType ) );
125cdf0e10cSrcweir
126cdf0e10cSrcweir if( aAvailableMissingValueTreatment.getLength() )
127cdf0e10cSrcweir xDiaProp->setPropertyValue( C2U( "MissingValueTreatment" ), uno::makeAny( aAvailableMissingValueTreatment[0] ) );
128cdf0e10cSrcweir else
129cdf0e10cSrcweir xDiaProp->setPropertyValue( C2U( "MissingValueTreatment" ), uno::Any() );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir } // anonymous namespace
134cdf0e10cSrcweir
135cdf0e10cSrcweir namespace chart
136cdf0e10cSrcweir {
137cdf0e10cSrcweir
ChartTypeTemplate(Reference<uno::XComponentContext> const & xContext,const::rtl::OUString & rServiceName)138cdf0e10cSrcweir ChartTypeTemplate::ChartTypeTemplate(
139cdf0e10cSrcweir Reference< uno::XComponentContext > const & xContext,
140cdf0e10cSrcweir const ::rtl::OUString & rServiceName ) :
141cdf0e10cSrcweir m_xContext( xContext ),
142cdf0e10cSrcweir m_aServiceName( rServiceName )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
~ChartTypeTemplate()146cdf0e10cSrcweir ChartTypeTemplate::~ChartTypeTemplate()
147cdf0e10cSrcweir {}
148cdf0e10cSrcweir
149cdf0e10cSrcweir // ____ XChartTypeTemplate ____
createDiagramByDataSource(const uno::Reference<data::XDataSource> & xDataSource,const uno::Sequence<beans::PropertyValue> & aArguments)150cdf0e10cSrcweir uno::Reference< XDiagram > SAL_CALL ChartTypeTemplate::createDiagramByDataSource(
151cdf0e10cSrcweir const uno::Reference< data::XDataSource >& xDataSource,
152cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aArguments )
153cdf0e10cSrcweir throw (uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir Reference< XDiagram > xDia;
156cdf0e10cSrcweir
157cdf0e10cSrcweir try
158cdf0e10cSrcweir {
159cdf0e10cSrcweir // create diagram
160cdf0e10cSrcweir xDia.set(
161cdf0e10cSrcweir GetComponentContext()->getServiceManager()->createInstanceWithContext(
162cdf0e10cSrcweir C2U( "com.sun.star.chart2.Diagram" ),
163cdf0e10cSrcweir GetComponentContext() ),
164cdf0e10cSrcweir uno::UNO_QUERY_THROW );
165cdf0e10cSrcweir
166cdf0e10cSrcweir // modify diagram
167cdf0e10cSrcweir Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter());
168cdf0e10cSrcweir chart2::InterpretedData aData(
169cdf0e10cSrcweir xInterpreter->interpretDataSource(
170cdf0e10cSrcweir xDataSource, aArguments, Sequence< Reference< XDataSeries > >() ));
171cdf0e10cSrcweir
172cdf0e10cSrcweir Sequence< Sequence< Reference< XDataSeries > > > aSeries( aData.Series );
173cdf0e10cSrcweir sal_Int32 i, j, nCount = 0;
174cdf0e10cSrcweir for( i=0; i<aSeries.getLength(); ++i )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir for( j=0; j<aSeries[i].getLength(); ++j, ++nCount )
177cdf0e10cSrcweir lcl_applyDefaultStyle( aSeries[i][j], nCount, xDia );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir Sequence< Reference< XChartType > > aOldChartTypesSeq;
181cdf0e10cSrcweir FillDiagram( xDia, aData.Series, aData.Categories, aOldChartTypesSeq, true );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir catch( uno::Exception & ex )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir return xDia;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
supportsCategories()191cdf0e10cSrcweir sal_Bool SAL_CALL ChartTypeTemplate::supportsCategories()
192cdf0e10cSrcweir throw (uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir return sal_True;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
changeDiagram(const uno::Reference<XDiagram> & xDiagram)197cdf0e10cSrcweir void SAL_CALL ChartTypeTemplate::changeDiagram( const uno::Reference< XDiagram >& xDiagram )
198cdf0e10cSrcweir throw (uno::RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir if( ! xDiagram.is())
201cdf0e10cSrcweir return;
202cdf0e10cSrcweir
203cdf0e10cSrcweir try
204cdf0e10cSrcweir {
205cdf0e10cSrcweir Sequence< Sequence< Reference< XDataSeries > > > aSeriesSeq(
206cdf0e10cSrcweir DiagramHelper::getDataSeriesGroups( xDiagram ));
207cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
208cdf0e10cSrcweir const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.getLength();
209cdf0e10cSrcweir
210cdf0e10cSrcweir // chart-type specific interpretation of existing data series
211cdf0e10cSrcweir Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter());
212cdf0e10cSrcweir chart2::InterpretedData aData;
213cdf0e10cSrcweir aData.Series = aSeriesSeq;
214cdf0e10cSrcweir aData.Categories = DiagramHelper::getCategoriesFromDiagram( xDiagram );
215cdf0e10cSrcweir
216cdf0e10cSrcweir if( xInterpreter->isDataCompatible( aData ) )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir aData = xInterpreter->reinterpretDataSeries( aData );
219cdf0e10cSrcweir }
220cdf0e10cSrcweir else
221cdf0e10cSrcweir {
222cdf0e10cSrcweir Reference< data::XDataSource > xSource( xInterpreter->mergeInterpretedData( aData ));
223cdf0e10cSrcweir // todo: get a "range-union" from the data provider by calling
224cdf0e10cSrcweir // OUString aRange = getRangeRepresentationByData( xSource );
225cdf0e10cSrcweir // xSource.set( getDataByRangeRepresentation( aRange, aParam ));
226cdf0e10cSrcweir // where aParam == ??
227cdf0e10cSrcweir Sequence< beans::PropertyValue > aParam;
228cdf0e10cSrcweir if( aData.Categories.is())
229cdf0e10cSrcweir {
230cdf0e10cSrcweir aParam.realloc( 1 );
231cdf0e10cSrcweir aParam[0] = beans::PropertyValue( C2U("HasCategories"), -1, uno::makeAny( true ),
232cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE );
233cdf0e10cSrcweir }
234cdf0e10cSrcweir aData = xInterpreter->interpretDataSource( xSource, aParam, aFlatSeriesSeq );
235cdf0e10cSrcweir }
236cdf0e10cSrcweir aSeriesSeq = aData.Series;
237cdf0e10cSrcweir
238cdf0e10cSrcweir sal_Int32 i, j, nIndex = 0;
239cdf0e10cSrcweir for( i=0; i<aSeriesSeq.getLength(); ++i )
240cdf0e10cSrcweir for( j=0; j<aSeriesSeq[i].getLength(); ++j, ++nIndex )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if( nIndex >= nFormerSeriesCount )
243cdf0e10cSrcweir lcl_applyDefaultStyle( aSeriesSeq[i][j], nIndex, xDiagram );
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
246cdf0e10cSrcweir // remove charttype groups from all coordinate systems
247cdf0e10cSrcweir Sequence< Reference< XChartType > > aOldChartTypesSeq(
248cdf0e10cSrcweir DiagramHelper::getChartTypesFromDiagram(xDiagram) );
249cdf0e10cSrcweir
250cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCoordSysCnt( xDiagram, uno::UNO_QUERY );
251cdf0e10cSrcweir OSL_ASSERT( xCoordSysCnt.is());
252cdf0e10cSrcweir if( xCoordSysCnt.is())
253cdf0e10cSrcweir {
254cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
255cdf0e10cSrcweir xCoordSysCnt->getCoordinateSystems());
256cdf0e10cSrcweir for( sal_Int32 nCooSysIdx = 0; nCooSysIdx < aCooSysSeq.getLength(); ++nCooSysIdx )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir Reference< XChartTypeContainer > xContainer( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY );
259cdf0e10cSrcweir if( xContainer.is() )
260cdf0e10cSrcweir xContainer->setChartTypes( Sequence< Reference< XChartType > >() );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
264cdf0e10cSrcweir FillDiagram( xDiagram, aSeriesSeq, aData.Categories, aOldChartTypesSeq, false );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir catch( uno::Exception & ex )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
changeDiagramData(const Reference<chart2::XDiagram> & xDiagram,const Reference<chart2::data::XDataSource> & xDataSource,const Sequence<beans::PropertyValue> & aArguments)272cdf0e10cSrcweir void SAL_CALL ChartTypeTemplate::changeDiagramData(
273cdf0e10cSrcweir const Reference< chart2::XDiagram >& xDiagram,
274cdf0e10cSrcweir const Reference< chart2::data::XDataSource >& xDataSource,
275cdf0e10cSrcweir const Sequence< beans::PropertyValue >& aArguments )
276cdf0e10cSrcweir throw (uno::RuntimeException)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir if( ! (xDiagram.is() &&
279cdf0e10cSrcweir xDataSource.is()) )
280cdf0e10cSrcweir return;
281cdf0e10cSrcweir
282cdf0e10cSrcweir try
283cdf0e10cSrcweir {
284cdf0e10cSrcweir // interpret new data and re-use existing series
285cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aFlatSeriesSeq(
286cdf0e10cSrcweir ::chart::ContainerHelper::ContainerToSequence( DiagramHelper::getDataSeriesFromDiagram( xDiagram )));
287cdf0e10cSrcweir const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.getLength();
288cdf0e10cSrcweir Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter());
289cdf0e10cSrcweir chart2::InterpretedData aData =
290cdf0e10cSrcweir xInterpreter->interpretDataSource( xDataSource, aArguments, aFlatSeriesSeq );
291cdf0e10cSrcweir
292cdf0e10cSrcweir // data series
293cdf0e10cSrcweir Sequence< Sequence< Reference< XDataSeries > > > aSeriesSeq( aData.Series );
294cdf0e10cSrcweir
295cdf0e10cSrcweir sal_Int32 i, j, nIndex = 0;
296cdf0e10cSrcweir for( i=0; i<aSeriesSeq.getLength(); ++i )
297cdf0e10cSrcweir for( j=0; j<aSeriesSeq[i].getLength(); ++j, ++nIndex )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir if( nIndex >= nFormerSeriesCount )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir lcl_applyDefaultStyle( aSeriesSeq[i][j], nIndex, xDiagram );
302cdf0e10cSrcweir applyStyle( aSeriesSeq[i][j], i, j, aSeriesSeq[i].getLength() );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir // categories
307cdf0e10cSrcweir DiagramHelper::setCategoriesToDiagram( aData.Categories, xDiagram, true, supportsCategories() );
308cdf0e10cSrcweir
309cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypes(
310cdf0e10cSrcweir DiagramHelper::getChartTypesFromDiagram( xDiagram ));
311cdf0e10cSrcweir sal_Int32 nMax = ::std::min( aChartTypes.getLength(), aSeriesSeq.getLength());
312cdf0e10cSrcweir for( i=0; i<nMax; ++i )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir Reference< XDataSeriesContainer > xDSCnt( aChartTypes[i], uno::UNO_QUERY_THROW );
315cdf0e10cSrcweir xDSCnt->setDataSeries( aSeriesSeq[i] );
316cdf0e10cSrcweir }
317cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
318cdf0e10cSrcweir OSL_TRACE( "ChartTypeTemplate::changeDiagramData: Showing Diagram structure" );
319cdf0e10cSrcweir OSL_TRACE( "---------------------------------------------------------------" );
320cdf0e10cSrcweir debug::ChartDebugTraceDiagram( xDiagram );
321cdf0e10cSrcweir #endif
322cdf0e10cSrcweir }
323cdf0e10cSrcweir catch( uno::Exception & ex )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
326cdf0e10cSrcweir }
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
matchesTemplate(const Reference<chart2::XDiagram> & xDiagram,sal_Bool)329cdf0e10cSrcweir sal_Bool SAL_CALL ChartTypeTemplate::matchesTemplate(
330cdf0e10cSrcweir const Reference< chart2::XDiagram >& xDiagram,
331cdf0e10cSrcweir sal_Bool /* bAdaptProperties */ )
332cdf0e10cSrcweir throw (uno::RuntimeException)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir sal_Bool bResult = sal_False;
335cdf0e10cSrcweir
336cdf0e10cSrcweir if( ! xDiagram.is())
337cdf0e10cSrcweir return bResult;
338cdf0e10cSrcweir
339cdf0e10cSrcweir try
340cdf0e10cSrcweir {
341cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysCnt(
342cdf0e10cSrcweir xDiagram, uno::UNO_QUERY_THROW );
343cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
344cdf0e10cSrcweir xCooSysCnt->getCoordinateSystems());
345cdf0e10cSrcweir
346cdf0e10cSrcweir // need to have at least one coordinate system
347cdf0e10cSrcweir bResult = (aCooSysSeq.getLength() > 0);
348cdf0e10cSrcweir if( bResult )
349cdf0e10cSrcweir {
350cdf0e10cSrcweir Sequence< Reference< XChartType > > aFormerlyUsedChartTypes;
351cdf0e10cSrcweir const OUString aChartTypeToMatch( getChartTypeForNewSeries(aFormerlyUsedChartTypes)->getChartType());
352cdf0e10cSrcweir const sal_Int32 nDimensionToMatch = getDimension();
353cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; bResult && (nCooSysIdx < aCooSysSeq.getLength()); ++nCooSysIdx )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir // match dimension
356cdf0e10cSrcweir bResult = bResult && (aCooSysSeq[nCooSysIdx]->getDimension() == nDimensionToMatch);
357cdf0e10cSrcweir
358cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW );
359cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
360cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; bResult && (nCTIdx < aChartTypeSeq.getLength()); ++nCTIdx )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir // match chart type
363cdf0e10cSrcweir bResult = bResult && aChartTypeSeq[nCTIdx]->getChartType().equals( aChartTypeToMatch );
364cdf0e10cSrcweir bool bFound=false;
365cdf0e10cSrcweir bool bAmbiguous=false;
366cdf0e10cSrcweir // match stacking mode
367cdf0e10cSrcweir bResult = bResult &&
368cdf0e10cSrcweir ( DiagramHelper::getStackModeFromChartType(
369cdf0e10cSrcweir aChartTypeSeq[nCTIdx], bFound, bAmbiguous,
370cdf0e10cSrcweir aCooSysSeq[nCooSysIdx] )
371cdf0e10cSrcweir == getStackMode( nCTIdx ) );
372cdf0e10cSrcweir }
373cdf0e10cSrcweir }
374cdf0e10cSrcweir }
375cdf0e10cSrcweir }
376cdf0e10cSrcweir catch( uno::Exception & ex )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir
381cdf0e10cSrcweir return bResult;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir
getDataInterpreter()384cdf0e10cSrcweir Reference< chart2::XDataInterpreter > SAL_CALL ChartTypeTemplate::getDataInterpreter()
385cdf0e10cSrcweir throw (uno::RuntimeException)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir if( ! m_xDataInterpreter.is())
388cdf0e10cSrcweir m_xDataInterpreter.set( new DataInterpreter( GetComponentContext() ) );
389cdf0e10cSrcweir
390cdf0e10cSrcweir return m_xDataInterpreter;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
applyStyle(const Reference<chart2::XDataSeries> & xSeries,::sal_Int32 nChartTypeIndex,::sal_Int32,::sal_Int32)393cdf0e10cSrcweir void SAL_CALL ChartTypeTemplate::applyStyle(
394cdf0e10cSrcweir const Reference< chart2::XDataSeries >& xSeries,
395cdf0e10cSrcweir ::sal_Int32 nChartTypeIndex,
396cdf0e10cSrcweir ::sal_Int32 /* nSeriesIndex */,
397cdf0e10cSrcweir ::sal_Int32 /* nSeriesCount */ )
398cdf0e10cSrcweir throw (uno::RuntimeException)
399cdf0e10cSrcweir {
400cdf0e10cSrcweir // sset stacking mode
401cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
402cdf0e10cSrcweir if( xSeriesProp.is())
403cdf0e10cSrcweir {
404cdf0e10cSrcweir try
405cdf0e10cSrcweir {
406cdf0e10cSrcweir StackMode eStackMode = getStackMode( nChartTypeIndex );
407cdf0e10cSrcweir const uno::Any aPropValue = uno::makeAny(
408cdf0e10cSrcweir ( (eStackMode == StackMode_Y_STACKED) ||
409cdf0e10cSrcweir (eStackMode == StackMode_Y_STACKED_PERCENT) )
410cdf0e10cSrcweir ? chart2::StackingDirection_Y_STACKING
411cdf0e10cSrcweir : (eStackMode == StackMode_Z_STACKED )
412cdf0e10cSrcweir ? chart2::StackingDirection_Z_STACKING
413cdf0e10cSrcweir : chart2::StackingDirection_NO_STACKING );
414cdf0e10cSrcweir xSeriesProp->setPropertyValue( C2U("StackingDirection"), aPropValue );
415cdf0e10cSrcweir
416cdf0e10cSrcweir //ensure valid label placement
417cdf0e10cSrcweir {
418cdf0e10cSrcweir uno::Sequence < sal_Int32 > aAvailablePlacements( ChartTypeHelper::getSupportedLabelPlacements(
419cdf0e10cSrcweir getChartTypeForIndex( nChartTypeIndex ), getDimension(), isSwapXAndY(), xSeries ) );
420cdf0e10cSrcweir lcl_ensureCorrectLabelPlacement( xSeriesProp, aAvailablePlacements );
421cdf0e10cSrcweir
422cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
423cdf0e10cSrcweir if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList )
424cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
425cdf0e10cSrcweir lcl_ensureCorrectLabelPlacement( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), aAvailablePlacements );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir }
428cdf0e10cSrcweir catch( const uno::Exception & ex )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
431cdf0e10cSrcweir }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
applyStyles(const Reference<chart2::XDiagram> & xDiagram)435cdf0e10cSrcweir void SAL_CALL ChartTypeTemplate::applyStyles( const Reference< chart2::XDiagram >& xDiagram )
436cdf0e10cSrcweir throw (uno::RuntimeException)
437cdf0e10cSrcweir {
438cdf0e10cSrcweir // apply chart-type specific styles, like "symbols on" for example
439cdf0e10cSrcweir Sequence< Sequence< Reference< XDataSeries > > > aNewSeriesSeq(
440cdf0e10cSrcweir DiagramHelper::getDataSeriesGroups( xDiagram ));
441cdf0e10cSrcweir for( sal_Int32 i=0; i<aNewSeriesSeq.getLength(); ++i )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir const sal_Int32 nNumSeries = aNewSeriesSeq[i].getLength();
444cdf0e10cSrcweir for( sal_Int32 j=0; j<nNumSeries; ++j )
445cdf0e10cSrcweir applyStyle( aNewSeriesSeq[i][j], i, j, nNumSeries );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir
448cdf0e10cSrcweir //ensure valid empty cell handling (for first chart type...)
449cdf0e10cSrcweir lcl_ensureCorrectMissingValueTreatment( xDiagram, getChartTypeForIndex( 0 ) );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir
resetStyles(const Reference<chart2::XDiagram> & xDiagram)452cdf0e10cSrcweir void SAL_CALL ChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
453cdf0e10cSrcweir throw (uno::RuntimeException)
454cdf0e10cSrcweir {
455cdf0e10cSrcweir // reset number format if we had percent stacking on
456cdf0e10cSrcweir sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT);
457cdf0e10cSrcweir if( bPercent )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir Sequence< Reference< chart2::XAxis > > aAxisSeq( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
460cdf0e10cSrcweir for( sal_Int32 i=0; i<aAxisSeq.getLength(); ++i )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir if( 1== AxisHelper::getDimensionIndexOfAxis( aAxisSeq[i], xDiagram ) )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir Reference< beans::XPropertySet > xAxisProp( aAxisSeq[i], uno::UNO_QUERY );
465cdf0e10cSrcweir if( xAxisProp.is())
466cdf0e10cSrcweir {
467cdf0e10cSrcweir // set number format to source format
468cdf0e10cSrcweir uno::Any aValue( xAxisProp->getPropertyValue(C2U("NumberFormat")));
469cdf0e10cSrcweir if( aValue.hasValue())
470cdf0e10cSrcweir xAxisProp->setPropertyValue(C2U("NumberFormat"), uno::Any());
471cdf0e10cSrcweir }
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir }
475cdf0e10cSrcweir
476cdf0e10cSrcweir //reset label placement if default
477cdf0e10cSrcweir {
478cdf0e10cSrcweir uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
479cdf0e10cSrcweir if( xCooSysContainer.is() )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
482cdf0e10cSrcweir for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
485cdf0e10cSrcweir
486cdf0e10cSrcweir //iterate through all chart types in the current coordinate system
487cdf0e10cSrcweir uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
488cdf0e10cSrcweir OSL_ASSERT( xChartTypeContainer.is());
489cdf0e10cSrcweir if( !xChartTypeContainer.is() )
490cdf0e10cSrcweir continue;
491cdf0e10cSrcweir uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
492cdf0e10cSrcweir for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
495cdf0e10cSrcweir
496cdf0e10cSrcweir //iterate through all series in this chart type
497cdf0e10cSrcweir uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
498cdf0e10cSrcweir OSL_ASSERT( xDataSeriesContainer.is());
499cdf0e10cSrcweir if( !xDataSeriesContainer.is() )
500cdf0e10cSrcweir continue;
501cdf0e10cSrcweir
502cdf0e10cSrcweir uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
503cdf0e10cSrcweir for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir Reference< XDataSeries > xSeries(aSeriesList[nS]);
506cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
507cdf0e10cSrcweir if(!xSeries.is() || !xSeriesProp.is() )
508cdf0e10cSrcweir continue;
509cdf0e10cSrcweir
510cdf0e10cSrcweir uno::Sequence < sal_Int32 > aAvailablePlacements( ChartTypeHelper::getSupportedLabelPlacements(
511cdf0e10cSrcweir xChartType, getDimension(), isSwapXAndY(), xSeries ) );
512cdf0e10cSrcweir if(!aAvailablePlacements.getLength())
513cdf0e10cSrcweir continue;
514cdf0e10cSrcweir
515cdf0e10cSrcweir sal_Int32 nDefaultPlacement = aAvailablePlacements[0];
516cdf0e10cSrcweir
517cdf0e10cSrcweir lcl_resetLabelPlacementIfDefault( xSeriesProp, nDefaultPlacement );
518cdf0e10cSrcweir
519cdf0e10cSrcweir uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
520cdf0e10cSrcweir if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList )
521cdf0e10cSrcweir for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
522cdf0e10cSrcweir lcl_resetLabelPlacementIfDefault( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), nDefaultPlacement );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir }
525cdf0e10cSrcweir }
526cdf0e10cSrcweir }
527cdf0e10cSrcweir }
528cdf0e10cSrcweir
529cdf0e10cSrcweir return;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
532cdf0e10cSrcweir // ____ XServiceName ____
getServiceName()533cdf0e10cSrcweir ::rtl::OUString SAL_CALL ChartTypeTemplate::getServiceName()
534cdf0e10cSrcweir throw (uno::RuntimeException)
535cdf0e10cSrcweir {
536cdf0e10cSrcweir return m_aServiceName;
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
539cdf0e10cSrcweir // ________________________________________
540cdf0e10cSrcweir
getDimension() const541cdf0e10cSrcweir sal_Int32 ChartTypeTemplate::getDimension() const
542cdf0e10cSrcweir {
543cdf0e10cSrcweir return 2;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
getStackMode(sal_Int32) const546cdf0e10cSrcweir StackMode ChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
547cdf0e10cSrcweir {
548cdf0e10cSrcweir return StackMode_NONE;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
isSwapXAndY() const551cdf0e10cSrcweir bool ChartTypeTemplate::isSwapXAndY() const
552cdf0e10cSrcweir {
553cdf0e10cSrcweir return false;
554cdf0e10cSrcweir }
555cdf0e10cSrcweir
556cdf0e10cSrcweir // ________________________________________
557cdf0e10cSrcweir
createCoordinateSystems(const Reference<chart2::XCoordinateSystemContainer> & xOutCooSysCnt)558cdf0e10cSrcweir void ChartTypeTemplate::createCoordinateSystems(
559cdf0e10cSrcweir const Reference< chart2::XCoordinateSystemContainer > & xOutCooSysCnt )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir if( ! xOutCooSysCnt.is())
562cdf0e10cSrcweir return;
563cdf0e10cSrcweir Sequence< Reference< XChartType > > aFormerlyUsedChartTypes;
564cdf0e10cSrcweir Reference< XChartType > xChartType( getChartTypeForNewSeries(aFormerlyUsedChartTypes));
565cdf0e10cSrcweir if( ! xChartType.is())
566cdf0e10cSrcweir return;
567cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys( xChartType->createCoordinateSystem( getDimension()));
568cdf0e10cSrcweir if( ! xCooSys.is())
569cdf0e10cSrcweir {
570cdf0e10cSrcweir // chart type wants no coordinate systems
571cdf0e10cSrcweir xOutCooSysCnt->setCoordinateSystems( Sequence< Reference< XCoordinateSystem > >());
572cdf0e10cSrcweir return;
573cdf0e10cSrcweir }
574cdf0e10cSrcweir // #i69680# make grid of first y-axis visible (was in the CooSys CTOR before)
575cdf0e10cSrcweir if( xCooSys->getDimension() >= 2 )
576cdf0e10cSrcweir {
577cdf0e10cSrcweir Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1, 0 ));
578cdf0e10cSrcweir if( xAxis.is())
579cdf0e10cSrcweir AxisHelper::makeGridVisible( xAxis->getGridProperties() );
580cdf0e10cSrcweir }
581cdf0e10cSrcweir
582cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCoordinateSystems(
583cdf0e10cSrcweir xOutCooSysCnt->getCoordinateSystems());
584cdf0e10cSrcweir
585cdf0e10cSrcweir if( aCoordinateSystems.getLength())
586cdf0e10cSrcweir {
587cdf0e10cSrcweir bool bOk = true;
588cdf0e10cSrcweir for( sal_Int32 i=0; bOk && i<aCoordinateSystems.getLength(); ++i )
589cdf0e10cSrcweir bOk = bOk && ( xCooSys->getCoordinateSystemType().equals( aCoordinateSystems[i]->getCoordinateSystemType()) &&
590cdf0e10cSrcweir (xCooSys->getDimension() == aCoordinateSystems[i]->getDimension()) );
591cdf0e10cSrcweir // coordinate systems are ok
592cdf0e10cSrcweir if( bOk )
593cdf0e10cSrcweir return;
594cdf0e10cSrcweir // there are coordinate systems but they do not fit. So overwrite them.
595cdf0e10cSrcweir }
596cdf0e10cSrcweir
597cdf0e10cSrcweir //copy as much info from former coordinate system as possible:
598cdf0e10cSrcweir if( aCoordinateSystems.getLength() )
599cdf0e10cSrcweir {
600cdf0e10cSrcweir Reference< XCoordinateSystem > xOldCooSys( aCoordinateSystems[0] );
601cdf0e10cSrcweir sal_Int32 nMaxDimensionCount = std::min( xCooSys->getDimension(), xOldCooSys->getDimension() );
602cdf0e10cSrcweir
603cdf0e10cSrcweir for(sal_Int32 nDimensionIndex=0; nDimensionIndex<nMaxDimensionCount; nDimensionIndex++)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir const sal_Int32 nMaximumAxisIndex = xOldCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
606cdf0e10cSrcweir for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
607cdf0e10cSrcweir {
608cdf0e10cSrcweir uno::Reference< XAxis > xAxis( xOldCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
609cdf0e10cSrcweir if( xAxis.is())
610cdf0e10cSrcweir {
611cdf0e10cSrcweir xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
612cdf0e10cSrcweir }
613cdf0e10cSrcweir }
614cdf0e10cSrcweir }
615cdf0e10cSrcweir }
616cdf0e10cSrcweir
617cdf0e10cSrcweir // set new coordinate systems
618cdf0e10cSrcweir aCoordinateSystems.realloc( 1 );
619cdf0e10cSrcweir aCoordinateSystems[0] = xCooSys;
620cdf0e10cSrcweir
621cdf0e10cSrcweir xOutCooSysCnt->setCoordinateSystems( aCoordinateSystems );
622cdf0e10cSrcweir }
623cdf0e10cSrcweir
adaptScales(const Sequence<Reference<chart2::XCoordinateSystem>> & aCooSysSeq,const Reference<data::XLabeledDataSequence> & xCategories)624cdf0e10cSrcweir void ChartTypeTemplate::adaptScales(
625cdf0e10cSrcweir const Sequence< Reference< chart2::XCoordinateSystem > > & aCooSysSeq,
626cdf0e10cSrcweir const Reference< data::XLabeledDataSequence > & xCategories //@todo: in future there may be more than one sequence of categories (e.g. charttype with categories at x and y axis )
627cdf0e10cSrcweir )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir bool bSupportsCategories( supportsCategories() );
630cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir try
633cdf0e10cSrcweir {
634cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIdx] );
635cdf0e10cSrcweir if( !xCooSys.is() )
636cdf0e10cSrcweir continue;
637cdf0e10cSrcweir
638cdf0e10cSrcweir // attach categories to first axis
639cdf0e10cSrcweir sal_Int32 nDim( xCooSys->getDimension());
640cdf0e10cSrcweir if( nDim > 0 )
641cdf0e10cSrcweir {
642cdf0e10cSrcweir const sal_Int32 nDimensionX = 0;
643cdf0e10cSrcweir const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionX);
644cdf0e10cSrcweir for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
645cdf0e10cSrcweir {
646cdf0e10cSrcweir Reference< XAxis > xAxis( xCooSys->getAxisByDimension(nDimensionX,nI) );
647cdf0e10cSrcweir if( xAxis.is())
648cdf0e10cSrcweir {
649cdf0e10cSrcweir ScaleData aData( xAxis->getScaleData() );
650cdf0e10cSrcweir aData.Categories = xCategories;
651cdf0e10cSrcweir if(bSupportsCategories)
652cdf0e10cSrcweir {
653cdf0e10cSrcweir
654cdf0e10cSrcweir Reference< XChartType > xChartType( getChartTypeForNewSeries(Sequence< Reference< XChartType > >() ));
655cdf0e10cSrcweir bool bSupportsDates = ::chart::ChartTypeHelper::isSupportingDateAxis( xChartType, 2, nDimensionX );
656cdf0e10cSrcweir if( aData.AxisType != AxisType::CATEGORY && ( aData.AxisType != AxisType::DATE || !bSupportsDates) )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir aData.AxisType = AxisType::CATEGORY;
659cdf0e10cSrcweir aData.AutoDateAxis = true;
660cdf0e10cSrcweir AxisHelper::removeExplicitScaling( aData );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir }
663cdf0e10cSrcweir else
664cdf0e10cSrcweir aData.AxisType = AxisType::REALNUMBER;
665cdf0e10cSrcweir
666cdf0e10cSrcweir xAxis->setScaleData( aData );
667cdf0e10cSrcweir }
668cdf0e10cSrcweir }
669cdf0e10cSrcweir }
670cdf0e10cSrcweir // set percent stacking mode at second axis
671cdf0e10cSrcweir if( nDim > 1 )
672cdf0e10cSrcweir {
673cdf0e10cSrcweir const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1);
674cdf0e10cSrcweir for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1,nI ));
677cdf0e10cSrcweir if( xAxis.is())
678cdf0e10cSrcweir {
679cdf0e10cSrcweir sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT);
680cdf0e10cSrcweir chart2::ScaleData aScaleData = xAxis->getScaleData();
681cdf0e10cSrcweir
682cdf0e10cSrcweir if( bPercent != (aScaleData.AxisType==AxisType::PERCENT) )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir if( bPercent )
685cdf0e10cSrcweir aScaleData.AxisType = AxisType::PERCENT;
686cdf0e10cSrcweir else
687cdf0e10cSrcweir aScaleData.AxisType = AxisType::REALNUMBER;
688cdf0e10cSrcweir xAxis->setScaleData( aScaleData );
689cdf0e10cSrcweir }
690cdf0e10cSrcweir }
691cdf0e10cSrcweir }
692cdf0e10cSrcweir }
693cdf0e10cSrcweir }
694cdf0e10cSrcweir catch( const uno::Exception & ex )
695cdf0e10cSrcweir {
696cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
697cdf0e10cSrcweir }
698cdf0e10cSrcweir }
699cdf0e10cSrcweir }
700cdf0e10cSrcweir
adaptDiagram(const Reference<XDiagram> &)701cdf0e10cSrcweir void ChartTypeTemplate::adaptDiagram( const Reference< XDiagram > & /* xDiagram */ )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir return;
704cdf0e10cSrcweir }
705cdf0e10cSrcweir
createAxes(const Sequence<Reference<XCoordinateSystem>> & rCoordSys)706cdf0e10cSrcweir void ChartTypeTemplate::createAxes(
707cdf0e10cSrcweir const Sequence< Reference< XCoordinateSystem > > & rCoordSys )
708cdf0e10cSrcweir {
709cdf0e10cSrcweir //create missing axes
710cdf0e10cSrcweir if( rCoordSys.getLength() > 0 )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir sal_Int32 nCooSysIdx = 0;
713cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys( rCoordSys[nCooSysIdx] );
714cdf0e10cSrcweir if(!xCooSys.is())
715cdf0e10cSrcweir return;
716cdf0e10cSrcweir
717cdf0e10cSrcweir //create main axis in first coordinate system
718cdf0e10cSrcweir sal_Int32 nDimCount = xCooSys->getDimension();
719cdf0e10cSrcweir sal_Int32 nDim=0;
720cdf0e10cSrcweir for( nDim=0; nDim<nDimCount; ++nDim )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir sal_Int32 nAxisCount = getAxisCountByDimension( nDim );
723cdf0e10cSrcweir if( nDim == 1 &&
724cdf0e10cSrcweir nAxisCount < 2 && AxisHelper::isSecondaryYAxisNeeded( xCooSys ))
725cdf0e10cSrcweir nAxisCount = 2;
726cdf0e10cSrcweir for( sal_Int32 nAxisIndex = 0; nAxisIndex < nAxisCount; ++nAxisIndex )
727cdf0e10cSrcweir {
728cdf0e10cSrcweir Reference< XAxis > xAxis = AxisHelper::getAxis( nDim, nAxisIndex, xCooSys );
729cdf0e10cSrcweir if( !xAxis.is())
730cdf0e10cSrcweir {
731cdf0e10cSrcweir // create and add axis
732cdf0e10cSrcweir xAxis.set( AxisHelper::createAxis(
733cdf0e10cSrcweir nDim, nAxisIndex, xCooSys, GetComponentContext() ));
734cdf0e10cSrcweir }
735cdf0e10cSrcweir }
736cdf0e10cSrcweir }
737cdf0e10cSrcweir }
738cdf0e10cSrcweir }
739cdf0e10cSrcweir
adaptAxes(const Sequence<Reference<XCoordinateSystem>> & rCoordSys)740cdf0e10cSrcweir void ChartTypeTemplate::adaptAxes(
741cdf0e10cSrcweir const Sequence< Reference< XCoordinateSystem > > & rCoordSys )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir //adapt properties of exsisting axes and remove superfluous axes
744cdf0e10cSrcweir
745cdf0e10cSrcweir if( rCoordSys.getLength() > 0 )
746cdf0e10cSrcweir {
747cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx < rCoordSys.getLength(); ++nCooSysIdx )
748cdf0e10cSrcweir {
749cdf0e10cSrcweir Reference< XCoordinateSystem > xCooSys( rCoordSys[nCooSysIdx] );
750cdf0e10cSrcweir if( !xCooSys.is() )
751cdf0e10cSrcweir continue;
752cdf0e10cSrcweir sal_Int32 nDimCount = xCooSys->getDimension();
753cdf0e10cSrcweir for( sal_Int32 nDim=0; nDim<nDimCount; ++nDim )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension( nDim );
756cdf0e10cSrcweir for( sal_Int32 nAxisIndex=0; nAxisIndex<=nMaxAxisIndex; nAxisIndex++ )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir Reference< XAxis > xAxis( AxisHelper::getAxis( nDim, nAxisIndex, xCooSys ) );
759cdf0e10cSrcweir if( !xAxis.is() )
760cdf0e10cSrcweir continue;
761cdf0e10cSrcweir
762cdf0e10cSrcweir if( nAxisIndex == MAIN_AXIS_INDEX || nAxisIndex == SECONDARY_AXIS_INDEX )
763cdf0e10cSrcweir {
764cdf0e10cSrcweir // adapt scales
765cdf0e10cSrcweir sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT);
766cdf0e10cSrcweir if( bPercent && nDim == 1 )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY );
769cdf0e10cSrcweir if( xAxisProp.is())
770cdf0e10cSrcweir {
771cdf0e10cSrcweir // set number format to source format
772cdf0e10cSrcweir uno::Any aValue( xAxisProp->getPropertyValue(C2U("NumberFormat")));
773cdf0e10cSrcweir if( aValue.hasValue())
774cdf0e10cSrcweir xAxisProp->setPropertyValue(C2U("NumberFormat"), uno::Any());
775cdf0e10cSrcweir }
776cdf0e10cSrcweir }
777cdf0e10cSrcweir }
778cdf0e10cSrcweir }
779cdf0e10cSrcweir }
780cdf0e10cSrcweir }
781cdf0e10cSrcweir }
782cdf0e10cSrcweir }
783cdf0e10cSrcweir
getAxisCountByDimension(sal_Int32 nDimension)784cdf0e10cSrcweir sal_Int32 ChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir return (nDimension < getDimension()) ? 1 : 0;
787cdf0e10cSrcweir }
788cdf0e10cSrcweir
FillDiagram(const Reference<XDiagram> & xDiagram,const Sequence<Sequence<Reference<XDataSeries>>> & aSeriesSeq,Reference<data::XLabeledDataSequence> xCategories,const Sequence<Reference<XChartType>> & aOldChartTypesSeq,bool)789cdf0e10cSrcweir void ChartTypeTemplate::FillDiagram(
790cdf0e10cSrcweir const Reference< XDiagram >& xDiagram,
791cdf0e10cSrcweir const Sequence< Sequence< Reference< XDataSeries > > >& aSeriesSeq,
792cdf0e10cSrcweir Reference< data::XLabeledDataSequence > xCategories,
793cdf0e10cSrcweir const Sequence< Reference< XChartType > >& aOldChartTypesSeq,
794cdf0e10cSrcweir bool /* bCreate */ )
795cdf0e10cSrcweir {
796cdf0e10cSrcweir adaptDiagram( xDiagram );
797cdf0e10cSrcweir
798cdf0e10cSrcweir try
799cdf0e10cSrcweir {
800cdf0e10cSrcweir // create coordinate systems and scales
801cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCoordSysCnt( xDiagram, uno::UNO_QUERY_THROW );
802cdf0e10cSrcweir createCoordinateSystems( xCoordSysCnt );
803cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCoordinateSystems( xCoordSysCnt->getCoordinateSystems());
804cdf0e10cSrcweir createAxes( aCoordinateSystems );
805cdf0e10cSrcweir adaptAxes( aCoordinateSystems );
806cdf0e10cSrcweir adaptScales( aCoordinateSystems, xCategories );
807cdf0e10cSrcweir
808cdf0e10cSrcweir // chart types
809cdf0e10cSrcweir createChartTypes( aSeriesSeq, aCoordinateSystems, aOldChartTypesSeq );
810cdf0e10cSrcweir applyStyles( xDiagram );
811cdf0e10cSrcweir }
812cdf0e10cSrcweir catch( const uno::Exception & ex )
813cdf0e10cSrcweir {
814cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
815cdf0e10cSrcweir }
816cdf0e10cSrcweir
817cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
818cdf0e10cSrcweir OSL_TRACE( "ChartTypeTemplate::FillDiagram: Showing Diagram structure" );
819cdf0e10cSrcweir OSL_TRACE( "---------------------------------------------------------" );
820cdf0e10cSrcweir debug::ChartDebugTraceDiagram( xDiagram );
821cdf0e10cSrcweir #endif
822cdf0e10cSrcweir }
823cdf0e10cSrcweir
createChartTypes(const Sequence<Sequence<Reference<XDataSeries>>> & aSeriesSeq,const Sequence<Reference<XCoordinateSystem>> & rCoordSys,const Sequence<Reference<XChartType>> & aOldChartTypesSeq)824cdf0e10cSrcweir void ChartTypeTemplate::createChartTypes(
825cdf0e10cSrcweir const Sequence< Sequence< Reference< XDataSeries > > > & aSeriesSeq,
826cdf0e10cSrcweir const Sequence< Reference< XCoordinateSystem > > & rCoordSys,
827cdf0e10cSrcweir const Sequence< Reference< XChartType > >& aOldChartTypesSeq )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir if( rCoordSys.getLength() == 0 ||
830cdf0e10cSrcweir ! rCoordSys[0].is() )
831cdf0e10cSrcweir return;
832cdf0e10cSrcweir
833cdf0e10cSrcweir try
834cdf0e10cSrcweir {
835cdf0e10cSrcweir sal_Int32 nCooSysIdx=0;
836cdf0e10cSrcweir Reference< XChartType > xCT;
837cdf0e10cSrcweir if( aSeriesSeq.getLength() == 0 )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir // we need a new chart type
840cdf0e10cSrcweir xCT.set( getChartTypeForNewSeries( aOldChartTypesSeq ));
841cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( rCoordSys[nCooSysIdx], uno::UNO_QUERY_THROW );
842cdf0e10cSrcweir Sequence< Reference< XChartType > > aCTSeq( xCTCnt->getChartTypes());
843cdf0e10cSrcweir aCTSeq.realloc( 1 );
844cdf0e10cSrcweir aCTSeq[0] = xCT;
845cdf0e10cSrcweir xCTCnt->setChartTypes( aCTSeq );
846cdf0e10cSrcweir }
847cdf0e10cSrcweir else
848cdf0e10cSrcweir {
849cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeriesSeq.getLength(); ++nSeriesIdx )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir if( nSeriesIdx == nCooSysIdx )
852cdf0e10cSrcweir {
853cdf0e10cSrcweir // we need a new chart type
854cdf0e10cSrcweir xCT.set( getChartTypeForNewSeries( aOldChartTypesSeq ));
855cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( rCoordSys[nCooSysIdx], uno::UNO_QUERY_THROW );
856cdf0e10cSrcweir Sequence< Reference< XChartType > > aCTSeq( xCTCnt->getChartTypes());
857cdf0e10cSrcweir if( aCTSeq.getLength())
858cdf0e10cSrcweir {
859cdf0e10cSrcweir aCTSeq[0] = xCT;
860cdf0e10cSrcweir xCTCnt->setChartTypes( aCTSeq );
861cdf0e10cSrcweir }
862cdf0e10cSrcweir else
863cdf0e10cSrcweir xCTCnt->addChartType( xCT );
864cdf0e10cSrcweir
865cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
866cdf0e10cSrcweir xDSCnt->setDataSeries( aSeriesSeq[nSeriesIdx] );
867cdf0e10cSrcweir }
868cdf0e10cSrcweir else
869cdf0e10cSrcweir {
870cdf0e10cSrcweir // reuse existing chart type
871cdf0e10cSrcweir OSL_ASSERT( xCT.is());
872cdf0e10cSrcweir Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
873cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aNewSeriesSeq( xDSCnt->getDataSeries());
874cdf0e10cSrcweir sal_Int32 nNewStartIndex = aNewSeriesSeq.getLength();
875cdf0e10cSrcweir aNewSeriesSeq.realloc( nNewStartIndex + aSeriesSeq[nSeriesIdx].getLength() );
876cdf0e10cSrcweir ::std::copy( aSeriesSeq[nSeriesIdx].getConstArray(),
877cdf0e10cSrcweir aSeriesSeq[nSeriesIdx].getConstArray() + aSeriesSeq[nSeriesIdx].getLength(),
878cdf0e10cSrcweir aNewSeriesSeq.getArray() + nNewStartIndex );
879cdf0e10cSrcweir xDSCnt->setDataSeries( aNewSeriesSeq );
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir // spread the series over the available coordinate systems
883cdf0e10cSrcweir if( rCoordSys.getLength() > (nCooSysIdx + 1) )
884cdf0e10cSrcweir ++nCooSysIdx;
885cdf0e10cSrcweir }
886cdf0e10cSrcweir }
887cdf0e10cSrcweir }
888cdf0e10cSrcweir catch( uno::Exception & ex )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
891cdf0e10cSrcweir }
892cdf0e10cSrcweir }
893cdf0e10cSrcweir
copyPropertiesFromOldToNewCoordianteSystem(const Sequence<Reference<XChartType>> & rOldChartTypesSeq,const Reference<XChartType> & xNewChartType)894cdf0e10cSrcweir void ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem(
895cdf0e10cSrcweir const Sequence< Reference< XChartType > > & rOldChartTypesSeq,
896cdf0e10cSrcweir const Reference< XChartType > & xNewChartType )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir Reference< beans::XPropertySet > xDestination( xNewChartType, uno::UNO_QUERY );
899cdf0e10cSrcweir if( !xDestination.is() )
900cdf0e10cSrcweir return;
901cdf0e10cSrcweir
902cdf0e10cSrcweir OUString aNewChartType( xNewChartType->getChartType() );
903cdf0e10cSrcweir
904cdf0e10cSrcweir Reference< beans::XPropertySet > xSource;
905cdf0e10cSrcweir sal_Int32 nN=0;
906cdf0e10cSrcweir for( nN=0; nN<rOldChartTypesSeq.getLength();++nN)
907cdf0e10cSrcweir {
908cdf0e10cSrcweir Reference< XChartType > xOldType( rOldChartTypesSeq[nN] );
909cdf0e10cSrcweir if( xOldType.is() && xOldType->getChartType().equals( aNewChartType ) )
910cdf0e10cSrcweir {
911cdf0e10cSrcweir xSource.set( Reference< beans::XPropertySet >(xOldType, uno::UNO_QUERY ) );
912cdf0e10cSrcweir if( xSource.is() )
913cdf0e10cSrcweir break;
914cdf0e10cSrcweir }
915cdf0e10cSrcweir }
916cdf0e10cSrcweir if( xSource.is() )
917cdf0e10cSrcweir comphelper::copyProperties( xSource, xDestination );
918cdf0e10cSrcweir }
919cdf0e10cSrcweir
920cdf0e10cSrcweir // ________
921cdf0e10cSrcweir
getSupportedServiceNames_Static()922cdf0e10cSrcweir Sequence< OUString > ChartTypeTemplate::getSupportedServiceNames_Static()
923cdf0e10cSrcweir {
924cdf0e10cSrcweir Sequence< OUString > aServices( 3 );
925cdf0e10cSrcweir aServices[ 0 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
926cdf0e10cSrcweir aServices[ 1 ] = C2U( "com.sun.star.layout.LayoutElement" );
927cdf0e10cSrcweir aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
928cdf0e10cSrcweir return aServices;
929cdf0e10cSrcweir }
930cdf0e10cSrcweir
GetComponentContext() const931cdf0e10cSrcweir Reference< uno::XComponentContext > ChartTypeTemplate::GetComponentContext() const
932cdf0e10cSrcweir {
933cdf0e10cSrcweir return m_xContext;
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
936cdf0e10cSrcweir // ================================================================================
937cdf0e10cSrcweir
938cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
939cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( ChartTypeTemplate,
940cdf0e10cSrcweir C2U( "com.sun.star.comp.chart.ChartTypeTemplate" ));
941cdf0e10cSrcweir } // namespace chart
942