diagrammatron 0.2.2 → 0.3.0
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/bin/diagrammatron-edges +15 -26
- data/bin/diagrammatron-get +4 -16
- data/bin/diagrammatron-nodes +3 -16
- data/bin/diagrammatron-place +10 -23
- data/bin/diagrammatron-prune +2 -15
- data/bin/diagrammatron-render +11 -21
- data/bin/diagrammatron-template +4 -17
- data/bin/dot_json2diagrammatron +2 -19
- data/lib/common.rb +15 -1
- data/template/internal.yaml +1 -1
- data/template/svg_1.1.erb +4 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5e755dfc41bacfbfb226e77365b8d54a5ff0f01ea5b642febdbb1699497d21
|
4
|
+
data.tar.gz: c9b8b67509f94635cd65b77ed89a3cf0a456f6c666a7b3773539760a8e429fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '081df6de2fb3489cc0976a2805c829fb846ce5561617b15d7446dda4a6bfd0a63bbc9abf234e89e895ed90f710f756cbc8b1f47618ee4216e89a2c4e522e9046'
|
7
|
+
data.tar.gz: 85e77e7adf696cd3f46fe2b41a77266d67cf1d7e904cb1c9eb4f83bae6e3fef8db7f199313923e588c8802e8edb6d8148869f2c8ef93685aeb3af48dc6a83252
|
data/bin/diagrammatron-edges
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'set'
|
@@ -109,7 +109,8 @@ def edge_subsets(work)
|
|
109
109
|
end
|
110
110
|
|
111
111
|
Segment = Struct.new(:vertical, :cc, :range, :edge_index, :at_node, :segment_index, :offset) do
|
112
|
-
|
112
|
+
# To decreasing or increasing coordinates.
|
113
|
+
def direction(s)
|
113
114
|
return 0 if s.nil?
|
114
115
|
if segment_index < s.segment_index
|
115
116
|
(cc < s.range[1]) ? 1 : -1
|
@@ -119,7 +120,7 @@ Segment = Struct.new(:vertical, :cc, :range, :edge_index, :at_node, :segment_ind
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def over_other_node(work, node_subset)
|
122
|
-
ck, rk = vertical ? [
|
123
|
+
ck, rk = vertical ? %i[xo yo] : %i[yo xo]
|
123
124
|
i0, i1 = (range[0] < range[1]) ? [0, 1] : [1, 0]
|
124
125
|
node_subset.each do |n|
|
125
126
|
node = work[:nodes][n]
|
@@ -172,8 +173,7 @@ def segment(x0, y0, x1, y1)
|
|
172
173
|
Segment.new(vert, cc, range, 0, [false, false], 0)
|
173
174
|
end
|
174
175
|
|
175
|
-
Connection = Struct.new(:node_index, :side_index)
|
176
|
-
end
|
176
|
+
Connection = Struct.new(:node_index, :side_index)
|
177
177
|
|
178
178
|
$paths = {}
|
179
179
|
Path = Struct.new(:edge_index, :ends, :segments, :id, :crosses, :steps) do
|
@@ -439,7 +439,7 @@ def segment_order(a, b)
|
|
439
439
|
a[0].edge_index <=> b[0].edge_index
|
440
440
|
end
|
441
441
|
|
442
|
-
GapState = Struct.new(:order, :
|
442
|
+
GapState = Struct.new(:order, :cross_count) do
|
443
443
|
def fitness(segments, k)
|
444
444
|
crossings = 0
|
445
445
|
s = segments[k]
|
@@ -454,7 +454,7 @@ GapState = Struct.new(:order, :count) do
|
|
454
454
|
crossings += 1
|
455
455
|
end
|
456
456
|
end
|
457
|
-
|
457
|
+
cross_count + crossings
|
458
458
|
end
|
459
459
|
end
|
460
460
|
|
@@ -463,13 +463,13 @@ def depth_first_search(segments, state, best)
|
|
463
463
|
segments.each_index do |k|
|
464
464
|
next if state.order.include? k
|
465
465
|
c = state.fitness(segments, k)
|
466
|
-
next if (best.nil? ? c + 1 : best.
|
466
|
+
next if (best.nil? ? c + 1 : best.cross_count) <= c
|
467
467
|
state.order.push(k)
|
468
468
|
best = depth_first_search(segments, GapState.new(state.order, c), best)
|
469
469
|
state.order.pop
|
470
470
|
end
|
471
471
|
else
|
472
|
-
best = GapState.new(state.order.clone, state.
|
472
|
+
best = GapState.new(state.order.clone, state.cross_count)
|
473
473
|
end
|
474
474
|
best
|
475
475
|
end
|
@@ -526,6 +526,7 @@ def group_stacked_offsets(group)
|
|
526
526
|
group[k][0].offset = k + 1
|
527
527
|
end
|
528
528
|
return group.size
|
529
|
+
%q(
|
529
530
|
# This produces narrower gaps but they may be less clear.
|
530
531
|
prev = group[0]
|
531
532
|
prev[0].offset = 1
|
@@ -535,6 +536,7 @@ def group_stacked_offsets(group)
|
|
535
536
|
prev = g
|
536
537
|
end
|
537
538
|
prev[0].offset
|
539
|
+
)
|
538
540
|
end
|
539
541
|
|
540
542
|
def direct_range(paths)
|
@@ -549,7 +551,7 @@ def offsets(conn, paths, direct_ranges)
|
|
549
551
|
dlow = [ here[0], opposite[0] ].max
|
550
552
|
dhigh = [ here[2] - here[1], opposite[2] - opposite[1] ].max - 1
|
551
553
|
d = dlow + here[1] - here[0] + dhigh + 1
|
552
|
-
low, high,
|
554
|
+
low, high, _size = here
|
553
555
|
offsets = []
|
554
556
|
(0...low).each do |k|
|
555
557
|
offsets.push(Rational((k + 1) * dlow, (d + 1) * low))
|
@@ -589,7 +591,7 @@ end
|
|
589
591
|
def place_edges(work)
|
590
592
|
subsets = edge_subsets(work)
|
591
593
|
subsets.each_pair do |sid, subset|
|
592
|
-
full =
|
594
|
+
full = {}
|
593
595
|
subset.each do |edge_index|
|
594
596
|
link = work[:edges][edge_index][:between]
|
595
597
|
full[edge_index] = candidates(
|
@@ -826,20 +828,7 @@ Input YAML file is expected to be the output of diagrammatron-nodes.
|
|
826
828
|
|
827
829
|
place_edges(work)
|
828
830
|
prepare_output(doc, work)
|
829
|
-
|
830
|
-
d = YAML.dump(doc, line_width: 1000000)
|
831
|
-
if output.nil?
|
832
|
-
$stdout.puts d
|
833
|
-
else
|
834
|
-
fp = Pathname.new output
|
835
|
-
fp.open('w') do |f|
|
836
|
-
f.puts d
|
837
|
-
end
|
838
|
-
end
|
839
|
-
rescue StandardError => e
|
840
|
-
return aargh("#{e}\nFailed to write output: #{output || 'stdout'}", 4)
|
841
|
-
end
|
842
|
-
0
|
831
|
+
dump_result(output, YAML.dump(doc, line_width: 1_000_000), 4)
|
843
832
|
end
|
844
833
|
|
845
834
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-get
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'pathname'
|
10
10
|
|
@@ -16,7 +16,6 @@ def template(name = nil)
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def main
|
19
|
-
input = nil
|
20
19
|
output = nil
|
21
20
|
parser = OptionParser.new do |opts|
|
22
21
|
opts.summary_indent = ' '
|
@@ -48,6 +47,7 @@ Given a name of a included file, saves it to --output.
|
|
48
47
|
next if name.start_with? '.'
|
49
48
|
$stdout.puts name
|
50
49
|
end
|
50
|
+
return 0
|
51
51
|
elsif ARGV.size > 1
|
52
52
|
return aargh('You can give only one content-file name.', 1)
|
53
53
|
end
|
@@ -59,19 +59,7 @@ Given a name of a included file, saves it to --output.
|
|
59
59
|
rescue StandardError => e
|
60
60
|
return aargh("#{e}\nFailed to read #{ARGV.first}", 3)
|
61
61
|
end
|
62
|
-
|
63
|
-
if output.nil?
|
64
|
-
$stdout.puts src
|
65
|
-
else
|
66
|
-
fp = Pathname.new output
|
67
|
-
fp.open('w') do |f|
|
68
|
-
f.puts src
|
69
|
-
end
|
70
|
-
end
|
71
|
-
rescue StandardError => e
|
72
|
-
return aargh([ e, "Failed to write output: #{output || 'stdout'}" ], 4)
|
73
|
-
end
|
74
|
-
0
|
62
|
+
dump_result(output, src, 4)
|
75
63
|
end
|
76
64
|
|
77
65
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-nodes
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'set'
|
@@ -420,20 +420,7 @@ The 'sid' indicates the sub-diagram consisting of connected nodes.
|
|
420
420
|
|
421
421
|
algo.call(work)
|
422
422
|
prepare_output(doc, work)
|
423
|
-
|
424
|
-
d = YAML.dump(doc, line_width: 1000000)
|
425
|
-
if output.nil?
|
426
|
-
$stdout.puts d
|
427
|
-
else
|
428
|
-
fp = Pathname.new output
|
429
|
-
fp.open('w') do |f|
|
430
|
-
f.puts d
|
431
|
-
end
|
432
|
-
end
|
433
|
-
rescue StandardError => e
|
434
|
-
return aargh("#{e}\nFailed to write output: #{output || 'stdout'}", 4)
|
435
|
-
end
|
436
|
-
0
|
423
|
+
dump_result(output, YAML.dump(doc, line_width: 1_000_000), 4)
|
437
424
|
end
|
438
425
|
|
439
426
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-place
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'set'
|
11
11
|
require 'pathname'
|
12
12
|
|
13
|
-
def info(msg, return_value = nil
|
14
|
-
$stderr.puts(msg) unless $QUIET
|
13
|
+
def info(msg, return_value = nil)
|
14
|
+
$stderr.puts(msg) unless $QUIET
|
15
15
|
return_value
|
16
16
|
end
|
17
17
|
|
@@ -310,7 +310,7 @@ def pre_search_bounding_boxes(work)
|
|
310
310
|
end
|
311
311
|
|
312
312
|
def shift(work, sid, dx, dy)
|
313
|
-
[
|
313
|
+
%i[edges nodes].each do |kind|
|
314
314
|
work[kind].fetch(sid, []).each do |item|
|
315
315
|
item.shift(dx, dy)
|
316
316
|
end
|
@@ -402,16 +402,16 @@ do not overlap.
|
|
402
402
|
begin
|
403
403
|
whratio = Float($W2HRATIO)
|
404
404
|
if whratio <= 0
|
405
|
-
return
|
405
|
+
return aargh("Ratio must be greater than zero: #{$W2HRATIO}", 1)
|
406
406
|
end
|
407
407
|
$W2HRATIO = whratio
|
408
408
|
rescue StandardError
|
409
|
-
return
|
409
|
+
return aargh("Ratio parameter not a number: #{$W2HRATIO}", 1)
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
413
413
|
unless $algorithms.key? algo
|
414
|
-
return
|
414
|
+
return aargh("Unrecognized algorithm: #{algo}", 2)
|
415
415
|
end
|
416
416
|
algo = $algorithms[algo]
|
417
417
|
|
@@ -422,25 +422,12 @@ do not overlap.
|
|
422
422
|
work = work_copy(doc)
|
423
423
|
return 3 if work.nil?
|
424
424
|
rescue StandardError
|
425
|
-
return
|
425
|
+
return aargh('Error processing input.', 3)
|
426
426
|
end
|
427
427
|
|
428
428
|
algo.call(work)
|
429
429
|
prepare_output(doc, work)
|
430
|
-
|
431
|
-
d = YAML.dump(doc, line_width: 1000000)
|
432
|
-
if output.nil?
|
433
|
-
$stdout.puts d
|
434
|
-
else
|
435
|
-
fp = Pathname.new output
|
436
|
-
fp.open('w') do |f|
|
437
|
-
f.puts d
|
438
|
-
end
|
439
|
-
end
|
440
|
-
rescue StandardError => e
|
441
|
-
return info("#{e}\nFailed to write output: #{output || 'stdout'}", 4, true)
|
442
|
-
end
|
443
|
-
0
|
430
|
+
dump_result(output, YAML.dump(doc, line_width: 1_000_000), 4)
|
444
431
|
end
|
445
432
|
|
446
433
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-prune
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Copyright © 2021 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'set'
|
@@ -98,20 +98,7 @@ removed or kept depending on options. Edges to removed nodes are removed.
|
|
98
98
|
return aargh('Error processing input.', 3)
|
99
99
|
end
|
100
100
|
|
101
|
-
|
102
|
-
d = YAML.dump(doc, line_width: 1000000)
|
103
|
-
if output.nil?
|
104
|
-
$stdout.puts d
|
105
|
-
else
|
106
|
-
fp = Pathname.new output
|
107
|
-
fp.open('w') do |f|
|
108
|
-
f.puts d
|
109
|
-
end
|
110
|
-
end
|
111
|
-
rescue StandardError => e
|
112
|
-
return aargh("#{e}\nFailed to write output: #{output || 'stdout'}", 4)
|
113
|
-
end
|
114
|
-
0
|
101
|
+
dump_result(output, YAML.dump(doc, line_width: 1_000_000), 4)
|
115
102
|
end
|
116
103
|
|
117
104
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-render
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'erb'
|
@@ -135,7 +135,7 @@ class SizeEstimation
|
|
135
135
|
|
136
136
|
def default_size(width_scale = nil, height_scale = nil, line_spacing = nil,
|
137
137
|
width_margin = nil, height_margin = nil, edge_gap = nil)
|
138
|
-
lines = @node
|
138
|
+
lines = @node['label']
|
139
139
|
w = 2 * (width_margin || @defaults.width_margin) +
|
140
140
|
(width_scale || @default.font.width) * (lines.map &(:size)).max
|
141
141
|
@node[@defaults.width_key] = [ w, max_edges('xo', edge_gap) ].max
|
@@ -151,9 +151,12 @@ def estimate_sizes(doc, template, ckd2count, defaults)
|
|
151
151
|
sizes = template.fetch('sizes', {})
|
152
152
|
defaults = template.fetch('defaults', {})
|
153
153
|
doc['nodes'].each do |node|
|
154
|
+
label = node.fetch('label', 'unnamed')
|
155
|
+
# Substitute "text" as label if present, split to lines.
|
156
|
+
node['label'] = node.fetch('text', node.fetch('label', '')).split("\n")
|
154
157
|
$render.node = node
|
155
158
|
style = node.fetch('style', 'default')
|
156
|
-
code = sizes.fetch(style, defaults.fetch('size',
|
159
|
+
code = sizes.fetch(style, defaults.fetch('size',
|
157
160
|
%(raise NotImplementedError, "No size estimator for style: #{style}")))
|
158
161
|
if sizes.key? code
|
159
162
|
code = sizes.fetch(code)
|
@@ -162,7 +165,7 @@ def estimate_sizes(doc, template, ckd2count, defaults)
|
|
162
165
|
begin
|
163
166
|
eval(code, $render.get_binding)
|
164
167
|
rescue StandardError => e
|
165
|
-
return aargh("Size estimate style #{style} node #{
|
168
|
+
return aargh("Size estimate style #{style} node #{label} error #{e}", false)
|
166
169
|
end
|
167
170
|
end
|
168
171
|
$render = nil
|
@@ -216,11 +219,11 @@ def remap_coordinates(coords, cmax, c2min, defaults)
|
|
216
219
|
coord.object[coord.key] = c + coord.fraction * cmax[coord.integer]
|
217
220
|
else
|
218
221
|
coord.object[coord.key] =
|
219
|
-
c + defaults.edge_gap * coord.fraction / c2min[coord.integer]
|
222
|
+
c + (defaults.edge_gap * coord.fraction) / c2min[coord.integer]
|
220
223
|
end
|
221
224
|
when 1
|
222
225
|
gap = defaults.edge_gap
|
223
|
-
c += cmax[coord.integer] unless
|
226
|
+
c += cmax[coord.integer] unless prev_dir == 1
|
224
227
|
coord.object[coord.key] = c
|
225
228
|
zero_after_decrease = false
|
226
229
|
end
|
@@ -336,20 +339,7 @@ Output is the file produced by the erb-template.
|
|
336
339
|
remap_coordinates(xcoords, xmax, x2min, defaults)
|
337
340
|
remap_coordinates(ycoords, ymax, y2min, defaults)
|
338
341
|
|
339
|
-
|
340
|
-
begin
|
341
|
-
if output.nil?
|
342
|
-
$stdout.puts out
|
343
|
-
else
|
344
|
-
fp = Pathname.new output
|
345
|
-
fp.open('w') do |f|
|
346
|
-
f.puts out
|
347
|
-
end
|
348
|
-
end
|
349
|
-
rescue StandardError => e
|
350
|
-
return aargh([ e, "Failed to write output: #{output || 'stdout'}" ], 5)
|
351
|
-
end
|
352
|
-
0
|
342
|
+
dump_result(output, apply(doc, template, defaults), 5)
|
353
343
|
end
|
354
344
|
|
355
345
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/diagrammatron-template
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'set'
|
@@ -21,7 +21,7 @@ def add_field(doc, field_name, content)
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def missing(doc)
|
24
|
-
[
|
24
|
+
%w[defaults sizes template].each do |key|
|
25
25
|
next if doc.key? key
|
26
26
|
next if doc.key? "base64#{key}"
|
27
27
|
return aargh("#{key} is missing", 4)
|
@@ -88,20 +88,7 @@ Extra fields are not restricted in any manner.
|
|
88
88
|
m = missing(doc)
|
89
89
|
return m unless m.nil?
|
90
90
|
|
91
|
-
|
92
|
-
d = YAML.dump(doc, line_width: 1000000)
|
93
|
-
if output.nil?
|
94
|
-
$stdout.puts d
|
95
|
-
else
|
96
|
-
fp = Pathname.new output
|
97
|
-
fp.open('w') do |f|
|
98
|
-
f.puts d
|
99
|
-
end
|
100
|
-
end
|
101
|
-
rescue StandardError => e
|
102
|
-
return aargh([ e, "Failed to write output: #{output || 'stdout'}" ], 5)
|
103
|
-
end
|
104
|
-
0
|
91
|
+
dump_result(output, YAML.dump(doc, line_width: 1_000_000), 5)
|
105
92
|
end
|
106
93
|
|
107
94
|
exit(main) if (defined? $unit_test).nil?
|
data/bin/dot_json2diagrammatron
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
4
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
5
5
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
6
6
|
|
7
|
-
require_relative '../lib/common
|
7
|
+
require_relative '../lib/common'
|
8
8
|
require 'optparse'
|
9
9
|
require 'yaml'
|
10
10
|
require 'json'
|
11
11
|
require 'pathname'
|
12
12
|
|
13
|
-
'''
|
14
|
-
def load_source
|
15
|
-
begin
|
16
|
-
if $INPUT.nil?
|
17
|
-
src = $stdin.read
|
18
|
-
else
|
19
|
-
src = File.read($INPUT)
|
20
|
-
end
|
21
|
-
src = JSON.parse(src)
|
22
|
-
rescue Errno::ENOENT
|
23
|
-
return aargh("Could not load #{$INPUT || 'stdin'}")
|
24
|
-
rescue StandardError => e
|
25
|
-
return aargh("#{e}\nFailed to read #{$INPUT || 'stdin'}")
|
26
|
-
end
|
27
|
-
src
|
28
|
-
end
|
29
|
-
'''
|
30
13
|
|
31
14
|
def convert(src)
|
32
15
|
idx2label = {}
|
data/lib/common.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright © 2021 Ismo Kärkkäinen
|
3
|
+
# Copyright © 2021, 2022 Ismo Kärkkäinen
|
4
4
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
5
5
|
|
6
6
|
def aargh(message, return_value = nil)
|
@@ -24,3 +24,17 @@ def load_source_hash(input)
|
|
24
24
|
end
|
25
25
|
src
|
26
26
|
end
|
27
|
+
|
28
|
+
def dump_result(output, doc, error_return)
|
29
|
+
if output.nil?
|
30
|
+
$stdout.puts doc
|
31
|
+
else
|
32
|
+
fp = Pathname.new output
|
33
|
+
fp.open('w') do |f|
|
34
|
+
f.puts doc
|
35
|
+
end
|
36
|
+
end
|
37
|
+
0
|
38
|
+
rescue StandardError => e
|
39
|
+
aargh([ e, "Failed to write output: #{output || 'stdout'}" ], error_return)
|
40
|
+
end
|
data/template/internal.yaml
CHANGED
@@ -18,4 +18,4 @@ sizes:
|
|
18
18
|
$render.node.fetch('width_margin', $render.defaults.width_margin),
|
19
19
|
$render.node.fetch('height_margin', $render.defaults.height_margin),
|
20
20
|
$render.node.fetch('edge_gap', $render.defaults.edge_gap))
|
21
|
-
base64template: PD94bWwgdmVyc2lvbj0iMS4wIj8+CjwlPQp3LCBoaCA9ICRyZW5kZXIuZGltZW5zaW9ucwpobSA9ICRyZW5kZXIuZGVmYXVs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HRzID0gcGF0aC5tYXAgeyB8cHwgIiN7cFsneG8nXX0sI3twWyd5byddfSIgfQogICAgb3V0LnB1c2goJSg8cG9seWxpbmUgI3tsaW5lc3R5bGV9IHBvaW50cz0iI3twdHMuam9pbignICcpfSIvPikpCiAgZW5kCmVuZApvdXQuam9pbigiXG4iKQolPgo8L3N2Zz4K
|
data/template/svg_1.1.erb
CHANGED
@@ -26,14 +26,13 @@ $render.doc.fetch('nodes', []).each do |node|
|
|
26
26
|
y += hm + ma # Baseline for first line.
|
27
27
|
url = node.fetch('url', nil)
|
28
28
|
url.encode!(:xml => :attr) unless url.nil?
|
29
|
-
lines = node.fetch('label', '').split("\n")
|
30
29
|
y0 = y
|
31
|
-
|
32
|
-
|
30
|
+
node['label'].each do |line|
|
31
|
+
line.encode!(:xml => :text)
|
33
32
|
if url.nil?
|
34
|
-
out.push(%(<text #{textstyle} x="#{x}" y="#{y0}">#{
|
33
|
+
out.push(%(<text #{textstyle} x="#{x}" y="#{y0}">#{line}</text>))
|
35
34
|
else
|
36
|
-
out.push(%(<a xlink:href=#{url} target="_parent"><text #{linkstyle} x="#{x}" y="#{y0}">#{
|
35
|
+
out.push(%(<a xlink:href=#{url} target="_parent"><text #{linkstyle} x="#{x}" y="#{y0}">#{line}</text></a>))
|
37
36
|
end
|
38
37
|
y0 += lh # Shift baseline by full line + spacing height.
|
39
38
|
end
|
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.3.0
|
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: 2023-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
|
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 2.7.0
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ">="
|