Skip to content

Commit d93b679

Browse files
authored
Merge pull request #301 from vizzuhq/options_unify
Options refactor
2 parents 9cbe40b + 94906ba commit d93b679

33 files changed

+271
-294
lines changed

src/apps/weblib/interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <span>
44

5-
#include "base/io/log.h"
65
#include "base/conv/auto_json.h"
6+
#include "base/io/log.h"
77

88
#include "interfacejs.h"
99
#include "jscriptcanvas.h"

src/base/conv/auto_json.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ concept Optional =
2929
*val;
3030
};
3131

32-
template <class T> concept Tuple = sizeof(std::tuple_size<T>) > 0;
32+
template <class T> concept Tuple = sizeof(std::tuple_size<T>) != 0;
3333

3434
template <class T>
3535
concept Pair = Tuple<T> && std::tuple_size_v<T> == 2;
@@ -244,7 +244,7 @@ struct JSONObj : JSON
244244

245245
template <class T> inline void JSON::dynamicObj(const T &val) const
246246
{
247-
JSONObj j{json};
247+
JSONObj j{json}; // NOLINT
248248
for (const auto &[k, v] : val) { j(toString(k), v); }
249249
}
250250

src/chart/animator/animation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ void Animation::addKeyframe(const Gen::PlotPtr &next,
8383
!target->getOptions()->getChannels().anyAxisSet()
8484
&& next->getOptions()->getChannels().anyAxisSet();
8585

86-
auto geometryChanges = target->getOptions()->shapeType
87-
!= next->getOptions()->shapeType;
86+
auto geometryChanges = target->getOptions()->geometry
87+
!= next->getOptions()->geometry;
8888

8989
auto basedOnSource =
9090
loosingCoordsys || (!gainingCoordsys && geometryChanges);

src/chart/animator/morph.cpp

Lines changed: 6 additions & 6 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
}
@@ -99,8 +99,8 @@ void Shape::transform(const Gen::Options &source,
9999
Gen::Options &actual,
100100
double factor) const
101101
{
102-
actual.shapeType = interpolate(source.shapeType,
103-
target.shapeType,
102+
actual.geometry = interpolate(source.geometry,
103+
target.geometry,
104104
factor);
105105
}
106106

@@ -148,9 +148,9 @@ void Connection::transform(const Gen::Options &source,
148148
double factor) const
149149
{
150150
auto sourceIsConnecting =
151-
Vizzu::Gen::isConnecting(source.shapeType.get());
151+
Vizzu::Gen::isConnecting(source.geometry.get());
152152
auto targetIsConnecting =
153-
Vizzu::Gen::isConnecting(target.shapeType.get());
153+
Vizzu::Gen::isConnecting(target.geometry.get());
154154

155155
if (sourceIsConnecting && !targetIsConnecting) {
156156
actual.horizontal = source.horizontal;

src/chart/animator/planner.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ void Planner::createPlan(const Gen::Plot &source,
101101
addMorph(SectionId::coordSystem, std::max(step, posDuration));
102102

103103
const auto &geomEasing =
104-
srcOpt->shapeType == Gen::ShapeType::circle ? in3
105-
: trgOpt->shapeType == Gen::ShapeType::circle ? out3
106-
: srcOpt->shapeType == Gen::ShapeType::line ? in3
107-
: trgOpt->shapeType == Gen::ShapeType::line ? out3
108-
: inOut5;
104+
srcOpt->geometry == Gen::ShapeType::circle ? in3
105+
: trgOpt->geometry == Gen::ShapeType::circle ? out3
106+
: srcOpt->geometry == Gen::ShapeType::line ? in3
107+
: trgOpt->geometry == Gen::ShapeType::line ? out3
108+
: inOut5;
109109

110110
addMorph(SectionId::geometry,
111111
std::max(step, posDuration),
@@ -245,11 +245,11 @@ 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] =
252-
srcOpt->shapeType != trgOpt->shapeType;
252+
srcOpt->geometry != trgOpt->geometry;
253253

254254
animNeeded[SectionId::y] = needVertical();
255255
animNeeded[SectionId::x] = needHorizontal();
@@ -282,8 +282,8 @@ bool Planner::positionMorphNeeded() const
282282
{
283283
typedef Gen::ShapeType ST;
284284

285-
auto &srcShape = source->getOptions()->shapeType;
286-
auto &trgShape = target->getOptions()->shapeType;
285+
auto &srcShape = source->getOptions()->geometry;
286+
auto &trgShape = target->getOptions()->geometry;
287287

288288
auto anyCircle = srcShape == ST::circle || trgShape == ST::circle;
289289

src/chart/generator/guides.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ bool GuidesByAxis::operator==(const GuidesByAxis &other) const
3131
void Guides::init(const Axises &axises, const Options &options)
3232
{
3333
auto isCircle =
34-
options.shapeType.get() == ShapeType::circle;
35-
auto isLine = options.shapeType.get() == ShapeType::line;
34+
options.geometry.get() == ShapeType::circle;
35+
auto isLine = options.geometry.get() == ShapeType::line;
3636
auto isHorizontal = static_cast<bool>(options.horizontal);
3737
auto yIsMeasure = static_cast<bool>(
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);
@@ -79,7 +79,7 @@ void Guides::init(const Axises &axises, const Options &options)
7979

8080
auto stretchedPolar =
8181
isPolar && !yIsMeasure
82-
&& (options.alignType == Base::Align::Type::stretch);
82+
&& (options.align == Base::Align::Type::stretch);
8383

8484
y.labels = yOpt.axisLabels.getValue(
8585
!stretchedPolar

src/chart/generator/marker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Marker::Marker(const Options &options,
6767

6868
mainId = Id(data, options.mainAxis().dimensionIds, index);
6969

70-
auto stackInhibitingShape = options.shapeType == ShapeType::area;
70+
auto stackInhibitingShape = options.geometry == ShapeType::area;
7171
if (stackInhibitingShape) {
7272
Data::SeriesList subIds(options.subAxis().dimensionIds);
7373
subIds.remove(options.mainAxis().dimensionIds);

src/chart/generator/plot.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Plot::Plot(const Data::DataTable &dataTable,
113113
if (gotSpecLayout) {
114114
calcDimensionAxises(dataTable);
115115
normalizeColors();
116-
if (options->shapeType != ShapeType::circle)
116+
if (options->geometry != ShapeType::circle)
117117
normalizeSizes();
118118
calcAxises(dataTable);
119119
}
@@ -201,7 +201,7 @@ Plot::sortedBuckets(const Buckets &buckets, bool main)
201201
}
202202
}
203203

204-
if (main && options->sorted) {
204+
if (main && options->sort == Sort::byValue) {
205205
std::sort(sorted.begin(),
206206
sorted.end(),
207207
[=](const std::pair<uint64_t, double> &a,
@@ -315,7 +315,7 @@ Axis Plot::calcAxis(ChannelId type, const Data::DataTable &dataTable)
315315
: scale.title;
316316

317317
if (type == options->subAxisType()
318-
&& options->alignType == Base::Align::Type::stretch) {
318+
&& options->align == Base::Align::Type::stretch) {
319319
return {Math::Range<double>(0, 100),
320320
title,
321321
"%",
@@ -397,12 +397,12 @@ void Plot::calcDimensionAxis(ChannelId type,
397397

398398
void Plot::addAlignment()
399399
{
400-
if (static_cast<bool>(options->splitted)) return;
400+
if (static_cast<bool>(options->split)) return;
401401

402402
auto &axis = axises.at(options->subAxisType());
403403
if (axis.range.getMin() < 0) return;
404404

405-
if (options->alignType == Base::Align::Type::none) return;
405+
if (options->align == Base::Align::Type::none) return;
406406

407407
for (auto &bucketIt : subBuckets) {
408408
Math::Range<double> range;
@@ -414,7 +414,7 @@ void Plot::addAlignment()
414414
range.include(size);
415415
}
416416

417-
Base::Align aligner(options->alignType,
417+
Base::Align aligner(options->align,
418418
Math::Range(0.0, 1.0));
419419
auto transform = aligner.getAligned(range) / range;
420420

@@ -431,10 +431,10 @@ void Plot::addAlignment()
431431

432432
void Plot::addSeparation()
433433
{
434-
if (static_cast<bool>(options->splitted)) {
435-
auto align = options->alignType == Base::Align::Type::none
434+
if (static_cast<bool>(options->split)) {
435+
auto align = options->align == Base::Align::Type::none
436436
? Base::Align::Type::min
437-
: options->alignType;
437+
: options->align;
438438

439439
std::vector<Math::Range<double>> ranges(mainBuckets.size(),
440440
Math::Range(0.0, 0.0));
@@ -481,8 +481,8 @@ void Plot::addSeparation()
481481

482482
void Plot::normalizeSizes()
483483
{
484-
if (options->shapeType == ShapeType::circle
485-
|| options->shapeType == ShapeType::line) {
484+
if (options->geometry == ShapeType::circle
485+
|| options->geometry == ShapeType::line) {
486486
Math::Range<double> size;
487487

488488
for (auto &marker : markers)

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/events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <optional>
55

66
#include "base/anim/control.h"
7+
#include "base/conv/auto_json.h"
78
#include "base/geom/line.h"
89
#include "base/geom/rect.h"
9-
#include "base/conv/auto_json.h"
1010
#include "base/util/eventdispatcher.h"
1111

1212
namespace Vizzu

0 commit comments

Comments
 (0)