-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsimpleServer.kt
90 lines (77 loc) · 2.57 KB
/
simpleServer.kt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.html.a
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.style
import space.kscience.dataforge.meta.invoke
import space.kscience.plotly.Plot
import space.kscience.plotly.Plotly
import space.kscience.plotly.models.Trace
import space.kscience.plotly.models.invoke
import space.kscience.plotly.plot
import space.kscience.plotly.server.close
import space.kscience.plotly.server.serve
import space.kscience.plotly.server.show
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
@ExperimentalCoroutinesApi
fun main() {
val server = Plotly.serve {
val x = (0..100).map { it.toDouble() / 100.0 }.toDoubleArray()
val y1 = x.map { sin(2.0 * PI * it) }.toDoubleArray()
val y2 = x.map { cos(2.0 * PI * it) }.toDoubleArray()
val trace1 = Trace(x, y1) { name = "sin" }
val trace2 = Trace(x, y2) { name = "cos" }
val plot1: Plot = Plotly.plot{
traces(trace1, trace2)
layout {
title = "First graph, row: 1, size: 8/12"
xaxis { title = "x axis name" }
yaxis { title = "y axis name" }
}
}
//root level plots go to default page
page {
h1 { +"This is the plot page" }
a("/other") { +"The other page" }
div {
style = "display: flex; align-items: stretch; "
div {
style = "width: 64%;"
plot(plot1)
}
div {
style = "width: 32%;"
plot {
traces(trace1, trace2)
layout {
title = "Second graph, row: 1, size: 4/12"
xaxis { title = "x axis name" }
yaxis { title = "y axis name" }
}
}
}
}
div {
plot {
traces(trace1, trace2)
layout {
title = "Third graph, row: 2, size: 12/12"
xaxis { title = "x axis name" }
yaxis { title = "y axis name" }
}
}
}
}
page("other") {
h1 { +"This is the other plot page" }
a("/") { +"Back to the main page" }
plot(plot1)
}
}
server.show()
println("Press Enter to close server")
readLine()
server.close()
}