Skip to content

Commit d898156

Browse files
committed
Merge remote-tracking branch 'origin/separate_enums_make_interpolated' into options_unify
# Conflicts: # src/chart/main/stylesheet.cpp # src/chart/options/options.cpp
2 parents e2a8a3a + e9eb28e commit d898156

24 files changed

+114
-79
lines changed

src/chart/animator/morph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void CoordinateSystem::transform(const Gen::Options &source,
6868
Gen::Options &actual,
6969
double factor) const
7070
{
71-
actual.polar =
72-
interpolate(source.polar, target.polar, factor);
71+
actual.coordSystem =
72+
interpolate(source.coordSystem, target.coordSystem, factor);
7373
actual.angle =
7474
interpolate(source.angle, target.angle, factor);
7575
}

src/chart/animator/planner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void Planner::calcNeeded()
245245
animNeeded[SectionId::color] = needColor();
246246

247247
animNeeded[SectionId::coordSystem] =
248-
srcOpt->polar != trgOpt->polar
248+
srcOpt->coordSystem != trgOpt->coordSystem
249249
|| srcOpt->angle != trgOpt->angle;
250250

251251
animNeeded[SectionId::geometry] =

src/chart/generator/guides.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void Guides::init(const Axises &axises, const Options &options)
3838
axises.at(ChannelId::y).enabled.calculate<Math::FuzzyBool>());
3939
auto xIsMeasure = static_cast<bool>(
4040
axises.at(ChannelId::x).enabled.calculate<Math::FuzzyBool>());
41-
auto isPolar = static_cast<bool>(options.polar);
41+
auto isPolar = options.coordSystem.get() == CoordSystem::polar;
4242

4343
const auto &xOpt = options.getChannels().at(ChannelId::x);
4444
const auto &yOpt = options.getChannels().at(ChannelId::y);

src/chart/generator/plot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Plot::sortedBuckets(const Buckets &buckets, bool main)
201201
}
202202
}
203203

