iruby-chartkick 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b39050caa3f7e3d2a9b1859b0a3ddd21c851eb9d0afc39e59e03364b2b61417
4
- data.tar.gz: b3fac3e8b089bc3dcf2766a84a7544a40b2f6bd569f652445db0bf291b979053
3
+ metadata.gz: 3c9205612f657c33c8668a8dc7ba9383087bfdf41e2889818db30840fa911857
4
+ data.tar.gz: '0283547ff021be8b728c25c51600eb0b6847f03311e8f039066eb130677d4426'
5
5
  SHA512:
6
- metadata.gz: 4bb0ceffc6ce1d7a0febdc9c82ed4a75cb1b26c610f9e0d53654a232b6e26048a594a5a231e67e3c4dc8fc300311a0066d7372c81b354f1b6799042467f41892
7
- data.tar.gz: 391b51c7cfc00469515ab17b3dfbff7ac15b79580a47b249d396e5a37253a04017e0f5129eab568efa5f9e9c69ffd1b4f930b64b5775e98888d5a8490e64560f
6
+ metadata.gz: 7c8a1585cc7343c4abeb65b3be3ae19767ab452b90b48aa7839addf20e23f38987e7e629ce2c6689d909f0c6b17f3b6951eaabac581ec394ba1495a2b0115701
7
+ data.tar.gz: ec03a4555165519f3455e630e4997150c1d44309c7f00bb6c652ae1c492e857392bfd26aeff56d9f675f5c0998cde1fcba623053dd933ed154e82e4ccb87dfd2
@@ -0,0 +1,22 @@
1
+ name: build
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ branches:
8
+ - master
9
+ jobs:
10
+ build:
11
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: [ '2.6', '3.0' ]
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /node_modules/
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.4
1
+ 3.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ### HEAD (not released yet)
4
+
5
+ ### v0.3.1
6
+ * Update javascript (chartkick v.4.1.0 & chart.js v.3.6.0)
7
+ * Update chartkick gem (4.1.0)
8
+
9
+ ### v0.3.0
10
+
11
+ * Update all javascript (chartkick v.4.0.5 & chart.js v.3.5.1)
12
+ * Use webpack to create javascript bundle
13
+ * Switch from travis to github actions
14
+
15
+ ### v0.2.1
16
+
17
+ * Only load JS scripts once
18
+
19
+ ### v0.2.0
20
+
21
+ * Support for area charts
22
+ * Support for scatter plots
23
+ * Support for timeline
24
+ * Support for geo charts
25
+ * Support for column charts
26
+ * Support keyword arguments for charts like height, width etc.
27
+
28
+ ### v0.1.0
29
+
30
+ * Initial version
31
+ * Support for line chart, bar chart and pie chart
data/Gemfile.lock CHANGED
@@ -1,47 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iruby-chartkick (0.1.0)
5
- chartkick
4
+ iruby-chartkick (0.3.1)
5
+ chartkick (~> 4.1.0)
6
6
  iruby
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- bond (0.5.1)
12
- chartkick (3.2.2)
11
+ chartkick (4.1.0)
13
12
  data_uri (0.1.0)
14
- diff-lcs (1.3)
15
- iruby (0.4.0)
16
- bond (~> 0.5)
13
+ diff-lcs (1.4.4)
14
+ ffi (1.15.4)
15
+ ffi-rzmq (2.0.7)
16
+ ffi-rzmq-core (>= 1.0.7)
17
+ ffi-rzmq-core (1.0.7)
18
+ ffi
19
+ io-console (0.5.9)
20
+ irb (1.3.7)
21
+ reline (>= 0.2.7)
22
+ iruby (0.7.4)
17
23
  data_uri (~> 0.1)
18
- mimemagic (~> 0.3)
24
+ ffi-rzmq
25
+ irb
26
+ mime-types (>= 3.3.1)
19
27
  multi_json (~> 1.11)
