chart_bibz 0.1.0 → 0.1.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: 6df699587ec922c251c5c46d1a9b07dfec59e7af8f555df7b9e89543bd5f62ae
4
- data.tar.gz: 1aec799a23b9c11c098a4e0b0cbd2f7fd3eec856828bce253a8b276ed0a715e4
3
+ metadata.gz: 8340301db148379344f907087206294a3f9936ab872e7ba093224fba40623d5a
4
+ data.tar.gz: 9bec2b998ced586af65237ccd0667da5658cafdb8a25c205debe670fdc0601e0
5
5
  SHA512:
6
- metadata.gz: c4e53911af3059f3afbcb0d57212a8526734872b50025d05cc30b9522882f6414f6c60907b9e69bc318dc3d770fa7c5e67efc22e814948c2bc8fec4a6a6ee7d7
7
- data.tar.gz: 97078b7ebe824c85587fcc9ef96b0392be653b09fe0a79b19107186afc1c1b109d03195d820bd8e4d517e8253849a82daed55da1b87133c5b85592eabd99a576
6
+ metadata.gz: bfe263f9fe1f7ae798630a32c82af6b8b3e95b058bad2b93afbb6bfa8f9d89e41376bbda4d411af4cc908c47bdc1b923c8f35a515b24c611773003405f2259b1
7
+ data.tar.gz: 996431bc8d191d857c75554de16c1f458d19c37cf4e60239432f56b917c30cf5c0ee3d9d6d89ff5bb702e937216f685584a464586d481b7fa1f4156310ca3452
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'chart_bibz/railtie'
4
4
 
5
+ # The Main module for ChartBibz
5
6
  module ChartBibz
6
7
  extend ActiveSupport::Autoload
7
8
 
@@ -1,8 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The Main module
3
4
  module ChartBibz
5
+ # Add the Helpers module to Chart Bibz
4
6
  module Helpers
5
- module ChartHelper # rubocop:disable Style/Documentation
7
+ # Helper for chart bibz
8
+ module ChartHelper
9
+ # Generate the html of the canvas
10
+ #
11
+ # @example Generate the canvas
12
+ # chart {datasets: {data: [1,2,3]}}, {type: :bar}, {class: "My-chart"}
13
+ #
14
+ # @see ChartBibz::ViewComponents::ChartViewComponent#initialize
15
+ #
16
+ # @param [Hash] data
17
+ # @param [Hash] options
18
+ # @param [Hash] html_options
19
+ # @return [String] HTML
20
+ #
21
+ # @api public
6
22
  def chart(data = {}, options = {}, html_options = {})
7
23
  ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options).render
8
24
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The Main Module
3
4
  module ChartBibz
4
- VERSION = '0.1.0'
5
+ # The current version of Chart Bibz
6
+ VERSION = '0.1.1'
5
7
  end
@@ -1,16 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChartBibz
4
+ # A batch of view components
4
5
  module ViewComponents
5
- class ApplicationViewComponent # rubocop:disable Style/Documentation
6
+ # The view components base
7
+ class ApplicationViewComponent
6
8
  include ActionView::Helpers::TagHelper
7
9
  include ActionView::Helpers::CaptureHelper
8
10
  include ActionView::Helpers::TextHelper
9
11
  include ActionView::Helpers::TranslationHelper
12
+
13
+ # ActionView::Helpers::TagHelper need of this
14
+ #
15
+ # @example
16
+ # tag.div "content"
17
+ #
18
+ # @param [Object] output_buffer
19
+ # @return [Object] the output_buffer
20
+ #
21
+ # @api public
10
22
  attr_accessor :output_buffer
11
23
 
12
24
  protected
13
25
 
26
+ # Create a list of classes in a string
27
+ #
28
+ # @example Generate the canves
29
+ # join_classes(["test1", "test2"], :test3, "test4")
30
+ #
31
+ # @param [String, Symbol, Hash] classes The class names
32
+ # @return [String] The list of the classes
33
+ #
34
+ # @api semipublic
14
35
  def join_classes(*classes)
15
36
  klasses = Array(classes).flatten.map(&:to_s).compact.uniq.reject(&:blank?)
16
37
  klasses.empty? ? nil : klasses
@@ -5,33 +5,64 @@ module ChartBibz
5
5
  # Generate the canvas view through the render method
6
6
  class CanvasViewComponent < ApplicationViewComponent
7
7
  # Constants
