Skip to content

Commit 6ff1a88

Browse files
authored
Merge pull request #416 from vizzuhq/scheduling
Time for update() supplied from js api
2 parents 68d1835 + d6a241b commit 6ff1a88

File tree

9 files changed

+32
-18
lines changed

9 files changed

+32
-18
lines changed

src/apps/weblib/cinterface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,14 @@ void vizzu_update(APIHandles::Chart chart,
184184
APIHandles::Canvas canvas,
185185
double width,
186186
double height,
187+
double timeInMSecs,
187188
int renderControl)
188189
{
189190
return Interface::getInstance().update(chart,
190191
canvas,
191192
width,
192193
height,
194+
timeInMSecs,
193195
static_cast<Interface::RenderControl>(renderControl));
194196
}
195197

src/apps/weblib/cinterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern void vizzu_update(APIHandles::Chart chart,
6666
APIHandles::Canvas canvas,
6767
double width,
6868
double height,
69+
double timeInMSecs,
6970
int renderControl);
7071
extern const char *vizzu_errorMessage(
7172
APIHandles::Exception exceptionPtr,

src/apps/weblib/interface.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,20 @@ void Interface::update(ObjectRegistry::Handle chart,
353353
ObjectRegistry::Handle canvas,
354354
double width,
355355
double height,
356+
double timeInMSecs,
356357
RenderControl renderControl)
357358
{
358359
auto &&widget = objects.get<UI::ChartWidget>(chart);
359-
widget->getChart().getAnimControl().update(
360-
std::chrono::steady_clock::now());
360+
361+
std::chrono::duration<double, std::milli> milliSecs(timeInMSecs);
362+
363+
auto nanoSecs =
364+
std::chrono::duration_cast<std::chrono::nanoseconds>(
365+
milliSecs);
366+
367+
::Anim::TimePoint time(nanoSecs);
368+
369+
widget->getChart().getAnimControl().update(time);
361370

362371
if (const Geom::Size size{width, height};
363372
renderControl == force

src/apps/weblib/interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Interface
4747
ObjectRegistry::Handle canvas,
4848
double width,
4949
double height,
50+
double timeInMSecs,
5051
RenderControl renderControl);
5152

5253
ObjectRegistry::Handle storeAnim(ObjectRegistry::Handle chart);

src/apps/weblib/ts-api/cvizzu.types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface CVizzu {
9494
canvas: CCanvasPtr,
9595
width: number,
9696
height: number,
97+
time: number,
9798
renderControl: number
9899
): void
99100
_vizzu_errorMessage(exceptionPtr: CException, typeinfo: CTypeInfo): CString

src/apps/weblib/ts-api/module/cchart.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ export class CChart extends CObject {
4242
this.animOptions = this._makeAnimOptions()
4343
}
4444

45-
update(cCanvas: CCanvas, width: number, height: number, renderControl: number): void {
45+
update(
46+
cCanvas: CCanvas,
47+
width: number,
48+
height: number,
49+
time: number,
50+
renderControl: number
51+
): void {
4652
this._cCanvas = cCanvas
47-
this._call(this._wasm._vizzu_update)(cCanvas.getId(), width, height, renderControl)
53+
this._call(this._wasm._vizzu_update)(cCanvas.getId(), width, height, time, renderControl)
4854
}
4955

5056
animate(callback: (ok: boolean) => void): void {

src/apps/weblib/ts-api/render.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export class Render implements Plugin, Canvas {
4848
updateFrame(force: boolean = false): void {
4949
const size = this._canvas.calcSize()
5050
if (size.x >= 1 && size.y >= 1) {
51+
const time = performance.now()
5152
const renderControl = !this._enabled ? 2 : force ? 1 : 0
52-
this._cchart.update(this._ccanvas, size.x, size.y, renderControl)
53+
this._cchart.update(this._ccanvas, size.x, size.y, time, renderControl)
5354
}
5455
}
5556

test/e2e/test_cases/test_cases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,7 @@
32873287
"refs": ["2a18132"]
32883288
},
32893289
"web_content/cookbook/rendering/motion_blur": {
3290-
"refs": ["be67912"]
3290+
"refs": ["3a48367"]
32913291
},
32923292
"web_content/cookbook/style/colorfilter": {
32933293
"refs": ["05406ff"]

test/e2e/test_cases/web_content/cookbook/rendering/motion_blur.mjs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,11 @@ const testSteps = [
3737

3838
chart.on('draw-complete', drawComplete)
3939

40-
return chart
41-
.animate({
42-
coordSystem: 'polar',
43-
y: 'Joy factors',
44-
x: 'Value 2 (+)'
45-
})
46-
.then((chart) => {
47-
const handle = setInterval(() => {
48-
const ctx = chart.feature.htmlCanvas.element.getContext('2d')
49-
if (!drawImages(ctx)) clearInterval(handle)
50-
}, 40)
51-
})
40+
return chart.animate({
41+
coordSystem: 'polar',
42+
y: 'Joy factors',
43+
x: 'Value 2 (+)'
44+
})
5245
}
5346
]
5447

0 commit comments

Comments
 (0)