Skip to content

Commit 1c47e4d

Browse files
committed
Merge remote-tracking branch 'origin/main' into resolution
# Conflicts: # src/chart/main/chart.cpp
2 parents 460c234 + 130dd5d commit 1c47e4d

24 files changed

+713
-644
lines changed

src/chart/main/chart.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@ void Chart::draw(Gfx::ICanvas &canvas, bool highResolution)
103103
->setResMode(highResolution ? Draw::ResolutionMode::High
104104
: Draw::ResolutionMode::Low);
105105

106-
Draw::DrawChart{Draw::DrawingContext{canvas,
107-
layout,
108-
events,
109-
actPlot,
106+
renderedChart = Draw::RenderedChart{
107+
actPlot ? Draw::CoordinateSystem{layout.plotArea,
108+
actPlot->getOptions()->angle,
109+
actPlot->getOptions()->coordSystem,
110+
actPlot->keepAspectRatio}
111+
: Draw::CoordinateSystem{layout.plotArea},
112+
actPlot};
113+
114+
Draw::DrawChart{Draw::DrawingContext{actPlot,
115+
renderedChart,
116+
renderedChart.getCoordSys(),
110117
actPlot ? actPlot->getStyle()
111118
: stylesheet.getDefaultParams(),
112-
renderedChart}}
113-
.draw();
119+
events}}
120+
.draw(canvas, layout);
114121
}
115122

116123
Gen::PlotPtr Chart::plot(const Gen::PlotOptionsPtr &options)

src/chart/rendering/drawaxes.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
namespace Vizzu::Draw
99
{
1010

11-
DrawAxes::DrawAxes(const DrawingContext &context) :
12-
DrawingContext(context)
13-
{}
14-
15-
void DrawAxes::drawBase()
11+
void DrawAxes::drawGeometries() const
1612
{
1713
interlacing.drawGeometries();
1814

1915
drawAxis(Gen::ChannelId::x);
2016
drawAxis(Gen::ChannelId::y);
2117

22-
DrawGuides(*this);
18+
DrawGuides{{ctx()}, canvas, painter}.draw();
2319
}
2420

25-
void DrawAxes::drawLabels()
21+
void DrawAxes::drawLabels() const
2622
{
2723
interlacing.drawTexts();
2824

@@ -48,7 +44,7 @@ Geom::Line DrawAxes::getAxis(Gen::ChannelId axisIndex) const
4844
return {};
4945
}
5046

51-
void DrawAxes::drawAxis(Gen::ChannelId axisIndex)
47+
void DrawAxes::drawAxis(Gen::ChannelId axisIndex) const
5248
{
5349
auto eventTarget =
5450
Events::Targets::axis(axisIndex == Gen::ChannelId::x);
@@ -156,7 +152,7 @@ Geom::Point DrawAxes::getTitleOffset(Gen::ChannelId axisIndex,
156152
: Geom::Point{orthogonal, -parallel};
157153
}
158154

159-
void DrawAxes::drawTitle(Gen::ChannelId axisIndex)
155+
void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const
160156
{
161157
const auto &titleString = plot->commonAxises.at(axisIndex).title;
162158

@@ -234,11 +230,11 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex)
234230
auto upsideDown =
235231
realAngle > M_PI / 2.0 && realAngle < 3 * M_PI / 2.0;
236232

237-
[[maybe_unused]] const DrawLabel label(*this,
233+
DrawLabel{{ctx()}}.draw(canvas,
238234
Geom::TransformedRect{transform, Geom::Size{size}},
239235
title.value,
240236
titleStyle,
241-
rootEvents.draw.plot.axis.title,
237+
*rootEvents.draw.plot.axis.title,
242238
Events::Targets::axisTitle(title.value,
243239
axisIndex == Gen::ChannelId::x),
244240
DrawLabel::Options(false, 1.0, upsideDown));
@@ -248,7 +244,7 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex)
248244
}
249245
}
250246

251-
void DrawAxes::drawDimensionLabels(bool horizontal)
247+
void DrawAxes::drawDimensionLabels(bool horizontal) const
252248
{
253249
auto axisIndex =
254250
horizontal ? Gen::ChannelId::x : Gen::ChannelId::y;
@@ -273,7 +269,7 @@ void DrawAxes::drawDimensionLabels(bool horizontal)
273269

274270
void DrawAxes::drawDimensionLabel(bool horizontal,
275271
const Geom::Point &origo,
276-
Gen::DimensionAxis::Values::const_iterator it)
272+
Gen::DimensionAxis::Values::const_iterator it) const
277273
{
278274
const auto &enabled =
279275
horizontal ? plot->guides.x : plot->guides.y;
@@ -328,13 +324,15 @@ void DrawAxes::drawDimensionLabel(bool horizontal,
328324

329325
posDir = posDir.extend(sign);
330326

331-
OrientedLabelRenderer labelRenderer(*this);
327+
OrientedLabelRenderer labelRenderer{{ctx()},
328+
canvas,
329+
painter};
332330
auto label =
333331
labelRenderer.create(text, posDir, labelStyle, 0);
334332
labelRenderer.render(label,
335333
textColor * weight * position.weight,
336334
*labelStyle.backgroundColor,
337-
rootEvents.draw.plot.axis.label,
335+
*rootEvents.draw.plot.axis.label,
338336
Events::Targets::axisLabel(text, horizontal));
339337
});
340338
}