8
- WIDTH = 400
9
- HEIGHT = 400
10
8
 
11
- # @param args [Hash] The html options
9
+ WIDTH = 400 # Default width for the html canvas
10
+ HEIGHT = 400 # Default height for the html canvas
11
+
12
+ # Only html_options can be passed
13
+ #
14
+ # @example
15
+ # ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test')
16
+ #
17
+ # @param [Hash] args The html options
12
18
  # @return [void]
19
+ #
20
+ # @api public
13
21
  def initialize(args = {})
14
22
  @args = args
15
23
  end
16
24
 
17
25
  # Generate the html canvas
26
+ #
27
+ # @example
28
+ # ChartBibz::ViewComponents::CanvasViewComponent.new(class:
29
+ # 'test').render
30
+ #
18
31
  # @return [String] The html canvas
32
+ #
33
+ # @api public
19
34
  def render
20
35
  tag.canvas(**html_options)
21
36
  end
22
37
 
38
+ # Get the id
39
+ #
40
+ # @example
41
+ # ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test').id
42
+ #
23
43
  # @return [String] The canvas html id
44
+ #
45
+ # @api public
24
46
  def id
25
47
  html_options[:id]
26
48
  end
27
49
 
28
50
  private
29
51
 
52
+ # Get all html options
53
+ #
30
54
  # @return [String] The canvas html attributes
55
+ #
56
+ # @api private
31
57
  def html_options
32
58
  @html_options ||= base_html_options.merge(@args).merge(class: join_classes('chart-bibz', @args[:class]))
33
59
  end
34
60
 
61
+ # Get the html options base
62
+ #
63
+ # @return [String] The canvas html attributes
64
+ #
65
+ # @api private
35
66
  def base_html_options
36
67
  { id: "chart-#{Random.uuid}", width: WIDTH, height: HEIGHT, role: 'img' }
37
68
  end
@@ -7,6 +7,11 @@ module ChartBibz
7
7
  # @see CanvasViewComponent#id
8
8
  delegate :id, to: :canvas
9
9
 
10
+ # Need of CanvasViewComponent to work
11
+ #
12
+ # @example
13
+ # ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options)
14
+ #
10
15
  # @param data [Hash] the chartjs data
11
16
  # @param options [Hash] the chartjs options
12
17
  # @option options [Symbol] :type The chart type [:bar, :line, ...]
@@ -16,24 +21,45 @@ module ChartBibz
16
21
  # @option html_options [String] :class The class of the canvas
17
22
  #
18
23
  # @return [void]
24
+ #
25
+ # @api public
19
26
  def initialize(data = {}, options = {}, html_options = {})
20
27
  @data = data
21
28
  @options = options
22
29
  @html_options = html_options
23
30
  end
24
31
 
32
+ # Generate the html canvas
33
+ #
34
+ # @example
35
+ # ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options).render
36
+ #
37
+ # @see ChartBibz::ViewComponents::CanvasViewComponent#canvas
25
38
  # @return [String] The canvas html
39
+ #
40
+ # @api public
26
41
  delegate :render, to: :canvas
27
42
 
43
+ # Get the Canvas with new html_options
44
+ #
45
+ # @example
46
+ # ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options).canvas
47
+ #
28
48
  # @see CanvasViewComponent
29
49
  # @return [Object] The canvas object
50
+ #
51
+ # @api public
30
52
  def canvas
31
53
  @canvas ||= CanvasViewComponent.new(new_html_options)
32
54
  end
33
55
 
34
56
  private
35
57
 
58
+ # Update html_options
59
+ #
36
60
  # @return [Hash] The new html options with the data attributes
61
+ #
62
+ # @api private
37
63
  def new_html_options
38
64
  @html_options['data-cb-data'] = @data.to_json
39
65
  @html_options['data-cb-type'] = @options.delete(:type) || :bar
@@ -42,6 +68,11 @@ module ChartBibz
42
68
  @html_options
43
69
  end
44
70
 
71
+ # Create an aria lable
72
+ #
73
+ # @return [String]
74
+ #
75
+ # @api private
45
76
  def aria_label
46
77
  @options[:title].nil? ? 'Chart' : "Chart of #{@options[:title]}"
47
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chart_bibz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas HUMMEL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: overcommit
@@ -142,6 +142,20 @@ dependencies:
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: yard
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
145
159
  description: ChartJs with ruby.
146
160
  email:
147
161
  - thomas@hummel.link