Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide x-axis bar chart #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.aay.compose.utils.ChartDefaultValues
*/
@Composable
fun BarChart(
modifier: Modifier = ChartDefaultValues.barModifier,
chartParameters: List<BarParameters> = ChartDefaultValues.barParameters,
gridColor: Color = ChartDefaultValues.gridColor,
xAxisData: List<String> = emptyList(),
Expand Down Expand Up @@ -83,6 +84,7 @@ fun BarChart(
}

BarChartContent(
modifier = modifier,
barsParameters = chartParameters,
gridColor = gridColor,
xAxisData = xAxisData,
Expand Down Expand Up @@ -119,7 +121,7 @@ fun BarChart(
barWidth = barWidth,
spaceBetweenBars = spaceBetweenBars,
spaceBetweenGroups = spaceBetweenGroups,
modifier = Modifier.weight(1f),
modifier = modifier.weight(1f),
barCornerRadius = barCornerRadius
)

Expand All @@ -142,6 +144,7 @@ fun BarChart(

LegendPosition.DISAPPEAR -> {
BarChartContent(
modifier = modifier,
barsParameters = chartParameters,
gridColor = gridColor,
xAxisData = xAxisData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.aay.compose.barChart.components

import androidx.compose.animation.core.*
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
Expand All @@ -28,6 +29,7 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalTextApi::class)
@Composable
internal fun BarChartContent(
modifier: Modifier = Modifier,
barsParameters: List<BarParameters>,
gridColor: Color,
xAxisData: List<String>,
Expand All @@ -43,7 +45,6 @@ internal fun BarChartContent(
barWidth: Dp,
spaceBetweenBars: Dp,
spaceBetweenGroups: Dp,
modifier: Modifier = Modifier,
barCornerRadius: Dp
) {

Expand Down Expand Up @@ -82,10 +83,10 @@ internal fun BarChartContent(
}
) {
Canvas(
modifier = Modifier.fillMaxSize()
modifier = Modifier.size(height = boxHeight, width = boxWidth)
) {

val spacingY = (boxHeight / 10)
val spacingY = (boxHeight - ((boxHeight - 20.0.dp.toPx().toDp()) / 1.1f.toDp().toPx()))
xRegionWidth = ((barWidth + spaceBetweenBars) * barsParameters.size) + spaceBetweenGroups
xRegionWidthWithoutSpacing = xRegionWidth - spaceBetweenGroups
maxWidth = (xRegionWidth * xAxisData.size) - spaceBetweenGroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.aay.compose.utils

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -59,4 +61,5 @@ internal object ChartDefaultValues {
val gridOrientation = GridOrientation.HORIZONTAL
val legendPosition = LegendPosition.TOP
val barCornerRadius = 0.dp
val barModifier = Modifier.fillMaxSize()
}
4 changes: 2 additions & 2 deletions common/src/commonMain/kotlin/com/aay/common/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import androidx.compose.runtime.Composable
fun App() {

/** Sample of Line Chart **/
LineChartSample()
// LineChartSample()


/** Sample of Bar Chart **/
// BarChartSample()
BarChartSample()

/** Sample of Donut Chart **/
// DonutChartSample()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fun BarChartSample() {

Box(Modifier.fillMaxSize().padding(24.dp)) {
BarChart(
modifier = Modifier.fillMaxSize(),
chartParameters = testBarParameters,
gridColor = Color.DarkGray,
xAxisData = listOf("2016", "2017", "2018", "2019", "2020", "2021", "2022"),
Expand Down