Class: Ea::Svg::EaEmitter::Element::StereotypeIconRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb

Overview

Emits stereotype decorator icons inside an element's body. EA renders a small symbolic polygon (typically a diamond or chevron) when a stereotype provides a custom icon via ShapeScript.

Currently provides hardcoded fallback polygons for the most common GML stereotypes (FeatureType, Type) since the source ShapeScript definitions live in EA's encrypted InternalTechnologies (TODO.diagrams/87). Future enhancement: read shapescript from MDG files when available.

Constant Summary collapse

FALLBACK_ICONS =

Hardcoded fallback icons keyed by stereotype name. Each entry is [fill, stroke, points_array].

{
  "FeatureType" => ["#FAF1EC", "#69738C",
                    [[0, -5], [5, 0], [0, 5], [-5, 0]]],
  "Type" => ["#FAF1EC", "#69738C",
             [[0, -5], [5, 0], [0, 5], [-5, 0]]]
}.freeze
OFFSET_X =

Default position offset from element's center

0
OFFSET_Y =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(classifier:, bounds:, canvas: nil) ⇒ StereotypeIconRenderer

Returns a new instance of StereotypeIconRenderer.



33
34
35
36
37
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 33

def initialize(classifier:, bounds:, canvas: nil)
  @classifier = classifier
  @bounds = bounds
  @canvas = canvas
end

Instance Attribute Details

#boundsObject (readonly)

Returns the value of attribute bounds.



31
32
33
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 31

def bounds
  @bounds
end

#canvasObject (readonly)

Returns the value of attribute canvas.



31
32
33
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 31

def canvas
  @canvas
end

#classifierObject (readonly)

Returns the value of attribute classifier.



31
32
33
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 31

def classifier
  @classifier
end

Class Method Details

.render(classifier:, bounds:, canvas: nil, **_) ⇒ Object



39
40
41
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 39

def self.render(classifier:, bounds:, canvas: nil, **_)
  new(classifier: classifier, bounds: bounds, canvas: canvas).to_svg
end

Instance Method Details

#to_svgString

Returns SVG polygon fragment, or "" if no icon applies.

Returns:

  • (String)

    SVG polygon fragment, or "" if no icon applies



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 44

def to_svg
  return "" unless classifier && bounds

  spec = FALLBACK_ICONS[stereotype_name]
  return "" unless spec

  fill, stroke, points = spec
  cx = bounds.x + bounds.width / 2 + OFFSET_X
  cy = bounds.y + bounds.height / 2 + OFFSET_Y
  translated = points.map { |x, y| translate_point(cx + x, cy + y) }
  pts_str = translated.map { |x, y| coord(x) + "," + coord(y) }.join(" ")
  %(<polygon points="#{pts_str}" fill="#{fill}" stroke="#{stroke}" stroke-width="1"/>)
end