import io.data2viz.color.Colors
import io.data2viz.geom.*
import io.data2viz.viz.bindRendererOn
import io.data2viz.viz.*
import kotlin.random.Random
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
import kotlin.time.measureTimedValue
const val parameterCount = 64
const val dataSize = 1000
val data by lazy {
Array(dataSize) {
Array(parameterCount) { Random.nextDouble(.0, 100.0) }
}
}
fun main() {
// render(document.getElementById("root")) {
// child(App::class) {}
// }
println("Hello Kotlin/JS")
processStats()
var timedValue = measureTimedValue { processStats() }
println("Stats processed in ${timedValue.duration.inMilliseconds} ms")
// timedValue = measureTimedValue { processStats() }
// println("Stats processed in ${timedValue.duration.inMilliseconds} ms")
// timedValue = measureTimedValue { processStats() }
// println("Stats processed in ${timedValue.duration.inMilliseconds} ms")
val viz = viz {
size = size(1000, 400)
timedValue.value.forEachIndexed { i, s ->
path {
stroke = Colors.Web.black
moveTo(i.toDouble(), 100.0 - s.min)
lineTo(i.toDouble(), 100.0 - s.max)
}
}
}
viz.bindRendererOnNewCanvas()
}
fun processStats(): List<Stat> = data.map { sample ->
var min = Double.MAX_VALUE
var max = Double.MIN_VALUE
var mean = .0
sample.forEach { datum ->
if (datum < min) min = datum
if (datum > max) max = datum
mean += datum
}
mean /= parameterCount
Stat(min, max, mean)
}
data class Stat(val min: Double, val max: Double, val mean: Double)
comments