jsMain.chartjs_builder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addons-chartjs Show documentation
Show all versions of addons-chartjs Show documentation
"Kraft Extension ChartJs - Javascript charts - https://www.npmjs.com/package/chart.js"
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)
}