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

commonMain.jetbrains.datalore.plot.config.CoordConfig.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.plot.builder.coord.CoordProvider
import jetbrains.datalore.plot.config.Option.Coord.FLIPPED

class CoordConfig private constructor(
    private val name: String,
    options: Map,
    private val defaultCoordProvider: CoordProvider
) : OptionsAccessor(options) {

    companion object {
        fun create(coordOpts: Any?, defaultCoordProvider: CoordProvider): CoordProvider {
            if (coordOpts == null) return defaultCoordProvider

            val coordName = when (coordOpts) {
                is Map<*, *> -> ConfigUtil.featureName(coordOpts)
                else -> coordOpts.toString()
            }

            @Suppress("UNCHECKED_CAST")
            val options: Map = when (coordOpts) {
                is Map<*, *> -> coordOpts as Map
                else -> emptyMap()
            }
            return when (coordName) {
                Option.CoordName.FLIP -> {
                    // Flip the 'default' coord system.
                    val withFlip = options + mapOf(FLIPPED to true)
                    CoordProto.createCoordProvider(defaultCoordProvider, over(withFlip))
                }
                else -> {
                    CoordProto.createCoordProvider(coordName, over(options))
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy