-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.d
60 lines (54 loc) · 1.38 KB
/
app.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import spasm.spa;
import spasm.bindings.html : HTMLElement;
import ldc.attributes;
struct LineData {
uint time;
float value;
}
struct Chart {
JsHandle handle;
alias handle this;
this(Handle h) {
handle = JsHandle(h);
}
static Chart create(scope ref HTMLElement container) {
return Chart(createChart(*container.handle.ptr));
}
LineSeries addLineSeries() {
return LineSeries(Chart_addLineSeries(*handle.ptr));
}
}
struct LineSeries {
JsHandle handle;
alias handle this;
this(Handle h) {
handle = JsHandle(h);
}
void setData(const LineData[] data) {
lineSeries_setData(*handle.ptr, data);
}
}
extern (C) {
// should work in ldc 1.16.0
// @llvmAttr("wasm-import-module", "npm:lightweight-charts")
// {
Handle createChart(Handle);
Handle Chart_addLineSeries(Handle);
void lineSeries_setData(Handle, const LineData[]);
// }
}
pragma(mangle, "_start")
void _start() {
auto node = HTMLElement(getRoot());
static immutable data = [
LineData(1562694650, 45),
LineData(1562694660, 46),
LineData(1562694670, 48),
LineData(1562694680, 52),
LineData(1562694690, 49.1),
LineData(1562694700, 33),
LineData(1562694710, 22.7),
LineData(1562694720, 24)
];
Chart.create(node).addLineSeries().setData(data[]);
}