├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── themes.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── xml
│ │ │ ├── backup_rules.xml
│ │ │ └── data_extraction_rules.xml
│ │ ├── values-night
│ │ │ └── themes.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── ted
│ │ └── gun0912
│ │ └── rangebarchartdemo
│ │ └── MainActivity.kt
├── proguard-rules.pro
└── build.gradle.kts
├── rangebarchart
├── .gitignore
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── ted
│ │ └── gun0912
│ │ └── rangebarchart
│ │ ├── RangeBarEntry.kt
│ │ ├── RangeBarDataProvider.kt
│ │ ├── RangeBarData.kt
│ │ ├── RangeBarChart.kt
│ │ ├── RangeBarDataSet.kt
│ │ └── RangeBarChartRenderer.kt
├── proguard-rules.pro
└── build.gradle.kts
├── art
├── min_max.png
├── draw_label.png
├── highlight.gif
└── range_bar.png
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── settings.gradle.kts
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/rangebarchart/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/rangebarchart/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/art/min_max.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/art/min_max.png
--------------------------------------------------------------------------------
/art/draw_label.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/art/draw_label.png
--------------------------------------------------------------------------------
/art/highlight.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/art/highlight.gif
--------------------------------------------------------------------------------
/art/range_bar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/art/range_bar.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RangeBarChart
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 | local.properties
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/RangeBarChart/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/rangebarchart/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 14 17:26:36 KST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | mavenCentral()
5 | google()
6 | jcenter()
7 | }
8 | }
9 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
10 |
11 | rootProject.name = "RangeBarChartDemo"
12 | include(":app")
13 | include(":rangebarchart")
14 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarEntry.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import com.github.mikephil.charting.data.Entry
4 |
5 | data class RangeBarEntry(
6 | private val xPosition: Float,
7 | var min: Float,
8 | var max: Float,
9 | ) : Entry(xPosition, (min + max) / 2) {
10 |
11 | override fun copy(): RangeBarEntry = copy()
12 | }
13 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarDataProvider.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider
4 | import ted.gun0912.rangebarchart.RangeBarData
5 |
6 | interface RangeBarDataProvider : BarLineScatterCandleBubbleDataProvider {
7 |
8 | fun getRangeBarData(): RangeBarData
9 | }
10 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarData.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData
4 |
5 | class RangeBarData(dataSets: MutableList = mutableListOf()) :
6 | BarLineScatterCandleBubbleData(dataSets) {
7 |
8 | constructor(dataSet: RangeBarDataSet) : this(mutableListOf(dataSet))
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarChart.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import com.github.mikephil.charting.charts.BarLineChartBase
6 |
7 | class RangeBarChart @JvmOverloads constructor(
8 | context: Context,
9 | attrs: AttributeSet? = null,
10 | defStyleAttr: Int = 0,
11 | ) : BarLineChartBase(context, attrs, defStyleAttr), RangeBarDataProvider {
12 |
13 | override fun getRangeBarData(): RangeBarData = mData
14 |
15 | override fun init() {
16 | super.init()
17 | mRenderer = RangeBarChartRenderer(this, animator, viewPortHandler)
18 |
19 | xAxis.apply {
20 | spaceMin = 0.5f
21 | spaceMax = 0.5f
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/rangebarchart/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | kotlin = "1.6.21"
3 | gradle = "7.2.0"
4 |
5 | # AndroidX
6 | androidx-core = "1.8.0"
7 | androidx-activity = "1.4.0"
8 | androidx-fragment = "1.2.4"
9 | androidx-multidex = "2.0.0"
10 |
11 | # Google
12 | material = "1.6.1"
13 |
14 |
15 | [libraries]
16 | gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
17 | kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
18 |
19 |
20 | # AndroidX
21 | androidx-activity = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" }
22 | androidx-fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "androidx-fragment" }
23 | androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
24 | androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "androidx-multidex" }
25 |
26 |
27 | material = { module = "com.google.android.material:material", version.ref = "material" }
28 |
29 | chart = "com.github.PhilJay:MPAndroidChart:v3.1.0"
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("kotlin-android")
4 | id("kotlin-kapt")
5 | }
6 |
7 | android {
8 | defaultConfig {
9 | applicationId = ApplicationId.id
10 | compileSdk = Config.compileSdk
11 | minSdk = Config.minSdk
12 | targetSdk = Config.targetSdk
13 |
14 | versionCode = Releases.versionCode
15 | versionName = Releases.versionName
16 | multiDexEnabled = true
17 | }
18 |
19 | buildTypes {
20 | named("debug") {
21 | isMinifyEnabled = true
22 | proguardFiles("proguard-rules.pro")
23 | }
24 | named("release") {
25 | isMinifyEnabled = true
26 | proguardFiles(
27 | getDefaultProguardFile("proguard-android-optimize.txt"),
28 | "proguard-rules.pro"
29 | )
30 | }
31 | }
32 |
33 | compileOptions {
34 | sourceCompatibility = JavaVersion.VERSION_11
35 | targetCompatibility = JavaVersion.VERSION_11
36 | }
37 | // For Kotlin projects
38 | kotlinOptions {
39 | jvmTarget = "11"
40 | }
41 |
42 | buildFeatures {
43 | dataBinding = true
44 | }
45 | }
46 |
47 | dependencies {
48 |
49 | implementation(libs.androidx.core)
50 | implementation(libs.material)
51 |
52 | implementation(projects.rangebarchart)
53 | }
54 |
--------------------------------------------------------------------------------
/rangebarchart/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("kotlin-android")
4 | id("kotlin-kapt")
5 | }
6 |
7 | buildscript {
8 | repositories {
9 | mavenCentral()
10 | }
11 | dependencies {
12 | classpath("com.vanniktech:gradle-maven-publish-plugin:0.21.0")
13 | }
14 | }
15 |
16 | android {
17 | defaultConfig {
18 | compileSdk = Config.compileSdk
19 | minSdk = Config.minSdk
20 | targetSdk = Config.targetSdk
21 | multiDexEnabled = true
22 | }
23 |
24 | buildTypes {
25 | named("debug") {
26 | isMinifyEnabled = true
27 | consumerProguardFiles("proguard-rules.pro")
28 | }
29 | named("release") {
30 | isMinifyEnabled = false
31 | proguardFiles(
32 | getDefaultProguardFile("proguard-android-optimize.txt"),
33 | "proguard-rules.pro"
34 | )
35 | }
36 | }
37 |
38 | compileOptions {
39 | sourceCompatibility = JavaVersion.VERSION_1_8
40 | targetCompatibility = JavaVersion.VERSION_1_8
41 | }
42 |
43 | kotlinOptions {
44 | jvmTarget = "1.8"
45 | }
46 |
47 | buildFeatures {
48 | dataBinding = true
49 | }
50 | }
51 |
52 | dependencies {
53 |
54 | implementation(libs.androidx.core)
55 | implementation(libs.material)
56 |
57 | api(libs.chart)
58 | }
59 |
60 | apply {
61 | plugin("com.vanniktech.maven.publish")
62 | }
63 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarDataSet.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import android.graphics.Color
4 | import androidx.annotation.ColorInt
5 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleDataSet
6 | import com.github.mikephil.charting.data.DataSet
7 |
8 | class RangeBarDataSet(yVals: List?, label: String) :
9 | BarLineScatterCandleBubbleDataSet(yVals, label) {
10 |
11 | var barWidth: Float = 0.85f
12 | set(value) {
13 | field = value.coerceIn(0f, 1f)
14 | }
15 |
16 | var isMinMaxEnabled = true
17 |
18 | @ColorInt
19 | var minColor: Int = Color.BLUE
20 | var maxColor: Int = Color.RED
21 |
22 | val maxEntry
23 | get() = mValues
24 | .sortedByDescending { it.min }
25 | .maxByOrNull { it.max }
26 |
27 | val minEntry
28 | get() = mValues
29 | .sortedBy { it.max }
30 | .minByOrNull { it.min }
31 |
32 | override fun getEntryIndex(entry: RangeBarEntry): Int = super.getEntryIndex(entry)
33 |
34 | override fun copy(): DataSet {
35 | val values: List = mValues ?: return RangeBarDataSet(null, label)
36 | val entries = values.map { it.copy() }
37 | return RangeBarDataSet(entries, label).also {
38 | copy(it)
39 | }
40 | }
41 |
42 | protected fun copy(rangeBarDataSet: RangeBarDataSet) {
43 | super.copy(rangeBarDataSet)
44 | rangeBarDataSet.barWidth = barWidth
45 | rangeBarDataSet.isMinMaxEnabled = isMinMaxEnabled
46 | rangeBarDataSet.minColor = minColor
47 | rangeBarDataSet.maxColor = maxColor
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
24 |
25 |
26 | SONATYPE_HOST=S01
27 | RELEASE_SIGNING_ENABLED=true
28 |
29 | GROUP=io.github.ParkSangGwon
30 | POM_ARTIFACT_ID=range-bar-chart
31 | VERSION_NAME=0.0.6
32 |
33 | POM_NAME=RangeBarChart
34 | POM_PACKAGING=aar
35 |
36 | POM_DESCRIPTION=RangeBarChart is bar chart by min/max value(using MPAndroidChart)
37 | POM_INCEPTION_YEAR=2022
38 |
39 | POM_URL=https://github.com/ParkSangGwon/RangeBarChart
40 | POM_SCM_URL=https://github.com/ParkSangGwon/RangeBarChart
41 | POM_SCM_CONNECTION=scm:git:git://github.com/ParkSangGwon/RangeBarChart.git
42 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/ParkSangGwon/RangeBarChart.git
43 |
44 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
45 | POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
46 | POM_LICENCE_DIST=repo
47 |
48 | POM_DEVELOPER_ID=ParkSangGwon
49 | POM_DEVELOPER_NAME=ParkSangGwon
50 | POM_DEVELOPER_URL=https://github.com/ParkSangGwon
51 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/ted/gun0912/rangebarchartdemo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchartdemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.widget.CheckBox
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.github.mikephil.charting.components.XAxis
8 | import com.github.mikephil.charting.formatter.ValueFormatter
9 | import ted.gun0912.rangebarchart.RangeBarChart
10 | import ted.gun0912.rangebarchart.RangeBarData
11 | import ted.gun0912.rangebarchart.RangeBarDataSet
12 | import ted.gun0912.rangebarchart.RangeBarEntry
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private val chart: RangeBarChart by lazy { findViewById(R.id.chart) }
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContentView(R.layout.activity_main)
21 | chart.setup()
22 | chart.addData()
23 | setupListener()
24 | }
25 |
26 | private fun RangeBarChart.setup() {
27 | setScaleEnabled(false)
28 | setDrawGridBackground(false)
29 | setBackgroundColor(Color.TRANSPARENT)
30 | description.isEnabled = false
31 |
32 | xAxis.apply {
33 | position = XAxis.XAxisPosition.BOTTOM
34 | setDrawGridLines(false)
35 | }
36 |
37 | axisLeft.apply {
38 | setDrawGridLines(false)
39 | axisMinimum = -20f
40 | axisMaximum = 40f
41 | }
42 | axisRight.isEnabled = false
43 |
44 | legend.isEnabled = false
45 |
46 | data = RangeBarData(createSet())
47 | }
48 |
49 |
50 | private fun createSet(): RangeBarDataSet =
51 | RangeBarDataSet(null, "RangeBar").apply {
52 | color = Color.parseColor("#2BDD9E")
53 |
54 | barWidth = 0.4f
55 |
56 | isHighlightEnabled = true
57 | highLightColor = Color.CYAN
58 |
59 | minColor = Color.parseColor("#22BCFE")
60 | maxColor = Color.parseColor("#FC351E")
61 |
62 | setDrawValues(false)
63 | valueTextSize = 12f
64 | valueFormatter = object : ValueFormatter() {
65 | override fun getFormattedValue(value: Float): String = "${value.toInt()}°C"
66 | }
67 | }
68 |
69 | private fun RangeBarChart.addData() {
70 |
71 | val data = data ?: return
72 | val rangeBarDataSet = data.getDataSetByIndex(0) ?: return
73 |
74 | val values = getWeatherEntries()
75 |
76 | rangeBarDataSet.values = values
77 | data.notifyDataChanged()
78 | notifyDataSetChanged()
79 | }
80 |
81 | private fun getWeatherEntries(): List {
82 | val values = mutableListOf()
83 | values.add(RangeBarEntry(1f, -7f, 1f))
84 | values.add(RangeBarEntry(2f, -4f, 4f))
85 | values.add(RangeBarEntry(3f, 2f, 11f))
86 | values.add(RangeBarEntry(4f, 8f, 18f))
87 | values.add(RangeBarEntry(5f, 14f, 23f))
88 | values.add(RangeBarEntry(6f, 19f, 26f))
89 | values.add(RangeBarEntry(7f, 23f, 28f))
90 | values.add(RangeBarEntry(8f, 25f, 33f))
91 | values.add(RangeBarEntry(9f, 17f, 25f))
92 | values.add(RangeBarEntry(10f, 10f, 18f))
93 | values.add(RangeBarEntry(11f, 3f, 11f))
94 | values.add(RangeBarEntry(12f, -3f, 4f))
95 | return values
96 | }
97 |
98 | private fun setupListener() {
99 | findViewById(R.id.cb_show_min_max).setOnCheckedChangeListener { _, isChecked ->
100 | for (dataSet in chart.data.dataSets) {
101 | dataSet.isMinMaxEnabled = isChecked
102 | }
103 | chart.invalidate()
104 | }
105 |
106 | findViewById(R.id.cb_show_value).setOnCheckedChangeListener { _, isChecked ->
107 | chart.data.setDrawValues(isChecked)
108 | chart.invalidate()
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RangeBarChart
2 | ⚡ Range bar chart library for Android using [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart)⚡
3 |
4 | - There were no charts in [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart) to show ranges.
5 | - We were forced to show the range charts we wanted using a similarly capable candlestick chart.
6 | - This library can be used when you want to create charts that can represent ranges such as weather and heart rate.
7 |
8 |
9 | | Default | Min/Max | Draw Label |
10 | | :----------------:| :----------------: | :----------------: |
11 | | | ||
12 |
13 |
14 | ## Demo
15 | 
16 |
17 |
18 |
19 | ## Setup
20 |
21 | ### Gradle
22 | [](https://search.maven.org/search?q=g:%22io.github.ParkSangGwon%22%20AND%20a:%range-bar-chart%22)
23 |
24 | ```gradle
25 |
26 | repositories {
27 | google()
28 | mavenCentral()
29 | maven { url 'https://jitpack.io' } // For using MPAndroidChart
30 | }
31 |
32 | dependencies {
33 | implementation 'io.github.ParkSangGwon:range-bar-chart:x.y.z'
34 | //implementation 'io.github.ParkSangGwon:range-bar-chart:0.0.6'
35 | }
36 |
37 | ```
38 |
39 | If you think this library is useful, please press star button at upside.
40 |
41 |
42 |
43 |
44 | ## How to use
45 | - The usage of this library is perfectly consistent with that of [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart)
46 | - Please read [official document](https://weeklycoding.com/mpandroidchart-documentation/)
47 | - A detailed explanation can be understood immediately by looking at the code of the sample project.
48 |
49 | ## RangeBarEntry
50 | - min
51 | - max
52 |
53 | ## Setup Chart
54 | ```kotlin
55 | private fun RangeBarChart.setup() {
56 | setScaleEnabled(false)
57 | setDrawGridBackground(false)
58 | setBackgroundColor(Color.TRANSPARENT)
59 | description.isEnabled = false
60 | xAxis.apply {
61 | position = XAxis.XAxisPosition.BOTTOM
62 | setDrawGridLines(false)
63 | }
64 | axisLeft.apply {
65 | setDrawGridLines(false)
66 | axisMinimum = -20f
67 | axisMaximum = 40f
68 | }
69 | axisRight.isEnabled = false
70 | legend.isEnabled = false
71 | data = RangeBarData(createSet())
72 | }
73 | ```
74 |
75 | ## Create DataSet
76 | ```kotlin
77 | RangeBarDataSet(null, "RangeBar").apply {
78 | color = Color.parseColor("#2BDD9E")
79 | barWidth = 0.4f
80 | isHighlightEnabled = true
81 | highLightColor = Color.CYAN
82 | minColor = Color.parseColor("#22BCFE")
83 | maxColor = Color.parseColor("#FC351E")
84 | setDrawValues(false)
85 | valueTextSize = 12f
86 | valueFormatter = object : ValueFormatter() {
87 | override fun getFormattedValue(value: Float): String = "${value.toInt()}°C"
88 | }
89 | }
90 | ```
91 | ## Add your entries
92 | ```kotlin
93 | private fun getWeatherEntries(): List {
94 | val values = mutableListOf()
95 | values.add(RangeBarEntry(1f, -7f, 1f))
96 | values.add(RangeBarEntry(2f, -4f, 4f))
97 | values.add(RangeBarEntry(3f, 2f, 11f))
98 | values.add(RangeBarEntry(4f, 8f, 18f))
99 | values.add(RangeBarEntry(5f, 14f, 23f))
100 | values.add(RangeBarEntry(6f, 19f, 26f))
101 | values.add(RangeBarEntry(7f, 23f, 28f))
102 | values.add(RangeBarEntry(8f, 25f, 33f))
103 | values.add(RangeBarEntry(9f, 17f, 25f))
104 | values.add(RangeBarEntry(10f, 10f, 18f))
105 | values.add(RangeBarEntry(11f, 3f, 11f))
106 | values.add(RangeBarEntry(12f, -3f, 4f))
107 | return values
108 | }
109 | ```
110 | ```kotlin
111 | private fun RangeBarChart.addData() {
112 | val data = data ?: return
113 | val rangeBarDataSet = data.getDataSetByIndex(0) ?: return
114 | val values = getWeatherEntries()
115 | rangeBarDataSet.values = values
116 | data.notifyDataChanged()
117 | notifyDataSetChanged()
118 | }
119 | ```
120 |
121 |
122 |
123 |
124 | ## Customize
125 | ### RangeBarDataSet
126 |
127 | | variable | Description |
128 | | ----------------------- | ---------------- |
129 | | `barWidth` | Adjust board width |
130 | | `minColor` | Min color int |
131 | | `maxColor` | Max color int |
132 |
133 | ## FAQ
134 |
135 | ### Can I use BarChart's function/variable?
136 | - Yes, RangeBarChart is a class implemented by inheriting from BarChart.
137 | - So you can use all the features that BarChart uses.
138 |
139 |
140 | ### How is it different from candlestick charts?
141 | - Candle charts must specify a starting and ending point as well as a minimum and maximum.
142 | - It is used for the purpose of using stock charts, not to display only the range we want.
143 | - RangeBarChart only shows the minimum and maximum ranges.
144 |
145 |
146 |
147 | ## License
148 |
149 | ````code
150 | Copyright 2022 Ted Park
151 |
152 | Licensed under the Apache License, Version 2.0 (the "License");
153 | you may not use this file except in compliance with the License.
154 | You may obtain a copy of the License at
155 |
156 | http://www.apache.org/licenses/LICENSE-2.0
157 |
158 | Unless required by applicable law or agreed to in writing, software
159 | distributed under the License is distributed on an "AS IS" BASIS,
160 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
161 | See the License for the specific language governing permissions and
162 | limitations under the License.```
163 | ````
164 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/rangebarchart/src/main/java/ted/gun0912/rangebarchart/RangeBarChartRenderer.kt:
--------------------------------------------------------------------------------
1 | package ted.gun0912.rangebarchart
2 |
3 | import android.graphics.Canvas
4 | import android.graphics.Paint
5 | import android.graphics.RectF
6 | import com.github.mikephil.charting.animation.ChartAnimator
7 | import com.github.mikephil.charting.formatter.ValueFormatter
8 | import com.github.mikephil.charting.highlight.Highlight
9 | import com.github.mikephil.charting.renderer.BarLineScatterCandleBubbleRenderer
10 | import com.github.mikephil.charting.utils.Transformer
11 | import com.github.mikephil.charting.utils.Utils
12 | import com.github.mikephil.charting.utils.ViewPortHandler
13 |
14 | class RangeBarChartRenderer(
15 | private val chart: RangeBarDataProvider,
16 | animator: ChartAnimator,
17 | viewPortHandler: ViewPortHandler
18 | ) : BarLineScatterCandleBubbleRenderer(animator, viewPortHandler) {
19 |
20 | override fun initBuffers() {
21 |
22 | }
23 |
24 | override fun drawData(canvas: Canvas) {
25 |
26 | val rangeBarData: RangeBarData = chart.getRangeBarData()
27 |
28 | for (index in 0 until rangeBarData.dataSetCount) {
29 | val set = rangeBarData.getDataSetByIndex(index)
30 | if (set.isVisible) {
31 | drawDataSet(canvas, set)
32 | }
33 | }
34 | }
35 |
36 | protected fun drawDataSet(canvas: Canvas, dataSet: RangeBarDataSet) {
37 |
38 | val transformer: Transformer = chart.getTransformer(dataSet.axisDependency)
39 | mRenderPaint.style = Paint.Style.FILL
40 |
41 | val minEntry = dataSet.minEntry
42 | val maxEntry = dataSet.maxEntry
43 | val barWidth = dataSet.barWidth
44 |
45 | mXBounds[chart] = dataSet
46 | for (index in mXBounds.min..mXBounds.range + mXBounds.min) {
47 | val entry: RangeBarEntry = dataSet.getEntryForIndex(index)
48 | val rect = getRect(entry, transformer, barWidth)
49 |
50 | when {
51 | !dataSet.isMinMaxEnabled -> mRenderPaint.color = dataSet.color
52 | entry == minEntry -> {
53 | mRenderPaint.color = dataSet.minColor
54 | dataSet.minEntry?.let { drawMinMaxValue(canvas, dataSet, it) }
55 | }
56 | entry == maxEntry -> {
57 | mRenderPaint.color = dataSet.maxColor
58 | dataSet.maxEntry?.let { drawMinMaxValue(canvas, dataSet, it) }
59 | }
60 | else -> mRenderPaint.color = dataSet.color
61 | }
62 | canvas.drawRect(rect, mRenderPaint)
63 |
64 | }
65 |
66 | }
67 |
68 | private fun drawMinMaxValue(
69 | canvas: Canvas,
70 | dataSet: RangeBarDataSet,
71 | entry: RangeBarEntry
72 | ) {
73 | if (dataSet.isDrawValuesEnabled) {
74 | return
75 | }
76 | val transformer: Transformer = chart.getTransformer(dataSet.axisDependency)
77 | applyValueTextStyle(dataSet)
78 | drawValue(
79 | canvas,
80 | entry,
81 | transformer,
82 | dataSet.valueFormatter,
83 | dataSet.valueTextSize,
84 | dataSet.valueTextColor
85 | )
86 | }
87 |
88 | private fun getRect(entry: RangeBarEntry, transformer: Transformer, barWidth: Float) =
89 | RectF().apply {
90 | val xPosition = entry.x
91 |
92 | left = xPosition - barWidth / 2
93 | right = xPosition + barWidth / 2
94 | top = entry.max
95 | bottom = entry.min
96 |
97 | transformer.rectToPixelPhase(this, mAnimator.phaseY)
98 | }
99 |
100 | override fun drawValues(canvas: Canvas) {
101 | if (!isDrawingValuesAllowed(chart)) {
102 | return
103 | }
104 | chart.getRangeBarData().dataSets
105 | .filter { shouldDrawValues(it) && it.entryCount > 0 }
106 | .forEach { dataSet ->
107 | drawValue(canvas, dataSet)
108 | }
109 | }
110 |
111 | private fun drawValue(canvas: Canvas, dataSet: RangeBarDataSet) {
112 | if (!dataSet.isDrawValuesEnabled) {
113 | return
114 | }
115 | applyValueTextStyle(dataSet)
116 | mXBounds[chart] = dataSet
117 | val transformer: Transformer = chart.getTransformer(dataSet.axisDependency)
118 | for (index in mXBounds.min..mXBounds.range + mXBounds.min) {
119 | val entry: RangeBarEntry = dataSet.getEntryForIndex(index)
120 | drawValue(
121 | canvas,
122 | entry,
123 | transformer,
124 | dataSet.valueFormatter,
125 | dataSet.valueTextSize,
126 | dataSet.valueTextColor
127 | )
128 | }
129 | }
130 |
131 | private fun drawValue(
132 | canvas: Canvas,
133 | entry: RangeBarEntry,
134 | transformer: Transformer,
135 | valueFormatter: ValueFormatter,
136 | textSize: Float,
137 | textColor: Int
138 | ) {
139 | val yOffset = Utils.convertDpToPixel(TEXT_VALUE_MARGIN_DP)
140 |
141 | val rect = getRect(entry, transformer, 0f)
142 | val maxY = rect.top
143 | val minY = rect.bottom
144 |
145 | // draw max
146 | drawValue(
147 | canvas,
148 | valueFormatter.getFormattedValue(entry.max),
149 | rect.centerX(),
150 | (maxY - yOffset),
151 | textColor,
152 | )
153 |
154 | // draw min
155 | drawValue(
156 | canvas,
157 | valueFormatter.getFormattedValue(entry.min),
158 | rect.centerX(),
159 | (minY + yOffset + textSize * 0.7f),
160 | textColor,
161 | )
162 | }
163 |
164 | override fun drawValue(c: Canvas, valueText: String, x: Float, y: Float, color: Int) {
165 | mValuePaint.color = color
166 | c.drawText(valueText, x, y, mValuePaint)
167 | }
168 |
169 | override fun drawExtras(c: Canvas) {
170 |
171 | }
172 |
173 | override fun drawHighlighted(canvas: Canvas, indices: Array) {
174 |
175 | val rangeBarData = chart.getRangeBarData()
176 | for (highlight in indices) {
177 | val rangeBarDataSet = rangeBarData.getDataSetByIndex(highlight.dataSetIndex)
178 | if (rangeBarDataSet == null || !rangeBarDataSet.isHighlightEnabled) {
179 | continue
180 | }
181 | val entry = rangeBarDataSet.getEntryForXValue(highlight.x, highlight.y)
182 | if (!isInBoundsX(entry, rangeBarDataSet)) continue
183 | mHighlightPaint.apply {
184 | color = rangeBarDataSet.highLightColor
185 | style = Paint.Style.FILL
186 | }
187 | drawHighlight(canvas, mHighlightPaint, rangeBarDataSet, entry)
188 | }
189 | }
190 |
191 | private fun drawHighlight(
192 | canvas: Canvas,
193 | paint: Paint,
194 | dataSet: RangeBarDataSet,
195 | entry: RangeBarEntry
196 | ) {
197 | val transformer = chart.getTransformer(dataSet.axisDependency)
198 | val barWidth = dataSet.barWidth
199 | val rect = getRect(entry, transformer, barWidth)
200 | canvas.drawRect(rect, paint)
201 |
202 | if (!dataSet.isDrawValuesEnabled) {
203 | applyValueTextStyle(dataSet)
204 | drawValue(
205 | canvas,
206 | entry,
207 | transformer,
208 | dataSet.valueFormatter,
209 | dataSet.valueTextSize,
210 | dataSet.valueTextColor
211 | )
212 | }
213 | }
214 |
215 | companion object {
216 |
217 | private const val TEXT_VALUE_MARGIN_DP = 6f
218 | }
219 | }
220 |
--------------------------------------------------------------------------------