All Projects → futuredapp → Donut

futuredapp / Donut

Licence: mit
Doughnut-like graph view capable of displaying multiple datasets with assignable colors

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Donut

Metatron Discovery
Powerful & Easy way for big data discovery
Stars: ✭ 297 (-25.19%)
Mutual labels:  chart
Aachartcore Kotlin
📈📊⛰⛰⛰An elegant modern declarative data visualization chart framework for Android . Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 332 (-16.37%)
Mutual labels:  chart
Britecharts
Client-side reusable Charting Library based on D3.js v5 that allows easy and intuitive use of charts and components that can be composed together creating amazing visualizations.
Stars: ✭ 3,688 (+828.97%)
Mutual labels:  chart
Plotlib
Data plotting library for Rust
Stars: ✭ 308 (-22.42%)
Mutual labels:  chart
Tplink Energy Monitor
An energy monitoring dashboard for TP-Link smart plugs
Stars: ✭ 316 (-20.4%)
Mutual labels:  chart
Vue Tree Chart
A vue2 component to display tree chart
Stars: ✭ 351 (-11.59%)
Mutual labels:  chart
Sparklinelayout
Simple and lightweight library for drawing sparklines / graphs. Support markers and gradients.
Stars: ✭ 291 (-26.7%)
Mutual labels:  chart
React Chartjs 2
React components for Chart.js, the most popular charting library
Stars: ✭ 4,667 (+1075.57%)
Mutual labels:  chart
React Jsx Highcharts
Highcharts built with proper React components
Stars: ✭ 336 (-15.37%)
Mutual labels:  chart
React Vis Force
d3-force graphs as React Components.
Stars: ✭ 372 (-6.3%)
Mutual labels:  chart
Klinechart
📈Lightweight k-line chart that can be highly customized. Zero dependencies. Support mobile.(可高度自定义的轻量级k线图,无第三方依赖,支持移动端)
Stars: ✭ 303 (-23.68%)
Mutual labels:  chart
Colormap Shaders
A collection of shaders to draw color maps.
Stars: ✭ 315 (-20.65%)
Mutual labels:  chart
G2 React
This repo is being deprecated, check Ant Design Charts https://github.com/ant-design/ant-design-charts
Stars: ✭ 360 (-9.32%)
Mutual labels:  chart
Hxcharts
📊 Chart for iOS 仪表盘、柱状图、圆形图、折线图、环形图
Stars: ✭ 301 (-24.18%)
Mutual labels:  chart
Helm
The Kubernetes Package Manager
Stars: ✭ 20,846 (+5150.88%)
Mutual labels:  chart
Rumble Charts
React components for building composable and flexible charts
Stars: ✭ 293 (-26.2%)
Mutual labels:  chart
Reports kit
Beautiful, interactive charts and tables for Ruby on Rails
Stars: ✭ 349 (-12.09%)
Mutual labels:  chart
Hycharts
柱状图、折/曲线图、K线图(主图、交易量图、辅助图), 图与图可以自由组合, 支持分页加载数据 -----> 低内存、低耗电、滑动缩放顺滑
Stars: ✭ 394 (-0.76%)
Mutual labels:  chart
Androidplot
Charts and plots for Android
Stars: ✭ 381 (-4.03%)
Mutual labels:  chart
Angular Echarts
💹 angularjs bindings for baidu echarts
Stars: ✭ 367 (-7.56%)
Mutual labels:  chart

Donut

Download Build Status Android Arsenal Android Weekly License Jetpack Compose

Donut is an Android library which helps you to easily create beautiful doughnut-like charts.

Installation

module/build.gradle:

dependencies {
    implementation("app.futured.donut:library:$version")

    // If you want to use Jetpack Compose version then use only this one dependency
    implementation("app.futured.donut:library-compose:$version")
}

Features

DonutProgressView is a configurable doughnut-like chart view capable of displaying multiple sections with assignable colors. It supports animations and features a gap at the top, which makes it look like a gauge (or tasty bitten-off donut - that's why the name).

Header

The view automatically scales it's sections proportionally to their values once it gets filled up. This allows you to show your users their daily progresses, reached goals, etc.

Usage

Place the view in your layout

<app.futured.donut.DonutProgressView
    android:id="@+id/donut_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:donut_bgLineColor="@color/cloud"
    app:donut_gapWidth="20"
    app:donut_gapAngle="270"
    app:donut_strokeWidth="16dp"/>

Submit data to the view

val section1 = DonutSection(
    name = "section_1",
    color = Color.parseColor("#FB1D32"),
    amount = 1f
)

val section2 = DonutSection(
    name = "section_2",
    color = Color.parseColor("#FFB98E"),
    amount = 1f
)

donut_view.cap = 5f
donut_view.submitData(listOf(section1, section2))

You'll get something like this:

View with cap unexceeded

About the data cap

Once the sum of all section values exceeds view's cap property, the view starts to scale it's sections proportionally to their amounts along it's length. E.g. if we, in the upper example, set cap to donut_view.cap = 1f (section1.amount + section2.amount > 1f), we would get something like this:

View with cap exceeded

Submitting data

The view accepts list of DonutSection objects that define data to be displayed. Each DonutSection object holds section's unique name (string), it's color (color int) and section's value. (Note: the view uses unique name for each section to resolve it's internal state and animations, and throws IllegalStateException if multiple sections with same name are submitted.)

