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

Need of CanvasViewComponent to work

Examples:

ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options)

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



26
27
28
29
30
# File 'lib/chart_bibz/view_components/chart_view_component.rb', line 26

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

Instance Method Details

#canvasObject

Get the Canvas with new html_options

Examples:

ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options).canvas

Returns:

  • (Object)

    The canvas object

See Also:



52
53
54
# File 'lib/chart_bibz/view_components/chart_view_component.rb', line 52

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

#renderString

Generate the html canvas

Examples:

ChartBibz::ViewComponents::ChartViewComponent.new(data, options, html_options).render

Returns:

  • (String)

    The canvas html

See Also:

  • ChartBibz::ViewComponents::CanvasViewComponent#canvas


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

delegate :render, to: :canvas