Class: RailsDataExplorer::DataSeries
- Inherits:
-
Object
- Object
- RailsDataExplorer::DataSeries
- Defined in:
- lib/rails-data-explorer/data_series.rb
Instance Attribute Summary collapse
-
#chart_roles ⇒ Object
readonly
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures.
-
#data_type ⇒ Object
readonly
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures.
-
#name ⇒ Object
readonly
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures.
-
#values ⇒ Object
readonly
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures.
Class Method Summary collapse
-
.large_dynamic_range_threshold ⇒ Object
Any data series with a dynamic range greater than this is considered having a large dynamic range We consider dynamic range the ratio between the largest and the smallest value.
-
.many_uniq_vals_threshold ⇒ Object
Any data series with more than this uniq vals is considered having many uniq values.
Instance Method Summary collapse
-
#axis_scale(d3_or_vega) ⇒ Object
@param d3_or_vega :d3 or :vega.
- #axis_tick_format ⇒ Object
-
#descriptive_statistics ⇒ Object
Returns descriptive_statistics as a flat Array.
-
#descriptive_statistics_table ⇒ Object
Returns descriptive_statistics as a renderable table structure.
- #dynamic_range ⇒ Object
- #has_large_dynamic_range? ⇒ Boolean
-
#has_many_uniq_vals? ⇒ Boolean
Used to decide whether we can render certain chart types.
-
#initialize(_name, _values, options = {}) ⇒ DataSeries
constructor
options: :chart_roles, :data_type (all optional).
- #inspect(indent = 1, recursive = 1000) ⇒ Object
- #label_sorter(label_val_key, value_sorter) ⇒ Object
- #max_val ⇒ Object
- #min_val ⇒ Object
- #number_of_values ⇒ Object
- #uniq_vals ⇒ Object
- #uniq_vals_count ⇒ Object
- #values_summary ⇒ Object
Constructor Details
#initialize(_name, _values, options = {}) ⇒ DataSeries
options: :chart_roles, :data_type (all optional)
25 26 27 28 29 30 31 |
# File 'lib/rails-data-explorer/data_series.rb', line 25 def initialize(_name, _values, ={}) = { chart_roles: [], data_type: nil }.merge() @name = _name @values = _values @data_type = init_data_type([:data_type]) @chart_roles = init_chart_roles([:chart_roles]) # after data_type! end |
Instance Attribute Details
#chart_roles ⇒ Object (readonly)
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures
7 8 9 |
# File 'lib/rails-data-explorer/data_series.rb', line 7 def chart_roles @chart_roles end |
#data_type ⇒ Object (readonly)
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures
7 8 9 |
# File 'lib/rails-data-explorer/data_series.rb', line 7 def data_type @data_type end |
#name ⇒ Object (readonly)
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures
7 8 9 |
# File 'lib/rails-data-explorer/data_series.rb', line 7 def name @name end |
#values ⇒ Object (readonly)
TODO: Add concept of significant figures for rounding values when displaying them en.wikipedia.org/wiki/Significant_figures
7 8 9 |
# File 'lib/rails-data-explorer/data_series.rb', line 7 def values @values end |
Class Method Details
.large_dynamic_range_threshold ⇒ Object
Any data series with a dynamic range greater than this is considered having a large dynamic range We consider dynamic range the ratio between the largest and the smallest value.
14 15 16 |
# File 'lib/rails-data-explorer/data_series.rb', line 14 def self.large_dynamic_range_threshold 10000.0 end |
.many_uniq_vals_threshold ⇒ Object
Any data series with more than this uniq vals is considered having many uniq values.
20 21 22 |
# File 'lib/rails-data-explorer/data_series.rb', line 20 def self.many_uniq_vals_threshold 30 end |
Instance Method Details
#axis_scale(d3_or_vega) ⇒ Object
@param d3_or_vega :d3 or :vega
74 75 76 |
# File 'lib/rails-data-explorer/data_series.rb', line 74 def axis_scale(d3_or_vega) data_type.axis_scale(self, d3_or_vega) end |
#axis_tick_format ⇒ Object
69 70 71 |
# File 'lib/rails-data-explorer/data_series.rb', line 69 def axis_tick_format data_type.axis_tick_format(values) end |
#descriptive_statistics ⇒ Object
Returns descriptive_statistics as a flat Array
34 35 36 |
# File 'lib/rails-data-explorer/data_series.rb', line 34 def descriptive_statistics @data_type.descriptive_statistics(values) end |
#descriptive_statistics_table ⇒ Object
Returns descriptive_statistics as a renderable table structure
39 40 41 |
# File 'lib/rails-data-explorer/data_series.rb', line 39 def descriptive_statistics_table @data_type.descriptive_statistics_table(values) end |
#dynamic_range ⇒ Object
99 100 101 102 |
# File 'lib/rails-data-explorer/data_series.rb', line 99 def dynamic_range # TODO: avoid division by zero max_val / [min_val, max_val].min.to_f end |
#has_large_dynamic_range? ⇒ Boolean
104 105 106 |
# File 'lib/rails-data-explorer/data_series.rb', line 104 def has_large_dynamic_range? dynamic_range > self.class.large_dynamic_range_threshold end |
#has_many_uniq_vals? ⇒ Boolean
Used to decide whether we can render certain chart types
95 96 97 |
# File 'lib/rails-data-explorer/data_series.rb', line 95 def has_many_uniq_vals? uniq_vals_count > self.class.many_uniq_vals_threshold end |
#inspect(indent = 1, recursive = 1000) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rails-data-explorer/data_series.rb', line 55 def inspect(indent=1, recursive=1000) r = %(#<#{ self.class.to_s }\n) r << [ "@name=#{ name.inspect }", "@data_type=#{ data_type.inspect }", "@chart_roles=#{ chart_roles.inspect }", "@values=<count: #{ values.count }, items: #{ values_summary }>", ].map { |e| "#{ ' ' * indent }#{ e }\n"}.join if recursive > 0 # nothing to recurse end r << %(#{ ' ' * (indent-1) }>\n) end |
#label_sorter(label_val_key, value_sorter) ⇒ Object
108 109 110 |
# File 'lib/rails-data-explorer/data_series.rb', line 108 def label_sorter(label_val_key, value_sorter) data_type.label_sorter(label_val_key, self, value_sorter) end |
#max_val ⇒ Object
90 91 92 |
# File 'lib/rails-data-explorer/data_series.rb', line 90 def max_val @max_val ||= values.compact.max end |
#min_val ⇒ Object
86 87 88 |
# File 'lib/rails-data-explorer/data_series.rb', line 86 def min_val @min_val ||= values.compact.min end |
#number_of_values ⇒ Object
43 44 45 |
# File 'lib/rails-data-explorer/data_series.rb', line 43 def number_of_values values.length end |
#uniq_vals ⇒ Object
78 79 80 |
# File 'lib/rails-data-explorer/data_series.rb', line 78 def uniq_vals @uniq_vals ||= values.uniq end |
#uniq_vals_count ⇒ Object
82 83 84 |
# File 'lib/rails-data-explorer/data_series.rb', line 82 def uniq_vals_count @uniq_vals_count ||= uniq_vals.length end |
#values_summary ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rails-data-explorer/data_series.rb', line 47 def values_summary if values.length < 3 || values.inspect.length < 80 values.inspect else "[#{ values.first } ... #{ values.last }]" end end |