rsvgr 0.0.1 → 0.0.2
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/examples/chart.rb +28 -0
- data/examples/crowd.rb +11 -0
- data/examples/multable.rb +9 -0
- data/lib/rsvgr.rb +8 -13
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57ae7236d7ad70541c443a79ff46b350b329a18b
|
4
|
+
data.tar.gz: 3b2b17d2b27be8fe4902585000716a469e759c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6b1014cad2b629d67bce579080339a6159b962e8b77043a610c79f66272f4c6e312466966e313f9d66ea38c2dcd18f95c492deb74543f5a543917a437d9669
|
7
|
+
data.tar.gz: 879debc0e25101c7bccbcf4912379d2a972bba407c9a9f2b721adca70e18a6974f3f82d736490fef5bea3a7b9f1847b03b3bbe7283e466025f029ef1cfd424bb
|
data/examples/chart.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "../rsvgr"
|
2
|
+
include RSVGR
|
3
|
+
|
4
|
+
world = {
|
5
|
+
"4000 до н.э." => 7,
|
6
|
+
"1000 до н.э." => 50,
|
7
|
+
"500 до н.э." => 100,
|
8
|
+
1 => 300,
|
9
|
+
1000 => 400,
|
10
|
+
1800 => 1000,
|
11
|
+
1900 => 1650,
|
12
|
+
1990 => 5264,
|
13
|
+
}
|
14
|
+
asia = {
|
15
|
+
"10000 до н.э." => 1,
|
16
|
+
"4000 до н.э." => 4,
|
17
|
+
"1000 до н.э." => 34,
|
18
|
+
1000 => 270,
|
19
|
+
1900 => 962,
|
20
|
+
1990 => 3216,
|
21
|
+
}
|
22
|
+
ticks_x = (world.keys + asia.keys).sort_by{ |date| date.is_a?(String) ? [0, -date.to_i] : [1, date] }.uniq
|
23
|
+
|
24
|
+
svg = Root.new << plot = Samples::Plot.new(ticks_x:ticks_x)
|
25
|
+
plot.add_line(title: "население Земли", data_pairs: world)\
|
26
|
+
.add_line(title: "население Азии", data_pairs: asia)
|
27
|
+
|
28
|
+
svg.cat.save.open_with "Chromium"
|
data/examples/crowd.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "../lib/rsvgr"
|
2
|
+
include RSVGR
|
3
|
+
|
4
|
+
grid_size_x, grid_size_y = 30, 20
|
5
|
+
|
6
|
+
svg = Root.new
|
7
|
+
svg << Samples::Grid.new(xn:grid_size_x, yn:grid_size_y){ |cell,i,j|
|
8
|
+
cell << Samples::face(rotate:rand(360)) if i&j==0
|
9
|
+
}
|
10
|
+
|
11
|
+
svg.cat.save#.open_with "Chromium"
|
data/lib/rsvgr.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
# I don't give a fuck about namespaces, xslt, etc.
|
2
1
|
# I don't use any xml library, because I just don't really need it here
|
3
|
-
# I don't give a fuck about xslt and other shit
|
4
|
-
# I JUST A PSYCHO REDING THIS AND DOING THE EASIEST WAY
|
5
2
|
|
6
3
|
# http://www.w3.org/TR/SVGTiny12/single-page.html
|
7
4
|
|
8
5
|
|
9
6
|
module RSVGR
|
10
7
|
|
11
|
-
DEFAULT_SIZE = 100.0
|
12
8
|
UNSUPPORTED = ->{ raise "not supported currently" }
|
13
9
|
|
10
|
+
DEFAULT_SIZE = 100.0 # if we use such small value as 1.0 vertical text alignment goes mad
|
11
|
+
|
14
12
|
class Node
|
15
13
|
def initialize args = {}
|
16
14
|
args[:x1] ||= 0
|
@@ -56,6 +54,9 @@ module RSVGR
|
|
56
54
|
"#{" stroke=\"#{@stroke_color}\"" if @stroke_color}" \
|
57
55
|
">\n" + to_s_children(additional_child) + "</g>\n"
|
58
56
|
end
|
57
|
+
# def []= k,v
|
58
|
+
# instance_variable_set "@#{k}",v
|
59
|
+
# end
|
59
60
|
end
|
60
61
|
|
61
62
|
class Root < CanIHazChildren
|
@@ -109,7 +110,7 @@ module RSVGR
|
|
109
110
|
save_as to_s, "temp.svg"
|
110
111
|
end
|
111
112
|
def save_html
|
112
|
-
UNSUPPORTED
|
113
|
+
UNSUPPORTED
|
113
114
|
save_as to_html, "temp.html"
|
114
115
|
end
|
115
116
|
def save_as what, where
|
@@ -239,8 +240,6 @@ module RSVGR
|
|
239
240
|
end
|
240
241
|
class Grid < Group
|
241
242
|
def initialize args = {}
|
242
|
-
#args[:x2] ||= args[:xn] + args[:x1] ||= 0
|
243
|
-
#args[:y2] ||= args[:yn] + args[:y1] ||= 0
|
244
243
|
args[:fill_color] = "white"
|
245
244
|
super
|
246
245
|
if @xn*(@y2-@y1) > (@x2-@x1)*@yn
|
@@ -261,7 +260,8 @@ module RSVGR
|
|
261
260
|
scale_x: w/DEFAULT_SIZE,
|
262
261
|
scale_y: h/DEFAULT_SIZE,
|
263
262
|
)
|
264
|
-
cell << Rect.new(stroke_color:"silver", stroke_width:DEFAULT_SIZE/10)
|
263
|
+
cell << Rect.new(stroke_color:"silver", stroke_width:DEFAULT_SIZE/10) if args[:grid]
|
264
|
+
cell << inside = Group.new(
|
265
265
|
x: DEFAULT_SIZE*0.1,
|
266
266
|
y: DEFAULT_SIZE*0.1,
|
267
267
|
scale_x: 0.8,
|
@@ -398,8 +398,3 @@ module RSVGR
|
|
398
398
|
|
399
399
|
end
|
400
400
|
|
401
|
-
|
402
|
-
if __FILE__ == $0
|
403
|
-
puts `ruby -Cexamples chart.rb`
|
404
|
-
end
|
405
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsvgr
|
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
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: not ready for public usage -- uploaded for personal usage
|
14
14
|
email: nakilon@gmail.com
|
@@ -17,6 +17,9 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/rsvgr.rb
|
20
|
+
- examples/multable.rb
|
21
|
+
- examples/crowd.rb
|
22
|
+
- examples/chart.rb
|
20
23
|
homepage: http://rubygems.org/gems/rsvgr
|
21
24
|
licenses:
|
22
25
|
- MIT
|