Charts - Performance Mode (100'000 points)
import io.data2viz.charts.*
import io.data2viz.charts.core.*
import io.data2viz.charts.dimension.*
import io.data2viz.charts.chart.*
import io.data2viz.charts.chart.mark.*
import io.data2viz.charts.viz.*
import io.data2viz.charts.layout.*
import io.data2viz.geom.*
import io.data2viz.color.*
import io.data2viz.random.RandomDistribution
import io.data2viz.timeFormat.*
import io.data2viz.timeFormat.TimeLocale
import kotlinx.datetime.Instant
import io.data2viz.math.*
import io.data2viz.shape.*
import kotlin.random.*
import kotlin.math.*
fun main() {
// Creating and sizing the VizContainer
val vc = newVizContainer().apply {
size = Size(width, height)
}
val samples = generateData(5, 20_000)
vc.chart(samples) {
config {
performanceMode = true
events {
triggerMode = TriggerMode.Column
zoomMode = ZoomMode.X
panMode = PanMode.X
}
cursor {
show = false
}
}
val timeDim = quantitative( { domain.second.toDouble() } )
val tempDim = quantitative( { domain.third } )
series = discrete( {domain.first} )
line(timeDim, tempDim) {
marker = discrete ( { Symbols.Circle } )
}
}
}
val width = 450.0
val height = 300.0
fun generateData(series:Int, samplesPerSeries:Int): List<Triple<Int, Int, Double>> =
(0 until series).map { s ->
val i = 40 * Random.nextDouble()
val o = 40 * Random.nextDouble()
val r = 160 * Random.nextDouble()
(0 until samplesPerSeries).map { sample ->
var n = r * (s + 1) * exp(abs(sample - samplesPerSeries / 2) / samplesPerSeries.toDouble()) * sin(sample / (samplesPerSeries / i)) * cos(sample / (samplesPerSeries / o))
Triple(s, sample, n)
}
}.flatten()
comments