Class: Ea::Svg::EaEmitter::Element::LegendRenderer

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

Overview

Emits the auto-generated legend block that EA renders from a Text element whose StyleEx carries LegendOpts=. Layout (verified against plateau reference SVGs):

┌──────────────────────────────┐
│            凡例              │  ← title baseline 19px below top
│  ┌──┐                        │
│  └──┘  GMLに定義されたクラス  │  ← item 0 (icon top + 30px)
│  ┌──┐                        │
│  └──┘  CityGMLに定義されたクラス
│  ┌──┐                        │
│  └──┘  i-URに定義されたクラス  │
└──────────────────────────────┘

Container: bounds.width × bounds.height, rx=3. Each item: 17×17 icon rect + label text on the same line. Item spacing is 19px (icon height 17 + 2 padding).

Constant Summary collapse

CONTAINER_RX =
3
ICON_SIZE =
17
TITLE_Y_OFFSET =
19
FIRST_ITEM_Y_OFFSET =
30
ITEM_SPACING =
19
ICON_X_OFFSET =
10
ICON_LABEL_GAP =
22
LABEL_BASELINE_FROM_ICON_TOP =
12
DEFAULT_ITEM_FONT_SIZE =
9

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bounds, legend, family, canvas) ⇒ LegendRenderer

Returns a new instance of LegendRenderer.



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

def initialize(bounds, legend, family, canvas)
  @bounds = bounds
  @legend = legend
  @family = family
  @canvas = canvas
end

Class Method Details

.render(bounds, legend:, family:, canvas: nil) ⇒ Object



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

def self.render(bounds, legend:, family:, canvas: nil)
  new(bounds, legend, family, canvas).to_svg
end

Instance Method Details

#to_svgObject



46
47
48
# File 'lib/ea/svg/ea_emitter/element/legend_renderer.rb', line 46

def to_svg
  [container_layer, items_layer, title_layer].compact.join("\n")
end