Visualize.Shape.Needle (Visualize v0.2.35)

Copy Markdown View Source

Needle generator: one filled pointer per datum from the hub to its angle, as long as its length — a gauge's indicator, a compass needle (spec/04 §16, #392).

angle/2 is in the domain units of the radial scale given to scale/2 (radians without one); length/2, inner_radius/2, width/2 and tail/2 are pixels. Each datum's path is a tapered shape from the base at the hub to the tip, closed; hub_path/2 is the hub circle the pointer turns about.

Examples

reading = Visualize.Scale.linear() |> Visualize.Scale.domain([0, 100]) |> Visualize.Scale.range([-2.0944, 2.0944])

needle =
  Visualize.Shape.Needle.new()
  |> Visualize.Shape.Needle.scale(reading)
  |> Visualize.Shape.Needle.angle(:value)
  |> Visualize.Shape.Needle.length(120)
  |> Visualize.Shape.Needle.tail(12)

[path] = Visualize.Shape.Needle.generate_path(needle, [%{value: 42}])

Summary

Functions

Sets the angle accessor, in the scale's domain units (radians without a scale)

Sets the tip: :point, :round or :flat

Returns the list of SVG path-data strings, one pointer per datum

Returns the list of IR.Path, one pointer per datum: from the base corner behind the hub, round the tail, to the other corner, then to the tip as the cap says, closed.

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

Returns the hub circle's IR.Path for a datum, radius hub (the width when nil)

Sets where the pointer starts, in pixels (default 0)

Sets the tip's radius accessor, in pixels

Creates a needle generator reading tuple elements 0 and 1 as angle and length

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

Sets how far the pointer extends behind the hub, in pixels (default 0)

Sets the base width accessor, in pixels (default 6)

Types

cap()

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

t()

@type t() :: %Visualize.Shape.Needle{
  angle: Visualize.Shape.Line.accessor() | nil,
  cap: cap(),
  hub: Visualize.Shape.Line.accessor() | nil,
  inner_radius: Visualize.Shape.Line.accessor(),
  length: Visualize.Shape.Line.accessor() | nil,
  scale: struct() | nil,
  tail: Visualize.Shape.Line.accessor(),
  width: Visualize.Shape.Line.accessor()
}

Functions

angle(n, accessor)

@spec angle(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the angle accessor, in the scale's domain units (radians without a scale)

cap(n, cap)

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

Sets the tip: :point, :round or :flat

generate(n, data)

@spec generate(t(), Visualize.Data.Table.source()) :: [String.t()]

Returns the list of SVG path-data strings, one pointer per datum

generate_path(n, data)

@spec generate_path(t(), Visualize.Data.Table.source()) :: [Visualize.IR.Path.t()]

Returns the list of IR.Path, one pointer per datum: from the base corner behind the hub, round the tail, to the other corner, then to the tip as the cap says, closed.

hub(n, accessor)

@spec hub(t(), Visualize.Shape.Line.accessor() | nil) :: t()

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

hub_path(n, d)

@spec hub_path(t(), term()) :: Visualize.IR.Path.t()

Returns the hub circle's IR.Path for a datum, radius hub (the width when nil)

inner_radius(n, accessor)

@spec inner_radius(t(), Visualize.Shape.Line.accessor()) :: t()

Sets where the pointer starts, in pixels (default 0)

length(n, accessor)

@spec length(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the tip's radius accessor, in pixels

new()

@spec new() :: t()

Creates a needle generator reading tuple elements 0 and 1 as angle and length

scale(n, scale)

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

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

tail(n, accessor)

@spec tail(t(), Visualize.Shape.Line.accessor()) :: t()

Sets how far the pointer extends behind the hub, in pixels (default 0)

width(n, accessor)

@spec width(t(), Visualize.Shape.Line.accessor()) :: t()

Sets the base width accessor, in pixels (default 6)