Class: Keystone::Ui::LineChartComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Keystone::Ui::LineChartComponent
- Defined in:
- app/components/keystone/ui/line_chart_component.rb
Constant Summary collapse
- HEIGHT_CLASSES =
{ sm: "h-48", md: "h-64", lg: "h-96" }.freeze
- DASH_PATTERN =
[ 6, 6 ].freeze
Instance Method Summary collapse
- #chart_data ⇒ Object
- #chart_data_json ⇒ Object
- #container_classes ⇒ Object
- #height_class ⇒ Object
-
#initialize(series:, labels:, height: :md) ⇒ LineChartComponent
constructor
A new instance of LineChartComponent.
Constructor Details
#initialize(series:, labels:, height: :md) ⇒ LineChartComponent
Returns a new instance of LineChartComponent.
16 17 18 19 20 |
# File 'app/components/keystone/ui/line_chart_component.rb', line 16 def initialize(series:, labels:, height: :md) @series = series @labels = labels @height = height end |
Instance Method Details
#chart_data ⇒ Object
22 23 24 |
# File 'app/components/keystone/ui/line_chart_component.rb', line 22 def chart_data { labels: @labels, datasets: @series.map { |s| dataset_for(s) } } end |
#chart_data_json ⇒ Object
26 27 28 |
# File 'app/components/keystone/ui/line_chart_component.rb', line 26 def chart_data_json chart_data.to_json end |
#container_classes ⇒ Object
34 35 36 |
# File 'app/components/keystone/ui/line_chart_component.rb', line 34 def container_classes "#{height_class} relative w-full min-w-0" end |
#height_class ⇒ Object
30 31 32 |
# File 'app/components/keystone/ui/line_chart_component.rb', line 30 def height_class HEIGHT_CLASSES.fetch(@height) end |