@@ -11,6 +11,8 @@ import co.yml.charts.common.model.Point
11
11
import co.yml.charts.ui.barchart.models.BarChartType
12
12
import co.yml.charts.ui.barchart.models.BarData
13
13
import co.yml.charts.ui.barchart.models.GroupBar
14
+ import co.yml.charts.ui.bubblechart.model.Bubble
15
+ import co.yml.charts.ui.bubblechart.model.BubbleStyle
14
16
import co.yml.charts.ui.piechart.models.PieChartData
15
17
import kotlin.math.sin
16
18
import kotlin.random.Random
@@ -35,6 +37,77 @@ object DataUtils {
35
37
return list
36
38
}
37
39
40
+ /* *
41
+ * Returns list of points
42
+ * @param listSize: Size of total number of points needed.
43
+ * @param start: X values to start from. ex: 50 to 100
44
+ * @param maxRange: Max range of Y values
45
+ */
46
+ fun getRandomPoints (listSize : Int , start : Int = 0, maxRange : Int ): List <Point > {
47
+ val list = arrayListOf<Point >()
48
+ for (index in 0 until listSize) {
49
+ list.add(
50
+ Point (
51
+ index.toFloat(),
52
+ (start until maxRange).random().toFloat()
53
+ )
54
+ )
55
+ }
56
+ return list
57
+ }
58
+
59
+ /* *
60
+ * Returns list of points
61
+ * @param listSize: Size of total number of points needed.
62
+ * @param start: X values to start from. ex: 50 to 100
63
+ * @param maxRange: Max range of Y values
64
+ */
65
+ fun getBubbleChartDataWithGradientStyle (
66
+ points : List <Point >,
67
+ minDensity : Float = 10F,
68
+ maxDensity : Float = 100F
69
+ ): List <Bubble > {
70
+ val list = arrayListOf<Bubble >()
71
+ 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
+ )
80
+
81
+ }
82
+ return list
83
+ }
84
+
85
+ /* *
86
+ * Returns list of points
87
+ * @param listSize: Size of total number of points needed.
88
+ * @param start: X values to start from. ex: 50 to 100
89
+ * @param maxRange: Max range of Y values
90
+ */
91
+ fun getBubbleChartDataWithSolidStyle (
92
+ points : List <Point >,
93
+ minDensity : Float = 10F,
94
+ maxDensity : Float = 100F
95
+ ): List <Bubble > {
96
+ val list = arrayListOf<Bubble >()
97
+ points.forEachIndexed { index, point ->
98
+ val bubbleColor = if (index % 2 == 0 ) Color .Red else Color .Blue
99
+ list.add(
100
+ Bubble (
101
+ center = point,
102
+ density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
103
+ bubbleStyle = BubbleStyle (solidColor = bubbleColor, useGradience = false )
104
+ )
105
+ )
106
+
107
+ }
108
+ return list
109
+ }
110
+
38
111
/* *
39
112
* Return the sample bar chart data
40
113
* @param duration : Duration of the wave in seconds
@@ -71,6 +144,7 @@ object DataUtils {
71
144
" %.2f" .format(Random .nextDouble(1.0 , maxRange.toDouble())).toFloat()
72
145
)
73
146
}
147
+
74
148
BarChartType .HORIZONTAL -> {
75
149
Point (
76
150
" %.2f" .format(Random .nextDouble(1.0 , maxRange.toDouble())).toFloat(),
0 commit comments