Fixed x axis label bug
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user