archsight 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/archimate.md +4 -3
- data/docs/diagram.md +107 -6
- data/docs/icons.md +1 -0
- data/docs/index.md.erb +1 -0
- data/docs/modeling.md +71 -2
- data/lib/archsight/diagram/graph/attributes.rb +66 -11
- data/lib/archsight/diagram/graph/builder.rb +101 -3
- data/lib/archsight/diagram/graph/edge.rb +7 -1
- data/lib/archsight/diagram/graph/node.rb +29 -1
- data/lib/archsight/diagram/graph/port.rb +28 -0
- data/lib/archsight/diagram/graph.rb +18 -1
- data/lib/archsight/diagram/includes.rb +22 -4
- data/lib/archsight/diagram/layout/alignment.rb +138 -0
- data/lib/archsight/diagram/layout/expander.rb +13 -0
- data/lib/archsight/diagram/layout/ports.rb +182 -0
- data/lib/archsight/diagram/layout/rank_arranger.rb +27 -1
- data/lib/archsight/diagram/layout/stacker.rb +3 -2
- data/lib/archsight/diagram/layout.rb +15 -5
- data/lib/archsight/diagram/legend/inventory.rb +52 -4
- data/lib/archsight/diagram/legend/row.rb +44 -0
- data/lib/archsight/diagram/parser/ast.rb +9 -0
- data/lib/archsight/diagram/parser.rb +56 -5
- data/lib/archsight/diagram/renderer/dataflow_renderer.rb +2 -1
- data/lib/archsight/diagram/renderer/edge_renderer.rb +5 -2
- data/lib/archsight/diagram/renderer/label_placer.rb +98 -22
- data/lib/archsight/diagram/renderer/node_renderer.rb +49 -1
- data/lib/archsight/diagram/renderer/path_renderer.rb +2 -2
- data/lib/archsight/diagram/renderer/stylesheet.rb +10 -1
- data/lib/archsight/diagram/renderer/text_renderer.rb +1 -0
- data/lib/archsight/diagram/renderer.rb +21 -5
- data/lib/archsight/diagram/resource_links.rb +18 -12
- data/lib/archsight/diagram/routing/edge_routing.rb +106 -5
- data/lib/archsight/diagram/support/markdown_text.rb +2 -2
- data/lib/archsight/diagram/support/text_metrics.rb +7 -3
- data/lib/archsight/export/confluence/analysis_output.rb +12 -5
- data/lib/archsight/linter/structure.rb +17 -3
- data/lib/archsight/linter.rb +30 -4
- data/lib/archsight/pdf/embeds.rb +3 -2
- data/lib/archsight/pdf/typst/archsight.typ +4 -0
- data/lib/archsight/resources/base.rb +5 -0
- data/lib/archsight/resources/grouping.rb +80 -0
- data/lib/archsight/resources/technology_node.rb +17 -2
- data/lib/archsight/resources/technology_service.rb +6 -0
- data/lib/archsight/resources/technology_system_software.rb +5 -0
- data/lib/archsight/resources.rb +28 -0
- data/lib/archsight/summary/lens.rb +10 -0
- data/lib/archsight/template.rb +2 -2
- data/lib/archsight/version.rb +1 -1
- metadata +5 -1
|
@@ -10,6 +10,7 @@ module Archsight
|
|
|
10
10
|
# decides *how* those rows look once assembled. `relations` are the
|
|
11
11
|
# relations actually drawn (see `Legend.rows`).
|
|
12
12
|
class Inventory
|
|
13
|
+
Attributes = Graph::Attributes
|
|
13
14
|
def initialize(graph, relations:)
|
|
14
15
|
@graph = graph
|
|
15
16
|
@relations = relations
|
|
@@ -18,7 +19,7 @@ module Archsight
|
|
|
18
19
|
def rows
|
|
19
20
|
return @rows if defined?(@rows)
|
|
20
21
|
|
|
21
|
-
@rows = trivial? ? [] : shape_rows + relation_rows + dataflow_rows + swatch_rows
|
|
22
|
+
@rows = trivial? ? [] : shape_rows + port_rows + relation_rows + line_rows + dataflow_rows + swatch_rows + badge_rows
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
private
|
|
@@ -28,7 +29,29 @@ module Archsight
|
|
|
28
29
|
def trivial?
|
|
29
30
|
(used_shapes - ["rectangle"]).empty? && @relations.all? { |r| Relations.for(r).default? } &&
|
|
30
31
|
!boundary_present? && !application_present? && @graph.dataflows.empty? && used_tints.empty? &&
|
|
31
|
-
tinted_containers.empty?
|
|
32
|
+
tinted_containers.empty? && @graph.ports.empty? && used_badges.empty? && used_lines.empty?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def port_rows = @graph.ports.empty? ? [] : [PortRow.new("Port")]
|
|
36
|
+
|
|
37
|
+
# A row per line style that is drawn and has its legend text from a top-level `line "..." { label }`.
|
|
38
|
+
def line_rows = used_lines.map { |d| LineRow.new(d.label, line_style: d.id) }
|
|
39
|
+
|
|
40
|
+
def badge_rows = used_badges.map { |d| BadgeRow.new(d.label, tint: d.tint, badge: d.id) }
|
|
41
|
+
|
|
42
|
+
def used_lines
|
|
43
|
+
@used_lines ||= Attributes::LINE_STYLES.filter_map do |style|
|
|
44
|
+
definition = @graph.line_definition(style)
|
|
45
|
+
definition if definition && @graph.edges.any? { |e| e.line_style == style && @relations.include?(e.relation) }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Badges in the order they are defined.
|
|
50
|
+
def used_badges
|
|
51
|
+
@used_badges ||= begin
|
|
52
|
+
ids = (@graph.nodes_by_id.values.filter_map(&:badge) + @graph.ports.filter_map(&:badge)).uniq
|
|
53
|
+
@graph.definitions.values.select { |d| d.kind == :badge && ids.include?(d.id) }
|
|
54
|
+
end
|
|
32
55
|
end
|
|
33
56
|
|
|
34
57
|
def shape_rows
|
|
@@ -62,9 +85,34 @@ module Archsight
|
|
|
62
85
|
rows << SwatchRow.new("Trust boundary", tint: Tints.for("red"), dash_class: "asd-swatch-boundary") if default_boundary_present?
|
|
63
86
|
tinted_containers.each do |n|
|
|
64
87
|
dash_class = n.boundary? ? "asd-swatch-boundary" : "asd-swatch-container"
|
|
65
|
-
|
|
88
|
+
label = n.legend_label || MarkdownText.like(n.label, "#{n.kind.to_s.capitalize} #{n.label}")
|
|
89
|
+
rows << SwatchRow.new(label, tint: Tints.for(n.effective_tint), dash_class: dash_class)
|
|
66
90
|
end
|
|
67
|
-
rows +
|
|
91
|
+
rows + tint_rows
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# One row per tint set on a leaf, named by a `legend "..."` of one of those leaves, else by the leaves'
|
|
95
|
+
# own names -- not by the color, which says nothing. Left out when every such leaf sits inside a
|
|
96
|
+
# container of the same tint, whose own row already explains it.
|
|
97
|
+
def tint_rows
|
|
98
|
+
used_tints.filter_map do |tint|
|
|
99
|
+
leaves = tinted_leaves.select { |n| n.tint == tint.name }
|
|
100
|
+
next if leaves.all? { |n| inside_same_tinted_container?(n) }
|
|
101
|
+
|
|
102
|
+
label = leaves.filter_map(&:legend_label).first || leaves.map { |n| display_name(n) }.uniq.join(", ")
|
|
103
|
+
SwatchRow.new(label, tint: tint)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def tinted_leaves = @graph.nodes_by_id.values.reject { |n| n.container? || n.kind == :text || n.tint.nil? }
|
|
108
|
+
|
|
109
|
+
def inside_same_tinted_container?(node)
|
|
110
|
+
node.ancestors.drop(1).any? { |a| !a.anonymous? && a.tint == node.tint }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# A node's name as its label shows it: the first line, without markdown markers.
|
|
114
|
+
def display_name(node)
|
|
115
|
+
TextMetrics.markdown_runs(TextMetrics.lines(node.label).first).map(&:first).join.strip
|
|
68
116
|
end
|
|
69
117
|
|
|
70
118
|
def used_shapes
|
|
@@ -138,6 +138,50 @@ module Archsight
|
|
|
138
138
|
m.to_s
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
|
+
|
|
142
|
+
# A port tab (see `NodeRenderer#render_ports`).
|
|
143
|
+
class PortRow < Row
|
|
144
|
+
def id_key = "port"
|
|
145
|
+
|
|
146
|
+
def icon(cx, cy, id:)
|
|
147
|
+
m = Renderer::Markup.new
|
|
148
|
+
m.element("rect", id: "#{id}__icon", x: SvgFormat.fmt(cx - 11), y: SvgFormat.fmt(cy - 6), width: 22, height: 12, rx: 3,
|
|
149
|
+
class: %w[asd-port asd-stroke-blue-0])
|
|
150
|
+
m.to_s
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# A dashed/dotted edge line, explained by a top-level `line "dashed" { label "..." }`.
|
|
155
|
+
class LineRow < Row
|
|
156
|
+
def initialize(label, line_style:)
|
|
157
|
+
super(label)
|
|
158
|
+
@line_style = line_style
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def id_key = "line-#{@line_style}"
|
|
162
|
+
|
|
163
|
+
def icon(cx, cy, id:)
|
|
164
|
+
legend_line_sample(cx, cy, css_class: ["asd-relation-dependency", "asd-stroke-thin", "asd-line-#{@line_style}"],
|
|
165
|
+
marker_id: Renderer::MarkerDefs.marker_id("dependency"), id: "#{id}__icon")
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# A badge dot (`badge "id" { tint; label }`).
|
|
170
|
+
class BadgeRow < Row
|
|
171
|
+
def initialize(label, tint:, badge:)
|
|
172
|
+
super(label)
|
|
173
|
+
@tint = tint
|
|
174
|
+
@badge = badge
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def id_key = "badge-#{Renderer::ElementIds.slug(@badge)}"
|
|
178
|
+
|
|
179
|
+
def icon(cx, cy, id:)
|
|
180
|
+
m = Renderer::Markup.new
|
|
181
|
+
m.element("circle", id: "#{id}__icon", cx: SvgFormat.fmt(cx), cy: SvgFormat.fmt(cy), r: 4, class: "asd-badge-#{@tint}")
|
|
182
|
+
m.to_s
|
|
183
|
+
end
|
|
184
|
+
end
|
|
141
185
|
end
|
|
142
186
|
end
|
|
143
187
|
end
|
|
@@ -51,6 +51,15 @@ module Archsight
|
|
|
51
51
|
# A top-level diagram-wide `key "value"` setting -- currently only
|
|
52
52
|
# `theme "compact"` (see `Theme`).
|
|
53
53
|
Setting = Struct.new(:key, :value, :line, keyword_init: true)
|
|
54
|
+
|
|
55
|
+
# `port "id" { label "..."; side "top"; at "left"; badge "..." }` inside a leaf: a labelled tab on
|
|
56
|
+
# the leaf's border that edges attach to (`a -> leaf.id`). Its id is local to the leaf.
|
|
57
|
+
Port = Struct.new(:id, :attrs, :line, keyword_init: true)
|
|
58
|
+
|
|
59
|
+
# A top-level legend definition: `badge "id" { tint "orange"; label "..." }` (a dot nodes and
|
|
60
|
+
# ports carry with `badge "id"`) or `line "dashed" { label "..." }` (the legend text of edges
|
|
61
|
+
# drawn with `line "dashed"`). `kind` is :badge or :line.
|
|
62
|
+
Definition = Struct.new(:kind, :id, :attrs, :line, keyword_init: true)
|
|
54
63
|
end
|
|
55
64
|
end
|
|
56
65
|
end
|
|
@@ -14,12 +14,15 @@ module Archsight
|
|
|
14
14
|
#
|
|
15
15
|
# Grammar (informal):
|
|
16
16
|
# program := statement*
|
|
17
|
-
# statement := block | dataflow | edge | setting | include
|
|
17
|
+
# statement := block | dataflow | edge | setting | include | definition
|
|
18
|
+
# definition := ("badge" | "line") STRING "{" attr* "}" -- top level only
|
|
18
19
|
# include := "include" STRING ["{" "namespace" STRING "}"] [";"]
|
|
19
20
|
# -- top level, or where a container may hold blocks and edges
|
|
20
21
|
# setting := ("theme" | "legend" | "ranks") STRING [";"] -- top level only
|
|
21
|
-
# block := (CONTAINER_KEYWORD | LEAF_KEYWORD) [STRING] "{" (attr | block | edge | include)* "}"
|
|
22
|
-
# -- the id is required except for ANONYMOUS_KEYWORDS
|
|
22
|
+
# block := (CONTAINER_KEYWORD | LEAF_KEYWORD) [STRING] "{" (attr | block | edge | include | port)* "}"
|
|
23
|
+
# -- the id is required except for ANONYMOUS_KEYWORDS; a leaf holds
|
|
24
|
+
# only attrs and ports, a container no ports
|
|
25
|
+
# port := "port" STRING "{" attr* "}"
|
|
23
26
|
# dataflow := "dataflow" STRING "{" (hop | hop_group | attr)* "}"
|
|
24
27
|
# -- needs >= 2 hops (per branch, if a hop_group is present);
|
|
25
28
|
# at most one hop_group per dataflow
|
|
@@ -50,6 +53,7 @@ module Archsight
|
|
|
50
53
|
NAMESPACE = /\A[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*\z/
|
|
51
54
|
ANONYMOUS_KEYWORDS = %w[layer stack].freeze
|
|
52
55
|
SETTING_KEYWORDS = %w[theme legend ranks].freeze
|
|
56
|
+
DEFINITION_KEYWORDS = %w[badge line].freeze
|
|
53
57
|
EDGE_ARROWS = {
|
|
54
58
|
arrow: :directed,
|
|
55
59
|
biarrow: :bidirectional,
|
|
@@ -89,6 +93,8 @@ module Archsight
|
|
|
89
93
|
edge
|
|
90
94
|
elsif SETTING_KEYWORDS.any? { |k| cursor.check(:ident, k) } && cursor.peek_type(1) == :string
|
|
91
95
|
setting
|
|
96
|
+
elsif definition?
|
|
97
|
+
definition
|
|
92
98
|
else
|
|
93
99
|
t = cursor.current
|
|
94
100
|
raise ParseError, "expected #{BLOCK_KEYWORDS.map(&:inspect).join(", ")}, 'dataflow', or an edge " \
|
|
@@ -123,10 +129,14 @@ module Archsight
|
|
|
123
129
|
|
|
124
130
|
cursor.expect(:rbrace, "expected '}' to close #{label}")
|
|
125
131
|
|
|
126
|
-
|
|
132
|
+
leaf = LEAF_KEYWORDS.include?(kind_token.value)
|
|
133
|
+
if leaf && children.any? { |c| !c.is_a?(AST::Port) }
|
|
127
134
|
raise ParseError, "#{label} at line #{kind_token.line} cannot " \
|
|
128
135
|
"contain nested blocks, edges or includes (did you mean 'group'?)"
|
|
129
136
|
end
|
|
137
|
+
if !leaf && (port = children.find { |c| c.is_a?(AST::Port) })
|
|
138
|
+
raise ParseError, "port #{port.id.inspect} at line #{port.line}: only a leaf (component, database, ...) has ports, not #{label}"
|
|
139
|
+
end
|
|
130
140
|
|
|
131
141
|
raise ParseError, "#{label} at line #{kind_token.line}: columns only applies to containers" if LEAF_KEYWORDS.include?(kind_token.value) && attrs.key?("columns")
|
|
132
142
|
|
|
@@ -135,10 +145,12 @@ module Archsight
|
|
|
135
145
|
AST::Block.new(kind: kind, id: id, anonymous: anonymous, attrs: attrs, children: children, line: kind_token.line)
|
|
136
146
|
end
|
|
137
147
|
|
|
138
|
-
# The nested block, edge or
|
|
148
|
+
# The nested block, edge, include or port at the cursor, nil if it is something else (an attribute)
|
|
139
149
|
def container_child
|
|
140
150
|
if check_block_keyword?
|
|
141
151
|
block
|
|
152
|
+
elsif keyword_block?("port")
|
|
153
|
+
port
|
|
142
154
|
elsif include_directive?
|
|
143
155
|
include_statement
|
|
144
156
|
elsif cursor.check(:ident) && EDGE_ARROWS.key?(cursor.peek_type(1))
|
|
@@ -185,6 +197,45 @@ module Archsight
|
|
|
185
197
|
AST::Setting.new(key: key_token.value, value: value_token.value, line: key_token.line)
|
|
186
198
|
end
|
|
187
199
|
|
|
200
|
+
# `port "id" { ... }` -- `port "x"` without a block stays an (unknown) attribute, so it is reported as one
|
|
201
|
+
def port
|
|
202
|
+
keyword = cursor.advance
|
|
203
|
+
id = cursor.advance
|
|
204
|
+
label = "port #{id.value.inspect}"
|
|
205
|
+
raise ParseError, "port at line #{keyword.line} has an empty id" if id.value.strip.empty?
|
|
206
|
+
raise ParseError, "#{label} at line #{keyword.line}: a port id cannot contain '.'" if id.value.include?(".")
|
|
207
|
+
|
|
208
|
+
attrs = read_attr_block(label)
|
|
209
|
+
AST::Port.new(id: id.value, attrs: attrs, line: keyword.line)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def definition?
|
|
213
|
+
DEFINITION_KEYWORDS.any? { |k| keyword_block?(k) }
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# `badge "id" { ... }` / `line "dashed" { ... }` at the top level
|
|
217
|
+
def definition
|
|
218
|
+
keyword = cursor.advance
|
|
219
|
+
id = cursor.advance
|
|
220
|
+
attrs = read_attr_block("#{keyword.value} #{id.value.inspect}")
|
|
221
|
+
AST::Definition.new(kind: keyword.value.to_sym, id: id.value, attrs: attrs, line: keyword.line)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# `KEYWORD STRING {` -- the brace tells it apart from an attribute (`badge "x"`) or an edge (`line -> x`)
|
|
225
|
+
def keyword_block?(keyword)
|
|
226
|
+
cursor.check(:ident, keyword) && cursor.peek_type(1) == :string && cursor.peek_type(2) == :lbrace
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# `{ attr* }`, read into a fresh hash
|
|
230
|
+
def read_attr_block(label)
|
|
231
|
+
cursor.expect(:lbrace, "expected '{' to open #{label}")
|
|
232
|
+
attrs = {}
|
|
233
|
+
parse_attrs_until_rbrace(attrs, label, expected: "an attribute") { false }
|
|
234
|
+
cursor.expect(:rbrace, "expected '}' to close #{label}")
|
|
235
|
+
cursor.consume(:semi)
|
|
236
|
+
attrs
|
|
237
|
+
end
|
|
238
|
+
|
|
188
239
|
def next_anonymous_id
|
|
189
240
|
@anon_counter += 1
|
|
190
241
|
"__asd_anon_#{@anon_scope}#{@anon_counter}"
|
|
@@ -46,7 +46,8 @@ module Archsight
|
|
|
46
46
|
css_class: "asd-dataflow-line", id: @ids.part(df, "line"))
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
pt = @label_placer.place_label_along(points, df.label, font_size: @theme.edge_label_font_size
|
|
49
|
+
pt = @label_placer.place_label_along(points, df.label, font_size: @theme.edge_label_font_size,
|
|
50
|
+
arrow_end: MarkerDefs::DATAFLOW_MARKER_SIZE.to_f)
|
|
50
51
|
return unless pt
|
|
51
52
|
|
|
52
53
|
body.raw(@text_renderer.halo_text(pt[0], pt[1] - 6, df.label, font_size: @theme.edge_label_font_size,
|
|
@@ -29,11 +29,14 @@ module Archsight
|
|
|
29
29
|
@path_renderer.draw_relation_path(body, points, edge.relation,
|
|
30
30
|
marker_end: edge.direction != :undirected,
|
|
31
31
|
marker_start: edge.direction == :bidirectional,
|
|
32
|
-
curve: curve, color: color, id: @ids.part(edge, "line"))
|
|
32
|
+
curve: curve, color: color, id: @ids.part(edge, "line"), line_style: edge.line_style)
|
|
33
33
|
@path_renderer.draw_hit_path(body, points, curve: curve, id: @ids.part(edge, "hit"))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
arrow = MarkerDefs::MARKER_SIZE * EDGE_STROKE_WIDTH
|
|
37
|
+
pt = @label_placer.place_label_along(points, edge.label, font_size: @theme.edge_label_font_size,
|
|
38
|
+
arrow_start: edge.direction == :bidirectional ? arrow : 0.0,
|
|
39
|
+
arrow_end: edge.direction == :undirected ? 0.0 : arrow)
|
|
37
40
|
return unless pt
|
|
38
41
|
|
|
39
42
|
body.raw(@text_renderer.halo_text(pt[0], pt[1] - 6, edge.label, font_size: @theme.edge_label_font_size,
|
|
@@ -28,10 +28,23 @@ module Archsight
|
|
|
28
28
|
# or beside some other line.
|
|
29
29
|
LABEL_FRACTION_CANDIDATES = [0.35, 0.65, 0.5, 0.25, 0.75, 0.15, 0.85].freeze
|
|
30
30
|
|
|
31
|
-
# Below this total path length, biasing toward source/target
|
|
32
|
-
# landing the label on (or past) the node it's leaving/entering,
|
|
33
|
-
# only the
|
|
31
|
+
# Below this total path length, biasing far toward source/target
|
|
32
|
+
# risks landing the label on (or past) the node it's leaving/entering,
|
|
33
|
+
# so the midpoint comes first and only the moderate shifts follow --
|
|
34
|
+
# needed when the midpoint crowds an arrowhead (a short line's label
|
|
35
|
+
# box, which sits above its anchor, reaches the tip of an upward arrow).
|
|
34
36
|
MIN_LENGTH_FOR_LABEL_BIAS = 80.0
|
|
37
|
+
SHORT_LABEL_FRACTION_CANDIDATES = [0.5, 0.35, 0.65, 0.25, 0.75].freeze
|
|
38
|
+
|
|
39
|
+
# A label on its own line's arrowhead hides where the arrow points:
|
|
40
|
+
# as costly as covering a node. The arrowhead's box is grown by
|
|
41
|
+
# `ARROWHEAD_CLEARANCE` so the text's halo doesn't eat into the tip either.
|
|
42
|
+
ARROWHEAD_PENALTY = 1.0
|
|
43
|
+
ARROWHEAD_CLEARANCE = 2.0
|
|
44
|
+
# When no fixed position is clear, spots every `ARROWHEAD_SEARCH_STEP`
|
|
45
|
+
# px behind each arrowhead are tried, up to `ARROWHEAD_SEARCH_RANGE` px.
|
|
46
|
+
ARROWHEAD_SEARCH_STEP = 2.0
|
|
47
|
+
ARROWHEAD_SEARCH_RANGE = 120.0
|
|
35
48
|
|
|
36
49
|
# Same flat char-width heuristic style as `Layout::EDGE_LABEL_CHAR_WIDTH`,
|
|
37
50
|
# used here for a cheap label bounding-box estimate rather than real
|
|
@@ -127,29 +140,24 @@ module Archsight
|
|
|
127
140
|
# position along `points` with no overlaps, falling back to whichever
|
|
128
141
|
# candidate overlaps the least -- a label is always placed somewhere,
|
|
129
142
|
# never skipped, matching the previous fixed-midpoint behavior.
|
|
130
|
-
|
|
143
|
+
# `arrow_start`/`arrow_end` are the lengths of the arrowheads drawn at
|
|
144
|
+
# the line's ends (0 for none), which the label keeps clear of.
|
|
145
|
+
def place_label_along(points, label, font_size: 11, arrow_start: 0.0, arrow_end: 0.0)
|
|
131
146
|
return unless label
|
|
132
147
|
|
|
133
148
|
total = Geometry.path_length(points)
|
|
134
|
-
fractions = total < MIN_LENGTH_FOR_LABEL_BIAS ?
|
|
149
|
+
fractions = total < MIN_LENGTH_FOR_LABEL_BIAS ? SHORT_LABEL_FRACTION_CANDIDATES : LABEL_FRACTION_CANDIDATES
|
|
150
|
+
arrowheads = [arrowhead_rect(points[1], points[0], arrow_start), arrowhead_rect(points[-2], points[-1], arrow_end)].compact
|
|
135
151
|
|
|
136
|
-
candidates = fractions.map
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
candidates.each_with_index do |(pt, box), i|
|
|
146
|
-
score = (native_scores ? native_scores[i] : label_overlap_score(box)) + border_score(box) + path_scores[i] +
|
|
147
|
-
bend_score(box, points)
|
|
148
|
-
if score < best_score
|
|
149
|
-
best = pt
|
|
150
|
-
best_score = score
|
|
151
|
-
end
|
|
152
|
-
break if score.zero?
|
|
152
|
+
candidates = fractions.map { |f| candidate(Geometry.point_along(points, f), label, font_size) }
|
|
153
|
+
best, best_score = best_candidate(candidates, points, arrowheads)
|
|
154
|
+
if best_score.positive? && arrowheads.any?
|
|
155
|
+
# Every fixed position crowds something: try the spots right
|
|
156
|
+
# behind each arrowhead too (a short line has its room there).
|
|
157
|
+
ends = [(0.0 if arrow_start.positive?), (1.0 if arrow_end.positive?)].compact
|
|
158
|
+
clear = behind_arrowheads(points, total, ends, label, font_size)
|
|
159
|
+
extra, extra_score = best_candidate(clear, points, arrowheads) unless clear.empty?
|
|
160
|
+
best = extra if extra && extra_score < best_score
|
|
153
161
|
end
|
|
154
162
|
|
|
155
163
|
placed = LabelPlacer.label_bbox(best[0], best[1] - 6, label, font_size)
|
|
@@ -187,6 +195,74 @@ module Archsight
|
|
|
187
195
|
touched * CONTAINER_BORDER_PENALTY
|
|
188
196
|
end
|
|
189
197
|
|
|
198
|
+
# A candidate anchor `pt` with the box its label would take there.
|
|
199
|
+
def candidate(pt, label, font_size)
|
|
200
|
+
[pt, LabelPlacer.label_bbox(pt[0], pt[1] - 6, label, font_size)]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# The first (in order) of `candidates` that overlaps nothing, or the
|
|
204
|
+
# one that overlaps least, with its score.
|
|
205
|
+
def best_candidate(candidates, points, arrowheads)
|
|
206
|
+
boxes = candidates.map(&:last)
|
|
207
|
+
native_scores = native_overlap_scores(boxes)
|
|
208
|
+
path_scores = path_scores(boxes, points)
|
|
209
|
+
|
|
210
|
+
best = nil
|
|
211
|
+
best_score = Float::INFINITY
|
|
212
|
+
candidates.each_with_index do |(pt, box), i|
|
|
213
|
+
score = (native_scores ? native_scores[i] : label_overlap_score(box)) + border_score(box) + path_scores[i] +
|
|
214
|
+
bend_score(box, points) + arrowhead_score(box, arrowheads)
|
|
215
|
+
if score < best_score
|
|
216
|
+
best = pt
|
|
217
|
+
best_score = score
|
|
218
|
+
end
|
|
219
|
+
break if score.zero?
|
|
220
|
+
end
|
|
221
|
+
[best, best_score]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Spots stepping back from each end with an arrowhead (`ends`: 0.0
|
|
225
|
+
# start, 1.0 end), nearest first, up to `ARROWHEAD_SEARCH_RANGE` --
|
|
226
|
+
# scored like any candidate, so the first one clear of the arrowhead,
|
|
227
|
+
# the nodes and the other labels wins.
|
|
228
|
+
def behind_arrowheads(points, total, ends, label, font_size)
|
|
229
|
+
return [] unless total.positive?
|
|
230
|
+
|
|
231
|
+
range = [total, ARROWHEAD_SEARCH_RANGE].min
|
|
232
|
+
(0..(range / ARROWHEAD_SEARCH_STEP).floor).flat_map do |step|
|
|
233
|
+
ends.map do |end_fraction|
|
|
234
|
+
f = (end_fraction - (step * ARROWHEAD_SEARCH_STEP / total)).abs
|
|
235
|
+
candidate(Geometry.point_along(points, f), label, font_size)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# The box around an arrowhead of `length` whose tip is `tip`, pointing
|
|
241
|
+
# away from `from` (the neighbouring point of the line), or nil for none.
|
|
242
|
+
def arrowhead_rect(from, tip, length)
|
|
243
|
+
return nil unless length.positive? && from && tip
|
|
244
|
+
|
|
245
|
+
dx = tip[0] - from[0]
|
|
246
|
+
dy = tip[1] - from[1]
|
|
247
|
+
norm = Math.hypot(dx, dy)
|
|
248
|
+
return nil if norm.zero?
|
|
249
|
+
|
|
250
|
+
ux = dx / norm
|
|
251
|
+
uy = dy / norm
|
|
252
|
+
base_x = tip[0] - (ux * length)
|
|
253
|
+
base_y = tip[1] - (uy * length)
|
|
254
|
+
half = length / 2.0
|
|
255
|
+
xs = [tip[0], base_x + (uy * half), base_x - (uy * half)]
|
|
256
|
+
ys = [tip[1], base_y - (ux * half), base_y + (ux * half)]
|
|
257
|
+
c = ARROWHEAD_CLEARANCE
|
|
258
|
+
{ left: xs.min - c, right: xs.max + c, top: ys.min - c, bottom: ys.max + c }
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# See `ARROWHEAD_PENALTY`.
|
|
262
|
+
def arrowhead_score(box, arrowheads)
|
|
263
|
+
arrowheads.count { |head| LabelPlacer.rects_intersect?(box, head) } * ARROWHEAD_PENALTY
|
|
264
|
+
end
|
|
265
|
+
|
|
190
266
|
# See `OWN_BEND_PENALTY`.
|
|
191
267
|
def bend_score(box, points)
|
|
192
268
|
return 0 if points.length < 3
|
|
@@ -15,8 +15,12 @@ module Archsight
|
|
|
15
15
|
# `Stylesheet#edge_hover_css`), so its hover target -- a leaf's own
|
|
16
16
|
# `<g>`, a container's frame -- and its label are marked for the
|
|
17
17
|
# stylesheet's dim-everything-else rule.
|
|
18
|
-
|
|
18
|
+
# `ports` are the port tabs (`Layout::Result#ports`), `graph` names the badges' tints.
|
|
19
|
+
def initialize(boxes, text_renderer, ids:, theme:, hover_sources: Set.new, ports: {}, graph: nil)
|
|
19
20
|
@boxes = boxes
|
|
21
|
+
@ports = ports
|
|
22
|
+
@graph = graph
|
|
23
|
+
@port_metrics = Layout::PortMetrics.new(theme)
|
|
20
24
|
@text_renderer = text_renderer
|
|
21
25
|
@ids = ids
|
|
22
26
|
@hover_sources = hover_sources
|
|
@@ -47,6 +51,9 @@ module Archsight
|
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
HOVER_SOURCE_CLASS = "asd-hover-source"
|
|
54
|
+
# How far a node's badge dot sits from its top-right corner, and its radius.
|
|
55
|
+
BADGE_INSET = 9.0
|
|
56
|
+
BADGE_RADIUS = 4.0
|
|
50
57
|
# A node whose `resource` reference didn't resolve (see `ResourceLinks`)
|
|
51
58
|
BROKEN_LINK_CLASS = "asd-broken-link"
|
|
52
59
|
|
|
@@ -104,6 +111,47 @@ module Archsight
|
|
|
104
111
|
body.raw(@text_renderer.label_text(representer.label_x(box), representer.label_y(box, @theme), node.label,
|
|
105
112
|
font_size: representer.label_font_size(@theme), link: node.link,
|
|
106
113
|
attrs: @ids.label_attrs(node), extra_class: label_class(node)))
|
|
114
|
+
badge_dot(body, box.right - BADGE_INSET, box.top + BADGE_INSET, node.badge, id: @ids.part(node, "badge")) if node.badge
|
|
115
|
+
render_ports(body, node, style[:stroke_class])
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Each port as a small white tab straddling the border, its label in monospace, its badge at its right end.
|
|
119
|
+
def render_ports(body, node, stroke_class)
|
|
120
|
+
node.ports.each do |port|
|
|
121
|
+
tab = @ports[port.ref]
|
|
122
|
+
next unless tab
|
|
123
|
+
|
|
124
|
+
name = "port-#{port.id.gsub(/[^A-Za-z0-9_-]/, "_")}"
|
|
125
|
+
if port.broken_link
|
|
126
|
+
body.element("g", class: BROKEN_LINK_CLASS) do
|
|
127
|
+
body.raw(Markup.tag("title", escape(port.broken_link)))
|
|
128
|
+
render_port(body, node, port, tab, name, stroke_class)
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
render_port(body, node, port, tab, name, stroke_class)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# The tab, its label and badge; a `link` (or resolved `resource`) wraps the tab and the label.
|
|
137
|
+
def render_port(body, node, port, tab, name, stroke_class)
|
|
138
|
+
rect = Markup.new
|
|
139
|
+
rect.element("rect", id: @ids.part(node, name), x: fmt(tab.left), y: fmt(tab.top), width: fmt(tab.width), height: fmt(tab.height),
|
|
140
|
+
rx: 4, class: ["asd-port", stroke_class], "data-asd-port": port.id)
|
|
141
|
+
body.raw(@text_renderer.wrap_link(rect.to_s, port.link))
|
|
142
|
+
room = port.badge ? Layout::PortMetrics::BADGE_ROOM : 0.0
|
|
143
|
+
body.raw(@text_renderer.label_text(tab.x - (room / 2.0), tab.y, port.label, font_size: @port_metrics.font_size, link: port.link,
|
|
144
|
+
attrs: { id: @ids.part(node, "#{name}-label"), "data-asd-owner": @ids.id(node), "data-asd-line": port.line },
|
|
145
|
+
extra_class: "asd-port-text asd-run-code"))
|
|
146
|
+
badge_dot(body, tab.right - Layout::PortMetrics::PADDING_X - 1.0, tab.y, port.badge, id: @ids.part(node, "#{name}-badge")) if port.badge
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def badge_dot(body, cx, cy, badge, id:)
|
|
150
|
+
definition = @graph&.badge_definition(badge)
|
|
151
|
+
tint = definition ? definition.tint : "gray"
|
|
152
|
+
body.element("circle", id: id, cx: fmt(cx), cy: fmt(cy), r: fmt(BADGE_RADIUS), class: "asd-badge-#{tint}") do
|
|
153
|
+
body.raw(Markup.tag("title", escape(definition.label))) if definition
|
|
154
|
+
end
|
|
107
155
|
end
|
|
108
156
|
|
|
109
157
|
# A `text` has no shape for the broken-link styling to dash, so its label is dimmed and dashed itself.
|
|
@@ -18,13 +18,13 @@ module Archsight
|
|
|
18
18
|
# replaces the default `asd-stroke-thin` width when the caller
|
|
19
19
|
# needs its own (only a dataflow's thicker, hover-animated line does).
|
|
20
20
|
def draw_relation_path(body, points, relation, marker_end: false, marker_start: false, color: nil, curve: false,
|
|
21
|
-
css_class: nil, id: nil)
|
|
21
|
+
css_class: nil, id: nil, line_style: "solid")
|
|
22
22
|
path_d = PathGeometry.path_d_string(points, curve: curve)
|
|
23
23
|
marker_id = "url(##{MarkerDefs.marker_id(relation, color: color)})"
|
|
24
24
|
|
|
25
25
|
body.element("path", id: id, d: path_d,
|
|
26
26
|
class: ["asd-line", "asd-relation-#{relation}", css_class || "asd-stroke-thin",
|
|
27
|
-
(MarkerDefs.color_class(color) if color)],
|
|
27
|
+
(MarkerDefs.color_class(color) if color), ("asd-line-#{line_style}" unless line_style == "solid")],
|
|
28
28
|
"marker-end": (marker_id if marker_end),
|
|
29
29
|
"marker-start": (marker_id if marker_start))
|
|
30
30
|
end
|
|
@@ -55,7 +55,7 @@ module Archsight
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def style_block
|
|
58
|
-
css = [text_css, line_css, relation_css, shape_css, tint_css, legend_css, line_color_css].join("\n")
|
|
58
|
+
css = [text_css, line_css, relation_css, shape_css, tint_css, port_css, legend_css, line_color_css].join("\n")
|
|
59
59
|
wrap(css)
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -233,6 +233,7 @@ module Archsight
|
|
|
233
233
|
.asd-underline { text-decoration: underline; }
|
|
234
234
|
.asd-run-bold { font-weight: bold; }
|
|
235
235
|
.asd-run-italic { font-style: italic; }
|
|
236
|
+
.asd-run-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace; }
|
|
236
237
|
.asd-run-underline { text-decoration: underline; }
|
|
237
238
|
.asd-broken-text { opacity: 0.6; text-decoration: underline dashed; }
|
|
238
239
|
.asd-text-hit { fill: transparent; stroke: none; }
|
|
@@ -244,6 +245,8 @@ module Archsight
|
|
|
244
245
|
.asd-line { fill: none; }
|
|
245
246
|
.asd-stroke-thin { stroke-width: #{EDGE_STROKE_WIDTH}; }
|
|
246
247
|
.asd-stroke-application { stroke-width: 2.5; }
|
|
248
|
+
.asd-line.asd-line-dashed { stroke-dasharray: 6 4; }
|
|
249
|
+
.asd-line.asd-line-dotted { stroke-dasharray: 1.5 3; stroke-linecap: round; }
|
|
247
250
|
.asd-dataflow-line { stroke-width: #{DATAFLOW_STROKE_WIDTH}; transition: stroke-width 0.15s ease; }
|
|
248
251
|
.asd-dataflow-halo { fill: none; stroke: #fff; stroke-width: #{DataflowRenderer::DATAFLOW_HALO_WIDTH}; stroke-linecap: round; }
|
|
249
252
|
CSS
|
|
@@ -294,6 +297,12 @@ module Archsight
|
|
|
294
297
|
end.join("\n")
|
|
295
298
|
end
|
|
296
299
|
|
|
300
|
+
# Port tabs (see `NodeRenderer#render_ports`) and badge dots, one fill rule per tint.
|
|
301
|
+
def port_css
|
|
302
|
+
badges = Tints.names.map { |name| ".asd-badge-#{name} { fill: #{Tints.for(name).border(0)}; }" }
|
|
303
|
+
[".asd-port { fill: #fff; stroke-width: 1.1; }", *badges].join("\n")
|
|
304
|
+
end
|
|
305
|
+
|
|
297
306
|
def legend_css
|
|
298
307
|
<<~CSS.chomp
|
|
299
308
|
.asd-legend-bg { fill: #fafbfc; stroke-width: 1; }
|
|
@@ -123,6 +123,7 @@ module Archsight
|
|
|
123
123
|
classes << "asd-run-bold" if style[:bold]
|
|
124
124
|
classes << "asd-run-italic" if style[:italic]
|
|
125
125
|
classes << "asd-run-underline" if style[:underline] || style[:link]
|
|
126
|
+
classes << "asd-run-code" if style[:code]
|
|
126
127
|
|
|
127
128
|
span = Markup.tag("tspan", escape(content), class: classes)
|
|
128
129
|
return span if style[:link].nil? || suppress_inline_links
|
|
@@ -74,16 +74,20 @@ module Archsight
|
|
|
74
74
|
# The legend's frame is as solid as a node box, as far as a label is
|
|
75
75
|
# concerned.
|
|
76
76
|
legend_boxes = @layout.legend ? @boxes.slice(@layout.legend.frame.id) : {}
|
|
77
|
-
|
|
77
|
+
ports = layout.ports || {}
|
|
78
|
+
port_boxes = ports.transform_keys { |ref| "port:#{ref}" }
|
|
79
|
+
@label_placer = LabelPlacer.new(@boxes.slice(*nodes.select(&:leaf?).map(&:id)).merge(legend_boxes, port_boxes, title_boxes(nodes, theme)),
|
|
78
80
|
containers: @boxes.slice(*nodes.reject { |n| n.leaf? || n.anonymous? }.map(&:id)))
|
|
79
81
|
@node_renderer = NodeRenderer.new(@boxes, @text_renderer, ids: @ids, theme: theme,
|
|
80
|
-
hover_sources: drawn_edges.to_set { |e| e.from.id }
|
|
82
|
+
hover_sources: drawn_edges.to_set { |e| e.from.id },
|
|
83
|
+
ports: ports, graph: @graph)
|
|
81
84
|
@implements_tree_renderer = ImplementsTreeRenderer.new(@boxes, path_renderer: @path_renderer, text_renderer: @text_renderer,
|
|
82
85
|
ids: @ids, theme: theme)
|
|
83
86
|
# Both routing stages avoid the same boxes, so they share one map
|
|
84
87
|
# (and, with the native kernels, one packed box table).
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
# Port tabs are obstacles too, so other lines don't end on top of one.
|
|
89
|
+
obstacle_map = ObstacleMap.new(@boxes.merge(port_boxes), ignoring: nodes.select { |n| n.anonymous? && !n.leaf? }.map(&:id))
|
|
90
|
+
@edge_routing = EdgeRouting.new(@graph, @boxes, obstacle_map: obstacle_map, ports: ports)
|
|
87
91
|
@edge_renderer = EdgeRenderer.new(path_renderer: @path_renderer, text_renderer: @text_renderer, label_placer: @label_placer,
|
|
88
92
|
ids: @ids, theme: theme)
|
|
89
93
|
@dataflow_routing = DataflowRouting.new(@graph, @boxes, obstacle_map: obstacle_map)
|
|
@@ -230,7 +234,7 @@ module Archsight
|
|
|
230
234
|
# default `hash`/`==`.
|
|
231
235
|
@implements_tree_groups ||=
|
|
232
236
|
drawn_edges
|
|
233
|
-
.select { |e| e.relation_type.tree_grouped? && e.direction == :directed && !e.attrs.key?("style") && e.tint.nil? }
|
|
237
|
+
.select { |e| e.relation_type.tree_grouped? && e.direction == :directed && !e.attrs.key?("style") && e.tint.nil? && !e.attrs.key?("line") && !e.to_port && !e.from_port }
|
|
234
238
|
.group_by { |e| e.to.id }
|
|
235
239
|
.filter_map { |_id, edges| [edges.first.to, edges] if edges.length > 1 }
|
|
236
240
|
end
|
|
@@ -246,6 +250,18 @@ module Archsight
|
|
|
246
250
|
@tree_grouped_edges ||= implements_tree_groups.flat_map { |_target, edges| edges }
|
|
247
251
|
end
|
|
248
252
|
|
|
253
|
+
# Where each named container's title is written (see `NodeRenderer#render_container`), so edge labels
|
|
254
|
+
# keep off it like off a node.
|
|
255
|
+
def title_boxes(nodes, theme)
|
|
256
|
+
nodes.select { |n| n.container? && !n.anonymous? && @boxes[n.id] }.to_h do |n|
|
|
257
|
+
box = @boxes[n.id]
|
|
258
|
+
size = n.boundary? ? theme.boundary_title_font_size : theme.group_title_font_size
|
|
259
|
+
width = TextMetrics.rendered_width(MarkdownText.new("**#{n.label}**"), font_size: size)
|
|
260
|
+
height = n.layout_title_height(theme)
|
|
261
|
+
["title:#{n.id}", Layout::Box.new(box.left + theme.title_inset_x + (width / 2.0), box.top + (height / 2.0), width, height)]
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
249
265
|
# --- edges -------------------------------------------------------------
|
|
250
266
|
|
|
251
267
|
def individually_routed_edges
|