svgstack 0.1.0 → 0.1.1

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: d2eb1336f84071ff927fe47a7e4bc3648188e24e1abc1aea1ac7658fd1f19434
4
- data.tar.gz: 826f69323600074ed5f57ff449b272e7f209eadb94cc2fd36ce1b10b96d847a6
3
+ metadata.gz: ad4ff843110d0f458af2c7328e96804b0c13e8292e5594af777ca0985c306171
4
+ data.tar.gz: 2aa80a53cf8e23a6657e1ba3d2acb35c7c1542f0738813d2a1336314cea97041
5
5
  SHA512:
6
- metadata.gz: 1806321fe1adbd2e5c50f76136df91a7726149bd4731da9f475df37c78945b8e57481f3bd03cfe95db7c7e2e5aa317d2b60e7e29d6e9e5285e9728d3a7f52aab
7
- data.tar.gz: eb382e514ef2cf3d64f316c3be504e46f80140ceb2797e40739fbeb85781797184ceade1b24ad1a70a99ea37d504cc74583be025147b511d12c5d2efed7c14f2
6
+ metadata.gz: 23e4f3ccc0b18c78e3b69f5681cc9122c82b5c73c66e3a2f7b1ee7ad082132ee5f1cb13cd5d6320f43f276af9525ab024888dd014f03fcf8a7153d8c97965d7c
7
+ data.tar.gz: 0be5f5b38b47a74cbc239c9d3518fe6195c392e02f3bdc214a37459d5e1bf143464351e018076ae1705d45c10fd740737bc2e9e9769846a1ce55a5a9bb12349d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/svgstack.rb CHANGED
@@ -22,18 +22,38 @@ hkey_gems
22
22
  end
23
23
 
24
24
  class SvgStack
25
+
26
+ attr_accessor :css
25
27
 
26
- def initialize(data=nil, x: 0, y: 0, width: 700, height: 70)
28
+ def initialize(data=nil, x: 0, y: 0, width: 150, height: nil)
27
29
 
28
30
  boxes = data if data.is_a? Array
31
+
32
+ height ||= (boxes.length * 50) + 50
29
33
 
30
34
  @svg = Victor::SVG.new viewBox: [x, y, width, height].join(' ')
35
+ @boxwidth = width
31
36
  build boxes
37
+
38
+ @css = "
39
+ rect {
40
+ fill: #f6f;
41
+ }
42
+
43
+ text { fill: blue}
44
+ "
32
45
 
33
46
  end
34
47
 
35
48
  def save(file='untitled')
49
+
36
50
  @svg.save file
51
+
52
+ #inject the css
53
+
54
+ s = File.read file
55
+ s2 = s.lines.insert 7, css_code()
56
+ File.write file, s2.join
37
57
  end
38
58
 
39
59
  private
@@ -42,12 +62,14 @@ class SvgStack
42
62
 
43
63
  y = 0
44
64
 
45
- labels.each do |label|
65
+ labels.reverse.each do |label|
46
66
 
47
67
  @svg.g do
48
- @svg.rect x: 50, y: y, width: 100, height: 40, fill: '#362'
49
- @svg.text label, x: 60, y: y+20, font_family: 'arial',
50
- font_weight: 'bold', font_size: 20, fill: 'blue'
68
+ @svg.rect x: 0, y: y, width: @boxwidth, height: 40
69
+ @svg.text label, {x: @boxwidth / 2, y: y+20, font_family: 'arial',
70
+ font_weight: 'bold', font_size: 20,
71
+ :"dominant-baseline" => "middle", :"text-anchor" => "middle"}
72
+
51
73
  end
52
74
 
53
75
  y+=50
@@ -55,5 +77,15 @@ class SvgStack
55
77
  end
56
78
 
57
79
  end
58
-
80
+
81
+ def css_code()
82
+ <<EOF
83
+ <defs>
84
+ <style type='text/css'><![CDATA[
85
+ #{@css}
86
+ ]]></style>
87
+ </defs>
88
+
89
+ EOF
90
+ end
59
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  /t04zmFjtiFj2Zd4pHZCw0lFsUaO9SEZpWpWqWQpOSoonkVFhiZL1DTTEqmGq2HS
36
36
  cW6mXMQVJTv3bDf0prQ7jjkt
37
37
  -----END CERTIFICATE-----
38
- date: 2019-06-03 00:00:00.000000000 Z
38
+ date: 2019-06-04 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: victor
metadata.gz.sig CHANGED
Binary file