Skip to content

Commit

Permalink
Merge pull request #20394 from wordpress-mobile/issue/20363-fix-acces…
Browse files Browse the repository at this point in the history
…sibility-issue-on-traffic-chart

Fix accessibility issue on the traffic chart
  • Loading branch information
ravishanker authored Mar 3, 2024
2 parents 9a9abce + 668dd97 commit cb12a0f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ sealed class BlockListItem(val type: Type) {

data class TrafficBarChartItem(
val entries: List<Bar>,
val overlappingEntries: List<Bar>? = null,
val selectedItem: String? = null,
val onBarSelected: ((period: String?) -> Unit)? = null,
val onBarChartDrawn: ((visibleBarCount: Int) -> Unit)? = null,
val entryContentDescriptions: List<String>
) : BlockListItem(TRAFFIC_BAR_CHART) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,8 @@ class TrafficBarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
val barCount = chart.draw(item)
if (hasData(item.entries)) {
chart.post {
val accessibilityEvent = object : BarChartAccessibilityHelper.BarChartAccessibilityEvent {
override fun onHighlight(
entry: BarEntry,
index: Int
) {
val value = entry.data as? String
value?.let {
item.onBarSelected?.invoke(it)
}
}
}

val cutContentDescriptions = takeEntriesWithinGraphWidth(barCount, item.entryContentDescriptions)
accessibilityHelper = BarChartAccessibilityHelper(
chart,
contentDescriptions = cutContentDescriptions,
accessibilityEvent = accessibilityEvent
)
accessibilityHelper = BarChartAccessibilityHelper(chart, cutContentDescriptions)

ViewCompat.setAccessibilityDelegate(chart, accessibilityHelper)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ class TrafficOverviewMapper @Inject constructor(
fun buildChart(
dates: List<VisitsAndViewsModel.PeriodData>,
statsGranularity: StatsGranularity,
onBarSelected: (String?) -> Unit,
onBarChartDrawn: (visibleBarCount: Int) -> Unit,
selectedType: Int,
selectedItemPeriod: String
selectedType: Int
): List<BlockListItem> {
val chartItems = dates.map {
val value = when (SelectedType.valueOf(selectedType)) {
Expand Down Expand Up @@ -116,15 +114,7 @@ class TrafficOverviewMapper @Inject constructor(
chartItems
)

result.add(
BlockListItem.TrafficBarChartItem(
chartItems,
selectedItem = selectedItemPeriod,
onBarSelected = onBarSelected,
onBarChartDrawn = onBarChartDrawn,
entryContentDescriptions = contentDescriptions
)
)
result.add(BlockListItem.TrafficBarChartItem(chartItems, onBarChartDrawn, contentDescriptions))
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.wordpress.android.ui.stats.refresh.lists.widget.WidgetUpdater
import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter
import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider
import org.wordpress.android.ui.stats.refresh.utils.StatsUtils
import org.wordpress.android.ui.stats.refresh.utils.trackGranular
import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
Expand Down Expand Up @@ -269,14 +268,7 @@ class TrafficOverviewUseCase(
selectedItem: VisitsAndViewsModel.PeriodData
) {
items.addAll(
trafficOverviewMapper.buildChart(
dates,
lowerGranularity,
this::onBarSelected,
this::onBarChartDrawn,
uiState.selectedPosition,
selectedItem.period
)
trafficOverviewMapper.buildChart(dates, lowerGranularity, this::onBarChartDrawn, uiState.selectedPosition)
)
items.add(
trafficOverviewMapper.buildColumns(
Expand All @@ -287,20 +279,6 @@ class TrafficOverviewUseCase(
)
}

private fun onBarSelected(period: String?) {
analyticsTracker.trackGranular(
AnalyticsTracker.Stat.STATS_OVERVIEW_BAR_CHART_TAPPED,
lowerGranularity
)
if (period != null && period != "empty") {
val selectedDate = statsDateFormatter.parseStatsDate(lowerGranularity, period)
selectedDateProvider.selectDate(
selectedDate,
lowerGranularity
)
}
}

@Suppress("MagicNumber")
private fun onColumnSelected(position: Int) {
val event = when (position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
class BarChartAccessibilityHelper(
private val barChart: BarChart,
private val contentDescriptions: List<String>,
private val accessibilityEvent: BarChartAccessibilityEvent
private val accessibilityEvent: BarChartAccessibilityEvent? = null
) : ExploreByTouchHelper(barChart) {
private val dataSet: IBarDataSet = barChart.data.dataSets.first()

Expand Down Expand Up @@ -51,7 +51,7 @@ class BarChartAccessibilityHelper(
when (action) {
AccessibilityNodeInfoCompat.ACTION_CLICK -> {
val entry = dataSet.getEntryForIndex(virtualViewId)
accessibilityEvent.onHighlight(entry, virtualViewId)
accessibilityEvent?.onHighlight(entry, virtualViewId)
return true
}
}
Expand All @@ -74,7 +74,7 @@ class BarChartAccessibilityHelper(
}
}

node.addAction(AccessibilityActionCompat.ACTION_CLICK)
accessibilityEvent?.let { node.addAction(AccessibilityActionCompat.ACTION_CLICK) }
val entryRectF = barChart.getBarBounds(dataSet.getEntryForIndex(virtualViewId))
val entryRect = Rect()
entryRectF.round(entryRect)
Expand Down

0 comments on commit cb12a0f

Please sign in to comment.