diagrammatron 0.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '058b0f84871cad8d010d3b1607460a08c00cccfa21100868cd929dbb94f6eb02'
4
- data.tar.gz: d88732e433f5a5e4de81acf2bb4a226e806d0af1fb447ad6aabcf15aacf2db95
3
+ metadata.gz: 6d5e755dfc41bacfbfb226e77365b8d54a5ff0f01ea5b642febdbb1699497d21
4
+ data.tar.gz: c9b8b67509f94635cd65b77ed89a3cf0a456f6c666a7b3773539760a8e429fec
5
5
  SHA512:
6
- metadata.gz: 97b796b2b213dd6f25acf8a749d6ec25a557657c53566834a6db292c1df9a8e90f5625964f6a5b36b1f7ac9640bc7c52d053ab7ca2437b578b26988ec188a846
7
- data.tar.gz: 4b25e7189ba7ccd794148b31d347c9362fd18ccbffb68af50f3f7bce1115bfdd12d3733330ee079c114f065136425bea358135303933bc33969051cc3a8ccc0a
6
+ metadata.gz: '081df6de2fb3489cc0976a2805c829fb846ce5561617b15d7446dda4a6bfd0a63bbc9abf234e89e895ed90f710f756cbc8b1f47618ee4216e89a2c4e522e9046'
7
+ data.tar.gz: 85e77e7adf696cd3f46fe2b41a77266d67cf1d7e904cb1c9eb4f83bae6e3fef8db7f199313923e588c8802e8edb6d8148869f2c8ef93685aeb3af48dc6a83252
@@ -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 '../lib/common.rb'
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
- def direction(s) # To decreasing or increasing coordinates.
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 ? [:xo, :yo] : [:yo, :xo]
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) do
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, :count) do
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
- count + crossings
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.count) <= c
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.count)
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, size = here
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 = Hash.new
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
- begin
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?
@@ -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 '../lib/common.rb'
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
- begin
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?
@@ -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 '../lib/common.rb'
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
- begin
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?
@@ -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 '../lib/common.rb'
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, loud = false)
14
- $stderr.puts(msg) unless $QUIET && !loud
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
- [ :edges, :nodes ].each do |kind|
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 info("Ratio must be greater than zero: #{$W2HRATIO}", 1, true)
405
+ return aargh("Ratio must be greater than zero: #{$W2HRATIO}", 1)
406
406
  end
407
407
  $W2HRATIO = whratio
408
408
  rescue StandardError
409
- return info("Ratio parameter not a number: #{$W2HRATIO}", 1, true)
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 info("Unrecognized algorithm: #{algo}", 2, true)
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 info('Error processing input.', 3, true)
425
+ return aargh('Error processing input.', 3)
426
426
  end
427
427
 
428
428
  algo.call(work)
429
429
  prepare_output(doc, work)
430
- begin
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?
@@ -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 '../lib/common.rb'
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
- begin
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?
@@ -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 '../lib/common.rb'
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.fetch('label', '').split("\n")
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 #{node.fetch('label', 'unnamed')} error #{e}", false)
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 1 == prev_dir
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
- out = apply(doc, template, defaults)
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?
@@ -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 '../lib/common.rb'
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
- [ 'defaults', 'sizes', 'template' ].each do |key|
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
- begin
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?
@@ -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 '../lib/common.rb'
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
@@ -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+CjwlPQp3LCBoaCA9ICRyZW5kZXIuZGltZW5zaW9ucwpobSA9ICRyZW5kZXIuZGVmYXVsdHMuaGVpZ2h0X21hcmdpbgpoaCArPSBobQptYSA9ICRyZW5kZXIuZGVmYXVsdHMuZm9udC5tYXhfYXNjZW5kCmZzID0gJHJlbmRlci5kZWZhdWx0cy5mb250LnNpemUKbGggPSBmcyArICRyZW5kZXIuZGVmYXVsdHMuZm9udC5saW5lX3NwYWNpbmcKd20gPSAkcmVuZGVyLmRlZmF1bHRzLndpZHRoX21hcmdpbgpzdyA9ICRyZW5kZXIuZ2V0X2RlZmF1bHQoJ3N0cm9rZV93aWR0aCcsIDUpCmxpbmVzdHlsZSA9ICUoZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IiN7c3d9IikKdGV4dHN0eWxlID0gJShmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2VyaWYiIGZvbnQtc2l6ZT0iI3tmc30iIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSIwIiB4bWw6c3BhY2U9InByZXNlcnZlIikKbGlua3N0eWxlID0gJShmaWxsPSIjMjAyMGZmIiBmb250LWZhbWlseT0ic2VyaWYiIGZvbnQtc2l6ZT0iI3tmc30iIHN0cm9rZT0iIzIwMjBmZiIgc3Ryb2tlLXdpZHRoPSIwIiB4bWw6c3BhY2U9InByZXNlcnZlIikKCm91dCA9IFsKICAlKDxzdmcgd2lkdGg9IiN7dyArICRyZW5kZXIuZGVmYXVsdHMud2lkdGhfbWFyZ2lufSIgaGVpZ2h0PSIje2hofSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMD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IG5pbCkKICBuZXh0IGlmIHBhdGgubmlsPwogIHBhdGguZWFjaCBkbyB8cHwKICAgIHBbJ3hvJ10gPSBwWyd4byddLnRvX2kudG9fcwogICAgcFsneW8nXSA9IChoaCAtIHBbJ3lvJ10pLnRvX2kudG9fcwogIGVuZAogIGlmIHBhdGguc2l6ZSA9PSAyCiAgICBvdXQucHVzaCglKDxsaW5lICN7bGluZXN0eWxlfSB4MT0iI3twYXRoWzBdWyd4byddfSIgeDI9IiN7cGF0aFsxXVsneG8nXX0iIHkxPSIje3BhdGhbMF1bJ3lvJ119IiB5Mj0iI3twYXRoWzFdWyd5byddfSIvPikpCiAgZWxzZQogICAgcHRzID0gcGF0aC5tYXAgeyB8cHwgIiN7cFsneG8nXX0sI3twWyd5byddfSIgfQogICAgb3V0LnB1c2goJSg8cG9seWxpbmUgI3tsaW5lc3R5bGV9IHBvaW50cz0iI3twdHMuam9pbignICcpfSIvPikpCiAgZW5kCmVuZApvdXQuam9pbigiXG4iKQolPgo8L3N2Zz4K
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
- lines.each do |label|
32
- label.encode!(:xml => :text)
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}">#{label}</text>))
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}">#{label}</text></a>))
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,21 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diagrammatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
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: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
 
15
15
  Generates diagrams in SVG format from input material. Split into multiple
16
16
  programs that each perform one stage.
17
-
18
- Licensed under Universal Permissive License, see LICENSE.txt.
19
17
  email: ismokarkkainen@icloud.com
20
18
  executables:
21
19
  - diagrammatron-get
@@ -54,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
52
  requirements:
55
53
  - - ">="
56
54
  - !ruby/object:Gem::Version
57
- version: '0'
55
+ version: 2.7.0
58
56
  required_rubygems_version: !ruby/object:Gem::Requirement
59
57
  requirements:
60
58
  - - ">="