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

Fix the height of bar charts when a bar is focussed. #136

Merged
merged 1 commit into from
Aug 3, 2024
Merged
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 @@ -101,20 +101,19 @@ private fun DrawScope.drawBars(
val spacing = style.space.toPx()
val barWidth = (size.width - spacing * (dataSize - 1)) / dataSize

val finalBarHeight = size.height * (abs(value) / (maxValue - minValue))
val selectedBarScale = if (index == selectedIndex) MAX_SCALE else DEFAULT_SCALE
val finalBarHeight = size.height * selectedBarScale * (abs(value) / (maxValue - minValue))
val barHeight = lerp(0f, finalBarHeight.toFloat(), progress[index].value)

val top = if (value >= 0) baselineY - barHeight else baselineY
val left = (barWidth + spacing) * index

val selectedBarScale = if (index == selectedIndex) MAX_SCALE else DEFAULT_SCALE

drawRect(
color = barColor,
topLeft = Offset(x = left, y = top.toFloat()),
size = Size(
width = barWidth * selectedBarScale,
height = barHeight * selectedBarScale
height = barHeight
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private fun DrawScope.drawBars(
item.item.points.forEachIndexed { dataIndex, value ->
val height = lerp(
0f,
(value.toFloat() / totalMaxValue.toFloat()) * size.height,
(value.toFloat() * selectedBarScale / totalMaxValue.toFloat()) * size.height,
progress[index].value
)
topOffset -= height
Expand All @@ -108,7 +108,7 @@ private fun DrawScope.drawBars(
topLeft = Offset(x = index * (barWidth + spacing), y = topOffset),
size = Size(
width = barWidth * selectedBarScale,
height = height * selectedBarScale
height = height
)
)
}
Expand Down