/compose-treemap-chart

Jetpack compose treemap chart implementation

Primary LanguageKotlinMIT LicenseMIT

Compose Treemap Chart

Maven Central Build Static analysis codecov Badge-Android Badge-JVM Badge-iOS Badge-JS

Jetpack compose treemap chart implementation

Usage

Adding to the project

Add this to your dependencies gradle block:

implementation "io.github.overpas:treemap-chart:0.1.0"
implementation "io.github.overpas:treemap-chart-compose:0.1.0"

Sample code

private val simpleTreeData = tree(10) {
    node(6) {
        node(4)
        node(2) {
            node(1)
            node(1)
        }
    }
    node(3) {
        node(2)
        node(1)
    }
    node(1)
}

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposetreemapchartTheme {
                Surface(color = MaterialTheme.colors.background) {
                    TreemapChart(
                        data = simpleTreeData,
                        evaluateItem = { it.toDouble() },
                        treemapChartMeasurer = remember { SquarifiedMeasurer() },
                        modifier = Modifier
                            .fillMaxHeight()
                            .fillMaxWidth(),
                    ) { item ->
                        SimpleTreemapItem(item = item.toString())
                    }
                }
            }
        }
    }
}

The code above produces something like this:

For more advanced Kotlin Multiplatform samples check out the /sample directory