diagrams-rb 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/diagrams/dot.rb +87 -57
- data/lib/diagrams/resources.rb +0 -1
- data/lib/diagrams/version.rb +1 -1
- metadata +2 -3
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a88b43b3643bbb75a44ca94744b7cfe4a617cb6f5439520edd899d32d55757
|
4
|
+
data.tar.gz: 272798c4dcf1f125604ac817121a61d76f346fc521fcd98d2f0d6e53f7b42999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b408960a0da513d5f87935ea8db6bbedb69b734318675352adb69d9bf175345871dc3047eda9d6b927b014dfce916f91decacb8ec35c87a1cc07e163dd96fbf
|
7
|
+
data.tar.gz: 5ff6dbb9349aa5bdda6e4c63f95dc7a52ea34bc699aca4e75fb01d8b6280e4825ffeb89cb722408716fe1c7a94225e8d3c1fd5365f1ff1e0a6463908affbb7c2
|
data/lib/diagrams/dot.rb
CHANGED
@@ -4,73 +4,73 @@ require 'open3'
|
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
6
|
module Diagrams
|
7
|
-
class Dot
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
7
|
+
class Dot # rubocop:disable Metrics/ClassLength
|
8
|
+
DEFAULTS = {
|
9
|
+
|
10
|
+
GRAPH: {
|
11
|
+
pad: '2.0',
|
12
|
+
splines: 'ortho',
|
13
|
+
nodesep: '0.60',
|
14
|
+
ranksep: '0.75',
|
15
|
+
rankdir: 'TB',
|
16
|
+
fontname: '"Sans-Serif"',
|
17
|
+
fontsize: '15',
|
18
|
+
fontcolor: '"#2D3436"'
|
19
|
+
},
|
20
|
+
|
21
|
+
NODE: {
|
22
|
+
shape: 'box',
|
23
|
+
style: 'rounded',
|
24
|
+
fixedsize: 'true',
|
25
|
+
width: '1.4',
|
26
|
+
height: '1.4',
|
27
|
+
labelloc: 'b',
|
28
|
+
imagescale: 'true',
|
29
|
+
penwidth: '0',
|
30
|
+
fontname: '"Sans-Serif"',
|
31
|
+
fontsize: '13',
|
32
|
+
fontcolor: '"#2D3436"'
|
33
|
+
},
|
34
|
+
|
35
|
+
CLUSTER: {
|
36
|
+
shape: 'box',
|
37
|
+
style: 'rounded',
|
38
|
+
labeljust: 'l',
|
39
|
+
pencolor: '"#AEB6BE"'
|
40
|
+
},
|
41
|
+
|
42
|
+
CLUSTER_BGCOLORS: %w[#E5F5FD #EBF3E7 #ECE8F6 #FDF7E3],
|
43
|
+
|
44
|
+
EDGE: {
|
45
|
+
color: '"#7B8894"',
|
46
|
+
fontcolor: '"#2D3436"',
|
47
|
+
fontname: '"Sans-Serif"',
|
48
|
+
fontsize: '13'
|
49
|
+
},
|
50
|
+
|
51
|
+
PADDING: 0.45
|
41
52
|
|
42
|
-
EDGE_DEFAULTS = {
|
43
|
-
color: '"#7B8894"',
|
44
|
-
fontcolor: '"#2D3436"',
|
45
|
-
fontname: '"Sans-Serif"',
|
46
|
-
fontsize: '13'
|
47
53
|
}.freeze
|
48
54
|
|
49
|
-
attr_accessor :
|
55
|
+
attr_accessor :format, :space, :bg_color_len
|
50
56
|
|
51
57
|
def initialize(**attrs)
|
52
|
-
@dot_output = "digraph G {\n".dup
|
53
58
|
@format = attrs.delete(:format) || 'png'
|
54
|
-
|
55
|
-
@dot_output << " #{key}=#{value};\n"
|
56
|
-
end
|
59
|
+
@test = attrs.delete(:test)
|
57
60
|
@space = ' '
|
58
|
-
@
|
61
|
+
@bg_color_len = DEFAULTS[:CLUSTER_BGCOLORS].length
|
59
62
|
@depth = 0
|
60
63
|
@cluster_idx = -1
|
61
|
-
|
62
|
-
|
63
|
-
def indent
|
64
|
-
space * @depth
|
64
|
+
write_digraph_default(attrs)
|
65
65
|
end
|
66
66
|
|
67
67
|
def add_node(id, label: '', icon: nil, **attrs)
|
68
|
-
attributes =
|
68
|
+
attributes = DEFAULTS[:NODE].merge(attrs.merge(height: node_height(label))).map { |k, v| "#{k}=#{v}" }.join(',')
|
69
69
|
dot_output << "#{indent} #{id} [label=\"#{label}\", image=\"#{icon}\", #{attributes}];\n"
|
70
70
|
end
|
71
71
|
|
72
72
|
def add_edge(from, to:, **attrs)
|
73
|
-
attributes =
|
73
|
+
attributes = DEFAULTS[:EDGE].merge(attrs).map { |k, v| "#{k}=#{v}" }.join(',')
|
74
74
|
dot_output << " #{from} -> #{to} [#{attributes}];\n"
|
75
75
|
end
|
76
76
|
|
@@ -79,11 +79,12 @@ module Diagrams
|
|
79
79
|
|
80
80
|
dot_output << "#{indent}subgraph cluster_#{identifier(cluster_label)} {\n"
|
81
81
|
dot_output << "#{indent} label=\"#{label}\";\n"
|
82
|
-
dot_output << "#{indent} bgcolor=\"#{CLUSTER_BGCOLORS[@depth %
|
83
|
-
|
84
|
-
dot_output << "#{indent}
|
82
|
+
dot_output << "#{indent} bgcolor=\"#{DEFAULTS[:CLUSTER_BGCOLORS][@depth % bg_color_len]}\";\n"
|
83
|
+
DEFAULTS[:CLUSTER].merge(attrs).each do |key, value|
|
84
|
+
dot_output << "#{indent} #{key}=#{value};\n"
|
85
85
|
end
|
86
86
|
@depth += 1
|
87
|
+
@dot_output
|
87
88
|
end
|
88
89
|
|
89
90
|
def end_cluster
|
@@ -91,13 +92,38 @@ module Diagrams
|
|
91
92
|
@depth -= 1
|
92
93
|
end
|
93
94
|
|
95
|
+
def generate_image
|
96
|
+
dot_output << "}\n"
|
97
|
+
return dot_output if @test
|
98
|
+
|
99
|
+
write_output
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def dot_output
|
105
|
+
@dot_output ||= "digraph G {\n".dup
|
106
|
+
end
|
107
|
+
|
108
|
+
def write_digraph_default(attrs)
|
109
|
+
DEFAULTS[:GRAPH].merge(attrs).each do |key, value|
|
110
|
+
dot_output << " #{key}=#{value};\n"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def indent
|
115
|
+
space * @depth
|
116
|
+
end
|
117
|
+
|
118
|
+
def node_height(label)
|
119
|
+
(DEFAULTS[:NODE][:height].to_f + (DEFAULTS[:PADDING] * label.split("\\n").size)).round(1).to_s
|
120
|
+
end
|
121
|
+
|
94
122
|
def identifier(string)
|
95
123
|
string.gsub(/\s+/, '_')
|
96
124
|
end
|
97
125
|
|
98
|
-
def
|
99
|
-
output_path = caller_locations.last.path.gsub('.rb', ".#{format}")
|
100
|
-
dot_output << "}\n"
|
126
|
+
def write_output
|
101
127
|
Tempfile.open('temp.dot') do |file|
|
102
128
|
File.write(file.path, dot_output)
|
103
129
|
|
@@ -106,5 +132,9 @@ module Diagrams
|
|
106
132
|
puts stderr unless status.success?
|
107
133
|
end
|
108
134
|
end
|
135
|
+
|
136
|
+
def output_path
|
137
|
+
caller_locations.last.path.gsub('.rb', ".#{format}")
|
138
|
+
end
|
109
139
|
end
|
110
140
|
end
|
data/lib/diagrams/resources.rb
CHANGED
data/lib/diagrams/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diagrams-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerard O'Mahony
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
This Ruby-based DSL allows you to create complex Graphviz DOT diagrams programmatically.
|
@@ -25,7 +25,6 @@ files:
|
|
25
25
|
- CHANGELOG.md
|
26
26
|
- CODE_OF_CONDUCT.md
|
27
27
|
- LICENSE
|
28
|
-
- LICENSE.txt
|
29
28
|
- README.md
|
30
29
|
- Rakefile
|
31
30
|
- lib/diagrams-rb.rb
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 TODO: Write your name
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|