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

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

The newest version!
/*
* Copyright 2020-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

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.layers.builders.BarsBuilder

/**
 * Adds a new `bars` layer to the plot.
 *
 * The `bars` layer is used to create bar charts, which are useful for comparing quantities among discrete categories.
 *
 * 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.
 *
 * ## Bars Aesthetics
 * * **`x`** - The X-coordinate specifying the categories.
 * * **`y`** - The Y-coordinate specifying the height of the bars.
 * * **`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 Usage
 *
 * ```kotlin
 * plot {
 *     bars {
 *         // Positional mapping
 *         x(listOf("Apple", "Banana", "Cherry", "Orange", "Strawberry"))
 *         y(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.bars(block: BarsBuilder.() -> Unit) {
    createLayer(BarsBuilder(this).apply {
        position = Position.dodge()
    }, block)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy