commonMain.jetbrains.datalore.plot.config.ScaleTransformConfig.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.stringFormat.StringFormat
import jetbrains.datalore.plot.base.Transform
import jetbrains.datalore.plot.base.scale.transform.TransformKind
import jetbrains.datalore.plot.base.scale.transform.Transforms
internal class ScaleTransformConfig private constructor(
val transform: Transform,
opts: Map
) : OptionsAccessor(opts) {
companion object {
fun create(trans: Any, format: String?): ScaleTransformConfig {
// trans - name (identity,log10 ...)
// or
// map with transform options
if (trans is Map<*, *>) {
@Suppress("UNCHECKED_CAST")
val opts = trans as Map
return createForName(
ConfigUtil.featureName(opts),
opts,
format
)
}
return createForName(
trans.toString(),
HashMap(),
format
)
}
private fun createForName(name: String, opts: Map, format: String?): ScaleTransformConfig {
val stringFormat = format?.let { StringFormat.create(it) }
val transform = Transforms.createTransform(
transKind = TransformKind.safeValueOf(name),
labelFormatter = stringFormat?.let { { value: Any -> it.format(value) } }
)
return ScaleTransformConfig(transform, opts)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy