Skip to content

Zoomable and Draggable Graphs based-on Jetpack Compose. Supports Android & iOS, Web and Desktop.

License

Notifications You must be signed in to change notification settings

bytebeats/compose-graphs

Repository files navigation

compose-graphs

GitHub latest commit GitHub contributors GitHub issues Open Source? Yes! GitHub forks GitHub stars GitHub watchers

Zoomable and Draggable Graphs based-on Jetpack Compose. Supports Android & iOS, Web and Desktop.

Features

  • Full customization of the various parts of the graph (like the point, line between the points, highlight when selected, the values in x-axis and y-axis, etc...)
  • Supports scrolling, zooming and touch drag selection

How to use

Just add the LineGraph composable and pass it a Plot with all your configuration and customisation. Please take a look at the app app to see the various customisations available. Almost every aspect of the graph is customisable. You can even override the default draw implementations and can draw a Rectangle instead of a Circle, etc. The below code renders the Orange graph that you see in the above screenshots.

@Composable
fun LineGraph1(lines: List<List<PointF>>) {
    LineGraph(
        plot = Plot(
            lines = listOf(
                Plot.Line(
                    points = lines[0],
                    connection = Plot.Connection(LightGreen600, 2.dp),
                    intersection = Plot.Intersection(LightGreen600, 5.dp),
                    highlight = Plot.Highlight(Green900, 5.dp),
                    underline = Plot.Underline(LightGreen600, 0.3F)
                ),
                Plot.Line(
                    points = lines[1], connection = Plot.Connection(Color.LightGray, 2.dp),
                    intersection = Plot.Intersection { center, point ->
                        val px = 2.dp.toPx()
                        val topStart = Offset(center.x - px, center.y - px)
                        drawRect(Color.LightGray, topLeft = topStart, Size(px * 2, px * 2))
                    },
                ),
            ),
            selection = Plot.Selection(
                highlight = Plot.Connection(
                    Green900, strokeWidth = 2.dp, pathEffect = PathEffect.dashPathEffect(
                        floatArrayOf(40F, 20F)
                    )
                )
            ),
        ),
        modifier = Modifier
            .fillMaxWidth()
            .height(180.dp)
    )
}

Stargazers over time

Stargazers over time

Github Stars Sparklines

Sparkline

Contributors

Contributors over time

MIT License

Copyright (c) 2021 Chen Pan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Zoomable and Draggable Graphs based-on Jetpack Compose. Supports Android & iOS, Web and Desktop.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages