commonMain.jetbrains.datalore.plot.base.stat.BaseStat.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.base.stat
import jetbrains.datalore.plot.base.Aes
import jetbrains.datalore.plot.base.DataFrame
import jetbrains.datalore.plot.base.Stat
import jetbrains.datalore.plot.base.data.TransformVar
abstract class BaseStat(private val defaultMappings: Map, DataFrame.Variable>) : Stat {
override fun hasDefaultMapping(aes: Aes<*>): Boolean {
return defaultMappings.containsKey(aes)
}
override fun getDefaultMapping(aes: Aes<*>): DataFrame.Variable {
if (defaultMappings.containsKey(aes)) {
return defaultMappings[aes]!!
}
throw IllegalArgumentException("Stat " + this::class.simpleName + " has no default mapping for aes: " + aes)
}
protected fun hasRequiredValues(data: DataFrame, vararg aes: Aes<*>): Boolean {
for (requiredAes in aes) {
val variable = TransformVar.forAes(requiredAes)
if (data.hasNoOrEmpty(variable)) {
return false
}
}
return true
}
protected fun withEmptyStatValues(): DataFrame {
val newData = DataFrame.Builder()
for (aes in Aes.values()) {
if (hasDefaultMapping(aes)) {
newData.put(getDefaultMapping(aes), emptyList())
}
}
return newData.build()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy