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

jsMain.chartjs_builder.kt Maven / Gradle / Ivy

Go to download

"Kraft Extension ChartJs - Javascript charts - https://www.npmjs.com/package/chart.js"

There is a newer version: 0.48.1
Show newest version
package de.peekandpoke.kraft.addons.chartjs

import kotlinx.css.Color

@Suppress("unused")
interface SingleOrArray

typealias StringOrArray = SingleOrArray

typealias NumberOrArray = SingleOrArray

fun chartJsData(builder: ChartJsDataBuilder.() -> ChartConfig): ChartConfig {
    return ChartJsDataBuilder().builder()
}

class ChartJsDataBuilder {

    val colors = arrayOf(
        "#4dc9f6",
        "#f67019",
        "#f53794",
        "#537bc4",
        "#acc236",
        "#166a8f",
        "#00a950",
        "#58595b",
        "#8549ba"
    )

    private var nextColorIdx = 0

    fun nextColor() = Color(colors[nextColorIdx]).also {
        nextColorIdx = (nextColorIdx + 1) % colors.size
    }

    fun  value(value: T) = value.unsafeCast>()

    fun  value(value: Array) = value.unsafeCast>()

    fun  value(vararg value: T) = value.unsafeCast>()

    fun numberLabels(count: Int): Array = ChartJsUtils.numberLabels(count)

    fun numberLabels(range: IntRange): Array = ChartJsUtils.numberLabels(range)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy