Skip to content

Commit 06f752a

Browse files
committed
add bubble chart density
1 parent ce606a0 commit 06f752a

File tree

14 files changed

+809
-13
lines changed

14 files changed

+809
-13
lines changed

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

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package co.yml.charts.ui.bubblechart.model
2+
3+
import androidx.compose.ui.graphics.Color
4+
import androidx.compose.ui.unit.Dp
5+
import androidx.compose.ui.unit.dp
6+
import co.yml.charts.axis.AxisData
7+
import co.yml.charts.common.model.AccessibilityConfig
8+
import co.yml.charts.common.model.Point
9+
import co.yml.charts.ui.linechart.model.GridLines
10+
import co.yml.charts.ui.linechart.model.IntersectionPoint
11+
import co.yml.charts.ui.linechart.model.SelectionHighlightPoint
12+
import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
13+
import co.yml.charts.ui.linechart.model.ShadowUnderLine
14+
15+
16+
/**
17+
*
18+
* LineGraphData data class that contains all params user need to define to draw a line graph.
19+
* @param bubblePlotData: The path to be drawn on the graph represented by a line.
20+
* @param xAxisData: All the configurations related to X-Axis to be defined here in [AxisData]
21+
* @param yAxisData: All the configurations related to Y-Axis to be defined here in [AxisData]
22+
* @param isZoomAllowed: True if zoom in for all vertical graph components is allowed else false.
23+
* @param paddingTop: Padding from the top of the canvas to start of the graph container.
24+
* @param paddingRight: Padding from the end of the canvas to end of the graph container.
25+
* @param bottomPadding: Padding from the bottom of the canvas to bottom of the graph container.
26+
* @param containerPaddingEnd: Container inside padding end after the last point of the graph.
27+
* @param backgroundColor: Background color of the Y & X components,
28+
* @param gridLines: This enables graph to draw horizontal and vertical grid lines
29+
* @param accessibilityConfig: Configs related to accessibility service defined here in [AccessibilityConfig]
30+
*/
31+
data class BubbleChartData(
32+
val bubblePlotData: BubblePlotData,
33+
val xAxisData: AxisData = AxisData.Builder().build(),
34+
val yAxisData: AxisData = AxisData.Builder().build(),
35+
val isZoomAllowed: Boolean = true,
36+
val paddingTop: Dp = 30.dp,
37+
val bottomPadding: Dp = 10.dp,
38+
val paddingRight: Dp = 10.dp,
39+
val containerPaddingEnd: Dp = 15.dp,
40+
val backgroundColor: Color = Color.White,
41+
val gridLines: GridLines? = null,
42+
val accessibilityConfig: AccessibilityConfig = AccessibilityConfig()
43+
)
44+
45+
/**
46+
* Represent a Line in the [co.yml.charts.ui.linechart]
47+
*
48+
* @param dataPoints list of points [Point] in the line
49+
* @param bubbleStyle Adds styling options in [LineStyle] to the line path drawn.
50+
* @param intersectionPoint drawing logic to draw the point itself in [IntersectionPoint].
51+
* If null, the point is not drawn.
52+
* @param selectionHighlightPoint drawing logic to draw the highlight at the point when it is selected
53+
* in [SelectionHighlightPoint] If null, the point won't be highlighted on selection
54+
* @param shadowUnderLine drawing logic for the section under the line in [ShadowUnderLine].
55+
* @param selectionHighlightPopUp All prams related to selection popup to be added here in [SelectionHighlightPopUp]
56+
*/
57+
data class Bubble(
58+
val dataPoints: List<Point>,
59+
val bubbleStyle: BubbleStyle = BubbleStyle(),
60+
val intersectionPoint: IntersectionPoint? = null,
61+
val selectionHighlightPoint: SelectionHighlightPoint? = null,
62+
val shadowUnderLine: ShadowUnderLine? = null,
63+
val selectionHighlightPopUp: SelectionHighlightPopUp? = null
64+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package co.yml.charts.ui.bubblechart.model
2+
3+
import co.yml.charts.common.model.PlotData
4+
import co.yml.charts.common.model.PlotType
5+
6+
/**
7+
* LinePlotData is a data class that holds line graph related data and styling components
8+
* @param plotType : Defines the type of plot/graph
9+
* @param lines : Data related to the list of lines to be drawn.
10+
*/
11+
data class BubblePlotData(
12+
override val plotType: PlotType = PlotType.Line,
13+
val bubbles: List<Bubble>
14+
) : PlotData {
15+
companion object {
16+
fun default() =
17+
BubblePlotData(bubbles = listOf())
18+
}
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package co.yml.charts.ui.bubblechart.model
2+
3+
import androidx.compose.ui.graphics.BlendMode
4+
import androidx.compose.ui.graphics.Color
5+
import androidx.compose.ui.graphics.ColorFilter
6+
import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultBlendMode
7+
import androidx.compose.ui.graphics.drawscope.DrawStyle
8+
import androidx.compose.ui.graphics.drawscope.Stroke
9+
import co.yml.charts.ui.linechart.model.LineType
10+
11+
/**
12+
* Handles styling for the path drawn in the line graph
13+
*
14+
* @param color Defines the color of the path or line.
15+
* @param width Defines the width of the path/line stroke.
16+
* @param alpha Defines the alpha of the path/line.
17+
* @param style Defines if the path/line is filled or stroke.
18+
* @param colorFilter ColorFilter to apply to the [color] when drawn into the destination.
19+
* @param blendMode All prams related to selection popup to be added here in [SelectionHighlightPopUp]
20+
*/
21+
data class BubbleStyle(
22+
val lineType: BubbleType = BubbleType.SmoothCurve(isDotted = false),
23+
val color: Color = Color.Black,
24+
val width: Float = 8f,
25+
val alpha: Float = 1.0f,
26+
val style: DrawStyle = Stroke(width = width),
27+
val colorFilter: ColorFilter? = null,
28+
val blendMode: BlendMode = DefaultBlendMode
29+
)
30+
31+
/**
32+
* Represent different types of line to be drawn
33+
* @see LineType.Straight Draws straight lines with no curves, just a connection from
34+
* one point to another.
35+
* @see LineType.SmoothCurve Draws curved lines using cubic paths
36+
* It has @param isDotted true if line has to be dotted else false.
37+
* Also @param intervals Array of "on" and "off" distances for the dashed line segments
38+
* phase - Pixel offset into the intervals array
39+
*/
40+
sealed class BubbleType {
41+
abstract val isDotted: Boolean
42+
abstract var intervals: FloatArray
43+
44+
data class Straight(
45+
override val isDotted: Boolean = false,
46+
override var intervals: FloatArray = floatArrayOf(30f, 10f)
47+
) : BubbleType()
48+
49+
data class SmoothCurve(
50+
override val isDotted: Boolean = false,
51+
override var intervals: FloatArray = floatArrayOf(30f, 10f)
52+
) : BubbleType()
53+
}

YChartsLib/src/main/java/co/yml/charts/ui/combinedchart/CombinedChart.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import co.yml.charts.ui.linechart.drawShadowUnderLineAndIntersectionPoint
5353
import co.yml.charts.ui.linechart.drawStraightOrCubicLine
5454
import co.yml.charts.ui.linechart.getCubicPoints
5555
import co.yml.charts.ui.linechart.getMappingPointsToGraph
56-
import co.yml.charts.ui.linechart.model.LinePlotData
5756
import co.yml.charts.common.components.ItemDivider
5857
import co.yml.charts.common.components.accessibility.AccessibilityBottomSheetDialog
5958
import co.yml.charts.common.components.accessibility.CombinedChartInfo
@@ -66,6 +65,7 @@ import co.yml.charts.common.extensions.isTapped
6665
import co.yml.charts.common.model.PlotData
6766
import co.yml.charts.common.model.PlotType
6867
import co.yml.charts.common.model.Point
68+
import co.yml.charts.ui.linechart.model.LinePlotData
6969
import kotlinx.coroutines.launch
7070

7171
/**

YChartsLib/src/main/java/co/yml/charts/ui/linechart/LineChart.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ import co.yml.charts.axis.XAxis
4242
import co.yml.charts.axis.YAxis
4343
import co.yml.charts.axis.getXAxisScale
4444
import co.yml.charts.chartcontainer.container.ScrollableCanvasContainer
45-
import co.yml.charts.ui.linechart.model.IntersectionPoint
46-
import co.yml.charts.ui.linechart.model.Line
47-
import co.yml.charts.ui.linechart.model.LineChartData
48-
import co.yml.charts.ui.linechart.model.LineStyle
49-
import co.yml.charts.ui.linechart.model.LineType
50-
import co.yml.charts.ui.linechart.model.SelectionHighlightPoint
51-
import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
5245
import co.yml.charts.common.components.ItemDivider
5346
import co.yml.charts.common.components.accessibility.AccessibilityBottomSheetDialog
5447
import co.yml.charts.common.components.accessibility.LinePointInfo
@@ -57,6 +50,13 @@ import co.yml.charts.common.extensions.collectIsTalkbackEnabledAsState
5750
import co.yml.charts.common.extensions.drawGridLines
5851
import co.yml.charts.common.extensions.isNotNull
5952
import co.yml.charts.common.model.Point
53+
import co.yml.charts.ui.linechart.model.IntersectionPoint
54+
import co.yml.charts.ui.linechart.model.Line
55+
import co.yml.charts.ui.linechart.model.LineChartData
56+
import co.yml.charts.ui.linechart.model.LineStyle
57+
import co.yml.charts.ui.linechart.model.LineType
58+
import co.yml.charts.ui.linechart.model.SelectionHighlightPoint
59+
import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
6060
import kotlinx.coroutines.launch
6161

6262
/**

YChartsLib/src/main/java/co/yml/charts/ui/linechart/model/IntersectionPoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import androidx.compose.ui.unit.dp
2525
*/
2626
data class IntersectionPoint(
2727
val color: Color = Color.Black,
28-
val radius: Dp = 6.dp,
28+
val radius: Dp = 26.dp,
2929
val alpha: Float = 1.0f,
3030
val style: DrawStyle = Fill,
3131
val colorFilter: ColorFilter? = null,

YChartsLib/src/main/java/co/yml/charts/ui/linechart/model/LinePlotData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package co.yml.charts.ui.linechart.model
22

33
import co.yml.charts.common.model.PlotData
44
import co.yml.charts.common.model.PlotType
5+
56
/**
67
* LinePlotData is a data class that holds line graph related data and styling components
78
* @param plotType : Defines the type of plot/graph

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
android:exported="false"
3939
android:label="@string/title_activity_combined_line_bar_chart"
4040
android:theme="@style/Theme.YCharts" />
41+
<activity
42+
android:name="co.yml.ycharts.app.presentation.BubbleChartActivity"
43+
android:exported="false"
44+
android:label="@string/title_activity_bubble_chart"
45+
android:theme="@style/Theme.YCharts" />
4146
<activity
4247
android:name=".MainActivity"
4348
android:exported="true"

app/src/main/java/co/yml/ycharts/app/MainActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ class MainActivity : ComponentActivity() {
7777
)
7878
addActivityInOutAnim()
7979
})
80+
ChartButton(
81+
title = getString(R.string.bubble_chart),
82+
onClick = {
83+
startActivity(
84+
Intent(
85+
this@MainActivity,
86+
BubbleChartActivity::class.java
87+
)
88+
)
89+
addActivityInOutAnim()
90+
})
8091
}
8192
}
8293
}

0 commit comments

Comments
 (0)