SimpleXlsx  r0.19
 All Classes Namespaces Functions Variables Enumerations Pages
Chartsheet.h
1 #ifndef __CHARTSHEET_H__
2 #define __CHARTSHEET_H__
3 
4 namespace xmlw {
5  class XmlStream;
6 }
7 
8 // ****************************************************************************
13 // ****************************************************************************
14 namespace SimpleXlsx {
15 
16 class CWorksheet;
17 
18 // ****************************************************************************
23 // ****************************************************************************
24 class CChartsheet {
25 public:
27  enum EPosition {
28  POS_NONE = 0,
29  POS_LEFT,
30  POS_RIGHT,
31  POS_TOP,
32  POS_BOTTOM,
33  POS_LEFT_ASIDE,
34  POS_RIGHT_ASIDE,
35  POS_TOP_ASIDE,
36  POS_BOTTOM_ASIDE
37  };
38 
40  enum EGridLines {
41  GRID_NONE = 0,
42  GRID_MAJOR,
43  GRID_MINOR,
44  GRID_MAJOR_N_MINOR
45  };
46 
48  enum ETableData {
49  TBL_DATA_NONE = 0,
50  TBL_DATA,
51  TBL_DATA_N_KEYS
52  };
53 
55  enum EAxisCross {
56  CROSS_AUTO_ZERO = 0,
57  CROSS_MIN,
58  CROSS_MAX
59  };
60 
63  BAR_DIR_VERTICAL = 0,
64  BAR_DIR_HORIZONTAL
65  };
66 
68  enum EBarGrouping {
69  BAR_GROUP_CLUSTERED = 0,
70  BAR_GROUP_STACKED,
71  BAR_GROUP_PERCENT_STACKED
72  };
73 
76  SCATTER_FILL = 0,
77  SCATTER_POINT
78  };
79 
83  struct Series {
90 
91  _tstring title;
92  bool isMarked;
93  bool isSmoothed;
94  bool isDashed;
95 
96  Series() {
97  catSheet = NULL;
98  valSheet = NULL;
99 
100  title = _T("");
101  isMarked = false;
102  isSmoothed = false;
103  isDashed = false;
104  }
105  };
106 
107 private:
110  struct Axis {
111  uint32_t id;
112  _tstring name;
113  uint32_t nameSize;
118  _tstring minValue;
119  _tstring maxValue;
122  int lblAngle;
123 
124  Axis() {
125  id = 0;
126  name = _T("");
127  nameSize = 10;
128  pos = POS_LEFT;
129  gridLines = GRID_NONE;
130  cross = CROSS_AUTO_ZERO;
131  sourceLinked = false;
132 
133  minValue = _T("");
134  maxValue = _T("");
135 
136  lblSkipInterval = -1; // auto
137  markSkipInterval = -1; // auto
138  lblAngle = -1; // none
139  }
140  };
141 
143  struct Diagramm {
144  _tstring name;
145  uint32_t nameSize;
150 
151  EBarDirection barDir;
152  EBarGrouping barGroup;
153  EScatterStyle scatterStyle;
154 
155  Diagramm() {
156  name = _T("");
157  nameSize = 18;
158  legend_pos = POS_RIGHT;
159  tableData = TBL_DATA_NONE;
160  typeMain = CHART_LINEAR;
161  typeAdditional = CHART_NONE;
162 
163  barDir = BAR_DIR_VERTICAL;
164  barGroup = BAR_GROUP_CLUSTERED;
165  scatterStyle = SCATTER_FILL;
166  }
167  };
168 
169 private:
170  _tofstream *m_f;
171  xmlw::XmlStream *m_xmlStream;
172  int32_t m_index;
173  _tstring m_temp_path;
174  _tstring m_title;
175  bool m_isOk;
176 
177  std::vector<Series> m_seriesSet;
178  std::vector<Series> m_seriesSetAdd;
184 
185 public:
186  // @section Constructors / destructor
187  CChartsheet();
188  CChartsheet(uint32_t index, const _tstring& temp_path);
189  CChartsheet(uint32_t index, EChartTypes type, const _tstring& temp_path);
190  virtual ~CChartsheet();
191 
192  // @section Interclasses internal interface methods
193  int32_t GetIndex() const { return m_index; }
194 
195  // @section User interface
196  _tstring GetTitle() const { return m_title; }
197  void SetTitle(const _tstring& title) { m_title = title.length() > 31 ? title.substr(0, 31) : title; }
198 
199  EChartTypes GetMainType() const { return m_diagramm.typeMain; }
200  void SetMainType(EChartTypes type) { m_diagramm.typeMain = type; }
201 
202  EChartTypes GetAddType() const { return m_diagramm.typeAdditional; }
203  void SetAddType(EChartTypes type) { m_diagramm.typeAdditional = type; }
204 
205  void SetDiagrammNameSize(uint32_t size) { m_diagramm.nameSize = size; }
206  void SetDiagrammName(const _tstring& name) { m_diagramm.name = name; }
207  void SetTableDataState(ETableData state) { m_diagramm.tableData = state; }
208  void SetLegendPos(EPosition pos) { m_diagramm.legend_pos = pos; }
209 
210  void SetBarDirection(EBarDirection barDir) { m_diagramm.barDir = barDir; }
211  void SetBarGrouping(EBarGrouping barGroup) { m_diagramm.barGroup = barGroup; }
212  void SetScatterStyle(EScatterStyle style) { m_diagramm.scatterStyle = style; }
213 
214  void SetXAxisLblInterval(int value) { m_xAxis.lblSkipInterval = value; }
215  void SetXAxisMarkInterval(int value) { m_xAxis.markSkipInterval = value; }
216  void SetXAxisLblAngle(int degrees) { m_xAxis.lblAngle = degrees; }
217  void SetXAxisMin(const _tstring& value) { m_xAxis.minValue = value; }
218  void SetXAxisMax(const _tstring& value) { m_xAxis.maxValue = value; }
219  void SetYAxisMin(const _tstring& value) { m_yAxis.minValue = value; }
220  void SetYAxisMax(const _tstring& value) { m_yAxis.maxValue = value; }
221  void SetXAxisNameSize(uint32_t size) { m_xAxis.nameSize = size; }
222  void SetYAxisNameSize(uint32_t size) { m_yAxis.nameSize = size; }
223  void SetXAxisName(const _tstring& name) { m_xAxis.name = name; }
224  void SetYAxisName(const _tstring& name) { m_yAxis.name = name; }
225  void SetXAxisPos(EPosition pos) { m_xAxis.pos = pos; }
226  void SetYAxisPos(EPosition pos) { m_yAxis.pos = pos; }
227  void SetXAxisGrid(EGridLines state) { m_xAxis.gridLines = state; }
228  void SetYAxisGrid(EGridLines state) { m_yAxis.gridLines = state; }
229  void SetXAxisCross(EAxisCross cross) { m_xAxis.cross = cross; }
230  void SetYAxisCross(EAxisCross cross) { m_yAxis.cross = cross; }
231 
232  void SetX2AxisLblInterval(int value) { m_x2Axis.lblSkipInterval = value; }
233  void SetX2AxisMarkInterval(int value) { m_x2Axis.markSkipInterval = value; }
234  void SetX2AxisLblAngle(int degrees) { m_x2Axis.lblAngle = degrees; }
235  void SetX2AxisMin(const _tstring& value) { m_x2Axis.minValue = value; }
236  void SetX2AxisMax(const _tstring& value) { m_x2Axis.maxValue = value; }
237  void SetY2AxisMin(const _tstring& value) { m_y2Axis.minValue = value; }
238  void SetY2AxisMax(const _tstring& value) { m_y2Axis.maxValue = value; }
239  void SetX2AxisNameSize(uint32_t size) { m_x2Axis.nameSize = size; }
240  void SetY2AxisNameSize(uint32_t size) { m_y2Axis.nameSize = size; }
241  void SetX2AxisName(const _tstring& name) { m_x2Axis.name = name; }
242  void SetY2AxisName(const _tstring& name) { m_y2Axis.name = name; }
243  void SetX2AxisPos(EPosition pos) { m_x2Axis.pos = pos; }
244  void SetY2AxisPos(EPosition pos) { m_y2Axis.pos = pos; }
245  void SetX2AxisGrid(EGridLines state) { m_x2Axis.gridLines = state; }
246  void SetY2AxisGrid(EGridLines state) { m_y2Axis.gridLines = state; }
247  void SetX2AxisCross(EAxisCross cross) { m_x2Axis.cross = cross; }
248  void SetY2AxisCross(EAxisCross cross) { m_y2Axis.cross = cross; }
249 
250  bool AddSeries(const Series& series, bool mainChart = true);
251  bool Save();
252  bool IsOk() const { return m_isOk; }
253 
254 private:
255  void Init(uint32_t index, EChartTypes type);
256 
257  void AddTitle(const TCHAR* name, uint32_t size, bool vertPos);
258  void AddTableData();
259  void AddLegend();
260  void AddXAxis(const Axis& x, uint32_t crossAxisId = 0);
261  void AddYAxis(const Axis& y, uint32_t crossAxisId = 0);
262 
263  void AddLineChart(Axis& xAxis, uint32_t yAxisId, const std::vector<Series>& series, uint32_t firstSeriesId);
264  void AddBarChart(Axis& xAxis, uint32_t yAxisId, const std::vector<Series>& series, uint32_t firstSeriesId, EBarDirection barDir, EBarGrouping barGroup);
265  void AddScatterChart(uint32_t xAxisId, uint32_t yAxisId, const std::vector<Series>& series, uint32_t firstSeriesId, EScatterStyle style);
266 };
267 
268 } // namespace SimpleXlsx
269 
270 #endif // __CHARTSHEET_H__