charma 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ SampleMaker = Struct.new(:size) do
9
9
  end
10
10
 
11
11
  def samples(*peaks)
12
- srand(0)
12
+ srand(peaks.sum)
13
13
  Array.new(size){
14
14
  r + peaks.sample
15
15
  }
@@ -36,20 +36,23 @@ Charma::Document.new do |doc|
36
36
  ],
37
37
  x_ticks: %w(Q1 Q2 Q3 Q4),
38
38
  },
39
+ [10,50].map do |bins|
39
40
  {
40
- title: "Small size sample",
41
+ title: "Small size sample (bins=#{bins})",
42
+ bins: bins,
41
43
  series:[
42
44
  {
43
45
  name: "foo",
44
- y: Array.new(4){ |n| small.samples(n+2, (n+2)*2) }
46
+ y: Array.new(4){ |n| small.samples(n+4, (n+2)*2) }
45
47
  },
46
48
  {
47
49
  name: "bar",
48
- y: Array.new(4){ |n| small.samples(n+2, (n+2)*2, 6) }
50
+ y: Array.new(4){ |n| small.samples(n+4, (n+2)*2, 6) }
49
51
  },
50
52
  ],
51
53
  x_ticks: %w(Q1 Q2 Q3 Q4),
52
- },
54
+ }
55
+ end
53
56
  ].each do |opts|
54
57
  doc.new_page do |page|
55
58
  case opts
@@ -2,21 +2,23 @@
2
2
 
3
3
  module Charma
4
4
  class Document
5
- def initialize( &block )
5
+ def initialize(opts={}, &block )
6
6
  @pages = []
7
+ @opts = opts
7
8
  block[self]
8
9
  end
9
10
 
10
- def new_page(&block)
11
- page = Page.new(self)
11
+ def new_page(opts={},&block)
12
+ page = Page.new(opts)
12
13
  block[page]
13
14
  @pages.push page
14
15
  end
15
16
 
16
17
  def render( filename )
17
18
  raise "no page added" if @pages.empty?
18
- opts = @pages.first.create_opts
19
+ opts = @pages.first.create_opts.merge(@opts)
19
20
  Prawn::Document.generate(filename, opts) do |pdf|
21
+ pdf.font( File.expand_path(@opts[:font]) ) if @opts[:font]
20
22
  @pages.each.with_index do |page,ix|
21
23
  pdf.start_new_page(page.create_opts) if ix != 0
22
24
  page.render(pdf)
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Charma
4
4
  class Page
5
- def initialize( doc )
6
- @doc = doc
5
+ def initialize( opts )
6
+ @opts = opts
7
7
  @graphs = []
8
8
  end
9
9
 
@@ -11,7 +11,7 @@ module Charma
11
11
  {
12
12
  page_size: "A4",
13
13
  page_layout: :landscape,
14
- }
14
+ }.merge(@opts)
15
15
  end
16
16
 
17
17
  def split_rect( rc, pos, size )
@@ -37,6 +37,7 @@ module Charma
37
37
  end
38
38
 
39
39
  def render(pdf)
40
+ pdf.font File.expand_path(@opts[:font]) if @opts[:font]
40
41
  @graphs.each.with_index do |g,ix|
41
42
  g.render( pdf, area(pdf.margin_box, ix) )
42
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Charma
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -36,6 +36,7 @@ module Charma
36
36
  cx = rc.x + rc.w/2
37
37
  h = rc.h / hist.size.to_f
38
38
  hist.each.with_index do |f, ix|
39
+ next if f==0
39
40
  w = rc.w * f
40
41
  top = rc.bottom + h*(ix+1)
41
42
  edge = 1e-1 # バーの隙間を埋める
@@ -57,7 +58,7 @@ module Charma
57
58
  end
58
59
 
59
60
  def make_histograms( vals, range )
60
- hist_size = [10,Math.sqrt( meansize(vals) ).round].max
61
+ hist_size = @opts[:bins] || [10,Math.sqrt( meansize(vals) ).round].max
61
62
  min = range.min
62
63
  step = (range.max - min).to_f / hist_size
63
64
  bottoms = Array.new(hist_size){ |ix| min + (ix+1)*step }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nabetani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-24 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -102,8 +102,12 @@ files:
102
102
  - charma.gemspec
103
103
  - examples/bar_charts.pdf
104
104
  - examples/bar_charts.rb
105
+ - examples/japanese.pdf
106
+ - examples/japanese.rb
105
107
  - examples/line_charts.pdf
106
108
  - examples/line_charts.rb
109
+ - examples/pagefont.pdf
110
+ - examples/pagefont.rb
107
111
  - examples/runall.rb
108
112
  - examples/shortest.pdf
109
113
  - examples/shortest.rb