Skip to content

Commit

Permalink
Merge pull request #109 from AkYML/feature/ui-cleanups
Browse files Browse the repository at this point in the history
UI cleanups
  • Loading branch information
dkk009 authored Jun 22, 2023
2 parents 1494441 + 4ca6024 commit 68c6fed
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 158 deletions.
32 changes: 24 additions & 8 deletions YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import co.yml.charts.ui.barchart.models.GroupBar
import co.yml.charts.ui.bubblechart.model.Bubble
import co.yml.charts.ui.bubblechart.model.BubbleGradientType
import co.yml.charts.ui.bubblechart.model.BubbleStyle
import co.yml.charts.ui.linechart.model.SelectionHighlightPoint
import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp
import co.yml.charts.ui.piechart.models.PieChartData
import kotlin.math.sin
import kotlin.random.Random
Expand Down Expand Up @@ -50,7 +52,7 @@ object DataUtils {
for (index in 0 until listSize) {
list.add(
Point(
index.toFloat(),
index.toFloat(),
(start until maxRange).random().toFloat()
)
)
Expand Down Expand Up @@ -82,7 +84,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.RadialGradient)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.RadialGradient),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand All @@ -91,7 +95,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.LinearGradient)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.LinearGradient),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand All @@ -100,7 +106,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.VerticalGradient)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.VerticalGradient),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand All @@ -109,7 +117,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand All @@ -118,7 +128,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Repeated)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Repeated),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand All @@ -127,7 +139,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Mirror)
bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient,tileMode = TileMode.Mirror),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand Down Expand Up @@ -156,7 +170,9 @@ object DataUtils {
Bubble(
center = point,
density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(),
bubbleStyle = BubbleStyle(solidColor = bubbleColor, useGradience = false)
bubbleStyle = BubbleStyle(solidColor = bubbleColor, useGradience = false),
selectionHighlightPoint = SelectionHighlightPoint(Color.Black),
selectionHighlightPopUp = SelectionHighlightPopUp(Color.White)
)
)
}
Expand Down
102 changes: 54 additions & 48 deletions YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/BubbleChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
containerBackgroundColor = backgroundColor,
isPinchZoomEnabled = isZoomAllowed,
drawXAndYAxis = { scrollOffset, xZoom ->
YAxis(
modifier = Modifier
.fillMaxHeight()
.onGloballyPositioned {
columnWidth = it.size.width.toFloat()
}, yAxisData = yAxisData
)

XAxis(xAxisData = xAxisData,
modifier = Modifier
.fillMaxWidth()
Expand All @@ -149,24 +157,24 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
zoomScale = xZoom,
chartData = bubblePoints,
axisStart = columnWidth)
YAxis(
modifier = Modifier
.fillMaxHeight()
.onGloballyPositioned {
columnWidth = it.size.width.toFloat()
}, yAxisData = yAxisData
)

},
onDraw = { scrollOffset, xZoom ->
val yBottom = size.height - rowHeight

val yOffset = ((yBottom - paddingTop.toPx()) / maxElementInYAxis)
xOffset = xAxisData.axisStepSize.toPx() * xZoom
val xLeft = columnWidth // To add extra space if needed
val pointsData = getMappingPointsToGraph(
bubblePoints, xMin, xOffset, xLeft, scrollOffset, yBottom, yMin, yOffset
bubblePoints,
xMin,
xOffset,
xLeft,
scrollOffset,
yBottom,
yMin,
yOffset
)
val (cubicPoints1, cubicPoints2) = getCubicPoints(pointsData)
val tapPointLocks = mutableMapOf<Int, Pair<Point, Offset>>()
// Draw guide lines
gridLines?.let {
Expand All @@ -184,17 +192,28 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
it
)
}
drawUnderScrollMask(columnWidth, paddingRight, bgColor)

pointsData.forEachIndexed { index, offset ->
val drawingOffset = Offset(offset.x, offset.y)
bubbles[index].draw(
this,
drawingOffset,
bubbleChartData.maximumBubbleRadius
)

bubbles[index].draw(this, offset, bubbleChartData.maximumBubbleRadius)
if (isTapped && offset.isTapped(tapOffset.x, xOffset)) {
tapPointLocks[0] = bubbles[index].center to offset
identifiedPoint = tapPointLocks.values.map { it.first }.first()
drawHighLightOnSelectedPoint(
tapPointLocks,
columnWidth,
paddingRight,
yBottom,
bubbles[index].selectionHighlightPoint
)

pointsData.forEachIndexed { index, point ->
if (isTapped && point.isTapped(tapOffset.x, xOffset)) {
// Dealing with only one line graph hence tapPointLocks[0]
tapPointLocks[0] = bubbles[index].center to point
}
}

val selectedOffset = tapPointLocks.values.firstOrNull()?.second

if (selectionTextVisibility && selectedOffset.isNotNull()) {
Expand All @@ -204,22 +223,7 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
bubbles[index].selectionHighlightPopUp
)
}
if (isTapped) {
val x = tapPointLocks.values.firstOrNull()?.second?.x
if (x != null) identifiedPoint =
tapPointLocks.values.map { it.first }.first()
drawHighLightOnSelectedPoint(
tapPointLocks,
columnWidth,
paddingRight,
yBottom,
bubbles[index].selectionHighlightPoint
)
}

}
drawUnderScrollMask(columnWidth, paddingRight, bgColor)


},
onPointClicked = { offset: Offset, _: Float ->
Expand All @@ -244,23 +248,25 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
backgroundColor = Color.White,
content = {
LazyColumn {
items(bubbles?.size ?: 0) { index ->
Column {
BubblePointInfo(
xAxisData.axisLabelDescription(
xAxisData.labelData(
index
)
),
bubbles[index].center.description,
bubbles[index].bubbleStyle.solidColor,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
dividerColor = accessibilityConfig.dividerColor
)
bubbles.size?.let {
items(it) { index ->
Column {
BubblePointInfo(
xAxisData.axisLabelDescription(
xAxisData.labelData(
index
)
),
bubbles[index].center.description + "density is" + { bubbles[index].density },
bubbles[index].bubbleStyle.solidColor,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
dividerColor = accessibilityConfig.dividerColor
)
}
}
}
}
Expand Down
Loading

0 comments on commit 68c6fed

Please sign in to comment.