LibreOffice Module chart2 (master) 1
VCartesianCoordinateSystem.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include "VCartesianGrid.hxx"
22#include "VCartesianAxis.hxx"
24#include <AxisIndexDefines.hxx>
25#include <Axis.hxx>
26#include <DataTable.hxx>
27#include <Diagram.hxx>
28#include <AxisHelper.hxx>
30#include <ChartModel.hxx>
31#include <GridProperties.hxx>
32#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
33#include <com/sun/star/chart2/AxisType.hpp>
34
35namespace chart
36{
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::chart2;
39using ::com::sun::star::uno::Reference;
40
41namespace {
42
43class TextualDataProvider : public ::cppu::WeakImplHelper<
44 css::chart2::data::XTextualDataSequence
45 >
46{
47public:
48 explicit TextualDataProvider( const uno::Sequence< OUString >& rTextSequence )
49 : m_aTextSequence( rTextSequence )
50 {
51 }
52
53 //XTextualDataSequence
54 virtual uno::Sequence< OUString > SAL_CALL getTextualData() override
55 {
56 return m_aTextSequence;
57 }
58
59private: //member
60 uno::Sequence< OUString > m_aTextSequence;
61};
62
63}
64
66 : VCoordinateSystem(xCooSys)
67{
68}
69
70VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
71{
72}
73
74void VCartesianCoordinateSystem::createGridShapes()
75{
76 if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
77 return;
78
79 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
80 bool bSwapXAndY = getPropertySwapXAndYAxis();
81
82 for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
83 {
84 sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
85 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel );
86 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
87 continue;
88
89 VCartesianGrid aGrid(nDimensionIndex,nDimensionCount, getGridListFromAxis( xAxis ));
90 aGrid.setExplicitScaleAndIncrement( getExplicitScale(nDimensionIndex,nAxisIndex)
91 , getExplicitIncrement(nDimensionIndex,nAxisIndex) );
92 aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
93
94 aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget
95 , createCIDForGrid( nDimensionIndex,nAxisIndex ) );
96 if(nDimensionCount==2)
97 aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
98 aGrid.setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
99 aGrid.createShapes();
100 }
101}
102
103void VCartesianCoordinateSystem::createVAxisList(
104 const rtl::Reference<::chart::ChartModel> & xChartDoc,
105 const awt::Size& rFontReferenceSize,
106 const awt::Rectangle& rMaximumSpaceForLabels,
107 bool bLimitSpaceForLabels,
108 std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList,
109 uno::Reference<uno::XComponentContext> const& rComponentContext)
110{
111 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
112 // a leak from VCartesianAxis due to cyclic reference
113 uno::Reference<util::XNumberFormatsSupplier> const xNumberFormatsSupplier(
114 xChartDoc->getNumberFormatsSupplier());
115
116 m_aAxisMap.clear();
117
118 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
119 bool bSwapXAndY = getPropertySwapXAndYAxis();
120
121 if(nDimensionCount<=0)
122 return;
123
124 sal_Int32 nDimensionIndex = 0;
125
126 // dimension index -> x, y or z axis.
127 for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
128 {
129 // axis index -> primary or secondary axis.
130 sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
131 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
132 {
133 rtl::Reference< Axis > xAxis = getAxisByDimension(nDimensionIndex,nAxisIndex);
134 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
135 continue;
136
137 rtl::Reference<Diagram> xDiagram(xChartDoc->getFirstChartDiagram());
138 AxisProperties aAxisProperties(xAxis, getExplicitCategoriesProvider(), xDiagram->getDataTableRef());
139 aAxisProperties.m_nDimensionIndex = nDimensionIndex;
140 aAxisProperties.m_bSwapXAndY = bSwapXAndY;
141 aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
142 aAxisProperties.m_bLimitSpaceForLabels = bLimitSpaceForLabels;
143 rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel );
144 if( xCrossingMainAxis.is() )
145 {
146 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
147 aAxisProperties.m_bCrossingAxisHasReverseDirection = (aCrossingScale.Orientation==AxisOrientation_REVERSE);
148
149 if( aCrossingScale.AxisType == AxisType::CATEGORY )
150 aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
151 }
152
153 if( nDimensionIndex == 2 )
154 {
155 aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
156
157 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
158 rtl::Reference< Axis > xSisterAxis = AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel );
159 aAxisProperties.initAxisPositioning( xSisterAxis );
160 }
161 aAxisProperties.init(true);
162 if(aAxisProperties.m_bDisplayLabels)
163 aAxisProperties.m_nNumberFormatKey = getNumberFormatKeyForAxis(xAxis, xChartDoc);
164
165 auto apVAxis = std::make_shared<VCartesianAxis>(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount);
166 tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
167 m_aAxisMap[aFullAxisIndex] = apVAxis;
168 apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
169
170 apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
171 apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier, xChartDoc, rComponentContext);
172 }
173 }
174}
175
176void VCartesianCoordinateSystem::initVAxisInList()
177{
178 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
179 return;
180
181 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
182 bool bSwapXAndY = getPropertySwapXAndYAxis();
183
184 for (auto const& [nIndexPair, pVAxis] : m_aAxisMap)
185 {
186 if (pVAxis)
187 {
188 auto [nDimensionIndex, nAxisIndex] = nIndexPair;
189 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
190 pVAxis->initPlotter(m_xLogicTargetForAxes, m_xFinalTarget, createCIDForAxis( nDimensionIndex, nAxisIndex ) );
191 if(nDimensionCount==2)
192 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
193 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
194 }
195 }
196}
197
198void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
199{
200 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
201 return;
202
203 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
204 bool bSwapXAndY = getPropertySwapXAndYAxis();
205
206 for (auto const& [nIndexPair, pVAxis] : m_aAxisMap)
207 {
208 if (pVAxis)
209 {
210 auto [nDimensionIndex, nAxisIndex] = nIndexPair;
211
212 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
213 if(nDimensionCount==2)
214 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
215 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
216 }
217 }
218}
219
220} //namespace chart
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Sequence< OUString > m_aTextSequence
virtual void setScales(std::vector< ExplicitScaleData > &&rScales, bool bSwapXAndYAxis)
Definition: PlotterBase.cxx:51
virtual void initPlotter(const rtl::Reference< SvxShapeGroupAnyD > &xLogicTarget, const rtl::Reference< SvxShapeGroupAnyD > &xFinalTarget, const OUString &rCID)
Definition: PlotterBase.cxx:36
void set3DWallPositions(CuboidPlanePosition eLeftWallPos, CuboidPlanePosition eBackWallPos, CuboidPlanePosition eBottomPos)
virtual void setExplicitScaleAndIncrement(const ExplicitScaleData &rScale, const ExplicitIncrementData &rIncrement)
virtual void setTransformationSceneToScreen(const css::drawing::HomogenMatrix &rMatrix) override
virtual void createShapes() override
std::pair< sal_Int32, sal_Int32 > tFullAxisIndex
const sal_Int32 MAIN_AXIS_INDEX
css::uno::Reference< css::chart2::data::XTextualDataSequence > m_xAxisTextProvider
void init(bool bCartesian=false)
void initAxisPositioning(const css::uno::Reference< css::beans::XPropertySet > &xAxisProp)