diagrammatron 0.5.1 → 0.6.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 +4 -4
- data/LICENSE.txt +1 -1
- data/bin/diagrammatron-copy +103 -0
- data/bin/diagrammatron-edges +2 -0
- data/bin/diagrammatron-nodes +26 -5
- data/lib/copy.yaml +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec55e1ae9f1ad84dd5ee189215011bb6e84fde797d229d7c2965294c4330004a
|
4
|
+
data.tar.gz: bf3c4dd72c1ba1d60d978309a00bfeef09c8e6b55ab449d56b1d6bd9ee48af31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2afa0026ce65f039d1db74bffe5f9dd3d6e85ce8879760d66c44260fac26b5a6f2876af3135ef3ad5086f898f505d9da2834a742531a0645cf9b28952b97136
|
7
|
+
data.tar.gz: eb2f854603ca55a6d1bb14c73e7bc55ab319bacb894fe605cb1264a0fd1a2b1494e5a4abf8987a307a1088f1b7b7da67cbd8b4e5fec0fde7a0e3e31fe43a1f7d
|
data/LICENSE.txt
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2023 Ismo Kärkkäinen
|
5
|
+
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
|
+
|
7
|
+
require_relative '../lib/common'
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
def make_dst2src(args)
|
11
|
+
dst2src = {}
|
12
|
+
(0...args.size).step(2) do |sidx|
|
13
|
+
src = args[sidx]
|
14
|
+
dst = args[sidx + 1]
|
15
|
+
dst2src[dst] = src
|
16
|
+
end
|
17
|
+
dst2src
|
18
|
+
end
|
19
|
+
|
20
|
+
def invert(dst2src)
|
21
|
+
src2dst = {}
|
22
|
+
dst2src.each do |dst, src|
|
23
|
+
src2dst[src] = src2dst.fetch(src, []).push(dst)
|
24
|
+
end
|
25
|
+
src2dst
|
26
|
+
end
|
27
|
+
|
28
|
+
def gather_values(item, src2dst)
|
29
|
+
vals = {}
|
30
|
+
src2dst.each_key do |src|
|
31
|
+
v = item.fetch(src, nil)
|
32
|
+
vals[src] = v unless v.nil?
|
33
|
+
end
|
34
|
+
vals
|
35
|
+
end
|
36
|
+
|
37
|
+
def copy_fields(item, src2dst)
|
38
|
+
vals = gather_values(item, src2dst)
|
39
|
+
copied = {}
|
40
|
+
vals.each do |src, v|
|
41
|
+
src2dst[src].each do |dst|
|
42
|
+
copied[dst] = v
|
43
|
+
end
|
44
|
+
end
|
45
|
+
copied
|
46
|
+
end
|
47
|
+
|
48
|
+
def main
|
49
|
+
input = nil
|
50
|
+
output = nil
|
51
|
+
input_output_schema = 'copy'
|
52
|
+
ENV['POSIXLY_CORRECT'] = '1' # Leaves field name pairs as they are.
|
53
|
+
parser = OptionParser.new do |opts|
|
54
|
+
opts.summary_indent = ' '
|
55
|
+
opts.summary_width = 20
|
56
|
+
opts.banner = 'Usage: diagrammatron-copy [options] source destination ...'
|
57
|
+
opts.separator ''
|
58
|
+
opts.separator 'Options:'
|
59
|
+
opts.on('-i', '--input FILE', 'Input file name. Read from stdin if not given.') do |filename|
|
60
|
+
input = filename
|
61
|
+
end
|
62
|
+
opts.on('-o', '--output FILE', 'Output file name. Write to stdout if not given.') do |filename|
|
63
|
+
output = filename
|
64
|
+
end
|
65
|
+
opts.on('-h', '--help', 'Print this help and exit.') do
|
66
|
+
$stdout.puts %(#{opts}
|
67
|
+
Source and destination are field names in pairs.
|
68
|
+
|
69
|
+
Input and output YAML file schema is returned by:
|
70
|
+
diagrammatron-schema #{input_output_schema}
|
71
|
+
|
72
|
+
Output is the input file with fields in nodes and edges copied from source,
|
73
|
+
when present, to destination field name. All copies are made at the same
|
74
|
+
time, so you can swap field contents, but chaining the copying is not
|
75
|
+
supported. In such case, provide the same source field in multiple pairs.
|
76
|
+
)
|
77
|
+
exit 0
|
78
|
+
end
|
79
|
+
end
|
80
|
+
parser.parse! ARGV
|
81
|
+
|
82
|
+
return aargh('Field name count is not multiple of 2', 1) if ARGV.size.odd?
|
83
|
+
|
84
|
+
# Same source can be copied to multiple destinations.
|
85
|
+
# Same destination copied to multiple times, last copy remains.
|
86
|
+
# Make destination from source mapping and then invert it for actual use.
|
87
|
+
src2dst = invert(make_dst2src(ARGV))
|
88
|
+
|
89
|
+
doc = load_verified(input, input_output_schema)
|
90
|
+
return 2 if doc.nil?
|
91
|
+
|
92
|
+
%w[edges nodes].each do |category|
|
93
|
+
items = doc.fetch(category, nil)
|
94
|
+
next if items.nil?
|
95
|
+
items.each do |item|
|
96
|
+
copies = copy_fields(item, src2dst)
|
97
|
+
item.merge!(copies)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
save_verified(output, doc, 4, input_output_schema)
|
101
|
+
end
|
102
|
+
|
103
|
+
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-edges
CHANGED
@@ -153,6 +153,7 @@ def segment(x0, y0, x1, y1)
|
|
153
153
|
Segment.new(vert, cc, range, 0, [false, false], 0)
|
154
154
|
end
|
155
155
|
|
156
|
+
# side_index is 0 up, 1 right, 2 down, 3 left.
|
156
157
|
Connection = Struct.new(:node_index, :side_index)
|
157
158
|
|
158
159
|
$paths = {}
|
@@ -576,6 +577,7 @@ def place_edges(work)
|
|
576
577
|
$insignificant = 0.1 / (splits.values.max + 1)
|
577
578
|
splits = nil
|
578
579
|
|
580
|
+
# Ordering of segments in gaps between nodes.
|
579
581
|
gaps = {
|
580
582
|
false => {},
|
581
583
|
true => {}
|
data/bin/diagrammatron-nodes
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021-
|
4
|
+
# Copyright © 2021-2024 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
7
|
require_relative '../lib/common'
|
@@ -9,12 +9,27 @@ require 'optparse'
|
|
9
9
|
require 'set'
|
10
10
|
|
11
11
|
|
12
|
+
def horizontal(work)
|
13
|
+
count = {}
|
14
|
+
work[:nodes].each_index do |k|
|
15
|
+
node = work[:nodes][k]
|
16
|
+
c = count.fetch(node[:yo], 0)
|
17
|
+
node[:xo] = c
|
18
|
+
node[:yo] = 0 unless node.key?(:yo)
|
19
|
+
node[:sid] = 0
|
20
|
+
count[node[:yo]] = c + 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
12
24
|
def vertical(work)
|
25
|
+
count = {}
|
13
26
|
work[:nodes].each_index do |k|
|
14
27
|
node = work[:nodes][k]
|
15
|
-
node[:xo]
|
16
|
-
node[:
|
28
|
+
c = count.fetch(node[:xo], 0)
|
29
|
+
node[:xo] = 0 unless node.key?(:xo)
|
30
|
+
node[:yo] = c
|
17
31
|
node[:sid] = 0
|
32
|
+
count[node[:xo]] = c + 1
|
18
33
|
end
|
19
34
|
end
|
20
35
|
|
@@ -269,7 +284,8 @@ end
|
|
269
284
|
|
270
285
|
$algorithms = {
|
271
286
|
'pathlength' => method(:pathlength2coordinates),
|
272
|
-
'vertical' => method(:vertical)
|
287
|
+
'vertical' => method(:vertical),
|
288
|
+
'horizontal' => method(:horizontal)
|
273
289
|
}
|
274
290
|
|
275
291
|
def work_copy(src, quiet)
|
@@ -296,6 +312,11 @@ def work_copy(src, quiet)
|
|
296
312
|
nodes.each_index do |k|
|
297
313
|
work[:nodes].push({ idx: k })
|
298
314
|
node = nodes[k]
|
315
|
+
# Retain xo, yo if present.
|
316
|
+
%i[xo yo].each do |s|
|
317
|
+
sk = s.to_s
|
318
|
+
work[:nodes].last[s] = node[sk] if node.key?(sk)
|
319
|
+
end
|
299
320
|
label = node['label']
|
300
321
|
if label2idx.key?(label) && edge_nodes.member?(label)
|
301
322
|
aargh "Edge-referred label used twice: #{label}"
|
@@ -361,7 +382,7 @@ def main
|
|
361
382
|
opts.on('-h', '--help', 'Print this help and exit.') do
|
362
383
|
$stdout.puts opts
|
363
384
|
$stdout.puts %(
|
364
|
-
Algorithm names are: #{$algorithms.keys.sort
|
385
|
+
Algorithm names are: #{$algorithms.keys.sort!.join(' ')}
|
365
386
|
|
366
387
|
Input YAML file schema is returned by:
|
367
388
|
diagrammatron-schema #{input_schema}
|
data/lib/copy.yaml
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diagrammatron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismo Kärkkäinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_schemer
|
@@ -36,6 +36,7 @@ description: |2
|
|
36
36
|
programs that each perform one stage.
|
37
37
|
email: ismokarkkainen@icloud.com
|
38
38
|
executables:
|
39
|
+
- diagrammatron-copy
|
39
40
|
- diagrammatron-get
|
40
41
|
- diagrammatron-edges
|
41
42
|
- diagrammatron-nodes
|
@@ -50,6 +51,7 @@ extensions: []
|
|
50
51
|
extra_rdoc_files: []
|
51
52
|
files:
|
52
53
|
- LICENSE.txt
|
54
|
+
- bin/diagrammatron-copy
|
53
55
|
- bin/diagrammatron-edges
|
54
56
|
- bin/diagrammatron-get
|
55
57
|
- bin/diagrammatron-nodes
|
@@ -61,6 +63,7 @@ files:
|
|
61
63
|
- bin/diagrammatron-template
|
62
64
|
- bin/dot_json2diagrammatron
|
63
65
|
- lib/common.rb
|
66
|
+
- lib/copy.yaml
|
64
67
|
- lib/edges.yaml
|
65
68
|
- lib/nodes.yaml
|
66
69
|
- lib/place.yaml
|