Class: RCharts::GraphHelper::Graph::Axes

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/rcharts/graph_helper/graph/axes.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(graphable = {}, axis_options = {}) ⇒ Axes

Returns a new instance of Axes.



9
10
11
12
13
# File 'app/helpers/rcharts/graph_helper/graph/axes.rb', line 9

def initialize(graphable = {}, axis_options = {})
  @axes = Options.new(graphable.keys, axis_options).to_h do |name, axes|
    [name, axes.collect { |index, options| build_axis(graphable:, name:, index:, **options) }]
  end
end

Instance Method Details

#continuousObject



24
25
26
# File 'app/helpers/rcharts/graph_helper/graph/axes.rb', line 24

def continuous
  fetch(:y).then { !it.discrete? && it } || axes.values.flatten.find { !it.discrete? } || fetch(:y)
end

#discreteObject



20
21
22
# File 'app/helpers/rcharts/graph_helper/graph/axes.rb', line 20

def discrete
  fetch(:x).then { it.discrete? && it } || axes.values.flatten.find(&:discrete?) || fetch(:x)
end

#fetch(name, index = 0) ⇒ Object



15
16
17
18
# File 'app/helpers/rcharts/graph_helper/graph/axes.rb', line 15

def fetch(name, index = 0)
  axes.fetch(name) { raise ArgumentError, "Unknown axis #{name}" }
      .fetch(index) { raise ArgumentError, "Unknown index #{index} for axis #{name}" }
end