Skip to content

Commit

Permalink
Merge branch 'feature/bubbleChart' into feature/acccessibilityCustomi…
Browse files Browse the repository at this point in the history
…zations
  • Loading branch information
AkYML committed Jun 15, 2023
2 parents fc2385f + 7ddd4a6 commit d2c6891
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 27 deletions.
93 changes: 83 additions & 10 deletions YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package co.yml.charts.common.utils

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.text.TextStyle
import co.yml.charts.axis.DataCategoryOptions
import co.yml.charts.common.model.LegendLabel
Expand All @@ -12,6 +13,7 @@ import co.yml.charts.ui.barchart.models.BarChartType
import co.yml.charts.ui.barchart.models.BarData
import co.yml.charts.ui.barchart.models.GroupBar
import co.yml.charts.ui.bubblechart.model.Bubble
import co.yml.charts.ui.bubblechart.model.BubbleGradientType
import co.yml.charts.ui.bubblechart.model.BubbleStyle
import co.yml.charts.ui.piechart.models.PieChartData
import kotlin.math.sin
Expand Down Expand Up @@ -69,14 +71,86 @@ object DataUtils {
): List<Bubble> {
val list = arrayListOf<Bubble>()
points.forEachIndexed { index, point ->
val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor, Color.White), useGradience = true)
)
)
val bubbleColor1 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
val bubbleColor2 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
val bubbleColor3 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
val bubbleColor4 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))

when(Random.nextInt(0,7)){
0->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.RadialGradient)
)
)
}
1->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.LinearGradient)
)
)
}
2->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.VerticalGradient)
)
)
}
3->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient)
)
)
}
4->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient, tileMode = TileMode.Decal)
)
)
}
5->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Repeated)
)
)
}
6->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Clamp)
)
)
}
7->{
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Mirror)
)
)
}
}


}
return list
Expand All @@ -95,15 +169,14 @@ object DataUtils {
): List<Bubble> {
val list = arrayListOf<Bubble>()
points.forEachIndexed { index, point ->
val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue
val bubbleColor =Color(red = Random.nextInt(256),green= Random.nextInt(256),blue= Random.nextInt(256), alpha =Random.nextInt(from = 150, until = 256) )
list.add(
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(solidColor = bubbleColor, useGradience = false)
)
)

}
return list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,43 @@ data class Bubble(
)

private fun getBrush(bubbleStyle: BubbleStyle, center: Offset, density: Float): Brush {
return Brush.radialGradient(
colors = bubbleStyle.gradientColors,
center = center,
radius = density,
tileMode = TileMode.Decal
)
when (bubbleStyle.gradientType) {
BubbleGradientType.RadialGradient -> {
return Brush.radialGradient(
colors = bubbleStyle.gradientColors,
center = center,
radius = density,
tileMode = bubbleStyle.tileMode
)
}

BubbleGradientType.LinearGradient -> {
return Brush.linearGradient(
colors = bubbleStyle.gradientColors,
tileMode = bubbleStyle.tileMode,
start = center,
end = center
)
}

BubbleGradientType.VerticalGradient -> {
return Brush.verticalGradient(
colors = bubbleStyle.gradientColors,
tileMode = bubbleStyle.tileMode,
startY = center.y - density / 2,
endY = center.y + density / 2,
)
}

BubbleGradientType.HorizontalGradient -> {
return Brush.horizontalGradient(
colors = bubbleStyle.gradientColors,
tileMode = bubbleStyle.tileMode,
startX = center.x - density / 2,
endX = center.x + density / 2,
)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.LinearGradient
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultBlendMode
import androidx.compose.ui.graphics.drawscope.DrawStyle
import androidx.compose.ui.graphics.drawscope.Fill
Expand All @@ -26,9 +27,10 @@ import co.yml.charts.ui.linechart.model.LineType
*/
data class BubbleStyle(
val gradientColors: List<Color> = listOf(Color.Blue, Color.Red),
val gradientType: BubbleGradientType = BubbleGradientType.None(),
val solidColor: Color = Color.Blue,
val gradientType: BubbleGradientType = BubbleGradientType.HorizontalGradient,
val tileMode: TileMode = TileMode.Decal,
val useGradience: Boolean = false,
val solidColor: Color = Color.Blue,
val width: Float = 8f,
val alpha: Float = 1.0f,
val style: DrawStyle = Fill,
Expand Down Expand Up @@ -70,14 +72,6 @@ sealed class BubbleGradientType {
*
* @constructor Create empty Horizontal gradient
*/
class HorizontalGradient() : BubbleGradientType()

/**
* None
*
* @constructor Create empty None
*/
class None() : BubbleGradientType()

object HorizontalGradient : BubbleGradientType()

}

0 comments on commit d2c6891

Please sign in to comment.