Skip to content

Commit 0493510

Browse files
committed
Fix qt + simplify segmentedfunc
1 parent 66d4039 commit 0493510

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

src/base/anim/easinggradient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ EasingGradient EasingGradient::Bezier(const Geom::Point &p1,
1919
if (p1.x < 0 || p1.x > 1 || p2.x < 0 || p2.x > 1)
2020
throw std::logic_error("bezier point is out of range");
2121

22-
EasingGradient res;
22+
EasingGradient res(stepCount);
2323

2424
const Geom::CubicBezier<Geom::Point> bezier(Geom::Point{0, 0},
2525
p1,
@@ -29,7 +29,7 @@ EasingGradient EasingGradient::Bezier(const Geom::Point &p1,
2929
for (auto i = 0U; i < stepCount; ++i) {
3030
auto point = bezier(static_cast<double>(i)
3131
/ static_cast<double>(stepCount - 1));
32-
res.stops.emplace_back(point.x, point.y);
32+
res.stops[i] = {point.x, point.y};
3333
}
3434

3535
return res;

src/base/math/segmentedfunc.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ template <typename T> struct SegmentedFunction
1010
{
1111
struct Stop
1212
{
13-
double pos;
14-
T value;
15-
Stop() : pos(0), value(T()) {}
16-
Stop(double pos, const T &value) : pos(pos), value(value) {}
13+
double pos{};
14+
T value{};
1715
bool operator==(const Stop &other) const
1816
{
1917
return pos == other.pos && value == other.value;
@@ -22,8 +20,9 @@ template <typename T> struct SegmentedFunction
2220

2321
std::vector<Stop> stops;
2422

25-
SegmentedFunction() = default;
26-
explicit SegmentedFunction(std::vector<Stop> stops) :
23+
SegmentedFunction() noexcept = default;
24+
explicit SegmentedFunction(std::size_t init) : stops(init) {}
25+
explicit SegmentedFunction(std::vector<Stop> &&stops) noexcept :
2726
stops(std::move(stops))
2827
{}
2928

src/base/math/segmentedfunc.tpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ T Math::SegmentedFunction<T>::at(double pos) const
1616
if (pos > stops.back().pos) return stops.back().value;
1717

1818
for (auto i = 1U; i < stops.size(); ++i) {
19-
if (pos >= stops.at(i - 1).pos && pos <= stops.at(i).pos) {
20-
const Range range(stops.at(i - 1).pos, stops.at(i).pos);
21-
22-
auto factor = range.rescale(pos);
23-
24-
return interpolate(stops.at(i - 1).value,
25-
stops.at(i).value,
26-
factor);
27-
}
19+
auto &[ppos, pval] = stops[i - 1];
20+
auto &[cpos, cval] = stops[i];
21+
if (ppos <= pos && pos <= cpos)
22+
return interpolate(pval,
23+
cval,
24+
Range{ppos, cpos}.rescale(pos));
2825
}
2926

3027
return stops.back().value;

src/chart/generator/marker.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ double Marker::getValueForChannel(const Channels &channels,
165165

166166
if (channel.isEmpty()) return channel.defaultValue;
167167

168-
auto measure = channel.measureId;
169-
170168
double value{};
171169

172170
auto &stat = stats.channels[type];

test/qtest/chart.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "chart/rendering/drawplot.h"
66
#include "chart/rendering/logo.h"
77
#include "chart/ui/events.h"
8-
#include "data/datacube/datacube.h"
8+
#include "dataframe/old/datatable.h"
99

1010
TestChart::TestChart() {}
1111

@@ -142,14 +142,16 @@ void TestChart::run()
142142
IO::log() << "step 1b";
143143
auto &options = chart.getChart().getOptions();
144144
auto &styles = chart.getChart().getStyles();
145-
options.dataFilter = {[&](const auto &row)
145+
options.dataFilter = {1,
146+
[&](const Vizzu::Data::RowWrapper &row)
146147
{
147-
return std::string{row["Cat1"].dimensionValue()}
148+
return std::get<std::string_view>(
149+
row.get_value("Cat1"))
148150
== "A"
149-
|| std::string{row["Cat2"].dimensionValue()}
151+
|| std::get<std::string_view>(
152+
row.get_value("Cat2"))
150153
== "b";
151-
},
152-
0};
154+
}};
153155
options.title = "VIZZU Chart - Phase 1b";
154156
styles.legend.marker.type =
155157
Vizzu::Styles::Legend::Marker::Type::circle;

0 commit comments

Comments
 (0)