diagramatics logo Diagramatics GitHub Docs Guides Editor Examples

Annotation

Diagramatics provide functions to annotate diagrams.
// by default, the text will be in the tip of the arrow, // you can change the position of the text using `text_offset` let sq = square(10); let vann1 = annotation.vector(V2(0,-8), "mg", V2(1.5,0) , 0.4) .stroke('blue').fill('blue'); let vann2 = annotation.vector(V2(3, 0), "F" , V2(-0.5,1.5), 0.4) .stroke('blue').fill('blue') .position(sq.get_anchor('center-right')); draw(sq, vann1, vann2)
annotation.vector
( v  :  Vector2str?  :  stringtext_offset?  :  Vector2arrow_head_size?  :  number )  :  Diagram

// by default, the text will be in the tip of the arrow, // you can change the position of the text using `text_offset` let sq = square(10); let vann1 = annotation.vector(V2(0,-8), "mg", V2(1.5,0) , 0.4) .stroke('blue').fill('blue'); let vann2 = annotation.vector(V2(3, 0), "F" , V2(-0.5,1.5), 0.4) .stroke('blue').fill('blue') .position(sq.get_anchor('center-right')); draw(sq, vann1, vann2)

// annotate angle ∠ABC given the point [A,B,C] // the default position of the text is at distance the point B // you can change the position of the text using `text_offset` let points = [V2(4,3), V2(3,0), V2(0,0)] let tr = polygon(points); let ann = annotation.angle(points, "\\theta", 0.4, 0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);
annotation.angle
( p  :  [Vector2, Vector2, Vector2]str?  :  stringradius  :  number = 1text_offset?  :  Vector2 | number )  :  Diagram

// annotate angle ∠ABC given the point [A,B,C] // the default position of the text is at distance the point B // you can change the position of the text using `text_offset` let points = [V2(4,3), V2(3,0), V2(0,0)] let tr = polygon(points); let ann = annotation.angle(points, "\\theta", 0.4, 0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);
// the order of points determine which angle to be annotated // the angle will be in the counter-clockwise direction // *if you want to annotate the smaller angle, use `annotation.angle_smaller` let points = [V2(0,0), V2(3,0), V2(4,3)] let tr = polygon(points); let ann = annotation.angle(points, "\\theta", 0.4, -0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);
// the order of points determine which angle to be annotated // the angle will be in the counter-clockwise direction // *if you want to annotate the smaller angle, use `annotation.angle_smaller` let points = [V2(0,0), V2(3,0), V2(4,3)] let tr = polygon(points); let ann = annotation.angle(points, "\\theta", 0.4, -0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);
let points = [V2(0,0), V2(3,0), V2(4,3)] let tr = polygon(points); let ann = annotation.angle_smaller(points, "\\theta", 0.4, 0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);
annotation.angle_smaller
( p  :  [Vector2, Vector2, Vector2]str?  :  stringradius  :  number = 1text_offset?  :  Vector2 | number )  :  Diagram

let points = [V2(0,0), V2(3,0), V2(4,3)] let tr = polygon(points); let ann = annotation.angle_smaller(points, "\\theta", 0.4, 0.6) .fill('lightblue').strokewidth(2).stroke('blue'); draw(tr, ann);

// if not defined, `text_offset` is `2*offset` let points = [V2(0,0), V2(3,0), V2(4,3)]; let tr = polygon(points); let ann = annotation.length(points[1], points[2], 'x', 0.3, 0.2).stroke('blue'); draw(tr, ann);
length
( p1  :  Vector2p2  :  Vector2str  :  stringoffset  :  number
    tablength?  :  numbertextoffset?  :  numbertabsymmetric  :  boolean = true )  :  Diagram


// if not defined, `text_offset` is `2*offset` let points = [V2(0,0), V2(3,0), V2(4,3)]; let tr = polygon(points); let ann = annotation.length(points[1], points[2], 'x', 0.3, 0.2).stroke('blue'); draw(tr, ann);