DEFINITIONS
  "LibrarySVG.def";
  VISB_JSON_FILE == "";
  WIDTH == 400.0; HEIGHT == 50.0;
  VISB_SVG_BOX == rec(height:HEIGHT+40.0, width:WIDTH+5.0); //, viewBox:"-10 -10 420 230");

 XOffset == 10;
 vehLen == 1.0;
 MAX == 30;
 Scale == WIDTH/real(MAX);
 
 VISB_SVG_OBJECTS1 == rec(svg_class:"polygon", stroke:"gray", `stroke-width`:1, fill:"gray",
       transform: ```translate(0,${HEIGHT})```,
       points:svg_axis(0..MAX,(WIDTH/real(MAX)),real(MAX),5.0)
      );

  xcoord(x) == (x)*WIDTH/real(MAX);
  
  VISB_SVG_OBJECTS2 == rec(svg_class:"circle", r:2.0, 
      cx:xcoord(m), cy:44, fill:"red", `stroke-width`:0.1, title: ```Movement limit m=${m}```);
  VISB_SVG_OBJECTS3a == rec(svg_class:"circle", r:2.0, 
      cx:xcoord(z), cy:55, fill:"green", `stroke-width`:0.1, title: ```Train position z=${z}```);
  VISB_SVG_OBJECTS3b == rec(svg_class:"circle", r:2.0, 
      cx:xcoord(z2), cy:55, fill:"blue", `stroke-width`:0.1, title: ```Train position z2=${z2}```);

  TRAIN(Nr,zpos,vpos,apos,Col) == 
      (rec(svg_class:"polygon", stroke:Col, `stroke-width`: 0.5,
                   fill: IF apos <0.0 THEN "red" ELSIF apos>0.0 THEN "olivedrab" ELSE "lightgray" END, opacity: 0.6,
                   transform:```translate(0,43)```,
                   points:svg_train(zpos, vehLen ,Scale, 1.5,6.0),
                   title: ```Train ${Nr} at position ${zpos} and speed ${vpos}.```
                ),
      rec(svg_class:"text",x:xcoord(zpos), y:40, text:```t${Nr}: ${IF apos>0.0 THEN "acc" ELSIF apos<0.0 THEN "brake" ELSE "keep" END}, a:${apos}```, `font-size`:4.0,
         `alignment-baseline`:"middle", `text-anchor`:"start"),
      rec(svg_class:"text", x:xcoord(zpos), y:62, text:```t${Nr} z:${zpos}, v:${vpos}```, `font-size`:4.0,
         `alignment-baseline`:"middle", `text-anchor`:"middle"),
       rec(svg_class:"line", stroke:Col, x1:xcoord(zpos), x2:xcoord(zpos+vpos),
            y1:55, y2:55, `stroke-width`:0.4, visibility:bool(vpos>0.0),
            `marker-start`:"url(#dot)", `marker-end`:"url(#arrowhead)"));
  NEXTTRAIN(Nr,zpos,vpos,Col) == rec(svg_class:"polygon", stroke:Col, `stroke-width`: 0.5,
                   fill: "lightgray", opacity: 0.4, `stroke-dasharray`: "1.5 1.5", 
                   transform:```translate(0,52)```,
                   points:svg_train(zpos+vpos, vehLen ,Scale, 1.5,6.0),
                   title: ```Train ${Nr} at next position ${zpos+vpos} and speed ${vpos}.```
                );

  VISB_SVG_OBJECTS4 == TRAIN(1,z,v,a,"black");
  VISB_SVG_OBJECTS5 == NEXTTRAIN(1,z,v,"green"); 
  VISB_SVG_OBJECTS6 == TRAIN(2,z2,v2,a2,"blue");
  VISB_SVG_OBJECTS7 == NEXTTRAIN(2,z2,v2,"cyan");
  
  VISB_SVG_CONTENTS == '''
     <defs>
    <marker id="arrowhead" markerWidth="6" markerHeight="4" fill="black"
    refX="6" refY="2" orient="auto">
      <polygon points="0 0, 6 2.0, 0 4" />
    </marker>

    <marker
      id="dot"
      viewBox="0 0 6.1 6.1"
      refX="3"
      refY="3"
      markerWidth="3"
      markerHeight="3">
      <circle cx="3" cy="3" r="3" fill="gray" />
    </marker>
  </defs>'''
