charty 0.1.1.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +62 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +21 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +388 -0
  7. data/Rakefile +2 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/charty.gemspec +31 -0
  11. data/examples/Gemfile +29 -0
  12. data/examples/active_record.ipynb +281 -0
  13. data/examples/daru.ipynb +308 -0
  14. data/examples/nmatrix.ipynb +242 -0
  15. data/examples/numo-narray.ipynb +245 -0
  16. data/examples/sample_gruff.ipynb +465 -0
  17. data/examples/sample_images/bar_gruff.png +0 -0
  18. data/examples/sample_images/bar_matplot.png +0 -0
  19. data/examples/sample_images/bar_rubyplot.png +0 -0
  20. data/examples/sample_images/boxplot_matplot.png +0 -0
  21. data/examples/sample_images/bubble_matplot.png +0 -0
  22. data/examples/sample_images/bubble_rubyplot.png +0 -0
  23. data/examples/sample_images/curve_gruff.png +0 -0
  24. data/examples/sample_images/curve_matplot.png +0 -0
  25. data/examples/sample_images/curve_rubyplot.png +0 -0
  26. data/examples/sample_images/curve_with_function_matplot.png +0 -0
  27. data/examples/sample_images/curve_with_function_rubyplot.png +0 -0
  28. data/examples/sample_images/errorbar_matplot.png +0 -0
  29. data/examples/sample_images/hist_matplot.png +0 -0
  30. data/examples/sample_images/scatter_gruff.png +0 -0
  31. data/examples/sample_images/scatter_matplot.png +0 -0
  32. data/examples/sample_images/scatter_rubyplot.png +0 -0
  33. data/examples/sample_images/subplot2_matplot.png +0 -0
  34. data/examples/sample_images/subplot_matplot.png +0 -0
  35. data/examples/sample_matplotlib.ipynb +372 -0
  36. data/examples/sample_rubyplot.ipynb +432 -0
  37. data/images/design_concept.png +0 -0
  38. data/lib/charty.rb +12 -0
  39. data/lib/charty/gruff.rb +75 -0
  40. data/lib/charty/layout.rb +75 -0
  41. data/lib/charty/linspace.rb +21 -0
  42. data/lib/charty/matplot.rb +91 -0
  43. data/lib/charty/plotter.rb +241 -0
  44. data/lib/charty/rubyplot.rb +90 -0
  45. data/lib/charty/table.rb +41 -0
  46. data/lib/charty/version.rb +9 -0
  47. metadata +120 -0
