Diagrams with scaling and crosshair - mkraska/meclib GitHub Wiki

Example of a diagram with interactive crosshair and scaled axes.

If the optional [fx,fy] argument of "grid" is used, then the tick values at the axes are scaled accordingly. These axes are drawn if their labels are non-empty. Here we use just a space character because the default label positioning is inappropriate.

The scaling can be conveyed to the "crosshair" object, where we also can set the decimal places of the co-ordinate infobox (appears when mouse is on crosshair)

Curves made with "spline"

The "spline" objects are defined in terms of unscaled grid units. The style "pure" hides all items except the curve. Also highlighting is switched off in order to not expose the bounds of the individual splines to the user.

initdata: [ 
  [ "grid", " ", " ", -0.5,maxx, -1, maxy, 40, [fx, fy] ],
  [ "label", "\\(\\sigma \\) in MPa", [0.6,maxy-0.5] ],
  [ "label", "\\(\\varepsilon \\) in %", [maxx-0.9,0] ],  
  [ "spline", "eqn", p0, p0, p1, p0, p1, "", "pure"],
  [ "spline", "eqn", p0, p1, p2, p0, p2+[1,0], "", "pure"],
  [ "spline", "eqn", p0, p2, p3, p2+[1,0], p4, "", "pure"],
  [ "crosshair", "", [2,2], [0,0], [fx,fy], [2,1] ]
];
init: stackjson_stringify(float(initdata));

Example: TM2 04 04 at Demo Moodle Course

Curves made with "line"

Similar to above, but curve not generated by "spline" objects but by a "line" object. The points are generated using makelist().

fx: 0.1;
Dt: 0.05*Td;
initdata: [ 
  [ "grid", " "," ", -1 ,9,  -3, 4, 40, [fx, 1] ],
  [ "label", "\\(t\\) in s", [8.1,0.5] ],
  [ "label", "\\(x\\) in cm", [0.2,3.5] ],
  [ "crosshair", "", [0,0], [0,0], [fx,1], [3,2] ],
  [ "line", "", makelist(t/fx , t, 0, 8*fx, Dt), makelist(a*exp(-b*t)*cos(omega*t), t, 0,  8*fx, Dt) ,"-", 1.5 ]
];
init: stackjson_stringify(float(initdata));