This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit b94520859178b362f6967f1b219c9f5b001a90ed Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jul 3 18:46:50 2026 +0200 CAMEL-23831: Add intermediate time markers to heap chart x-axis in camel-tui Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../dsl/jbang/core/commands/tui/MemoryTab.java | 61 ++++++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryTab.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryTab.java index 529cfaf9adc3..a269e1576d51 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryTab.java +++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/MemoryTab.java @@ -316,31 +316,58 @@ class MemoryTab extends AbstractTab { private void renderTimeAxis(Frame frame, Rect area, IntegrationInfo info) { LinkedList<Long> hist = heapMemHistory.get(info.pid); int points = hist != null ? hist.size() : 0; - long totalSeconds = points * 5L; - - String timeLabel; - if (totalSeconds < 60) { - timeLabel = totalSeconds + "s ago"; - } else { - timeLabel = (totalSeconds / 60) + "m ago"; - } int w = area.width(); if (w < 10) { return; } - // Pad to fill the width: "Xm ago" on the left, "now" on the right - String left = " " + timeLabel; - String right = "now "; - int gap = Math.max(1, w - left.length() - right.length()); + // The chart area has the same width; each column = 1 data point = 5 seconds + // chartW columns map to the rightmost `chartW` points of history + int chartW = w; + int totalPoints = Math.min(points, chartW); + long totalSeconds = totalPoints * 5L; + + Buffer buf = frame.buffer(); + Style dimStyle = Style.EMPTY.dim(); + int xAxisY = area.y(); + int startX = area.x(); + + // "now" label at the right edge + int nowX = startX + chartW - 3; + if (nowX >= startX) { + buf.setString(nowX, xAxisY, "now", dimStyle); + } - Line line = Line.from( - Span.styled(left, Style.EMPTY.dim()), - Span.raw(" ".repeat(gap)), - Span.styled(right, Style.EMPTY.dim())); + // Pick step interval based on total time span + int stepSeconds; + if (totalSeconds <= 120) { + stepSeconds = 30; + } else if (totalSeconds <= 300) { + stepSeconds = 60; + } else if (totalSeconds <= 900) { + stepSeconds = 120; + } else { + stepSeconds = 300; + } - frame.renderWidget(Paragraph.builder().text(Text.from(line)).build(), area); + // Place markers from right to left at regular time intervals + for (int s = stepSeconds; s <= totalSeconds; s += stepSeconds) { + int col = chartW - 1 - (s / 5); + if (col < 0) { + break; + } + String label; + if (s < 60) { + label = "-" + s + "s"; + } else { + label = "-" + (s / 60) + "m"; + } + int markerX = startX + col; + if (markerX + label.length() <= startX + chartW - 4 && markerX >= startX) { + buf.setString(markerX, xAxisY, label, dimStyle); + } + } } private static Span computeTrendSpan(LinkedList<Long> hist) {
