svgplot 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +49 -3
- data/bin/svgplot +0 -0
- data/circle.yml +12 -0
- data/lib/svgplot.rb +0 -1
- data/lib/svgplot/gradient.rb +9 -7
- data/lib/svgplot/parsers.rb +1 -1
- data/lib/svgplot/plot.rb +2 -1
- data/lib/svgplot/tag.rb +5 -1
- data/lib/svgplot/transform.rb +2 -1
- data/spec/spec_helper.rb +7 -6
- data/spec/svgplot/application_spec.rb +4 -0
- data/spec/svgplot/gradients_spec.rb +4 -0
- data/spec/svgplot/meta_spec.rb +4 -0
- data/spec/svgplot/parsers_spec.rb +4 -0
- data/spec/svgplot/path_spec.rb +4 -0
- data/spec/svgplot/plot_spec.rb +4 -0
- data/spec/svgplot/spec_spec.rb +4 -0
- data/spec/svgplot/tag_spec.rb +4 -0
- data/spec/svgplot/transform_spec.rb +61 -0
- data/spec/svgplot_spec.rb +4 -2
- data/svgplot.gemspec +4 -4
- metadata +30 -12
- data/.travis.yml +0 -15
- data/lib/svgplot/defaults.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f32bc9623d7681312a258c6e9b2d0d44e0570668
|
4
|
+
data.tar.gz: e26356a75dae5566315c4d3ac64c29c7134cbafe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da5deef4fb30b076469c3da597b73f04d199ef373fac1b47b83cf6b0983c90f4bdcef0966f622ba09a555e2a1e52f76e085645292b1670bf73d867ef45d73b3
|
7
|
+
data.tar.gz: f2f38af1aa3c60f20c4d7149b141cb91b8ed7975bf10b7f2821fcb101054c520f64e706e5016ba543af550a4cc5e7bc35a6bbf98e42cd4c641b152c2623064e1
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -3,15 +3,61 @@ svgplot
|
|
3
3
|
|
4
4
|
[![Gem Version](https://img.shields.io/gem/v/svgplot.svg)](https://rubygems.org/gems/svgplot)
|
5
5
|
[![Dependency Status](https://img.shields.io/gemnasium/akerl/svgplot.svg)](https://gemnasium.com/akerl/svgplot)
|
6
|
-
[![
|
7
|
-
[![Coverage Status](https://img.shields.io/
|
8
|
-
[![
|
6
|
+
[![Build Status](https://img.shields.io/circleci/project/akerl/svgplot.svg)](https://circleci.com/gh/akerl/svgplot)
|
7
|
+
[![Coverage Status](https://img.shields.io/codecov/c/github/akerl/svgplot.svg)](https://codecov.io/github/akerl/svgplot)
|
8
|
+
[![Code Quality](https://img.shields.io/codacy/a4ad68dc9c4940b58f9b78ec1996f533.svg)](https://www.codacy.com/app/akerl/svgplot)
|
9
9
|
[![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
|
10
10
|
|
11
11
|
SVG creation library forked from [xytis's Rasem fork](https://github.com/xytis/rasem).
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
+
Create an SVG object by initializing it with a size:
|
16
|
+
|
17
|
+
```
|
18
|
+
plot = SVGPlot.new(width: 100, height: 100)
|
19
|
+
```
|
20
|
+
|
21
|
+
SVGPlot is based directly on the SVG spec. Add children by calling their methods on the plot:
|
22
|
+
|
23
|
+
```
|
24
|
+
# Add the text 'foo' at position (1, 2)
|
25
|
+
plot.text(1, 2) { 'foo' }
|
26
|
+
```
|
27
|
+
|
28
|
+
```
|
29
|
+
# Add a rectangle
|
30
|
+
plot.rectangle(1, 1, 10, 10)
|
31
|
+
```
|
32
|
+
|
33
|
+
A good example of the SVG library in practice is [GithubChart](https://github.com/akerl/githubchart/blob/master/lib/githubchart/svg.rb)
|
34
|
+
|
35
|
+
### Transformations
|
36
|
+
|
37
|
+
To do an SVG transform on an object, just call the desired transform method on it:
|
38
|
+
|
39
|
+
```
|
40
|
+
plot = SVGPlot.new(width: 100, height: 100)
|
41
|
+
plot.text(1, 1) { 'foobar' }.translate(5, 5)
|
42
|
+
```
|
43
|
+
|
44
|
+
You can call transforms after the fact as well:
|
45
|
+
|
46
|
+
```
|
47
|
+
plot = SVGPlot.new(width: 100, height: 100)
|
48
|
+
text = plot.text(1, 1) { 'foobar' }
|
49
|
+
text.scale(2)
|
50
|
+
```
|
51
|
+
|
52
|
+
The list of available transforms:
|
53
|
+
|
54
|
+
* translate(x, y = 0)
|
55
|
+
* scale(x, y = 1)
|
56
|
+
* rotate(angle, x = nil, y = nil)
|
57
|
+
* skew_x(angle)
|
58
|
+
* skew_y(angle)
|
59
|
+
* matrix(a, b, c, d, e, f)
|
60
|
+
|
15
61
|
## Installation
|
16
62
|
|
17
63
|
gem install svgplot
|
data/bin/svgplot
CHANGED
File without changes
|
data/circle.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
dependencies:
|
2
|
+
override:
|
3
|
+
- 'rvm-exec 1.9.3-p551 bundle install'
|
4
|
+
- 'rvm-exec 2.0.0-p645 bundle install'
|
5
|
+
- 'rvm-exec 2.1.6 bundle install'
|
6
|
+
- 'rvm-exec 2.2.2 bundle install'
|
7
|
+
test:
|
8
|
+
override:
|
9
|
+
- 'rvm-exec 1.9.3-p551 bundle exec rake'
|
10
|
+
- 'rvm-exec 2.0.0-p645 bundle exec rake'
|
11
|
+
- 'rvm-exec 2.1.6 bundle exec rake'
|
12
|
+
- 'rvm-exec 2.2.2 bundle exec rake'
|
data/lib/svgplot.rb
CHANGED
data/lib/svgplot/gradient.rb
CHANGED
@@ -7,13 +7,15 @@ module SVGPlot
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def stop(offset, color, opacity)
|
10
|
-
append_child(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
append_child(
|
11
|
+
ChildTag.new(
|
12
|
+
@img,
|
13
|
+
'stop',
|
14
|
+
'offset' => offset,
|
15
|
+
'stop-color' => color,
|
16
|
+
'stop-opacity' => opacity
|
17
|
+
)
|
18
|
+
)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
data/lib/svgplot/parsers.rb
CHANGED
@@ -43,7 +43,7 @@ module SVGPlot
|
|
43
43
|
def parse_transforms(transforms)
|
44
44
|
return nil unless transforms && valid_attribute?(:transform)
|
45
45
|
transforms.each_with_object('') do |(attr, value), str|
|
46
|
-
str << "#{attr}(#{value.is_a?(Array) ? value.join(',') : value
|
46
|
+
str << "#{attr}(#{value.is_a?(Array) ? value.join(',') : value}) "
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
data/lib/svgplot/plot.rb
CHANGED
@@ -5,7 +5,7 @@ module SVGPlot
|
|
5
5
|
DEFAULTS = {
|
6
6
|
version: 1.1,
|
7
7
|
xmlns: 'http://www.w3.org/2000/svg',
|
8
|
-
:'xmlns:xlink' => 'http://www.w3.org/1999/xlink'
|
8
|
+
:'xmlns:xlink' => 'http://www.w3.org/1999/xlink' # rubocop:disable Style/HashSyntax, Metrics/LineLength, Lint/UnneededDisable
|
9
9
|
}
|
10
10
|
|
11
11
|
def initialize(params = {}, output = nil, &block)
|
@@ -17,6 +17,7 @@ module SVGPlot
|
|
17
17
|
|
18
18
|
def add_def(id, child, if_exists = :skip, &block)
|
19
19
|
@defs ||= ChildTag.new(@img, 'defs')
|
20
|
+
@defs_ids ||= {}
|
20
21
|
old_id = check_conflicts(id, if_exists) if @defs_ids.key? id
|
21
22
|
return old_id if old_id
|
22
23
|
|
data/lib/svgplot/tag.rb
CHANGED
@@ -4,10 +4,10 @@ module SVGPlot
|
|
4
4
|
class Tag
|
5
5
|
include Parsers::Tag
|
6
6
|
include Transform
|
7
|
-
include Defaults
|
8
7
|
include Expansion
|
9
8
|
|
10
9
|
attr_reader :tag, :attributes, :children
|
10
|
+
attr_writer :defaults
|
11
11
|
|
12
12
|
def initialize(tag, attributes = {}, &block)
|
13
13
|
@tag = parse_tag tag
|
@@ -25,6 +25,10 @@ module SVGPlot
|
|
25
25
|
append_child Path.new(@img, attributes, &block)
|
26
26
|
end
|
27
27
|
|
28
|
+
def defaults
|
29
|
+
@defaults ||= {}
|
30
|
+
end
|
31
|
+
|
28
32
|
def use(id, attributes = {})
|
29
33
|
id = id.attributes[:id] if id.is_a? Tag
|
30
34
|
attributes.merge!('xlink:href' => "##{id}")
|
data/lib/svgplot/transform.rb
CHANGED
@@ -13,7 +13,7 @@ module SVGPlot
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def rotate(angle, cx = nil, cy = nil)
|
16
|
-
string = [cx, cy].any?(&:nil?) ?
|
16
|
+
string = [cx, cy].any?(&:nil?) ? "#{angle}" : "#{angle}, #{cx}, #{cy}"
|
17
17
|
add_transform(:rotate, string)
|
18
18
|
self
|
19
19
|
end
|
@@ -39,6 +39,7 @@ module SVGPlot
|
|
39
39
|
def add_transform(type, params)
|
40
40
|
validate_attribute(:transform)
|
41
41
|
@attributes[:transform] ||= ''
|
42
|
+
@attributes[:transform] << ' ' if @attributes[:transform].size > 0
|
42
43
|
@attributes[:transform] << "#{type}(#{params})"
|
43
44
|
end
|
44
45
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
SimpleCov.formatter =
|
5
|
-
SimpleCov.start do
|
6
|
-
|
1
|
+
if ENV['CI'] == 'true'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'codecov'
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/spec/'
|
7
|
+
end
|
7
8
|
end
|
8
9
|
|
9
10
|
require 'rspec'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SVGPlot::Transform do
|
4
|
+
let(:subject) do
|
5
|
+
SVGPlot.new(width: 10, height: 10).text(1, 1) { 'test' }
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can translate on x plane' do
|
9
|
+
subject.translate(1)
|
10
|
+
expect(subject.attributes[:transform]).to eql 'translate(1, 0)'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can translate on y and y planes' do
|
14
|
+
subject.translate(1, 10)
|
15
|
+
expect(subject.attributes[:transform]).to eql 'translate(1, 10)'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can scale on x plane' do
|
19
|
+
subject.scale(2)
|
20
|
+
expect(subject.attributes[:transform]).to eql 'scale(2, 1)'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can scale on y and y planes' do
|
24
|
+
subject.scale(1, 10)
|
25
|
+
expect(subject.attributes[:transform]).to eql 'scale(1, 10)'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can rotate to an angle' do
|
29
|
+
subject.rotate(10)
|
30
|
+
expect(subject.attributes[:transform]).to eql 'rotate(10)'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can rotate to an angle and offset' do
|
34
|
+
subject.rotate(10, 5, 6)
|
35
|
+
expect(subject.attributes[:transform]).to eql 'rotate(10, 5, 6)'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can skew to an x angle' do
|
39
|
+
subject.skew_x(10)
|
40
|
+
expect(subject.attributes[:transform]).to eql 'skewX(10)'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'can skew to a y angle' do
|
44
|
+
subject.skew_y(10)
|
45
|
+
expect(subject.attributes[:transform]).to eql 'skewY(10)'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can do a matrix transform' do
|
49
|
+
subject.matrix(1, 2, 3, 4, 5, 6)
|
50
|
+
expect(subject.attributes[:transform]).to eql 'matrix(1, 2, 3, 4, 5, 6)'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'validates matrix args' do
|
54
|
+
expect { subject.matrix(1, 2) }.to raise_error RuntimeError
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can chain transforms' do
|
58
|
+
subject.skew_x(5).scale(1, 2)
|
59
|
+
expect(subject.attributes[:transform]).to eql 'skewX(5) scale(1, 2)'
|
60
|
+
end
|
61
|
+
end
|
data/spec/svgplot_spec.rb
CHANGED
data/svgplot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'svgplot'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '1.0.0'
|
4
4
|
s.date = Time.now.strftime("%Y-%m-%d")
|
5
5
|
|
6
6
|
s.summary = 'SVG Generation Library'
|
@@ -19,10 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.test_files = `git ls-files spec/*`.split
|
20
20
|
s.executables = ['svgplot']
|
21
21
|
|
22
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
22
|
+
s.add_development_dependency 'rubocop', '~> 0.34.0'
|
23
23
|
s.add_development_dependency 'rake', '~> 10.4.0'
|
24
|
-
s.add_development_dependency '
|
25
|
-
s.add_development_dependency 'rspec', '~> 3.
|
24
|
+
s.add_development_dependency 'codecov', '~> 0.1.1'
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.3.0'
|
26
26
|
s.add_development_dependency 'fuubar', '~> 2.0.0'
|
27
27
|
s.add_development_dependency 'nokogiri', '~> 1.6.5'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svgplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rubocop
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.34.0
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 0.34.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,33 +42,33 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 10.4.0
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
45
|
+
name: codecov
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.
|
50
|
+
version: 0.1.1
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
57
|
+
version: 0.1.1
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - "~>"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: 3.
|
64
|
+
version: 3.3.0
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - "~>"
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 3.
|
71
|
+
version: 3.3.0
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: fuubar
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,16 +107,16 @@ files:
|
|
107
107
|
- ".gitignore"
|
108
108
|
- ".rspec"
|
109
109
|
- ".rubocop.yml"
|
110
|
-
-
|
110
|
+
- CHANGELOG.md
|
111
111
|
- Gemfile
|
112
112
|
- LICENSE
|
113
113
|
- README.md
|
114
114
|
- Rakefile
|
115
115
|
- bin/svgplot
|
116
|
+
- circle.yml
|
116
117
|
- dev/update_spec.rb
|
117
118
|
- lib/svgplot.rb
|
118
119
|
- lib/svgplot/application.rb
|
119
|
-
- lib/svgplot/defaults.rb
|
120
120
|
- lib/svgplot/gradient.rb
|
121
121
|
- lib/svgplot/meta.rb
|
122
122
|
- lib/svgplot/parsers.rb
|
@@ -126,6 +126,15 @@ files:
|
|
126
126
|
- lib/svgplot/tag.rb
|
127
127
|
- lib/svgplot/transform.rb
|
128
128
|
- spec/spec_helper.rb
|
129
|
+
- spec/svgplot/application_spec.rb
|
130
|
+
- spec/svgplot/gradients_spec.rb
|
131
|
+
- spec/svgplot/meta_spec.rb
|
132
|
+
- spec/svgplot/parsers_spec.rb
|
133
|
+
- spec/svgplot/path_spec.rb
|
134
|
+
- spec/svgplot/plot_spec.rb
|
135
|
+
- spec/svgplot/spec_spec.rb
|
136
|
+
- spec/svgplot/tag_spec.rb
|
137
|
+
- spec/svgplot/transform_spec.rb
|
129
138
|
- spec/svgplot_spec.rb
|
130
139
|
- svgplot.gemspec
|
131
140
|
homepage: https://github.com/AUTHOR_NAME/REPO_NAME
|
@@ -148,10 +157,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
157
|
version: '0'
|
149
158
|
requirements: []
|
150
159
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.4.5.1
|
152
161
|
signing_key:
|
153
162
|
specification_version: 4
|
154
163
|
summary: SVG Generation Library
|
155
164
|
test_files:
|
156
165
|
- spec/spec_helper.rb
|
166
|
+
- spec/svgplot/application_spec.rb
|
167
|
+
- spec/svgplot/gradients_spec.rb
|
168
|
+
- spec/svgplot/meta_spec.rb
|
169
|
+
- spec/svgplot/parsers_spec.rb
|
170
|
+
- spec/svgplot/path_spec.rb
|
171
|
+
- spec/svgplot/plot_spec.rb
|
172
|
+
- spec/svgplot/spec_spec.rb
|
173
|
+
- spec/svgplot/tag_spec.rb
|
174
|
+
- spec/svgplot/transform_spec.rb
|
157
175
|
- spec/svgplot_spec.rb
|
data/.travis.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
rvm:
|
4
|
-
- 2.1.2
|
5
|
-
- 2.1.1
|
6
|
-
- 2.1.0
|
7
|
-
- 2.0.0
|
8
|
-
- 1.9.3
|
9
|
-
notifications:
|
10
|
-
email: false
|
11
|
-
irc:
|
12
|
-
template:
|
13
|
-
- "%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}"
|
14
|
-
channels:
|
15
|
-
secure: abJmnLwEbJFJyI2hS+LS8kbdVw1be33W3ubjizV7/8z5jmqyYn6hWivOOIh88nquxPmtWvI2SZvWqnrse5MUAdn48vW04JWJSFLRewzkq7Scz4N+RgOT8ZvaVQBJnwJTTdBohOuiVASeRnigCgozS2MjJtnyqhUGgOhAjXCtnb0=
|
data/lib/svgplot/defaults.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module SVGPlot
|
2
|
-
##
|
3
|
-
# Adds default attributes helpers for Tags
|
4
|
-
module Defaults
|
5
|
-
attr_writer :defaults
|
6
|
-
|
7
|
-
def defaults
|
8
|
-
@defaults ||= {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def with(defaults, &block)
|
12
|
-
@defaults = defaults
|
13
|
-
instance_exec(&block)
|
14
|
-
@defaults = {}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|