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

org.jetbrains.kotlinx.ggdsl.letsplot.layers.boxplotStat.kt Maven / Gradle / Ivy

There is a newer version: 0.4.0-dev-15
Show newest version
/*
* Copyright 2020-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.kotlinx.ggdsl.letsplot.layers

//public val BOXPLOT_STAT: LetsPlotGeom = LetsPlotGeom("boxplot_stat")

/*
@PlotDslMarker
<<<<<<< HEAD
class OutlierSubContext(parentContext: BindingContext) : SubContext(parentContext), SelfInvocationContext {
    parent: LayerCollectorContext = mutableMapOf()
    val color = OutlierColorAes(parentContext)
    val fillColor = OutlierFillAes(parentContext)
    val symbol = OutlierShapeAes(parentContext)
    val size = OutlierSizeAes(parentContext)
=======
public class OutlierSubContext(parentContext: BindingContext) : SubContext(parentContext), SelfInvocationContext {
    override var data: MutableNamedData = mutableMapOf()
    public val color: OutlierColorAes = OutlierColorAes(parentContext)
    public val fillColor: OutlierFillAes = OutlierFillAes(parentContext)
    public val symbol: OutlierShapeAes = OutlierShapeAes(parentContext)
    public val size: OutlierSizeAes = OutlierSizeAes(parentContext)
>>>>>>> main
}

// TODO Stats
@PlotDslMarker
// todo move x/y?
<<<<<<< HEAD
class BoxplotStatContext(
    parent: LayerCollectorContext,
=======
public class BoxplotStatContext(
    override var data: MutableNamedData,
>>>>>>> main
    varWidth: Boolean?,
) : LayerContext(parent) {
    init {
        varWidth?.let {
            varWidth(it)
        }
    }

    @PublishedApi
    internal val _x: XAes get() = XAes(this)

    @PublishedApi
    internal val _y: YAes get() = YAes(this)

    public val x: XDummyAes get() = XDummyAes(this)
    public val y: YDummyAes get() = YDummyAes(this)

    public val alpha: AlphaAes get() = AlphaAes(this)
    public val fillColor: FillAes get() = FillAes(this)

    public val fatten: FattenAes get() = FattenAes(this)

    public val width: WidthAes get() = WidthAes(this)

    /*  TODO*/
    public val borderLineColor: ColorAes get() = ColorAes(this)
    public val borderLineWidth: SizeAes get() = SizeAes(this)
    public val borderLineType: LineTypeAes get() = LineTypeAes(this)

    public val outlier: OutlierSubContext get() = OutlierSubContext(this)

    @PublishedApi
    internal val varWidth: VarWidthAes get() = VarWidthAes(this)

    public object Statistics {
        public val X: BoxplotStat.X = BoxplotStat.X() // TODO!!!
        public val MIDDLE: BoxplotStat.Middle = BoxplotStat.Middle
        public val Y_MIN: BoxplotStat.YMin = BoxplotStat.YMin
        public val Y_MAX: BoxplotStat.YMax = BoxplotStat.YMax
        public val LOWER: BoxplotStat.Lower = BoxplotStat.Lower
        public val UPPER: BoxplotStat.Upper = BoxplotStat.Upper
    }

    public val Stat: Statistics = Statistics

    public fun orderBy(stat: BoxplotStat<*>, descending: Boolean = false) {
        val mapping = bindingCollector.mappings[X] as ScaledPositionalUnspecifiedMapping<*>
        if (mapping.scaleParameters == null) {
            mapping.scaleParameters = PositionalParameters(Axis()).apply {
                orderBy = OrderBy(
                    if (stat is BoxplotStat.X) {
                        null
                    } else stat.name,
                    if (descending) {
                        -1
                    } else 1
                )
            }
        }
    }

}

<<<<<<< HEAD
inline fun  PlotContext.boxplot(
    sourceX: ColumnPointer,
    sourceY: ColumnPointer,
=======
public inline fun  PlotContext.boxplot(
    sourceX: DataSource,
    sourceY: DataSource,
>>>>>>> main
    varWidth: Boolean? = null,
    block: BoxplotStatContext.() -> Unit
) {
    layers.add(
        BoxplotStatContext(data, varWidth)
            .apply {
                copyFrom(this@boxplot)
                _x(sourceX.scaled(categoricalPos()))
                _y(sourceY)
            }
            .apply(block)
            .toLayer(BOXPLOT_STAT)
    )
}

public inline fun  PlotContext.boxplot(
    sourceX: Iterable,
    sourceY: Iterable,
    varWidth: Boolean? = null,
    block: BoxplotStatContext.() -> Unit
) {
    layers.add(
        BoxplotStatContext(data, varWidth)
            .apply {
                copyFrom(this@boxplot)
                _x(sourceX.scaled(categoricalPos()))
                _y(sourceY)
            }
            .apply(block)
            .toLayer(BOXPLOT_STAT)
    )
}

 */





© 2015 - 2025 Weber Informatics LLC | Privacy Policy