Skip to content

Commit

Permalink
Added a check if Offset is unspecified (#37)
Browse files Browse the repository at this point in the history
* Added a check if Offset is unspecified
* Closes Issue #36
  • Loading branch information
GabeGiro committed Jan 4, 2023
1 parent 8182293 commit 70b0caf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 58 deletions.
51 changes: 25 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Compose Charts

This is an exploratory playground library to figure out how to Draw and animate using Android Jetpack Compose library.

[![Release](https://jitpack.io/v/tehras/charts.svg)]
(https://jitpack.io/#tehras/charts)
This is a library that Draws and animates charts using Android Jetpack Compose library.

## Implementation:

latest_release = ![Release](https://jitpack.io/v/tehras/charts.svg)

build.gradle (app)
```groovy
dependecies {
implementation 'com.github.tehras:charts:0.2.2-alpha'
implementation "com.github.tehras:charts:$latest_release"
}
```

Expand All @@ -34,10 +33,10 @@ repositories {
fun MyChartParent() {
PieChart(
pieChartData = PieChartData(listOf(Slice(...), Slice(...),....)),
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
sliceDrawer = SimpleSliceDrawer()
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
sliceDrawer = SimpleSliceDrawer()
)
}
```
Expand All @@ -49,14 +48,14 @@ fun MyChartParent() {
fun MyBarChartParent() {
fun BarChart(
barChartData = BarChartData(bars = listOf(Bar(label = "Bar Label", value = 100f, color = Color.Red)),
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
barDrawer = SimpleBarDrawer(),
xAxisDrawer = SimpleXAxisDrawer(),
yAxisDrawer = SimpleYAxisDrawer(),
labelDrawer = SimpleValueDrawer()
)
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
barDrawer = SimpleBarDrawer(),
xAxisDrawer = SimpleXAxisDrawer(),
yAxisDrawer = SimpleYAxisDrawer(),
labelDrawer = SimpleValueDrawer()
)
}
```

Expand All @@ -67,15 +66,15 @@ fun MyBarChartParent() {
fun MyLineChartParent() {
LineChart(
linesChartData = listOf(LineChartData(points = listOf(LineChartData.Point(1f,"Label 1"), ...))),
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
pointDrawer = FilledCircularPointDrawer(),
lineDrawer = SolidLineDrawer(),
xAxisDrawer = SimpleXAxisDrawer(),
yAxisDrawer = SimpleYAxisDrawer(),
horizontalOffset = 5f,
labels = listOf("label 1" ...)
// Optional properties.
modifier = Modifier.fillMaxSize(),
animation = simpleChartAnimation(),
pointDrawer = FilledCircularPointDrawer(),
lineDrawer = SolidLineDrawer(),
xAxisDrawer = SimpleXAxisDrawer(),
yAxisDrawer = SimpleYAxisDrawer(),
horizontalOffset = 5f,
labels = listOf("label 1" ...)
)
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.tehras.charts.line
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.geometry.isSpecified
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -123,24 +124,26 @@ object LineChartUtils {
index = index
)

if (index == 0) {
moveTo(pointLocation.x, pointLocation.y)
} else {
if (progress <= 1f) {
// We have to change the `dy` based on the progress
val prevX = prevPointLocation!!.x
val prevY = prevPointLocation!!.y

val x = (pointLocation.x - prevX) * progress + prevX
val y = (pointLocation.y - prevY) * progress + prevY

lineTo(x, y)
if (pointLocation.isSpecified) {
if (index == 0) {
moveTo(pointLocation.x, pointLocation.y)
} else {
lineTo(pointLocation.x, pointLocation.y)
if (progress <= 1f) {
// We have to change the `dy` based on the progress
val prevX = prevPointLocation!!.x
val prevY = prevPointLocation!!.y

val x = (pointLocation.x - prevX) * progress + prevX
val y = (pointLocation.y - prevY) * progress + prevY

lineTo(x, y)
} else {
lineTo(pointLocation.x, pointLocation.y)
}
}
}

prevPointLocation = pointLocation
prevPointLocation = pointLocation
}
}
}
}
Expand All @@ -167,28 +170,30 @@ object LineChartUtils {
index = index
)

if (index == 0) {
lineTo(drawableArea.left, pointLocation.y)
lineTo(pointLocation.x, pointLocation.y)
} else {
if (progress <= 1f) {
// We have to change the `dy` based on the progress
val prevX = prevPointLocation!!.x
val prevY = prevPointLocation!!.y
if (pointLocation.isSpecified) {
if (index == 0) {
lineTo(drawableArea.left, pointLocation.y)
lineTo(pointLocation.x, pointLocation.y)
} else {
if (progress <= 1f) {
// We have to change the `dy` based on the progress
val prevX = prevPointLocation!!.x
val prevY = prevPointLocation!!.y

val x = (pointLocation.x - prevX) * progress + prevX
val y = (pointLocation.y - prevY) * progress + prevY
val x = (pointLocation.x - prevX) * progress + prevX
val y = (pointLocation.y - prevY) * progress + prevY

lineTo(x, y)
lineTo(x, y)

prevPointX = x
} else {
lineTo(pointLocation.x, pointLocation.y)
prevPointX = pointLocation.x
prevPointX = x
} else {
lineTo(pointLocation.x, pointLocation.y)
prevPointX = pointLocation.x
}
}
}

prevPointLocation = pointLocation
prevPointLocation = pointLocation
}
}
}
// We need to connect the line to the end of the drawable area
Expand Down

0 comments on commit 70b0caf

Please sign in to comment.