%useLatestDescriptors %use lets-plot import kotlin.random.Random fun timePlot( title: String, entries: Iterable, duration: Long, yTimeAxis: Boolean = false ): org.jetbrains.letsPlot.intern.Plot { val rnd = Random(0) val time = entries.map { it * duration } val values = time.indices.map { rnd.nextDouble(0.0, 20.0) } val data = mapOf( "time" to time, "values" to values ) return ggplot(data) + if (yTimeAxis) { geomLine { x = "values"; y = "time" } + scaleYTime() + ggtitle(title + " (y-axis)") } else { geomLine { x = "time"; y = "values" } + scaleXTime() + ggtitle(title) } } val MS: Long = 1 val SECOND: Long = 1000 * MS val MINUTE: Long = 60 * SECOND val HOUR: Long = 60 * MINUTE val plots = listOf( timePlot("5 seconds", 0..5000 step 5, MS), timePlot("24 hours", 0..24, HOUR), timePlot("5 days", 0..120, HOUR), timePlot("30 days", 0..720, HOUR), timePlot("-30..30, MINUTE", -30..30, MINUTE), timePlot("-30..30, MINUTE", -30..30, MINUTE, yTimeAxis = true) ) gggrid(plots, ncol = 2, cellWidth = 470, cellHeight = 300).show()