Skip to content

Commit

Permalink
Merge pull request #34 from bytebeats/dev
Browse files Browse the repository at this point in the history
improve projects
  • Loading branch information
bytebeats authored May 31, 2024
2 parents 6be6185 + a55f48c commit 06a4fc7
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 71 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Simple Jetpack Compose Charts for multi-platform. Including Android, Web, Deskto

Compose Multiplatform for Desktop: [compose-charts-desktop](https://github.com/bytebeats/compose-charts-desktop).

**LATEST_VERSION**: 0.1.2
**LATEST_VERSION**: 0.2.1

**COMPOSE_VERSION**: 1.1.1
**COMPOSE_VERSION**: 1.6.7

**KOTLIN_VERSION**: 1.6.10
**KOTLIN_VERSION**: 1.9.24

## Graph Effects

Expand All @@ -26,23 +26,25 @@ Compose Multiplatform for Desktop: [compose-charts-desktop](https://github.com/b

1. add maven and dependency:

1.1. add specific maven url in your root `build.gradle`
1.1. add specific maven url in your root `build.gradle.kts`

```
repositories {
maven { url('https://repo1.maven.org/maven2/') }
...
...
maven {
url = uri("https://repo1.maven.org/maven2/")
}
}
```

1.2. add dependency in your module `build.gradle`
1.2. add dependency in your module `build.gradle.kts`

```
dependencies {
implementation "androidx.compose.ui:ui:$compose_version"
implementation("androidx.compose.ui:ui:$compose_version")
// implementation project(':charts')
implementation('io.github.bytebeats:compose-charts:LATEST_VERSION')
// implementation(project(":charts"))
implementation("io.github.bytebeats:compose-charts:${LATEST_VERSION}")
}
```

Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.detekt.gradle.plugin)
}

android {
Expand Down Expand Up @@ -58,6 +59,6 @@ dependencies {
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)

implementation(project(":charts"))
// implementation(libs.compose.charts)
// implementation(project(":charts"))
implementation(libs.compose.charts)
}
12 changes: 4 additions & 8 deletions app/src/main/java/me/bytebeats/views/charts/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package me.bytebeats.views.charts.app
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import me.bytebeats.views.charts.app.ui.ComposeCharts


/**
* Main activity
*/
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -15,9 +17,3 @@ class MainActivity : ComponentActivity() {
}
}
}

