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

io.docops.asciidoc.charts.DrillDownData.kt Maven / Gradle / Ivy

There is a newer version: 2023.20
Show newest version
package io.docops.asciidoc.charts


@ChartDsl
class BarChartModels {
    var width: Int = 800
    var height: Int = 400
    var title = ""
    var subTitle = ""
    var yAxisLabel = ""
    var xAxisLabel = ""
    val legend = mutableListOf()
    val xAxisData = mutableListOf()
    val seriesData = mutableListOf()
    var barChartData: MutableList = mutableListOf()
    var dg = mutableListOf()

    fun data(inputData: BarChartData.() -> Unit) {
        val dt = BarChartData().apply(inputData)
        barChartData.add(dt)
    }

    private fun fromBcToDataGroup() {
        this.barChartData.forEach {
            val list = mutableListOf>()
            it.nameValues.forEach { values ->
                val m = mutableMapOf(values.name to values.value.toDouble())
                list.add(mutableListOf(Data(values.value.toDouble(), values.name)))
            }
            dg.add(DataGroup(dataGroupId = it.name, value = it.value.toDouble(), data = list))
            seriesData.add(Data(it.value.toDouble(), it.name))
            legend.add(it.name)
        }
    }

    private fun xAxisData() {
        barChartData.forEach {
            xAxisData.add(it.name)
        }

    }


    fun validate(): BarChartModels {
        fromBcToDataGroup()
        xAxisData()
        return this
    }

}

@ChartDsl
class BarChartData {
    var name: String = ""
    var value: Number = 0.0
    var nameValues = mutableListOf()
    fun nv(name: String, value: Number) {
        nameValues.add(NameValue(name, value))
    }
}

@ChartDsl
class NameValue(val name: String, val value: Number)

fun barChart(barChartModels: BarChartModels.() -> Unit): BarChartModels {
    return BarChartModels().apply(barChartModels).validate()
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy