Skip to content

Commit 464f3c6

Browse files
authored
Merge pull request #519 from vizzuhq/iterate_on_dataframe
Iterate on dataframe v2
2 parents 0e8d606 + 0493510 commit 464f3c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+881
-1042
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- From now legend appears/disappears linear time.
1414
- Axis labels are not animated to a different axis label.
1515
- Dimension axis density on sorted values was wrongly calculated.
16+
- Tooltip with 'seriesName' does not rewrite first series data.
17+
- Handle as different category the empty string and the missing value.
1618

1719
### Added
1820

project/cmake/lib/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ include(../common.txt)
33
file(GLOB_RECURSE sources CONFIGURE_DEPENDS
44
${root}/plugin/*.cpp
55
${root}/src/base/*.cpp
6-
${root}/src/data/*.cpp
76
${root}/src/chart/*.cpp
87
${root}/src/dataframe/*.cpp)
98

@@ -12,10 +11,7 @@ include(../version.txt)
1211
file(GLOB_RECURSE headers CONFIGURE_DEPENDS
1312
${root}/plugin/*.h
1413
${root}/src/base/*.h
15-
${root}/src/data/*.h
16-
${root}/src/data/*.inc
1714
${root}/src/chart/*.h
18-
${root}/src/chart/*.inc
1915
${root}/src/dataframe/*.h)
2016

2117
add_library(vizzulib ${sources})

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Checks: >
66
-bugprone-narrowing-conversions,
77
-bugprone-unchecked-optional-access,
88
cert-*,
9+
-cert-dcl21-cpp,
910
-cert-err58-cpp,
1011
clang-analyzer-*,
1112
clang-diagnostic-*,

src/apps/weblib/interface.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "base/conv/auto_json.h"
66
#include "base/io/log.h"
77
#include "base/refl/auto_accessor.h"
8+
#include "chart/main/version.h"
9+
#include "chart/ui/chart.h"
810

911
#include "canvas.h"
1012
#include "interfacejs.h"
@@ -21,6 +23,26 @@ std::unique_ptr<T, Deleter> create_unique_ptr(T *&&ptr,
2123
return {ptr, std::forward<Deleter>(deleter)};
2224
}
2325

26+
struct Interface::Snapshot
27+
{
28+
Snapshot(Gen::Options options, Styles::Chart styles) :
29+
options(std::move(options)),
30+
styles(std::move(styles))
31+
{}
32+
Gen::Options options;
33+
Styles::Chart styles;
34+
};
35+
36+
struct Interface::Animation
37+
{
38+
Animation(Anim::AnimationPtr anim, Snapshot snapshot) :
39+
animation(std::move(anim)),
40+
snapshot(std::move(snapshot))
41+
{}
42+
Anim::AnimationPtr animation;
43+
Snapshot snapshot;
44+
};
45+
2446
Interface &Interface::getInstance()
2547
{
2648
static Interface instance;

src/apps/weblib/interface.h

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndef LIB_INTERFACE_H
22
#define LIB_INTERFACE_H
33

4-
#include "chart/main/version.h"
5-
#include "chart/ui/chart.h"
6-
4+
#include "cinterface.h"
75
#include "jsfunctionwrapper.h"
86
#include "objectregistry.h"
97

108
namespace Vizzu
119
{
10+
class Chart;
1211

1312
class Interface
1413
{
@@ -122,28 +121,11 @@ class Interface
122121
const char *column);
123122

124123
private:
125-
struct Snapshot
126-
{
127-
Snapshot(Gen::Options options, Styles::Chart styles) :
128-
options(std::move(options)),
129-
styles(std::move(styles))
130-
{}
131-
Gen::Options options;
132-
Styles::Chart styles;
133-
};
134-
135-
struct Animation
136-
{
137-
Animation(Anim::AnimationPtr anim, Snapshot snapshot) :
138-
animation(std::move(anim)),
139-
snapshot(std::move(snapshot))
140-
{}
141-
Anim::AnimationPtr animation;
142-
Snapshot snapshot;
143-
};
144-
145-
std::shared_ptr<Vizzu::Chart> getChart(
146-
ObjectRegistry::Handle chart);
124+
struct Snapshot;
125+
126+
struct Animation;
127+
128+
std::shared_ptr<Chart> getChart(ObjectRegistry::Handle chart);
147129

148130
ObjectRegistry objects;
149131
};

src/apps/weblib/objectregistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <any>
55
#include <memory>
66
#include <shared_mutex>
7+
#include <thread>
78
#include <unordered_map>
89

910
namespace Vizzu

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/conv/auto_json.h

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,9 @@ struct JSON
9292
}
9393
}
9494

95-
template <class T> inline void array(const T &val) const
96-
{
97-
json += '[';
98-
bool not_first = false;
99-
for (const auto &e : val) {
100-
if (not_first)
101-
json += ',';
102-
else
103-
not_first = true;
104-
any(e);
105-
}
106-
json += ']';
107-
}
95+
template <class T> inline void array(const T &val) const;
10896

109-
template <class T> inline void tupleObj(const T &val) const
110-
{
111-
std::apply(
112-
[this](const auto &arg, const auto &...args)
113-
{
114-
json += '[';
115-
any(arg);
116-
((json += ',', any(args)), ...);
117-
json += ']';
118-
},
119-
val);
120-
}
97+
template <class T> inline void tupleObj(const T &val) const;
12198

12299
template <class T> void dynamicObj(const T &val) const;
123100

@@ -267,26 +244,36 @@ template <class J> struct JSONNoBaseAutoObj : JSONAutoObj
267244
}
268245
};
269246

270-
struct JSONObj : JSON
247+
template <char open, char close> struct JSONRepeat : JSON
271248
{
272249
using JSON::JSON;
273250

274-
inline ~JSONObj()
251+
JSONRepeat(JSONRepeat &&) = delete;
252+
JSONRepeat(const JSONRepeat &) = delete;
253+
JSONRepeat &operator=(const JSONRepeat &) = delete;
254+
JSONRepeat &operator=(JSONRepeat &&) = delete;
255+
256+
inline ~JSONRepeat()
275257
{
276-
if (!was) json += '{';
277-
json += '}';
258+
if (!was) json += open;
259+
json += close;
278260
}
279261

280-
JSONObj(JSONObj &&) = delete;
281-
JSONObj(const JSONObj &) = delete;
282-
JSONObj &operator=(const JSONObj &) = delete;
283-
JSONObj &operator=(JSONObj &&) = delete;
262+
void sep() { json += std::exchange(was, true) ? ',' : open; }
263+
264+
bool was{};
265+
};
266+
267+
struct JSONArr;
268+
269+
struct JSONObj : protected JSONRepeat<'{', '}'>
270+
{
271+
using JSONRepeat::JSONRepeat;
284272

285273
template <bool KeyNoEscape = true>
286274
inline JSON &key(std::string_view key)
287275
{
288-
json += std::exchange(was, true) ? ',' : '{';
289-
276+
sep();
290277
json += '\"';
291278
if constexpr (KeyNoEscape)
292279
json.append(key);
@@ -304,6 +291,9 @@ struct JSONObj : JSON
304291
return JSONObj{json};
305292
}
306293

294+
template <bool KeyNoEscape = true>
295+
inline JSONArr nestedArr(std::string_view key);
296+
307297
template <bool KeyNoEscape = true>
308298
inline JSONObj &raw(std::string_view key, const std::string &str)
309299
{
@@ -327,10 +317,48 @@ struct JSONObj : JSON
327317
any(val);
328318
return std::move(*this);
329319
}
320+
};
330321

331-
bool was{};
322+
struct JSONArr : protected JSONRepeat<'[', ']'>
323+
{
324+
using JSONRepeat::JSONRepeat;
325+
326+
template <class T> inline JSONArr &operator<<(const T &obj)
327+
{
328+
sep();
329+
any(obj);
330+
return *this;
331+
}
332+
333+
inline JSONArr nested()
334+
{
335+
sep();
336+
return JSONArr{json};
337+
}
338+
339+
inline JSONObj nestedObj()
340+
{
341+
sep();
342+
return JSONObj{json};
343+
}
332344
};
333345

346+
template <class T> inline void JSON::array(const T &val) const
347+
{
348+
auto arr = JSONArr{json};
349+
for (const auto &e : val) arr << e;
350+
}
351+
352+
template <class T> inline void JSON::tupleObj(const T &val) const
353+
{
354+
std::apply(
355+
[this](const auto &...args)
356+
{
357+
(JSONArr{json} << ... << args);
358+
},
359+
val);
360+
}
361+
334362
template <class T> inline void JSON::dynamicObj(const T &val) const
335363
{
336364
auto j = JSONObj{json};
@@ -344,6 +372,13 @@ template <class T> inline void JSON::staticObj(const T &val) const
344372
Refl::visit(JSONNoBaseAutoObj<T>{json}, val);
345373
}
346374

375+
template <bool KeyNoEscape>
376+
inline JSONArr JSONObj::nestedArr(std::string_view key)
377+
{
378+
this->key<KeyNoEscape>(key);
379+
return JSONArr{json};
380+
}
381+
347382
template <class T> inline std::string toJSON(const T &v)
348383
{
349384
std::string res;

src/base/gfx/draw/textbox.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,19 @@ TextBox &TextBox::operator<<(const NewLine &)
8888
TextBox &TextBox::operator<<(const Font &font)
8989
{
9090
newTextRun();
91-
if (font.opCode == 0)
92-
currentTextRun.font.size = font.size;
93-
else if (font.opCode == 1)
91+
switch (font.opCode) {
92+
case 0: currentTextRun.font.size = font.size; break;
93+
case 1:
9494
currentTextRun.font.weight = Gfx::Font::Weight::Bold();
95-
else if (font.opCode == 2)
95+
break;
96+
case 2:
9697
currentTextRun.font.style = Gfx::Font::Style::italic;
97-
else if (font.opCode == 3) {
98+
break;
99+
case 3:
98100
currentTextRun.font.weight = Gfx::Font::Weight::Normal();
99101
currentTextRun.font.style = Gfx::Font::Style::normal;
102+
break;
103+
default: break;
100104
}
101105
return *this;
102106
}
@@ -209,22 +213,20 @@ void TextBox::newTextRun()
209213
{
210214
size.x = size.y = 0;
211215
if (!currentTextRun.content.empty()) {
212-
currentLine.texts.push_back(currentTextRun);
213-
currentTextRun = TextRun{};
214-
currentTextRun.font = currentLine.texts.rbegin()->font;
215-
currentTextRun.backgroundColor =
216-
currentLine.texts.rbegin()->backgroundColor;
217-
currentTextRun.foregroundColor =
218-
currentLine.texts.rbegin()->foregroundColor;
216+
auto &preTextRun =
217+
currentLine.texts.emplace_back(std::move(currentTextRun));
218+
currentTextRun =
219+
TextRun{.foregroundColor = preTextRun.foregroundColor,
220+
.backgroundColor = preTextRun.backgroundColor,
221+
.font = preTextRun.font};
219222
}
220223
}
221224

222225
void TextBox::newLine()
223226
{
224227
newTextRun();
225-
lines.push_back(currentLine);
226-
currentLine = Line{};
227-
currentLine.spacing = lines.rbegin()->spacing;
228+
auto &back = lines.emplace_back(std::move(currentLine));
229+
currentLine = Line{.spacing = back.spacing};
228230
}
229231

230232
}

src/base/gfx/draw/textbox.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ class TextBox
9898
std::optional<int> backgroundColor;
9999
double width{0};
100100
Gfx::Font font{};
101-
std::string content;
101+
std::string content{};
102102
};
103103

104104
struct Line
105105
{
106106
double spacing{1.0};
107107
double height{0};
108108
double width{0};
109-
std::vector<TextRun> texts;
109+
std::vector<TextRun> texts{};
110110
};
111111

112112
Geom::Size size;

0 commit comments

Comments
 (0)