@Preview
@Composable
private fun DefaultPreview() {
ComposeCharts()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ enum class Screen {
Pie,
Bar,
Line;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ import androidx.compose.runtime.setValue
object ScreenRouter {
var currentScreen by mutableStateOf(Screen.Home)

/**
* Navigate
*
* @param screen
*/
fun navigate(screen: Screen) {
currentScreen = screen
}

/**
* Navigate home
*/
fun navigateHome() {
currentScreen = Screen.Home
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import me.bytebeats.views.charts.app.ui.Screen
import me.bytebeats.views.charts.app.ui.ScreenRouter
import me.bytebeats.views.charts.app.ui.theme.Margins
import me.bytebeats.views.charts.app.ui.theme.Margin

/**
* Created by bytebeats on 2021/9/30 : 11:43
Expand Down Expand Up @@ -69,8 +69,8 @@ private fun ChartScreenSelector(
) {
Row(
modifier = Modifier.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
) {
TextButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BarChartDataModel {
field = value
}

fun addBar() {
internal fun addBar() {
barChartData = barChartData.copy(bars = bars.toMutableList().apply {
add(
BarChartData.Bar(
Expand All @@ -86,7 +86,7 @@ class BarChartDataModel {
}.toList())
}

fun removeBar() {
internal fun removeBar() {
barChartData = barChartData.copy(bars = bars.toMutableList().apply {
val lastBar = bars.last()
colors.add(lastBar.color)
Expand All @@ -99,4 +99,4 @@ class BarChartDataModel {
val idx = Random.Default.nextInt(colors.size)
return colors.removeAt(idx)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import me.bytebeats.views.charts.app.ui.ScreenRouter
import me.bytebeats.views.charts.app.ui.theme.Margins
import me.bytebeats.views.charts.app.ui.theme.Margin
import me.bytebeats.views.charts.bar.BarChart
import me.bytebeats.views.charts.bar.render.label.SimpleLabelDrawer.DrawLocation
import me.bytebeats.views.charts.bar.render.yaxis.SimpleYAxisDrawer
Expand Down Expand Up @@ -67,8 +67,8 @@ private fun BarChartContent(modifier: Modifier = Modifier) {
val barChartDataModel = BarChartDataModel()
Column(
modifier = modifier.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
) {
BarChartRow(barChartDataModel = barChartDataModel)
Expand All @@ -86,7 +86,7 @@ private fun BarChartRow(barChartDataModel: BarChartDataModel) {
modifier = Modifier
.fillMaxWidth()
.height(280.dp)
.padding(vertical = Margins.verticalLarge)
.padding(vertical = Margin.verticalLarge)
) {
BarChart(
barChartData = barChartDataModel.barChartData,
Expand All @@ -112,15 +112,15 @@ private fun DrawLabelLocation(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = Margins.verticalLarge),
.padding(top = Margin.verticalLarge),
verticalAlignment = Alignment.CenterVertically,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
.align(Alignment.CenterVertically),
horizontalArrangement = Arrangement.SpaceEvenly
Expand All @@ -142,7 +142,7 @@ private fun AddOrRemoveBar(barChartDataModel: BarChartDataModel) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = Margins.vertical),
.padding(vertical = Margin.vertical),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
) {
Expand All @@ -158,7 +158,7 @@ private fun AddOrRemoveBar(barChartDataModel: BarChartDataModel) {
}

Row(
modifier = Modifier.padding(horizontal = Margins.horizontal),
modifier = Modifier.padding(horizontal = Margin.horizontal),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "Bars: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class LineChartDataModel {


private fun randomYValue(): Float = Random.Default.nextInt(45, 145).toFloat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import me.bytebeats.views.charts.app.ui.ScreenRouter
import me.bytebeats.views.charts.app.ui.theme.Margins
import me.bytebeats.views.charts.app.ui.theme.Margin
import me.bytebeats.views.charts.line.LineChart

/**
Expand Down Expand Up @@ -65,8 +65,8 @@ private fun LineChartContent(

Column(
modifier = modifier.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
) {
LineChartRow(lineChartDataModel = lineChartData)
Expand Down Expand Up @@ -95,8 +95,8 @@ private fun HorizontalOffsetSelector(lineChartDataModel: LineChartDataModel) {
val pointDrawType = lineChartDataModel.pointDrawerType
Column(
modifier = Modifier.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
),
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand All @@ -106,8 +106,8 @@ private fun HorizontalOffsetSelector(lineChartDataModel: LineChartDataModel) {
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Expand All @@ -126,16 +126,16 @@ private fun HorizontalOffsetSelector(lineChartDataModel: LineChartDataModel) {
@Composable
private fun OffsetProgress(lineChartDataModel: LineChartDataModel) {
Column(
modifier = Modifier.padding(horizontal = Margins.horizontal),
modifier = Modifier.padding(horizontal = Margin.horizontal),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Offset")
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
.align(Alignment.CenterHorizontally)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PieChartDataModel {
val slices
get() = pieChartData.slices

fun addSlice() {
internal fun addSlice() {
pieChartData = pieChartData.copy(
slices = slices.toMutableList().apply {
add(
Expand All @@ -67,7 +67,7 @@ class PieChartDataModel {
)
}

fun removeSlice() {
internal fun removeSlice() {
pieChartData = pieChartData.copy(
slices = slices.toMutableList().apply {
val lastSlice = slices.last()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import me.bytebeats.views.charts.app.ui.ScreenRouter
import me.bytebeats.views.charts.app.ui.theme.Margins
import me.bytebeats.views.charts.app.ui.theme.Margin
import me.bytebeats.views.charts.pie.PieChart
import me.bytebeats.views.charts.pie.render.SimpleSliceDrawer

Expand Down Expand Up @@ -72,8 +72,8 @@ private fun PieChartScreenContent(

Column(
modifier = modifier.padding(
horizontal = Margins.horizontal,
vertical = Margins.vertical
horizontal = Margin.horizontal,
vertical = Margin.vertical
)
) {
PieChartRow(pieChartDataModel = pieChartDataModel)
Expand All @@ -91,7 +91,7 @@ private fun PieChartRow(pieChartDataModel: PieChartDataModel) {
modifier = Modifier
.fillMaxWidth()
.height(150.dp)
.padding(vertical = Margins.vertical)
.padding(vertical = Margin.vertical)
) {
PieChart(
pieChartData = pieChartDataModel.pieChartData,
Expand All @@ -105,14 +105,14 @@ private fun SliceThicknessRow(sliceThickness: Float, onValueUpdated: (Float) ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = Margins.verticalLarge),
.padding(vertical = Margin.verticalLarge),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Slice Thickness: ",
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(end = Margins.horizontal)
.padding(end = Margin.horizontal)
)
Slider(
value = sliceThickness,
Expand All @@ -127,7 +127,7 @@ private fun AddOrRemoveSliceRow(pieChartDataModel: PieChartDataModel) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = Margins.vertical),
.padding(top = Margin.vertical),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Expand All @@ -142,7 +142,7 @@ private fun AddOrRemoveSliceRow(pieChartDataModel: PieChartDataModel) {
)
}
Row(
modifier = Modifier.padding(horizontal = Margins.horizontal),
modifier = Modifier.padding(horizontal = Margin.horizontal),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "Slices: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import androidx.compose.ui.graphics.Color
val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)
val Teal200 = Color(0xFF03DAC5)
Loading

0 comments on commit 06a4fc7

Please sign in to comment.