/src/libmwaw/src/lib/MWAWChart.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 | | /* libmwaw |
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 MWAW_CHART |
40 | | # define MWAW_CHART |
41 | | |
42 | | #include <iostream> |
43 | | #include <vector> |
44 | | #include <map> |
45 | | |
46 | | #include "libmwaw_internal.hxx" |
47 | | |
48 | | #include "MWAWEntry.hxx" |
49 | | #include "MWAWFont.hxx" |
50 | | #include "MWAWGraphicStyle.hxx" |
51 | | |
52 | | namespace MWAWChartInternal |
53 | | { |
54 | | class SubDocument; |
55 | | } |
56 | | /** a class used to store a chart associated to a spreadsheet .... */ |
57 | | class MWAWChart |
58 | | { |
59 | | friend class MWAWChartInternal::SubDocument; |
60 | | public: |
61 | | //! a axis in a chart |
62 | | struct Axis { |
63 | | //! the axis content |
64 | | enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty }; |
65 | | //! constructor |
66 | | Axis(); |
67 | 572 | Axis &operator=(Axis const &)=default; |
68 | | //! destructor |
69 | | ~Axis(); |
70 | | //! add content to the propList |
71 | | void addContentTo(std::string const &sheetName, int coord, librevenge::RVNGPropertyList &propList) const; |
72 | | //! add style to the propList |
73 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
74 | | //! operator<< |
75 | | friend std::ostream &operator<<(std::ostream &o, Axis const &axis); |
76 | | //! the sequence type |
77 | | Type m_type; |
78 | | //! show or not the grid |
79 | | bool m_showGrid; |
80 | | //! show or not the label |
81 | | bool m_showLabel; |
82 | | //! the label range if defined |
83 | | MWAWBox2i m_labelRange; |
84 | | //! the graphic style |
85 | | MWAWGraphicStyle m_style; |
86 | | }; |
87 | | //! a legend in a chart |
88 | | struct Legend { |
89 | | //! constructor |
90 | | Legend() |
91 | 1.60k | : m_show(false) |
92 | 1.60k | , m_autoPosition(true) |
93 | 1.60k | , m_relativePosition(libmwaw::RightBit) |
94 | 1.60k | , m_position(0,0) |
95 | 1.60k | , m_font() |
96 | 1.60k | , m_style() |
97 | 1.60k | { |
98 | 1.60k | } |
99 | | //! add content to the propList |
100 | | void addContentTo(librevenge::RVNGPropertyList &propList) const; |
101 | | //! add style to the propList |
102 | | void addStyleTo(librevenge::RVNGPropertyList &propList, std::shared_ptr<MWAWFontConverter> fontConverter) const; |
103 | | //! operator<< |
104 | | friend std::ostream &operator<<(std::ostream &o, Legend const &legend); |
105 | | //! show or not the legend |
106 | | bool m_show; |
107 | | //! automatic position |
108 | | bool m_autoPosition; |
109 | | //! the automatic position libmwaw::LeftBit|... |
110 | | int m_relativePosition; |
111 | | //! the position in points |
112 | | MWAWVec2f m_position; |
113 | | //! the font |
114 | | MWAWFont m_font; |
115 | | //! the graphic style |
116 | | MWAWGraphicStyle m_style; |
117 | | }; |
118 | | //! a series in a chart |
119 | | struct Series { |
120 | | //! the series type |
121 | | enum Type { S_Area, S_Bar, S_Column, S_Line, S_Pie, S_Scatter, S_Stock }; |
122 | | //! constructor |
123 | | Series(); |
124 | 4.28k | Series(Series const &)=default; |
125 | | //! destructor |
126 | | virtual ~Series(); |
127 | | //! add content to the propList |
128 | | void addContentTo(std::string const &sheetName, librevenge::RVNGPropertyList &propList) const; |
129 | | //! add style to the propList |
130 | | void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
131 | | //! returns a string corresponding to a series type |
132 | | static std::string getSeriesTypeName(Type type); |
133 | | //! operator<< |
134 | | friend std::ostream &operator<<(std::ostream &o, Series const &series); |
135 | | //! the type |
136 | | Type m_type; |
137 | | //! the data range |
138 | | MWAWBox2i m_range; |
139 | | //! the graphic style |
140 | | MWAWGraphicStyle m_style; |
141 | | }; |
142 | | //! a text zone a chart |
143 | | struct TextZone { |
144 | | //! the text type |
145 | | enum Type { T_Title, T_SubTitle, T_AxisX, T_AxisY, T_AxisZ }; |
146 | | //! the text content type |
147 | | enum ContentType { C_Cell, C_Text }; |
148 | | |
149 | | //! constructor |
150 | | TextZone(); |
151 | | TextZone(TextZone const &)=default; |
152 | 370 | TextZone &operator=(TextZone const &)=default; |
153 | | //! destructor |
154 | | ~TextZone(); |
155 | | //! add content to the propList |
156 | | void addContentTo(std::string const &sheetName, librevenge::RVNGPropertyList &propList) const; |
157 | | //! add to the propList |
158 | | void addStyleTo(librevenge::RVNGPropertyList &propList, std::shared_ptr<MWAWFontConverter> fontConverter) const; |
159 | | //! operator<< |
160 | | friend std::ostream &operator<<(std::ostream &o, TextZone const &zone); |
161 | | //! the zone type |
162 | | Type m_type; |
163 | | //! the content type |
164 | | ContentType m_contentType; |
165 | | //! the position in the zone |
166 | | MWAWVec2f m_position; |
167 | | //! the cell position ( for title and subtitle ) |
168 | | MWAWVec2i m_cell; |
169 | | //! the text entry |
170 | | MWAWEntry m_textEntry; |
171 | | //! the zone format |
172 | | MWAWFont m_font; |
173 | | //! the graphic style |
174 | | MWAWGraphicStyle m_style; |
175 | | }; |
176 | | |
177 | | //! the constructor |
178 | | MWAWChart(std::string const &sheetName, MWAWFontConverterPtr const &fontConverter, MWAWVec2f const &dim=MWAWVec2f()); |
179 | | //! the destructor |
180 | | virtual ~MWAWChart(); |
181 | | //! send the chart to the listener |
182 | | void sendChart(MWAWSpreadsheetListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface); |
183 | | //! send the zone content (called when the zone is of text type) |
184 | | virtual void sendContent(TextZone const &zone, MWAWListenerPtr &listener)=0; |
185 | | |
186 | | //! sets the chart type |
187 | | void setDataType(Series::Type type, bool dataStacked) |
188 | 286 | { |
189 | 286 | m_type=type; |
190 | 286 | m_dataStacked=dataStacked; |
191 | 286 | } |
192 | | |
193 | | //! return the chart dimension |
194 | | MWAWVec2f const &getDimension() const |
195 | 0 | { |
196 | 0 | return m_dim; |
197 | 0 | } |
198 | | //! return the chart dimension |
199 | | void setDimension(MWAWVec2f const &dim) |
200 | 256 | { |
201 | 256 | m_dim=dim; |
202 | 256 | } |
203 | | //! adds an axis (corresponding to a coord) |
204 | | void add(int coord, Axis const &axis); |
205 | | //! return an axis (corresponding to a coord) |
206 | | Axis const &getAxis(int coord) const; |
207 | | |
208 | | //! set the legend |
209 | | void set(Legend const &legend) |
210 | 286 | { |
211 | 286 | m_legend=legend; |
212 | 286 | } |
213 | | //! return the legend |
214 | | Legend const &getLegend() const |
215 | 0 | { |
216 | 0 | return m_legend; |
217 | 0 | } |
218 | | |
219 | | //! adds a series |
220 | | void add(Series const &series); |
221 | | //! return the list of series |
222 | | std::vector<Series> const &getSeries() const |
223 | 0 | { |
224 | 0 | return m_seriesList; |
225 | 0 | } |
226 | | |
227 | | //! adds a textzone |
228 | | void add(TextZone const &textZone); |
229 | | //! returns a textzone content(if set) |
230 | | bool getTextZone(TextZone::Type type, TextZone &textZone); |
231 | | |
232 | | protected: |
233 | | //! sends a textzone content |
234 | | void sendTextZoneContent(TextZone::Type type, MWAWListenerPtr &listener); |
235 | | |
236 | | protected: |
237 | | //! the sheet name |
238 | | std::string m_sheetName; |
239 | | //! the chart dimension in point |
240 | | MWAWVec2f m_dim; |
241 | | //! the chart type (if no series) |
242 | | Series::Type m_type; |
243 | | //! a flag to know if the data are stacked or not |
244 | | bool m_dataStacked; |
245 | | //! the x,y,z and a bad axis |
246 | | Axis m_axis[4]; |
247 | | //! the legend |
248 | | Legend m_legend; |
249 | | //! the list of series |
250 | | std::vector<Series> m_seriesList; |
251 | | //! a map text zone type to text zone |
252 | | std::map<TextZone::Type, TextZone> m_textZoneMap; |
253 | | //! the font converter |
254 | | MWAWFontConverterPtr m_fontConverter; |
255 | | private: |
256 | | explicit MWAWChart(MWAWChart const &orig) = delete; |
257 | | MWAWChart &operator=(MWAWChart const &orig) = delete; |
258 | | }; |
259 | | |
260 | | #endif |
261 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |