Visualize.Chart.Builder.Fills (Visualize v0.2.25)

Copy Markdown View Source

A fill as a fill style (spec/14 §18.6): none, solid, a linear or a radial gradient.

A style's fill is one key, but a person writes it as a choice among four, two of which are a gradient the design declares under defs (spec/14 §2.7). This module is the pure part: what the controls of the fill group mean — fill_style, fill.stop.<i>, fill.stop.<i>.slot, fill.stop.<i>.opacity, fill.angle, fill.centre.x, fill.centre.y — as writes to the style's fill and to the gradient named for the style, and what the form shows for a fill. The builder applies the writes, since only it knows which site declares what.

This module compiles only when Phoenix.Component is loaded (spec/10 §1.1, D-45, D-85).

Summary

Types

A write the fill group asks for.

Functions

Whether a control of the form belongs to the fill group rather than to a key.

The name of the gradient a style at a path fills with (spec/14 §18.6): the style's name, or its path spelt with underscores, and _fill.

The fill style a value shows as: :none, :solid, or the kind of the gradient a paint names — :linear when the gradient is not declared, so the choice still reads.

The four fill styles in order.

What the form shows for a fill (spec/14 §18.6): the fill style, and for a gradient its stops as wells, its angle or its centre.

What a control of the fill group writes (spec/14 §18.6), given the fill's current value, the design's defs, the gradient's name for this style, and the colour the well shows. fill.angle.range is the angle's scrubber and writes as fill.angle does.

Types

write()

@type write() ::
  {:fill, {:ok, term()} | :error}
  | {:declare, atom(), map()}
  | {:gradient, atom(), (map() -> map())}

A write the fill group asks for.

Functions

control?(arg1)

@spec control?(String.t()) :: boolean()

Whether a control of the form belongs to the fill group rather than to a key.

iex> Visualize.Chart.Builder.Fills.control?("fill_style")
true

iex> Visualize.Chart.Builder.Fills.control?("fill.stop.1.slot")
true

iex> Visualize.Chart.Builder.Fills.control?("fill.slot")
false

name(path)

@spec name([term()]) :: atom()

The name of the gradient a style at a path fills with (spec/14 §18.6): the style's name, or its path spelt with underscores, and _fill.

iex> Visualize.Chart.Builder.Fills.name([:styles, :series])
:series_fill

iex> Visualize.Chart.Builder.Fills.name([:marks, 0, :style])
:marks_0_style_fill

iex> Visualize.Chart.Builder.Fills.name([:style])
:style_fill

style_of(arg1, defs)

@spec style_of(term(), map()) :: :none | :solid | :linear | :radial

The fill style a value shows as: :none, :solid, or the kind of the gradient a paint names — :linear when the gradient is not declared, so the choice still reads.

iex> Visualize.Chart.Builder.Fills.style_of(:none, %{})
:none

iex> Visualize.Chart.Builder.Fills.style_of({:paint, :g}, %{g: %{kind: :radial}})
:radial

iex> Visualize.Chart.Builder.Fills.style_of("#abc", %{})
:solid

iex> Visualize.Chart.Builder.Fills.style_of(nil, %{})
:solid

styles()

@spec styles() :: [atom()]

The four fill styles in order.

view(value, defs, name)

@spec view(term(), map(), atom()) :: map()

What the form shows for a fill (spec/14 §18.6): the fill style, and for a gradient its stops as wells, its angle or its centre.

writes(angle, picked, value, defs, name, well)

@spec writes(String.t(), String.t() | nil, term(), map(), atom(), String.t() | nil) ::
  [write()]

What a control of the fill group writes (spec/14 §18.6), given the fill's current value, the design's defs, the gradient's name for this style, and the colour the well shows. fill.angle.range is the angle's scrubber and writes as fill.angle does.

iex> Visualize.Chart.Builder.Fills.writes("fill_style", "none", "#abc", %{}, :s_fill, "#abc")
[fill: {:ok, :none}]

iex> Visualize.Chart.Builder.Fills.writes("fill_style", "solid", {:paint, :s_fill}, %{s_fill: %{kind: :linear, stops: [%{offset: 0, colour: "#123"}]}}, :s_fill, "#123")
[fill: {:ok, "#123"}]

iex> [{:declare, :s_fill, gradient}, {:fill, {:ok, {:paint, :s_fill}}}] =
...>   Visualize.Chart.Builder.Fills.writes("fill_style", "linear", "#abc", %{}, :s_fill, "#abc")
iex> gradient
%{kind: :linear, stops: [%{offset: 0, colour: "#abc", opacity: 0.8}, %{offset: 1, colour: "#abc", opacity: 0.1}]}

iex> [{:gradient, :s_fill, fun}] = Visualize.Chart.Builder.Fills.writes("fill.angle", "90", nil, %{}, :s_fill, nil)
iex> fun.(%{kind: :linear, stops: []})
%{kind: :linear, stops: [], angle: 90}

iex> Visualize.Chart.Builder.Fills.writes("fill.nonsense", "1", nil, %{}, :s_fill, nil)
[]