Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump/improvements #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ android {

dependencies {
implementation(project(":charty"))
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.core:core-ktx:_'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:_'
implementation 'androidx.activity:activity-compose:_'
implementation platform('androidx.compose:compose-bom:_')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
testImplementation 'junit:junit:_'
androidTestImplementation 'androidx.test.ext:junit:_'
androidTestImplementation 'androidx.test.espresso:espresso-core:_'
androidTestImplementation platform('androidx.compose:compose-bom:_')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ buildscript {
}

plugins {
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'com.android.application' version '8.1.0' apply false
id 'com.android.library' version '8.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
id("org.jetbrains.dokka") version "1.8.20"
}
22 changes: 13 additions & 9 deletions charty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ android {
buildFeatures {
compose true
}
lint {
abortOnError false
warningsAsErrors true
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.7'
}
Expand All @@ -50,12 +54,12 @@ mavenPublishing {
}
dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.core:core-ktx:_'
implementation 'androidx.appcompat:appcompat:_'
implementation 'com.google.android.material:material:_'

//Compose
implementation platform('androidx.compose:compose-bom:2023.05.01')
implementation platform('androidx.compose:compose-bom:_')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
Expand All @@ -65,12 +69,12 @@ dependencies {
implementation 'androidx.compose.material:material-icons-extended'

//time
implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.4.0'
lintChecks('com.slack.lint.compose:compose-lint-checks:1.2.0')
implementation 'org.jetbrains.kotlinx:kotlinx-datetime:_'
lintChecks('com.slack.lint.compose:compose-lint-checks:_')

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:_'
androidTestImplementation 'androidx.test.espresso:espresso-core:_'

dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.8.20")
dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:_")
}
4 changes: 3 additions & 1 deletion charty/src/main/java/com/himanshoe/charty/area/AreaChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ fun AreaChart(
axisConfig: AxisConfig = ChartDefaults.axisConfigDefaults(),
padding: Dp = 16.dp,
) {
val items = areaData.data.flatMap { it.points }
val items = remember(areaData) {
areaData.data.flatMap { it.points }
}
val maxValue = items.maxOrNull() ?: 0F
val minValue = items.minOrNull() ?: 0f
var chartWidth by remember { mutableStateOf(0F) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -96,7 +95,6 @@ fun BubbleChart(
val maxVolumeSize = data.maxOf { it.volumeSize }

dataCollection.data.fastForEachIndexed { index, data ->

if (data is BubbleData) {
val bubbleRadius =
data.volumeSize / maxVolumeSize * 50 // Adjust the scaling factor here
Expand All @@ -106,9 +104,9 @@ fun BubbleChart(
.coerceIn(0f, chartHeight - bubbleRadius * 2) + bubbleRadius

drawCircle(
color = Color.Blue,
brush = contentColor,
radius = bubbleRadius,
center = Offset(x, y)
center = Offset(x = x, y = y)
)
if (points.count() < 14) {
drawXAxisLabels(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ fun CandleStickChart(
padding: Dp = 16.dp,
candleConfig: CandleStickConfig = CandleStickDefaults.defaultCandleStickConfig(),
) {
val listOfAxisValues = candleData.data.flatMap { listOf(it.high, it.low, it.open, it.close) }
.distinct()
.sorted()

val listOfAxisValues = remember(candleData.data) {
candleData.data.flatMap { listOf(it.high, it.low, it.open, it.close) }
.distinct()
.sorted()
}
val maxValue = candleData.data.maxOf { maxOf(it.high, it.open, it.close) }
val minValue = candleData.data.minOf { minOf(it.low, it.open, it.close) }

Expand Down
19 changes: 17 additions & 2 deletions charty/src/main/java/com/himanshoe/charty/gauge/GaugeChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.himanshoe.charty.gauge

import android.graphics.Paint
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.tween
Expand All @@ -24,6 +25,8 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.preview.Preview
import com.himanshoe.charty.gauge.config.GaugeChartConfig
import com.himanshoe.charty.gauge.config.GaugeChartDefaults
Expand Down Expand Up @@ -53,7 +56,7 @@ fun GaugeChart(
animated: Boolean = true,
animationSpec: AnimationSpec<Float> = tween(),
) {
require(percentValue in 1..100) { "percentValue must be within the range of 1 to 100" }
require(percentValue in 0..100) { "percentValue must be within the range of 1 to 100" }

val animatedPercent = rememberAnimatedPercent(animated, percentValue, animationSpec)
Box(modifier = modifier.aspectRatio(1f)) {
Expand Down Expand Up @@ -142,6 +145,18 @@ fun GaugeChart(
style = Stroke(width = needleConfig.strokeWidth, cap = StrokeCap.Round)
)
}
if (gaugeChartConfig.showText) {
drawContext.canvas.nativeCanvas.drawText(
"$percentValue %",
center.x,
size.height - size.height / 4,
Paint().apply {
color = gaugeChartConfig.textColor.toArgb()
textSize = size.width / 25
textAlign = Paint.Align.CENTER
}
)
}
}
}
}
Expand Down Expand Up @@ -182,7 +197,7 @@ private fun rememberAnimatedPercent(

@Preview
@Composable
fun GaugeChartPreview() {
private fun GaugeChartPreview() {
val percentValue = 100
GaugeChart(percentValue = percentValue)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.ui.graphics.Color
*
* @param placeHolderColor The color of the placeholder arc in the gauge chart.
* @param primaryColor The color of the primary arc in the gauge chart.
* @param textColor The color of the text in the gauge chart.
* @param showText Indicates whether to show the text in the gauge chart.
* @param strokeWidth The width of the arcs in the gauge chart.
* @param showNeedle Indicates whether to show the needle in the gauge chart.
* @param showIndicator Indicates whether to show the indicator in the gauge chart.
Expand All @@ -30,5 +32,7 @@ data class GaugeChartConfig(
val showNeedle: Boolean,
val showIndicator: Boolean,
val indicatorColor: Color,
val textColor: Color,
val showText: Boolean,
val indicatorWidth: Float,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ object GaugeChartDefaults {
strokeWidth = 48F,
showNeedle = true,
showIndicator = true,
showText = true,
indicatorColor = Color(0xffed625d),
textColor = Color(0xffed625d),
indicatorWidth = 8F
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ fun GroupedBarChart(
) {
require(barWidthRatio in 0.4f..0.9f) { "barWidthRatio must be within the range of 0.4F to 0.9F, but use 0.8F for best looking View" }

val allDataPoints = groupBarDataCollection.data.flatMap { it.dataPoints }
val allDataPoints = remember(groupBarDataCollection.data) {
groupBarDataCollection.data.flatMap { it.dataPoints }
}
val maxValue = allDataPoints.maxOrNull() ?: 0f
val minValue = allDataPoints.minOrNull() ?: 0f
val newItems = if (allDataPoints.min() > 0F) {
Expand Down
5 changes: 4 additions & 1 deletion docs/GAUGECHART.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ To use the GaugeChart, follow the steps below:
- Include the Charty library in your Android project.
- Use the `GaugeChart` composable in your code:

```kotlin @Composable
```kotlin
@Composable
fun GaugeChart(
percentValue: Int,
modifier: Modifier = Modifier,
Expand All @@ -28,7 +29,9 @@ fun GaugeChart(
- Properties of `GaugeChartConfig`:
- `placeHolderColor`: `Color` - Color of the background arc of the chart. Default is `Color.LightGray`.
- `primaryColor`: `Color` - Color of the primary arc indicating the current value. Default is `Color.Blue`.
- `textColor`: `Color` - Color of the primary text indicating the current value.
- `showNeedle`: `Boolean` - Specifies whether to show the needle indicating the current value. Default is `true`.
- `showText`: `Boolean` - Specifies whether to show the text of the current value. Default is `true`.
- `showIndicator`: `Boolean` - Specifies whether to show the minute hour dividers. Default is `true`.
- `indicatorColor`: `Color` - Color of the minute hour dividers. Default is `Color.Red`.
- `indicatorWidth`: `Dp` - Width of the minute hour dividers. Default is `2.dp`.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#Sun May 14 12:03:03 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 3 additions & 6 deletions quality/static-check.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
apply plugin: "io.gitlab.arturbosch.detekt"
apply plugin: "org.jlleitschuh.gradle.ktlint"

android {
lintOptions {
warningsAsErrors true
abortOnError false
}
}

ktlint {
version = "0.37.2"
Expand All @@ -16,4 +10,7 @@ ktlint {
detekt {
config = files("../quality/detekt-rules.yml")
buildUponDefaultConfig = true
}
dependencies {
detektPlugins "io.nlopez.compose.rules:detekt:0.2.1"
}
18 changes: 18 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,31 @@ pluginManagement {
gradlePluginPortal()
}
}
plugins {
// See https://jmfayard.github.io/refreshVersions
id 'de.fayard.refreshVersions' version '0.51.0'
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}

rootProject.name = "Charty"
include ':app'
include ':charty'

refreshVersions {
featureFlags {
enable 'LIBS'
disable 'GRADLE_UPDATES'
}

// ignore all non-stable releases
rejectVersionIf {
candidate.stabilityLevel != StabilityLevel.Stable
}
}
30 changes: 30 additions & 0 deletions versions.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#### Dependencies and Plugin versions with their available updates.
#### Generated by `./gradlew refreshVersions` version 0.51.0
####
#### Don't manually edit or split the comments that start with four hashtags (####),
#### they will be overwritten by refreshVersions.
####
#### suppress inspection "SpellCheckingInspection" for whole file
#### suppress inspection "UnusedProperty" for whole file

version.androidx.activity=1.7.2

version.androidx.appcompat=1.6.1

version.androidx.compose=2023.08.00

version.androidx.core=1.10.1

version.androidx.lifecycle=2.6.1

version.androidx.test.espresso=3.5.1

version.androidx.test.ext.junit=1.1.5

version.com.slack.lint.compose..compose-lint-checks=1.2.0

version.google.android.material=1.9.0

version.junit.junit=4.13.2

version.kotlinx.datetime=0.4.0