Skip to content

Commit c87327e

Browse files
committed
- Implement drawStraightLine straightFactor (vertical polar lines are curves).
- Remove duplicated circles on line-circle transition - Fix area - circle polar transition. - This commit broke the line-rectangle polar connection linearity.
1 parent f9b5680 commit c87327e

File tree

12 files changed

+123
-60
lines changed

12 files changed

+123
-60
lines changed

src/base/anim/interpolated.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ template <typename Type> class Interpolated
132132
return values[has_second && static_cast<bool>(index)];
133133
}
134134

135+
[[nodiscard]] std::optional<InterpolateIndex> get_index(
136+
const Type &type) const
137+
{
138+
if (values[0].value == type) return first;
139+
if (has_second && values[1].value == type) return second;
140+
return {};
141+
}
142+
135143
template <class T>
136144
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
137145
[[nodiscard]] auto get(T &&) const = delete;

src/chart/generator/plotbuilder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ PlotBuilder::sortedBuckets(const Buckets &buckets, bool main) const
184184

185185
void PlotBuilder::addSpecLayout(Buckets &buckets)
186186
{
187-
auto geometry = plot->getOptions()
188-
->geometry.get_or_first(::Anim::first)
189-
.value;
187+
auto geometry = plot->getOptions()->geometry.values[0].value;
190188
if (auto &markers = plot->markers; isConnecting(geometry)) {
191189
Charts::TableChart::setupVector(markers, true);
192190
}

src/chart/main/style.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ struct Font
106106
[[nodiscard]] std::string calculatedFamily() const
107107
{
108108
if (fontFamily.has_value())
109-
if (auto &&ff =
110-
fontFamily->get_or_first(::Anim::first).value;
111-
!ff.empty())
109+
if (auto &&ff = fontFamily->values[0].value; !ff.empty())
112110
return ff;
113111

114112
if (fontParent) return fontParent->calculatedFamily();

src/chart/rendering/colorbuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ColorBuilder::ColorBuilder(const LightnessRange &lightnessRange,
2424
Gfx::Color ColorBuilder::render(
2525
const Anim::Interpolated<Gen::ColorBase> &colorBase) const
2626
{
27-
if (!colorBase.get_or_first(::Anim::first).value.isDiscrete()
27+
if (!colorBase.values[0].value.isDiscrete()
2828
&& !colorBase.get_or_first(::Anim::second)
2929
.value.isDiscrete()) {
3030
auto pos = colorBase.combine(

src/chart/rendering/drawaxes.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,11 @@ void DrawAxes::drawDimensionLabel(bool horizontal,
370370
draw(text.get_or_first(index), position.weight);
371371
if (!labelStyle.position->interpolates()
372372
&& !text.interpolates())
373-
draw(text.get_or_first(::Anim::first));
373+
draw(text.values[0]);
374374
else if (labelStyle.position->interpolates())
375-
draw(text.get_or_first(::Anim::first),
376-
position.weight);
375+
draw(text.values[0], position.weight);
377376
else if (text.interpolates()) {
378-
draw(text.get_or_first(::Anim::first));
377+
draw(text.values[0]);
379378
draw(text.get_or_first(::Anim::second));
380379
}
381380
});

src/chart/rendering/drawmarkerinfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ void DrawMarkerInfo::draw(Gfx::ICanvas &canvas,
195195
const Geom::Rect &boundary) const
196196
{
197197
for (const auto &info : plot->getMarkersInfo()) {
198-
auto &&[cnt1, weight1] =
199-
info.second.get_or_first(::Anim::first);
198+
auto &&[cnt1, weight1] = info.second.values[0];
200199
if (!info.second.interpolates() && cnt1) {
201200
MarkerDC dc(*this, canvas, boundary, cnt1);
202201
dc.draw(weight1);

src/chart/rendering/markerrenderer.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,31 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
110110

111111
draw(canvas, painter, circle, 1, false);
112112

113-
blended.marker.prevMainMarker.visit(
114-
[this, &blended, &canvas, &painter](
115-
::Anim::InterpolateIndex index,
116-
const auto &value)
117-
{
118-
draw(canvas,
119-
painter,
120-
ConnectingMarker{ctx(),
121-
blended.marker,
122-
index,
123-
Gen::ShapeType::line},
124-
value.weight,
125-
true);
126-
});
113+
auto drawMarker = [this, &blended, &canvas, &painter](
114+
::Anim::InterpolateIndex index,
115+
const auto &value)
116+
{
117+
draw(canvas,
118+
painter,
119+
ConnectingMarker{ctx(),
120+
blended.marker,
121+
index,
122+
Gen::ShapeType::line},
123+
value.weight,
124+
true);
125+
};
126+
127+
if (blended.marker.prevMainMarker.interpolates())
128+
blended.marker.prevMainMarker.visit(drawMarker);
129+
else {
130+
auto index =
131+
getOptions()
132+
.geometry.get_index(Gen::ShapeType::line)
133+
.value();
134+
drawMarker(index,
135+
blended.marker.prevMainMarker.get_or_first(
136+
index));
137+
}
127138
}
128139
else {
129140
std::optional<AbstractMarker> other;
@@ -178,9 +189,7 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
178189
if (containsSingle) {
179190
auto lineIndex =
180191
isConnecting(
181-
getOptions()
182-
.geometry.get_or_first(::Anim::first)
183-
.value)
192+
getOptions().geometry.values[0].value)
184193
? ::Anim::first
185194
: ::Anim::second;
186195

@@ -195,9 +204,8 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
195204
}
196205
else
197206
drawMarker(::Anim::first,
198-
::Anim::Weighted{blended.marker.prevMainMarker
199-
.get_or_first(::Anim::first)
200-
.value,
207+
::Anim::Weighted{
208+
blended.marker.prevMainMarker.values[0].value,
201209
sum_weight});
202210
}
203211
}
@@ -211,7 +219,7 @@ void MarkerRenderer::drawLabels(Gfx::ICanvas &canvas) const
211219
if (blended.marker.enabled == false) continue;
212220
drawLabel(canvas,
213221
blended,
214-
axis.unit.get_or_first(::Anim::first).value,
222+
axis.unit.values[0].value,
215223
keepMeasure,
216224
::Anim::first);
217225
drawLabel(canvas,
@@ -270,7 +278,11 @@ void MarkerRenderer::draw(Gfx::ICanvas &canvas,
270278
{Geom::Line(p0, p1), false}))) {
271279
painter.drawStraightLine(line,
272280
abstractMarker.lineWidth,
273-
static_cast<double>(abstractMarker.linear));
281+
getOptions().coordSystem.factor(
282+
Gen::CoordSystem::cartesian)
283+
== 1.0
284+
? 1.0
285+
: static_cast<double>(abstractMarker.linear));
274286

275287
renderedChart.emplace(
276288
Draw::Marker{abstractMarker.marker.enabled != false,

src/chart/rendering/markers/abstractmarker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ AbstractMarker AbstractMarker::createInterpolated(
6767
{
6868
const auto &options = ctx.getOptions();
6969

70-
auto fromShapeType =
71-
options.geometry.get_or_first(::Anim::first).value;
70+
auto fromShapeType = options.geometry.values[0].value;
7271

7372
auto fromMarker = create(ctx, marker, fromShapeType, lineIndex);
7473

src/chart/rendering/markers/connectingmarker.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
2929
auto isLine = type == Gen::ShapeType::line;
3030
auto isArea = type == Gen::ShapeType::area;
3131

32+
auto needConnection =
33+
!ctx.getOptions().geometry.interpolates()
34+
|| isConnecting(
35+
ctx.getOptions().geometry.get_or_first(lineIndex).value);
36+
37+
auto otherNeedConnection = isConnecting(
38+
ctx.getOptions()
39+
.geometry
40+
.get_or_first(lineIndex == ::Anim::first ? ::Anim::second
41+
: ::Anim::first)
42+
.value);
43+
3244
auto polar = ctx.getOptions().coordSystem.factor<Math::FuzzyBool>(
3345
Gen::CoordSystem::polar);
3446
auto horizontal =
@@ -37,6 +49,14 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
3749

3850
linear = !polar || horizontal;
3951

52+
auto &&isHorizontal =
53+
ctx.getOptions().orientation.get_or_first(lineIndex).value
54+
== Gen::Orientation::horizontal;
55+
56+
auto &&isPolar =
57+
ctx.getOptions().coordSystem.get_or_first(lineIndex).value
58+
== Gen::CoordSystem::polar;
59+
4060
lineWidth[0] = lineWidth[1] = 0;
4161

4262
const auto *prev =
@@ -49,7 +69,8 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
4969
if (prev) {
5070
enabled = labelEnabled && prev->enabled;
5171
connected = Math::FuzzyBool::And(enabled,
52-
marker.prevMainMarker.get_or_first(lineIndex).weight);
72+
marker.prevMainMarker.get_or_first(lineIndex).weight,
73+
needConnection);
5374
if (auto &&pc =
5475
marker.polarConnection.get_or_first(lineIndex);
5576
pc.value) {
@@ -59,6 +80,9 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
5980
|| Math::FuzzyBool::Or(polar, pc.weight).more();
6081
connected = connected && newPolar && horizontal;
6182
enabled = enabled && newPolar && horizontal;
83+
84+
if (polar != false && prev != &marker)
85+
linear = linear || Math::FuzzyBool{isHorizontal};
6286
}
6387
}
6488
else {
@@ -92,13 +116,16 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
92116
auto prevSpacing = prev->spacing * prev->size / 2;
93117
auto prevPos = prev->position;
94118

95-
if (polar != false
96-
&& ctx.getOptions()
97-
.orientation.get_or_first(lineIndex)
98-
.value
99-
== Gen::Orientation::horizontal
100-
&& prev != &marker && prevPos.x >= 1) {
101-
prevPos.x -= 1;
119+
if (polar != false && isHorizontal && prev != &marker) {
120+
if (prevPos.x >= 1)
121+
prevPos.x -= 1;
122+
else if (needConnection && !otherNeedConnection
123+
&& isPolar
124+
&& marker.polarConnection
125+
.get_or_first(lineIndex)
126+
.value) {
127+
prevPos.x -= 1;
128+
}
102129
}
103130

104131
points[3] = prevPos - prevSpacing;

src/chart/rendering/painter/drawline.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "base/math/interpolation.h"
99

1010
#include "coordinatesystem.h"
11+
#include "drawpolygon.h"
1112
#include "pathsampler.h"
1213

1314
namespace Vizzu::Draw
@@ -22,15 +23,14 @@ DrawLine::DrawLine(const Geom::Line &line,
2223

2324
DrawLine::DrawLine(const Geom::Line &line,
2425
std::array<double, 2> widths,
25-
[[maybe_unused]] double straightFactor,
26-
CoordinateSystem &coordSys,
26+
const Options &options,
2727
Gfx::ICanvas &canvas)
2828
{
29-
auto pBeg = coordSys.convert(line.begin);
30-
auto pEnd = coordSys.convert(line.end);
29+
auto pBeg = options.coordSys.convert(line.begin);
30+
auto pEnd = options.coordSys.convert(line.end);
3131

32-
auto wBeg = widths[0] * coordSys.getRect().size.minSize();
33-
auto wEnd = widths[1] * coordSys.getRect().size.minSize();
32+
auto wBeg = widths[0] * options.coordSys.getRect().size.minSize();
33+
auto wEnd = widths[1] * options.coordSys.getRect().size.minSize();
3434

3535
const auto &[p0, p1, p2, p3] =
3636
Geom::ConvexQuad::Isosceles(pBeg, pEnd, wBeg * 2, wEnd * 2)
@@ -41,12 +41,25 @@ DrawLine::DrawLine(const Geom::Line &line,
4141
if (pBeg != pEnd) {
4242
canvas.circle(Geom::Circle(pEnd, wEnd));
4343

44-
canvas.beginPolygon();
45-
canvas.addPoint(p0);
46-
canvas.addPoint(p1);
47-
canvas.addPoint(p2);
48-
canvas.addPoint(p3);
49-
canvas.endPolygon();
44+
if (options.straightFactor == 1.0) {
45+
canvas.beginPolygon();
46+
canvas.addPoint(p0);
47+
canvas.addPoint(p1);
48+
canvas.addPoint(p2);
49+
canvas.addPoint(p3);
50+
canvas.endPolygon();
51+
}
52+
else {
53+
DrawPolygon({options.coordSys.getOriginal(p0),
54+
options.coordSys.getOriginal(p1),
55+
options.coordSys.getOriginal(p2),
56+
options.coordSys.getOriginal(p3)},
57+
{static_cast<PathSampler::Options>(options),
58+
{.toCircleFactor = 0,
59+
.straightFactor = options.straightFactor}},
60+
canvas,
61+
false);
62+
}
5063
}
5164
}
5265

0 commit comments

Comments
 (0)