A scene node (spec/10 §1.1), copied from visualize's Visualize.IR.Element.
A node is %Macaw.Draw.IR.Element{type, attrs, style, transform, children, content, path, clip}: its type, its geometric and data attributes (atom keys for the attributes
the scene names, string keys such as "data-mw-id" for any other), its style keys, a
Macaw.Draw.IR.Transform or nil, its child nodes, a text's content, a :path's
Macaw.Draw.IR.Path and its clip, nil or %{shape: node, keep: :inside | :outside}.
iex> alias Macaw.Draw.IR.{Element, Path}
iex> path = Path.new() |> Path.move_to(0, 0) |> Path.line_to(100, 100)
iex> node = Element.path(path, %{stroke: "blue", fill: :none})
iex> {node.type, node.style}
{:path, %{fill: :none, stroke: "blue"}}The node types are :path, :rect, :circle, :ellipse, :line, :polyline,
:polygon, :text, :tspan, :group, :root, :image, :defs, :clip_path,
:linear_gradient, :radial_gradient, :pattern, :stop, :filter,
:fe_drop_shadow, :fe_gaussian_blur, :title and :desc (types/0); visualize's
:style node is not one, since a page holds no <style> (spec/10 §1.1).
A constructor builds its node from arguments of the right type and answers a type fault,
{:error, [{path, {:type, expected}}]}, for an argument of the wrong one (spec/06 §1.2);
a node built by hand with values of the wrong shape is the renderer's to refuse, as a
fault by its path (spec/10 §2.5), so building a scene never raises.
The effective paint decides in one place what a canvas draws (spec/10 §1.1, visualize
#934, D-320, D-322): fills?/2, strokes?/2, stroke_first?/2, font/2 and
font_size/2 each read a node's own style over the inherited style its groups give
it.
Summary
Types
Where a node is drawn: only where the shape is, or only where it is not.
A refusal: faults with their paths.
A node's style: the keys of spec/10 §1.1.
A node type (spec/10 §1.1).
Functions
Appends a node, or a list of nodes, to a node's children.
A :circle node at (cx, cy) of radius r.
The node drawn only where shape is (:inside) or only where it is not (:outside)
(spec/10 §1.1, visualize D-211): the shape keeps its geometry alone, its transform,
style, clip and data attributes dropped, so it is in the node's own user space and a
node clipped to itself is clipped to its outline wherever its transform puts it.
A :clip_path definition of id holding children.
Writes a datum's fields onto the node as the data attributes the tooltip reads (spec/10 §1.1, §7.3; visualize D-75, D-225).
A :defs node: definitions, drawn nowhere.
A :desc: the accessible description of its parent.
A drop shadow primitive of the offset and the blur radius, at 0.35 opacity.
A drop shadow primitive of the offset, the blur radius and a color: flood-color the
color at flood-opacity 1, so the color's own alpha is the shadow's; a nil color is
drop_shadow/3.
An :ellipse node at (cx, cy) of radii rx and ry.
Whether a canvas draws the node's fill, by its effective fill: its own :fill, else
inherited's (spec/10 §1.1, visualize #934, D-320). :none is never drawn whatever a
group above set; a :line has no area; a node that draws no shape has no fill; an
absent fill is SVG's initial black on a :text and nothing on any other shape (D-122).
A :filter of id holding its primitives, for a node's :effect.
The font a canvas draws a :text in, the CSS shorthand [style] [weight] size family
of its effective :font_style, :font_weight, :font_size and :font_family
(spec/10 §1.1, visualize #1150, D-322): the size font_size/2's with px, the family
"sans-serif" where none is set, the style and the weight only where set. nil when
none of the four is set on the text or above it, and for every node but a :text.
A text's effective :font_size where it is a number, else 10, the canvas default's:
the size font/2 writes and the one an em dy is read at (spec/10 §1.1, D-321).
A Gaussian blur primitive of the radius.
A :group node with options :style, :transform and :attrs.
An :image node: a same-origin href (spec/10 §8) at (x, y), width by height.
A :line node from (x1, y1) to (x2, y2).
A :linear_gradient of id with options :x1, :y1, :x2, :y2 and :stops.
A node of type with options :attrs, :style, :transform, :children, :content
and :path.
A :path node drawing a Macaw.Draw.IR.Path.
A :polygon node, the closed form of polyline/2.
A :polyline node through a list of {x, y} points, or a points string.
Prepends a node, or a list of nodes, to a node's children.
The node with one attribute set: key an atom, or a string for an attribute the scene
has no name for ("data-mw-id").
A :radial_gradient of id with options :cx, :cy, :r, :fx, :fy and :stops.
A :rect node at (x, y), width by height.
The whole drawing (spec/10 §1.1; visualize D-54, D-56, D-142, D-201): attrs width,
height, view_box ("0 0 W H" by default) and role: "img".
The node with attributes merged over its own.
The node with its text content set; nil clears it.
The node with style keys merged over its own.
The node with its transform replaced.
A gradient's :stop at offset (a number from 0 to 1, or a percentage string) of
color (a color term or a string), with the option :opacity.
Whether the node paints its stroke under its fill: a :text that strokes?/2, its
stroke its own or its groups' (spec/10 §1.1, visualize D-235). A text's stroke is a
halo, which frames the glyphs and never covers them; every target asks this.
Whether a canvas draws the node's stroke: a shape or a :text whose effective stroke is
neither absent nor :none, SVG's initial stroke being none (spec/10 §1.1, D-320).
A :text node with options :x, :y, :dx, :dy and :style.
A :text node at (x, y).
Whether a value has a text form a tooltip shows (spec/10 §1.1; visualize #1111, D-303):
a string, a number, an atom, or a Date, Time, NaiveDateTime or DateTime. A path,
a geometry, a point, a list, a tuple and any other struct have none.
A :title: the accessible name of the node it is the first child of.
The node translated by (x, y) after its own transform's operations.
A node, or a list of nodes, in a group translated by (x, y).
One line of a :text: a :tspan with its content and attrs, x and dy among them. A
:text whose children are tspans and whose content is nil is a text of several lines.
The node types a target writes or knowingly drops (spec/10 §1.1).
Types
@type clip() :: %{shape: t(), keep: :inside | :outside}
Where a node is drawn: only where the shape is, or only where it is not.
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type style() :: map()
A node's style: the keys of spec/10 §1.1.
@type t() :: %Macaw.Draw.IR.Element{ attrs: map(), children: [t()], clip: clip() | nil, content: String.t() | nil, path: Macaw.Draw.IR.Path.t() | nil, style: style(), transform: Macaw.Draw.IR.Transform.t() | nil, type: type() }
@type type() ::
:path
| :rect
| :circle
| :ellipse
| :line
| :polyline
| :polygon
| :text
| :tspan
| :group
| :root
| :image
| :defs
| :clip_path
| :linear_gradient
| :radial_gradient
| :pattern
| :stop
| :filter
| :fe_drop_shadow
| :fe_gaussian_blur
| :title
| :desc
A node type (spec/10 §1.1).
Functions
Appends a node, or a list of nodes, to a node's children.
A :circle node at (cx, cy) of radius r.
The node drawn only where shape is (:inside) or only where it is not (:outside)
(spec/10 §1.1, visualize D-211): the shape keeps its geometry alone, its transform,
style, clip and data attributes dropped, so it is in the node's own user space and a
node clipped to itself is clipped to its outline wherever its transform puts it.
iex> square = Macaw.Draw.IR.Element.rect(0, 0, 10, 10, %{fill: "red"})
iex> clipped = Macaw.Draw.IR.Element.clip(square, square, :inside)
iex> {clipped.clip.keep, clipped.clip.shape.style}
{:inside, %{}}
A :clip_path definition of id holding children.
Writes a datum's fields onto the node as the data attributes the tooltip reads (spec/10 §1.1, §7.3; visualize D-75, D-225).
fields is a map, written in Enum.sort/1 order, or a keyword list, in its own order.
"data-mw-datum" lists the field names space-separated; "data-mw-datum-<field>"
carries to_string/1 of each value, every _ in the name as -, a nil value and a
value with no text form (text?/1) writing no attribute; "data-mw-named-<field>" is
the value's display name for each field written that names holds. Keys are strings,
so no atom is made from a row's names.
iex> Macaw.Draw.IR.Element.circle(1, 2, 3)
...> |> Macaw.Draw.IR.Element.datum([state: "degraded", big_n: 2], %{state: "Degraded"})
...> |> Map.fetch!(:attrs)
...> |> Map.drop([:cx, :cy, :r])
%{
"data-mw-datum" => "state big_n",
"data-mw-datum-big-n" => "2",
"data-mw-datum-state" => "degraded",
"data-mw-named-state" => "Degraded"
}
A :defs node: definitions, drawn nowhere.
A :desc: the accessible description of its parent.
A drop shadow primitive of the offset and the blur radius, at 0.35 opacity.
@spec drop_shadow( number(), number(), number(), String.t() | Macaw.Layers.Color.t() | nil ) :: t() | error()
A drop shadow primitive of the offset, the blur radius and a color: flood-color the
color at flood-opacity 1, so the color's own alpha is the shadow's; a nil color is
drop_shadow/3.
An :ellipse node at (cx, cy) of radii rx and ry.
Whether a canvas draws the node's fill, by its effective fill: its own :fill, else
inherited's (spec/10 §1.1, visualize #934, D-320). :none is never drawn whatever a
group above set; a :line has no area; a node that draws no shape has no fill; an
absent fill is SVG's initial black on a :text and nothing on any other shape (D-122).
iex> alias Macaw.Draw.IR.Element
iex> Element.fills?(Element.text("A", 0, 0, %{fill: :none}), %{fill: "#000"})
false
iex> Element.fills?(Element.text("A", 0, 0), %{})
true
iex> Element.fills?(Element.rect(0, 0, 2, 2), %{})
false
A :filter of id holding its primitives, for a node's :effect.
The font a canvas draws a :text in, the CSS shorthand [style] [weight] size family
of its effective :font_style, :font_weight, :font_size and :font_family
(spec/10 §1.1, visualize #1150, D-322): the size font_size/2's with px, the family
"sans-serif" where none is set, the style and the weight only where set. nil when
none of the four is set on the text or above it, and for every node but a :text.
iex> alias Macaw.Draw.IR.Element
iex> Element.font(Element.text("A", 0, 10, %{font_weight: :bold}), %{font_size: 20, font_family: "serif"})
"bold 20px serif"
iex> Element.font(Element.text("A", 0, 10), %{})
nil
A text's effective :font_size where it is a number, else 10, the canvas default's:
the size font/2 writes and the one an em dy is read at (spec/10 §1.1, D-321).
iex> alias Macaw.Draw.IR.Element
iex> {Element.font_size(Element.text("A", 0, 10), %{font_size: 20}), Element.font_size(Element.text("A", 0, 10), %{})}
{20, 10}
A Gaussian blur primitive of the radius.
A :group node with options :style, :transform and :attrs.
An :image node: a same-origin href (spec/10 §8) at (x, y), width by height.
A :line node from (x1, y1) to (x2, y2).
A :linear_gradient of id with options :x1, :y1, :x2, :y2 and :stops.
A node of type with options :attrs, :style, :transform, :children, :content
and :path.
@spec path(Macaw.Draw.IR.Path.t(), style()) :: t() | error()
A :path node drawing a Macaw.Draw.IR.Path.
A :polygon node, the closed form of polyline/2.
A :polyline node through a list of {x, y} points, or a points string.
Prepends a node, or a list of nodes, to a node's children.
The node with one attribute set: key an atom, or a string for an attribute the scene
has no name for ("data-mw-id").
iex> Macaw.Draw.IR.Element.group([]) |> Macaw.Draw.IR.Element.put_attr("data-mw-id", "f.1.#1") |> Map.fetch!(:attrs)
%{"data-mw-id" => "f.1.#1"}
A :radial_gradient of id with options :cx, :cy, :r, :fx, :fy and :stops.
A :rect node at (x, y), width by height.
The whole drawing (spec/10 §1.1; visualize D-54, D-56, D-142, D-201): attrs width,
height, view_box ("0 0 W H" by default) and role: "img".
Options:
:view_box,:preserve_aspect_ratioand:children;:title, the root'saria_label, never a<title>child, which a browser shows as a tooltip under the pointer;:description, adesc/1first child with the id<id>-desc, whicharia_describedbynames; a description with no title is named by"aria-labelledby"alone, a string key as the attribute is spelled;hidden: true,aria_hidden: "true": one layer of a picture another element names;:id, the root's id and the description's prefix, by default"mw-"and the base-36:erlang.phash2/1of the title and the description, set when either is;:class, the root's own class, andresponsive: true, which adds the classmw-frame-responsiveafter it (spec/10 §3.6) andpreserveAspectRatio="xMidYMid meet"unless given, never an inlinestyle.iex> root = Macaw.Draw.IR.Element.root(200, 100, title: "Sales", responsive: true) iex> Map.take(root.attrs, [:aria_label, :class, :view_box, :role]) %{aria_label: "Sales", class: "mw-frame-responsive", role: "img", view_box: "0 0 200 100"}
The node with attributes merged over its own.
The node with its text content set; nil clears it.
The node with style keys merged over its own.
@spec set_transform(t(), Macaw.Draw.IR.Transform.t()) :: t() | error()
The node with its transform replaced.
A gradient's :stop at offset (a number from 0 to 1, or a percentage string) of
color (a color term or a string), with the option :opacity.
Whether the node paints its stroke under its fill: a :text that strokes?/2, its
stroke its own or its groups' (spec/10 §1.1, visualize D-235). A text's stroke is a
halo, which frames the glyphs and never covers them; every target asks this.
iex> alias Macaw.Draw.IR.Element
iex> Element.stroke_first?(Element.text("A", 0, 0, %{fill: "#222"}), %{stroke: "#fff"})
true
iex> Element.stroke_first?(Element.rect(0, 0, 2, 2, %{stroke: "#fff"}), %{})
false
Whether a canvas draws the node's stroke: a shape or a :text whose effective stroke is
neither absent nor :none, SVG's initial stroke being none (spec/10 §1.1, D-320).
iex> alias Macaw.Draw.IR.Element
iex> Element.strokes?(Element.rect(0, 0, 2, 2, %{stroke: :none}), %{stroke: "#fff"})
false
iex> Element.strokes?(Element.line(0, 0, 2, 2), %{stroke: "#fff"})
true
A :text node with options :x, :y, :dx, :dy and :style.
A :text node at (x, y).
Whether a value has a text form a tooltip shows (spec/10 §1.1; visualize #1111, D-303):
a string, a number, an atom, or a Date, Time, NaiveDateTime or DateTime. A path,
a geometry, a point, a list, a tuple and any other struct have none.
iex> Enum.map(["north", ~D[2024-01-01], %{"type" => "Point"}, {1, 2}], &Macaw.Draw.IR.Element.text?/1)
[true, true, false, false]
A :title: the accessible name of the node it is the first child of.
The node translated by (x, y) after its own transform's operations.
A node, or a list of nodes, in a group translated by (x, y).
One line of a :text: a :tspan with its content and attrs, x and dy among them. A
:text whose children are tspans and whose content is nil is a text of several lines.
@spec types() :: [type()]
The node types a target writes or knowingly drops (spec/10 §1.1).
iex> :path in Macaw.Draw.IR.Element.types()
true