Class: ChartBibz::ViewComponents::ChartViewComponent

Inherits:
ApplicationViewComponent show all
Defined in:
lib/chart_bibz/view_components/chart_view_component.rb

Overview

Generate the chart view through the render method

Instance Attribute Summary

Attributes inherited from ApplicationViewComponent

#output_buffer

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, options = {}, html_options = {}) ⇒ void

Parameters:

  • data (Hash) (defaults to: {})

    the chartjs data

  • options (Hash) (defaults to: {})

    the chartjs options

  • html_options (Hash) (defaults to: {})

    the html_options of the canvas

Options Hash (options):

  • :type (Symbol)

    The chart type [:bar, :line, …]

Options Hash (html_options):

  • :id (String)

    The id of the canvas

  • :class (String)

    The class of the canvas



19
20
21
22
23
# File 'lib/chart_bibz/view_components/chart_view_component.rb', line 19

def initialize(data = {}, options = {}, html_options = {})
  @data = data
  @options = options
  @html_options = html_options
end

Instance Method Details

#canvasObject

Returns The canvas object.

Returns:

  • (Object)

    The canvas object

See Also:



30
31
32
# File 'lib/chart_bibz/view_components/chart_view_component.rb', line 30

def canvas
  @canvas ||= CanvasViewComponent.new(new_html_options)
end

#renderString

Returns The canvas html.

Returns:

  • (String)

    The canvas html



26
# File 'lib/chart_bibz/view_components/chart_view_component.rb', line 26

delegate :render, to: :canvas