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

org.jetbrains.kotlinx.kandy.letsplot.layers.barsH.kt Maven / Gradle / Ivy

There is a newer version: 0.8.0-dev-57
Show newest version
package org.jetbrains.kotlinx.kandy.letsplot.layers

import org.jetbrains.kotlinx.kandy.dsl.internal.LayerCreatorScope
import org.jetbrains.kotlinx.kandy.letsplot.feature.Position
import org.jetbrains.kotlinx.kandy.letsplot.feature.position
import org.jetbrains.kotlinx.kandy.letsplot.feature.reversed
import org.jetbrains.kotlinx.kandy.letsplot.layers.builders.BarsBuilder

/**
 * Adds a new `barsH` layer to the plot.
 *
 * The `barsH` layer is designed to visualize data using horizontal bars.
 * It serves a similar purpose as `bars`, but the orientation of the bars is horizontal rather than vertical.
 *
 * This function creates a context where you can set aesthetic mappings (`aes`) or aesthetic constants.
 * - Mappings are specified by calling methods that correspond to aesthetic names (`aes`).
 * - Constants are directly assigned using properties with the names corresponding to aesthetics.
 * For positional aesthetics, you can use the `.constant()` method.
 *
 * ## BarsH Aesthetics
 * * **`x`** - The X-coordinate specifying the length of the bars.
 * * **`y`** - The Y-coordinate specifying the categories.
 * * **`fillColor`** - The fill color of the bars.
 * * **`alpha`** - The transparency of the bars.
 * * **`width`** - The width of the bars.
 * * **`borderLine.color`** - Color of the bars' borderline.
 * * **`borderLine.width`** - Width of the bars' borderline.
 * * **`borderLine.type`** - Type of the bars' borderline, such as dashed or dotted.
 *
 * ## Example
 *
 * ```kotlin
 * plot {
 *     barsH {
 *         // Positional mapping
 *         y(listOf("Apple", "Banana", "Cherry", "Orange", "Strawberry"))
 *         x(listOf(5.0, 7.5, 3.0, 4.5, 6.0)) {
 *             axis.breaks((0..16).map { it / 2.0 })
 *         }
 *
 *         // Non-positional settings
 *         alpha = 0.7
 *         width = 0.4
 *
 *         // BorderLine settings
 *         borderLine {
 *             color = Color.BLACK
 *             width = 2.5
 *             type = LineType.DASHED
 *         }
 *
 *         // Non-positional mapping
 *         fillColor(listOf("a", "b", "b", "c", "a"))
 *     }
 * }
 * ```
 */
public inline fun LayerCreatorScope.barsH(block: BarsBuilder.() -> Unit) {
    createLayer(BarsBuilder(this).apply {
        position = Position.dodge()
        reversed = true
    }, block)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy