charma 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +74 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/charma.gemspec +33 -0
- data/examples/bar_charts.pdf +4273 -0
- data/examples/bar_charts.rb +67 -0
- data/examples/line_charts.pdf +5645 -0
- data/examples/line_charts.rb +106 -0
- data/examples/runall.rb +6 -0
- data/examples/violin_charts.pdf +8020 -0
- data/examples/violin_charts.rb +65 -0
- data/lib/charma/bar_chart.rb +75 -0
- data/lib/charma/chart.rb +188 -0
- data/lib/charma/document.rb +27 -0
- data/lib/charma/error.rb +5 -0
- data/lib/charma/line_chart.rb +141 -0
- data/lib/charma/page.rb +58 -0
- data/lib/charma/rect.rb +52 -0
- data/lib/charma/version.rb +5 -0
- data/lib/charma/violin_chart.rb +121 -0
- data/lib/charma.rb +14 -0
- metadata +143 -0
@@ -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" )
|