commonMain.jetbrains.datalore.plot.config.BunchConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.plot.config
import jetbrains.datalore.base.gcommon.base.Preconditions.checkState
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.config.Option.GGBunch
import jetbrains.datalore.plot.config.Option.GGBunch.Item
class BunchConfig(opts: Map) : OptionsAccessor(opts) {
private val myItems = ArrayList()
val bunchItems: List
get() = myItems
init {
val items = getList(GGBunch.ITEMS)
for (itemRaw in items) {
if (itemRaw is Map<*, *>) {
@Suppress("UNCHECKED_CAST")
val itemOptions = OptionsAccessor(itemRaw as MutableMap)
myItems.add(
BunchItem(
itemOptions.getMap(Item.FEATURE_SPEC),
itemOptions.getDouble(Item.X)!!,
itemOptions.getDouble(Item.Y)!!,
itemOptions.getDouble(Item.WIDTH),
itemOptions.getDouble(Item.HEIGHT)
)
)
}
}
}
class BunchItem(
private val myFeatureSpec: Map<*, *>,
val x: Double,
val y: Double,
private val myWidth: Double?,
private val myHeight: Double?
) {
val featureSpec: Map
@Suppress("UNCHECKED_CAST")
get() = myFeatureSpec as Map
val size: DoubleVector
get() {
checkState(hasSize(), "Size is not defined")
return DoubleVector(myWidth!!, myHeight!!)
}
fun hasSize(): Boolean {
return myWidth != null && myHeight != null
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy