elkrb 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8699f197aff817a1de6a193b1fb421d59e5df023ed0bbb39f7cfa75cedefcf82
4
- data.tar.gz: cfa580618758f94d81542c86cf4bb87014375057c3271ee00031b962f2faa598
3
+ metadata.gz: 56dca5568676af3dcdaf9f5a4fe3675fcd6710e408d3a93f788f7fe412949655
4
+ data.tar.gz: 8b996680adf2fd9b516f3a96a7997f431869193a63d7b227293ed9de0c61176b
5
5
  SHA512:
6
- metadata.gz: 19b997af148da717eae04d0c30274276a654999f8d3bac9254bf3e7098f9f0fedfaba00744961e734f54f8dfa0db009620be9c3cd7d7891b5886400af1c4ee6c
7
- data.tar.gz: c7ec92a9b09af0c7797fac7c567b869a0fe0faeacdcae1ad5d7c2312c0051c5f91272f22beba34789b0856ac3bb656c3ceeb10eebd08831855de9e0fb90e113f
6
+ metadata.gz: 7e8cb2d796c37c92ce9703b4c1a0dc3b004006923718b6c2ee765ce64f28f72d061f29a1dfbb2b37fae9d94fd40a43b478b40a85267753e60081422ba2d975ba
7
+ data.tar.gz: c43ffbc85dcd2bc83d45147594e8b7f60dd7222196a5f062154c5bab94ebe1759110598c9bb2839447c7345d0de147c0caa3f1ac21194ff053d657b8cbba2e29
data/CHANGELOG.adoc CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to Elkrb are recorded here.
4
4
 
5
+ == 2.0.1 (2026-11-02)
6
+
7
+ * The layered algorithm honours `elk.alignment` on a node: LEFT or RIGHT in a
8
+ horizontal layout, TOP or BOTTOM in a vertical one, and CENTER, place the
9
+ node at that side of its layer instead of centring it. The default,
10
+ AUTOMATIC, is unchanged.
11
+
5
12
  == 2.0.0 (2026-10-10)
6
13
 
7
14
  === Breaking changes
data/README.adoc CHANGED
@@ -1086,7 +1086,7 @@ file fails.
1086
1086
  [source,sh]
1087
1087
  ----
1088
1088
  $ elkrb version
1089
- elkrb version 2.0.0
1089
+ elkrb version 2.0.1
1090
1090
  ----
1091
1091
 
1092
1092
  == Benchmarking
@@ -18,7 +18,24 @@ module Elkrb
18
18
  # Gap between a long edge and a node, or another long edge, beside it.
19
19
  EDGE_SPACING = 10.0
20
20
 
21
+ # Where `elk.alignment` puts a node across its layer, as the share
22
+ # of the free room before it, in the unmirrored layout. Named by
23
+ # the side of the picture: LEFT and RIGHT mean the start and end of
24
+ # a RIGHT layer, TOP and BOTTOM those of a DOWN layer. A side across
25
+ # the layers, and AUTOMATIC, leave the node to its ports.
26
+ ALIGNMENT_RATIOS = {
27
+ "CENTER" => 0.5,
28
+ "LEFT" => 0.0, "RIGHT" => 1.0,
29
+ "TOP" => 0.0, "BOTTOM" => 1.0
30
+ }.freeze
31
+ LAYER_SIDES = {
32
+ horizontal: %w[LEFT RIGHT CENTER],
33
+ vertical: %w[TOP BOTTOM CENTER],
34
+ }.freeze
35
+
21
36
  attr_writer :index, :port_order, :orthogonal
37
+ # @return [#call] the `elk.alignment` of a node, given the node
38
+ attr_writer :alignment_of
22
39
 
23
40
  # @param layer_spacing [Numeric] gap between consecutive layers
24
41
  # @param node_spacing [Numeric] gap between nodes in one layer
@@ -96,6 +113,26 @@ module Elkrb
96
113
  end
97
114
 
98
115
  def alignment_ratio(node)
116
+ explicit_ratio(node) || port_ratio(node)
117
+ end
118
+
119
+ def explicit_ratio(node)
120
+ alignment = @alignment_of&.call(node).to_s
121
+ return unless layer_sides.include?(alignment)
122
+
123
+ ratio = ALIGNMENT_RATIOS.fetch(alignment)
124
+ mirrored? ? 1.0 - ratio : ratio
125
+ end
126
+
127
+ def layer_sides
128
+ LAYER_SIDES.fetch(horizontal? ? :horizontal : :vertical)
129
+ end
130
+
131
+ def mirrored?
132
+ %w[LEFT UP].include?(@direction)
133
+ end
134
+
135
+ def port_ratio(node)
99
136
  outgoing = port_order.visual(node.id, :east).size
100
137
  incoming = port_order.visual(node.id, :west).size
101
138
  total = outgoing + incoming
@@ -216,7 +253,7 @@ module Elkrb
216
253
  end
217
254
 
218
255
  def mirror_layers(layer_positions, layer_extents)
219
- return unless %w[LEFT UP].include?(@direction)
256
+ return unless mirrored?
220
257
 
221
258
  bound = layer_positions.zip(layer_extents)
222
259
  .map { |position, extent| position + extent }.max
@@ -499,9 +499,14 @@ module Elkrb
499
499
  placer.index = index
500
500
  placer.port_order = @port_order
501
501
  placer.orthogonal = get_edge_routing_style(graph) == "ORTHOGONAL"
502
+ placer.alignment_of = method(:node_alignment)
502
503
  placer.place_nodes
503
504
  end
504
505
 
506
+ def node_alignment(node)
507
+ resolver.get("elk.alignment", node)
508
+ end
509
+
505
510
  def validate_edges(index)
506
511
  index.edges.each do |edge|
507
512
  validate_simple_edge!(edge)
@@ -36,6 +36,7 @@ module Elkrb
36
36
  "disco.componentArrangement" => { type: :string, values: %w[row column grid], default: "row", namespace: :elkrb, algorithms: %w[disco], status: :honoured, description: "How components are arranged" },
37
37
  "disco.componentSpacing" => { type: :float, default: 20.0, namespace: :elkrb, algorithms: %w[disco], status: :honoured, description: "Spacing between components" },
38
38
  "elk.algorithm" => { type: :string, default: "layered", aliases: %w[algorithm], algorithms: :all, status: :honoured, description: "The layout algorithm to use" },
39
+ "elk.alignment" => { type: :enum, values: %w[AUTOMATIC LEFT RIGHT TOP BOTTOM CENTER], default: "AUTOMATIC", aliases: %w[alignment], algorithms: %w[layered], status: :partial, readers: %w[layered], carriers: %i[node call], note: "Layered only: places a node across its layer (LEFT or RIGHT in a horizontal layout, TOP or BOTTOM in a vertical one, CENTER in either); a side across the layers acts as AUTOMATIC", description: "Alignment of a node relative to the other nodes of its layer" },
39
40
  "elk.aspectRatio" => { type: :float, default: 1.6, aliases: %w[aspectRatio aspect_ratio], algorithms: %w[box disco layered random], status: :honoured, description: "Target width/height ratio (box, disco, layered, random)" },
40
41
  "elk.bendPoints" => { type: :kvector_chain, default: nil, aliases: %w[bendPoints], algorithms: :all, status: :partial, readers: %w[fixed], carriers: %i[edge call], note: "No other algorithm applies explicit bend points", description: "Manual bend points for an edge" },
41
42
  "elk.box.packingMode" => { type: :enum, values: %w[SIMPLE GROUP_DEC GROUP_MIXED GROUP_INC], default: "SIMPLE", algorithms: %w[box], status: :accepted, description: "Box layout packing mode; SIMPLE is implemented and GROUP_* values fall back to it" },
data/lib/elkrb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Elkrb
4
- VERSION = "2.0.0"
4
+ VERSION = "2.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elkrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-16 00:00:00.000000000 Z
11
+ date: 2026-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model