Sha256: fd19f7b86c5f08e56db3eceed61db98b05f65de12d6d9a5325dc0e41b35dec0d

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# -*- coding: utf-8 -*-

class RailsDataExplorer
  class Chart

    # Responsibilities:
    #  * Render a histogram for univariate analysis of a temporal data series.
    #
    # Collaborators:
    #  * DataSet
    #
    class HistogramTemporal < HistogramQuantitative

      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 = 960
        {
          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,
          css_class: 'rde-histogram-temporal',
        }
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails-data-explorer-1.0.4 lib/rails_data_explorer/chart/histogram_temporal.rb
rails-data-explorer-1.0.3 lib/rails_data_explorer/chart/histogram_temporal.rb
rails-data-explorer-1.0.2 lib/rails_data_explorer/chart/histogram_temporal.rb
rails-data-explorer-1.0.1 lib/rails_data_explorer/chart/histogram_temporal.rb
rails-data-explorer-1.0.0 lib/rails_data_explorer/chart/histogram_temporal.rb