20
- mimemagic (0.3.3)
21
- multi_json (1.14.1)
22
- rake (10.5.0)
23
- rspec (3.9.0)
24
- rspec-core (~> 3.9.0)
25
- rspec-expectations (~> 3.9.0)
26
- rspec-mocks (~> 3.9.0)
27
- rspec-core (3.9.0)
28
- rspec-support (~> 3.9.0)
29
- rspec-expectations (3.9.0)
28
+ native-package-installer
29
+ mime-types (3.3.1)
30
+ mime-types-data (~> 3.2015)
31
+ mime-types-data (3.2021.0901)
32
+ multi_json (1.15.0)
33
+ native-package-installer (1.1.1)
34
+ rake (13.0.6)
35
+ reline (0.2.7)
36
+ io-console (~> 0.5)
37
+ rspec (3.10.0)
38
+ rspec-core (~> 3.10.0)
39
+ rspec-expectations (~> 3.10.0)
40
+ rspec-mocks (~> 3.10.0)
41
+ rspec-core (3.10.1)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-expectations (3.10.1)
30
44
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.9.0)
32
- rspec-mocks (3.9.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-mocks (3.10.2)
33
47
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-support (3.9.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-support (3.10.2)
36
50
 
37
51
  PLATFORMS
38
- ruby
52
+ x86_64-darwin-20
53
+ x86_64-linux
39
54
 
40
55
  DEPENDENCIES
41
56
  bundler
42
57
  iruby-chartkick!
43
- rake (~> 10.0)
58
+ rake (~> 13.0)
44
59
  rspec (~> 3.0)
45
60
 
46
61
  BUNDLED WITH
47
- 2.0.2
62
+ 2.2.15
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Robin Neumann
3
+ Copyright (c) 2019 Robin Stammer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # iruby-chartkick [![Build Status](https://travis-ci.com/Absolventa/iruby-chartkick.svg?branch=master)](https://travis-ci.com/Absolventa/iruby-chartkick)
1
+ # iruby-chartkick [![build](https://github.com/Absolventa/iruby-chartkick/actions/workflows/build.yml/badge.svg)](https://github.com/Absolventa/iruby-chartkick/actions/workflows/build.yml)
2
2
 
3
- You like writing [Ruby within Juypter](https://github.com/SciRuby/iruby/) notebooks? Awesome, you're not alone - we do so, too ☀️ Since we also fell in love with the handy charting API of [ankane/chartkick](https://github.com/ankane/chartkick), we wrote this little gem bringing them together.
3
+ You like writing [Ruby within Juypter](https://github.com/SciRuby/iruby/) notebooks? Awesome, you're not alone - we do so, too ☀️ Since we also fell in love with the handy charting API of [ankane/chartkick](https://github.com/ankane/chartkick), we wrote this little gem bringing them together.
4
4
 
5
5
  `iruby-chartkick` was made for easy plug-n-play plotting data using the awesomeness of chartkick within IRuby-backed Jupyter notebooks.
6
6
 
@@ -12,7 +12,7 @@ You like writing [Ruby within Juypter](https://github.com/SciRuby/iruby/) noteb
12
12
 
13
13
  You can either include the module `IRuby::Chartkick` and use the wrapper methods, like `line_chart`:
14
14
 
15
- ```Ruby
15
+ ```ruby
16
16
  include IRuby::Chartkick
17
17
 
18
18
  data = {
@@ -26,7 +26,7 @@ line_chart(data)
26
26
 
27
27
  Or you use the chart wrapper classes directly:
28
28
 
29
- ```Ruby
29
+ ```ruby
30
30
  include IRuby::Chartkick
31
31
 
32
32
  data = {
@@ -38,6 +38,99 @@ data = {
38
38
  IRuby::Chartkick::LineChart.new(data).plot
39
39
  ```
40
40
 
41
- ### In a Jupyter notebook:
41
+ ### Examples:
42
42
 
43
- ![Bildschirmfoto 2019-10-31 um 14 13 27](https://user-images.githubusercontent.com/3685123/67949871-d9688180-fbe8-11e9-9930-ceea4f42bf61.png)
43
+ ```ruby
44
+ include IRuby::Chartkick
45
+
46
+ data = [
47
+ {
48
+ name: "Monkeys",
49
+ data: {
50
+ 2010 => 20,
51
+ 2011 => 190,
52
+ 2012 => 188,
53
+ 2013 => 230,
54
+ 2014 => 422,
55
+ 2015 => 56,
56
+ 2016 => 299,
57
+ 2019 => 100
58
+ }
59
+ },
60
+ {
61
+ name: "Pirates",
62
+ data: {
63
+ 2010 => 20,
64
+ 2011 => 90,
65
+ 2012 => 488,
66
+ 2013 => 430,
67
+ 2014 => 122,
68
+ 2015 => 6,
69
+ 2016 => 399,
70
+ 2019 => 500
71
+ }
72
+ }
73
+ ]
74
+ ```
75
+
76
+ #### LineChart
77
+
78
+ ```ruby
79
+ line_chart(data)
80
+ ```
81
+ ![LineChart](https://user-images.githubusercontent.com/3856862/136750966-3fe8908d-356c-477e-8c0e-220bc302d07e.png)
82
+
83
+ ```ruby
84
+ line_chart(data, points: false)
85
+ ```
86
+ ![LineChart](https://user-images.githubusercontent.com/3856862/136767403-a2839f21-d6af-45af-a710-2f9f0ed2203c.png)
87
+
88
+ ```ruby
89
+ line_chart(data, points: false, width: "700px", min: 50, max: 300)
90
+ ```
91
+ ![LineChart](https://user-images.githubusercontent.com/3856862/136751184-7d96c152-ec1f-490a-9676-0ea16606addf.png)
92
+
93
+ #### AreaChart
94
+
95
+ ```ruby
96
+ area_chart(data)
97
+ ```
98
+ ![AreaChart](https://user-images.githubusercontent.com/3856862/136751437-9ceb092c-b1a1-4aee-a868-91a0ac3e9cbc.png)
99
+
100
+ #### ColumnChart
101
+
102
+ ```ruby
103
+ column_chart(data)
104
+ ```
105
+ ![ColumnChart](https://user-images.githubusercontent.com/3856862/136751574-252b40cb-b842-41ff-8a25-57695eb4e5b0.png)
106
+
107
+ #### BarChart
108
+
109
+ ```ruby
110
+ bar_chart(data)
111
+ ```
112
+ ![BarChart](https://user-images.githubusercontent.com/3856862/136751822-8383166d-894b-42fd-8ea7-fecf00964567.png)
113
+
114
+ #### ScatterChart
115
+
116
+ ```ruby
117
+ scatter_chart(data)
118
+ ```
119
+ ![ScatterChart](https://user-images.githubusercontent.com/3856862/136751938-35acbdc7-baee-4262-ac67-1fe1262f071c.png)
120
+
121
+ #### PieChart
122
+
123
+ ```ruby
124
+ include IRuby::Chartkick
125
+
126
+ data = [
127
+ ["Blueberry", 44],
128
+ ["Strawberry", 23],
129
+ ["Banana", 22],
130
+ ["Apple", 21],
131
+ ["Grape", 13]
132
+ ]
133
+
134
+ pie_chart(data)
135
+ ```
136
+ ![PieChart](https://user-images.githubusercontent.com/3856862/136752074-d5bc9ecb-b046-4b84-9108-546326125db4.png)
@@ -5,8 +5,8 @@ require "iruby/chartkick/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "iruby-chartkick"
7
7
  spec.version = IRuby::Chartkick::VERSION
8
- spec.authors = ["Robin Neumann\n"]
9
- spec.email = ["robin.neumann@posteo.de"]
8
+ spec.authors = ["Robin Stammer\n"]
9
+ spec.email = ["robin.stammer@posteo.de"]
10
10
 
11
11
  spec.summary = %q{Minimalistic wrapper around chartkick to use it within IRuby}
12
12
  spec.homepage = "https://github.com/Absolventa/iruby-chartkick"
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_runtime_dependency "iruby"
29
- spec.add_runtime_dependency "chartkick"
29
+ spec.add_dependency "chartkick", "~> 4.1.0"
30
30
 
31
31
  spec.add_development_dependency "bundler"
32
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
34
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module IRuby
3
+ module Chartkick
4
+ class AreaChart < IRuby::Chartkick::BaseChart
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + area_chart(@data, **ArgumentModifier[args, self]))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,8 +2,8 @@
2
2
  module IRuby
3
3
  module Chartkick
4
4
  class BarChart < IRuby::Chartkick::BaseChart
5
- def plot
6
- ::IRuby.html(js_prefix + bar_chart(@data, id: randomized_dom_id))
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + bar_chart(@data, **ArgumentModifier[args, self]))
7
7
  end
8
8
  end
9
9
  end
@@ -4,38 +4,37 @@ module IRuby
4
4
  class BaseChart
5
5
  include ::Chartkick::Helper
6
6
 
7
+ ArgumentModifier = ->(args, callee) do
8
+ modified = args.inject({}) do |sum, item|
9
+ item.each do |k, v|
10
+ sum[k] = v
11
+ end
12
+ sum
13
+ end
14
+ modified[:id] = callee.randomized_dom_id
15
+ modified
16
+ end
17
+
7
18
  def initialize(data)
8
19
  @data = data
9
20
  end
10
21
 
11
22
  def js_prefix
23
+ return "" if IRuby::Chartkick.js_loaded?
24
+ IRuby::Chartkick.mark_js_as_loaded
25
+
12
26
  <<-JS
13
- <script type="text/javascript">
14
- #{adapter_javascript}
15
- </script>
16
- <script type="text/javascript">
17
- #{chartkick_javascript}
27
+ <script name="iruby-chartkick-charting-engine-loaders" type="text/javascript">
28
+ #{javascript}
18
29
  </script>
19
30
  JS
20
31
  end
21
32
 
22
- def javascripts
23
- [
24
- adapter_javascript,
25
- chartkick_javascript
26
- ]
27
- end
28
-
29
- def adapter_javascript
30
- adapter_js_path = File.join(File.dirname(__FILE__), "..", "..", "..", "vendor", "assets", "javascripts", "adapter.js")
33
+ def javascript
34
+ adapter_js_path = File.join(File.dirname(__FILE__), "..", "..", "..", "vendor", "assets", "javascripts", "bundle.js")
31
35
  File.read(adapter_js_path)
32
36
  end
33
37
 
34
- def chartkick_javascript
35
- chartkick_js_path = File.join(File.dirname(__FILE__), "..", "..", "..", "vendor", "assets", "javascripts", "chartkick.js")
36
- File.read(chartkick_js_path)
37
- end
38
-
39
38
  def randomized_dom_id
40
39
  "#{self.class.to_s.downcase.gsub("::", "-")}-#{rand(100000)}"
41
40
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module IRuby
3
+ module Chartkick
4
+ class ColumnChart < IRuby::Chartkick::BaseChart
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + column_chart(@data, **ArgumentModifier[args, self]))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module IRuby
3
+ module Chartkick
4
+ class GeoChart < IRuby::Chartkick::BaseChart
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + geo_chart(@data, **ArgumentModifier[args, self]))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,8 +2,8 @@
2
2
  module IRuby
3
3
  module Chartkick
4
4
  class LineChart < IRuby::Chartkick::BaseChart
5
- def plot
6
- ::IRuby.html(js_prefix + line_chart(@data, id: randomized_dom_id))
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + line_chart(@data, **ArgumentModifier[args, self]))
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
  module IRuby
3
3
  module Chartkick
4
4
  class PieChart < IRuby::Chartkick::BaseChart
5
- def plot
6
- ::IRuby.html(js_prefix + pie_chart(@data, id: randomized_dom_id))
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + pie_chart(@data, **ArgumentModifier[args, self]))
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module IRuby
3
+ module Chartkick
4
+ class ScatterChart < IRuby::Chartkick::BaseChart
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + scatter_chart(@data, **ArgumentModifier[args, self]))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module IRuby
3
+ module Chartkick
4
+ class Timeline < IRuby::Chartkick::BaseChart
5
+ def plot(*args)
6
+ ::IRuby.html(js_prefix + timeline(@data, **ArgumentModifier[args, self]))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module IRuby
3
3
  module Chartkick
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
6
6
  end
@@ -5,20 +5,61 @@ require "iruby/chartkick/version"
5
5
  require "iruby/chartkick/base_chart"
6
6
  require "iruby/chartkick/line_chart"
7
7
  require "iruby/chartkick/bar_chart"
8
+ require "iruby/chartkick/column_chart"
8
9
  require "iruby/chartkick/pie_chart"
10
+ require "iruby/chartkick/area_chart"
11
+ require "iruby/chartkick/scatter_chart"
12
+ require "iruby/chartkick/geo_chart"
13
+ require "iruby/chartkick/timeline"
9
14
 
10
15
  module IRuby
11
16
  module Chartkick
12
- def line_chart(data)
13
- LineChart.new(data).plot
17
+ class << self
18
+ def js_loaded?
19
+ @@js_loaded
20
+ end
21
+
22
+ def mark_js_as_loaded
23
+ @@js_loaded = true
24
+ end
25
+
26
+ def mark_js_as_unloaded
27
+ @@js_loaded = false
28
+ end
29
+ end
30
+
31
+ mark_js_as_unloaded
32
+
33
+ def line_chart(data, **args)
34
+ LineChart.new(data).plot(**args)
35
+ end
36
+
37
+ def bar_chart(data, **args)
38
+ BarChart.new(data).plot(**args)
39
+ end
40
+
41
+ def column_chart(data, **args)
42
+ ColumnChart.new(data).plot(**args)
43
+ end
44
+
45
+ def pie_chart(data, **args)
46
+ PieChart.new(data).plot(**args)
47
+ end
48
+
49
+ def area_chart(data, **args)
50
+ AreaChart.new(data).plot(**args)
51
+ end
52
+
53
+ def scatter_chart(data, **args)
54
+ ScatterChart.new(data).plot(**args)
14
55
  end
15
56
 
16
- def bar_chart(data)
17
- BarChart.new(data).plot
57
+ def geo_chart(data, **args)
58
+ GeoChart.new(data).plot(**args)
18
59
  end
19
60
 
20
- def pie_chart(data)
21
- PieChart.new(data).plot
61
+ def timeline(data, **args)
62
+ Timeline.new(data).plot(**args)
22
63
  end
23
64
  end
24
65
  end