@@ -0,0 +1,90 @@
1
+ require 'rubyplot'
2
+
3
+ module Charty
4
+ class Rubyplot
5
+ def initialize
6
+ @plot = ::Rubyplot
7
+ end
8
+
9
+ def label(x, y)
10
+ end
11
+
12
+ def series=(series)
13
+ @series = series
14
+ end
15
+
16
+ def render_layout(layout)
17
+ (fig, axes) = *@plot.subplots(nrows: layout.num_rows, ncols: layout.num_cols)
18
+ layout.rows.each_with_index do |row, y|
19
+ row.each_with_index do |cel, x|
20
+ plot = layout.num_rows > 1 ? axes[y][x] : axes[x]
21
+ plot(plot, cel)
22
+ end
23
+ end
24
+ @plot.show
25
+ end
26
+
27
+ def render(context, filename)
28
+ plot(@plot, context).write(filename)
29
+ end
30
+
31
+ def plot(plot, context)
32
+ # case
33
+ # when plot.respond_to?(:xlim)
34
+ # plot.xlim(context.range_x.begin, context.range_x.end)
35
+ # plot.ylim(context.range_y.begin, context.range_y.end)
36
+ # when plot.respond_to?(:set_xlim)
37
+ # plot.set_xlim(context.range_x.begin, context.range_x.end)
38
+ # plot.set_ylim(context.range_y.begin, context.range_y.end)
39
+ # end
40
+
41
+ figure = ::Rubyplot::Figure.new
42
+ axes = figure.add_subplot 0,0
43
+ axes.title = context.title if context.title
44
+ axes.x_title = context.xlabel if context.xlabel
45
+ axes.y_title = context.ylabel if context.ylabel
46
+
47
+ case context.method
48
+ when :bar
49
+ context.series.each do |data|
50
+ axes.bar! do |p|
51
+ p.data(data.xs.to_a)
52
+ p.label = data.label
53
+ end
54
+ end
55
+ figure
56
+ when :boxplot
57
+ raise NotImplementedError
58
+ when :bubble
59
+ context.series.each do |data|
60
+ axes.bubble! do |p|
61
+ p.data(data.xs.to_a, data.ys.to_a, data.zs.to_a)
62
+ p.label = data.label if data.label
63
+ end
64
+ end
65
+ figure
66
+ when :curve
67
+ context.series.each do |data|
68
+ axes.line! do |p|
69
+ p.data(data.xs.to_a, data.ys.to_a)
70
+ p.label = data.label if data.label
71
+ end
72
+ end
73
+ figure
74
+ when :scatter
75
+ context.series.each do |data|
76
+ axes.scatter! do |p|
77
+ p.data(data.xs.to_a, data.ys.to_a)
78
+ p.label = data.label if data.label
79
+ end
80
+ end
81
+ figure
82
+ when :errorbar
83
+ # refs. https://github.com/SciRuby/rubyplot/issues/26
84
+ raise NotImplementedError
85
+ when :hist
86
+ raise NotImplementedError
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,41 @@
1
+
2
+ module Charty
3
+ class Table
4
+ def initialize(table)
5
+ @table = table
6
+ end
7
+
8
+ attr_reader :table
9
+
10
+ def to_a(x=nil, y=nil, z=nil)
11
+ case
12
+ when defined?(Daru::DataFrame) && table.kind_of?(Daru::DataFrame)
13
+ table.map(&:to_a)
14
+ when defined?(Numo::NArray) && table.kind_of?(Numo::NArray)
15
+ table.to_a
16
+ when defined?(NMatrix) && table.kind_of?(NMatrix)
17
+ table.to_a
18
+ when defined?(ActiveRecord::Relation) && table.kind_of?(ActiveRecord::Relation)
19
+ if z && x && y
20
+ [table.pluck(x), table.pluck(y), table.pluck(z)]
21
+ elsif x && y
22
+ [table.pluck(x), table.pluck(y)]
23
+ else
24
+ raise ArgumentError, "column_names is required to convert to_a from ActiveRecord::Relation"
25
+ end
26
+ else
27
+ raise ArgumentError, "unsupported object: #{table.inspect}"
28
+ end
29
+ end
30
+
31
+ def each
32
+ return to_enum(__method__) unless block_given?
33
+ data = to_a
34
+ i, n = 0, data.size
35
+ while i < n
36
+ yield data[i]
37
+ i += 1
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ module Charty
2
+ VERSION = "0.1.1-dev"
3
+
4
+ module Version
5
+ numbers, TAG = VERSION.split("-")
6
+ MAJOR, MINOR, MICRO = numbers.split(".").collect(&:to_i)
7
+ STRING = VERSION
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: charty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.dev
5
+ platform: ruby
6
+ authors:
7
+ - youchan
8
+ - mrkn
9
+ - 284km
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2019-03-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.16'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.16'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ description: Visualizing your data in a simple way.
44
+ email:
45
+ - youchan01@gmail.com
46
+ - mrkn@mrkn.jp
47
+ - k.furuhashi10@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - ".gitignore"
53
+ - Gemfile
54
+ - LICENSE
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - charty.gemspec
61
+ - examples/Gemfile
62
+ - examples/active_record.ipynb
63
+ - examples/daru.ipynb
64
+ - examples/nmatrix.ipynb
65
+ - examples/numo-narray.ipynb
66
+ - examples/sample_gruff.ipynb
67
+ - examples/sample_images/bar_gruff.png
68
+ - examples/sample_images/bar_matplot.png
69
+ - examples/sample_images/bar_rubyplot.png
70
+ - examples/sample_images/boxplot_matplot.png
71
+ - examples/sample_images/bubble_matplot.png
72
+ - examples/sample_images/bubble_rubyplot.png
73
+ - examples/sample_images/curve_gruff.png
74
+ - examples/sample_images/curve_matplot.png
75
+ - examples/sample_images/curve_rubyplot.png
76
+ - examples/sample_images/curve_with_function_matplot.png
77
+ - examples/sample_images/curve_with_function_rubyplot.png
78
+ - examples/sample_images/errorbar_matplot.png
79
+ - examples/sample_images/hist_matplot.png
80
+ - examples/sample_images/scatter_gruff.png
81
+ - examples/sample_images/scatter_matplot.png
82
+ - examples/sample_images/scatter_rubyplot.png
83
+ - examples/sample_images/subplot2_matplot.png
84
+ - examples/sample_images/subplot_matplot.png
85
+ - examples/sample_matplotlib.ipynb
86
+ - examples/sample_rubyplot.ipynb
87
+ - images/design_concept.png
88
+ - lib/charty.rb
89
+ - lib/charty/gruff.rb
90
+ - lib/charty/layout.rb
91
+ - lib/charty/linspace.rb
92
+ - lib/charty/matplot.rb
93
+ - lib/charty/plotter.rb
94
+ - lib/charty/rubyplot.rb
95
+ - lib/charty/table.rb
96
+ - lib/charty/version.rb
97
+ homepage: https://github.com/red-data-tools/charty
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">"
113
+ - !ruby/object:Gem::Version
114
+ version: 1.3.1
115
+ requirements: []
116
+ rubygems_version: 3.0.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Visualizing your data in a simple way.
120
+ test_files: []