Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix sidebar sparklines not rendering at small container sizes (#4361)

Juan José Mata623d64075396
diff --git a/app/javascript/controllers/time_series_chart_controller.js b/app/javascript/controllers/time_series_chart_controller.js
index da4f046197..12a6534b1e 100644
--- a/app/javascript/controllers/time_series_chart_controller.js
+++ b/app/javascript/controllers/time_series_chart_controller.js
@@ -83,15 +83,12 @@ export default class extends Controller {
}
_draw() {
- // Guard against invalid dimensions (e.g., when container is collapsed or not yet rendered)
- const minWidth = 50;
- const minHeight = 50;
-
- if (
- this._d3ContainerWidth < minWidth ||
- this._d3ContainerHeight < minHeight
- ) {
- // Skip rendering if dimensions are invalid
+ // Guard against unmeasurable dimensions (e.g., when the container is
+ // collapsed or not yet rendered). A hidden container measures 0x0, and the
+ // ResizeObserver re-installs the chart as soon as layout gives it a real
+ // size, so skipping here only ever defers hidden charts. Small-but-real
+ // containers like the 32px-wide sidebar sparklines still render.
+ if (this._d3ContainerWidth <= 0 || this._d3ContainerHeight <= 0) {
return;
}
diff --git a/test/system/sidebar_sparklines_test.rb b/test/system/sidebar_sparklines_test.rb
index aa39237884..4772c8ef96 100644
--- a/test/system/sidebar_sparklines_test.rb
+++ b/test/system/sidebar_sparklines_test.rb
@@ -83,6 +83,26 @@ class SidebarSparklinesTest < ApplicationSystemTestCase
end
end
+ # The frames above only prove markup arrived. The regression these two
+ # tests pin down is one step later: the chart controller refused to draw
+ # into the sidebar's 32px-wide containers, so a "complete" frame stayed
+ # blank. The trendline is the only <path> the controller draws at these
+ # sizes (the empty state uses a dashed <line> + <circle>), so asserting
+ # the path proves a real series got rendered, not just an SVG element.
+ test "the group total sparkline draws its chart, not just its frame" do
+ visit root_path
+
+ assert_selector "#{GROUP_SPARKLINE_FRAME}[complete] [data-controller='time-series-chart'] svg path", minimum: 1
+ end
+
+ test "expanding a group draws the account sparklines, not just their frames" do
+ visit root_path
+
+ expand_first_group
+
+ assert_selector "#{ACCOUNT_SPARKLINE_FRAME}[complete] [data-controller='time-series-chart'] svg path", minimum: 1
+ end
+
test "a request that never comes back still raises the timeout badge" do
with_short_sparkline_timeout do
visit root_path