pxgraphviz 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70f73184b1cef8e81842516e538451db8d8560579ae2ef32e4df8bf90d48d459
4
- data.tar.gz: af7d1eeb5592936825ba4865eed0c6573641140669d53a0a11edab252594a8aa
3
+ metadata.gz: a78ce580851bb82d22fa2fb8cae46f76b00983960ae6c5a5eb2a1b9a1a8345e2
4
+ data.tar.gz: ecb6566e9be469c2af046ea6be9fb80334a4c6bdbd94ce2bd7529224d6f39c24
5
5
  SHA512:
6
- metadata.gz: 3378a5d20a452a3d2f9edc6f33add84ef84d5eb3c8936e9980bd0e8b7d1bef76a6b42b49896e8fbbe3832ac07ba0a2381f181b9fe50f815f3cf87e0f6531097c
7
- data.tar.gz: ddf70aa9c62d18e4083d0ffa9f9012f91936cfd91537fe99c74496a7b5400759bafd69915020c9c11149d2f8dc2898f5ac2c6fe2d2cbb712cf15d99f56d71e2a
6
+ metadata.gz: e3c0eaf7ca54185fff20f64523bc34ed8a18d411dd61b63b03f5771a87a3ea86084f4a3e01ad6f7ee11e409ea3a2095b2128e95e30a16b5a987d84a96dcf5878
7
+ data.tar.gz: ffa438ed496981f3d213c83f920d2cd3fd38ff5ceb712aefd96fce90a462e1886da551ea17427a583dbc18f21739562d1d6209224591dc0390ff7cc4bf5a68be
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/pxgraphviz.rb CHANGED
@@ -7,38 +7,55 @@ require 'polyrex'
7
7
  require 'graphvizml'
8
8
 
9
9
 
10
+ module RegGem
11
+
12
+ def self.register()
13
+ '
14
+ hkey_gems
15
+ doctype
16
+ pxgraphviz
17
+ require pxgraphviz
18
+ class PxGraphViz
19
+ media_type svg
20
+ '
21
+ end
22
+ end
23
+
24
+
10
25
  class PxGraphViz < GraphVizML
11
26
  using ColouredText
12
27
 
13
28
  attr_reader :doc, :px
14
29
 
15
- def initialize(s, style: nil, debug: false, fill: '#778833',
30
+ def initialize(obj=nil, style: nil, debug: false, fill: '#778833',
16
31
  stroke: '#999999', text_color: '#ffeecc')
17
32
 
18
- @px = s =~ /^<\?/ ? Polyrex.new.import(s) : Polyrex.new(s)
33
+ if obj then
19
34
 
20
- @type = @px.summary[:type] == 'digraph' ? 'dir: forward;' : 'dir: none;'
21
- @shape = @px.summary[:shape] || 'ellipse;'
22
-
23
- style ||= default_stylesheet()
24
- doc = Rexslt.new(xslt_stylesheet(), @px.to_xml)\
25
- .to_doc.root.element('nodes')
26
-
27
- doc.root.elements.first.insert_before Rexle::Element.new('style')\
28
- .add_text style
29
- @doc = doc
30
- puts 'pxgraphviz: before super'.info if debug
35
+ s = RXFHelper.read(obj).first
36
+ @doc = import_string(s)
31
37
 
32
- super(doc, debug: debug, fill: fill,
33
- stroke: stroke, text_color: text_color)
38
+ puts 'pxgraphviz: before super'.info if debug
39
+
40
+ super(@doc, debug: debug, fill: fill,
41
+ stroke: stroke, text_color: text_color)
42
+
43
+ end
34
44
 
35
45
  @css = "
36
- .node ellipse {stroke: #{stroke}; fill: #{fill}}
46
+ .node polygon {stroke: #{stroke}; fill: #{fill}}
37
47
  .node text {fill: #{text_color}}
38
48
  .edge path {stroke: #{stroke}}
39
49
  .edge polygon {stroke: #{stroke}; fill: #{stroke}}
40
50
  "
41
51
 
52
+ end
53
+
54
+ def import(s)
55
+ s2 = RXFHelper.read(s).first
56
+ @doc = import_string s2
57
+ @g = build_from_nodes Domle.new(@doc.root.xml)
58
+ self
42
59
  end
43
60
 
44
61
 
@@ -49,8 +66,8 @@ class PxGraphViz < GraphVizML
49
66
  <<STYLE
50
67
  node {
51
68
  color: #ddaa66;
52
- fillcolor: #778833;
53
- fontcolor: #ffeecc;
69
+ fillcolor: #{@fill};
70
+ fontcolor: #{@text_color};
54
71
  fontname: 'Trebuchet MS';
55
72
  fontsize: 8;
56
73
  margin: 0.0;
@@ -65,7 +82,7 @@ class PxGraphViz < GraphVizML
65
82
 
66
83
  edge {
67
84
  arrowsize: 0.5;
68
- color: #999999;
85
+ color: #{@stroke};
69
86
  fontcolor: #444444;
70
87
  fontname: Verdana;
71
88
  fontsize: 8;
@@ -76,8 +93,62 @@ STYLE
76
93
 
77
94
  end
78
95
 
96
+
79
97
  private
80
98
 
99
+ def import_string(s)
100
+
101
+ @px = if s =~ /<\?pxgraphviz\b/ then
102
+
103
+ header = "<?polyrex schema='items[type, shape]/item[label, connection]' delimiter =' # '?>
104
+ type: digraph
105
+ shape: box
106
+ "
107
+ s2 = s.slice!(/<\?pxgraphviz\b[^>]*\?>/)
108
+
109
+ if s2 then
110
+
111
+ attributes = %w(id fill stroke text_color).inject({}) do |r, keyword|
112
+ found = s2[/(?<=#{keyword}=['"])[^'"]+/]
113
+ found ? r.merge(keyword.to_sym => found) : r
114
+ end
115
+
116
+ fill, stroke, text_color = %i(fill stroke text_color).map do |x|
117
+ attributes[x] ? attributes[x] : method(x).call
118
+ end
119
+
120
+ @css = "
121
+ .node ellipse {stroke: #{stroke}; fill: #{fill}}
122
+ .node text {fill: #{text_color}}
123
+ .edge path {stroke: #{stroke}}
124
+ .edge polygon {stroke: #{stroke}; fill: #{stroke}}
125
+ "
126
+
127
+ end
128
+ s3 = header + s
129
+ puts 's3: ' + s3.inspect if @debug
130
+ Polyrex.new.import(s3)
131
+
132
+ else
133
+
134
+ Polyrex.new(s)
135
+
136
+ end
137
+
138
+ @type = @px.summary[:type] == 'digraph' ? 'dir: forward;' : 'dir: none;'
139
+ @shape = @px.summary[:shape] || 'ellipse;'
140
+
141
+ style ||= default_stylesheet()
142
+ doc = Rexslt.new(xslt_stylesheet(), @px.to_xml)\
143
+ .to_doc.root.element('nodes')
144
+
145
+ doc.root.elements.first.insert_before Rexle::Element.new('style')\
146
+ .add_text style
147
+
148
+ doc
149
+
150
+ end
151
+
81
152
  def xslt_stylesheet()
82
153
 
83
154
  <<XSLT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pxgraphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file