Class: Keystone::Ui::LineChartComponent

Inherits:
ViewComponent::Base
  • Object
show all
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

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_dataObject



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_jsonObject



26
27
28
# File 'app/components/keystone/ui/line_chart_component.rb', line 26

def chart_data_json
  chart_data.to_json
end

#container_classesObject



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_classObject



30
31
32
# File 'app/components/keystone/ui/line_chart_component.rb', line 30

def height_class
  HEIGHT_CLASSES.fetch(@height)
end