Class: RailsDataExplorer::Exploration

Inherits:
Object
  • Object
show all
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).



40
41
42
43
44
45
# File 'lib/rails_data_explorer/exploration.rb', line 40

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.



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

def charts
  @charts
end

#data_setObject

Returns the value of attribute data_set.



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

def data_set
  @data_set
end

#titleObject

Returns the value of attribute title.



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

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)


24
25
26
# File 'lib/rails_data_explorer/exploration.rb', line 24

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



52
53
54
# File 'lib/rails_data_explorer/exploration.rb', line 52

def dom_id
  self.class.compute_dom_id(data_series_names)
end

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



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails_data_explorer/exploration.rb', line 56

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

#render_charts?Boolean

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/rails_data_explorer/exploration.rb', line 48

def render_charts?
  @render_charts
end

#type_of_analysisObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rails_data_explorer/exploration.rb', line 68

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