Skip to content

Commit f44618c

Browse files
committed
Animation options object added, can be set from JS API.
(not used in animation for now)
1 parent ac04dcb commit f44618c

File tree

12 files changed

+95
-3
lines changed

12 files changed

+95
-3
lines changed

project/cmake/weblib/emcc.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
2525
'_removeEventListener',\
2626
'_event_preventDefault',\
2727
'_chart_animate',\
28-
'_anim_control'] \
28+
'_anim_control',\
29+
'_anim_setValue'] \
2930
-s ALLOW_TABLE_GROWTH \
3031
--js-library ${CMAKE_CURRENT_LIST_DIR}/../../../src/apps/weblib/interface.js \
3132
-s EXTRA_EXPORTED_RUNTIME_METHODS=[\

src/apps/weblib/cinterface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ void anim_control(const char *command, const char *param)
107107
{
108108
Interface::instance.animControl(command, param);
109109
}
110+
111+
void anim_setValue(const char *path, const char *value)
112+
{
113+
Interface::instance.setAnimValue(path, value);
114+
}

src/apps/weblib/cinterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern int addEventListener(const char *name);
2525
extern void removeEventListener(const char *name, int id);
2626
extern void event_preventDefault();
2727
extern void anim_control(const char *command, const char *param);
28+
extern void anim_setValue(const char *path, const char *value);
2829

2930
}
3031

src/apps/weblib/interface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ void Interface::animControl(const char *command, const char *param)
136136
}
137137
}
138138

139+
void Interface::setAnimValue(const char *path, const char *value)
140+
{
141+
if (chart) {
142+
chart->getChart().getAnimOptions().set(path, value);
143+
}
144+
}
145+
139146
void Interface::addCategories(const char *name,
140147
const char **categories,
141148
int count)

src/apps/weblib/interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Interface
3333
void preventDefaultEvent();
3434
void animate(void (*callback)());
3535
void animControl(const char *command, const char *param);
36+
void setAnimValue(const char *path, const char *value);
3637

3738
static const void *
3839
getRecordValue(void *record, const char *column, bool discrete);

src/apps/weblib/js-api/vizzu.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class Vizzu
8686
this.events.remove(eventName, handler);
8787
}
8888

89-
animate(obj)
89+
animate(obj, animOptions)
9090
{
9191
if (obj !== null && obj !== undefined && typeof obj === 'object')
9292
{
@@ -95,6 +95,14 @@ export default class Vizzu
9595
this.setDescriptor(obj.descriptor);
9696
}
9797

98+
if (animOptions !== null && animOptions !== undefined
99+
&& typeof animOptions === 'object')
100+
{
101+
this.iterateObject(animOptions, (path, value) => {
102+
this.call(this.module._anim_setValue)(path, value);
103+
});
104+
}
105+
98106
return new Promise((resolve, reject) => {
99107
let callbackPtr = this.module.addFunction(() => {
100108
resolve(this);

src/chart/animator/animator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void Animator::init(Diag::DiagramPtr diagram)
2828
}
2929

3030
void Animator::animate(const Diag::DiagramPtr &diagram,
31+
Options &&/*options*/,
3132
OnComplete onThisCompletes)
3233
{
3334
if (isRunning()) throw std::logic_error("animation already in progress");

src/chart/animator/animator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "chart/generator/diagram.h"
88

99
#include "planner.h"
10+
#include "options.h"
1011

1112
namespace Vizzu
1213
{
@@ -26,6 +27,7 @@ class Animator :
2627

2728
void init(Diag::DiagramPtr diagram);
2829
void animate(const Diag::DiagramPtr &diagram,
30+
Options &&options = Options(),
2931
OnComplete onThisCompletes = OnComplete());
3032

3133
OnDraw onDraw;

src/chart/animator/options.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "options.h"
2+
3+
#include "base/conv/parse.h"
4+
#include "base/text/smartstring.h"
5+
6+
using namespace Vizzu;
7+
using namespace Vizzu::Anim;
8+
9+
void Options::set(const std::string &path,
10+
const std::string &value)
11+
{
12+
auto parts = Text::SmartString::split(path, '.');
13+
14+
if (parts.size() != 2)
15+
throw std::logic_error("invalid animation option: " + path);
16+
17+
auto sectionId = SectionId(parts[0]);
18+
auto &section = sections.at((int)sectionId);
19+
20+
auto option = parts[1];
21+
if (option == "easing")
22+
section.easing = ::Anim::Easing(value);
23+
else if (option == "delay")
24+
section.delay = ::Anim::Duration(value);
25+
else if (option == "duration")
26+
section.duration = ::Anim::Duration(value);
27+
else throw std::logic_error("invalid animation option: " + option);
28+
}

src/chart/animator/options.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef CHART_ANIM_OPTIONS
2+
#define CHART_ANIM_OPTIONS
3+
4+
#include <array>
5+
#include <optional>
6+
7+
#include "base/anim/options.h"
8+
#include "base/refl/enum.h"
9+
10+
namespace Vizzu
11+
{
12+
namespace Anim
13+
{
14+
15+
class Enum(SectionId)
16+
(style,title,enable,color,coordsys,shape,vertical,horizontal);
17+
18+
class Options
19+
{
20+
public:
21+
struct Section {
22+
std::optional<::Anim::Easing> easing;
23+
std::optional<::Anim::Duration> delay;
24+
std::optional<::Anim::Duration> duration;
25+
};
26+
27+
std::array<Section, SectionId::EnumInfo::count()> sections;
28+
29+
void set(const std::string &path, const std::string &value);
30+
};
31+
32+
}
33+
}
34+
35+
#endif

0 commit comments

Comments
 (0)