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, mdg_registry: nil) ⇒ StereotypeIconRenderer

Returns a new instance of StereotypeIconRenderer.

Parameters:

  • mdg_registry (Ea::Mdg::Registry, nil) (defaults to: nil)

    optional registry to look up MDG-provided ShapeScript for the classifier's stereotype. When provided and the matching stereotype has a ShapeScript body, it's parsed and rendered. Otherwise falls back to FALLBACK_ICONS.



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

def initialize(classifier:, bounds:, canvas: nil, mdg_registry: nil)
  @classifier = classifier
  @bounds = bounds
  @canvas = canvas
  @mdg_registry = mdg_registry
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

#mdg_registryObject (readonly)

Returns the value of attribute mdg_registry.



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

def mdg_registry
  @mdg_registry
end

Class Method Details

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



45
46
47
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 45

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

Instance Method Details

#to_svgString

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

Returns:

  • (String)

    SVG fragment, or "" if no icon applies



50
51
52
53
54
55
# File 'lib/ea/svg/ea_emitter/element/stereotype_icon_renderer.rb', line 50

def to_svg
  return "" unless classifier && bounds
  return "" unless stereotype_name

  shapescript_svg || fallback_svg
end