charma 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'charma'
4
+
5
+ Charma::Document.new{ |doc|
6
+ [
7
+ {
8
+ title: "Lorem ipsum",
9
+ series:[
10
+ {
11
+ x: [2, 3, 5, 7, 11, 12, 13, 15, 17, 20],
12
+ y: [0.2, 0.7, 0.7, 0.1, 2.9, 4.4, 2.9, 4.5, 7.9, 0.5],
13
+ name: "The world is melon"
14
+ },
15
+ {
16
+ x: [4, 5, 7, 8, 10, 13, 15, 17, 20],
17
+ y: [1.0, 1.6, 0.9, 0.0, 0.3, 5.1, 2.1, 0.9, 4.9],
18
+ }
19
+ ],
20
+ },
21
+ {
22
+ title: "Semi-log graph",
23
+ y_scale: :log10,
24
+ series:[
25
+ {
26
+ x: [*1..10],
27
+ y: (1..10).map{ |x| 10.0**x },
28
+ name: "10.0**x"
29
+ },
30
+ {
31
+ x: [*1..10],
32
+ y: (1..10).map{ |e| 2**(1.41**e) },
33
+ name: "2**(1.41**e)"
34
+ },
35
+ ]
36
+ },
37
+ {
38
+ title: "Log-log graph",
39
+ x_scale: :log10,
40
+ y_scale: :log10,
41
+ series:[
42
+ {
43
+ x: (1..10).map{ |t| 10.0**t },
44
+ y: (1..10).map{ |t| 10.0**t+1e7 },
45
+ name: "10.0**x+1e7"
46
+ },
47
+ {
48
+ x: (1..10).map{ |t| 10.0**t },
49
+ y: (1..10).map{ |t| 10.0**t*3 },
50
+ name: "10.0**t*3"
51
+ },
52
+ ]
53
+ },
54
+ {
55
+ title: "Name only X",
56
+ x_ticks: ["2017-Q1", "2017-Q2", "2017-Q3", "2017-Q4", "2018-Q1", "2018-Q2", "2018-Q3", "2018-Q4"],
57
+ series:[
58
+ {
59
+ y: [41, -23, 52, -6, 18, 62, 70, 98],
60
+ name: "foo",
61
+ },
62
+ {
63
+ y: [63, -19, 2, 91, -2, 132, 93, 13],
64
+ name: "bar",
65
+ },
66
+ ]
67
+ },
68
+ {
69
+ title: "Y only",
70
+ series:[
71
+ {
72
+ y: Array.new(100){ |n| Math.sin(n*0.01*Math::PI*2) },
73
+ name: "sin",
74
+ },
75
+ {
76
+ y: Array.new(100){ |n| Math.cos(n*0.01*Math::PI*2) },
77
+ name: "cos",
78
+ },
79
+ ]
80
+ },
81
+ Array.new(4){ |g|
82
+ {
83
+ title:" Graph No. #{g}",
84
+ series: Array.new(4){ |n|
85
+ len=100
86
+ r = Math::PI*2/len
87
+ {
88
+ name: "sin(t*#{g})+sin(t**0.5*#{n})",
89
+ y:Array.new(len){ |t| Math.sin(t*r*g)+Math.sin((t*r)**0.5*n) }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ].each do |opts|
95
+ doc.new_page do |page|
96
+ case opts
97
+ when Hash
98
+ page.add_linechart( opts )
99
+ when Array
100
+ opts.each{ |o| page.add_linechart( o ) }
101
+ else
102
+ raise "unexpected input #{opts.inspect}"
103
+ end
104
+ end
105
+ end
106
+ }.render( File.basename(__FILE__, ".*")+".pdf" )
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob( "*.rb" ) do |fn|
4
+ next if /runall\.rb/===fn
5
+ %x( bundle exec ruby #{fn} )
6
+ end