Skip to content

Commit

Permalink
Merge pull request #107 from AkYML/feature/acccessibilityCustomizations
Browse files Browse the repository at this point in the history
Feature/acccessibility customizations
  • Loading branch information
dkk009 authored Jun 20, 2023
2 parents 5ccc97a + 0ff653a commit 1494441
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,31 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
* Composable to display each bar item for given bar chart
* @param axisLabelDescription: Axis label description
* @param barDescription: Bar description
* @param titleTextSize: TextUnit title font size
* @param descriptionTextSize: TextUnit description font size
*/
@Composable
fun BarInfo(
axisLabelDescription: String,
barDescription: String, barColor: Color
barDescription: String, barColor: Color,
titleTextSize:TextUnit,
descriptionTextSize:TextUnit
) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.clickable { }
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
) {
Text(axisLabelDescription, fontSize = 12.sp)
Text(axisLabelDescription, fontSize = titleTextSize)
Spacer(modifier = Modifier.width(10.dp))
Column(
modifier = Modifier
Expand All @@ -48,7 +53,7 @@ fun BarInfo(
.background(barColor)
.size(20.dp)
)
Text(barDescription, fontSize = 12.sp)
Text(barDescription, fontSize = descriptionTextSize)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand All @@ -23,20 +24,24 @@ import androidx.compose.ui.unit.sp
* @param axisLabelDescription: Axis label description.
* @param pointDescription: Details of each point on the line.
* @param bubbleColor: Color of each bubble.
* @param titleTextSize: TextUnit title font size
* @param descriptionTextSize: TextUnit description font size
*/
@Composable
fun BubblePointInfo(
axisLabelDescription: String,
pointDescription: String,
bubbleColor: Color
bubbleColor: Color,
titleTextSize: TextUnit,
descriptionTextSize: TextUnit
) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.clickable { }
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
) {
Text(axisLabelDescription, fontSize = 12.sp)
Text(axisLabelDescription, fontSize = titleTextSize)
Spacer(modifier = Modifier.width(5.dp))
Column(
modifier = Modifier
Expand All @@ -50,7 +55,7 @@ fun BubblePointInfo(
.background(bubbleColor)
.size(20.dp)
)
Text(pointDescription, fontSize = 12.sp)
Text(pointDescription, fontSize = descriptionTextSize)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import co.yml.charts.ui.barchart.models.GroupBar
Expand All @@ -32,6 +33,8 @@ import co.yml.charts.common.model.Point
* @param axisLabelDescription: Axis label description.
* @param barColorPaletteList: List of each bar colors for a given group bar.
* @param dividerColor: Divider color between each point items.
* @param titleTextSize: TextUnit title font size
* @param descriptionTextSize: TextUnit description font size
*/
@Composable
fun CombinedChartInfo(
Expand All @@ -40,15 +43,17 @@ fun CombinedChartInfo(
groupBar: GroupBar?,
axisLabelDescription: String,
barColorPaletteList: List<Color>,
dividerColor: Color
dividerColor: Color,
titleTextSize: TextUnit,
descriptionTextSize: TextUnit
) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.clickable { }
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
) {
Text(axisLabelDescription, fontSize = 12.sp)
Text(axisLabelDescription, fontSize = titleTextSize)
Spacer(modifier = Modifier.width(10.dp))
Column(
modifier = Modifier
Expand All @@ -66,7 +71,7 @@ fun CombinedChartInfo(
)
.size(10.dp)
)
Text(point.description, fontSize = 12.sp)
Text(point.description, fontSize = descriptionTextSize)
}
Spacer(modifier = Modifier.height(5.dp))
}
Expand All @@ -79,7 +84,7 @@ fun CombinedChartInfo(
.background(barColorPaletteList[index])
.size(20.dp)
)
Text(value.description, fontSize = 12.sp)
Text(value.description, fontSize = descriptionTextSize)
}
Spacer(modifier = Modifier.height(5.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import co.yml.charts.ui.barchart.models.GroupBar
Expand All @@ -26,20 +27,24 @@ import co.yml.charts.ui.barchart.models.GroupBar
* @param axisLabelDescription: Axis label description.
* @param groupBar: Details of each group bar.
* @param barColorPaletteList: List of each bar colors for a given group bar.
* @param titleTextSize: TextUnit title font size
* @param descriptionTextSize: TextUnit description font size
*/
@Composable
fun GroupBarInfo(
groupBar: GroupBar,
axisLabelDescription: String,
barColorPaletteList: List<Color>
barColorPaletteList: List<Color>,
titleTextSize: TextUnit,
descriptionTextSize: TextUnit
) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.clickable { }
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
) {
Text(axisLabelDescription, fontSize = 12.sp)
Text(axisLabelDescription, fontSize =titleTextSize)
Spacer(modifier = Modifier.width(10.dp))
Column(
modifier = Modifier
Expand All @@ -54,7 +59,7 @@ fun GroupBarInfo(
.background(barColorPaletteList[index])
.size(20.dp)
)
Text(value.description, fontSize = 12.sp)
Text(value.description, fontSize = descriptionTextSize)
}
Spacer(modifier = Modifier.height(5.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand All @@ -23,20 +24,25 @@ import androidx.compose.ui.unit.sp
* @param axisLabelDescription: Axis label description.
* @param pointDescription: Details of each point on the line.
* @param lineColor: Color of each line.
* @param titleTextSize: TextUnit title font size
* @param descriptionTextSize: TextUnit description font size
*
*/
@Composable
fun LinePointInfo(
axisLabelDescription: String,
pointDescription: String,
lineColor: Color
lineColor: Color,
titleTextSize: TextUnit,
descriptionTextSize: TextUnit
) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.clickable { }
.semantics(mergeDescendants = true) {}, verticalAlignment = Alignment.CenterVertically
) {
Text(axisLabelDescription, fontSize = 12.sp)
Text(axisLabelDescription, fontSize = titleTextSize)
Spacer(modifier = Modifier.width(5.dp))
Column(
modifier = Modifier
Expand All @@ -50,7 +56,7 @@ fun LinePointInfo(
.background(lineColor)
.size(20.dp)
)
Text(pointDescription, fontSize = 12.sp)
Text(pointDescription, fontSize = descriptionTextSize)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import co.yml.charts.ui.piechart.models.PieChartData
Expand All @@ -20,9 +21,10 @@ import co.yml.charts.ui.piechart.models.PieChartData
* Composable to display each slice for a given pie chart.
* @param slice: Details of each slice in pie/ donut chart.
* @param slicePercentage: Percentage of each slice.
* @param textSize: TextUnit text font size
*/
@Composable
fun SliceInfo(slice: PieChartData.Slice, slicePercentage: Int) {
fun SliceInfo(slice: PieChartData.Slice, slicePercentage: Int, textSize: TextUnit) {
// Merge elements below for accessibility purposes
Row(modifier = Modifier
.clickable { }
Expand All @@ -40,7 +42,7 @@ fun SliceInfo(slice: PieChartData.Slice, slicePercentage: Int) {
.weight(1f)
.padding(top = 10.dp, bottom = 10.dp)
) {
Text(slice.sliceDescription(slicePercentage), fontSize = 12.sp)
Text(slice.sliceDescription(slicePercentage), fontSize = textSize)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package co.yml.charts.common.model

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import co.yml.charts.common.utils.ChartConstants

/**
Expand All @@ -13,13 +15,17 @@ import co.yml.charts.common.utils.ChartConstants
* @param popUpTopRightButtonDescription: Content description of the button visible on the accessibility popUp at the top right.
* @param dividerColor: Defines the color for the divider used in the accessibility popUp
* @param dividerThickness: Defines the thickness for the divider in Dp used in the accessibility popUp
* @param titleTextSize: Defines the font-size of titles used in the accessibility popUp
* @param descriptionTextSize: Defines the font-size of descriptions used in the accessibility popUp
*/
data class AccessibilityConfig(
val chartDescription: String = ChartConstants.CHART_DESCRIPTION,
val shouldHandleBackWhenTalkBackPopUpShown: Boolean = true,
val popUpTopRightButtonTitle: String = ChartConstants.POPUP_TOP_RIGHT_BUTTON_TITLE,
val popUpTopRightButtonDescription: String = ChartConstants.POPUP_TOP_RIGHT_BUTTON_DESCRIPTION,
val dividerColor: Color = Color.Gray,
val dividerThickness: Dp = 2.dp
)
val dividerThickness: Dp = 2.dp,
val titleTextSize: TextUnit = 14.sp,
val descriptionTextSize: TextUnit = 14.sp,
)

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
* LegendsConfig data class params used in config label in graph.
Expand All @@ -19,6 +21,7 @@ import androidx.compose.ui.unit.dp
* */
data class LegendsConfig(
val legendLabelList: List<LegendLabel>,
val textSize: TextUnit = 14.sp,
val gridColumnCount: Int = 1,
val gridPaddingHorizontal: Dp = 8.dp,
val gridPaddingVertical: Dp = 8.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ fun BarChart(modifier: Modifier, barChartData: BarChartData) {
)
},
chartData[index].description,
chartData[index].color
chartData[index].color,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ fun GroupBarChart(modifier: Modifier, groupBarChartData: GroupBarChartData) {
xAxisData.axisLabelDescription(
xAxisData.labelData(index)
),
barPlotData.barColorPaletteList
barPlotData.barColorPaletteList,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ fun StackedBarChart(
xAxisData.axisLabelDescription(
xAxisData.labelData(index)
),
barPlotData.barColorPaletteList
barPlotData.barColorPaletteList,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ fun BubbleChart(modifier: Modifier, bubbleChartData: BubbleChartData) {
)
),
bubbles[index].center.description,
bubbles[index].bubbleStyle.solidColor
?: bubbles[index].bubbleStyle.gradientColors.first()
bubbles[index].bubbleStyle.solidColor,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ fun CombinedChart(modifier: Modifier, combinedChartData: CombinedChartData) {
xAxisData.labelData(index)
),
barColorPaletteList = barPlotData.barColorPaletteList,
dividerColor = accessibilityConfig.dividerColor
dividerColor = accessibilityConfig.dividerColor,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)
ItemDivider(
thickness = accessibilityConfig.dividerThickness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ fun LineChart(modifier: Modifier, lineChartData: LineChartData) {
)
),
point.description,
linePlotData.lines[lineIndex].lineStyle.color
linePlotData.lines[lineIndex].lineStyle.color,
accessibilityConfig.titleTextSize,
accessibilityConfig.descriptionTextSize
)

ItemDivider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ fun DonutPieChart(
items(pieChartData.slices.size) { index ->
SliceInfo(
pieChartData.slices[index],
proportions[index].roundToInt()
proportions[index].roundToInt(),
accessibilityConfig.descriptionTextSize
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ fun PieChart(
LazyColumn {
items(pieChartData.slices.size) { index ->
SliceInfo(
pieChartData.slices[index], proportions[index].roundToInt()
pieChartData.slices[index], proportions[index].roundToInt(),
accessibilityConfig.descriptionTextSize
)
}
}
Expand Down
Loading

0 comments on commit 1494441

Please sign in to comment.