Class: Jav::Dashboards::ChartkickCard

Inherits:
BaseCard
  • Object
show all
Defined in:
lib/jav/dashboards/chartkick_card.rb

Instance Attribute Summary

Attributes inherited from BaseCard

#arguments, #dashboard, #index, #options, #params

Instance Method Summary collapse

Methods inherited from BaseCard

#call_block, #card_classes, #compute_result, #description, #frame_url, #hydrate, #initialize, #is_card?, #is_divider?, #label, query, #range, #refresh_every, #result, #turbo_frame, #type, #visible

Methods included from Concerns::VisibleInDashboard

#call_block, #is_hidden?, #is_visible?

Constructor Details

This class inherits a constructor from Jav::BaseCard

Instance Method Details

#chartkick_classesObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jav/dashboards/chartkick_card.rb', line 12

def chartkick_classes
  case chart_type
  when :area_chart, :line_chart, :scatter_chart, :bar_chart, :column_chart
    if self.class.flush
      "-mx-1.5 top-auto -bottom-1.5"
    else
      "px-2"
    end
  else
    ""
  end
end

#chartkick_optionsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jav/dashboards/chartkick_card.rb', line 25

def chartkick_options
  card_height = 144
  card_heading = 40

  default = {
    # figure our the available height for the chart
    height: "#{(rows * card_height) - card_heading}px",
    colors: ::Jav.configuration.branding.chart_colors,
    library: {
      discrete: false,
      points: false,
      animation: true
    },
    id: "#{dashboard.id}-#{rand(10_000..99_999)}"
  }

  no_scale_options = { display: false }
  no_scale = {
    library: {
      scales: {
        x: no_scale_options,
        y: no_scale_options
      }
    }
  }

  no_legend = { library: { plugins: { legend: { display: false } } } }
  legend_on_left = { library: { plugins: { legend: { position: "left" } } } }
  legend_on_right = { library: { plugins: { legend: { position: "right" } } } }

  # Add chart.js configuration for the different states
  default = default.deep_merge(no_legend) unless self.class.legend

  default = default.deep_merge(no_scale) unless self.class.scale

  default = default.deep_merge(legend_on_left) if self.class.legend_on_left

  default = default.deep_merge(legend_on_right) if self.class.legend_on_right

  # Add the custom chart options at the end
  default.deep_merge(self.class.chart_options)
end