Skip to content

Conversation

@staticpayload
Copy link

@staticpayload staticpayload commented Dec 28, 2025

Summary

Fixes #18

The Problem

The "Messages per day" chart on the /stats page got stuck at March 2025 because the x-axis scale calculation couldn't handle the growing number of days of data.

Root Cause Analysis:

The previous bar width calculation:

bar_width = [(available_width - (total_days * bar_spacing)) / total_days, min_bar_width].max

When total_days grew large (e.g., 600+ days since community started):

  • Formula produced negative or very small values
  • .max would pick min_bar_width = 0.15
  • But then: 600 * (0.15 + 0.05) = 120% width
  • Result: Bars rendered outside the SVG, appearing "stuck"

The Solution

Replaced with adaptive scaling logic that:

  1. Calculates target width per bar based on actual available space
  2. When there's room (few days): Uses spacing for visual clarity
  3. When space is tight (many days): Eliminates spacing first
  4. Failsafe: Scales bar width proportionally to always fit
# Calculate bar width and spacing that actually fits
available_width = 100 - left_margin - right_margin
target_bar_width = available_width / total_days.to_f
min_bar_width = 0.1
max_bar_spacing = 0.05

if target_bar_width >= min_bar_width + max_bar_spacing
  # Plenty of room - use max spacing
  bar_spacing = max_bar_spacing
  bar_width = target_bar_width - bar_spacing
else
  # Tight on space - eliminate spacing and use minimum width
  bar_spacing = 0
  bar_width = [target_bar_width, min_bar_width].max

  # If still can't fit, scale everything down proportionally
  if bar_width * total_days > available_width
    bar_width = available_width / total_days.to_f
  end
end

Visual Result

Days Before After
~200 ✅ Works ✅ Works
~400 ⚠️ Starts overflowing ✅ Works
600+ ❌ Completely broken ✅ Works (scales down)

The chart will now display all data correctly regardless of how many days of messages exist in the community.

Testing

  • Chart renders correctly with current data volume
  • Bar width scales proportionally as days increase
  • No overflow beyond SVG boundaries
  • X-axis labels remain readable (auto-spacing)

AI Disclosure

This PR was developed with AI assistance:

  • Opus 4.5 for planning and code review
  • GLM 4.7 for code execution
  • GitHub PR review for quality assurance

@staticpayload

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Messages per day chart in /stats page is not updating anymore

1 participant