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 {
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 const &pos) const
74  {
75  return m_pos==pos.m_pos && m_sheetName==pos.m_sheetName;
76  }
78  bool operator!=(Position const &pos) const
79  {
80  return !(operator==(pos));
81  }
85  librevenge::RVNGString m_sheetName;
86  };
88  struct Axis
89  {
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);
114 
120  librevenge::RVNGString m_title;
122  librevenge::RVNGString m_subTitle;
125  };
127  struct Legend
128  {
131  : m_show(false)
132  , m_autoPosition(true)
133  , m_relativePosition(WPSBorder::RightBit)
134  , m_position(0,0)
135  , m_font()
136  , m_style()
137  {
138  }
140  void addContentTo(librevenge::RVNGPropertyList &propList) const;
142  void addStyleTo(librevenge::RVNGPropertyList &propList) const;
144  friend std::ostream &operator<<(std::ostream &o, Legend const &legend);
146  bool m_show;
157  };
159  struct Serie
160  {
165  {
170  };
172  Serie();
173  Serie(Serie const &)=default;
174  Serie(Serie &&)=default;
175  Serie &operator=(Serie const &)=default;
176  Serie &operator=(Serie &&)=default;
178  virtual ~Serie();
180  bool is1DStyle() const
181  {
183  }
185  void setPrimaryColor(WPSColor const &color, float opacity = 1, bool force1D=false)
186  {
187  if (force1D || is1DStyle())
188  m_style.m_lineColor=color;
189  else
190  m_style.setSurfaceColor(color, opacity);
191  }
193  void setPrimaryPattern(WPSGraphicStyle::Pattern const &pattern, bool force1D=false);
195  void setSecondaryColor(WPSColor const &color)
196  {
197  if (!is1DStyle())
198  m_style.m_lineColor=color;
199  }
201  bool valid() const
202  {
203  return m_ranges[0].valid(m_ranges[0]);
204  }
206  void addContentTo(librevenge::RVNGPropertyList &propList) const;
208  void addStyleTo(librevenge::RVNGPropertyList &propList) const;
210  static std::string getSerieTypeName(Type type);
212  friend std::ostream &operator<<(std::ostream &o, Serie const &series);
226  librevenge::RVNGString m_legendText;
231  };
233  struct TextZone
234  {
239 
241  explicit TextZone(Type type);
242  TextZone(TextZone const &)=default;
244  ~TextZone();
246  bool valid() const
247  {
248  if (!m_show) return false;
249  if (m_contentType==C_Cell)
250  return m_cell.valid();
251  if (m_contentType!=C_Text)
252  return false;
253  for (auto &e : m_textEntryList)
254  {
255  if (e.valid()) return true;
256  }
257  return false;
258  }
260  void addContentTo(librevenge::RVNGPropertyList &propList) const;
262  void addStyleTo(librevenge::RVNGPropertyList &propList) const;
264  friend std::ostream &operator<<(std::ostream &o, TextZone const &zone);
270  bool m_show;
276  std::vector<WPSEntry> m_textEntryList;
281  };
282 
284  explicit WKSChart(Vec2f const &dim=Vec2f());
286  virtual ~WKSChart();
288  void sendChart(WKSContentListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface) const;
290  virtual void sendContent(TextZone const &zone, WPSListenerPtr &listener) const=0;
291 
293  void setGridColor(WPSColor const &color)
294  {
295  m_gridColor=color;
296  }
298  Axis &getAxis(int coord);
300  Axis const &getAxis(int coord) const;
301 
303  Legend const &getLegend() const
304  {
305  return m_legend;
306  }
309  {
310  return m_legend;
311  }
312 
314  Serie *getSerie(int id, bool create);
316  std::map<int, Serie> const &getIdSerieMap() const
317  {
318  return m_serieMap;
319  }
321  TextZone *getTextZone(TextZone::Type type, bool create=false);
322 
323 protected:
325  void sendTextZoneContent(TextZone::Type type, WPSListenerPtr listener) const;
326 
327 public:
339  bool m_is3D;
342 
343  // main
344 
348  librevenge::RVNGString m_name;
349 
350  // plot area
351 
356 
357  // legend
358 
361 
366 
367 protected:
375  std::map<int, Serie> m_serieMap;
377  std::map<TextZone::Type, TextZone> m_textZoneMap;
378 private:
379  explicit WKSChart(WKSChart const &orig) = delete;
380  WKSChart &operator=(WKSChart const &orig) = delete;
381 };
382 
383 #endif
384 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Internal: the subdocument of a WKSChart.
Definition: WKSChart.cpp:49
a class used to store a chart associated to a spreadsheet ....
Definition: WKSChart.h:46
Vec2f m_dimension
the chart dimension in point
Definition: WKSChart.h:329
Serie::Type m_type
the chart type (if no series)
Definition: WKSChart.h:331
librevenge::RVNGString m_name
the chart name
Definition: WKSChart.h:348
bool m_dataStacked
a flag to know if the data are stacked or not
Definition: WKSChart.h:333
WKSChart & operator=(WKSChart const &orig)=delete
Legend m_legend
the legend
Definition: WKSChart.h:373
std::map< TextZone::Type, TextZone > m_textZoneMap
a map text zone type to text zone
Definition: WKSChart.h:377
std::map< int, Serie > m_serieMap
the list of series
Definition: WKSChart.h:375
WPSGraphicStyle m_style
the chart style
Definition: WKSChart.h:346
virtual void sendContent(TextZone const &zone, WPSListenerPtr &listener) const =0
send the zone content (called when the zone is of text type)
std::map< int, Serie > const & getIdSerieMap() const
returns the list of defined series
Definition: WKSChart.h:316
Legend const & getLegend() const
returns the legend
Definition: WKSChart.h:303
WPSGraphicStyle m_plotAreaStyle
the ploat area style
Definition: WKSChart.h:355
WPSBox2f m_legendPosition
the legend dimension in percent
Definition: WKSChart.h:360
void sendTextZoneContent(TextZone::Type type, WPSListenerPtr listener) const
sends a textzone content
Definition: WKSChart.cpp:176
Axis & getAxis(int coord)
return an axis (corresponding to a coord)
Definition: WKSChart.cpp:136
WKSChart(WKSChart const &orig)=delete
virtual ~WKSChart()
the destructor
Definition: WKSChart.cpp:132
Axis m_axis[5]
the x,y,y-second,z and a bad axis
Definition: WKSChart.h:371
bool m_dataPercentStacked
a flag to know if the data are percent stacked or not
Definition: WKSChart.h:335
void sendChart(WKSContentListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface) const
send the chart to the listener
Definition: WKSChart.cpp:186
bool m_is3DDeep
a flag to know if real 3D or 2D-extended
Definition: WKSChart.h:341
WKSChart(Vec2f const &dim=Vec2f())
the constructor
Definition: WKSChart.cpp:104
bool m_dataVertical
a flag to know if the data are vertical (for bar)
Definition: WKSChart.h:337
WPSGraphicStyle m_wallStyle
wall
Definition: WKSChart.h:365
void setGridColor(WPSColor const &color)
set the grid color
Definition: WKSChart.h:293
Legend & getLegend()
returns the legend
Definition: WKSChart.h:308
WPSColor m_gridColor
the grid color
Definition: WKSChart.h:369
WPSBox2f m_plotAreaPosition
the plot area dimension in percent
Definition: WKSChart.h:353
WPSGraphicStyle m_floorStyle
floor
Definition: WKSChart.h:363
bool m_is3D
a flag to know if the graphic is 3D
Definition: WKSChart.h:339
Serie * getSerie(int id, bool create)
return a serie
Definition: WKSChart.cpp:156
TextZone * getTextZone(TextZone::Type type, bool create=false)
returns a textzone content
Definition: WKSChart.cpp:166
define the font properties
Definition: WPSFont.h:37
a structure used to define a picture style
Definition: WPSGraphicStyle.h:38
void setSurfaceColor(WPSColor const &col, float opacity=1)
set the surface color
Definition: WPSGraphicStyle.h:254
WPSColor m_lineColor
the line color
Definition: WPSGraphicStyle.h:355
std::shared_ptr< WKSContentListener > WKSContentListenerPtr
shared pointer to WKSContentListener
Definition: libwps_internal.h:114
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:702
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
std::shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:105
Internal: the structures of a WKSChart.
Definition: WKSChart.cpp:45
a axis in a chart
Definition: WKSChart.h:89
librevenge::RVNGString m_title
the title label
Definition: WKSChart.h:120
bool m_showTitle
show or not the title/subtitle
Definition: WKSChart.h:116
Position m_labelRanges[2]
the label range if defined
Definition: WKSChart.h:113
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:124
void addContentTo(int coord, librevenge::RVNGPropertyList &propList) const
add content to the propList
Definition: WKSChart.cpp:398
void addStyleTo(librevenge::RVNGPropertyList &propList) const
add style to the propList
Definition: WKSChart.cpp:457
~Axis()
destructor
Definition: WKSChart.cpp:394
Vec2f m_scaling
the minimum, maximum scaling(if manual)
Definition: WKSChart.h:107
bool m_showLabel
show or not the label
Definition: WKSChart.h:111
friend std::ostream & operator<<(std::ostream &o, Axis const &axis)
operator<<
Definition: WKSChart.cpp:472
Axis()
constructor
Definition: WKSChart.cpp:379
Type m_type
the sequence type
Definition: WKSChart.h:103
bool m_showGrid
show or not the grid
Definition: WKSChart.h:109
librevenge::RVNGString m_subTitle
the subtitle label
Definition: WKSChart.h:122
Type
the axis content
Definition: WKSChart.h:91
@ A_Sequence_Skip_Empty
Definition: WKSChart.h:91
@ A_None
Definition: WKSChart.h:91
@ A_Numeric
Definition: WKSChart.h:91
@ A_Sequence
Definition: WKSChart.h:91
@ A_Logarithmic
Definition: WKSChart.h:91
bool m_automaticScaling
automatic scaling (or manual)
Definition: WKSChart.h:105
Position m_titleRange
the title cell range
Definition: WKSChart.h:118
a legend in a chart
Definition: WKSChart.h:128
int m_relativePosition
the automatic position libwps::LeftBit|...
Definition: WKSChart.h:150
Legend()
constructor
Definition: WKSChart.h:130
bool m_show
show or not the legend
Definition: WKSChart.h:146
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:156
WPSFont m_font
the font
Definition: WKSChart.h:154
friend std::ostream & operator<<(std::ostream &o, Legend const &legend)
operator<<
Definition: WKSChart.cpp:547
Vec2f m_position
the position in points
Definition: WKSChart.h:152
bool m_autoPosition
automatic position
Definition: WKSChart.h:148
void addContentTo(librevenge::RVNGPropertyList &propList) const
add content to the propList
Definition: WKSChart.cpp:517
void addStyleTo(librevenge::RVNGPropertyList &propList) const
add style to the propList
Definition: WKSChart.cpp:540
a cell position
Definition: WKSChart.h:51
bool valid(Position const &maxPos) const
return true if the position is valid
Definition: WKSChart.h:64
bool operator!=(Position const &pos) const
operator!=
Definition: WKSChart.h:78
bool operator==(Position const &pos) const
operator==
Definition: WKSChart.h:73
Position(Vec2i pos=Vec2i(-1,-1), librevenge::RVNGString const &sheetName="")
constructor
Definition: WKSChart.h:53
librevenge::RVNGString getCellName() const
return the cell name
Definition: WKSChart.cpp:354
Vec2i m_pos
the cell column and row
Definition: WKSChart.h:83
friend std::ostream & operator<<(std::ostream &o, Position const &pos)
operator<<
Definition: WKSChart.cpp:368
bool valid() const
return true if the position is valid
Definition: WKSChart.h:59
librevenge::RVNGString m_sheetName
the cell sheet name
Definition: WKSChart.h:85
a serie in a chart
Definition: WKSChart.h:160
Serie & operator=(Serie &&)=default
bool m_useSecondaryY
use or not the secondary y axis
Definition: WKSChart.h:218
bool valid() const
return true if the serie is valid
Definition: WKSChart.h:201
void addStyleTo(librevenge::RVNGPropertyList &propList) const
add style to the propList
Definition: WKSChart.cpp:683
PointType
the point type
Definition: WKSChart.h:165
@ P_Plus
Definition: WKSChart.h:168
@ P_None
Definition: WKSChart.h:166
@ P_Arrow_Up
Definition: WKSChart.h:167
@ P_Vertical_Bar
Definition: WKSChart.h:169
@ P_Arrow_Right
Definition: WKSChart.h:167
@ P_Horizontal_Bar
Definition: WKSChart.h:169
@ P_Star
Definition: WKSChart.h:168
@ P_Arrow_Down
Definition: WKSChart.h:166
@ P_Automatic
Definition: WKSChart.h:166
@ P_X
Definition: WKSChart.h:168
@ P_Square
Definition: WKSChart.h:166
@ P_Asterisk
Definition: WKSChart.h:168
@ P_Diamond
Definition: WKSChart.h:166
@ P_Hourglass
Definition: WKSChart.h:167
@ P_Circle
Definition: WKSChart.h:168
@ P_Bow_Tie
Definition: WKSChart.h:167
@ P_Arrow_Left
Definition: WKSChart.h:167
Position m_legendRange
the legend range if defined
Definition: WKSChart.h:224
librevenge::RVNGString m_legendText
the legend name if defined
Definition: WKSChart.h:226
void setPrimaryColor(WPSColor const &color, float opacity=1, bool force1D=false)
set the primary color
Definition: WKSChart.h:185
void setPrimaryPattern(WPSGraphicStyle::Pattern const &pattern, bool force1D=false)
set the primary pattern
Definition: WKSChart.cpp:707
PointType m_pointType
the point type
Definition: WKSChart.h:230
Type
the series type
Definition: WKSChart.h:162
@ S_Column
Definition: WKSChart.h:162
@ S_Circle
Definition: WKSChart.h:162
@ S_Bar
Definition: WKSChart.h:162
@ S_Area
Definition: WKSChart.h:162
@ S_Ring
Definition: WKSChart.h:162
@ S_Scatter
Definition: WKSChart.h:162
@ S_Gantt
Definition: WKSChart.h:162
@ S_Surface
Definition: WKSChart.h:162
@ S_Line
Definition: WKSChart.h:162
@ S_Stock
Definition: WKSChart.h:162
@ S_Bubble
Definition: WKSChart.h:162
@ S_Radar
Definition: WKSChart.h:162
void setSecondaryColor(WPSColor const &color)
set the secondary color
Definition: WKSChart.h:195
Serie()
constructor
Definition: WKSChart.cpp:577
static std::string getSerieTypeName(Type type)
returns a string corresponding to a series type
Definition: WKSChart.cpp:594
friend std::ostream & operator<<(std::ostream &o, Serie const &series)
operator<<
Definition: WKSChart.cpp:718
Serie(Serie const &)=default
bool is1DStyle() const
return true if the serie style is 1D
Definition: WKSChart.h:180
Position m_ranges[2]
the data range
Definition: WKSChart.h:216
Serie & operator=(Serie const &)=default
virtual ~Serie()
destructor
Definition: WKSChart.cpp:590
void addContentTo(librevenge::RVNGPropertyList &propList) const
add content to the propList
Definition: WKSChart.cpp:630
WPSFont m_font
the label font
Definition: WKSChart.h:220
Type m_type
the type
Definition: WKSChart.h:214
Serie(Serie &&)=default
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:228
Position m_labelRanges[2]
the label ranges if defined(unused)
Definition: WKSChart.h:222
a text zone a chart
Definition: WKSChart.h:234
void addStyleTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WKSChart.cpp:852
ContentType
the text content type
Definition: WKSChart.h:238
@ C_Cell
Definition: WKSChart.h:238
@ C_Text
Definition: WKSChart.h:238
WPSFont m_font
the zone format
Definition: WKSChart.h:278
bool m_show
true if the zone is visible
Definition: WKSChart.h:270
Type m_type
the zone type
Definition: WKSChart.h:266
TextZone(TextZone const &)=default
friend std::ostream & operator<<(std::ostream &o, TextZone const &zone)
operator<<
Definition: WKSChart.cpp:858
ContentType m_contentType
the content type
Definition: WKSChart.h:268
Position m_cell
the cell position ( or title and subtitle)
Definition: WKSChart.h:274
void addContentTo(librevenge::RVNGPropertyList &propList) const
add content to the propList
Definition: WKSChart.cpp:812
Type
the text type
Definition: WKSChart.h:236
@ T_Title
Definition: WKSChart.h:236
@ T_Footer
Definition: WKSChart.h:236
@ T_SubTitle
Definition: WKSChart.h:236
~TextZone()
destructor
Definition: WKSChart.cpp:808
TextZone(Type type)
constructor
Definition: WKSChart.cpp:795
WPSGraphicStyle m_style
the graphic style
Definition: WKSChart.h:280
bool valid() const
returns true if the textbox is valid
Definition: WKSChart.h:246
std::vector< WPSEntry > m_textEntryList
the text entry (or the list of text entry)
Definition: WKSChart.h:276
Vec2f m_position
the position in the zone
Definition: WKSChart.h:272
a border list
Definition: libwps_internal.h:395
the class to store a color
Definition: libwps_internal.h:281
a basic pattern used in a WPSGraphicStyle:
Definition: WPSGraphicStyle.h:89

Generated on Sat Sep 5 2020 04:52:14 for libwps by doxygen 1.9.1