Class: RailsDataExplorer::Chart::StackedBarChartCategoricalPercent

Inherits:
StackedBarChartCategorical show all
Defined in:
lib/rails_data_explorer/chart/stacked_bar_chart_categorical_percent.rb

Overview

Responsibilities:

* Render a stacked bar chart for bivariate analysis of two categorical
  data series. Renders percentage distribution of y-data series.

Collaborators:

* DataSet

Instance Attribute Summary

Attributes inherited from RailsDataExplorer::Chart

#output_buffer

Instance Method Summary collapse

Methods inherited from StackedBarChartCategorical

#compute_chart_attrs, #initialize, #render, #render_nvd3, #render_vega

Methods inherited from RailsDataExplorer::Chart

#dom_id, #render?

Constructor Details

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

Instance Method Details

#compute_y_axis_label(y_ds_name) ⇒ Object

Parameters:

  • y_ds_name (String)

    name of the y data series



22
23
24
# File 'lib/rails_data_explorer/chart/stacked_bar_chart_categorical_percent.rb', line 22

def compute_y_axis_label(y_ds_name)
  "#{ y_ds_name } distribution [%]"
end

#compute_y_value(data_matrix, x_val, y_val) ⇒ Object

Override this method to change how the y value is computed. E.g., to change from absolute values to percentages.



17
18
19
# File 'lib/rails_data_explorer/chart/stacked_bar_chart_categorical_percent.rb', line 17

def compute_y_value(data_matrix, x_val, y_val)
  (data_matrix[x_val][y_val] / data_matrix[x_val][:_sum].to_f) * 100
end