Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dautovicharis committed Jun 19, 2024
1 parent 72baa1b commit dc162ba
Show file tree
Hide file tree
Showing 47 changed files with 362 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import io.github.dautovicharis.charts.internal.common.composable.ChartView
import io.github.dautovicharis.charts.style.BarChartDefaults
import io.github.dautovicharis.charts.style.BarChartStyle

/**
* A composable function that displays a Bar Chart.
*
* @param dataSet The data set to be displayed in the chart.
* @param style The style to be applied to the chart. If not provided, the default style will be used.
*/
@Composable
fun BarChartView(
dataSet: ChartDataSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import io.github.dautovicharis.charts.internal.validateBarData
import io.github.dautovicharis.charts.style.StackedBarChartDefaults
import io.github.dautovicharis.charts.style.StackedBarChartStyle

/**
* A composable function that displays a Stacked Bar Chart.
*
* @param dataSet The data set to be displayed in the chart.
* @param style The style to be applied to the chart. If not provided, the default style will be used.
*/
@Composable
fun StackedBarChartView(
dataSet: MultiChartDataSet,
Expand All @@ -32,54 +38,59 @@ fun StackedBarChartView(
}

if (errors.isEmpty()) {
var title by remember { mutableStateOf(dataSet.data.title) }
var labels by remember { mutableStateOf(listOf<String>()) }
ChartContent(dataSet = dataSet, style = style)
} else {
ChartErrors(chartViewStyle = style.chartViewStyle, errors = errors)
}
}

val colors by remember {
mutableStateOf(
style.barColors.ifEmpty {
generateColorShades(style.barColor, dataSet.data.getFirstPointsSize())
}
)
}
@Composable
private fun ChartContent(dataSet: MultiChartDataSet, style: StackedBarChartStyle) {
var title by remember { mutableStateOf(dataSet.data.title) }
var labels by remember { mutableStateOf(listOf<String>()) }

ChartView(chartViewsStyle = style.chartViewStyle) {
Text(
modifier = style.chartViewStyle.modifierTopTitle,
text = title,
style = style.chartViewStyle.styleTitle
)
val colors by remember {
mutableStateOf(
style.barColors.ifEmpty {
generateColorShades(style.barColor, dataSet.data.getFirstPointsSize())
}
)
}

StackedBarChart(
data = dataSet.data,
style = style,
colors = colors
) { selectedIndex ->
title = when (selectedIndex) {
NO_SELECTION -> title
else -> {
dataSet.data.items[selectedIndex].label
}
}
ChartView(chartViewsStyle = style.chartViewStyle) {
Text(
modifier = style.chartViewStyle.modifierTopTitle,
text = title,
style = style.chartViewStyle.styleTitle
)

if (dataSet.data.hasCategories()) {
labels = when (selectedIndex) {
NO_SELECTION -> emptyList()
else -> dataSet.data.items[selectedIndex].item.labels
}
StackedBarChart(
data = dataSet.data,
style = style,
colors = colors
) { selectedIndex ->
title = when (selectedIndex) {
NO_SELECTION -> title
else -> {
dataSet.data.items[selectedIndex].label
}
}

if (dataSet.data.hasCategories()) {
LegendItem(
chartViewsStyle = style.chartViewStyle,
colors = colors,
legend = dataSet.data.categories,
labels = labels
)
labels = when (selectedIndex) {
NO_SELECTION -> emptyList()
else -> dataSet.data.items[selectedIndex].item.labels
}
}
}
} else {
ChartErrors(chartViewStyle = style.chartViewStyle, errors = errors)

if (dataSet.data.hasCategories()) {
LegendItem(
chartViewsStyle = style.chartViewStyle,
colors = colors,
legend = dataSet.data.categories,
labels = labels
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import io.github.dautovicharis.charts.internal.linechart.LineChartViewImpl
import io.github.dautovicharis.charts.style.LineChartDefaults
import io.github.dautovicharis.charts.style.LineChartStyle

/**
* A composable function that displays a Line Chart for a single data set.
*
* @param dataSet The data set to be displayed in the chart.
* @param style The style to be applied to the chart. If not provided, the default style will be used.
*/
@Composable
fun LineChartView(
dataSet: ChartDataSet,
Expand All @@ -22,6 +28,12 @@ fun LineChartView(
)
}

/**
* A composable function that displays a Line Chart for multiple data sets.
*
* @param dataSet The data sets to be displayed in the chart.
* @param style The style to be applied to the chart. If not provided, the default style will be used.
*/
@Composable
fun LineChartView(
dataSet: MultiChartDataSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import io.github.dautovicharis.charts.internal.validatePieData
import io.github.dautovicharis.charts.style.PieChartDefaults
import io.github.dautovicharis.charts.style.PieChartStyle

/**
* A composable function that displays a Pie Chart.
*
* @param dataSet The data set to be displayed in the chart.
* @param style The style to be applied to the chart. If not provided, the default style will be used.
*/
@Composable
fun PieChartView(
dataSet: ChartDataSet,
Expand All @@ -32,23 +38,31 @@ fun PieChartView(
if (errors.isNotEmpty()) {
ChartErrors(chartViewStyle = style.chartViewStyle, errors = errors)
} else {
var title by remember { mutableStateOf(dataSet.data.label) }
ChartContent(dataSet = dataSet, style = style)
}
}

@Composable
private fun ChartContent(
dataSet: ChartDataSet,
style: PieChartStyle
) {
var title by remember { mutableStateOf(dataSet.data.label) }

ChartView(chartViewsStyle = style.chartViewStyle) {
Text(
modifier = style.chartViewStyle.modifierTopTitle,
text = title,
style = style.chartViewStyle.styleTitle
)
PieChart(
chartData = dataSet.data.item,
style = style,
chartStyle = style.chartViewStyle
) {
title = when (it) {
NO_SELECTION -> dataSet.data.label
else -> dataSet.data.item.labels[it]
}
ChartView(chartViewsStyle = style.chartViewStyle) {
Text(
modifier = style.chartViewStyle.modifierTopTitle,
text = title,
style = style.chartViewStyle.styleTitle
)
PieChart(
chartData = dataSet.data.item,
style = style,
chartStyle = style.chartViewStyle
) {
title = when (it) {
NO_SELECTION -> dataSet.data.label
else -> dataSet.data.item.labels[it]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ package io.github.dautovicharis.charts.common.model
import io.github.dautovicharis.charts.internal.common.model.ChartDataItem
import io.github.dautovicharis.charts.internal.common.model.toChartData


/**
* A class that represents a data set for a chart.
*
* @property data The data item that represents the data set.
* @constructor Creates a new ChartDataSet with the provided items, title, prefix, and postfix.
*
* @param items The list of data items.
* @param title The title of the data set.
* @param prefix The prefix to be added to each data item. Defaults to an empty string.
* @param postfix The postfix to be added to each data item. Defaults to an empty string.
*/
class ChartDataSet(
items: List<Float>,
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import io.github.dautovicharis.charts.internal.common.model.ChartDataItem
import io.github.dautovicharis.charts.internal.common.model.MultiChartData
import io.github.dautovicharis.charts.internal.common.model.toChartData

/**
* A class that represents a data set for a chart.
*
* @property data The data item that represents the data set.
* @constructor Creates a new ChartDataSet with the provided items, title, prefix, and postfix.
*
* @param items The list of data items.
* @param title The title of the data set.
* @param prefix The prefix to be added to each data item. Defaults to an empty string.
* @param postfix The postfix to be added to each data item. Defaults to an empty string.
*/
class MultiChartDataSet(
items: List<Pair<String, List<Float>>>,
categories: List<String> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
* A class that defines the style for a Bar Chart.
*
* @property modifier The modifier to be applied to the chart.
* @property chartViewStyle The style to be applied to the chart view.
* @property barColor The color to be used for the bars in the chart.
* @property space The space between the bars in the chart.
*/
@Immutable
class BarChartStyle internal constructor(
internal val modifier: Modifier,
internal val chartViewStyle: ChartViewStyle,
val barColor: Color,
val space: Dp
): Style {
/**
* Returns a list of the properties of the BarChartStyle.
*/
override fun getProperties(): List<Pair<String, Any>> {
return listOf(
BarChartStyle::barColor.name to barColor,
Expand All @@ -26,7 +37,17 @@ class BarChartStyle internal constructor(
}
}

/**
* An object that provides default styles for a Bar Chart.
*/
object BarChartDefaults {
/**
* Returns a BarChartStyle with the provided parameters or their default values.
*
* @param barColor The color to be used for the bars in the chart. Defaults to the primary color of the MaterialTheme.
* @param space The space between the bars in the chart. Defaults to 10.dp.
* @param chartViewStyle The style to be applied to the chart view. Defaults to the default style of ChartViewDefaults.
*/
@Composable
fun style(
barColor: Color = MaterialTheme.colorScheme.primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
* Returns a BarChartStyle with the provided parameters or their default values.
*
* @param barColor The color to be used for the bars in the chart. Defaults to the primary color of the MaterialTheme.
* @param space The space between the bars in the chart. Defaults to 10.dp.
* @param chartViewStyle The style to be applied to the chart view. Defaults to the default style of ChartViewDefaults.
*/
@Immutable
class StackedBarChartStyle internal constructor(
internal val modifier: Modifier,
Expand All @@ -19,6 +26,9 @@ class StackedBarChartStyle internal constructor(
val space: Dp,
val barColors: List<Color>,
): Style {
/**
* Returns a list of the properties of the StackedBarChartStyle.
*/
override fun getProperties(): List<Pair<String, Any>> {
return listOf(
StackedBarChartStyle::barColor.name to barColor,
Expand All @@ -28,7 +38,18 @@ class StackedBarChartStyle internal constructor(
}
}

/**
* An object that provides default styles for a Stacked Bar Chart.
*/
object StackedBarChartDefaults {
/**
* Returns a StackedBarChartStyle with the provided parameters or their default values.
*
* @param barColor The color to be used for the bars in the chart. Defaults to the primary color of the MaterialTheme.
* @param space The space between the bars in the chart. Defaults to 10.dp.
* @param barColors The colors to be used for the bars in the chart. Defaults to an empty list.
* @param chartViewStyle The style to be applied to the chart view. Defaults to the default style of ChartViewDefaults.
*/
@Composable
fun style(
barColor: Color = MaterialTheme.colorScheme.primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
* A class that defines the style for a Chart View.
*
* @property modifierMain The main modifier to be applied to the chart view.
* @property styleTitle The style to be applied to the title of the chart view.
* @property modifierTopTitle The modifier to be applied to the top title of the chart view.
* @property modifierLegend The modifier to be applied to the legend of the chart view.
* @property innerPadding The inner padding of the chart view.
* @property width The width of the chart view.
* @property backgroundColor The background color of the chart view.
*/
@Immutable
class ChartViewStyle internal constructor(
val modifierMain: Modifier,
Expand All @@ -31,8 +42,20 @@ class ChartViewStyle internal constructor(
val backgroundColor: Color
)

/**
* An object that provides default styles for a Chart View.
*/
object ChartViewDefaults {

/**
* Returns a ChartViewStyle with the provided parameters or their default values.
*
* @param width The width of the chart view. Defaults to Dp.Infinity.
* @param outerPadding The outer padding of the chart view. Defaults to 20.dp.
* @param innerPadding The inner padding of the chart view. Defaults to 15.dp.
* @param cornerRadius The corner radius of the chart view. Defaults to 20.dp.
* @param shadow The shadow of the chart view. Defaults to 15.dp.
* @param backgroundColor The background color of the chart view. Defaults to the surface color of the MaterialTheme.
*/
@Composable
fun style(
width: Dp = Dp.Infinity,
Expand Down
Loading

0 comments on commit dc162ba

Please sign in to comment.