/src/libreoffice/include/oox/export/chartexport.hxx
Line | Count | Source |
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 | | |
20 | | #pragma once |
21 | | |
22 | | #include <set> |
23 | | #include <vector> |
24 | | |
25 | | #include <com/sun/star/uno/Reference.hxx> |
26 | | #include <com/sun/star/uno/Sequence.hxx> |
27 | | #include <com/sun/star/chart2/XFormattedString.hpp> |
28 | | #include <oox/dllapi.h> |
29 | | #include <oox/export/drawingml.hxx> |
30 | | #include <oox/export/utils.hxx> |
31 | | #include <oox/token/tokens.hxx> |
32 | | #include <rtl/ustring.hxx> |
33 | | #include <sal/types.h> |
34 | | #include <sax/fshelper.hxx> |
35 | | |
36 | | namespace com::sun::star { |
37 | | namespace beans { |
38 | | class XPropertySet; |
39 | | } |
40 | | namespace chart { |
41 | | class XDiagram; |
42 | | class XChartDocument; |
43 | | } |
44 | | namespace chart2 { |
45 | | struct RelativePosition; |
46 | | struct RelativeSize; |
47 | | class XDiagram; |
48 | | class XChartDocument; |
49 | | class XDataSeries; |
50 | | class XChartType; |
51 | | namespace data |
52 | | { |
53 | | class XDataSequence; |
54 | | class XLabeledDataSequence; |
55 | | } |
56 | | } |
57 | | namespace drawing { |
58 | | class XShape; |
59 | | } |
60 | | namespace frame { |
61 | | class XModel; |
62 | | } |
63 | | } |
64 | | |
65 | | namespace oox { |
66 | | namespace core { |
67 | | class XmlFilterBase; |
68 | | }} |
69 | | |
70 | | namespace model { |
71 | | struct StyleRef; |
72 | | struct FontRef; |
73 | | struct StyleEntry; |
74 | | } |
75 | | |
76 | | namespace oox::drawingml { |
77 | | |
78 | | struct LabelPlacementParam; |
79 | | |
80 | | enum AxisType |
81 | | { |
82 | | AXIS_PRIMARY_X, |
83 | | AXIS_PRIMARY_Y, |
84 | | AXIS_PRIMARY_Z, |
85 | | AXIS_SECONDARY_X, |
86 | | AXIS_SECONDARY_Y, |
87 | | AXIS_CATEGORY, // used for chartex |
88 | | AXIS_VALUE // used for chartex |
89 | | }; |
90 | | |
91 | | struct AxisIdPair { |
92 | | AxisType nAxisType; |
93 | | sal_Int32 nAxisId; |
94 | | sal_Int32 nCrossAx; |
95 | | |
96 | | AxisIdPair(AxisType nType, sal_Int32 nId, sal_Int32 nAx) |
97 | 0 | : nAxisType(nType) |
98 | 0 | , nAxisId(nId) |
99 | 0 | , nCrossAx(nAx) |
100 | 0 | {} |
101 | | }; |
102 | | |
103 | | /** |
104 | | A helper container class to collect the chart data point labels and the address |
105 | | of the cell[range] from which the labels are sourced if that is the case. This |
106 | | is then used to write the label texts under the extension tag <c15:datalabelsRange>. |
107 | | |
108 | | @since LibreOffice 7.3.0 |
109 | | */ |
110 | | class DataLabelsRange |
111 | | { |
112 | | public: |
113 | | |
114 | | /// type of the internal container that stores the indexed label text. |
115 | | typedef std::map<sal_Int32, OUString> LabelsRangeMap; |
116 | | |
117 | | /// Returns whether the container is empty or not. |
118 | | bool empty() const; |
119 | | /// Returns the count of labels stored. |
120 | | size_t count() const; |
121 | | /// Indicates whether the container has a label with index specified by nIndex. |
122 | | bool hasLabel(sal_Int32 nIndex) const; |
123 | | /// Returns the address of the cell[range] from which label contents are sourced. |
124 | | const OUString & getRange() const; |
125 | | |
126 | | /// Sets the address of the cell[range] from which label contents are sourced. |
127 | | void setRange(const OUString& rRange); |
128 | | /// Adds a new indexed label text. |
129 | | void setLabel(sal_Int32 nIndex, const OUString& rText); |
130 | | |
131 | | LabelsRangeMap::const_iterator begin() const; |
132 | | LabelsRangeMap::const_iterator end() const; |
133 | | |
134 | | private: |
135 | | OUString maRange; |
136 | | LabelsRangeMap maLabels; |
137 | | }; |
138 | | |
139 | | |
140 | | class ChartExport final : public DrawingML { |
141 | | |
142 | | public: |
143 | | // first: data sequence for label, second: data sequence for values. |
144 | | typedef ::std::vector< AxisIdPair > AxisVector; |
145 | | bool mbLinkToExternalData = true; |
146 | | |
147 | | private: |
148 | | struct ChartDimInfo |
149 | | { |
150 | | OUString sFormula; |
151 | | OUString sNFormula; |
152 | | OUString sDimTypeStr; // "val", "cat", "size", etc. |
153 | | bool bIsNumeric = false; |
154 | | bool bHasInfo = false; // true if chartex properties were found |
155 | | }; |
156 | | |
157 | | |
158 | | sal_Int32 mnXmlNamespace; |
159 | | sal_Int32 mnSeriesCount; |
160 | | css::uno::Reference< css::frame::XModel > mxChartModel; |
161 | | css::uno::Reference< css::chart::XDiagram > mxDiagram; |
162 | | css::uno::Reference< css::chart2::XDiagram > mxNewDiagram; |
163 | | std::shared_ptr<URLTransformer> mpURLTransformer; |
164 | | |
165 | | // members filled by InitRangeSegmentationProperties (retrieved from DataProvider) |
166 | | bool mbHasCategoryLabels; // if the categories are only automatically generated this will be false |
167 | | |
168 | | //css::uno::Reference< css::drawing::XShapes > mxAdditionalShapes; |
169 | | css::uno::Reference< css::chart2::data::XDataSequence > mxCategoriesValues; |
170 | | |
171 | | AxisVector maAxes; |
172 | | bool mbHasZAxis; |
173 | | bool mbIs3DChart; |
174 | | bool mbStacked; |
175 | | bool mbPercent; |
176 | | bool mbHasDateCategories; |
177 | | |
178 | | std::set<sal_Int32> maExportedAxis; |
179 | | |
180 | | private: |
181 | | sal_Int32 getChartType(); |
182 | | |
183 | | css::uno::Sequence< css::uno::Sequence< rtl::OUString > > getSplitCategoriesList(const OUString& rRange); |
184 | | |
185 | | OUString parseFormula( const OUString& rRange ); |
186 | | void InitPlotArea(); |
187 | | |
188 | | void ExportContent_(bool bIsChartex); |
189 | | void exportChartSpace( const css::uno::Reference< |
190 | | css::chart::XChartDocument >& rChartDoc, |
191 | | bool bIncludeTable, |
192 | | bool bIsChartex); |
193 | | void exportChart( const css::uno::Reference< |
194 | | css::chart::XChartDocument >& rChartDoc, |
195 | | bool bIsChartex); |
196 | | void exportData_chartex( const css::uno::Reference< |
197 | | css::chart::XChartDocument >& rChartDoc); |
198 | | void exportExternalData(bool bIsChartex); |
199 | | void exportLegend( const css::uno::Reference< |
200 | | css::chart::XChartDocument >& rChartDoc, |
201 | | bool bIsChartex); |
202 | | void exportTitle( const css::uno::Reference< css::drawing::XShape >& xShape, |
203 | | bool bIsChartex, |
204 | | const css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >& xFormattedSubTitle = |
205 | | css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >() ); |
206 | | void exportPlotArea( const css::uno::Reference< |
207 | | css::chart::XChartDocument >& rChartDoc, |
208 | | bool bIsChartex); |
209 | | void exportAdditionalShapes( const css::uno::Reference<css::chart::XChartDocument >& rChartDoc ); |
210 | | void exportFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); |
211 | | void exportSolidFill(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); |
212 | | void exportGradientFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); |
213 | | void exportBitmapFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); |
214 | | void exportHatch(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); |
215 | | void exportDataTable( ); |
216 | | ChartDimInfo getChartDimInfo( const css::uno::Reference<css::chart2::data::XDataSequence>& xSeq); |
217 | | |
218 | | void exportAreaChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
219 | | void exportBarChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
220 | | void exportBubbleChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
221 | | void exportDoughnutChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
222 | | // Output a chartex chart, other than RegionMap |
223 | | void exportChartex( const css::uno::Reference< css::chart2::XChartType >& xChartType, |
224 | | const char *sTypeName ); |
225 | | // Output a RegionMap chartex chart |
226 | | void exportRegionMapChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
227 | | void exportLineChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
228 | | void exportOfPieChart( const css::uno::Reference< css::chart2::XChartType >& |
229 | | xChartType, const char* s_subtype, double nSplitPos ); |
230 | | void exportPieChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
231 | | void exportRadarChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
232 | | void exportScatterChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
233 | | void exportScatterChartSeries( const css::uno::Reference< css::chart2::XChartType >& xChartType, |
234 | | const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries>>* pSeries); |
235 | | void exportStockChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
236 | | void exportSurfaceChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
237 | | void exportHiLowLines(); |
238 | | void exportUpDownBars(const css::uno::Reference< css::chart2::XChartType >& xChartType ); |
239 | | |
240 | | void exportAllSeries(const css::uno::Reference<css::chart2::XChartType>& xChartType, bool& rPrimaryAxes); |
241 | | void exportSeries_chart(const css::uno::Reference< css::chart2::XChartType >& xChartType, |
242 | | const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries> >& rSeriesSeq, |
243 | | bool& rPrimaryAxes); |
244 | | void exportSeries_chartex(const css::uno::Reference< css::chart2::XChartType >& xChartType, |
245 | | const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries> >& rSeriesSeq, |
246 | | const char* sTypeName); |
247 | | |
248 | | void exportVaryColors(const css::uno::Reference<css::chart2::XChartType>& xChartType); |
249 | | void exportCandleStickSeries( |
250 | | const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries>>& aSeriesSeq, |
251 | | bool& rPrimaryAxes); |
252 | | |
253 | | void exportSeriesText( |
254 | | const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, bool bIsChartex ); |
255 | | void exportSeriesCategory( |
256 | | const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, sal_Int32 nValueType = XML_cat ); |
257 | | void exportSeriesValues( |
258 | | const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, sal_Int32 nValueType = XML_val ); |
259 | | void exportShapeProps( const css::uno::Reference< css::beans::XPropertySet >& xPropSet, |
260 | | sal_Int32 nNS); |
261 | | static bool hasExplicitSpPr( |
262 | | const css::uno::Reference< css::beans::XPropertySet >& xPropSet); |
263 | | void exportDataPoints( |
264 | | const css::uno::Reference< css::beans::XPropertySet >& xSeriesProperties, |
265 | | sal_Int32 nSeriesLength, sal_Int32 eChartType ); |
266 | | void exportDataLabels( const css::uno::Reference<css::chart2::XDataSeries>& xSeries, sal_Int32 nSeriesLength, |
267 | | sal_Int32 eChartType, DataLabelsRange& rDLblsRange, |
268 | | bool bIsChartex); |
269 | | void exportGrouping( bool isBar = false ); |
270 | | void exportTrendlines( const css::uno::Reference< css::chart2::XDataSeries >& xSeries ); |
271 | | void exportMarker( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); |
272 | | void exportSmooth(); |
273 | | void exportFirstSliceAng(); |
274 | | |
275 | | void exportErrorBar(const css::uno::Reference< css::beans::XPropertySet >& xErrorBarProps, |
276 | | bool bYError); |
277 | | |
278 | | void exportManualLayout(const css::chart2::RelativePosition& rPos, const css::chart2::RelativeSize& rSize, const bool bIsExcludingDiagramPositioning); |
279 | | |
280 | | void exportAxes_chart(); |
281 | | void exportAxes_chartex(); |
282 | | void exportAxis(const AxisIdPair& rAxisIdPair, |
283 | | bool bIsChartex); |
284 | | void exportOneAxis_chart( |
285 | | const css::uno::Reference< css::beans::XPropertySet >& xAxisProp, |
286 | | const css::uno::Reference< css::drawing::XShape >& xAxisTitle, |
287 | | const css::uno::Reference< css::beans::XPropertySet >& xMajorGrid, |
288 | | const css::uno::Reference< css::beans::XPropertySet >& xMinorGrid, |
289 | | sal_Int32 nAxisType, |
290 | | const char* sAxisPos, |
291 | | const AxisIdPair& rAxisIdPair); |
292 | | void exportOneAxis_chartex( |
293 | | const css::uno::Reference< css::beans::XPropertySet >& xAxisProp, |
294 | | const css::uno::Reference< css::drawing::XShape >& xAxisTitle, |
295 | | const css::uno::Reference< css::beans::XPropertySet >& xMajorGrid, |
296 | | const css::uno::Reference< css::beans::XPropertySet >& xMinorGrid, |
297 | | sal_Int32 nAxisType, |
298 | | const AxisIdPair& rAxisIdPair); |
299 | | void createAxes_chart(bool bPrimaryAxes, bool bCheckCombinedAxes); |
300 | | void createAxes_chartex( |
301 | | const css::uno::Reference<css::chart2::XDataSeries>& xSeries); |
302 | | void exportView3D(); |
303 | | bool isDeep3dChart(); |
304 | | |
305 | | // Namespace abbreviations used in chartex charts |
306 | | enum class NamespaceAbbrev |
307 | | { |
308 | | NONE, // not chartex |
309 | | CX1, // cx1 = "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" |
310 | | CX2, // cx2 = "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" |
311 | | CX4 // cx4 = "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" |
312 | | }; |
313 | | |
314 | | // Determine if (at least one) chart exported is from the 2014 chartex |
315 | | // schema. If not, all are from the 2006 chart schema. |
316 | | bool isChartexNotChartNS(NamespaceAbbrev *peNS) const; |
317 | | |
318 | | void exportMissingValueTreatment(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); |
319 | | |
320 | | OUString getNumberFormatCode(sal_Int32 nKey) const; |
321 | | |
322 | | // Functions for style file output |
323 | | void outputStyleEntry(::sax_fastparser::FSHelperPtr pFS, |
324 | | sal_Int32 nElTokenId, model::StyleEntry& aEntry); |
325 | | void outputStyleRef(::sax_fastparser::FSHelperPtr pFS, |
326 | | sal_Int32 nElTokenId, const model::StyleRef& aColor); |
327 | | void outputFontRef(::sax_fastparser::FSHelperPtr pFS, |
328 | | sal_Int32 nElTokenId, const model::FontRef& aColor); |
329 | | |
330 | | void writeLabelProperties( |
331 | | const css::uno::Reference<css::beans::XPropertySet>& xPropSet, const LabelPlacementParam& rLabelParam, |
332 | | sal_Int32 nLabelIndex, DataLabelsRange& rDLblsRange, |
333 | | bool bIsChartex); |
334 | | |
335 | | static void writeChartDim(const ::sax_fastparser::FSHelperPtr& pFS, const ChartDimInfo& rInfo, |
336 | | bool *bIsCat /* output var: is this category data? */); |
337 | | public: |
338 | | |
339 | | OOX_DLLPUBLIC ChartExport( sal_Int32 nXmlNamespace, ::sax_fastparser::FSHelperPtr pFS, css::uno::Reference< css::frame::XModel > const & xModel, |
340 | | ::oox::core::XmlFilterBase* pFB, DocumentType eDocumentType ); |
341 | | |
342 | | OOX_DLLPUBLIC void SetURLTranslator(const std::shared_ptr<URLTransformer>& pTransformer); |
343 | | |
344 | 0 | const css::uno::Reference< css::frame::XModel >& getModel() const { return mxChartModel; } |
345 | | |
346 | | OOX_DLLPUBLIC void WriteChartObj( const css::uno::Reference< css::drawing::XShape >& xShape, sal_Int32 nID, sal_Int32 nChartCount ); |
347 | | void exportTextProps(const css::uno::Reference< css::beans::XPropertySet >& xPropSet, bool bIsChartex); |
348 | | |
349 | | OOX_DLLPUBLIC void ExportContent(); |
350 | | void InitRangeSegmentationProperties( |
351 | | const css::uno::Reference< |
352 | | css::chart2::XChartDocument > & xChartDoc ); |
353 | | |
354 | | OOX_DLLPUBLIC OUString GetExternalDataPath() const; |
355 | | }; |
356 | | |
357 | | } // namespace oox::drawingml |
358 | | |
359 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |