Coder Social home page Coder Social logo

mahozad / android-pie-chart Goto Github PK

View Code? Open in Web Editor NEW
43.0 2.0 6.0 31.79 MB

Highly customizable Android library for drawing Pie and Donut charts.

Home Page: https://mahozad.ir/android-pie-chart

License: Apache License 2.0

Kotlin 99.90% CSS 0.10%
android android-library chart charting-library charting pie-chart donut-chart piechart donutchart visualization

android-pie-chart's Introduction

android-pie-chart's People

Contributors

mahozad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

android-pie-chart's Issues

Improve the test application

Add every property of the chart to the test app screen as buttons, sliders, etc. so that the chart can be modified to get immediate feedback and to design a desired shape, color, ... for the chart and also to test all combinations of properties of the chart manually if required.

Also, create a java class and test the library in it to see if it works with java as well.

  • Rename the test subproject to something more appropriate like showcase or preview or demo or exhibition.
  • Use ComponentActivity as the base class of the activities. See https://developer.android.com/reference/androidx/activity/ComponentActivity
  • Mention in the README that "Each release is shipped with the showcase APK. You can download it in the assets section of each release."

Implement wedge-style slice gaps

Add a new wedge-shaped gap type to the existing rectangular gap type.

It should support gap placements like the rectangular gap.

Also add the necessary property(ies) for the user to choose their desired gap type.

Add screenshot tests

Use a library to add screenshot tests as acceptance tests to ensure the final appearance of the chart is appropriate.

The two libraries defined below do not support running screenshot tests on Windows 10.
Use them when/if they support Windows 10 (though it might be late to this because most of the library features will have been implemented by that time and writing tests afterwards may not be so useful).
Refer to this issue for shot and this section for screenshot-tests-for-android to see if they have started to support Windows 10 or not.

See this (note how it saves the images and compares them. Also note that it reads screenshots from the assets directory).

Possible libraries:

Another solution:

Can we use "Emulator Snapshots for test failures" available in newer versions of Android Studio?

Implement default color sets for slices

See #26.

Add some default color sets to use as slice colors.
Each color set must be available in two variants: single color for the slice or gradient for the slice.

Can we somehow use themes and styles for this?
We can have some default styles in our library that users can use.

<resource>
  <style name="ColorfulStyle">
    <item name="gap">4dp</item>
    ...
  </style>
</resource>
<ir.mahoza.android.piechart
  style="@style/ColorfulStyle"
... />

Possible options could be:

  • Monochrome: One shade of color with different lightness or saturation
  • Colorful 1: bright colors
  • Colorful 2: dim colors
  • Colorful 3: ...
  • Grayscale: varying shades of gray color

Create a logo for the library

See the following good examples:

  • IntelliJ brand

  • TensorFlow brand guidelines and brand assets

  • logo for the library itself

  • logo and icons for the showcase (test) app

  • Update the IntelliJ project icon and add it to VCS

  • Update the social preview image on repository GitHub settings

  • Can place the logo and branding assets in a directory in repository named extras or artwork or branding or visual style or brand guideline

Backdrop filter for SVG

Implement new slice value mode

Currently the slice accepts a fraction number between 0 and 1. The sum of the all slice fractions should be <= 1 (it could be less than one; in that case the remaining fraction of the chart is shown empty. See this issue).

Add a new mode to interpret slice values as quantity so the fraction of each slice is calculated by the chart itself.

  • Rename Slice::fraction to Slice::value
  • Add a property to the chart for the user to select the slice value type (FRACTION|QUANTITY)
  • If sum of the slice values is greater than 1, interpret the value type as QUANTITY no matter what value type user specified

Expand and improve the documentation on GitHub

Also see #32.

Add images of the chart, add wiki, add how-tos and so on.

Add a table specifying the available chart properties and their default values.

Add a section about how to do certain things with the chart:

  • How to disable the labels without having to set all the labels to empty string?

    Use LabelType::NONE

  • How to disable the legends without having to set all the labels to empty string?

    Use LegendType::NONE

It is possible to upload videos on GitHub. Create a showcase video of the library and embed it in the README.

Add a Persian version of the documentation (or readme)?

Add resource version of functions for setting attributes

In addition to a direct method for updating a property (like chart.setColor(color: Int)), provide a resource version of the method that takes a resource and resolves the value automatically (like chart.setColor(R.color.myColor)) for each property.

This is something practiced in Android Material components. See this for an example.

Also, add separate properties to modify a dimension in sp or dp.
For example, legendSize, legendSizeSp.

Implement sorting slices

Add a property to chart to sort the slices based on their value in asc or desc order.

Should also be able to disable the sorting.

Implement linear gradient

Add ability to specify a linear gradient with a desired angle for the whole chart (does it make sense to have a linear gradient for each slice separately?) (see this post and this post).

Make the chart interactive

Add property to make slices react when touched or clicked.

Can also implement a new label type called something like touchable label type which shows the label of each slice when touched.

Fix the javadoc artifact having no content in releases

The javadoc.jar artifact has no javadoc in it. For example, this javadoc for version 0.4.0 of the library.

See this post and this post and this page and also dokka homepage for setting up kdoc in Android.

Important

If the docs cannot be generated offline, add this block of code to the build script:

val dokka by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
dokka.configure<org.jetbrains.dokka.gradle.DokkaTask> {
    dokkaSourceSets {
        named("main") {
            noAndroidSdkLink.set(false)
        }
    }
}

See this and this and Kotlin/dokka#1706 for more information about the noAndroidSdkLink property.

Implement chart empty background

When/If slice values do not sum to 1, show a background for the empty remaining fraction.

A light gray may be a good default color for this background.

  • The user should be able to specify the color and opacity of the background
  • The user should be able to disable this background (can also set opacity to 0?)

Implement legends

Implement legends for the chart.

  • legend, legendSize, icon, iconHeight, iconTint, iconTransparency, iconMargin, percent, percentSize, percentMargin
  • Legends margin from the pie
  • Margin between each legend
  • Legends title
  • Legend title margin
  • Margin between lines if legends are so many that they constitute multiple lines
  • Custom legend icon
  • Box for legends
    • Background color
    • Box padding
    • Box border
      • Border thickness
      • Border color
      • Border shape (solid, dashed, ...)
      • Border corner radius
  • Property for aligning legend box in the view (center, start, end)

At the very least these legends should be supported:

  • horizontal top
  • horizontal bottom
  • vertical left/start
  • vertical right/end
  • vertical in-hole

Implement in-hole label

The labels will be like normal inside labels (totally horizontal), except that they are placed in the hole of the chart.

Implement scaling of the slices

Add a property to Slice class to be able to scale a slice to a value less than default (1).

Lower scale means the radius of the slice will be smaller.

Set up CI/CD for the project

Configure CI/CD for the library either with GitHub or with Travis CI (other tutorial 1, other tutorial 2).

  • Update the ciManagement in publishing block of the build script
  • Create and publish the test app APK in the GitHub release
  • Add or update the badge for CI/CD in the main README
  • Disable force push to prod branch in IntelliJ
  • Disable force push to prod branch in GitHub

Implement center label

Add ability to specify a label/icon in the center of the chart.

The chart hole is not modified and may overlap with the center label/icon (because the user may want that behavior).

It is up to the user to make sure the hole is big enough to accommodate the center label/icon, if he wants no overlap.

Implement automatic last slice

Relates to #7.
Add a property to chart so if user enables it, if the slice value in in FRACTION mode and sum of all slice values is < 1, then the chart automatically adds the last slice.

Also, add a property to specify the properties of the last slice (like its label, color, etc).

Convert instrumentation tests to unit tests where possible

This makes the tests a lot easier and faster to run.
We can use Robolectric (at the time of writing this, it does not support JUnit 5).

If you want to run Robolectric tests with Junit 4 (using @RunWith and @org.junit.Test etc), remember to include testImplementation("org.junit.vintage:junit-vintage-engine:5.7.2") dependency in the build script.

Remeber to delete the excludeEngines("junit-vintage") from the following block of code in piechart build script so we can run JUnit 4 tests as well with the vintage engine (why was it excluded in the first place?):

useJUnitPlatform {
     excludeEngines("junit-vintage")
 }

See this and this for an example.

  • Remember to update the GitHub workflows as well

Implement outside all-side label

The labels can be placed on any sides of the chart.

  • Each line should be customizable (its length, color, thickness, butt or rounded tip, etc.)
  • A customizable icon could be specified for the start of each line

Make the library extensible and pluggable

It is another way of saying "Make the library obey the dependency inversion principle".

Users should be able to add their own extensions or modifications to the library (like a custom labeling, custom animation, etc.)

See this and this.

Create a website for the library

In addition to #4, generate documentations, examples, etc. on a website using GitHub Pages.

The initial version of the website has been created in the website branch of the repository.

To show colored code in the site, create a gist in GitHub for that snippet of code and use its embed link in the site (customizing the gist).
We can also use online syntax highlighters such as this or this.

Testing the website performance: https://developers.google.com/speed/pagespeed/insights/

Add a header to site and add the following CSS property to it which results in something like header of this site (See this Stack Overflow post):

header {
  backdrop-filter: blur(4px);
}

Remember that dokka can produce a jekyll format as well.

Static site generators:

Websites and templates to inspire from:
https://google.github.io/accompanist/insets/
https://developer.chrome.com/tags/devtools-engineering/
https://www.kernel.org/
https://probot.github.io/docs/
https://docs.botui.org/
https://cssgradient.io/
https://fossheim.io/writing/posts/css-text-gradient/
https://doks.netlify.app/docs/prologue/commands/
https://geekdocs.de/
https://themes.gohugo.io/themes/hugo-changelog-theme/
https://github.com/pmarsceill/just-the-docs
https://github.com/collections/github-pages-examples
https://sighingnow.github.io/jekyll-gitbook
https://supunkavinda.github.io/jekyll-theme-leaf/
https://pmarsceill.github.io/just-the-docs/docs/configuration/
http://alexander.heimbu.ch/millidocs/
https://orderedlist.com/minimal/
https://docs.docker.com/
https://www.vectary.com/
https://github.com/wikimedia/wikimedia.github.io
https://kit.svelte.dev/

Screenshot (182)

candidate page background color: #faf7f4 (adopted from this site)

Implement secondary label

Add ability to specify a secondary (second line) label (along with the main label) for each slice.

Should also be able to specify the margin between the two labels.

The two labels will be horizontally centered with respect to each other.

  • Update the center label as well

Promote and advertise the library

Implement chart animations

Add some default animations to choose from.

For implementing animations, instead of reflowing all the subcomponents, we can simply use canvas::transform on the container or other similar functionalities of the canvas.

Instead of embeding the animation code into every component, we can create an animator class for each type of component and compose it with that component so it can manipulate that component properties. This way we obey single responsibility principle; component does not have to care about implementing the animations; it just cares about drawing itself.
This can be done with Decorator pattern, meaning the animator class has the same type as the component it animates.

https://youtu.be/N_x7SV3I3P0
https://youtu.be/ZTJkLtQXEfY
https://youtu.be/Ldz42dbUsQ0

  • Add a property so when it is enabled, updates to chart properties happen with animation.
  • The properties of the chart should be updatable while the chart is animating

https://proandroiddev.com/android-bring-life-to-your-custom-view-8604ab3967b3
https://medium.com/androiddevelopers/custom-canvas-animations-in-jetpack-compose-e7767e349339
https://www.raywenderlich.com/2785491-android-animation-tutorial-with-kotlin

Implement logarithmic scale

Add a property to chart to show slices in logarithmic scale.

Also, add a property for the user to be able to specify the base of the logarithm.

Add debug version of the library

This could be enabled by adding a property to the chart or maybe by implementing another flavor of the chart like a debug flavor.

See page 282 of the book *Grokking Simplicity *

We can use the Decorator pattern to implement this feature, meaning creating a debug version of a component that composes with that component and has the same type as that component and adds some additional feature to that component (here the debug feature).

For example, to implement a logger version of a component, we can subclass from that component and implement the same methods with logging. See Clean code, Episode 9, 36:00 for an example.

  • Implement showing layout boundaries, angles, paddings, etc. (Android already has this in Settings -> Developer Options)
  • Implement logging

Add a jetpack compose variant of the library

Can we add another Gradle module that implements the library for Jetpack Compose?

The compose version can be used in the compose for desktop which in turn can be shipped to Web, Windows, Linux, MacOs (Compose for Web currently does not allow you to directly reuse existing widgets (unlike the Android and Desktop targets for Jetpack Compose, which allow direct code sharing for most widgets out of the box)).
For an example, see sample number 6 in this page.

See the following Stack Overflow post: How to migrate my custom view to Jetpack Compose?.

Implementation:

  • Should have unit tests and screenshot tests
  • Should have an adapter so it can be used and configured in traditional View xml files

Videos:


Can we convert the library to Kotlin multiplatform so it can be used on other platforms like Web and IOS?

Implement outside double-side label

The labels will be placed only on the sides of the chart.

  • Each line should be customizable (its length, color, thickness, butt or rounded tip, etc.)
  • A customizable icon could be specified for the start of each line

Make unit test assertions more strict

In unit tests that compare floating point numbers, update the assertions to compare with 0.01 precision instead of current 1.

This is because current comparisons may give false negative results, that is, pass when they should have failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.