LibreOffice Module sc (master) 1
SparklineExt.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
11
12#include <oox/export/utils.hxx>
13#include <oox/token/namespaces.hxx>
14#include <oox/token/tokens.hxx>
15#include <SparklineGroup.hxx>
16#include <SparklineList.hxx>
17
18using namespace oox;
19
20namespace xcl::exp
21{
23 : XclExpExt(rRoot)
24{
25 maURI = "{05C60535-1F16-4fd2-B633-F4F36F0B64E0}";
26}
27
29{
30 auto& rDocument = GetDoc();
31
32 auto* pSparklineList = rDocument.GetSparklineList(GetCurrScTab());
33 if (!pSparklineList)
34 return;
35
36 auto const& rSparklineGroups = pSparklineList->getSparklineGroups();
37
38 sax_fastparser::FSHelperPtr& rWorksheet = rStream.GetCurrentStream();
39 rWorksheet->startElement(XML_ext, FSNS(XML_xmlns, XML_x14),
40 rStream.getNamespaceURL(OOX_NS(xls14Lst)), XML_uri, maURI);
41
42 rWorksheet->startElementNS(XML_x14, XML_sparklineGroups, FSNS(XML_xmlns, XML_xm),
43 rStream.getNamespaceURL(OOX_NS(xm)));
44
45 for (auto const& pSparklineGroup : rSparklineGroups)
46 {
47 auto const& rSparklineVector = pSparklineList->getSparklinesFor(pSparklineGroup);
48 addSparklineGroup(rStream, *pSparklineGroup, rSparklineVector);
49 }
50
51 rWorksheet->endElementNS(XML_x14, XML_sparklineGroups);
52 rWorksheet->endElement(XML_ext);
53}
54
57 sc::SparklineAttributes& rAttributes)
58{
59 if (rAttributes.getLineWeight() != 0.75)
60 pAttrList->add(XML_lineWeight, OString::number(rAttributes.getLineWeight()));
61
62 if (rAttributes.getType() != sc::SparklineType::Line)
63 {
64 if (rAttributes.getType() == sc::SparklineType::Column)
65 pAttrList->add(XML_type, "column");
66 else if (rAttributes.getType() == sc::SparklineType::Stacked)
67 pAttrList->add(XML_type, "stacked");
68 }
69
70 if (rAttributes.isDateAxis())
71 pAttrList->add(XML_dateAxis, "1");
72
74 {
76 pAttrList->add(XML_displayEmptyCellsAs, "gap");
78 pAttrList->add(XML_displayEmptyCellsAs, "span");
79 }
80
81 if (rAttributes.isMarkers())
82 pAttrList->add(XML_markers, "1");
83 if (rAttributes.isHigh())
84 pAttrList->add(XML_high, "1");
85 if (rAttributes.isLow())
86 pAttrList->add(XML_low, "1");
87 if (rAttributes.isFirst())
88 pAttrList->add(XML_first, "1");
89 if (rAttributes.isLast())
90 pAttrList->add(XML_last, "1");
91 if (rAttributes.isNegative())
92 pAttrList->add(XML_negative, "1");
93 if (rAttributes.shouldDisplayXAxis())
94 pAttrList->add(XML_displayXAxis, "1");
95 if (rAttributes.shouldDisplayHidden())
96 pAttrList->add(XML_displayHidden, "1");
97
98 if (rAttributes.getMinAxisType() != sc::AxisType::Individual)
99 {
100 if (rAttributes.getMinAxisType() == sc::AxisType::Group)
101 pAttrList->add(XML_minAxisType, "group");
102 else if (rAttributes.getMinAxisType() == sc::AxisType::Custom)
103 pAttrList->add(XML_minAxisType, "custom");
104 }
105
106 if (rAttributes.getMaxAxisType() != sc::AxisType::Individual)
107 {
108 if (rAttributes.getMaxAxisType() == sc::AxisType::Group)
109 pAttrList->add(XML_maxAxisType, "group");
110 else if (rAttributes.getMaxAxisType() == sc::AxisType::Custom)
111 pAttrList->add(XML_maxAxisType, "custom");
112 }
113
114 if (rAttributes.isRightToLeft())
115 pAttrList->add(XML_rightToLeft, "1");
116
117 if (rAttributes.getManualMax() && rAttributes.getMaxAxisType() == sc::AxisType::Custom)
118 pAttrList->add(XML_manualMax, OString::number(*rAttributes.getManualMax()));
119
120 if (rAttributes.getManualMin() && rAttributes.getMinAxisType() == sc::AxisType::Custom)
121 pAttrList->add(XML_manualMin, OString::number(*rAttributes.getManualMin()));
122}
123
125 sc::SparklineAttributes& rAttributes)
126{
127 sax_fastparser::FSHelperPtr& rWorksheet = rStream.GetCurrentStream();
128
129 rWorksheet->singleElementNS(XML_x14, XML_colorSeries, XML_rgb,
131
132 if (rAttributes.getColorNegative() != COL_TRANSPARENT)
133 {
134 rWorksheet->singleElementNS(XML_x14, XML_colorNegative, XML_rgb,
136 }
137
138 if (rAttributes.getColorAxis() != COL_TRANSPARENT)
139 {
140 rWorksheet->singleElementNS(XML_x14, XML_colorAxis, XML_rgb,
141 XclXmlUtils::ToOString(rAttributes.getColorAxis()));
142 }
143
144 if (rAttributes.getColorMarkers() != COL_TRANSPARENT)
145 {
146 rWorksheet->singleElementNS(XML_x14, XML_colorMarkers, XML_rgb,
148 }
149
150 if (rAttributes.getColorFirst() != COL_TRANSPARENT)
151 {
152 rWorksheet->singleElementNS(XML_x14, XML_colorFirst, XML_rgb,
154 }
155
156 if (rAttributes.getColorLast() != COL_TRANSPARENT)
157 {
158 rWorksheet->singleElementNS(XML_x14, XML_colorLast, XML_rgb,
159 XclXmlUtils::ToOString(rAttributes.getColorLast()));
160 }
161
162 if (rAttributes.getColorHigh() != COL_TRANSPARENT)
163 {
164 rWorksheet->singleElementNS(XML_x14, XML_colorHigh, XML_rgb,
165 XclXmlUtils::ToOString(rAttributes.getColorHigh()));
166 }
167
168 if (rAttributes.getColorLow() != COL_TRANSPARENT)
169 {
170 rWorksheet->singleElementNS(XML_x14, XML_colorLow, XML_rgb,
171 XclXmlUtils::ToOString(rAttributes.getColorLow()));
172 }
173}
174
176 std::vector<std::shared_ptr<sc::Sparkline>> const& rSparklines)
177{
178 sax_fastparser::FSHelperPtr& rWorksheet = rStream.GetCurrentStream();
179
180 // Sparkline Group Attributes
182
183 // Write ID
184 OString sUID = rSparklineGroup.getID().getString();
185 pAttrList->addNS(XML_xr2, XML_uid, sUID);
186
187 // Write attributes
188 addSparklineGroupAttributes(pAttrList, rSparklineGroup.getAttributes());
189
190 rWorksheet->startElementNS(XML_x14, XML_sparklineGroup, pAttrList);
191
192 addSparklineGroupColors(rStream, rSparklineGroup.getAttributes());
193
194 // Sparklines
195
196 rWorksheet->startElementNS(XML_x14, XML_sparklines);
197 for (auto const& rSparkline : rSparklines)
198 {
199 rWorksheet->startElementNS(XML_x14, XML_sparkline);
200
201 {
202 rWorksheet->startElementNS(XML_xm, XML_f);
203
204 OUString sRangeFormula;
206 rSparkline->getInputRange().Format(sRangeFormula, eFlags, GetDoc(),
208
209 rWorksheet->writeEscaped(sRangeFormula);
210 rWorksheet->endElementNS(XML_xm, XML_f);
211 }
212
213 {
214 rWorksheet->startElementNS(XML_xm, XML_sqref);
215
217 ScAddress aAddress(rSparkline->getColumn(), rSparkline->getRow(), GetCurrScTab());
218 OUString sLocation = aAddress.Format(ScRefFlags::VALID, &GetDoc(), detailsXL);
219
220 rWorksheet->writeEscaped(sLocation);
221 rWorksheet->endElementNS(XML_xm, XML_sqref);
222 }
223
224 rWorksheet->endElementNS(XML_x14, XML_sparkline);
225 }
226 rWorksheet->endElementNS(XML_x14, XML_sparklines);
227 rWorksheet->endElementNS(XML_x14, XML_sparklineGroup);
228}
229
231 : XclExpRoot(rRoot)
232{
233 auto& rDocument = GetDoc();
234 auto* pSparklineList = rDocument.GetSparklineList(GetCurrScTab());
235 if (pSparklineList && !pSparklineList->getSparklineGroups().empty())
236 {
237 xExtLst->AddRecord(new xcl::exp::SparklineExt(GetRoot()));
238 }
239}
240
241} // end namespace xcl::exp
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags
Definition: address.hxx:158
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
Base class for ext entries.
Definition: xeextlst.hxx:38
OString maURI
Definition: xeextlst.hxx:44
Access to global data from other classes.
Definition: xeroot.hxx:113
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xeroot.hxx:118
sax_fastparser::FSHelperPtr & GetCurrentStream()
Definition: xestream.cxx:912
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:162
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:285
static OString ToOString(const Color &rColor)
Definition: xestream.cxx:709
OUString getNamespaceURL(sal_Int32 nNSID) const
static rtl::Reference< FastAttributeList > createAttrList()
Common properties for a group of sparklines.
DisplayEmptyCellsAs getDisplayEmptyCellsAs() const
std::optional< double > getManualMax() const
SparklineType getType() const
std::optional< double > getManualMin() const
double getLineWeight() const
Line weight or width in points.
Common properties for a group of sparklines.
tools::Guid & getID()
SparklineAttributes & getAttributes()
OString getString() const
SparklineBuffer(const XclExpRoot &rRoot, const XclExtLstRef &xExtLst)
Export for sparkline type of <ext> element - top sparkline element.
static void addSparklineGroupAttributes(rtl::Reference< sax_fastparser::FastAttributeList > &pAttrList, sc::SparklineAttributes &rSparklineAttributes)
static void addSparklineGroupColors(XclExpXmlStream &rStream, sc::SparklineAttributes &rSparklineAttributes)
void addSparklineGroup(XclExpXmlStream &rStream, sc::SparklineGroup &rSparklineGroup, std::vector< std::shared_ptr< sc::Sparkline > > const &rSparklines)
void SaveXml(XclExpXmlStream &rStream) override
SparklineExt(const XclExpRoot &rRoot)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
XML_type