class ChartBibz::ViewComponents::CanvasViewComponent
Generate the canvas view through the render method
Constants
- HEIGHT
- WIDTH
Constants
Public Class Methods
new(args = {})
click to toggle source
Only html_options
can be passed
@example
ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test')
@param [Hash] args The html options @return [void]
@api public
# File lib/chart_bibz/view_components/canvas_view_component.rb, line 21 def initialize(args = {}) @args = args end
Public Instance Methods
id()
click to toggle source
Get the id
@example
ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test').id
@return [String] The canvas html id
@api public
# File lib/chart_bibz/view_components/canvas_view_component.rb, line 46 def id html_options[:id] end
render()
click to toggle source
Generate the html canvas
@example
ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test').render
@return [String] The html canvas
@api public
# File lib/chart_bibz/view_components/canvas_view_component.rb, line 34 def render tag.canvas(**html_options) end
Private Instance Methods
base_html_options()
click to toggle source
Get the html options base
@return [String] The canvas html attributes
@api private
# File lib/chart_bibz/view_components/canvas_view_component.rb, line 66 def base_html_options { id: "chart-#{Random.uuid}", width: WIDTH, height: HEIGHT, role: 'img' } end
html_options()
click to toggle source
Get all html options
@return [String] The canvas html attributes
@api private
# File lib/chart_bibz/view_components/canvas_view_component.rb, line 57 def html_options @html_options ||= base_html_options.merge(@args).merge(class: join_classes('chart-bibz', @args[:class])) end