cairo-graph 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a92ad657c35e87063c2ce8e5dab114ea646fca7e
4
- data.tar.gz: 8b6f9b0dce0fd8446daf91366cc6f5e07d450ccc
3
+ metadata.gz: d65aced2df6209d22f60d5ad3382b6f66475141a
4
+ data.tar.gz: 44be113372e08a635722699bfd6468070f7df16e
5
5
  SHA512:
6
- metadata.gz: 9fb035333001ca88284f8c1568e95ee8d3de4cbf5c0e7803ffbbe8ac06a12bb385a945f37e4cba6800754aa8f55b78893f80030578f3f0e6e935d6a8d79dad2d
7
- data.tar.gz: 6262ae14b7a809164ccac83806955d9cbc0be7f8b1a1559096f92a017728668a448e420c62aa7501da58a4bc536b5148b9dd196e4e3298c674f846c75389fd92
6
+ metadata.gz: 48663b86a1a724bab0d82b948abd4134ba1513036a83c260329ae66d9d58d981dd9c43fe758e6c10093884d4326a7bbf7620be6bdec5ff7b90255287ea55699c
7
+ data.tar.gz: daa47bd2e9fe58d5aa4a2ff2b95a7b488771432b66a9bc2be7c10d8217e2fdd79b39c94c4bf8431c3ab537f196ff5194e3e08487bb1fca84f040096b1033faa2
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
- See examples.
29
+ See [examples/basic.rb](https://github.com/myokoym/cairo-graph/blob/master/examples/basic.rb).
30
30
 
31
31
  ## Authors
32
32
 
data/examples/basic.rb CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require "cairo/graph"
2
4
 
3
5
  rows = [
data/lib/cairo/graph.rb CHANGED
@@ -8,7 +8,7 @@ module Cairo
8
8
  end
9
9
 
10
10
  class Graph
11
- VERSION = "0.0.1"
11
+ VERSION = "0.0.2"
12
12
 
13
13
  LINE_COLORS = [
14
14
  Cairo::Color.parse("#CCCCE6"),
@@ -17,10 +17,6 @@ module Cairo
17
17
  Cairo::Color.parse("#F9B351"),
18
18
  Cairo::Color.parse("#83BE41"),
19
19
  Cairo::Color.parse("#E2629C"),
20
- Cairo::Color::RGB.new(rand, rand, rand),
21
- Cairo::Color::RGB.new(rand, rand, rand),
22
- Cairo::Color::RGB.new(rand, rand, rand),
23
- Cairo::Color::RGB.new(rand, rand, rand),
24
20
  ]
25
21
 
26
22
  attr_reader :width
@@ -45,6 +41,8 @@ module Cairo
45
41
  attr_accessor :grid_max
46
42
  attr_accessor :grid_step
47
43
 
44
+ attr_accessor :font
45
+
48
46
  def initialize(options={})
49
47
  # TODO: validate options
50
48
 
@@ -82,6 +80,7 @@ module Cairo
82
80
  end
83
81
 
84
82
  def draw(context)
83
+ context.select_font_face(@font) if @font
85
84
  draw_background(context)
86
85
  draw_title(context)
87
86
  draw_grid(context)
@@ -145,7 +144,7 @@ module Cairo
145
144
  x1 = @width - (@margin_right * 0.85)
146
145
  x2 = @width - (@margin_right * 0.1)
147
146
  @names.each_with_index do |name, i|
148
- context.set_source_color(@colors[i] || LINE_COLORS[i])
147
+ context.set_source_color(line_color(i))
149
148
  text = (@names[i] || (i + 1)).to_s
150
149
  y = (@margin_top * 0.7) + (font_size * i * 1.8)
151
150
  context.stroke do
@@ -194,7 +193,7 @@ module Cairo
194
193
 
195
194
  def draw_row(context, index)
196
195
  row = @rows[index]
197
- context.set_source_color(@colors[index] || LINE_COLORS[index])
196
+ context.set_source_color(line_color(index))
198
197
  points = []
199
198
  row.each_with_index do |value, i|
200
199
  x = interval_x * i + @margin_left
@@ -283,5 +282,11 @@ module Cairo
283
282
  pattern.add_color_stop(1.0, @background_bottom_color)
284
283
  pattern
285
284
  end
285
+
286
+ def line_color(index)
287
+ @colors[index] ||
288
+ LINE_COLORS[index] ||
289
+ Cairo::Color::RGB.new(rand, rand, rand)
290
+ end
286
291
  end
287
292
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cairo-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cairo