| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
} |
| 44 |
|
| 45 |
class WKSChart |
| 46 |
{ |
| 47 |
friend class WKSChartInternal::SubDocument; |
| 48 |
public: |
| 49 |
|
| 50 |
struct Position |
| 51 |
{ |
| 52 |
|
| 53 |
explicit Position(Vec2i pos=Vec2i(-1,-1), librevenge::RVNGString const &sheetName="") |
| 54 |
: m_pos(pos) |
| 55 |
, m_sheetName(sheetName) |
| 56 |
, m_sheetId(-1) |
| 57 |
{ |
| 58 |
} |
| 59 |
|
| 60 |
bool valid() const |
| 61 |
{ |
| 62 |
return m_pos[0]>=0 && m_pos[1]>=0 && (!m_sheetName.empty() || m_sheetId>=0); |
| 63 |
} |
| 64 |
|
| 65 |
bool valid(Position const &maxPos) const |
| 66 |
{ |
| 67 |
return valid() && maxPos.valid() && maxPos.m_pos[0]>=m_pos[0] && maxPos.m_pos[1]>=m_pos[1]; |
| 68 |
} |
| 69 |
|
| 70 |
librevenge::RVNGString getCellName() const; |
| 71 |
|
| 72 |
friend std::ostream &operator<<(std::ostream &o, Position const &pos); |
| 73 |
|
| 74 |
bool operator==(Position const &pos) const |
| 75 |
{ |
| 76 |
return m_pos==pos.m_pos && m_sheetName==pos.m_sheetName && m_sheetId==pos.m_sheetId; |
| 77 |
} |
| 78 |
|
| 79 |
bool operator!=(Position const &pos) const |
| 80 |
{ |
| 81 |
return !(operator==(pos)); |
| 82 |
} |
| 83 |
|
| 84 |
Vec2i m_pos; |
| 85 |
|
| 86 |
librevenge::RVNGString m_sheetName; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
int m_sheetId; |
| 93 |
}; |
| 94 |
|
| 95 |
struct Axis |
| 96 |
{ |
| 97 |
|
| 98 |
enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty }; |
| 99 |
|
| 100 |
Axis(); |
| 101 |
|
| 102 |
~Axis(); |
| 103 |
|
| 104 |
void addContentTo(int coord, librevenge::RVNGPropertyList &propList) const; |
| 105 |
|
| 106 |
void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
| 107 |
|
| 108 |
friend std::ostream &operator<<(std::ostream &o, Axis const &axis); |
| 109 |
|
| 110 |
Type m_type; |
| 111 |
|
| 112 |
bool m_automaticScaling; |
| 113 |
|
| 114 |
Vec2f m_scaling; |
| 115 |
|
| 116 |
bool m_showGrid; |
| 117 |
|
| 118 |
bool m_showLabel; |
| 119 |
|
| 120 |
Position m_labelRanges[2]; |
| 121 |
|
| 122 |
|
| 123 |
bool m_showTitle; |
| 124 |
|
| 125 |
Position m_titleRange; |
| 126 |
|
| 127 |
librevenge::RVNGString m_title; |
| 128 |
|
| 129 |
librevenge::RVNGString m_subTitle; |
| 130 |
|
| 131 |
WPSGraphicStyle m_style; |
| 132 |
}; |
| 133 |
|
| 134 |
struct Legend |
| 135 |
{ |
| 136 |
|
| 137 |
Legend() |
| 138 |
: m_show(false) |
| 139 |
, m_autoPosition(true) |
| 140 |
, m_relativePosition(WPSBorder::RightBit) |
| 141 |
, m_position(0,0) |
| 142 |
, m_font() |
| 143 |
, m_style() |
| 144 |
{ |
| 145 |
} |
| 146 |
|
| 147 |
void addContentTo(librevenge::RVNGPropertyList &propList) const; |
| 148 |
|
| 149 |
void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
| 150 |
|
| 151 |
friend std::ostream &operator<<(std::ostream &o, Legend const &legend); |
| 152 |
|
| 153 |
bool m_show; |
| 154 |
|
| 155 |
bool m_autoPosition; |
| 156 |
|
| 157 |
int m_relativePosition; |
| 158 |
|
| 159 |
Vec2f m_position; |
| 160 |
|
| 161 |
WPSFont m_font; |
| 162 |
|
| 163 |
WPSGraphicStyle m_style; |
| 164 |
}; |
| 165 |
|
| 166 |
struct Serie |
| 167 |
{ |
| 168 |
|
| 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 |
|
| 171 |
enum PointType |
| 172 |
{ |
| 173 |
P_None=0, P_Automatic, P_Square, P_Diamond, P_Arrow_Down, |
| 174 |
P_Arrow_Up, P_Arrow_Right, P_Arrow_Left, P_Bow_Tie, P_Hourglass, |
| 175 |
P_Circle, P_Star, P_X, P_Plus, P_Asterisk, |
| 176 |
P_Horizontal_Bar, P_Vertical_Bar |
| 177 |
}; |
| 178 |
|
| 179 |
Serie(); |
| 180 |
Serie(Serie const &)=default; |
| 181 |
Serie(Serie &&)=default; |
| 182 |
Serie &operator=(Serie const &)=default; |
| 183 |
Serie &operator=(Serie &&)=default; |
| 184 |
|
| 185 |
virtual ~Serie(); |
| 186 |
|
| 187 |
bool is1DStyle() const |
| 188 |
{ |
| 189 |
return m_type==S_Line || m_type==S_Radar || (m_type==S_Scatter && m_pointType==P_None); |
| 190 |
} |
| 191 |
|
| 192 |
void setPrimaryColor(WPSColor const &color, float opacity = 1, bool force1D=false) |
| 193 |
{ |
| 194 |
if (force1D || is1DStyle()) |
| 195 |
m_style.m_lineColor=color; |
| 196 |
else |
| 197 |
m_style.setSurfaceColor(color, opacity); |
| 198 |
} |
| 199 |
|
| 200 |
void setPrimaryPattern(WPSGraphicStyle::Pattern const &pattern, bool force1D=false); |
| 201 |
|
| 202 |
void setSecondaryColor(WPSColor const &color) |
| 203 |
{ |
| 204 |
if (!is1DStyle()) |
| 205 |
m_style.m_lineColor=color; |
| 206 |
} |
| 207 |
|
| 208 |
bool valid() const |
| 209 |
{ |
| 210 |
return m_ranges[0].valid(m_ranges[0]); |
| 211 |
} |
| 212 |
|
| 213 |
void addContentTo(librevenge::RVNGPropertyList &propList) const; |
| 214 |
|
| 215 |
void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
| 216 |
|
| 217 |
static std::string getSerieTypeName(Type type); |
| 218 |
|
| 219 |
friend std::ostream &operator<<(std::ostream &o, Serie const &series); |
| 220 |
|
| 221 |
Type m_type; |
| 222 |
|
| 223 |
Position m_ranges[2]; |
| 224 |
|
| 225 |
bool m_useSecondaryY; |
| 226 |
|
| 227 |
WPSFont m_font; |
| 228 |
|
| 229 |
Position m_labelRanges[2]; |
| 230 |
|
| 231 |
Position m_legendRange; |
| 232 |
|
| 233 |
librevenge::RVNGString m_legendText; |
| 234 |
|
| 235 |
WPSGraphicStyle m_style; |
| 236 |
|
| 237 |
PointType m_pointType; |
| 238 |
}; |
| 239 |
|
| 240 |
struct TextZone |
| 241 |
{ |
| 242 |
|
| 243 |
enum Type { T_Title, T_SubTitle, T_Footer }; |
| 244 |
|
| 245 |
enum ContentType { C_Cell, C_Text }; |
| 246 |
|
| 247 |
|
| 248 |
explicit TextZone(Type type); |
| 249 |
TextZone(TextZone const &)=default; |
| 250 |
|
| 251 |
~TextZone(); |
| 252 |
|
| 253 |
bool valid() const |
| 254 |
{ |
| 255 |
if (!m_show) return false; |
| 256 |
if (m_contentType==C_Cell) |
| 257 |
return m_cell.valid(); |
| 258 |
if (m_contentType!=C_Text) |
| 259 |
return false; |
| 260 |
for (auto const &e : m_textEntryList) |
| 261 |
{ |
| 262 |
if (e.valid()) return true; |
| 263 |
} |
| 264 |
return false; |
| 265 |
} |
| 266 |
|
| 267 |
void addContentTo(librevenge::RVNGPropertyList &propList) const; |
| 268 |
|
| 269 |
void addStyleTo(librevenge::RVNGPropertyList &propList) const; |
| 270 |
|
| 271 |
friend std::ostream &operator<<(std::ostream &o, TextZone const &zone); |
| 272 |
|
| 273 |
Type m_type; |
| 274 |
|
| 275 |
ContentType m_contentType; |
| 276 |
|
| 277 |
bool m_show; |
| 278 |
|
| 279 |
Vec2f m_position; |
| 280 |
|
| 281 |
Position m_cell; |
| 282 |
|
| 283 |
std::vector<WPSEntry> m_textEntryList; |
| 284 |
|
| 285 |
WPSFont m_font; |
| 286 |
|
| 287 |
WPSGraphicStyle m_style; |
| 288 |
}; |
| 289 |
|
| 290 |
|
| 291 |
explicit WKSChart(Vec2f const &dim=Vec2f()); |
| 292 |
|
| 293 |
virtual ~WKSChart(); |
| 294 |
|
| 295 |
void sendChart(WKSContentListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface) const; |
| 296 |
|
| 297 |
virtual void sendContent(TextZone const &zone, WPSListenerPtr &listener) const=0; |
| 298 |
|
| 299 |
|
| 300 |
void setGridColor(WPSColor const &color) |
| 301 |
{ |
| 302 |
m_gridColor=color; |
| 303 |
} |
| 304 |
|
| 305 |
Axis &getAxis(int coord); |
| 306 |
|
| 307 |
Axis const &getAxis(int coord) const; |
| 308 |
|
| 309 |
|
| 310 |
Legend const &getLegend() const |
| 311 |
{ |
| 312 |
return m_legend; |
| 313 |
} |
| 314 |
|
| 315 |
Legend &getLegend() |
| 316 |
{ |
| 317 |
return m_legend; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
Serie *getSerie(int id, bool create); |
| 322 |
|
| 323 |
std::map<int, Serie> const &getIdSerieMap() const |
| 324 |
{ |
| 325 |
return m_serieMap; |
| 326 |
} |
| 327 |
|
| 328 |
TextZone *getTextZone(TextZone::Type type, bool create=false); |
| 329 |
|
| 330 |
protected: |
| 331 |
|
| 332 |
void sendTextZoneContent(TextZone::Type type, WPSListenerPtr listener) const; |
| 333 |
|
| 334 |
public: |
| 335 |
|
| 336 |
Vec2f m_dimension; |
| 337 |
|
| 338 |
Serie::Type m_type; |
| 339 |
|
| 340 |
bool m_dataStacked; |
| 341 |
|
| 342 |
bool m_dataPercentStacked; |
| 343 |
|
| 344 |
bool m_dataVertical; |
| 345 |
|
| 346 |
bool m_is3D; |
| 347 |
|
| 348 |
bool m_is3DDeep; |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
WPSGraphicStyle m_style; |
| 354 |
|
| 355 |
librevenge::RVNGString m_name; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
WPSBox2f m_plotAreaPosition; |
| 361 |
|
| 362 |
WPSGraphicStyle m_plotAreaStyle; |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
WPSBox2f m_legendPosition; |
| 368 |
|
| 369 |
|
| 370 |
WPSGraphicStyle m_floorStyle; |
| 371 |
|
| 372 |
WPSGraphicStyle m_wallStyle; |
| 373 |
|
| 374 |
protected: |
| 375 |
|
| 376 |
WPSColor m_gridColor; |
| 377 |
|
| 378 |
Axis m_axis[5]; |
| 379 |
|
| 380 |
Legend m_legend; |
| 381 |
|
| 382 |
std::map<int, Serie> m_serieMap; |
| 383 |
|
| 384 |
std::map<TextZone::Type, TextZone> m_textZoneMap; |
| 385 |
private: |
| 386 |
explicit WKSChart(WKSChart const &orig) = delete; |
| 387 |
WKSChart &operator=(WKSChart const &orig) = delete; |
| 388 |
}; |
| 389 |
|
| 390 |
#endif |
| 391 |
|