Skip to content

Commit d2c6891

Browse files
committed
Merge branch 'feature/bubbleChart' into feature/acccessibilityCustomizations
2 parents fc2385f + 7ddd4a6 commit d2c6891

File tree

3 files changed

+127
-27
lines changed

3 files changed

+127
-27
lines changed

YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package co.yml.charts.common.utils
22

33
import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.ui.graphics.Color
5+
import androidx.compose.ui.graphics.TileMode
56
import androidx.compose.ui.text.TextStyle
67
import co.yml.charts.axis.DataCategoryOptions
78
import co.yml.charts.common.model.LegendLabel
@@ -12,6 +13,7 @@ import co.yml.charts.ui.barchart.models.BarChartType
1213
import co.yml.charts.ui.barchart.models.BarData
1314
import co.yml.charts.ui.barchart.models.GroupBar
1415
import co.yml.charts.ui.bubblechart.model.Bubble
16+
import co.yml.charts.ui.bubblechart.model.BubbleGradientType
1517
import co.yml.charts.ui.bubblechart.model.BubbleStyle
1618
import co.yml.charts.ui.piechart.models.PieChartData
1719
import kotlin.math.sin
@@ -69,14 +71,86 @@ object DataUtils {
6971
): List<Bubble> {
7072
val list = arrayListOf<Bubble>()
7173
points.forEachIndexed { index, point ->
72-
val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue
73-
list.add(
74-
Bubble(
75-
center = point,
76-
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
77-
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor, Color.White), useGradience = true)
78-
)
79-
)
74+
val bubbleColor1 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
75+
val bubbleColor2 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
76+
val bubbleColor3 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
77+
val bubbleColor4 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
78+
79+
when(Random.nextInt(0,7)){
80+
0->{
81+
list.add(
82+
Bubble(
83+
center = point,
84+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
85+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.RadialGradient)
86+
)
87+
)
88+
}
89+
1->{
90+
list.add(
91+
Bubble(
92+
center = point,
93+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
94+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.LinearGradient)
95+
)
96+
)
97+
}
98+
2->{
99+
list.add(
100+
Bubble(
101+
center = point,
102+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
103+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.VerticalGradient)
104+
)
105+
)
106+
}
107+
3->{
108+
list.add(
109+
Bubble(
110+
center = point,
111+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
112+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient)
113+
)
114+
)
115+
}
116+
4->{
117+
list.add(
118+
Bubble(
119+
center = point,
120+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
121+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient, tileMode = TileMode.Decal)
122+
)
123+
)
124+
}
125+
5->{
126+
list.add(
127+
Bubble(
128+
center = point,
129+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
130+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Repeated)
131+
)
132+
)
133+
}
134+
6->{
135+
list.add(
136+
Bubble(
137+
center = point,
138+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
139+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Clamp)
140+
)
141+
)
142+
}
143+
7->{
144+
list.add(
145+
Bubble(
146+
center = point,
147+
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
148+
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Mirror)
149+
)
150+
)
151+
}
152+
}
153+
80154

81155
}
82156
return list
@@ -95,15 +169,14 @@ object DataUtils {
95169
): List<Bubble> {
96170
val list = arrayListOf<Bubble>()
97171
points.forEachIndexed { index, point ->
98-
val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue
172+
val bubbleColor =Color(red = Random.nextInt(256),green= Random.nextInt(256),blue= Random.nextInt(256), alpha =Random.nextInt(from = 150, until = 256) )
99173
list.add(
100174
Bubble(
101175
center = point,
102176
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
103177
bubbleStyle = BubbleStyle(solidColor = bubbleColor, useGradience = false)
104178
)
105179
)
106-
107180
}
108181
return list
109182
}

YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleChartData.kt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,43 @@ data class Bubble(
9191
)
9292

9393
private fun getBrush(bubbleStyle: BubbleStyle, center: Offset, density: Float): Brush {
94-
return Brush.radialGradient(
95-
colors = bubbleStyle.gradientColors,
96-
center = center,
97-
radius = density,
98-
tileMode = TileMode.Decal
99-
)
94+
when (bubbleStyle.gradientType) {
95+
BubbleGradientType.RadialGradient -> {
96+
return Brush.radialGradient(
97+
colors = bubbleStyle.gradientColors,
98+
center = center,
99+
radius = density,
100+
tileMode = bubbleStyle.tileMode
101+
)
102+
}
103+
104+
BubbleGradientType.LinearGradient -> {
105+
return Brush.linearGradient(
106+
colors = bubbleStyle.gradientColors,
107+
tileMode = bubbleStyle.tileMode,
108+
start = center,
109+
end = center
110+
)
111+
}
112+
113+
BubbleGradientType.VerticalGradient -> {
114+
return Brush.verticalGradient(
115+
colors = bubbleStyle.gradientColors,
116+
tileMode = bubbleStyle.tileMode,
117+
startY = center.y - density / 2,
118+
endY = center.y + density / 2,
119+
)
120+
}
121+
122+
BubbleGradientType.HorizontalGradient -> {
123+
return Brush.horizontalGradient(
124+
colors = bubbleStyle.gradientColors,
125+
tileMode = bubbleStyle.tileMode,
126+
startX = center.x - density / 2,
127+
endX = center.x + density / 2,
128+
)
129+
}
130+
}
131+
132+
100133
}

YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleStyle.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.ui.graphics.BlendMode
44
import androidx.compose.ui.graphics.Color
55
import androidx.compose.ui.graphics.ColorFilter
66
import androidx.compose.ui.graphics.LinearGradient
7+
import androidx.compose.ui.graphics.TileMode
78
import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultBlendMode
89
import androidx.compose.ui.graphics.drawscope.DrawStyle
910
import androidx.compose.ui.graphics.drawscope.Fill
@@ -26,9 +27,10 @@ import co.yml.charts.ui.linechart.model.LineType
2627
*/
2728
data class BubbleStyle(
2829
val gradientColors: List<Color> = listOf(Color.Blue, Color.Red),
29-
val gradientType: BubbleGradientType = BubbleGradientType.None(),
30-
val solidColor: Color = Color.Blue,
30+
val gradientType: BubbleGradientType = BubbleGradientType.HorizontalGradient,
31+
val tileMode: TileMode = TileMode.Decal,
3132
val useGradience: Boolean = false,
33+
val solidColor: Color = Color.Blue,
3234
val width: Float = 8f,
3335
val alpha: Float = 1.0f,
3436
val style: DrawStyle = Fill,
@@ -70,14 +72,6 @@ sealed class BubbleGradientType {
7072
*
7173
* @constructor Create empty Horizontal gradient
7274
*/
73-
class HorizontalGradient() : BubbleGradientType()
74-
75-
/**
76-
* None
77-
*
78-
* @constructor Create empty None
79-
*/
80-
class None() : BubbleGradientType()
81-
75+
object HorizontalGradient : BubbleGradientType()
8276

8377
}

0 commit comments

Comments
 (0)