WKSChart.h Source File documentation

WKSChart.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
12 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 */
21
22 /*
23 * Structure to store and construct a chart
24 *
25 */
26
27 #ifndef WKS_CHART
28 # define WKS_CHART
29
30 #include <iostream>
31 #include <vector>
32 #include <map>
33
34 #include "libwps_internal.h"
35
36 #include "WPSEntry.h"
37 #include "WPSFont.h"
38 #include "WPSGraphicStyle.h"
39
40 namespace WKSChartInternal
41 {
42 class SubDocument;
43 }
45 class WKSChart
46 {
47 friend class WKSChartInternal::SubDocument;
48 public:
50 struct Position
51 {
53 explicit Position(Vec2i pos=Vec2i(-1,-1), librevenge::RVNGString const &sheetName="")
54 : m_pos(pos)
55 , m_sheetName(sheetName)
56 {
57 }
59 bool valid() const
60 {
61 return m_pos[0]>=0 && m_pos[1]>=0 && !m_sheetName.empty();
62 }
64 bool valid(Position const &maxPos) const
65 {
66 return valid() && maxPos.valid() && maxPos.m_pos[0]>=m_pos[0] && maxPos.m_pos[1]>=m_pos[1];
67 }
69 librevenge::RVNGString getCellName() const;
71 friend std::ostream &operator<<(std::ostream &o, Position const &pos);
73 bool operator==(Position &pos) const
74 {
75 return m_pos==pos.m_pos && m_sheetName==pos.m_sheetName;
76 }
78 bool operator!=(Position &pos) const
79 {
80 return !(operator==(pos));
81 }
83 Vec2i m_pos;
85 librevenge::RVNGString m_sheetName;
86 };
88 struct Axis
89 {
91 enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty };
93 Axis();
95 ~Axis();
97 void addContentTo(int coord, librevenge::RVNGPropertyList &propList) const;
99 void addStyleTo(librevenge::RVNGPropertyList &propList) const;
101 friend std::ostream &operator<<(std::ostream &o, Axis const &axis);
103 Type m_type;
105 bool m_automaticScaling;
107 Vec2f m_scaling;
109 bool m_showGrid;
111 bool m_showLabel;
113 Position m_cellRanges[2];
115 Position m_labelRanges[2];
116
118 bool m_showTitle;
120 Position m_titleRange;
122 librevenge::RVNGString m_title;
124 librevenge::RVNGString m_subTitle;
126 WPSGraphicStyle m_style;
127 };
129 struct Legend
130 {
132 Legend()
133 : m_show(false)
134 , m_autoPosition(true)
135 , m_relativePosition(WPSBorder::RightBit)
136 , m_position(0,0)
137 , m_font()
138 , m_style()
139 {
140 }
142 void addContentTo(librevenge::RVNGPropertyList &propList) const;
144 void addStyleTo(librevenge::RVNGPropertyList &propList) const;
146 friend std::ostream &operator<<(std::ostream &o, Legend const &legend);
148 bool m_show;
150 bool m_autoPosition;
152 int m_relativePosition;
154 Vec2f m_position;
156 WPSFont m_font;
158 WPSGraphicStyle m_style;
159 };
161 struct Serie
162 {
164 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 };
166 enum PointType
167 {
168 P_None=0, P_Automatic, P_Square, P_Diamond, P_Arrow_Down,
169 P_Arrow_Up, P_Arrow_Right, P_Arrow_Left, P_Bow_Tie, P_Hourglass,
170 P_Circle, P_Star, P_X, P_Plus, P_Asterisk,
171 P_Horizontal_Bar, P_Vertical_Bar
172 };
174 Serie();
176 virtual ~Serie();
178 bool is1DStyle() const
179 {
180 return m_type==S_Line || m_type==S_Radar || (m_type==S_Scatter && m_pointType==P_None);
181 }
183 void setPrimaryColor(WPSColor const &color, float opacity = 1, bool force1D=false)
184 {
185 if (force1D || is1DStyle())
186 m_style.m_lineColor=color;
187 else
188 m_style.setSurfaceColor(color, opacity);
189 }
191 void setPrimaryPattern(WPSGraphicStyle::Pattern const &pattern, bool force1D=false);
193 void setSecondaryColor(WPSColor const &color)
194 {
195 if (!is1DStyle())
196 m_style.m_lineColor=color;
197 }
199 bool valid() const
200 {
201 return m_ranges[0].valid(m_ranges[0]);
202 }
204 void addContentTo(librevenge::RVNGPropertyList &propList) const;
206 void addStyleTo(librevenge::RVNGPropertyList &propList) const;
208 static std::string getSerieTypeName(Type type);
210 friend std::ostream &operator<<(std::ostream &o, Serie const &series);
212 Type m_type;
214 Position m_ranges[2];
216 bool m_useSecondaryY;
218 WPSFont m_font;
220 Position m_labelRanges[2];
222 Position m_legendRange;
224 librevenge::RVNGString m_legendText;
226 WPSGraphicStyle m_style;
228 PointType m_pointType;
229 };
231 struct TextZone
232 {
234 enum Type { T_Title, T_SubTitle, T_Footer };
236 enum ContentType { C_Cell, C_Text };
237
239 explicit TextZone(Type type);
241 ~TextZone();
243 bool valid() const
244 {
245 if (!m_show) return false;
246 if (m_contentType==C_Cell)
247 return m_cell.valid();
248 if (m_contentType!=C_Text)
249 return false;
250 for (auto &e : m_textEntryList)
251 {
252 if (e.valid()) return true;
253 }
254 return false;
255 }
257 void addContentTo(librevenge::RVNGPropertyList &propList) const;
259 void addStyleTo(librevenge::RVNGPropertyList &propList) const;
261 friend std::ostream &operator<<(std::ostream &o, TextZone const &zone);
263 Type m_type;
265 ContentType m_contentType;
267 bool m_show;
269 Vec2f m_position;
271 Position m_cell;
273 std::vector<WPSEntry> m_textEntryList;
275 WPSFont m_font;
277 WPSGraphicStyle m_style;
278 };
279
281 explicit WKSChart(Vec2f const &dim=Vec2f());
283 virtual ~WKSChart();
285 void sendChart(WKSContentListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface) const;
287 virtual void sendContent(TextZone const &zone, WPSListenerPtr &listener) const=0;
288
290 void setGridColor(WPSColor const &color)
291 {
292 m_gridColor=color;
293 }
295 Axis &getAxis(int coord);
297 Axis const &getAxis(int coord) const;
298
300 Legend const &getLegend() const
301 {
302 return m_legend;
303 }
305 Legend &getLegend()
306 {
307 return m_legend;
308 }
309
311 Serie *getSerie(int id, bool create);
313 std::map<int, Serie> const &getIdSerieMap() const
314 {
315 return m_serieMap;
316 }
318 TextZone *getTextZone(TextZone::Type type, bool create=false);
319
320 protected:
322 void sendTextZoneContent(TextZone::Type type, WPSListenerPtr listener) const;
323
324 public:
326 Vec2f m_dimension;
328 Serie::Type m_type;
330 bool m_dataStacked;
332 bool m_dataPercentStacked;
334 bool m_dataVertical;
336 bool m_is3D;
338 bool m_is3DDeep;
339
340 // main
341
343 WPSGraphicStyle m_style;
345 librevenge::RVNGString m_name;
346
347 // plot area
348
350 WPSBox2f m_plotAreaPosition;
352 WPSGraphicStyle m_plotAreaStyle;
353
354 // legend
355
357 WPSBox2f m_legendPosition;
358
360 WPSGraphicStyle m_floorStyle;
362 WPSGraphicStyle m_wallStyle;
363
364 protected:
366 WPSColor m_gridColor;
368 Axis m_axis[5];
370 Legend m_legend;
372 std::map<int, Serie> m_serieMap;
374 std::map<TextZone::Type, TextZone> m_textZoneMap;
375 private:
376 explicit WKSChart(WKSChart const &orig) = delete;
377 WKSChart &operator=(WKSChart const &orig) = delete;
378 };
379
380 #endif
381 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
libwps::getCellName
std::string getCellName(Vec2i const &cellPos, Vec2b const &relative)
returns the cell name corresponding to a cell&#39;s position
Definition: libwps_internal.cpp:838
WKSChart::Position
a cell position
Definition: WKSChart.h:50
WPSListenerPtr
std::shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:105
WKSChartInternal::SubDocument
Internal: the subdocument of a WKSChart.
Definition: WKSChart.cpp:48
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
WPSBorder
a border list
Definition: libwps_internal.h:394
WKSChart::Position::operator==
bool operator==(Position &pos) const
operator==
Definition: WKSChart.h:73
WKSChart
a class used to store a chart associated to a spreadsheet ....
Definition: WKSChart.h:45
WKSChart::m_serieMap
std::map< int, Serie > m_serieMap
the list of series
Definition: WKSChart.h:372
WKSChart::TextZone::m_style
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:277
WKSChart::TextZone::Type
Type
the text type
Definition: WKSChart.h:234
WKSChart::Position::m_sheetName
librevenge::RVNGString m_sheetName
the cell sheet name
Definition: WKSChart.h:85
WKSChart::TextZone::m_type
Type m_type
the zone type
Definition: WKSChart.h:263
WKSChart::m_floorStyle
WPSGraphicStyle m_floorStyle
floor
Definition: WKSChart.h:360
WKSChart::Axis::m_showTitle
bool m_showTitle
show or not the title/subtitle
Definition: WKSChart.h:118
WPSFont
define the font properties
Definition: WPSFont.h:36
WKSChart::m_name
librevenge::RVNGString m_name
the chart name
Definition: WKSChart.h:345
WKSChart::Position::Position
Position(Vec2i pos=Vec2i(-1,-1), librevenge::RVNGString const &sheetName="")
constructor
Definition: WKSChart.h:53
WKSChart::Axis::m_titleRange
Position m_titleRange
the title cell range
Definition: WKSChart.h:120
WKSChart::m_legend
Legend m_legend
the legend
Definition: WKSChart.h:370
WKSChart::Serie::m_legendRange
Position m_legendRange
the legend range if defined
Definition: WKSChart.h:222
WKSChart::Position::valid
bool valid(Position const &maxPos) const
return true if the position is valid
Definition: WKSChart.h:64
WKSChart::Legend::m_style
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:158
WKSChart::Serie::m_legendText
librevenge::RVNGString m_legendText
the legend name if defined
Definition: WKSChart.h:224
WKSChart::Axis::m_scaling
Vec2f m_scaling
the minimum, maximum scaling(if manual)
Definition: WKSChart.h:107
WKSChart::m_dataStacked
bool m_dataStacked
a flag to know if the data are stacked or not
Definition: WKSChart.h:330
WKSChart::m_wallStyle
WPSGraphicStyle m_wallStyle
wall
Definition: WKSChart.h:362
WKSChart::Serie::P_X
Definition: WKSChart.h:170
WKSChartInternal
Internal: the structures of a WKSChart.
Definition: WKSChart.cpp:44
WKSChart::getLegend
Legend & getLegend()
returns the legend
Definition: WKSChart.h:305
WKSChart::Axis::m_showGrid
bool m_showGrid
show or not the grid
Definition: WKSChart.h:109
WKSChart::m_plotAreaStyle
WPSGraphicStyle m_plotAreaStyle
the ploat area style
Definition: WKSChart.h:352
WKSChart::Serie::P_Square
Definition: WKSChart.h:168
WKSChart::Axis::m_style
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:126
WPSGraphicStyle.h
WKSChart::TextZone::m_textEntryList
std::vector< WPSEntry > m_textEntryList
the text entry (or the list of text entry)
Definition: WKSChart.h:273
WKSChart::TextZone::m_cell
Position m_cell
the cell position ( or title and subtitle)
Definition: WKSChart.h:271
WKSChart::Axis
a axis in a chart
Definition: WKSChart.h:88
WPSGraphicStyle
a structure used to define a picture style
Definition: WPSGraphicStyle.h:37
WKSChart::Legend::Legend
Legend()
constructor
Definition: WKSChart.h:132
WKSChart::Position::m_pos
Vec2i m_pos
the cell column and row
Definition: WKSChart.h:83
libwps_internal.h
WKSChart::m_style
WPSGraphicStyle m_style
the chart style
Definition: WKSChart.h:343
WKSChart::Serie::valid
bool valid() const
return true if the serie is valid
Definition: WKSChart.h:199
WKSChart::m_dimension
Vec2f m_dimension
the chart dimension in point
Definition: WKSChart.h:326
WKSChart::Serie::PointType
PointType
the point type
Definition: WKSChart.h:166
WKSChart::TextZone::m_font
WPSFont m_font
the zone format
Definition: WKSChart.h:275
WPSEntry.h
WKSChart::Legend::m_font
WPSFont m_font
the font
Definition: WKSChart.h:156
WKSChart::getIdSerieMap
std::map< int, Serie > const & getIdSerieMap() const
returns the list of defined series
Definition: WKSChart.h:313
WKSChart::Serie::m_font
WPSFont m_font
the label font
Definition: WKSChart.h:218
WKSChart::Axis::m_type
Type m_type
the sequence type
Definition: WKSChart.h:103
WPSBox2< float >
WKSChart::TextZone::m_show
bool m_show
true if the zone is visible
Definition: WKSChart.h:267
WKSChart::Legend::m_autoPosition
bool m_autoPosition
automatic position
Definition: WKSChart.h:150
WKSChart::Axis::m_subTitle
librevenge::RVNGString m_subTitle
the subtitle label
Definition: WKSChart.h:124
WKSChart::m_is3D
bool m_is3D
a flag to know if the graphic is 3D
Definition: WKSChart.h:336
WKSChart::Axis::m_title
librevenge::RVNGString m_title
the title label
Definition: WKSChart.h:122
WKSChart::Legend::m_relativePosition
int m_relativePosition
the automatic position libwps::LeftBit|...
Definition: WKSChart.h:152
WKSChart::TextZone::valid
bool valid() const
returns true if the textbox is valid
Definition: WKSChart.h:243
WKSChart::Serie::is1DStyle
bool is1DStyle() const
return true if the serie style is 1D
Definition: WKSChart.h:178
WKSChart::setGridColor
void setGridColor(WPSColor const &color)
set the grid color
Definition: WKSChart.h:290
WKSChart::TextZone::ContentType
ContentType
the text content type
Definition: WKSChart.h:236
Vec2i
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:702
WPSColor
the class to store a color
Definition: libwps_internal.h:280
WKSChart::Serie::m_useSecondaryY
bool m_useSecondaryY
use or not the secondary y axis
Definition: WKSChart.h:216
WKSChart::m_type
Serie::Type m_type
the chart type (if no series)
Definition: WKSChart.h:328
WKSChart::Legend::m_position
Vec2f m_position
the position in points
Definition: WKSChart.h:154
WKSChart::Serie::P_Hourglass
Definition: WKSChart.h:169
WKSChart::m_legendPosition
WPSBox2f m_legendPosition
the legend dimension in percent
Definition: WKSChart.h:357
WKSChart::Serie::setSecondaryColor
void setSecondaryColor(WPSColor const &color)
set the secondary color
Definition: WKSChart.h:193
WKSChart::Axis::m_automaticScaling
bool m_automaticScaling
automatic scaling (or manual)
Definition: WKSChart.h:105
WKSChart::Serie::setPrimaryColor
void setPrimaryColor(WPSColor const &color, float opacity=1, bool force1D=false)
set the primary color
Definition: WKSChart.h:183
WKSChart::m_plotAreaPosition
WPSBox2f m_plotAreaPosition
the plot area dimension in percent
Definition: WKSChart.h:350
WKSChart::m_gridColor
WPSColor m_gridColor
the grid color
Definition: WKSChart.h:366
WKSChart::Legend::m_show
bool m_show
show or not the legend
Definition: WKSChart.h:148
WKSChart::getLegend
Legend const & getLegend() const
returns the legend
Definition: WKSChart.h:300
WKSChart::TextZone::m_position
Vec2f m_position
the position in the zone
Definition: WKSChart.h:269
WKSContentListenerPtr
std::shared_ptr< WKSContentListener > WKSContentListenerPtr
shared pointer to WKSContentListener
Definition: libwps_internal.h:114
WPSFont.h
WKSChart::TextZone::m_contentType
ContentType m_contentType
the content type
Definition: WKSChart.h:265
WKSChart::Legend
a legend in a chart
Definition: WKSChart.h:129
WKSChart::m_textZoneMap
std::map< TextZone::Type, TextZone > m_textZoneMap
a map text zone type to text zone
Definition: WKSChart.h:374
Vec2< int >
WKSChart::m_dataVertical
bool m_dataVertical
a flag to know if the data are vertical (for bar)
Definition: WKSChart.h:334
WKSChart::Serie::m_style
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:226
operator<<
std::ostream & operator<<(std::ostream &o, WPSColor const &c)
Definition: libwps_internal.cpp:401
WKSChart::Serie
a serie in a chart
Definition: WKSChart.h:161
WKSChart::TextZone
a text zone a chart
Definition: WKSChart.h:231
WKSChart::m_is3DDeep
bool m_is3DDeep
a flag to know if real 3D or 2D-extended
Definition: WKSChart.h:338
WKSChart::Axis::m_showLabel
bool m_showLabel
show or not the label
Definition: WKSChart.h:111
WKSChart::Serie::Type
Type
the series type
Definition: WKSChart.h:164
WKSChart::Axis::Type
Type
the axis content
Definition: WKSChart.h:91
WKSChart::Serie::m_type
Type m_type
the type
Definition: WKSChart.h:212
WKSChart::Position::operator!=
bool operator!=(Position &pos) const
operator!=
Definition: WKSChart.h:78
WKSChart::Serie::m_pointType
PointType m_pointType
the point type
Definition: WKSChart.h:228
WKSChart::m_dataPercentStacked
bool m_dataPercentStacked
a flag to know if the data are percent stacked or not
Definition: WKSChart.h:332
WPSGraphicStyle::Pattern
a basic pattern used in a WPSGraphicStyle:
Definition: WPSGraphicStyle.h:88
WKSChart::Position::valid
bool valid() const
return true if the position is valid
Definition: WKSChart.h:59