class RailsDataExplorer class Chart class HistogramQuantitative < Chart def initialize(_data_set, options = {}) @data_set = _data_set @options = {}.merge(options) end def compute_chart_attrs x_ds = @data_set.data_series.first return false if x_ds.nil? # compute histogram quantizer = Utils::DataQuantizer.new(x_ds, :max_number_of_bins => 100) quantized_values = quantizer.values number_of_bars = quantizer.number_of_bins width = 800 h = quantized_values.inject(Hash.new(0)) { |m,e| m[e] += 1; m } { 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: 'linear', x_scale_nice: true, bar_width: (width / number_of_bars.to_f) - 3, y_axis_label: 'Frequency', y_axis_tick_format: "d3.format('r')", } end def render return '' unless render? ca = compute_chart_attrs return '' unless ca render_vega(ca) end def render_vega(ca) %(

Histogram

) end def render_nvd3(ca) %(

Histogram

) end end end end