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

commonMain.jetbrains.datalore.plot.base.Scale.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.base

import jetbrains.datalore.base.gcommon.collect.ClosedRange
import jetbrains.datalore.plot.base.scale.BreaksGenerator

/**
 * Translates input to aesthetics by
 * 1) Transforming data (like x1=log(x)). Must happen before 'stat' is applies to data
 * 2) Mapping data to aesthetic
 *
 *
 * name - (axis/legend title)
 * brakes (domain values) - ticks on axis, items/segments on legends
 * labels - tick labels
 *
 * @param  - type of target aesthetic
 *
 */
interface Scale {
    val name: String

    val breaks: List

    val labels: List

    val labelFormatter: ((Any) -> String)?

    /**
     * @return TRUE if both, domain and range are continuous
     */
    val isContinuous: Boolean

    val isContinuousDomain: Boolean

    val domainLimits: ClosedRange?

    val multiplicativeExpand: Double

    val additiveExpand: Double

    val transform: Transform

    val mapper: (Double?) -> T?

    val breaksGenerator: BreaksGenerator
        get() {
            val transform = transform
            if (transform is BreaksGenerator) {
                return transform
            }
            throw IllegalStateException("No breaks generator for '$name'")
        }

    fun hasBreaks(): Boolean

    fun hasLabels(): Boolean

    fun hasDomainLimits(): Boolean

    fun isInDomainLimits(v: Any): Boolean

    fun asNumber(input: Any?): Double?

    fun hasBreaksGenerator(): Boolean {
        return transform is BreaksGenerator
    }

    fun with(): Builder

    interface Builder {

        /**
         * Lower limit for scale with continuous domain.
         */
        fun lowerLimit(v: Double): Builder

        /**
         * Upper limit for scale with continuous domain.
         */
        fun upperLimit(v: Double): Builder

        /**
         * Limits for scale with discrete domain
         */
        fun limits(domainValues: List): Builder

        fun breaks(l: List): Builder

        fun labels(l: List): Builder

        fun labelFormatter(v: (Any) -> String): Builder

        fun mapper(m: (Double?) -> T?): Builder

        fun multiplicativeExpand(v: Double): Builder

        fun additiveExpand(v: Double): Builder

        fun continuousTransform(v: Transform): Builder

        fun build(): Scale
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy