Bland.Patterns (Elixir Technical Drawing v0.3.0)

Copy Markdown View Source

Monochrome SVG fill patterns — the hatching vocabulary of a 1970s technical report.

Each preset expands to a unique, deterministic <pattern> element id. Use the preset atom as a fill reference:

Bland.bar(fig, categories, values, hatch: :diagonal)

Presets

The shipped presets (in the order you'd typically use them for a multi-series plot, maximizing visual separation):

  • :solid_black — fully filled black
  • :solid_white — blank (paper color)
  • :diagonal — 45° lines, medium density
  • :anti_diagonal — 135° lines, medium density
  • :crosshatch — 45° + 135°
  • :horizontal — horizontal rules
  • :vertical — vertical rules
  • :grid — square grid
  • :dots_sparse — small dots, wide spacing
  • :dots_dense — small dots, tight spacing
  • :brick — running-bond brick
  • :zigzag — repeating zigzag line
  • :checker — 8x8 checker tiling
  • :dashed_h — interrupted horizontal dashes
  • :diagonal_dense — tightly packed 45° lines

All presets are rendered with 1px black lines on a transparent ground so they compose with any theme stroke color.

Custom patterns

Build your own with define/3:

Bland.Patterns.define("my-hatch", {10, 10}, ~s|<line x1="0" y1="0" x2="10" y2="10" stroke="black"/>|)

Summary

Functions

Returns the next n patterns from the cycle, skipping any already used.

Defines a custom pattern inline. Returns an iodata <pattern> element suitable for placing in a <defs> block. id is the DOM id you will reference via fill="url(#<id>)".

Emits the SVG <pattern> defs for every preset named in names.

Returns an SVG fill attribute value for a preset. Solid presets return color names; hatch presets return "url(#bland-pattern-...)".

Canonical DOM id for a preset.

Returns the list of preset names in a recommended cycling order. When a multi-series plot does not specify a per-series pattern, the renderer walks this list.

Functions

cycle(index, exclude \\ [])

@spec cycle(non_neg_integer(), [atom()]) :: atom()

Returns the next n patterns from the cycle, skipping any already used.

define(id, arg, body, opts \\ [])

@spec define(String.t(), {number(), number()}, iodata(), keyword()) :: iodata()

Defines a custom pattern inline. Returns an iodata <pattern> element suitable for placing in a <defs> block. id is the DOM id you will reference via fill="url(#<id>)".

defs(names)

@spec defs([atom()]) :: iodata()

Emits the SVG <pattern> defs for every preset named in names.

Duplicates are filtered. :solid_black and :solid_white emit no defs; they are handled as direct fills ("black", "white").

fill(name)

@spec fill(atom()) :: String.t()

Returns an SVG fill attribute value for a preset. Solid presets return color names; hatch presets return "url(#bland-pattern-...)".

id(name)

@spec id(atom()) :: String.t()

Canonical DOM id for a preset.

preset_cycle()

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

Returns the list of preset names in a recommended cycling order. When a multi-series plot does not specify a per-series pattern, the renderer walks this list.