From 7ddd4a6683ab4499b0769c18656b0bba6ac533a8 Mon Sep 17 00:00:00 2001 From: AkYML Date: Thu, 15 Jun 2023 10:48:13 +0530 Subject: [PATCH] update samples --- .../co/yml/charts/common/utils/DataUtils.kt | 93 +++++++++++++++++-- .../ui/bubblechart/model/BubbleChartData.kt | 45 +++++++-- .../ui/bubblechart/model/BubbleStyle.kt | 16 +--- 3 files changed, 127 insertions(+), 27 deletions(-) diff --git a/YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt b/YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt index 04fe47da..93f722c5 100644 --- a/YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt +++ b/YChartsLib/src/main/java/co/yml/charts/common/utils/DataUtils.kt @@ -2,6 +2,7 @@ package co.yml.charts.common.utils import androidx.compose.foundation.layout.Arrangement import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.TileMode import androidx.compose.ui.text.TextStyle import co.yml.charts.axis.DataCategoryOptions import co.yml.charts.common.model.LegendLabel @@ -12,6 +13,7 @@ import co.yml.charts.ui.barchart.models.BarChartType import co.yml.charts.ui.barchart.models.BarData 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.piechart.models.PieChartData import kotlin.math.sin @@ -69,14 +71,86 @@ object DataUtils { ): List { val list = arrayListOf() points.forEachIndexed { index, point -> - val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue - list.add( - Bubble( - center = point, - density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), - bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor, Color.White), useGradience = true) - ) - ) + val bubbleColor1 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)) + val bubbleColor2 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)) + val bubbleColor3 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)) + val bubbleColor4 = Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)) + + when(Random.nextInt(0,7)){ + 0->{ + list.add( + Bubble( + center = point, + density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), + bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2,bubbleColor3,bubbleColor4), useGradience = true, gradientType = BubbleGradientType.RadialGradient) + ) + ) + } + 1->{ + list.add( + Bubble( + center = point, + density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), + bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.LinearGradient) + ) + ) + } + 2->{ + list.add( + Bubble( + center = point, + density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), + bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.VerticalGradient) + ) + ) + } + 3->{ + list.add( + Bubble( + center = point, + density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), + bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient) + ) + ) + } + 4->{ + list.add( + Bubble( + center = point, + density = (minDensity.toInt() until maxDensity.toInt()).random().toFloat(), + bubbleStyle = BubbleStyle(gradientColors = listOf(bubbleColor1, bubbleColor2), useGradience = true, gradientType = BubbleGradientType.HorizontalGradient, tileMode = TileMode.Decal) + ) + ) + } + 5->{ + list.add( + 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) + ) + ) + } + 6->{ + list.add( + 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.Clamp) + ) + ) + } + 7->{ + list.add( + 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) + ) + ) + } + } + } return list @@ -95,7 +169,7 @@ object DataUtils { ): List { val list = arrayListOf() points.forEachIndexed { index, point -> - val bubbleColor = if (index % 2 == 0) Color.Red else Color.Blue + val bubbleColor =Color(red = Random.nextInt(256),green= Random.nextInt(256),blue= Random.nextInt(256), alpha =Random.nextInt(from = 150, until = 256) ) list.add( Bubble( center = point, @@ -103,7 +177,6 @@ object DataUtils { bubbleStyle = BubbleStyle(solidColor = bubbleColor, useGradience = false) ) ) - } return list } diff --git a/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleChartData.kt b/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleChartData.kt index 5949f416..61fb5367 100644 --- a/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleChartData.kt +++ b/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleChartData.kt @@ -91,10 +91,43 @@ data class Bubble( ) private fun getBrush(bubbleStyle: BubbleStyle, center: Offset, density: Float): Brush { - return Brush.radialGradient( - colors = bubbleStyle.gradientColors, - center = center, - radius = density, - tileMode = TileMode.Decal - ) + when (bubbleStyle.gradientType) { + BubbleGradientType.RadialGradient -> { + return Brush.radialGradient( + colors = bubbleStyle.gradientColors, + center = center, + radius = density, + tileMode = bubbleStyle.tileMode + ) + } + + BubbleGradientType.LinearGradient -> { + return Brush.linearGradient( + colors = bubbleStyle.gradientColors, + tileMode = bubbleStyle.tileMode, + start = center, + end = center + ) + } + + BubbleGradientType.VerticalGradient -> { + return Brush.verticalGradient( + colors = bubbleStyle.gradientColors, + tileMode = bubbleStyle.tileMode, + startY = center.y - density / 2, + endY = center.y + density / 2, + ) + } + + BubbleGradientType.HorizontalGradient -> { + return Brush.horizontalGradient( + colors = bubbleStyle.gradientColors, + tileMode = bubbleStyle.tileMode, + startX = center.x - density / 2, + endX = center.x + density / 2, + ) + } + } + + } diff --git a/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleStyle.kt b/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleStyle.kt index 8ca19b8d..79945fe5 100644 --- a/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleStyle.kt +++ b/YChartsLib/src/main/java/co/yml/charts/ui/bubblechart/model/BubbleStyle.kt @@ -4,6 +4,7 @@ import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.LinearGradient +import androidx.compose.ui.graphics.TileMode import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultBlendMode import androidx.compose.ui.graphics.drawscope.DrawStyle import androidx.compose.ui.graphics.drawscope.Fill @@ -26,9 +27,10 @@ import co.yml.charts.ui.linechart.model.LineType */ data class BubbleStyle( val gradientColors: List = listOf(Color.Blue, Color.Red), - val gradientType: BubbleGradientType = BubbleGradientType.None(), - val solidColor: Color = Color.Blue, + val gradientType: BubbleGradientType = BubbleGradientType.HorizontalGradient, + val tileMode: TileMode = TileMode.Decal, val useGradience: Boolean = false, + val solidColor: Color = Color.Blue, val width: Float = 8f, val alpha: Float = 1.0f, val style: DrawStyle = Fill, @@ -70,14 +72,6 @@ sealed class BubbleGradientType { * * @constructor Create empty Horizontal gradient */ - class HorizontalGradient() : BubbleGradientType() - - /** - * None - * - * @constructor Create empty None - */ - class None() : BubbleGradientType() - + object HorizontalGradient : BubbleGradientType() }