Tags
Diagramatics has a concept of tags. These tags can be used to make diagram manipulation easier.
Diagram.append_tags (
tags
:
string | string[] )
:
Diagram
let a = square(100).append_tags('blue').append_tags('big');
let b = square(10).append_tags(['blue', 'small']);
// a will have the tags 'blue' and 'big'
// b will have the tags 'blue' and 'small'
Diagram.remove_tags (
tags
:
string | string[] )
:
Diagram
let a = square(100).append_tags('blue').append_tags('big');
let b = square(10).append_tags(['blue', 'small']);
a = a.remove_tags('blue');
b = b.remove_tags(['blue', 'small']);
// a will have the tag 'big'
// b will have no tag
Diagram.reset_tags (
)
:
Diagram
let a = square(10).append_tags(['blue', 'small']);
a = a.reset_tags();
// a will have no tag
Diagram.contain_tag (
tag
:
string )
:
boolean
// check if a diagram contains a tag
let a = square(10).append_tags(['square', 'small']);
a.contain_tag('square'); // true
a.contain_tag('big'); // false
Diagram.contain_all_tags (
tags
:
string[] )
:
boolean
// check if a diagram contains all tags given
let a = square(10).append_tags(['square', 'small', 'blue']);
a.contain_all_tags(['square', 'small']); // true
a.contain_all_tags(['square', 'big']); // false
Tags Application
// this is useful if we have a deeply nested diagram, and we want to apply a function to all diagrams with a tag
let a = square(10);
let b = square(10).append_tags('blue');
let c = circle(5).append_tags('blue');
let d = circle(5);
let distributed = distribute_horizontal([a, b, c, d], 1);
let colored = distributed.apply_to_tagged_recursive('blue', d => d.fill('lightblue'));
draw(colored);
Diagram.apply_to_tagged_recursive (
tags
:
string | string[] , func
:
(d : Diagram) => Diagram )
:
Diagram
// this is useful if we have a deeply nested diagram, and we want to apply a function to all diagrams with a tag
let a = square(10);
let b = square(10).append_tags('blue');
let c = circle(5).append_tags('blue');
let d = circle(5);
let distributed = distribute_horizontal([a, b, c, d], 1);
let colored = distributed.apply_to_tagged_recursive('blue', d => d.fill('lightblue'));
draw(colored);
// this is useful if we have a deeply nested diagram, and we want to get the diagrams with certain tags
let a = square(10);
let b = square(10).append_tags('special');
let c = circle(5);
let d = circle(5).append_tags('special');
let distributed = distribute_horizontal([a, b, c, d], 1);
let specials = distributed.get_tagged_elements('special');
draw(...specials);
Diagram.get_tagged_elements (
tags
:
string | string[] )
:
Diagram[]
// this is useful if we have a deeply nested diagram, and we want to get the diagrams with certain tags
let a = square(10);
let b = square(10).append_tags('special');
let c = circle(5);
let d = circle(5).append_tags('special');
let distributed = distribute_horizontal([a, b, c, d], 1);
let specials = distributed.get_tagged_elements('special');
draw(...specials);
Built In Tags
Diagram.get_tagged_elements (
tags
:
string | string[] )
:
Diagram[]
enum TAG {
EMPTY = "empty",
LINE = "line",
CIRCLE = "circle",
TEXTVAR = "textvar",
// prefix
ROW_ = "row_",
COL_ = "col_",
// arrow
ARROW_LINE = "arrow_line",
ARROW_HEAD = "arrow_head",
// table
TABLE = "table",
CONTAIN_TABLE = "contain_table",
TABLE_CELL = "table_cell",
TABLE_CONTENT = "table_content",
EMPTY_CELL = "empty_cell",
//graph
GRAPH_AXIS = "graph_axis_line",
GRAPH_TICK = "graph_tick",
GRAPH_TICK_LABEL = "graph_tick_label",
GRAPH_GRID = "graph_grid",
}
let arr = arrow(V2(3,10), 2).strokewidth(4)
.apply_to_tagged_recursive(TAG.ARROW_HEAD, d => d.fill('blue').stroke('white'))
.apply_to_tagged_recursive(TAG.ARROW_LINE, d => d.stroke('blue'));
draw(arr);
Styling Arrow Line and Head separately
let arr = arrow(V2(3,10), 2).strokewidth(4)
.apply_to_tagged_recursive(TAG.ARROW_HEAD, d => d.fill('blue').stroke('white'))
.apply_to_tagged_recursive(TAG.ARROW_LINE, d => d.stroke('blue'));
draw(arr);