minichart 0.0.1 → 0.1.0

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
- SHA1:
3
- metadata.gz: 7a7348b03ecdf74aeaa57f5fba37079542211e40
4
- data.tar.gz: b85da04d30a6fe59f8b38b688e29962b8a69c1a2
2
+ SHA256:
3
+ metadata.gz: 0574d786b6188b0f2ed6977760ad85bbd2f2487a6d010de8e7be7f50127d51a3
4
+ data.tar.gz: 5b138c614099b58ff7365a38246641a586417c0fdccb6e1e2677494603f01eb8
5
5
  SHA512:
6
- metadata.gz: d14c1514bc83eb80ab82b05476999824097a378af0729f47ba02e8c998e60495bbf94c79834ccbd35f531a57056ac70c15e9609e36e047724334e3009a9744c8
7
- data.tar.gz: 8141275bea9a34dad840cd7c26d19b0c693b839f4162fddb87a2c7ac77fe81286c7dae653636befb848087097e797c6056acce759de370ab689e5df650737dbd
6
+ metadata.gz: 49471660072528ec03c129fb0b549b88f3a2a9f3f5286b969579402ddfb9233c7eb617f1fa64821273a43a88042a724432324bad8f7f0d0143d5825778f4d5fb
7
+ data.tar.gz: 23d208d26569d432380615d0e5e479a92dfa61492841cbd9c9211dd8c94c036f5be467f5710de49a66b58cffa92a2c3066f9a4a2bf6933fea72ba69c59b9e811
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  Minichart - SVG Chart Generator
2
2
  ==================================================
3
3
 
4
-
5
4
  ---
6
5
 
7
6
  Create SVG mini charts with Ruby
@@ -34,4 +33,7 @@ plot.data = [10, 30, 20, 40, 30]
34
33
  plot.save 'line'
35
34
  ```
36
35
 
37
- See more examples in the examples folder.
36
+ See more examples (code and SVG output) in the [examples folder][1].
37
+
38
+
39
+ [1]: https://github.com/DannyBen/minichart/tree/master/examples#examples
@@ -8,11 +8,7 @@ module Minichart
8
8
  end
9
9
  end
10
10
 
11
- private
12
-
13
- def style
14
- @style ||= { stroke_width: 1, stroke: '#eee' }
15
- end
11
+ private
16
12
 
17
13
  def bar_width
18
14
  @bar_width ||= width / data.size
@@ -23,10 +19,10 @@ module Minichart
23
19
  bar_height = height-y
24
20
  {
25
21
  x: x*width,
26
- y: y, width:
27
- bar_width, height:
28
- bar_height,
29
- style: style
22
+ y: y,
23
+ width: bar_width,
24
+ height: bar_height,
25
+ style: { fill: color, stroke_width: stroke, stroke: background }
30
26
  }
31
27
  end
32
28
  end
@@ -1,15 +1,19 @@
1
1
  module Minichart
2
2
  class Chart
3
- attr_accessor :data, :aspect_ratio
3
+ attr_accessor :data, :aspect_ratio, :opts
4
+
5
+ def initialize(opts={})
6
+ @opts = opts
7
+ end
4
8
 
5
9
  def save(name)
6
- svg.rect x: 0, y: 0, width: width, height: height, fill: '#ccc'
10
+ svg.rect x: 0, y: 0, width: width, height: height, fill: background
7
11
  build
8
12
  svg.save name
9
13
  end
10
14
 
11
15
  def build
12
- raise "Subeclass needs to implement #build"
16
+ raise NotImplementedError, "#build is not implemented"
13
17
  end
14
18
 
15
19
  def inverted_points(opts={})
@@ -41,7 +45,23 @@ module Minichart
41
45
  end
42
46
 
43
47
  def svg
44
- @svg ||= SVG.new viewBox: "0 0 #{width} #{height}", style: { background: '#ddd' }
48
+ @svg ||= Victor::SVG.new viewBox: "0 0 #{width} #{height}", style: style
49
+ end
50
+
51
+ def style
52
+ @opts[:style] ||= {}
53
+ end
54
+
55
+ def background
56
+ @opts[:background] ||= '#eee'
57
+ end
58
+
59
+ def color
60
+ @opts[:color] || '#333'
61
+ end
62
+
63
+ def stroke
64
+ @opts[:stroke] ||= 2
45
65
  end
46
66
  end
47
67
  end
@@ -1,9 +1,11 @@
1
1
  module Minichart
2
2
  class LineChart < Chart
3
3
  def build
4
- svg.polyline fill: :none, stroke: :black, stroke_width: 2, points: points
4
+ svg.polyline fill: :none, stroke: color, stroke_width: stroke, points: points
5
5
  end
6
6
 
7
+ private
8
+
7
9
  def points
8
10
  result = []
9
11
  inverted_points.each do |point|
@@ -1,3 +1,3 @@
1
1
  module Minichart
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minichart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-20 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: victor
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.1'
27
- - !ruby/object:Gem::Dependency
28
- name: runfile
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.8'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.8'
41
- - !ruby/object:Gem::Dependency
42
- name: runfile-tasks
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.4'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.4'
55
- - !ruby/object:Gem::Dependency
56
- name: byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '9.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '9.0'
69
- - !ruby/object:Gem::Dependency
70
- name: filewatcher
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.5'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.5'
83
27
  description: Generate mini charts with SVG
84
28
  email: db@dannyben.com
85
29
  executables: []
@@ -111,8 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
55
  - !ruby/object:Gem::Version
112
56
  version: '0'
113
57
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.6
58
+ rubygems_version: 3.0.3
116
59
  signing_key:
117
60
  specification_version: 4
118
61
  summary: SVG Mini Charts