Class: PhlexKit::Chart
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Chart
- Defined in:
- app/components/phlex_kit/chart/chart.rb
Overview
Chart, ported from ruby_ui's RubyUI::Chart — as a thin wrapper only. ruby_ui bundles chart.js; this kit deliberately does NOT (no charting dependency). It renders the
* if the host exposes chart.js as `window.Chart`, builds the chart with
ruby_ui's token-derived default colors (mapped to --pk-*), re-rendering
on theme change;
* otherwise dispatches "phlex-kit--chart:connect" with { canvas, options }
so the host can drive any charting library it ships.
render PhlexKit::Chart.new(options: { type: "line", data: { labels: [...],
datasets: [{ data: [...] }] } })
Instance Method Summary collapse
-
#initialize(options: {}, **attrs) ⇒ Chart
constructor
A new instance of Chart.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(options: {}, **attrs) ⇒ Chart
Returns a new instance of Chart.
16 17 18 19 |
# File 'app/components/phlex_kit/chart/chart.rb', line 16 def initialize(options: {}, **attrs) @options = @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/components/phlex_kit/chart/chart.rb', line 21 def view_template(&) canvas(**mix({ class: "pk-chart", data: { controller: "phlex-kit--chart", phlex_kit__chart_options_value: JSON.generate(@options) } }, @attrs), &) end |