Class: Ea::Theme::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/theme/definition.rb

Overview

Immutable value object describing a complete EA diagram theme.

Bundles ALL appearance values that EA's SVG renderer needs: fonts, colors, strokes, canvas insets, compartment spacing, marker geometry, etc. No renderer hardcodes appearance numbers — every value comes from the active Definition.

Defined Under Namespace

Classes: AttrSpec, CompartmentSpec, FrameSpec, Geometry, MarkerSpec, NoteSpec, PackageSpec

Constant Summary collapse

DEFAULT_GEOMETRY =
Geometry.new(inset_left: 35, inset_right: 50,
inset_top: 40, inset_bottom: 57).freeze
DEFAULT_FRAME =
FrameSpec.new(inset: 6, tab_height: 20, tab_slant: 13,
tab_label_x: 11, tab_label_y: 19,
tab_padding: 7).freeze
DEFAULT_COMPARTMENTS =
CompartmentSpec.new(header_top_padding: 9,
header_line_offset: 6,
divider_offset: 8,
attr_line_offset: 4,
attr_first_offset: 7,
op_line_offset: 4).freeze
DEFAULT_ATTR =
AttrSpec.new(visibility_x_offset: 5,
content_x_offset: 20).freeze
DEFAULT_MARKERS =
MarkerSpec.new(diamond_half_width: 5,
diamond_half_height: 10,
triangle_half_base: 6,
triangle_height: 11,
arrow_half_base: 6,
arrow_height: 11).freeze
DEFAULT_PACKAGE =
PackageSpec.new(tab_height: 20,
tab_label_padding: 10,
default_tab_width: 105).freeze
DEFAULT_NOTE =
NoteSpec.new(fold_size: 12, text_x_offset: 5,
text_y_offset: 12, line_height: 12).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name: nil, font_family: nil, font_size: nil, font_size_unit: "pt", text_weight_normal: 400, text_weight_bold: 700, element_font_size: 9, element_font_unit: "pt", text_color: "#000000", attribute_text_color: nil, method_text_color: nil, border_color: "#000000", fill_color: "#FFFFFF", background_color: "#FFFFFF", stroke_in_text_color: "#000000", element_border_width: 2, connector_line_width: 2, divider_stroke_width: 2, marker_stroke_width: 2, text_width_factor: 0.65, geometry: nil, frame: nil, compartments: nil, attribute_spec: nil, markers: nil, package: nil, note: nil, fills: {}) ⇒ Definition

Returns a new instance of Definition.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ea/theme/definition.rb', line 67

def initialize(id:, name: nil, font_family: nil, font_size: nil,
               font_size_unit: "pt", text_weight_normal: 400,
               text_weight_bold: 700,
               element_font_size: 9, element_font_unit: "pt",
               text_color: "#000000", attribute_text_color: nil,
               method_text_color: nil, border_color: "#000000",
               fill_color: "#FFFFFF", background_color: "#FFFFFF",
               stroke_in_text_color: "#000000",
               element_border_width: 2, connector_line_width: 2,
               divider_stroke_width: 2, marker_stroke_width: 2,
               text_width_factor: 0.65,
               geometry: nil, frame: nil, compartments: nil,
               attribute_spec: nil, markers: nil, package: nil,
               note: nil, fills: {})
  @id = id.to_s
  @name = name
  @font_family = font_family
  @font_size = font_size
  @font_size_unit = font_size_unit
  @text_weight_normal = text_weight_normal
  @text_weight_bold = text_weight_bold
  @element_font_size = element_font_size
  @element_font_unit = element_font_unit
  @text_color = text_color
  @attribute_text_color = attribute_text_color
  @method_text_color = method_text_color
  @border_color = border_color
  @fill_color = fill_color
  @background_color = background_color
  @stroke_in_text_color = stroke_in_text_color
  @element_border_width = element_border_width
  @connector_line_width = connector_line_width
  @divider_stroke_width = divider_stroke_width
  @marker_stroke_width = marker_stroke_width
  @text_width_factor = text_width_factor
  @geometry = geometry || DEFAULT_GEOMETRY.dup
  @frame = frame || DEFAULT_FRAME.dup
  @compartments = compartments || DEFAULT_COMPARTMENTS.dup
  @attribute_spec = attribute_spec || DEFAULT_ATTR.dup
  @markers = markers || DEFAULT_MARKERS.dup
  @package = package || DEFAULT_PACKAGE.dup
  @note = note || DEFAULT_NOTE.dup
  @fills = fills.dup.freeze
end

Instance Attribute Details

#attribute_specObject (readonly)

Returns the value of attribute attribute_spec.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def attribute_spec
  @attribute_spec
end

#attribute_text_colorObject (readonly)

Returns the value of attribute attribute_text_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def attribute_text_color
  @attribute_text_color
end

#background_colorObject (readonly)

Returns the value of attribute background_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def background_color
  @background_color
end

#border_colorObject (readonly)