src/chart/rendering/drawaxes.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
namespace Vizzu::Draw
1010
{
1111

12-
class DrawAxes : private DrawingContext
12+
class DrawAxes : public DrawingContext
1313
{
1414
public:
15-
explicit DrawAxes(const DrawingContext &context);
15+
void drawGeometries() const;
16+
void drawLabels() const;
1617

17-
void drawBase();
18-
void drawLabels();
18+
Gfx::ICanvas &canvas;
19+
Painter &painter;
20+
DrawInterlacing interlacing;
1921

2022
private:
2123
[[nodiscard]] Geom::Line getAxis(Gen::ChannelId axisIndex) const;
@@ -24,14 +26,12 @@ class DrawAxes : private DrawingContext
2426
[[nodiscard]] Geom::Point getTitleOffset(Gen::ChannelId axisIndex,
2527
int index,
2628
bool fades) const;
27-
void drawAxis(Gen::ChannelId axisIndex);
28-
void drawTitle(Gen::ChannelId axisIndex);
29-
void drawDimensionLabels(bool horizontal);
29+
void drawAxis(Gen::ChannelId axisIndex) const;
30+
void drawTitle(Gen::ChannelId axisIndex) const;
31+
void drawDimensionLabels(bool horizontal) const;
3032
void drawDimensionLabel(bool horizontal,
3133
const Geom::Point &origo,
32-
Gen::DimensionAxis::Values::const_iterator it);
33-
34-
DrawInterlacing interlacing{*this};
34+
Gen::DimensionAxis::Values::const_iterator it) const;
3535
};
3636

3737
}

src/chart/rendering/drawbackground.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@
55
namespace Vizzu::Draw
66
{
77

8-
DrawBackground::DrawBackground(const DrawingContext &context,
8+
void DrawBackground::draw(Gfx::ICanvas &canvas,
99
const Geom::Rect &rect,
1010
const Styles::Box &style,
11-
const Util::EventDispatcher::event_ptr &onDraw,
12-
std::unique_ptr<Util::EventTarget> eventTarget) :
13-
DrawingContext(context)
11+
Util::EventDispatcher::Event &onDraw,
12+
std::unique_ptr<Util::EventTarget> &&eventTarget) const
1413
{
1514
Events::OnRectDrawEvent eventObj(*eventTarget, {rect, false});
1615
if (!style.borderColor->isTransparent()
1716
|| !style.backgroundColor->isTransparent()) {
1817
canvas.setBrushColor(*style.backgroundColor);
1918
canvas.setLineColor(*style.borderColor);
2019
canvas.setLineWidth(*style.borderWidth);
21-
if (onDraw->invoke(std::move(eventObj))) {
20+
if (onDraw.invoke(std::move(eventObj))) {
2221
canvas.rectangle(rect);
2322
renderedChart.emplace(
2423
Geom::TransformedRect::fromRect(rect),
2524
std::move(eventTarget));
2625
}
2726
canvas.setLineWidth(0);
2827
}
29-
else if (onDraw->invoke(std::move(eventObj))) {
28+
else if (onDraw.invoke(std::move(eventObj))) {
3029
renderedChart.emplace(Geom::TransformedRect::fromRect(rect),
3130
std::move(eventTarget));
3231
}

src/chart/rendering/drawbackground.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
namespace Vizzu::Draw
1111
{
1212

13-
class DrawBackground : public DrawingContext
13+
struct DrawBackground : DrawingContext
1414
{
15-
public:
16-
DrawBackground(const DrawingContext &context,
15+
void draw(Gfx::ICanvas &canvas,
1716
const Geom::Rect &rect,
1817
const Styles::Box &style,
19-
const Util::EventDispatcher::event_ptr &onDraw,
20-
std::unique_ptr<Util::EventTarget> eventTarget);
18+
Util::EventDispatcher::Event &onDraw,
19+
std::unique_ptr<Util::EventTarget> &&eventTarget) const;
2120
};
2221

2322
}

src/chart/rendering/drawchart.cpp

+77-35
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,54 @@
99

1010
namespace Vizzu::Draw
1111
{
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+
1245
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
1449
{
1550
getter(getOptions())
1651
.visit(
1752
[&layout = getter(layout),
1853
&style = getter(rootStyle),
19-
&event = getter(rootEvents.draw),
54+
&event = *getter(rootEvents.draw),
55+
&canvas,
2056
this](int, const auto &weighted)
2157
{
2258
if (weighted.value.has_value()) {
23-
DrawLabel(*this,
59+
DrawLabel{{ctx()}}.draw(canvas,
2460
Geom::TransformedRect::fromRect(layout),
2561
*weighted.value,
2662
style,
@@ -32,61 +68,67 @@ void DrawChart::drawHeading(const MemberGetter &&getter)
3268
});
3369
}
3470

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
3679
{
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+
3798
if (plot && rootEvents.draw.begin->invoke()) {
3899

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)));
44102

45-
DrawPlot{*this};
103+
drawPlot(canvas, painter, layout.plot);
46104

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);
55106

56-
drawHeading<&Events::Targets::chartTitle>(
107+
drawHeading<&Events::Targets::chartTitle>(canvas,
108+
layout,
57109
[](auto &obj) -> decltype((obj.title))
58110
{
59111
return (obj.title);
60112
});
61113

62-
drawHeading<&Events::Targets::chartSubtitle>(
114+
drawHeading<&Events::Targets::chartSubtitle>(canvas,
115+
layout,
63116
[](auto &obj) -> decltype((obj.subtitle))
64117
{
65118
return (obj.subtitle);
66119
});
67120

68-
drawHeading<&Events::Targets::chartCaption>(
121+
drawHeading<&Events::Targets::chartCaption>(canvas,
122+
layout,
69123
[](auto &obj) -> decltype((obj.caption))
70124
{
71125
return (obj.caption);
72126
});
73127

74-
DrawMarkerInfo(layout, canvas, *plot);
128+
drawMarkerInfo(canvas, layout.boundary);
75129
}
76130

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);
90132

91133
rootEvents.draw.complete->invoke();
92134
}

0 commit comments

Comments
 (0)