Class: Trackplot::PhlexComponent
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Trackplot::PhlexComponent
- Defined in:
- lib/trackplot/phlex_component.rb
Instance Method Summary collapse
-
#initialize(data:, **options, &block) ⇒ PhlexComponent
constructor
A new instance of PhlexComponent.
- #view_template ⇒ Object
Constructor Details
#initialize(data:, **options, &block) ⇒ PhlexComponent
Returns a new instance of PhlexComponent.
10 11 12 13 14 |
# File 'lib/trackplot/phlex_component.rb', line 10 def initialize(data:, **, &block) @data = data @options = @block = block end |
Instance Method Details
#view_template ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trackplot/phlex_component.rb', line 16 def view_template builder = ChartBuilder.new(@data, **@options) @block&.call(builder) config = builder.send(:build_config) chart_id = @options[:id] || "trackplot-#{SecureRandom.hex(8)}" width = @options[:width] || "100%" height = @options[:height] || "400px" tag( "trackplot-chart", id: chart_id, config: config.to_json, style: "display:block;width:#{width};height:#{height};", class: ["trackplot-chart", @options[:class]].compact.join(" "), role: @options[:title] ? "img" : nil, **aria_attributes ) end |