Returns the value of attribute border_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def border_color
  @border_color
end

#compartmentsObject (readonly)

Returns the value of attribute compartments.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def compartments
  @compartments
end

#connector_line_widthObject (readonly)

Returns the value of attribute connector_line_width.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def connector_line_width
  @connector_line_width
end

#divider_stroke_widthObject (readonly)

Returns the value of attribute divider_stroke_width.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def divider_stroke_width
  @divider_stroke_width
end

#element_border_widthObject (readonly)

Returns the value of attribute element_border_width.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def element_border_width
  @element_border_width
end

#element_font_sizeObject (readonly)

Returns the value of attribute element_font_size.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def element_font_size
  @element_font_size
end

#element_font_unitObject (readonly)

Returns the value of attribute element_font_unit.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def element_font_unit
  @element_font_unit
end

#fill_colorObject (readonly)

Returns the value of attribute fill_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def fill_color
  @fill_color
end

#fillsObject (readonly)

Returns the value of attribute fills.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def fills
  @fills
end

#font_familyObject (readonly)

Returns the value of attribute font_family.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def font_family
  @font_family
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def font_size
  @font_size
end

#font_size_unitObject (readonly)

Returns the value of attribute font_size_unit.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def font_size_unit
  @font_size_unit
end

#frameObject (readonly)

Returns the value of attribute frame.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def frame
  @frame
end

#geometryObject (readonly)

Returns the value of attribute geometry.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def geometry
  @geometry
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def id
  @id
end

#marker_stroke_widthObject (readonly)

Returns the value of attribute marker_stroke_width.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def marker_stroke_width
  @marker_stroke_width
end

#markersObject (readonly)

Returns the value of attribute markers.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def markers
  @markers
end

#method_text_colorObject (readonly)

Returns the value of attribute method_text_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def method_text_color
  @method_text_color
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def name
  @name
end

#noteObject (readonly)

Returns the value of attribute note.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def note
  @note
end

#packageObject (readonly)

Returns the value of attribute package.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def package
  @package
end

#stroke_in_text_colorObject (readonly)

Returns the value of attribute stroke_in_text_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def stroke_in_text_color
  @stroke_in_text_color
end

#text_colorObject (readonly)

Returns the value of attribute text_color.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def text_color
  @text_color
end

#text_weight_boldObject (readonly)

Returns the value of attribute text_weight_bold.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def text_weight_bold
  @text_weight_bold
end

#text_weight_normalObject (readonly)

Returns the value of attribute text_weight_normal.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def text_weight_normal
  @text_weight_normal
end

#text_width_factorObject (readonly)

Returns the value of attribute text_width_factor.



29
30
31
# File 'lib/ea/theme/definition.rb', line 29

def text_width_factor
  @text_width_factor
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



126
127
128
# File 'lib/ea/theme/definition.rb', line 126

def ==(other)
  other.is_a?(Definition) && id == other.id
end

#attribute_colorObject



141
142
143
# File 'lib/ea/theme/definition.rb', line 141

def attribute_color
  attribute_text_color
end

#fill_for(classifier) ⇒ Object



116
117
118
119
120
# File 'lib/ea/theme/definition.rb', line 116

def fill_for(classifier)
  return nil if classifier.nil?

  fills[classifier.class.name]
end

#hashObject



130
131
132
# File 'lib/ea/theme/definition.rb', line 130

def hash
  id.hash
end

#method_colorObject



145
146
147
# File 'lib/ea/theme/definition.rb', line 145

def method_color
  method_text_color
end

#stroke_widthObject

Backward-compatible aliases for renamed attributes.



137
138
139
# File 'lib/ea/theme/definition.rb', line 137

def stroke_width
  element_border_width
end

#themed?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/ea/theme/definition.rb', line 112

def themed?
  id != "default"
end

#to_hObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/ea/theme/definition.rb', line 149

def to_h
  {
    id: id, name: name,
    font_family: font_family, font_size: font_size,
    font_size_unit: font_size_unit,
    text_weight_normal: text_weight_normal,
    text_weight_bold: text_weight_bold,
    element_font_size: element_font_size,
    element_font_unit: element_font_unit,
    text_color: text_color,
    attribute_text_color: attribute_text_color,
    method_text_color: method_text_color,
    border_color: border_color, fill_color: fill_color,
    background_color: background_color,
    stroke_in_text_color: stroke_in_text_color,
    element_border_width: element_border_width,
    connector_line_width: connector_line_width,
    divider_stroke_width: divider_stroke_width,
    marker_stroke_width: marker_stroke_width,
    text_width_factor: text_width_factor,
    geometry: geometry, frame: frame, compartments: compartments,
    attribute_spec: attribute_spec, markers: markers,
    package: package, note: note, fills: fills
  }
end

#with(**overrides) ⇒ Object



122
123
124
# File 'lib/ea/theme/definition.rb', line 122

def with(**overrides)
  Definition.new(**to_h.merge(overrides))
end