-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathevents.h
478 lines (411 loc) · 10.4 KB
/
events.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#ifndef EVENTS_H
#define EVENTS_H
#include <optional>
#include "base/anim/control.h"
#include "base/conv/auto_json.h"
#include "base/geom/line.h"
#include "base/geom/transformedrect.h"
#include "base/text/smartstring.h"
#include "base/util/eventdispatcher.h"
#include "chart/generator/marker.h"
#include "chart/options/channel.h"
#include "chart/rendering/renderedchart.h"
namespace Vizzu
{
class Events
{
public:
explicit Events(Util::EventDispatcher &ed);
struct OnUpdateDetail
{
::Anim::Duration position;
[[maybe_unused]] double progress{};
};
struct OnUpdateEvent :
public Util::EventDispatcher::Params,
public OnUpdateDetail
{
explicit OnUpdateEvent(const ::Anim::Control &control) :
OnUpdateDetail{control.getPosition(),
control.getProgress()}
{}
void appendToJSON(Conv::JSON &json) const override
{
json.any<OnUpdateDetail>(*this);
}
};
using OnDrawEvent = Util::EventDispatcher::Params;
struct OnRectDrawEvent : public OnDrawEvent
{
Draw::Rect rect;
OnRectDrawEvent(const Util::EventTarget &target,
const Draw::Rect &rect) :
OnDrawEvent(&target),
rect(rect)
{}
void appendToJSON(Conv::JSON &json) const override
{
json.any(rect);
}
};
struct OnLineDrawEvent : public OnDrawEvent
{
Draw::Line line;
OnLineDrawEvent(const Util::EventTarget &target,
const Draw::Line &line) :
OnDrawEvent(&target),
line(line)
{}
void appendToJSON(Conv::JSON &json) const override
{
json.any(line);
}
};
struct OnTextDrawDetail
{
Geom::TransformedRect outerRect;
[[maybe_unused]] Geom::Rect innerRect;
[[maybe_unused]] double align{};
std::string_view text;
};
struct OnTextDrawEvent :
public OnDrawEvent,
public OnTextDrawDetail
{
template <class... Ts>
explicit OnTextDrawEvent(const Util::EventTarget &target,
Ts &&...ts) :
OnDrawEvent(&target),
OnTextDrawDetail{std::forward<Ts>(ts)...}
{}
void appendToJSON(Conv::JSON &json) const override
{
json.any<OnTextDrawDetail>(*this);
}
};
struct DrawEvents
{
Util::EventDispatcher::event_ptr begin;
Util::EventDispatcher::event_ptr background;
Util::EventDispatcher::event_ptr title;
Util::EventDispatcher::event_ptr subtitle;
Util::EventDispatcher::event_ptr caption;
Util::EventDispatcher::event_ptr logo;
struct Legend
{
Util::EventDispatcher::event_ptr background;
Util::EventDispatcher::event_ptr title;
Util::EventDispatcher::event_ptr label;
Util::EventDispatcher::event_ptr marker;
Util::EventDispatcher::event_ptr bar;
} legend;
struct Plot
{
Util::EventDispatcher::event_ptr background;
Util::EventDispatcher::event_ptr area;
struct Marker
{
Util::EventDispatcher::event_ptr base;
Util::EventDispatcher::event_ptr label;
Util::EventDispatcher::event_ptr guide;
} marker;
struct Axis
{
Util::EventDispatcher::event_ptr base;
Util::EventDispatcher::event_ptr title;
Util::EventDispatcher::event_ptr label;
Util::EventDispatcher::event_ptr tick;
Util::EventDispatcher::event_ptr guide;
Util::EventDispatcher::event_ptr interlacing;
} axis;
} plot;
Util::EventDispatcher::event_ptr complete;
} draw;
struct Animation
{
Util::EventDispatcher::event_ptr begin;
Util::EventDispatcher::event_ptr update;
Util::EventDispatcher::event_ptr complete;
} animation;
struct Targets
{
struct Element : Util::EventTarget
{
std::string tagName;
explicit Element(std::string &&name) :
tagName(std::move(name))
{}
[[nodiscard]] std::string toJSON() const final
{
std::string res;
appendToJSON(Conv::JSONObj{res});
return res;
}
virtual void appendToJSON(Conv::JSONObj &&jsonObj) const
{
std::move(jsonObj)("tagName", tagName);
}
};
template <typename Parent> struct ParentHolder
{
Parent parent;
};
template <typename Parent>
struct ChildOf : ParentHolder<Parent>, Element
{
template <typename... Args>
explicit ChildOf(const std::string &name,
Args &&...args) :
ParentHolder<Parent>{
Parent{std::forward<Args>(args)...}},
Element(this->parent.tagName + "-" + name)
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
Element::appendToJSON(
std::move(jsonObj)("parent", this->parent));
}
};
template <class Base> struct Text : Base
{
std::string text;
template <typename... Args>
explicit Text(std::string text, Args &&...args) :
Base(std::forward<Args>(args)...),
text(std::move(text))
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
Base::appendToJSON(std::move(jsonObj)("value", text));
}
};
struct LegendProperties
{
Gen::LegendId channel;
double scrollTop{};
double scrollHeight{};
};
struct Legend : Element
{
LegendProperties properties;
explicit Legend(const LegendProperties &properties) :
Element("legend"),
properties(properties)
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
Element::appendToJSON(
std::move(jsonObj.mergeObj(properties)));
}
};
struct Axis : Element
{
Gen::AxisId axis;
explicit Axis(Gen::AxisId axis) :
Element("plot-axis"),
axis(axis)
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
Element::appendToJSON(std::move(jsonObj)("id", axis));
}
};
struct Marker : Element
{
const Gen::Marker ▮
struct DataPosition
{
Geom::Point top;
Geom::Point center;
} position;
explicit Marker(const Gen::Marker &marker,
const DataPosition &position) :
Element("plot-marker"),
marker(marker),
position(position)
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
Element::appendToJSON(marker.appendToJSON(
std::move(jsonObj))("position", position));
}
};
using LegendChild = ChildOf<Legend>;
using AxisChild = ChildOf<Axis>;
using MarkerChild = ChildOf<Marker>;
struct MarkerGuide : MarkerChild
{
Gen::AxisId axis;
MarkerGuide(const Gen::Marker &marker,
const Marker::DataPosition &position,
Gen::AxisId axis) :
MarkerChild("guide", marker, position),
axis(axis)
{}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
MarkerChild::appendToJSON(
std::move(jsonObj)("id", axis));
}
};
template <class Base> struct CategoryInfo : Base
{
std::string info;
template <class... Args>
explicit CategoryInfo(
const std::string_view &categoryName,
const std::string_view &categoryValue,
Args &&...args) :
Base(std::forward<Args>(args)...)
{
Conv::JSONObj{info}.template operator()<false>(
categoryName,
categoryValue);
}
void appendToJSON(Conv::JSONObj &&jsonObj) const override
{
jsonObj.raw("categories", info);
Base::appendToJSON(std::move(jsonObj));
}
};
static auto axis(Gen::AxisId axis)
{
return std::make_unique<Axis>(axis);
}
static auto legend(const LegendProperties &properties)
{
return std::make_unique<Legend>(properties);
}
static auto marker(const Gen::Marker &marker,
const Marker::DataPosition &position)
{
return std::make_unique<Marker>(marker, position);
}
static auto markerGuide(const Gen::Marker &marker,
const Marker::DataPosition &position,
Gen::AxisId axis)
{
return std::make_unique<MarkerGuide>(marker,
position,
axis);
}
static auto root()
{
return std::make_unique<Element>("root");
}
static auto plot()
{
return std::make_unique<Element>("plot");
}
static auto area()
{
return std::make_unique<Element>("plot-area");
}
static auto logo()
{
return std::make_unique<Element>("logo");
}
static auto chartTitle(const std::string &title)
{
return std::make_unique<Text<Element>>(title, "title");
}
static auto chartSubtitle(const std::string &subtitle)
{
return std::make_unique<Text<Element>>(subtitle,
"subtitle");
}
static auto chartCaption(const std::string &caption)
{
return std::make_unique<Text<Element>>(caption,
"caption");
}
static auto markerLabel(const std::string &label,
const Gen::Marker &marker,
const Marker::DataPosition &position)
{
return std::make_unique<Text<MarkerChild>>(label,
"label",
marker,
position);
}
static auto dimLegendLabel(
const std::string_view &categoryName,
const std::string &categoryValue,
const LegendProperties &properties)
{
return std::make_unique<CategoryInfo<Text<LegendChild>>>(
categoryName,
categoryValue,
categoryValue,
"label",
properties);
}
static auto measLegendLabel(const std::string &label,
const LegendProperties &properties)
{
return std::make_unique<Text<LegendChild>>(label,
"label",
properties);
}
static auto legendTitle(const std::string &title,
const LegendProperties &properties)
{
return std::make_unique<Text<LegendChild>>(title,
"title",
properties);
}
static auto legendMarker(const std::string_view &categoryName,
const std::string_view &categoryValue,
const LegendProperties &properties)
{
return std::make_unique<CategoryInfo<LegendChild>>(
categoryName,
categoryValue,
"marker",
properties);
}
static auto legendBar(const LegendProperties &properties)
{
return std::make_unique<LegendChild>("bar", properties);
}
static auto dimAxisLabel(const std::string_view &categoryName,
const std::string &categoryValue,
Gen::AxisId axis)
{
return std::make_unique<CategoryInfo<Text<AxisChild>>>(
categoryName,
categoryValue,
categoryValue,
"label",
axis);
}
static auto measAxisLabel(const std::string &label,
Gen::AxisId axis)
{
return std::make_unique<Text<AxisChild>>(label,
"label",
axis);
}
static auto axisTitle(const std::string &title,
Gen::AxisId axis)
{
return std::make_unique<Text<AxisChild>>(title,
"title",
axis);
}
static auto axisGuide(Gen::AxisId axis)
{
return std::make_unique<AxisChild>("guide", axis);
}
static auto axisTick(Gen::AxisId axis)
{
return std::make_unique<AxisChild>("tick", axis);
}
static auto axisInterlacing(Gen::AxisId axis)
{
return std::make_unique<AxisChild>("interlacing", axis);
}
};
};
}
#endif