commonMain.org.jetbrains.letsPlot.GGBunch.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-kotlin-kernel Show documentation
Show all versions of lets-plot-kotlin-kernel Show documentation
Lets-Plot Kotlin API without dependencies.
/*
* Copyright (c) 2021. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package org.jetbrains.letsPlot
import org.jetbrains.letsPlot.core.spec.Option
import org.jetbrains.letsPlot.core.spec.Option.GGBunch.ITEMS
import org.jetbrains.letsPlot.core.spec.Option.GGBunch.Item
import org.jetbrains.letsPlot.core.spec.Option.Meta.KIND
import org.jetbrains.letsPlot.frontend.CurrentFrontendContext
import org.jetbrains.letsPlot.intern.Plot
import org.jetbrains.letsPlot.intern.toSpec
/**
* Collection of plots created by ggplot function. Use method `addPlot()` to add plot to 'bunch'.
* Each plot can have arbitrary location and size. Use `show()` to draw all plots in bunch.
*
* ## Examples
*
* - [ggbunch.ipynb](https://nbviewer.jupyter.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/ggbunch.ipynb)
*
* - [geom_smooth.ipynb](https://nbviewer.jupyter.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/geom_smooth.ipynb)
*/
class GGBunch : Figure {
private val items: MutableList = ArrayList()
fun addPlot(plot: Plot, x: Int, y: Int, width: Int? = null, height: Int? = null): GGBunch {
items.add(PlotItem(plot, x, y, width, height))
return this;
}
fun toSpec(): MutableMap {
val spec = HashMap()
spec[KIND] = Option.Meta.Kind.GG_BUNCH
val itemSpecs = ArrayList