11package co.yml.charts.ui.bubblechart.model
22
33import androidx.compose.ui.geometry.Offset
4+ import androidx.compose.ui.graphics.Brush
45import androidx.compose.ui.graphics.Color
6+ import androidx.compose.ui.graphics.TileMode
57import androidx.compose.ui.graphics.drawscope.DrawScope
6- import androidx.compose.ui.unit.Density
78import androidx.compose.ui.unit.Dp
89import androidx.compose.ui.unit.dp
910import co.yml.charts.axis.AxisData
@@ -13,23 +14,23 @@ import co.yml.charts.ui.linechart.model.GridLines
1314import co.yml.charts.ui.linechart.model.IntersectionPoint
1415import co.yml.charts.ui.linechart.model.SelectionHighlightPoint
1516import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
16- import co.yml.charts.ui.linechart.model.ShadowUnderLine
1717
1818
1919/* *
20+ * Bubble chart data
2021 *
21- * BubbleChartData data class that contains all params user need to define to draw a bubble chart.
22- * @param bubbles: A list of Bubbles to be drawn.
23- * @param xAxisData: All the configurations related to X-Axis to be defined here in [AxisData]
24- * @param yAxisData: All the configurations related to Y-Axis to be defined here in [AxisData]
25- * @param isZoomAllowed: True if zoom in for all vertical graph components is allowed else false.
26- * @param paddingTop: Padding from the top of the canvas to start of the graph container.
27- * @param paddingRight: Padding from the end of the canvas to end of the graph container.
28- * @param bottomPadding: Padding from the bottom of the canvas to bottom of the graph container.
29- * @param containerPaddingEnd: Container inside padding end after the last point of the graph.
30- * @param backgroundColor: Background color of the Y & X components,
31- * @param gridLines: This enables graph to draw horizontal and vertical grid lines
32- * @param accessibilityConfig: Configs related to accessibility service defined here in [AccessibilityConfig]
22+ * @property bubbles
23+ * @property xAxisData
24+ * @property yAxisData
25+ * @property isZoomAllowed
26+ * @property paddingTop
27+ * @property bottomPadding
28+ * @property paddingRight
29+ * @property containerPaddingEnd
30+ * @property backgroundColor
31+ * @property gridLines
32+ * @property accessibilityConfig
33+ * @constructor Create empty Bubble chart data
3334 */
3435data class BubbleChartData (
3536 val bubbles : List <Bubble >,
@@ -46,32 +47,54 @@ data class BubbleChartData(
4647)
4748
4849/* *
49- * Represent a Bubble in the [co.yml.charts.ui.bubblechart]
50+ * Bubble
5051 *
51- * @param center center [Point] of the bubble
52- * @param bubbleStyle Adds styling options in [BubbleStyle] to the bubble to be drawn.
53- * @param intersectionPoint drawing logic to draw the point itself in [IntersectionPoint].
54- * If null, the point is not drawn.
55- * @param selectionHighlightPoint drawing logic to draw the highlight at the point when it is selected
56- * in [SelectionHighlightPoint] If null, the point won't be highlighted on selection
57- * @param selectionHighlightPopUp All prams related to selection popup to be added here in [SelectionHighlightPopUp]
52+ * @property center
53+ * @property density
54+ * @property bubbleStyle
55+ * @property intersectionPoint
56+ * @property selectionHighlightPoint
57+ * @property selectionHighlightPopUp
58+ * @property draw
59+ * @constructor Create empty Bubble
5860 */
5961data class Bubble (
60- val center : Point ,
62+ val center : Point ,
6163 val density : Float ,
6264 val bubbleStyle : BubbleStyle = BubbleStyle (),
6365 val intersectionPoint : IntersectionPoint ? = null ,
6466 val selectionHighlightPoint : SelectionHighlightPoint ? = null ,
6567 val selectionHighlightPopUp : SelectionHighlightPopUp ? = null ,
6668 val draw : DrawScope .(Offset ) -> Unit = { center ->
67- drawCircle(
68- bubbleStyle.color,
69- density,
70- center,
71- bubbleStyle.alpha,
72- bubbleStyle.style,
73- bubbleStyle.colorFilter,
74- bubbleStyle.blendMode
75- )
69+ if (bubbleStyle.useGradience) {
70+ drawCircle(
71+ brush = getBrush(bubbleStyle, center, density),
72+ center = center,
73+ radius = density,
74+ alpha = bubbleStyle.alpha,
75+ style = bubbleStyle.style,
76+ colorFilter = bubbleStyle.colorFilter,
77+ blendMode = bubbleStyle.blendMode
78+ )
79+ } else {
80+ drawCircle(
81+ bubbleStyle.solidColor,
82+ density,
83+ center,
84+ bubbleStyle.alpha,
85+ bubbleStyle.style,
86+ bubbleStyle.colorFilter,
87+ bubbleStyle.blendMode
88+ )
89+ }
7690 }
7791)
92+
93+ 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+ )
100+ }
0 commit comments