gnodet-bot commented on code in PR #28586:
URL: https://github.com/apache/camel/pull/28586#discussion_r4391706726


##########
components/camel-diagram/src/main/java/org/apache/camel/diagram/RouteDiagramRenderer.java:
##########
@@ -185,6 +186,7 @@ public static DiagramColors parse(String spec) {
             c.warning = parseColor(map.getOrDefault("warning", "#d29922"));
             c.warningBg = parseColor(map.getOrDefault("warningBg", "#272115"));
             c.warningText = parseColor(map.getOrDefault("warningText", 
"#e3b341"));
+            c.badgeText = parseColor(map.getOrDefault("badgeText", "#1f2328"));

Review Comment:
   💡 **`badgeText` is not part of the preset color strings (`LIGHT_COLORS` / 
`DARK_COLORS`)**
   
   The field is introduced here with a hard-coded default (`#1f2328`), but if 
`LIGHT_COLORS` and `DARK_COLORS` (defined elsewhere in this class) do not 
include a `badgeText` key, then users relying on those preset names cannot 
customise or override this colour without spelling out the full color map.
   
   Please verify that both preset strings include a `badgeText` entry, or 
document that this colour is intentionally fixed and only overridable via a 
custom map.



##########
components/camel-diagram/src/test/java/org/apache/camel/diagram/RouteDiagramCalloutTest.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.diagram;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.util.List;
+
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.Callout;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.LayoutRoute;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.NodeInfo;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.RouteInfo;
+import org.apache.camel.diagram.RouteDiagramRenderer.DiagramColors;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The problems of the steps in a route diagram image: callouts beside a 
route, a numbered list below a route with
+ * branches.
+ */
+class RouteDiagramCalloutTest {
+
+    private static final String GROOVY = "groovy reads fields of the body 
(body.items), but the body here is the file as"
+                                         + " it was read (a GenericFile), not 
parsed data - unmarshal it first";
+
+    private static NodeInfo node(String type, String code, int level, 
String... problems) {
+        NodeInfo n = new NodeInfo();
+        n.type = type;
+        n.id = type + level + code.length();
+        n.code = code;
+        n.level = level;
+        n.problems = List.of(problems);
+        return n;
+    }
+
+    private static RouteInfo orders() {
+        RouteInfo r = new RouteInfo();
+        r.routeId = "orders";
+        r.nodes.add(node("route", "route[orders]", 0));
+        r.nodes.add(node("from", "from[file:orders]", 1));
+        r.nodes.add(node("setBody", "setBody[groovy{body.items}]", 2, GROOVY));
+        r.nodes.add(node("to", "to[http:pricing]", 2, "the http producer 
cannot send a Map"));
+        r.nodes.add(node("to", "to[jms:priced]", 2));
+        return r;
+    }
+
+    private static RouteInfo choice() {
+        RouteInfo r = new RouteInfo();
+        r.routeId = "choice";
+        r.nodes.add(node("route", "route[choice]", 0));
+        r.nodes.add(node("from", "from[timer:tick]", 1));
+        r.nodes.add(node("choice", "choice", 2));
+        r.nodes.add(node("when", "when[simple{${header.kind} == 0}]", 3));
+        r.nodes.add(node("to", "to[kafka:zero?brokerz=localhost]", 4, "kafka 
has no option brokerz"));
+        r.nodes.add(node("otherwise", "otherwise", 3));
+        r.nodes.add(node("marshal", "marshal[jackson]", 4, "the body is a 
String here"));
+        return r;
+    }
+
+    private static RouteDiagramLayoutEngine engine(boolean problems) {
+        RouteDiagramLayoutEngine engine = new RouteDiagramLayoutEngine();
+        engine.setCardStyle(true);
+        engine.setProblems(problems);
+        return engine;
+    }
+
+    @Test
+    void calloutsBesideARoute() {
+        RouteDiagramLayoutEngine engine = engine(true);
+        LayoutRoute lr = engine.layoutRoute(orders(), 
RouteDiagramLayoutEngine.PADDING);
+
+        assertThat(lr.problemList).isFalse();
+        assertThat(lr.callouts).hasSize(2);
+        Callout groovy = lr.callouts.get(0);
+        Callout http = lr.callouts.get(1);
+        assertThat(groovy.node.type).isEqualTo("setBody");
+        assertThat(groovy.number).isZero();
+        // right of the steps, the text wrapped to more than one line
+        int right = groovy.node.x + engine.getNodeWidth();
+        assertThat(groovy.x).isEqualTo(right + 
RouteDiagramLayoutEngine.CALLOUT_GAP);
+        assertThat(groovy.lines).hasSizeGreaterThan(1);
+        assertThat(String.join(" ", groovy.lines)).contains("GenericFile");
+        // one below the other, and room for them in the image
+        assertThat(http.y).isGreaterThanOrEqualTo(groovy.y + groovy.height);
+        assertThat(lr.maxX).isEqualTo(groovy.x + groovy.width);
+
+        // without problems shown, the route does not change
+        LayoutRoute plain = engine(false).layoutRoute(orders(), 
RouteDiagramLayoutEngine.PADDING);
+        assertThat(plain.callouts).isEmpty();
+        assertThat(plain.maxX).isLessThan(lr.maxX);
+    }
+
+    @Test
+    void numberedListBelowARouteWithBranches() {
+        RouteDiagramLayoutEngine engine = engine(true);
+        LayoutRoute plain = engine(false).layoutRoute(choice(), 
RouteDiagramLayoutEngine.PADDING);
+        LayoutRoute lr = engine.layoutRoute(choice(), 
RouteDiagramLayoutEngine.PADDING);
+
+        assertThat(lr.problemList).isTrue();
+        assertThat(lr.callouts).hasSize(2);
+        // numbered in the order of the steps in the route, below the steps
+        assertThat(lr.callouts.get(0).number).isEqualTo(1);
+        assertThat(lr.callouts.get(0).node.type).isEqualTo("to");
+        assertThat(lr.callouts.get(1).number).isEqualTo(2);
+        assertThat(lr.callouts.get(1).node.type).isEqualTo("marshal");
+        assertThat(lr.callouts.get(0).y).isGreaterThan(plain.maxY);
+        assertThat(lr.maxY).isGreaterThan(plain.maxY);
+    }
+
+    @Test
+    void drawTheProblems() {

Review Comment:
   💡 **Missing rendering test for the numbered-list path**
   
   `numberedListBelowARouteWithBranches()` verifies layout properties 
(positions, sizes, `problemList` flag) but never calls `renderDiagram()` to 
produce an image. The callout path has a pixel-level rendering test 
(`drawTheProblems()`), but the numbered-list rendering path — which is 
exercised via a completely different code branch — has no equivalent.
   
   Consider adding a rendering assertion for the numbered-list path similar to 
what `drawTheProblems()` does for callouts: render to a `BufferedImage` and 
verify that at least the warning background or border colour is present at the 
expected coordinates.



##########
components/camel-diagram/src/main/java/org/apache/camel/diagram/RouteDiagramLayoutEngine.java:
##########
@@ -564,9 +620,77 @@ public LayoutRoute layoutRoute(RouteInfo route, int 
startY) {
         lr.maxX = extent.maxX + overhang;
         lr.maxY = Math.max(lr.maxY, extent.maxY);
 
+        if (problems) {
+            layoutProblems(lr);
+        }
         return lr;
     }
 
+    private void layoutProblems(LayoutRoute lr) {
+        // in the order of the steps in the route (the order of the source)
+        List<LayoutNode> withProblems = lr.nodes.stream()
+                .filter(ln -> !ln.tableRow && ln.treeNode != null && 
!ln.treeNode.info.problems.isEmpty())
+                .toList();
+        if (withProblems.isEmpty()) {
+            return;
+        }
+        int lineHeight = fontMetrics.getHeight();
+        lr.problemList = lr.nodes.stream().anyMatch(ln -> 
isBranchingEip(ln.type));
+        if (!lr.problemList) {
+            // a column of callouts beside the route, each at the height of 
its step, below the one above it
+            int x = lr.maxX + CALLOUT_GAP;
+            int width = calloutWidth(nodeWidth);
+            int bottom = Integer.MIN_VALUE;
+            // without branches the order of the steps is from the top down
+            for (LayoutNode ln : withProblems) {
+                Callout c = new Callout();
+                c.node = ln;
+                c.lines = problemLines(ln.treeNode.info.problems, width - 2 * 
CALLOUT_PAD);
+                c.x = x;
+                c.width = width;
+                c.height = c.lines.size() * lineHeight + 2 * CALLOUT_PAD;
+                c.y = Math.max(ln.y + ln.height / 2 - c.height / 2, bottom + 
CALLOUT_PAD);
+                bottom = c.y + c.height;
+                lr.callouts.add(c);
+                lr.maxY = Math.max(lr.maxY, bottom);
+            }
+            lr.maxX = x + width;
+        } else {
+            // a numbered list below the steps, as wide as the route
+            int width = Math.max(lr.maxX - PADDING, nodeWidth * 2);
+            int y = lr.maxY + V_GAP / 2;
+            int number = 0;
+            for (LayoutNode ln : withProblems) {
+                Callout c = new Callout();
+                c.node = ln;
+                c.number = ++number;
+                c.lines = problemLines(ln.treeNode.info.problems, width - 
PROBLEM_NUMBER_WIDTH);
+                c.x = PADDING;
+                c.y = y;
+                c.width = width;
+                c.height = c.lines.size() * lineHeight;
+                y += c.height + CALLOUT_PAD;
+                lr.callouts.add(c);
+            }
+            lr.maxY = y;
+            lr.maxX = Math.max(lr.maxX, PADDING + width);
+        }
+    }
+
+    /** The problems wrapped to the width, at most six lines: the renderer 
cuts the last one with an ellipsis. */
+    private List<String> problemLines(List<String> problems, int width) {
+        List<String> lines = new ArrayList<>();
+        for (String problem : problems) {
+            lines.addAll(wrapLabel(problem, width, MAX_CALLOUT_LINES));
+        }
+        if (lines.size() > MAX_CALLOUT_LINES) {
+            String rest = String.join(" ", lines.subList(MAX_CALLOUT_LINES - 
1, lines.size()));
+            lines = new ArrayList<>(lines.subList(0, MAX_CALLOUT_LINES - 1));
+            lines.add(rest);
+        }
+        return lines;
+    }

Review Comment:
   ⚠️ **Design concern: `problemLines()` silently merges overflow lines from 
multiple problems**
   
   When multiple problems each contribute lines that collectively exceed 
`MAX_CALLOUT_LINES`, the current logic joins the overflow fragments with 
`String.join(" ", ...)` across problem boundaries. The resulting merged string 
is then truncated with ellipsis by the renderer, so the user sees something 
like `"Step A detail text Step B detail..."` — a nonsensical concatenation of 
lines that came from different problems.
   
   Consider tracking how many lines each problem contributes and capping 
per-problem rather than globally, or at least inserting a separator between 
problem fragments before the overflow truncation:
   
   ```java
   private List<String> problemLines(List<String> problems, int width) {
       List<String> lines = new ArrayList<>();
       for (String problem : problems) {
           List<String> wrapped = wrapLabel(problem, width, MAX_CALLOUT_LINES);
           lines.addAll(wrapped);
           if (lines.size() >= MAX_CALLOUT_LINES) break; // stop adding more 
problems
       }
       if (lines.size() > MAX_CALLOUT_LINES) {
           String rest = String.join(" ", lines.subList(MAX_CALLOUT_LINES - 1, 
lines.size()));
           lines = new ArrayList<>(lines.subList(0, MAX_CALLOUT_LINES - 1));
           lines.add(rest);
       }
       return lines;
   }
   ```
   
   At minimum, the truncation behaviour when multiple problems are present is 
worth documenting.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelRouteDiagramAction.java:
##########
@@ -283,6 +291,7 @@ protected Integer doWatchCall() throws Exception {
         // an image draws the steps as cards: a title and its detail beside an 
icon
         engine.setCardStyle(!isTextTheme());
         engine.setBodyTypes(bodyTypes && !isTextTheme());
+        engine.setProblems(problems && !isTextTheme());

Review Comment:
   💡 **`engine.setProblems(...)` runs unconditionally in both source and 
running-app modes**
   
   The `RouteDiagramProblems.attach(routes, files)` call (which actually 
populates the problems) is guarded by `if (problems && !isTextTheme()) { ... }` 
in the source-mode branch. However, `engine.setProblems(problems && 
!isTextTheme())` on this line is in the common code path, executed for both 
source mode and running-app mode.
   
   In the running-app mode the engine flag is set but the route problems were 
never attached, so the effect is benign (the empty list causes an early 
return). However, for clarity and correctness it would be cleaner to guard this 
with `sourceMode` too:
   
   ```suggestion
           engine.setProblems(problems && sourceMode && !isTextTheme());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to