Class: RailsDataExplorer::Exploration

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/rails_data_explorer/exploration.rb

Overview

Responsibilities:

* Represent and initialize a data exploration
* Initialize and render self (including charts)

Collaborators:

* DataSet
* Chart

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_title, data_set_or_array, render_charts, chart_specs = nil) ⇒ Exploration

Initializes a new visualization.

Parameters:

  • _title (String)

    will be printed at top of visualization

  • data_set_or_array (Array)

    can be a number of things:

    • Array<Scalar> - for single data series, uni-variate options are applied.

    • Array<Hash> - for multiple data series, bi/multi-variate options are applied.

    • DataSet - For finer grained control.

  • render_charts (Boolean)

    set to true to render charts for this exploration

  • chart_specs (Array<Chart, String, Symbol>, optional) (defaults to: nil)

    The list of charts to include. Defaults to all applicable charts for the given data_set_or_array. Charts can be provided as Array of Strings, Symbols, or Chart classes (can be mixed).



42
43
44
45
46
47
# File 'lib/rails_data_explorer/exploration.rb', line 42

def initialize(_title, data_set_or_array, render_charts, chart_specs=nil)
  @title = _title
  @data_set = initialize_data_set(data_set_or_array)
  @render_charts = render_charts
  @charts = initialize_charts(chart_specs)
end

Instance Attribute Details

#chartsObject

Returns the value of attribute charts.



18
19
20
# File 'lib/rails_data_explorer/exploration.rb', line 18

def charts
  @charts
end

#data_setObject

Returns the value of attribute data_set.



18
19
20
# File 'lib/rails_data_explorer/exploration.rb', line 18

def data_set
  @data_set
end

#output_bufferObject

required for content_tag



15
16
17
# File 'lib/rails_data_explorer/exploration.rb', line 15

def output_buffer
  @output_buffer
end

#titleObject

Returns the value of attribute title.



18
19
20
# File 'lib/rails_data_explorer/exploration.rb', line 18

def title
  @title
end

Class Method Details

.compute_dom_id(data_series_names) ⇒ String

Computes a dom_id for data_series_names

Parameters:

  • data_series_names (Array<String>)

Returns:

  • (String)


26
27
28
# File 'lib/rails_data_explorer/exploration.rb', line 26

def self.compute_dom_id(data_series_names)
  "rde-exploration-#{ data_series_names.sort.map { |e| e.parameterize('') }.join('-') }"
end

Instance Method Details

#dom_idObject



70
71
72
# File 'lib/rails_data_explorer/exploration.rb', line 70

def dom_id
  self.class.compute_dom_id(data_series_names)
end

#inspect(indent = 1, recursive = 1000) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rails_data_explorer/exploration.rb', line 74

def inspect(indent=1, recursive=1000)
  r = %(#<#{ self.class.to_s }\n)
  r << [
    "@title=#{ @title.inspect }",
  ].map { |e| "#{ '  ' * indent }#{ e }\n"}.join
  if recursive > 0
    r << %(#{ '  ' * indent }@data_set=)
    r << data_set.inspect(indent + 1, recursive - 1)
  end
  r << %(#{ '  ' * (indent-1) }>\n)
end

#renderObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_data_explorer/exploration.rb', line 49

def render
  (:div, class: 'rde-exploration panel panel-default', id: dom_id) do
    (:div, class: 'panel-heading') do
      %(<span style="float: right;"><a href="#rails_data_explorer-toc">Top</a></span>).html_safe +
      (:h2, @title, class: 'rde-exploration-title panel-title')
    end +
    (:div, class: 'panel-body') do
      if @charts.any?
        @charts.map { |e| e.render }.join.html_safe
      else
        "No charts are available for this combination of data series."
      end
    end
  end.html_safe
end

#render_charts?Boolean

Returns true if charts for this exploration are to be rendered.

Returns:

  • (Boolean)


66
67
68
# File 'lib/rails_data_explorer/exploration.rb', line 66

def render_charts?
  @render_charts
end

#type_of_analysisObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rails_data_explorer/exploration.rb', line 86

def type_of_analysis
  case @data_set.dimensions_count
  when 0
    '[No data given]'
  when 1
    'Univariate'
  when 2
    'Bivariate'
  else
    'Multivariate'
  end
end