nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / view / axes / VCartesianCoordinateSystem.cxx
blobe7fe42a87124b29c16cf1d9c974c1030b0e99e8f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "VCartesianCoordinateSystem.hxx"
21 #include "VCartesianGrid.hxx"
22 #include "VCartesianAxis.hxx"
23 #include <AxisIndexDefines.hxx>
24 #include <AxisHelper.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <ChartModel.hxx>
27 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
28 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
29 #include <com/sun/star/chart2/AxisType.hpp>
31 namespace chart
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::chart2;
35 using ::com::sun::star::uno::Reference;
37 namespace {
39 class TextualDataProvider : public ::cppu::WeakImplHelper<
40 css::chart2::data::XTextualDataSequence
43 public:
44 explicit TextualDataProvider( const uno::Sequence< OUString >& rTextSequence )
45 : m_aTextSequence( rTextSequence )
49 //XTextualDataSequence
50 virtual uno::Sequence< OUString > SAL_CALL getTextualData() override
52 return m_aTextSequence;
55 private: //member
56 uno::Sequence< OUString > m_aTextSequence;
61 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
62 : VCoordinateSystem(xCooSys)
66 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
70 void VCartesianCoordinateSystem::createGridShapes()
72 if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
73 return;
75 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
76 bool bSwapXAndY = getPropertySwapXAndYAxis();
78 for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
80 sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
81 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
82 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
83 continue;
85 VCartesianGrid aGrid(nDimensionIndex,nDimensionCount, getGridListFromAxis( xAxis ));
86 aGrid.setExplicitScaleAndIncrement( getExplicitScale(nDimensionIndex,nAxisIndex)
87 , getExplicitIncrement(nDimensionIndex,nAxisIndex) );
88 aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
90 aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
91 , createCIDForGrid( nDimensionIndex,nAxisIndex ) );
92 if(nDimensionCount==2)
93 aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
94 aGrid.setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
95 aGrid.createShapes();
99 void VCartesianCoordinateSystem::createVAxisList(
100 const uno::Reference<chart2::XChartDocument> & xChartDoc
101 , const awt::Size& rFontReferenceSize
102 , const awt::Rectangle& rMaximumSpaceForLabels
103 , bool bLimitSpaceForLabels
106 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
107 // a leak from VCartesianAxis due to cyclic reference
108 uno::Reference<util::XNumberFormatsSupplier> const xNumberFormatsSupplier(
109 dynamic_cast<ChartModel&>(*xChartDoc).getNumberFormatsSupplier());
111 m_aAxisMap.clear();
113 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
114 bool bSwapXAndY = getPropertySwapXAndYAxis();
116 if(nDimensionCount<=0)
117 return;
119 sal_Int32 nDimensionIndex = 0;
121 // dimension index -> x, y or z axis.
122 for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
124 // axis index -> primary or secondary axis.
125 sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
126 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
128 Reference< XAxis > xAxis = getAxisByDimension(nDimensionIndex,nAxisIndex);
129 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
130 continue;
132 AxisProperties aAxisProperties(xAxis,getExplicitCategoriesProvider());
133 aAxisProperties.m_nDimensionIndex = nDimensionIndex;
134 aAxisProperties.m_bSwapXAndY = bSwapXAndY;
135 aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
136 aAxisProperties.m_bLimitSpaceForLabels = bLimitSpaceForLabels;
137 Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
138 if( xCrossingMainAxis.is() )
140 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
141 aAxisProperties.m_bCrossingAxisHasReverseDirection = (aCrossingScale.Orientation==AxisOrientation_REVERSE);
143 if( aCrossingScale.AxisType == AxisType::CATEGORY )
144 aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
147 if( nDimensionIndex == 2 )
149 aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
151 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
152 Reference< XAxis > xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel ) );
153 aAxisProperties.initAxisPositioning( Reference< beans::XPropertySet >( xSisterAxis, uno::UNO_QUERY) );
155 aAxisProperties.init(true);
156 if(aAxisProperties.m_bDisplayLabels)
157 aAxisProperties.m_nNumberFormatKey = getNumberFormatKeyForAxis(xAxis, xChartDoc);
159 auto apVAxis = std::make_shared<VCartesianAxis>(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount);
160 tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
161 m_aAxisMap[aFullAxisIndex] = apVAxis;
162 apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
164 apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
169 void VCartesianCoordinateSystem::initVAxisInList()
171 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
172 return;
174 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
175 bool bSwapXAndY = getPropertySwapXAndYAxis();
177 for (auto const& elem : m_aAxisMap)
179 VAxisBase* pVAxis = elem.second.get();
180 if( pVAxis )
182 sal_Int32 nDimensionIndex = elem.first.first;
183 sal_Int32 nAxisIndex = elem.first.second;
184 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
185 pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
186 , createCIDForAxis( nDimensionIndex, nAxisIndex ) );
187 if(nDimensionCount==2)
188 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
189 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
194 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
196 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
197 return;
199 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
200 bool bSwapXAndY = getPropertySwapXAndYAxis();
202 for (auto const& elem : m_aAxisMap)
204 VAxisBase* pVAxis = elem.second.get();
205 if( pVAxis )
207 sal_Int32 nDimensionIndex = elem.first.first;
208 sal_Int32 nAxisIndex = elem.first.second;
209 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
210 if(nDimensionCount==2)
211 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
212 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
217 } //namespace chart
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */