All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.plot.config.ScaleTransformConfig.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * 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