class ApexCharts::Charts::MixedCharts

Public Class Methods

new(outer_self, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 10
def initialize(outer_self, options={}, &block)
  @outer_self = outer_self
  @series = {series: []}
  options[:id] ||= apexcharts_id
  build_instance_variables

  instance_eval &block

  options[:annotations] = @annotations if @annotations
  @options = build_options(options)

  build_selection_range if brush?
end

Public Instance Methods

area_chart(data, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 34
def area_chart(data, options={}, &block)
  outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
  @series[:series] +=
    AreaChart.new(outer_self, data, options, &block).mixed_series
end
bar_chart(data, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 40
def bar_chart(data, options={}, &block)
  outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
  @series[:series] +=
    BarChart.new(outer_self, data, options, &block).mixed_series
end
chart_type() click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 24
def chart_type
  'area' # chosen default
end
column_chart(data, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 46
def column_chart(data, options={}, &block)
  outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
  @series[:series] +=
    ColumnChart.new(outer_self, data, options, &block).mixed_series
end
line_chart(data, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 28
def line_chart(data, options={}, &block)
  outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
  @series[:series] +=
    LineChart.new(outer_self, data, options, &block).mixed_series
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/apex_charts/charts/mixed_charts.rb, line 58
def method_missing(method, *args, &block)
  if @outer_self.respond_to?(method, true)
    @outer_self.send method, *args, &block
  else
    super
  end
end
respond_to_missing?(method, *args) click to toggle source
Calls superclass method
# File lib/apex_charts/charts/mixed_charts.rb, line 66
def respond_to_missing?(method, *args)
  @outer_self.respond_to?(method, true) || super
end
scatter_chart(data, options={}, &block) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 52
def scatter_chart(data, options={}, &block)
  outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
  @series[:series] +=
    ScatterChart.new(outer_self, data, options, &block).mixed_series
end

Private Instance Methods

brush?() click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 78
def brush?
  @options[:chart][:brush]&.[](:enabled) &&
    !@options[:chart][:selection]&.[](:xaxis)
end
build_instance_variables() click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 72
def build_instance_variables
  (@outer_self.instance_variables - instance_variables).each do |i|
    instance_variable_set(i, @outer_self.instance_variable_get(i))
  end
end
build_selection_range() click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 83
def build_selection_range
  last_data = @series[:series].last[:data]
  first_x = last_data.first[:x]
  last_x = last_data.last[:x]
  @options[:chart][:selection][:xaxis] = {
    min: handle_time(twenty_percent_before_last_x(first_x, last_x)),
    max: handle_time(last_x)
  }
end
handle_time(input) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 97
def handle_time(input)
  ApexCharts::Utils::DateTime.convert(input)
end
twenty_percent_before_last_x(first, last) click to toggle source
# File lib/apex_charts/charts/mixed_charts.rb, line 93
def twenty_percent_before_last_x(first, last)
  last - (0.2 * (last - first))
end