9
9
10
10
namespace Vizzu ::Draw
11
11
{
12
+ void DrawChart::drawBackground (Gfx::ICanvas &canvas,
13
+ const Geom::Rect &bounds) const
14
+ {
15
+ DrawBackground{{ctx ()}}.draw (canvas,
16
+ bounds,
17
+ rootStyle,
18
+ *rootEvents.draw .background ,
19
+ Events::Targets::root ());
20
+ }
21
+
22
+ void DrawChart::drawPlot (Gfx::ICanvas &canvas,
23
+ Painter &painter,
24
+ const Geom::Rect &plotRect) const
25
+ {
26
+ DrawPlot{{ctx ()}}.draw (canvas, painter, plotRect);
27
+ }
28
+
29
+ void DrawChart::drawLegend (Gfx::ICanvas &canvas,
30
+ const Geom::Rect &bounds) const
31
+ {
32
+ auto &&legendObj = DrawLegend{{ctx ()}};
33
+
34
+ getOptions ().legend .visit (
35
+ [&legendObj, &canvas, &bounds](int , const auto &legend)
36
+ {
37
+ if (legend.value )
38
+ legendObj.draw (canvas,
39
+ bounds,
40
+ Gen::Options::toChannel (*legend.value ),
41
+ legend.weight );
42
+ });
43
+ }
44
+
12
45
template <auto targetGetter, class MemberGetter >
13
- void DrawChart::drawHeading (const MemberGetter &&getter)
46
+ void DrawChart::drawHeading (Gfx::ICanvas &canvas,
47
+ const Layout &layout,
48
+ const MemberGetter &&getter) const
14
49
{
15
50
getter (getOptions ())
16
51
.visit (
17
52
[&layout = getter (layout),
18
53
&style = getter (rootStyle),
19
- &event = getter (rootEvents.draw ),
54
+ &event = *getter (rootEvents.draw ),
55
+ &canvas,
20
56
this ](int , const auto &weighted)
21
57
{
22
58
if (weighted.value .has_value ()) {
23
- DrawLabel (* this ,
59
+ DrawLabel{{ ctx ()}}. draw (canvas ,
24
60
Geom::TransformedRect::fromRect (layout),
25
61
*weighted.value ,
26
62
style,
@@ -32,61 +68,67 @@ void DrawChart::drawHeading(const MemberGetter &&getter)
32
68
});
33
69
}
34
70
35
- void DrawChart::draw ()
71
+ void DrawChart::drawMarkerInfo (Gfx::ICanvas &canvas,
72
+ const Geom::Rect &bounds) const
73
+ {
74
+ DrawMarkerInfo{{ctx ()}, rootStyle.tooltip }.draw (canvas, bounds);
75
+ }
76
+
77
+ void DrawChart::drawLogo (Gfx::ICanvas &canvas,
78
+ const Geom::Rect &bounds) const
36
79
{
80
+ if (auto logoElement = Events::Targets::logo ();
81
+ rootEvents.draw .logo ->invoke (
82
+ Events::OnRectDrawEvent (*logoElement, {bounds, false }))) {
83
+
84
+ Logo (canvas).draw (bounds.pos ,
85
+ bounds.width (),
86
+ *rootStyle.logo .filter );
87
+
88
+ renderedChart.emplace (Geom::TransformedRect::fromRect (bounds),
89
+ std::move (logoElement));
90
+ }
91
+ }
92
+
93
+ void DrawChart::draw (Gfx::ICanvas &canvas, const Layout &layout) const
94
+ {
95
+ Painter &painter = *static_cast <Painter *>(canvas.getPainter ());
96
+ painter.setCoordSys (coordSys);
97
+
37
98
if (plot && rootEvents.draw .begin ->invoke ()) {
38
99
39
- DrawBackground (*this ,
40
- layout.boundary .outline (Geom::Size::Square (1 )),
41
- rootStyle,
42
- rootEvents.draw .background ,
43
- Events::Targets::root ());
100
+ drawBackground (canvas,
101
+ layout.boundary .outline (Geom::Size::Square (1 )));
44
102
45
- DrawPlot{* this } ;
103
+ drawPlot (canvas, painter, layout. plot ) ;
46
104
47
- getOptions ().legend .visit (
48
- [this ](int , const auto &legend)
49
- {
50
- if (legend.value )
51
- DrawLegend (*this ,
52
- Gen::Options::toChannel (*legend.value ),
53
- legend.weight );
54
- });
105
+ drawLegend (canvas, layout.legend );
55
106
56
- drawHeading<&Events::Targets::chartTitle>(
107
+ drawHeading<&Events::Targets::chartTitle>(canvas,
108
+ layout,
57
109
[](auto &obj) -> decltype ((obj.title ))
58
110
{
59
111
return (obj.title );
60
112
});
61
113
62
- drawHeading<&Events::Targets::chartSubtitle>(
114
+ drawHeading<&Events::Targets::chartSubtitle>(canvas,
115
+ layout,
63
116
[](auto &obj) -> decltype ((obj.subtitle ))
64
117
{
65
118
return (obj.subtitle );
66
119
});
67
120
68
- drawHeading<&Events::Targets::chartCaption>(
121
+ drawHeading<&Events::Targets::chartCaption>(canvas,
122
+ layout,
69
123
[](auto &obj) -> decltype ((obj.caption ))
70
124
{
71
125
return (obj.caption );
72
126
});
73
127
74
- DrawMarkerInfo (layout, canvas, *plot );
128
+ drawMarkerInfo ( canvas, layout. boundary );
75
129
}
76
130
77
- if (auto logoElement = Events::Targets::logo ();
78
- rootEvents.draw .logo ->invoke (
79
- Events::OnRectDrawEvent (*logoElement,
80
- {layout.logo , false }))) {
81
-
82
- Logo (canvas).draw (layout.logo .pos ,
83
- layout.logo .width (),
84
- *rootStyle.logo .filter );
85
-
86
- renderedChart.emplace (
87
- Geom::TransformedRect::fromRect (layout.logo ),
88
- std::move (logoElement));
89
- }
131
+ drawLogo (canvas, layout.logo );
90
132
91
133
rootEvents.draw .complete ->invoke ();
92
134
}
0 commit comments