Class: Ea::Svg::EaEmitter::GhostLabels

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

Overview

Emits ghost classifier name <text> elements for connector endpoints that reference off-canvas classifiers. Each ghost label appears as italic text near the connector's on-canvas endpoint.

Constant Summary collapse

DEFAULT_FAMILY =
"Carlito"
DEFAULT_SIZE =
9
DEFAULT_UNIT =
"pt"
DEFAULT_FILL =
"#000000"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram, canvas: nil, family: DEFAULT_FAMILY, size: DEFAULT_SIZE, size_unit: DEFAULT_UNIT, fill: DEFAULT_FILL) ⇒ GhostLabels

Returns a new instance of GhostLabels.



18
19
20
21
22
23
24
25
26
27
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 18

def initialize(diagram, canvas: nil, family: DEFAULT_FAMILY,
               size: DEFAULT_SIZE, size_unit: DEFAULT_UNIT,
               fill: DEFAULT_FILL)
  @diagram = diagram
  @canvas = canvas
  @family = family
  @size = size
  @size_unit = size_unit
  @fill = fill
end

Instance Attribute Details

#canvasObject (readonly)

Returns the value of attribute canvas.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def canvas
  @canvas
end

#diagramObject (readonly)

Returns the value of attribute diagram.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def diagram
  @diagram
end

#familyObject (readonly)

Returns the value of attribute family.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def family
  @family
end

#fillObject (readonly)

Returns the value of attribute fill.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def fill
  @fill
end

#sizeObject (readonly)

Returns the value of attribute size.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def size
  @size
end

#size_unitObject (readonly)

Returns the value of attribute size_unit.



16
17
18
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 16

def size_unit
  @size_unit
end

Instance Method Details

#renderObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ea/svg/ea_emitter/ghost_labels.rb', line 29

def render
  texts = visible_connectors.flat_map do |connector|
    (connector.ghost_labels || []).map { |g| text_for(g) }
  end
  return "" if texts.empty?

  group_style = "stroke-width:1;stroke-linecap:round;" \
                "stroke-linejoin:bevel; fill:#{fill};" \
                "fill-opacity:1.00; stroke:#000000;" \
                " stroke-opacity:0.00"
  %(<g style="#{group_style}">\n#{texts.join("\n")}\n</g>)
end