LibreOffice Module chart2 (master) 1
ExplicitValueProvider.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 <AxisHelper.hxx>
22#include <ChartModel.hxx>
23#include <Diagram.hxx>
24#include <DiagramHelper.hxx>
25#include <unonames.hxx>
27#include <TitleHelper.hxx>
28#include <ObjectIdentifier.hxx>
29
32
33namespace chart
34{
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37using ::com::sun::star::uno::Reference;
38
39namespace
40{
41constexpr sal_Int32 constDiagramTitleSpace = 200; //=0,2 cm spacing
42
43bool lcl_getPropertySwapXAndYAxis(const rtl::Reference<Diagram>& xDiagram)
44{
45 bool bSwapXAndY = false;
46
47 if (xDiagram.is())
48 {
49 const std::vector<rtl::Reference<BaseCoordinateSystem>>& aCooSysList(
50 xDiagram->getBaseCoordinateSystems());
51 if (!aCooSysList.empty())
52 {
53 try
54 {
55 aCooSysList[0]->getPropertyValue("SwapXAndYAxis") >>= bSwapXAndY;
56 }
57 catch (const uno::Exception&)
58 {
59 TOOLS_WARN_EXCEPTION("chart2", "");
60 }
61 }
62 }
63 return bSwapXAndY;
64}
65
66} // end anonymous namespace
67
68sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
70 const rtl::Reference<::chart::BaseCoordinateSystem>& xCorrespondingCoordinateSystem,
72{
74 xAxis, xCorrespondingCoordinateSystem, xChartDoc,
75 true /*bSearchForParallelAxisIfNothingIsFound*/);
76}
77
78sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
79 const uno::Reference<beans::XPropertySet>& xSeriesOrPointProp)
80{
81 sal_Int32 nFormat = 0;
82 if (!xSeriesOrPointProp.is())
83 return nFormat;
84
85 try
86 {
87 xSeriesOrPointProp->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nFormat;
88 }
89 catch (const beans::UnknownPropertyException&)
90 {
91 }
92
93 if (nFormat < 0)
94 nFormat = 0;
95 return nFormat;
96}
97
98sal_Int32 ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
99 const uno::Reference<beans::XPropertySet>& xSeriesOrPointProp,
100 const uno::Reference<util::XNumberFormatsSupplier>& xNumberFormatsSupplier)
101{
102 sal_Int32 nFormat = 0;
103 if (!xSeriesOrPointProp.is())
104 return nFormat;
105 if (!(xSeriesOrPointProp->getPropertyValue("PercentageNumberFormat") >>= nFormat))
106 {
107 nFormat = DiagramHelper::getPercentNumberFormat(xNumberFormatsSupplier);
108 }
109 if (nFormat < 0)
110 nFormat = 0;
111 return nFormat;
112}
113
114awt::Rectangle ExplicitValueProvider::AddSubtractAxisTitleSizes(
115 ChartModel& rModel, ExplicitValueProvider* pChartView, const awt::Rectangle& rPositionAndSize,
116 bool bSubtract)
117{
118 awt::Rectangle aRet(rPositionAndSize);
119
120 //add axis title sizes to the diagram size
121 rtl::Reference<::chart::Title> xTitle_Height(
125 rtl::Reference<::chart::Title> xSecondTitle_Height(
127 rtl::Reference<::chart::Title> xSecondTitle_Width(
129 if (xTitle_Height.is() || xTitle_Width.is() || xSecondTitle_Height.is()
130 || xSecondTitle_Width.is())
131 {
132 ExplicitValueProvider* pExplicitValueProvider = pChartView;
133 if (pExplicitValueProvider)
134 {
135 //detect whether x axis points into x direction or not
136 if (lcl_getPropertySwapXAndYAxis(rModel.getFirstChartDiagram()))
137 {
138 std::swap(xTitle_Height, xTitle_Width);
139 std::swap(xSecondTitle_Height, xSecondTitle_Width);
140 }
141
142 sal_Int32 nTitleSpaceWidth = 0;
143 sal_Int32 nTitleSpaceHeight = 0;
144 sal_Int32 nSecondTitleSpaceWidth = 0;
145 sal_Int32 nSecondTitleSpaceHeight = 0;
146
147 if (xTitle_Height.is())
148 {
149 OUString aCID_X(
151 nTitleSpaceHeight
152 = pExplicitValueProvider->getRectangleOfObject(aCID_X, true).Height;
153 if (nTitleSpaceHeight)
154 nTitleSpaceHeight += constDiagramTitleSpace;
155 }
156 if (xTitle_Width.is())
157 {
158 OUString aCID_Y(
160 nTitleSpaceWidth = pExplicitValueProvider->getRectangleOfObject(aCID_Y, true).Width;
161 if (nTitleSpaceWidth)
162 nTitleSpaceWidth += constDiagramTitleSpace;
163 }
164 if (xSecondTitle_Height.is())
165 {
167 xSecondTitle_Height, &rModel));
168 nSecondTitleSpaceHeight
169 = pExplicitValueProvider->getRectangleOfObject(aCID_X, true).Height;
170 if (nSecondTitleSpaceHeight)
171 nSecondTitleSpaceHeight += constDiagramTitleSpace;
172 }
173 if (xSecondTitle_Width.is())
174 {
176 xSecondTitle_Width, &rModel));
177 nSecondTitleSpaceWidth
178 += pExplicitValueProvider->getRectangleOfObject(aCID_Y, true).Width;
179 if (nSecondTitleSpaceWidth)
180 nSecondTitleSpaceWidth += constDiagramTitleSpace;
181 }
182 if (bSubtract)
183 {
184 aRet.X += nTitleSpaceWidth;
185 aRet.Y += nSecondTitleSpaceHeight;
186 aRet.Width -= (nTitleSpaceWidth + nSecondTitleSpaceWidth);
187 aRet.Height -= (nTitleSpaceHeight + nSecondTitleSpaceHeight);
188 }
189 else
190 {
191 aRet.X -= nTitleSpaceWidth;
192 aRet.Y -= nSecondTitleSpaceHeight;
193 aRet.Width += nTitleSpaceWidth + nSecondTitleSpaceWidth;
194 aRet.Height += nTitleSpaceHeight + nSecondTitleSpaceHeight;
195 }
196 }
197 }
198 return aRet;
199}
200
201} //namespace chart
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int32 getExplicitNumberFormatKeyForAxis(const rtl::Reference< ::chart::Axis > &xAxis, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCorrespondingCoordinateSystem, const rtl::Reference< ::chart::ChartModel > &xChartDoc, bool bSearchForParallelAxisIfNothingIsFound)
Definition: AxisHelper.cxx:138
static sal_Int32 getPercentNumberFormat(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier)
static OUString createClassifiedIdentifierForObject(const css::uno::Reference< css::uno::XInterface > &xObject, const rtl::Reference<::chart::ChartModel > &xChartModel)
static rtl::Reference< ::chart::Title > getTitle(eTitleType nTitleIndex, ChartModel &rModel)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr OUStringLiteral CHART_UNONAME_NUMFMT
Definition: unonames.hxx:20