Class: ReportsKit::Reports::Data::ChartOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/reports_kit/reports/data/chart_options.rb

Constant Summary collapse

DEFAULT_COLORS =
%w(
  #1f77b4
  #aec7e8
  #ff7f0e
  #ffbb78
  #2ca02c
  #98df8a
  #d62728
  #ff9896
  #9467bd
  #c5b0d5
  #8c564b
  #c49c94
  #e377c2
  #f7b6d2
  #7f7f7f
  #c7c7c7
  #bcbd22
  #dbdb8d
  #17becf
  #9edae5
).freeze
DEFAULT_OPTIONS =
{
  scales: {
    xAxes: [{
      gridLines: {
        display: false
      },
      barPercentage: 0.9,
      categoryPercentage: 0.9
    }],
    yAxes: [{
      ticks: {
        beginAtZero: true
      }
    }]
  },
  legend: {
    labels: {
      usePointStyle: true
    }
  },
  maintainAspectRatio: false,
  tooltips: {
    xPadding: 8,
    yPadding: 7
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options:, inferred_options: {}) ⇒ ChartOptions



56
57
58
59
60
61
62
63
64
# File 'lib/reports_kit/reports/data/chart_options.rb', line 56

def initialize(data, options:, inferred_options: {})
  self.data = data
  self.options = options.try(:except, :options) || {}
  self.chart_options = options.try(:[], :options) || {}
  self.dataset_options = options.try(:[], :datasets)
  self.type = options.try(:[], :type) || 'bar'

  self.options = inferred_options.deep_merge(self.options) if inferred_options.present?
end

Instance Attribute Details

#chart_optionsObject

Returns the value of attribute chart_options.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def chart_options
  @chart_options
end

#dataObject

Returns the value of attribute data.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def data
  @data
end

#dataset_optionsObject

Returns the value of attribute dataset_options.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def dataset_options
  @dataset_options
end

#inferred_optionsObject

Returns the value of attribute inferred_options.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def inferred_options
  @inferred_options
end

#optionsObject

Returns the value of attribute options.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def options
  @options
end

#typeObject

Returns the value of attribute type.



54
55
56
# File 'lib/reports_kit/reports/data/chart_options.rb', line 54

def type
  @type
end

Instance Method Details

#performObject



66
67
68
69
70
71
72
# File 'lib/reports_kit/reports/data/chart_options.rb', line 66

def perform
  set_colors
  set_chart_options
  set_dataset_options
  set_type
  data
end