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

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

There is a newer version: 0.8.0-RC5
Show newest version
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.
 */
class SequentialScale
internal constructor(var interpolator: Interpolator) : Tickable, ClampableScale,
    StrictlyContinuousDomain {

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

    override var clamp: Boolean = false

    operator fun invoke(domainValue: Int): R {
        return this(domainValue.toDouble())
    }

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

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy