Module: Ea::Svg::EaEmitter::Compartment::Shape
- Defined in:
- lib/ea/svg/ea_emitter/compartment/shape.rb
Overview
Element shape: stroked rect for classifiers, folder silhouette for packages, note silhouette for notes.
Class Method Summary collapse
-
.hand_draw?(context) ⇒ Boolean
HandDraw=1 in the diagram StyleEx switches every element to EA's hand-drawn wavy silhouette.
-
.legend?(context) ⇒ Boolean
A Text element with LegendOpts= renders as the legend block rather than a folder silhouette.
- .package_label(model_element) ⇒ Object
-
.package_stereotype(model_element) ⇒ Object
EA renders a package's applied stereotype above the name inside the tab area when one is set.
- .render(context) ⇒ Object
Class Method Details
.hand_draw?(context) ⇒ Boolean
HandDraw=1 in the diagram StyleEx switches every element to EA's hand-drawn wavy silhouette.
59 60 61 |
# File 'lib/ea/svg/ea_emitter/compartment/shape.rb', line 59 def hand_draw?(context) context.diagram && context.diagram.hand_draw end |
.legend?(context) ⇒ Boolean
A Text element with LegendOpts= renders as the legend block rather than a folder silhouette. Dispatch on the presence of the attached Legend payload.
52 53 54 55 |
# File 'lib/ea/svg/ea_emitter/compartment/shape.rb', line 52 def legend?(context) context.model_element.is_a?(Ea::Model::Note) && context.model_element.legend end |
.package_label(model_element) ⇒ Object
63 64 65 |
# File 'lib/ea/svg/ea_emitter/compartment/shape.rb', line 63 def package_label(model_element) model_element.name.to_s end |
.package_stereotype(model_element) ⇒ Object
EA renders a package's applied stereotype above the name inside the tab area when one is set. Returns nil when no stereotype is applied (the common case).
70 71 72 73 74 75 76 77 |
# File 'lib/ea/svg/ea_emitter/compartment/shape.rb', line 70 def package_stereotype(model_element) return nil unless model_element.is_a?(Ea::Model::Package) refs = model_element.stereotype_refs return nil unless refs&.any? refs.first.to_s end |
.render(context) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ea/svg/ea_emitter/compartment/shape.rb', line 12 def render(context) if legend?(context) Element::LegendRenderer.render( context.bounds, legend: context.model_element.legend, family: context.family, canvas: context.canvas ) elsif context.model_element.is_a?(Ea::Model::Package) || context.model_element.is_a?(Ea::Model::Note) label = package_label(context.model_element) stereotype = package_stereotype(context.model_element) Element::PackageShapeRenderer.render( context.bounds, fill: context.fill, stroke: context.stroke, stroke_width: context.stroke_width, label: label, stereotype: stereotype, family: context.family, size: context.size, size_unit: context.size_unit, text_fill: context.text_fill ) elsif hand_draw?(context) Element::HandDrawShapeRenderer.render( context.bounds, fill: context.fill, stroke: context.stroke, stroke_width: context.stroke_width ) else Element::ShapeRenderer.render( context.bounds, fill: context.fill, stroke: context.stroke, stroke_width: context.stroke_width ) end end |