204-
if (main && options->sorted) {
204+
if (main && options->sorted == Sort::byValue) {
205205
std::sort(sorted.begin(),
206206
sorted.end(),
207207
[=](const std::pair<uint64_t, double> &a,

src/chart/main/chart.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Chart::Chart() :
2222
nextOptions = std::make_shared<Gen::Options>();
2323

2424
animator->onDraw.attach(
25-
[&](const Gen::PlotPtr& actPlot)
25+
[&](const Gen::PlotPtr &actPlot)
2626
{
2727
this->actPlot = actPlot;
2828
if (onChanged) onChanged();
@@ -56,9 +56,9 @@ void Chart::setBoundRect(const Geom::Rect &rect, Gfx::ICanvas &info)
5656
}
5757
}
5858

59-
void Chart::animate(const OnComplete& onComplete)
59+
void Chart::animate(const OnComplete &onComplete)
6060
{
61-
auto f = [=, this](const Gen::PlotPtr& plot, bool ok)
61+
auto f = [=, this](const Gen::PlotPtr &plot, bool ok)
6262
{
6363
actPlot = plot;
6464
if (ok) {
@@ -105,9 +105,11 @@ void Chart::draw(Gfx::ICanvas &canvas) const
105105
if (actPlot
106106
&& (!events.draw.begin
107107
|| events.draw.begin->invoke(
108-
Util::EventDispatcher::Params{})))
109-
{
110-
Draw::DrawingContext context(canvas, layout, events.draw, *actPlot);
108+
Util::EventDispatcher::Params{}))) {
109+
Draw::DrawingContext context(canvas,
110+
layout,
111+
events.draw,
112+
*actPlot);
111113

112114
Draw::DrawBackground(
113115
layout.boundary.outline(Geom::Size::Square(1)),
@@ -147,7 +149,7 @@ void Chart::draw(Gfx::ICanvas &canvas) const
147149

148150
if (events.draw.logo->invoke()) {
149151
auto filter = *(actPlot ? actPlot->getStyle()
150-
: stylesheet.getDefaultParams())
152+
: stylesheet.getDefaultParams())
151153
.logo.filter;
152154

153155
auto logoRect = getLogoBoundary();
@@ -164,8 +166,8 @@ void Chart::draw(Gfx::ICanvas &canvas) const
164166
Geom::Rect Chart::getLogoBoundary() const
165167
{
166168
const auto &logoStyle = (actPlot ? actPlot->getStyle()
167-
: stylesheet.getDefaultParams())
168-
.logo;
169+
: stylesheet.getDefaultParams())
170+
.logo;
169171

170172
auto logoWidth =
171173
logoStyle.width->get(layout.boundary.size.minSize(),
@@ -178,12 +180,12 @@ Geom::Rect Chart::getLogoBoundary() const
178180
Styles::Sheet::baseFontSize(layout.boundary.size, false));
179181

180182
return {layout.boundary.topRight()
181-
- Geom::Point(logoPad.right + logoWidth,
182-
logoPad.bottom + logoHeight),
183+
- Geom::Point(logoPad.right + logoWidth,
184+
logoPad.bottom + logoHeight),
183185
Geom::Size(logoWidth, logoHeight)};
184186
}
185187

186-
Gen::PlotPtr Chart::plot(const Gen::PlotOptionsPtr& options)
188+
Gen::PlotPtr Chart::plot(const Gen::PlotOptionsPtr &options)
187189
{
188190
computedStyles =
189191
stylesheet.getFullParams(options, layout.boundary.size);
@@ -202,12 +204,13 @@ Draw::CoordinateSystem Chart::getCoordSystem() const
202204

203205
return {plotArea,
204206
options.angle,
205-
options.polar,
207+
options.coordSystem,
206208
actPlot->keepAspectRatio};
207209
}
208210
return {plotArea,
209211
0.0,
210-
Math::FuzzyBool(),
212+
::Anim::Interpolated<Gen::CoordSystem>{
213+
Gen::CoordSystem::cartesian},
211214
Math::FuzzyBool()};
212215
}
213216

@@ -219,19 +222,19 @@ Gen::Marker *Chart::markerAt(const Geom::Point &point) const
219222

220223
const Draw::CoordinateSystem coordSys(plotArea,
221224
options.angle,
222-
options.polar,
225+
options.coordSystem,
223226
actPlot->keepAspectRatio);
224227

225228
auto originalPos = coordSys.getOriginal(point);
226229

227230
for (auto &marker : actPlot->getMarkers()) {
228-
auto drawItem = Draw::AbstractMarker::createInterpolated(
229-
marker,
230-
options,
231-
actPlot->getStyle(),
232-
coordSys,
233-
actPlot->getMarkers(),
234-
0);
231+
auto drawItem =
232+
Draw::AbstractMarker::createInterpolated(marker,
233+
options,
234+
actPlot->getStyle(),
235+
coordSys,
236+
actPlot->getMarkers(),
237+
0);
235238

236239
if (drawItem.bounds(originalPos)) return &marker;
237240
}

src/chart/main/stylesheet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ double Sheet::baseFontSize(const Geom::Size &size, bool rounded)
5656

5757
void Sheet::setPlot()
5858
{
59-
if (static_cast<bool>(options->polar)) {
59+
if (options->coordSystem.get() == Gen::CoordSystem::polar) {
6060
defaultParams.plot.paddingLeft = 0;
6161
}
6262
else if (!options->getChannels().anyAxisSet()) {
@@ -81,7 +81,7 @@ void Sheet::setAxis()
8181

8282
void Sheet::setAxisLabels()
8383
{
84-
if (options->polar) {
84+
if (options->coordSystem.get() == Gen::CoordSystem::polar) {
8585
auto &def = defaultParams.plot.xAxis.label;
8686
def.position = AxisLabel::Position::max_edge;
8787
def.side = AxisLabel::Side::positive;
@@ -90,7 +90,7 @@ void Sheet::setAxisLabels()
9090

9191
void Sheet::setAxisTitle()
9292
{
93-
if (options->polar) {
93+
if (options->coordSystem.get() == Gen::CoordSystem::polar) {
9494
auto &def = defaultParams.plot.xAxis.title;
9595
def.position = AxisTitle::Position::max_edge;
9696
def.side = AxisTitle::Side::positive;
@@ -122,7 +122,7 @@ void Sheet::setMarkers()
122122

123123
if (options->getChannels().anyAxisSet()
124124
&& options->geometry == Gen::ShapeType::rectangle
125-
&& static_cast<bool>(options->polar)
125+
&& options->coordSystem.get() == Gen::CoordSystem::polar
126126
&& options->getVeritalAxis().isEmpty()) {
127127
defaultParams.plot.marker.rectangleSpacing = 0;
128128
}

src/chart/options/config.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ void Config::setParam(const std::string &path,
9292

9393
std::string Config::getParam(const std::string &path) const
9494
{
95-
if (path.starts_with("channels."))
96-
return getChannelParam(path);
95+
if (path.starts_with("channels.")) return getChannelParam(path);
9796

9897
if (auto it = accessors.find(path); it != accessors.end())
9998
return it->second.get(setter->getOptions());
@@ -192,9 +191,7 @@ std::string Config::getChannelParam(const std::string &path) const
192191
if (property == "labels") {
193192
return Conv::toString(channel.axisLabels);
194193
}
195-
if (property == "ticks") {
196-
return Conv::toString(channel.ticks);
197-
}
194+
if (property == "ticks") { return Conv::toString(channel.ticks); }
198195
if (property == "interlacing") {
199196
return Conv::toString(channel.interlacing);
200197
}
@@ -255,15 +252,13 @@ Config::Accessors Config::initAccessors()
255252
{.get =
256253
[](const Options &options)
257254
{
258-
auto cs{options.polar ? CoordSystem::polar
259-
: CoordSystem::cartesian};
260-
return Conv::toString(cs);
255+
return Conv::toString(options.coordSystem);
261256
},
262257
.set =
263258
[](OptionsSetter &setter, const std::string &value)
264259
{
265-
auto coordSys = Conv::parse<CoordSystem>(value);
266-
setter.setPolar(coordSys == CoordSystem::polar);
260+
setter.setCoordSystem(
261+
Conv::parse<CoordSystem>(value));
267262
}}});
268263

269264
res.insert({"rotate",
@@ -301,14 +296,12 @@ Config::Accessors Config::initAccessors()
301296
{.get =
302297
[](const Options &options)
303298
{
304-
auto res(options.sorted ? Sort::byValue : Sort::none);
305-
return Conv::toString(res);
299+
return Conv::toString(options.sorted);
306300
},
307301
.set =
308302
[](OptionsSetter &setter, const std::string &value)
309303
{
310-
auto sort = Conv::parse<Sort>(value);
311-
setter.setSorted(sort == Sort::byValue);
304+
setter.setSorted(Conv::parse<Sort>(value));
312305
}}});
313306

314307
res.emplace(accessor<&Options::reverse>);

src/chart/options/config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ namespace Vizzu::Gen
1515
class Config
1616
{
1717
public:
18-
enum class CoordSystem { cartesian, polar };
19-
enum class Orientation { horizontal, vertical };
20-
enum class Sort { none, byValue };
21-
2218
static std::list<std::string> listParams();
2319
[[nodiscard]] std::string getParam(const std::string &path) const;
2420
void setParam(const std::string &path, const std::string &value);

src/chart/options/coordsystem.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef CHART_OPTIONS_COORDSYSTEM_H
2+
#define CHART_OPTIONS_COORDSYSTEM_H
3+
4+
namespace Vizzu::Gen
5+
{
6+
7+
enum class CoordSystem { cartesian, polar };
8+
9+
}
10+
11+
#endif

src/chart/options/options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ uint64_t Options::nextMarkerInfoId = 1;
1919

2020
Options::Options() :
2121
title(std::nullopt),
22-
polar(false),
22+
coordSystem(CoordSystem::cartesian),
2323
geometry(ShapeType::rectangle),
2424
horizontal(true),
25-
sorted(false),
25+
sorted(Sort::none),
2626
reverse(false)
2727
{}
2828

@@ -182,7 +182,7 @@ bool Options::sameShadowAttribs(const Options &other) const
182182
auto shapeOther = other.geometry;
183183
if (shapeOther == ShapeType::line) shapeOther = ShapeType::area;
184184

185-
return shape == shapeOther && polar == other.polar
185+
return shape == shapeOther && coordSystem == other.coordSystem
186186
&& angle == other.angle && horizontal == other.horizontal
187187
&& split == other.split && dataFilter == other.dataFilter
188188
&& align == other.align && sorted == other.sorted
@@ -276,7 +276,7 @@ void Options::setAutoRange(bool hPositive, bool vPositive)
276276
setRange(h, 0.0_perc, 100.0_perc);
277277
setRange(v, 0.0_perc, 100.0_perc);
278278
}
279-
else if (!static_cast<bool>(polar)) {
279+
else if (coordSystem.get() != CoordSystem::polar) {
280280
if (!h.isDimension() && !v.isDimension()
281281
&& geometry == ShapeType::rectangle) {
282282
setRange(h, 0.0_perc, 100.0_perc);

0 commit comments

Comments
 (0)