Macaw.Draw.Shape.Needle (macaw_draw v0.1.0)

Copy Markdown View Source

A gauge's or compass's pointer (spec/07 §16), copied from visualize's Visualize.Shape.Needle: one filled pointer per datum from the hub to its angle.

angle/2 is in the radial scale's domain units, radians without one; length/2, inner_radius/2, width/2 and tail/2 are pixel accessors; hub/2 is the hub circle's radius, the width when nil; cap/2 is :point, :round or :flat, read by spelling, another {[], {:unknown, :cap, spelling}}.

iex> alias Macaw.Draw.Shape.Needle
iex> Needle.generate(Needle.new(), [{0, 100}])
["M3,0L-3,0L0,-100Z"]

With a the angle clockwise from 12 o'clock, u = (sin a, −cos a) the ray and p = (cos a, sin a) across it, each path runs from the base corner (inner_radius − tail)·u + (width/2)·p, to the other corner, then to the tip by its cap, and closes. A datum with a coordinate that is no number draws the empty path, so the list stays one path a datum.

Summary

Types

A refusal: faults with their paths.

t()

Functions

Sets the angle, in the scale's domain units (radians without one), accessor: a function, a field, or a number.

Sets the tip, :point, :round or :flat by spelling: {:ok, needle} or {:error, faults}.

As cap/2, the needle itself, raising Macaw.Draw.Error with its faults.

The pointers as SVG path data, one per datum.

One Macaw.Draw.IR.Path pointer per datum, in data order.

Sets the hub circle's radius accessor; nil means the width.

The hub circle about the origin for a datum, radius hub (the width when nil).

Sets the pointer's start, in pixels (default 0), accessor: a function, a field, or a number.

Sets the tip's radius, in pixels, accessor: a function, a field, or a number.

A needle reading tuple elements 0 and 1 as angle and length.

Sets the radial scale the angles map through; nil means radians.

Sets the length behind the hub, in pixels (default 0), accessor: a function, a field, or a number.

Sets the base width, in pixels (default 6), accessor: a function, a field, or a number.

Types

accessor()

@type accessor() :: (term() -> term()) | atom() | String.t() | number()

cap()

@type cap() :: :point | :round | :flat

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Shape.Needle{
  angle: (term() -> term()) | nil,
  cap: cap(),
  hub: (term() -> term()) | nil,
  inner_radius: (term() -> term()) | number(),
  length: (term() -> term()) | nil,
  scale: struct() | nil,
  tail: (term() -> term()) | number(),
  width: (term() -> term()) | number()
}

Functions

angle(needle, accessor)

@spec angle(t(), accessor()) :: t() | error()

Sets the angle, in the scale's domain units (radians without one), accessor: a function, a field, or a number.

cap(needle, cap)

@spec cap(t(), term()) :: {:ok, t()} | error()

Sets the tip, :point, :round or :flat by spelling: {:ok, needle} or {:error, faults}.

cap!(needle, cap)

@spec cap!(t(), term()) :: t()

As cap/2, the needle itself, raising Macaw.Draw.Error with its faults.

generate(needle, data)

@spec generate(t(), [term()]) :: [String.t()] | error()

The pointers as SVG path data, one per datum.

generate_path(needle, data)

@spec generate_path(t(), [term()]) :: [Macaw.Draw.IR.Path.t()] | error()

One Macaw.Draw.IR.Path pointer per datum, in data order.

hub(needle, accessor)

@spec hub(t(), accessor() | nil) :: t() | error()

Sets the hub circle's radius accessor; nil means the width.

hub_path(needle, datum)

@spec hub_path(t(), term()) :: Macaw.Draw.IR.Path.t() | error()

The hub circle about the origin for a datum, radius hub (the width when nil).

inner_radius(needle, accessor)

@spec inner_radius(t(), accessor()) :: t() | error()

Sets the pointer's start, in pixels (default 0), accessor: a function, a field, or a number.

length(needle, accessor)

@spec length(t(), accessor()) :: t() | error()

Sets the tip's radius, in pixels, accessor: a function, a field, or a number.

new()

@spec new() :: t()

A needle reading tuple elements 0 and 1 as angle and length.

scale(needle, scale)

@spec scale(t(), struct() | nil) :: t() | error()

Sets the radial scale the angles map through; nil means radians.

tail(needle, accessor)

@spec tail(t(), accessor()) :: t() | error()

Sets the length behind the hub, in pixels (default 0), accessor: a function, a field, or a number.

width(needle, accessor)

@spec width(t(), accessor()) :: t() | error()

Sets the base width, in pixels (default 6), accessor: a function, a field, or a number.