Class: Ea::Svg::EaEmitter::Element::HeaderLineProvider::Name
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::Element::HeaderLineProvider::Name
- Defined in:
- lib/ea/svg/ea_emitter/element/header_line_provider/name.rb
Overview
Emits the classifier's display name, with these behaviors:
- Bold-italic for abstract Klass; bold otherwise.
- Qualified name wrap when the rendered width exceeds the element bounds. EA splits "pkg::Class" across two lines when the combined width is too wide.
InstanceSpecification returns [] (InstanceSpec provider already emitted the full label).
Constant Summary collapse
- QUALIFIED_WRAP_WIDTH_FACTOR =
0.55- QUALIFIED_WRAP_PADDING =
8
Class Method Summary collapse
- .call(context) ⇒ Object
- .display_name(classifier, diagram_package_id = nil, _visually_nested = false) ⇒ Object
- .name_exceeds_bounds?(name, bounds_width, font_size) ⇒ Boolean
-
.weight_for(classifier) ⇒ Symbol
:bold_italic for abstract, :bold otherwise.
- .wrapped_name_lines(classifier, context, weight) ⇒ Object
Class Method Details
.call(context) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ea/svg/ea_emitter/element/header_line_provider/name.rb', line 21 def self.call(context) classifier = context.classifier return [] if classifier.is_a?(Ea::Model::InstanceSpecification) weight = weight_for(classifier) wrapped_name_lines(classifier, context, weight) end |
.display_name(classifier, diagram_package_id = nil, _visually_nested = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ea/svg/ea_emitter/element/header_line_provider/name.rb', line 54 def self.display_name(classifier, diagram_package_id = nil, _visually_nested = false) name = if classifier.is_a?(Ea::Model::Classifier) (classifier.qualified_name || classifier.name).to_s else classifier.name.to_s end return name if diagram_package_id.nil? return name unless name.include?("::") if classifier.is_a?(Ea::Model::Classifier) && classifier.package_id == diagram_package_id name.split("::").last else name end end |
.name_exceeds_bounds?(name, bounds_width, font_size) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/ea/svg/ea_emitter/element/header_line_provider/name.rb', line 48 def self.name_exceeds_bounds?(name, bounds_width, font_size) TextRenderer.estimate_width(name, font_size, QUALIFIED_WRAP_WIDTH_FACTOR) > (bounds_width - QUALIFIED_WRAP_PADDING) end |
.weight_for(classifier) ⇒ Symbol
Returns :bold_italic for abstract, :bold otherwise.
31 32 33 |
# File 'lib/ea/svg/ea_emitter/element/header_line_provider/name.rb', line 31 def self.weight_for(classifier) classifier.is_a?(Ea::Model::Klass) && classifier.is_abstract ? :bold_italic : :bold end |
.wrapped_name_lines(classifier, context, weight) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ea/svg/ea_emitter/element/header_line_provider/name.rb', line 35 def self.wrapped_name_lines(classifier, context, weight) name = display_name(classifier, context.diagram_package_id, context.visually_nested) unless context.bounds_width && name.include?("::") && name_exceeds_bounds?(name, context.bounds_width, context.font_size || 9) return [[name, weight]] end qualifier, base = name.split("::", 2) [["#{qualifier}::", weight], [base, weight]] end |