From 0762bfbd1e40e44814ac577a7deb561ef87112d9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 18 Oct 2025 10:01:51 -0400 Subject: [PATCH] Fixed x axis label bug --- text_graph.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/text_graph.js b/text_graph.js index ea36504..6b650a3 100644 --- a/text_graph.js +++ b/text_graph.js @@ -271,10 +271,15 @@ class ASCIIBarChart { output += yAxisPadding + ' +' + '-'.repeat(this.maxDataPoints) + '\n'; // TEMP: back to original length // Draw X-axis labels based on mode and format - let xAxisLabels = yAxisPadding + ' '; // Initial padding to align with X-axis + let xAxisLabels = yAxisPadding + ' '; // Initial padding to align with X-axis + + // Determine label interval (every 5 columns) + const labelInterval = 5; + + // Generate all labels first and store in array let labels = []; for (let i = 0; i < this.maxDataPoints; i++) { - if (i % 5 === 0) { + if (i % labelInterval === 0) { let label = ''; if (this.useBinMode) { // For bin mode, show labels for all possible positions @@ -286,23 +291,27 @@ class ASCIIBarChart { label = elapsedSec.toFixed(1) + 's'; } else { // Show whole seconds for 1+ second bins - label = ' ' + String(Math.round(elapsedSec)) + 's'; + label = String(Math.round(elapsedSec)) + 's'; } } else { // For legacy mode, show data point numbers const startIndex = Math.max(1, this.totalDataPoints - this.maxDataPoints + 1); - label = String(startIndex + i).padStart(3, ' '); + label = String(startIndex + i); } - labels.push({ position: i, text: label }); + labels.push(label); } } - // Position all labels - let currentPosition = yAxisPadding.length + 3; // Start after initial padding - for (const labelInfo of labels) { - const spacesBefore = Math.max(0, labelInfo.position - currentPosition); - xAxisLabels += ' '.repeat(spacesBefore) + labelInfo.text; - currentPosition = labelInfo.position + labelInfo.text.length; + // Build the label string with calculated spacing + for (let i = 0; i < labels.length; i++) { + const label = labels[i]; + xAxisLabels += label; + + // Add spacing: labelInterval - label.length (except for last label) + if (i < labels.length - 1) { + const spacing = labelInterval - label.length; + xAxisLabels += ' '.repeat(spacing); + } } // Ensure the label line extends to match the X-axis dash line length