Class: RailsDataExplorer::Chart::HistogramTemporal

Inherits:
HistogramQuantitative show all
Defined in:
lib/rails-data-explorer/chart/histogram_temporal.rb

Instance Attribute Summary

Attributes inherited from RailsDataExplorer::Chart

#output_buffer

Instance Method Summary collapse

Methods inherited from HistogramQuantitative

#initialize, #render, #render_nvd3, #render_vega

Methods inherited from RailsDataExplorer::Chart

#dom_id, #render?

Constructor Details

This class inherits a constructor from RailsDataExplorer::Chart::HistogramQuantitative

Instance Method Details

#compute_chart_attrsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails-data-explorer/chart/histogram_temporal.rb', line 6

def compute_chart_attrs
  x_ds = @data_set.data_series.first
  return false  if x_ds.nil?

  # compute histogram
  h = x_ds.values.inject(Hash.new(0)) { |m,e|
    # Round to day
    key = e.nil? ? nil : (e.beginning_of_day).to_i * 1000
    m[key] += 1
    m
  }
  histogram_values_ds = DataSeries.new('_', h.values)
  y_scale_type = histogram_values_ds.axis_scale(:vega)
  bar_y2_val = 'log' == y_scale_type ? histogram_values_ds.min_val / 10.0 : 0
  width = 800
  {
    values: h.map { |k,v| { x: k, y: v } },
    width: width,
    x_axis_label: x_ds.name,
    x_axis_tick_format: x_ds.axis_tick_format,
    x_scale_type: 'time',
    x_scale_nice: "'day'",
    bar_width: 2,
    y_axis_label: 'Frequency',
    y_axis_tick_format: "d3.format('r')",
    y_scale_type: y_scale_type,
    y_scale_domain: [bar_y2_val, histogram_values_ds.max_val],
    bar_y2_val: bar_y2_val,
  }
end