Skip to content

Commit 85c9809

Browse files
committed
cleanup for bubble chart
cleanup bubble chart-accessibility
1 parent ece2f58 commit 85c9809

File tree

8 files changed

+201
-189
lines changed

8 files changed

+201
-189
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package co.yml.charts.common.components.accessibility
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.Row
8+
import androidx.compose.foundation.layout.Spacer
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.size
11+
import androidx.compose.foundation.layout.width
12+
import androidx.compose.material3.Text
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.graphics.Color
17+
import androidx.compose.ui.semantics.semantics
18+
import androidx.compose.ui.unit.dp
19+
import androidx.compose.ui.unit.sp
20+
21+
/**
22+
* Composable to display each Bubble point data for given bubble chart.
23+
* @param axisLabelDescription: Axis label description.
24+
* @param pointDescription: Details of each point on the line.
25+
* @param bubbleColor: Color of each bubble.
26+
*/
27+
@Composable
28+
fun BubblePointInfo(
29+
axisLabelDescription: String,
30+
pointDescription: String,
31+
bubbleColor: Color
32+
) {
33+
// Merge elements below for accessibility purposes
34+
Row(modifier = Modifier
35+
.padding(start = 10.dp, end = 10.dp)
36+
.clickable { }
37+
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
38+
) {
39+
Text(axisLabelDescription, fontSize = 12.sp)
40+
Spacer(modifier = Modifier.width(5.dp))
41+
Column(
42+
modifier = Modifier
43+
.weight(1f)
44+
.padding(5.dp)
45+
) {
46+
Row(verticalAlignment = Alignment.CenterVertically) {
47+
Box(
48+
modifier = Modifier
49+
.padding(5.dp)
50+
.background(bubbleColor)
51+
.size(20.dp)
52+
)
53+
Text(pointDescription, fontSize = 12.sp)
54+
}
55+
}
56+
}
57+
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import co.yml.charts.common.model.Point
1111
import co.yml.charts.ui.barchart.models.BarChartType
1212
import co.yml.charts.ui.barchart.models.BarData
1313
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
1416
import co.yml.charts.ui.piechart.models.PieChartData
1517
import kotlin.math.sin
1618
import kotlin.random.Random
@@ -35,6 +37,51 @@ object DataUtils {
3537
return list
3638
}
3739

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 getBubbleChartData(
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(color = bubbleColor)
78+
)
79+
)
80+
81+
}
82+
return list
83+
}
84+
3885
/**
3986
* Return the sample bar chart data
4087
* @param duration : Duration of the wave in seconds
@@ -71,6 +118,7 @@ object DataUtils {
71118
"%.2f".format(Random.nextDouble(1.0, maxRange.toDouble())).toFloat()
72119
)
73120
}
121+
74122
BarChartType.HORIZONTAL -> {
75123
Point(
76124
"%.2f".format(Random.nextDouble(1.0, maxRange.toDouble())).toFloat(),

0 commit comments

Comments
 (0)