Class: RailsDataExplorer::DataType::Quantitative::Temporal

Inherits:
RailsDataExplorer::DataType::Quantitative show all
Defined in:
lib/rails_data_explorer/data_type/quantitative/temporal.rb

Overview

Responsibilities:

* Provide methods for temporal quantitative data type.

Collaborators:

* DataSet

Instance Method Summary collapse

Methods inherited from RailsDataExplorer::DataType::Quantitative

#axis_scale

Methods inherited from RailsDataExplorer::DataType

#available_chart_types

Instance Method Details

#all_available_chart_typesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_data_explorer/data_type/quantitative/temporal.rb', line 15

def all_available_chart_types
  [
    {
      chart_class: Chart::HistogramTemporal,
      chart_roles: [:x],
      dimensions_count_min: 1,
      dimensions_count_max: 1
    },
    {
      chart_class: Chart::DescriptiveStatisticsTable,
      chart_roles: [:any],
      dimensions_count_min: 1,
      dimensions_count_max: 1
    },
    {
      chart_class: Chart::ParallelCoordinates,
      chart_roles: [:dimension],
      dimensions_count_min: 3,
    },
    # {
    #   chart_class: Chart::StackedHistogramTemporal,
    #   chart_roles: [:x],
    #   dimensions_count_min: 2,
    #   dimensions_count_max: 2,
    # },
  ].freeze
end

#axis_tick_format(values) ⇒ Object



71
72
73
# File 'lib/rails_data_explorer/data_type/quantitative/temporal.rb', line 71

def axis_tick_format(values)
  %(function(d) { return d3.time.format('%x')(new Date(d)) })
end

#descriptive_statistics(values) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rails_data_explorer/data_type/quantitative/temporal.rb', line 43

def descriptive_statistics(values)
  non_nil_values = values.find_all { |e| !e.nil? }
  ruby_formatter = Proc.new { |v| v.nil? ? '' : v.strftime('%a, %b %e, %Y, %l:%M:%S %p %Z') }
  [
    { label: 'Min', value: non_nil_values.min, ruby_formatter: ruby_formatter },
    { label: 'Max', value: non_nil_values.max, ruby_formatter: ruby_formatter },
    { label: 'Count', value: values.length, ruby_formatter: Proc.new { |e| number_with_delimiter(e) } },
  ]
end

#descriptive_statistics_table(values) ⇒ Object

Returns an object that describes a statistics table.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rails_data_explorer/data_type/quantitative/temporal.rb', line 54

def descriptive_statistics_table(values)
  desc_stats = descriptive_statistics(values)
  table = Utils::RdeTable.new(
    desc_stats.map { |stat|
      Utils::RdeTableRow.new(
        :tr,
        [
          Utils::RdeTableCell.new(:th, stat[:label], css_class: 'rde-row_header'),
          Utils::RdeTableCell.new(:td, stat[:value], ruby_formatter: stat[:ruby_formatter], css_class: 'rde-cell-value'),
        ],
        css_class: 'rde-row-values',
      )
    }
  )
  table
end