/src/libstaroffice/src/lib/STOFFChart.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libstaroffice |
4 | | * Version: MPL 2.0 / LGPLv2+ |
5 | | * |
6 | | * The contents of this file are subject to the Mozilla Public License Version |
7 | | * 2.0 (the "License"); you may not use this file except in compliance with |
8 | | * the License or as specified alternatively below. You may obtain a copy of |
9 | | * the License at http://www.mozilla.org/MPL/ |
10 | | * |
11 | | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | | * for the specific language governing rights and limitations under the |
14 | | * License. |
15 | | * |
16 | | * Major Contributor(s): |
17 | | * Copyright (C) 2002 William Lachance (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
22 | | * |
23 | | * |
24 | | * All Rights Reserved. |
25 | | * |
26 | | * For minor contributions see the git repository. |
27 | | * |
28 | | * Alternatively, the contents of this file may be used under the terms of |
29 | | * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
30 | | * in which case the provisions of the LGPLv2+ are applicable |
31 | | * instead of those above. |
32 | | */ |
33 | | |
34 | | /* |
35 | | * Structure to store and construct a chart |
36 | | * |
37 | | */ |
38 | | |
39 | | #ifndef STOFF_CHART |
40 | | # define STOFF_CHART |
41 | | |
42 | | #include <iostream> |
43 | | #include <vector> |
44 | | #include <map> |
45 | | |
46 | | #include "libstaroffice_internal.hxx" |
47 | | |
48 | | #include "STOFFEntry.hxx" |
49 | | #include "STOFFFont.hxx" |
50 | | #include "STOFFGraphicStyle.hxx" |
51 | | |
52 | | namespace STOFFChartInternal |
53 | | { |
54 | | class SubDocument; |
55 | | } |
56 | | /** a class used to store a chart associated to a spreadsheet .... */ |
57 | | class STOFFChart |
58 | | { |
59 | | friend class STOFFChartInternal::SubDocument; |
60 | | public: |
61 | | //! a cell position |
62 | | struct Position { |
63 | | //! constructor |
64 | | explicit Position(STOFFVec2i pos=STOFFVec2i(-1,-1), librevenge::RVNGString const &sheetName="") |
65 | 0 | : m_pos(pos) |
66 | 0 | , m_sheetName(sheetName) |
67 | 0 | { |
68 | 0 | } |
69 | | //! return true if the position is valid |
70 | | bool valid() const |
71 | 0 | { |
72 | 0 | return m_pos[0]>=0 && m_pos[1]>=0 && !m_sheetName.empty(); |
73 | 0 | } |
74 | | //! return true if the position is valid |
75 | | bool valid(Position const &maxPos) const |
76 | 0 | { |
77 | 0 | return valid() && maxPos.valid() && maxPos.m_pos[0]>=m_pos[0] && maxPos.m_pos[1]>=m_pos[1]; |
78 | 0 | } |
79 | | //! return the cell name |
80 | | librevenge::RVNGString getCellName() const; |
81 | | //! operator<< |
82 | | friend std::ostream &operator<<(std::ostream &o, Position const &pos); |
83 | | //! operator== |
84 | | bool operator==(Position &pos) const |
85 | 0 | { |
86 | 0 | return m_pos==pos.m_pos && m_sheetName==pos.m_sheetName; |
87 | 0 | } |
88 | | //! operator!= |
89 | | bool operator!=(Position &pos) const |
90 | 0 | { |
91 | 0 | return !(operator==(pos)); |
92 | 0 | } |
93 | | //! the cell column and row |
94 | | STOFFVec2i m_pos; |
95 | | //! the cell sheet name |
96 | | librevenge::RVNGString m_sheetName; |
97 | | }; |
98 | | struct Axis { |
99 | | //! the axis content |
100 | | enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty }; |
101 | | //! constructor |
102 | | Axis(); |
103 | | //! destructor |
104 | | ~Axis(); |
105 | | //! add content to the propList |
106 | | void addContentTo(int coord, librevenge::RVNGPropertyList &propList) const; |
107 | | //! add style to the propList |
108 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
109 | | //! operator<< |
110 | | friend std::ostream &operator<<(std::ostream &o, Axis const &axis); |
111 | | //! the sequence type |
112 | | Type m_type; |
113 | | //! automatic scaling (or manual) |
114 | | bool m_automaticScaling; |
115 | | //! the minimum, maximum scaling(if manual) |
116 | | STOFFVec2f m_scaling; |
117 | | //! show or not the grid |
118 | | bool m_showGrid; |
119 | | //! show or not the label |
120 | | bool m_showLabel; |
121 | | //! the label range if defined |
122 | | Position m_labelRanges[2]; |
123 | | |
124 | | //! show or not the title/subtitle |
125 | | bool m_showTitle; |
126 | | //! the title cell range |
127 | | Position m_titleRange; |
128 | | //! the title label |
129 | | librevenge::RVNGString m_title; |
130 | | //! the subtitle label |
131 | | librevenge::RVNGString m_subTitle; |
132 | | //! the graphic style |
133 | | STOFFGraphicStyle m_style; |
134 | | }; |
135 | | //! a legend in a chart |
136 | | struct Legend { |
137 | | //! constructor |
138 | | Legend() |
139 | 0 | : m_show(false) |
140 | 0 | , m_autoPosition(true) |
141 | 0 | , m_relativePosition(libstoff::RightBit) |
142 | 0 | , m_position(0,0) |
143 | 0 | , m_font() |
144 | 0 | , m_style() |
145 | 0 | { |
146 | 0 | } |
147 | | //! add content to the propList |
148 | | void addContentTo(librevenge::RVNGPropertyList &propList) const; |
149 | | //! add style to the propList |
150 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
151 | | //! operator<< |
152 | | friend std::ostream &operator<<(std::ostream &o, Legend const &legend); |
153 | | //! show or not the legend |
154 | | bool m_show; |
155 | | //! automatic position |
156 | | bool m_autoPosition; |
157 | | //! the automatic position libstoff::LeftBit|... |
158 | | int m_relativePosition; |
159 | | //! the position in points |
160 | | STOFFVec2f m_position; |
161 | | //! the font |
162 | | STOFFFont m_font; |
163 | | //! the graphic style |
164 | | STOFFGraphicStyle m_style; |
165 | | }; |
166 | | //! a serie in a chart |
167 | | struct Serie { |
168 | | //! the series type |
169 | | enum Type { S_Area, S_Bar, S_Bubble, S_Circle, S_Column, S_Gantt, S_Line, S_Radar, S_Ring, S_Scatter, S_Stock, S_Surface }; |
170 | | //! the point type |
171 | | enum PointType { |
172 | | P_None=0, P_Automatic, P_Square, P_Diamond, P_Arrow_Down, |
173 | | P_Arrow_Up, P_Arrow_Right, P_Arrow_Left, P_Bow_Tie, P_Hourglass, |
174 | | P_Circle, P_Star, P_X, P_Plus, P_Asterisk, |
175 | | P_Horizontal_Bar, P_Vertical_Bar |
176 | | }; |
177 | | //! constructor |
178 | | Serie(); |
179 | 0 | Serie(Serie const &)=default; |
180 | | Serie(Serie &&)=default; |
181 | | Serie &operator=(Serie const &)=default; |
182 | 0 | Serie &operator=(Serie &&)=default; |
183 | | //! destructor |
184 | | virtual ~Serie(); |
185 | | //! return true if the serie style is 1D |
186 | | bool is1DStyle() const |
187 | 0 | { |
188 | 0 | return m_type==S_Line || m_type==S_Radar || (m_type==S_Scatter && m_pointType==P_None); |
189 | 0 | } |
190 | | //! return true if the serie is valid |
191 | | bool valid() const |
192 | 0 | { |
193 | 0 | return m_ranges[0].valid(m_ranges[0]); |
194 | 0 | } |
195 | | //! add content to the propList |
196 | | void addContentTo(librevenge::RVNGPropertyList &propList) const; |
197 | | //! add style to the propList |
198 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
199 | | //! returns a string corresponding to a series type |
200 | | static std::string getSerieTypeName(Type type); |
201 | | //! operator<< |
202 | | friend std::ostream &operator<<(std::ostream &o, Serie const &series); |
203 | | //! the type |
204 | | Type m_type; |
205 | | //! the data range |
206 | | Position m_ranges[2]; |
207 | | //! use or not the secondary y axis |
208 | | bool m_useSecondaryY; |
209 | | //! the label font |
210 | | STOFFFont m_font; |
211 | | //! the label ranges if defined(unused) |
212 | | Position m_labelRanges[2]; |
213 | | //! the legend range if defined |
214 | | Position m_legendRange; |
215 | | //! the legend name if defined |
216 | | librevenge::RVNGString m_legendText; |
217 | | //! the graphic style |
218 | | STOFFGraphicStyle m_style; |
219 | | //! the point type |
220 | | PointType m_pointType; |
221 | | }; |
222 | | //! a text zone a chart |
223 | | struct TextZone { |
224 | | //! the text type |
225 | | enum Type { T_Title, T_SubTitle, T_Footer }; |
226 | | //! the text content type |
227 | | enum ContentType { C_Cell, C_Text }; |
228 | | |
229 | | //! constructor |
230 | | explicit TextZone(Type type); |
231 | | //! destructor |
232 | | ~TextZone(); |
233 | | //! returns true if the textbox is valid |
234 | | bool valid() const |
235 | 0 | { |
236 | 0 | if (!m_show) return false; |
237 | 0 | if (m_contentType==C_Cell) |
238 | 0 | return m_cell.valid(); |
239 | 0 | if (m_contentType!=C_Text) |
240 | 0 | return false; |
241 | 0 | for (auto &e : m_textEntryList) { |
242 | 0 | if (e.valid()) return true; |
243 | 0 | } |
244 | 0 | return false; |
245 | 0 | } |
246 | | //! add content to the propList |
247 | | void addContentTo(librevenge::RVNGPropertyList &propList) const; |
248 | | //! add to the propList |
249 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
250 | | //! operator<< |
251 | | friend std::ostream &operator<<(std::ostream &o, TextZone const &zone); |
252 | | //! the zone type |
253 | | Type m_type; |
254 | | //! the content type |
255 | | ContentType m_contentType; |
256 | | //! true if the zone is visible |
257 | | bool m_show; |
258 | | //! the position in the zone |
259 | | STOFFVec2f m_position; |
260 | | //! the cell position ( or title and subtitle) |
261 | | Position m_cell; |
262 | | //! the text entry (or the list of text entry) |
263 | | std::vector<STOFFEntry> m_textEntryList; |
264 | | //! the zone format |
265 | | STOFFFont m_font; |
266 | | //! the graphic style |
267 | | STOFFGraphicStyle m_style; |
268 | | }; |
269 | | |
270 | | //! the constructor |
271 | | STOFFChart(STOFFVec2f const &dim=STOFFVec2f()); |
272 | | //! the destructor |
273 | | virtual ~STOFFChart(); |
274 | | //! send the chart to the listener |
275 | | void sendChart(STOFFSpreadsheetListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface); |
276 | | //! send the zone content (called when the zone is of text type) |
277 | | virtual void sendContent(TextZone const &zone, STOFFListenerPtr &listener) const =0; |
278 | | |
279 | | //! set the grid color |
280 | | void setGridColor(STOFFColor const &color) |
281 | 0 | { |
282 | 0 | m_gridColor=color; |
283 | 0 | } |
284 | | //! return an axis (corresponding to a coord) |
285 | | Axis &getAxis(int coord); |
286 | | //! return an axis (corresponding to a coord) |
287 | | Axis const &getAxis(int coord) const; |
288 | | |
289 | | //! returns the legend |
290 | | Legend const &getLegend() const |
291 | 0 | { |
292 | 0 | return m_legend; |
293 | 0 | } |
294 | | //! returns the legend |
295 | | Legend &getLegend() |
296 | 0 | { |
297 | 0 | return m_legend; |
298 | 0 | } |
299 | | |
300 | | //! return a serie |
301 | | Serie *getSerie(int id, bool create); |
302 | | //! returns the list of defined series |
303 | | std::map<int, Serie> const &getIdSerieMap() const |
304 | 0 | { |
305 | 0 | return m_serieMap; |
306 | 0 | } |
307 | | //! returns a textzone content |
308 | | TextZone *getTextZone(TextZone::Type type, bool create=false); |
309 | | |
310 | | protected: |
311 | | //! sends a textzone content |
312 | | void sendTextZoneContent(TextZone::Type type, STOFFListenerPtr &listener) const; |
313 | | |
314 | | public: |
315 | | //! the chart dimension in point |
316 | | STOFFVec2f m_dimension; |
317 | | //! the chart type (if no series) |
318 | | Serie::Type m_type; |
319 | | //! a flag to know if the data are stacked or not |
320 | | bool m_dataStacked; |
321 | | //! a flag to know if the data are percent stacked or not |
322 | | bool m_dataPercentStacked; |
323 | | //! a flag to know if the data are vertical (for bar) |
324 | | bool m_dataVertical; |
325 | | //! a flag to know if the graphic is 3D |
326 | | bool m_is3D; |
327 | | //! a flag to know if real 3D or 2D-extended |
328 | | bool m_is3DDeep; |
329 | | |
330 | | // main |
331 | | |
332 | | //! the chart style |
333 | | STOFFGraphicStyle m_style; |
334 | | //! the chart name |
335 | | librevenge::RVNGString m_name; |
336 | | |
337 | | // plot area |
338 | | |
339 | | //! the plot area dimension in percent |
340 | | STOFFBox2f m_plotAreaPosition; |
341 | | //! the ploat area style |
342 | | STOFFGraphicStyle m_plotAreaStyle; |
343 | | |
344 | | // legend |
345 | | |
346 | | //! the legend dimension in percent |
347 | | STOFFBox2f m_legendPosition; |
348 | | |
349 | | //! floor |
350 | | STOFFGraphicStyle m_floorStyle; |
351 | | //! wall |
352 | | STOFFGraphicStyle m_wallStyle; |
353 | | |
354 | | protected: |
355 | | //! the grid color |
356 | | STOFFColor m_gridColor; |
357 | | //! the x,y,y-second,z and a bad axis |
358 | | Axis m_axis[5]; |
359 | | //! the legend |
360 | | Legend m_legend; |
361 | | //! the list of series |
362 | | std::map<int, Serie> m_serieMap; |
363 | | //! a map text zone type to text zone |
364 | | std::map<TextZone::Type, TextZone> m_textZoneMap; |
365 | | private: |
366 | | explicit STOFFChart(STOFFChart const &orig) = delete; |
367 | | STOFFChart &operator=(STOFFChart const &orig) = delete; |
368 | | }; |
369 | | |
370 | | #endif |
371 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |