Skip to content

Commit 32f7759

Browse files
adalpariclaude
andauthored
CMM-2001: Replace previous-period line with stacked bars in Views chart (#22752)
* Replace previous-period line with stacked bars in Views chart Use stacked column bars instead of a dashed line overlay to show previous period data in the bar chart mode of the Views stats card. When the previous period exceeds the current, a grey bar stacks on top to reach the previous value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Round bar tops only when no stacked bar is present Use three stacked series so that bars without a grey delta portion get rounded tops while bars with a stacked grey portion stay flat, with only the grey bar rounded on top. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Reduce bar chart corner rounding from 40% to 20% Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9839944 commit 32f7759

1 file changed

Lines changed: 57 additions & 24 deletions

File tree

  • WordPress/src/main/java/org/wordpress/android/ui/newstats/viewsstats

WordPress/src/main/java/org/wordpress/android/ui/newstats/viewsstats/ViewsStatsCard.kt

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarkerVisibility
7979
import com.patrykandpatrick.vico.core.cartesian.marker.DefaultCartesianMarker
8080
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesianLayer
8181
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer
82+
import com.patrykandpatrick.vico.compose.cartesian.layer.stacked
8283
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
8384
import com.patrykandpatrick.vico.compose.cartesian.rememberVicoScrollState
8485
import com.patrykandpatrick.vico.core.common.Insets
@@ -520,13 +521,45 @@ private fun ViewsStatsChart(
520521
}
521522
ChartType.BAR -> modelProducer.runTransaction {
522523
columnSeries {
523-
series(chartData.currentPeriod.map { it.views.toInt() })
524-
}
525-
if (hasPreviousPeriod) {
526-
lineSeries {
524+
if (hasPreviousPeriod) {
525+
// Series 1: current value when no
526+
// delta (rounded top)
527+
series(
528+
chartData.currentPeriod.zip(
529+
chartData.previousPeriod
530+
) { current, previous ->
531+
if (previous.views <= current.views)
532+
current.views.toInt()
533+
else 0
534+
}
535+
)
536+
// Series 2: current value when there
537+
// is a delta (flat top)
538+
series(
539+
chartData.currentPeriod.zip(
540+
chartData.previousPeriod
541+
) { current, previous ->
542+
if (previous.views > current.views)
543+
current.views.toInt()
544+
else 0
545+
}
546+
)
547+
// Series 3: delta (rounded top)
548+
series(
549+
chartData.currentPeriod.zip(
550+
chartData.previousPeriod
551+
) { current, previous ->
552+
maxOf(
553+
0L,
554+
previous.views - current.views
555+
).toInt()
556+
}
557+
)
558+
} else {
527559
series(
528-
chartData.previousPeriod
529-
.map { it.views.toInt() }
560+
chartData.currentPeriod.map {
561+
it.views.toInt()
562+
}
530563
)
531564
}
532565
}
@@ -677,26 +710,26 @@ private fun ViewsStatsChart(
677710
fill = fill(primaryColor),
678711
thicknessDp = 16f,
679712
shape = CorneredShape.rounded(
680-
allPercent = 40
713+
topLeftPercent = 20,
714+
topRightPercent = 20,
715+
)
716+
),
717+
LineComponent(
718+
fill = fill(primaryColor),
719+
thicknessDp = 16f,
720+
),
721+
LineComponent(
722+
fill = fill(secondaryColor),
723+
thicknessDp = 16f,
724+
shape = CorneredShape.rounded(
725+
topLeftPercent = 20,
726+
topRightPercent = 20,
681727
)
682728
)
683-
)
684-
),
685-
rememberLineCartesianLayer(
686-
lineProvider = LineCartesianLayer
687-
.LineProvider.series(
688-
LineCartesianLayer.Line(
689-
fill = LineCartesianLayer
690-
.LineFill.single(
691-
fill(secondaryColor)
692-
),
693-
stroke = LineCartesianLayer
694-
.LineStroke.Dashed(),
695-
pointConnector =
696-
LineCartesianLayer
697-
.PointConnector.Sharp
698-
)
699-
)
729+
),
730+
mergeMode = {
731+
ColumnCartesianLayer.MergeMode.stacked()
732+
}
700733
),
701734
startAxis = VerticalAxis.rememberStart(
702735
line = null

0 commit comments

Comments
 (0)