val waterAmount = DonutSection(
    name = "drink_amount_water",
    color = Color.parseColor("#03BFFA"),
    amount = 1.2f
)

You have to submit new list of sections everytime you want to modify displayed data, as DonutSection object is immutable.

donut_view.submitData(listOf(waterAmount))

Granular controls

The view also provides methods for more granular control over displayed data. You can use addAmount, setAmount and removeAmount methods to add, set or remove specified amounts from displayed sections.

Adding amount
donut_view.addAmount(
    sectionName = "drink_amount_water",
    amount = 0.5f,
    color = Color.parseColor("#03BFFA") // Optional, pass color if you want to create new section
)

The addAmount adds specified amount to section with provided name. What if section does not yet exist? This method has one optional color parameter (default value is null) - when called, and there isn't already displayed any section with provided name and color parameter was specified, the new DonutSection with provided name, amount and color will be automatically created internally for you. If you leave the color param null while trying to add value to non-existent section, nothing happens.

Setting amount
donut_view.setAmount(
    sectionName = "drink_amount_water",
    amount = 2.5f
)

The setAmount methods sets specified amount to section with provided name. If provided amount is equal or less than 0, section and corresponding progress line are automatically removed after animation. If view does not contain specified section, nothing happens.

Removing amount
donut_view.removeAmount(
    sectionName = "drink_amount_water",
    amount = 0.1f
)

The removeAmount simply subtracts specified amount from any displayed section. If resulting amount is equal or less than 0, section and corresponding progress line are automatically removed after animation. If view does not contain specified section, nothing happens.

Get and clear data

If you want to get currently displayed data, call getData() method which returns immutable list of all displayed DonutSection objects. To clear displayed data, call clear() method.

Each call to a data method (submit, add, set, remove, clear) results in view automatically resolving and animating to the new state.

Customization

The view allows you to configure various properties to let you create a unique style that fits your needs. They can be changed either via XML attributes, or at runtime via property access.

XML attributes

Name Default value Description
donut_cap 1.0f View's cap property
donut_strokeWidth 12dp Width of background and section lines in dp
donut_strokeCap round The paint cap used for all lines. Can be either 'round' or 'butt'
donut_bgLineColor #e7e8e9 Color of background line
donut_gapWidth 45° Width of the line gap in degrees
donut_gapAngle 90° Position of the line gap around the view in degrees
donut_direction clockwise Progress lines direction (clockwise or anticlockwise)
donut_animateChanges true Animation enabled flag, if true, the view will animate it's state changes (enabled by default)
donut_animationInterpolator DecelerateInterpolator Interpolator to be used in state change animations
donut_animationDuration 1000 ms Duration of state change animations in ms

In addition to these XML attributes, the view features masterProgress property (0f to 1f) that can be changed programatically. It controls percentual progress of all lines, including the background line, which allows you to get creative with startup animations, etc.

Jetpack Compose version

This library is implemented as a standalone module also for Jetpack Compose. It has the same features as the original implementation, but it supports a wider variety of animations.

@Composable
fun Sample() {
    DonutProgress(
        model = DonutModel(
            cap = 8f,
            masterProgress = 1f,
            gapWidthDegrees = 270f,
            gapAngleDegrees = 90f,
            strokeWidth = 40f,
            backgroundLineColor = Color.LightGray,
            sections = listOf(
                DonutSection(amount = 1f, color = Color.Cyan),
                DonutSection(amount = 1f, color = Color.Red),
                DonutSection(amount = 1f, color = Color.Green),
                DonutSection(amount = 0f, color = Color.Blue)
            )
        ),
        config = DonutConfig(
            isGapAngleAnimationEnabled = true,
            gapAngleAnimationBuilder = TweenBuilder()
            // ...
        )
    )
}

Sample app

The quickest way to explore different styles is to try the sample app, which contains an interactive playground with buttons and sliders to fiddle with.

Playground

Contributors

Current maintainer and main contributor for the original version is Matej Semančík and for Jetpack Compose version is Martin Sumera

Licence

Donut is available under MIT license. See LICENSE file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].