Module: Sevgi::Graphics::Mixtures::Wrappers

Defined in:
lib/sevgi/graphics/mixtures/wrappers.rb

Overview

DSL wrappers for common SVG shapes and content patterns.

Instance Method Summary collapse

Instance Method Details

#css(hash = nil, **attributes) ⇒ Sevgi::Graphics::Element

Builds a style element with CSS content.

Parameters:

  • hash (Hash, nil) (defaults to: nil)

    CSS rules

  • attributes (Hash)

    style attributes or CSS rules when hash is nil

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when CSS content is not a hash



67
68
69
70
71
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 67

def css(hash = nil, **attributes)
  hash, attributes = attributes, {} unless hash

  style(Content.css(hash), type: "text/css", **attributes)
end

#HLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative horizontal line path.

Parameters:

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



78
79
80
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 78

def HLineBy(length:, x: 0, y: 0, **)
  path(d: "M #{x} #{y} h #{length}", **)
end

#HLineTo(x2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a horizontal line path ending at an absolute x coordinate.

Parameters:

  • x2 (Numeric)

    ending x coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



23
24
25
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 23

def HLineTo(x2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} H #{x2}", **)
end

#LineBy(angle:, length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative line path from angle and length.

Parameters:

  • angle (Numeric)

    angle in degrees

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



56
57
58
59
60
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 56

def LineBy(angle:, length:, x: 0, y: 0, **)
  dx = length * ::Math.cos(angle.to_f / 180 * ::Math::PI)
  dy = length * ::Math.sin(angle.to_f / 180 * ::Math::PI)
  path(d: "M #{x} #{y} l #{dx} #{dy}", **)
end

#LineTo(x2:, y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a line path ending at an absolute point.

Parameters:

  • x2 (Numeric)

    ending x coordinate

  • y2 (Numeric)

    ending y coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



14
15
16
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 14

def LineTo(x2:, y2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} L #{x2} #{y2}", **)
end

#square(length:) ⇒ Sevgi::Graphics::Element

Builds a square rect.

Parameters:

  • length (Numeric)

    side length

Returns:



85
86
87
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 85

def square(length:, **)
  rect(width: length, height: length, **)
end

#Symbol(name, **kwargs, &block) ⇒ Sevgi::Graphics::Element

Builds a titled SVG symbol.

Parameters:

  • name (String)

    human-readable symbol name

  • kwargs (Hash)

    symbol attributes

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 31

def Symbol(name, **kwargs, &block)
  id = (words = name.split).map(&:downcase).join("-")
  title = words.map(&:capitalize).join(" ")

  symbol(id:, **kwargs) do
    title(title)
    Within(&block)
  end
end

#VLineBy(length:, x: 0, y: 0) ⇒ Sevgi::Graphics::Element

Builds a relative vertical line path.

Parameters:

  • length (Numeric)

    line length

  • x (Numeric) (defaults to: 0)

    starting x coordinate

  • y (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



94
95
96
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 94

def VLineBy(length:, x: 0, y: 0, **)
  path(d: "M #{x} #{y} v #{length}", **)
end

#VLineTo(y2:, x1: 0, y1: 0) ⇒ Sevgi::Graphics::Element

Builds a vertical line path ending at an absolute y coordinate.

Parameters:

  • y2 (Numeric)

    ending y coordinate

  • x1 (Numeric) (defaults to: 0)

    starting x coordinate

  • y1 (Numeric) (defaults to: 0)

    starting y coordinate

Returns:



46
47
48
# File 'lib/sevgi/graphics/mixtures/wrappers.rb', line 46

def VLineTo(y2:, x1: 0, y1: 0, **)
  path(d: "M #{x1} #{y1} V #{y2}", **)
end