Skip to content

Commit fc96746

Browse files
committed
update max density
1 parent 7ddd4a6 commit fc96746

File tree

5 files changed

+42
-57
lines changed

5 files changed

+42
-57
lines changed

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object DataUtils {
5050
for (index in 0 until listSize) {
5151
list.add(
5252
Point(
53-
index.toFloat(),
53+
(start until maxRange).random().toFloat(),
5454
(start until maxRange).random().toFloat()
5555
)
5656
)
@@ -76,7 +76,7 @@ object DataUtils {
7676
val bubbleColor3 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
7777
val bubbleColor4 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))
7878

79-
when(Random.nextInt(0,7)){
79+
when(Random.nextInt(0,5)){
8080
0->{
8181
list.add(
8282
Bubble(
@@ -114,15 +114,6 @@ object DataUtils {
114114
)
115115
}
116116
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->{
126117
list.add(
127118
Bubble(
128119
center = point,
@@ -131,16 +122,7 @@ object DataUtils {
131122
)
132123
)
133124
}
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->{
125+
5->{
144126
list.add(
145127
Bubble(
146128
center = point,

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

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
6060
import kotlinx.coroutines.launch
6161

6262
/**
63+
* Bubble chart
6364
*
64-
* [BubbleChart] compose method used for drawing a Bubble Chart.
65-
* @param modifier :All modifier related property.
66-
* Data class [BubbleChartData] to save all params needed to draw the bubble chart.
67-
* @param bubbleChartData : Add data related to bubble chart.
65+
* @param modifier
66+
* @param bubbleChartData
6867
*/
6968
@OptIn(ExperimentalMaterialApi::class)
7069
@Composable
@@ -182,9 +181,9 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
182181
it
183182
)
184183
}
185-
pointsData.forEachIndexed {index,offset->
184+
pointsData.forEachIndexed { index, offset ->
186185

187-
bubbles[index].draw(this,offset)
186+
bubbles[index].draw(this, offset, bubbleChartData.maximumBubbleRadius)
188187

189188
pointsData.forEachIndexed { index, point ->
190189
if (isTapped && point.isTapped(tapOffset.x, xOffset)) {
@@ -272,15 +271,16 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
272271
}
273272

274273
/**
274+
* Get max scroll distance
275275
*
276-
* returns the max scrollable distance based on the points to be drawn along with padding etc.
277-
* @param columnWidth : Width of the Y-Axis.
278-
* @param xMax : Max X-Axis value.
279-
* @param xMin: Min X-Axis value.
280-
* @param xOffset: Total distance between two X-Axis points.
281-
* @param paddingRight : Padding at the end of the canvas.
282-
* @param canvasWidth : Total available canvas width.
283-
* @param containerPaddingEnd : Container inside padding end after the last point of the graph.
276+
* @param columnWidth
277+
* @param xMax
278+
* @param xMin
279+
* @param xOffset
280+
* @param paddingRight
281+
* @param canvasWidth
282+
* @param containerPaddingEnd
283+
* @return
284284
*/
285285
fun getMaxScrollDistance(
286286
columnWidth: Float,
@@ -317,9 +317,10 @@ private fun DrawScope.drawUnderScrollMask(columnWidth: Float, paddingRight: Dp,
317317

318318

319319
/**
320+
* Get cubic points
320321
*
321-
* getCubicPoints method provides left and right average value for a given point to get a smooth curve.
322-
* @param pointsData : List of the points on the Line graph.
322+
* @param pointsData
323+
* @return
323324
*/
324325
fun getCubicPoints(pointsData: List<Offset>): Pair<MutableList<Offset>, MutableList<Offset>> {
325326
val cubicPoints1 = mutableListOf<Offset>()
@@ -341,10 +342,11 @@ fun getCubicPoints(pointsData: List<Offset>): Pair<MutableList<Offset>, MutableL
341342
}
342343

343344
/**
344-
* Used to draw the highlighted text
345-
* @param identifiedPoint : Selected points
346-
* @param selectedOffset: Offset selected
347-
* @param selectionHighlightPopUp : Data class with all styling related info [SelectionHighlightPopUp]
345+
* Draw highlight text
346+
*
347+
* @param identifiedPoint
348+
* @param selectedOffset
349+
* @param selectionHighlightPopUp
348350
*/
349351
fun DrawScope.drawHighlightText(
350352
identifiedPoint: Point,
@@ -357,14 +359,13 @@ fun DrawScope.drawHighlightText(
357359
}
358360

359361
/**
362+
* Draw high light on selected point
360363
*
361-
* DrawScope.drawHighLightOnSelectedPoint extension method used for drawing and highlight the selected
362-
* point when dragging.
363-
* @param dragLocks : List of points to be drawn on the canvas and that can be selected.
364-
* @param columnWidth : Width of the Axis in the left or right.
365-
* @param paddingRight : Padding given to the right side of the canvas.
366-
* @param yBottom : Start position from below of the canvas.
367-
* @param selectionHighlightPoint : Data class to define all the styles to be drawn in [SelectionHighlightPoint]
364+
* @param dragLocks
365+
* @param columnWidth
366+
* @param paddingRight
367+
* @param yBottom
368+
* @param selectionHighlightPoint
368369
*/
369370
fun DrawScope.drawHighLightOnSelectedPoint(
370371
dragLocks: MutableMap<Int, Pair<Point, Offset>>,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package co.yml.charts.ui.bubblechart.model
33
import androidx.compose.ui.geometry.Offset
44
import androidx.compose.ui.graphics.Brush
55
import androidx.compose.ui.graphics.Color
6-
import androidx.compose.ui.graphics.TileMode
76
import androidx.compose.ui.graphics.drawscope.DrawScope
87
import androidx.compose.ui.unit.Dp
98
import androidx.compose.ui.unit.dp
@@ -20,6 +19,7 @@ import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
2019
* Bubble chart data
2120
*
2221
* @property bubbles
22+
* @property maximumBubbleRadius
2323
* @property xAxisData
2424
* @property yAxisData
2525
* @property isZoomAllowed
@@ -34,6 +34,7 @@ import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
3434
*/
3535
data class BubbleChartData(
3636
val bubbles: List<Bubble>,
37+
val maximumBubbleRadius:Float = 100f,
3738
val xAxisData: AxisData = AxisData.Builder().build(),
3839
val yAxisData: AxisData = AxisData.Builder().build(),
3940
val isZoomAllowed: Boolean = true,
@@ -65,12 +66,13 @@ data class Bubble(
6566
val intersectionPoint: IntersectionPoint? = null,
6667
val selectionHighlightPoint: SelectionHighlightPoint? = null,
6768
val selectionHighlightPopUp: SelectionHighlightPopUp? = null,
68-
val draw: DrawScope.(Offset) -> Unit = { center ->
69+
val draw: DrawScope.(Offset,Float) -> Unit = { center,maximumRadius ->
70+
val drawingRadius:Float = (density / maximumRadius) * 100
6971
if (bubbleStyle.useGradience) {
7072
drawCircle(
7173
brush = getBrush(bubbleStyle, center, density),
7274
center = center,
73-
radius = density,
75+
radius = drawingRadius,
7476
alpha = bubbleStyle.alpha,
7577
style = bubbleStyle.style,
7678
colorFilter = bubbleStyle.colorFilter,
@@ -79,7 +81,7 @@ data class Bubble(
7981
} else {
8082
drawCircle(
8183
bubbleStyle.solidColor,
82-
density,
84+
drawingRadius,
8385
center,
8486
bubbleStyle.alpha,
8587
bubbleStyle.style,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import co.yml.charts.ui.linechart.model.LineType
2828
data class BubbleStyle(
2929
val gradientColors: List<Color> = listOf(Color.Blue, Color.Red),
3030
val gradientType: BubbleGradientType = BubbleGradientType.HorizontalGradient,
31-
val tileMode: TileMode = TileMode.Decal,
31+
val tileMode: TileMode = TileMode.Clamp,
3232
val useGradience: Boolean = false,
3333
val solidColor: Color = Color.Blue,
3434
val width: Float = 8f,

app/src/main/java/co/yml/ycharts/app/presentation/BubbleChartActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class BubbleChartActivity : ComponentActivity() {
6767
BubbleChartWithGrid(
6868
pointsData = DataUtils.getRandomPoints(
6969
200,
70-
start = -50,
71-
maxRange = 50
70+
start = 30,
71+
maxRange = 100
7272
)
7373
)
7474
Spacer(modifier = Modifier.height(12.dp))
@@ -84,8 +84,8 @@ class BubbleChartActivity : ComponentActivity() {
8484
SolidBubbleChart(
8585
pointsData = DataUtils.getRandomPoints(
8686
200,
87-
start = -50,
88-
maxRange = 50
87+
start = 30,
88+
maxRange = 900
8989
)
9090
)
9191
Spacer(modifier = Modifier.height(12.dp))

0 commit comments

Comments
 (0)