@@ -2,6 +2,7 @@ package co.yml.charts.common.utils
22
33import androidx.compose.foundation.layout.Arrangement
44import androidx.compose.ui.graphics.Color
5+ import androidx.compose.ui.graphics.TileMode
56import androidx.compose.ui.text.TextStyle
67import co.yml.charts.axis.DataCategoryOptions
78import co.yml.charts.common.model.LegendLabel
@@ -12,6 +13,7 @@ import co.yml.charts.ui.barchart.models.BarChartType
1213import co.yml.charts.ui.barchart.models.BarData
1314import co.yml.charts.ui.barchart.models.GroupBar
1415import co.yml.charts.ui.bubblechart.model.Bubble
16+ import co.yml.charts.ui.bubblechart.model.BubbleGradientType
1517import co.yml.charts.ui.bubblechart.model.BubbleStyle
1618import co.yml.charts.ui.piechart.models.PieChartData
1719import 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 }
0 commit comments