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

io.data2viz.scale.Sequential.kt Maven / Gradle / Ivy

package io.data2viz.scale

import io.data2viz.interpolate.Interpolator
import io.data2viz.interpolate.uninterpolateNumber


/**
 * Sequential scales are similar to continuous scales in that they map a continuous numeric input domain to a
 * continuous output range. However, unlike continuous scales, the output range of a sequential scale is fixed
 * by its interpolator and not configurable.
 *
 * These scales do not expose invert, range, rangeRound and interpolate methods.
 *
 * TODO Domain take only list of 2 items... -> use a type
 */
class SequentialScale(var interpolator: Interpolator) : Tickable, ClampableScale, StrictlyContinuousDomain {

    override var domain: StrictlyContinuous = intervalOf(0.0, 1.0)


    override var clamp: Boolean = false

    operator fun invoke(domainValue: Double): R {
        var uninterpolatedDomain = uninterpolateNumber(domain.start, domain.end)(domainValue)
        if(clamp) uninterpolatedDomain = uninterpolatedDomain.coerceIn(0.0, 1.0)
        return interpolator(uninterpolatedDomain)
    }

    override fun ticks(count: Int) = io.data2viz.math.ticks(domain.start, domain.end, count)
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy