rails-data-explorer 0.2.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -3
  3. data/README.md +2 -0
  4. data/lib/rails-data-explorer-no-rails.rb +36 -32
  5. data/lib/rails-data-explorer.rb +38 -35
  6. data/lib/rails_data_explorer.rb +29 -10
  7. data/lib/{rails-data-explorer → rails_data_explorer}/action_view_extension.rb +39 -17
  8. data/lib/rails_data_explorer/active_record_extension.rb +19 -0
  9. data/lib/{rails-data-explorer → rails_data_explorer}/chart.rb +10 -0
  10. data/lib/rails_data_explorer/chart/anova.rb +1 -0
  11. data/lib/{rails-data-explorer → rails_data_explorer}/chart/box_plot.rb +12 -3
  12. data/lib/{rails-data-explorer → rails_data_explorer}/chart/box_plot_group.rb +49 -22
  13. data/lib/{rails-data-explorer → rails_data_explorer}/chart/contingency_table.rb +19 -8
  14. data/lib/{rails-data-explorer → rails_data_explorer}/chart/descriptive_statistics_table.rb +9 -0
  15. data/lib/rails_data_explorer/chart/descriptive_statistics_table_group.rb +1 -0
  16. data/lib/{rails-data-explorer → rails_data_explorer}/chart/histogram_categorical.rb +12 -8
  17. data/lib/{rails-data-explorer → rails_data_explorer}/chart/histogram_quantitative.rb +12 -2
  18. data/lib/{rails-data-explorer → rails_data_explorer}/chart/histogram_temporal.rb +11 -2
  19. data/lib/{rails-data-explorer → rails_data_explorer}/chart/multi_dimensional_charts.rb +2 -0
  20. data/lib/{rails-data-explorer → rails_data_explorer}/chart/parallel_coordinates.rb +11 -1
  21. data/lib/{rails-data-explorer → rails_data_explorer}/chart/parallel_set.rb +11 -2
  22. data/lib/{rails-data-explorer → rails_data_explorer}/chart/pie_chart.rb +12 -8
  23. data/lib/{rails-data-explorer → rails_data_explorer}/chart/scatterplot.rb +13 -1
  24. data/lib/{rails-data-explorer → rails_data_explorer}/chart/scatterplot_matrix.rb +2 -0
  25. data/lib/{rails-data-explorer/chart/stacked_bar_chart_categorical_percent.rb → rails_data_explorer/chart/stacked_bar_chart_categorical.rb} +37 -14
  26. data/lib/rails_data_explorer/chart/stacked_bar_chart_categorical_percent.rb +28 -0
  27. data/lib/rails_data_explorer/chart/stacked_histogram_temporal.rb +199 -0
  28. data/lib/rails_data_explorer/data_series.rb +241 -0
  29. data/lib/{rails-data-explorer → rails_data_explorer}/data_set.rb +13 -4
  30. data/lib/{rails-data-explorer → rails_data_explorer}/data_type.rb +13 -0
  31. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/categorical.rb +79 -18
  32. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/geo.rb +2 -0
  33. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/quantitative.rb +14 -4
  34. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/quantitative/decimal.rb +9 -0
  35. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/quantitative/integer.rb +9 -0
  36. data/lib/{rails-data-explorer → rails_data_explorer}/data_type/quantitative/temporal.rb +9 -0
  37. data/lib/{rails-data-explorer → rails_data_explorer}/engine.rb +12 -0
  38. data/lib/{rails-data-explorer → rails_data_explorer}/exploration.rb +11 -0
  39. data/lib/rails_data_explorer/statistics/pearsons_chi_squared_independence_test.rb +72 -0
  40. data/lib/{rails-data-explorer → rails_data_explorer}/statistics/rng_category.rb +13 -0
  41. data/lib/{rails-data-explorer → rails_data_explorer}/statistics/rng_gaussian.rb +12 -1
  42. data/lib/{rails-data-explorer → rails_data_explorer}/statistics/rng_power_law.rb +11 -0
  43. data/lib/{rails-data-explorer → rails_data_explorer}/utils/color_scale.rb +6 -0
  44. data/lib/{rails-data-explorer → rails_data_explorer}/utils/data_binner.rb +13 -8
  45. data/lib/{rails-data-explorer → rails_data_explorer}/utils/data_encoder.rb +2 -0
  46. data/lib/{rails-data-explorer → rails_data_explorer}/utils/data_quantizer.rb +8 -3
  47. data/lib/{rails-data-explorer → rails_data_explorer}/utils/rde_table.rb +14 -11
  48. data/lib/{rails-data-explorer → rails_data_explorer}/utils/value_formatter.rb +9 -4
  49. data/rails-data-explorer.gemspec +5 -6
  50. data/spec/rails_data_explorer/chart_spec.rb +11 -0
  51. data/spec/{rails-data-explorer → rails_data_explorer}/data_series_spec.rb +0 -0
  52. data/spec/rails_data_explorer/data_set_spec.rb +31 -0
  53. data/spec/rails_data_explorer/data_type/categorical_spec.rb +126 -0
  54. data/{lib/rails-data-explorer/chart/descriptive_statistics_table_group.rb → spec/rails_data_explorer/data_type/quantitative/decimal_spec.rb} +0 -0
  55. data/spec/rails_data_explorer/data_type/quantitative/integer_spec.rb +0 -0
  56. data/spec/rails_data_explorer/data_type/quantitative/temporal_spec.rb +34 -0
  57. data/spec/rails_data_explorer/data_type/quantitative_spec.rb +118 -0
  58. data/spec/rails_data_explorer/data_type_spec.rb +7 -0
  59. data/spec/{rails-data-explorer → rails_data_explorer}/exploration_spec.rb +5 -5
  60. data/spec/rails_data_explorer/statistics/pearsons_chi_squared_independence_test_spec.rb +0 -0
  61. data/spec/rails_data_explorer/utils/color_scale_spec.rb +13 -0
  62. data/spec/{rails-data-explorer → rails_data_explorer}/utils/data_binner_spec.rb +0 -0
  63. data/spec/{rails-data-explorer → rails_data_explorer}/utils/data_quantizer_spec.rb +0 -0
  64. data/spec/rails_data_explorer/utils/value_formatter_spec.rb +33 -0
  65. data/vendor/assets/stylesheets/sources/rde-default-style.css +5 -1
  66. metadata +91 -82
  67. data/lib/rails-data-explorer/active_record_extension.rb +0 -14
  68. data/lib/rails-data-explorer/constants.rb +0 -5
  69. data/lib/rails-data-explorer/data_series.rb +0 -156
  70. data/lib/rails-data-explorer/statistics/pearsons_chi_squared_independence_test.rb +0 -75
  71. data/spec/rails-data-explorer/data_type/categorical_spec.rb +0 -34
@@ -0,0 +1,7 @@
1
+ require_relative '../helper_no_rails'
2
+
3
+ class RailsDataExplorer
4
+ describe DataType do
5
+
6
+ end
7
+ end
@@ -22,19 +22,19 @@ class RailsDataExplorer
22
22
 
23
23
  [
24
24
  [
25
- ['Univariate Integer data', [nil, 1, 2, 3]],
25
+ ['Univariate Integer data', [1, 2, 3]],
26
26
  { has_charts: ['histogram-quantitative', 'descriptive-statistics-table'] }
27
27
  ],
28
28
  [
29
- ['Univariate Decimal data', [nil, 1.0, 2.0, 3.0]],
29
+ ['Univariate Decimal data', [1.0, 2.0, 3.0]],
30
30
  { has_charts: ['histogram-quantitative', 'descriptive-statistics-table'] }
31
31
  ],
32
32
  [
33
- ['Univariate Temporal data', [nil, Time.now]],
33
+ ['Univariate Temporal data', [DateTime.new(2015,2,7)]],
34
34
  { has_charts: ['histogram-temporal', 'descriptive-statistics-table'] }
35
35
  ],
36
36
  [
37
- ['Univariate Categorical data', [nil, 'a', 'b', 'c']],
37
+ ['Univariate Categorical data', ['a', 'b', 'c']],
38
38
  { has_charts: ['histogram-categorical', 'pie-chart', 'descriptive-statistics-table'] }
39
39
  ],
40
40
  ].each { |(args, xpect_options)|
@@ -42,7 +42,7 @@ class RailsDataExplorer
42
42
 
43
43
  it "renders #{ title } correctly" do
44
44
  check_render_expectations(
45
- Exploration.new(*args).render,
45
+ Exploration.new(*args, true).render,
46
46
  xpect_options
47
47
  )
48
48
  end
@@ -0,0 +1,13 @@
1
+ require_relative '../../helper_no_rails'
2
+
3
+ class RailsDataExplorer
4
+ module Utils
5
+ describe ColorScale do
6
+
7
+ it 'computes a color from an input value' do
8
+ ColorScale.new.compute(0).must_equal '#000000'
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../helper_no_rails'
2
+
3
+ class RailsDataExplorer
4
+ module Utils
5
+ describe ValueFormatter do
6
+
7
+ describe 'initialize from options' do
8
+
9
+ let(:value_formatter) {
10
+ ValueFormatter.new(
11
+ d3_format: 'd3f',
12
+ ruby_formatter: 'rf',
13
+ significant_figures: 2
14
+ )
15
+ }
16
+
17
+ it 'has d3_format' do
18
+ value_formatter.d3_format.must_equal 'd3f'
19
+ end
20
+
21
+ it 'has ruby_formatter' do
22
+ value_formatter.ruby_formatter.must_equal 'rf'
23
+ end
24
+
25
+ it 'has significant_figures' do
26
+ value_formatter.significant_figures.must_equal 2
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -15,6 +15,10 @@ h2.rde-exploration-title {
15
15
  font-size: 24px;
16
16
  }
17
17
 
18
+ .rde-chart {
19
+ overflow-x: scroll;
20
+ }
21
+
18
22
  h3.rde-chart-title {
19
23
  display: none;
20
24
  font-size: 16px;
@@ -63,7 +67,7 @@ td.rde_toc-available_not_rendered {
63
67
  }
64
68
 
65
69
  td.rde_toc-currently_rendered {
66
- background-color: #cfc;
70
+ background-color: #dff0d8;
67
71
  }
68
72
 
69
73
  td.rde_toc-not_available {
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-data-explorer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Hund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-04 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: color
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: descriptive-statistics
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.1.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: distribution
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.7.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.7.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: interpolate
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: actionview
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: yui-compressor
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  description: rails-data-explorer is a Rails Engine plugin that makes it easy to explore
154
140
  the data in your app using charts and statistics.
155
141
  email: jhund@clearcove.ca
@@ -169,55 +155,67 @@ files:
169
155
  - doc/rails-data-explorer-screenshot.png
170
156
  - lib/rails-data-explorer-no-rails.rb
171
157
  - lib/rails-data-explorer.rb
172
- - lib/rails-data-explorer/action_view_extension.rb
173
- - lib/rails-data-explorer/active_record_extension.rb
174
- - lib/rails-data-explorer/chart.rb
175
- - lib/rails-data-explorer/chart/box_plot.rb
176
- - lib/rails-data-explorer/chart/box_plot_group.rb
177
- - lib/rails-data-explorer/chart/contingency_table.rb
178
- - lib/rails-data-explorer/chart/descriptive_statistics_table.rb
179
- - lib/rails-data-explorer/chart/descriptive_statistics_table_group.rb
180
- - lib/rails-data-explorer/chart/histogram_categorical.rb
181
- - lib/rails-data-explorer/chart/histogram_quantitative.rb
182
- - lib/rails-data-explorer/chart/histogram_temporal.rb
183
- - lib/rails-data-explorer/chart/multi_dimensional_charts.rb
184
- - lib/rails-data-explorer/chart/parallel_coordinates.rb
185
- - lib/rails-data-explorer/chart/parallel_set.rb
186
- - lib/rails-data-explorer/chart/pie_chart.rb
187
- - lib/rails-data-explorer/chart/scatterplot.rb
188
- - lib/rails-data-explorer/chart/scatterplot_matrix.rb
189
- - lib/rails-data-explorer/chart/stacked_bar_chart_categorical_percent.rb
190
- - lib/rails-data-explorer/constants.rb
191
- - lib/rails-data-explorer/data_series.rb
192
- - lib/rails-data-explorer/data_set.rb
193
- - lib/rails-data-explorer/data_type.rb
194
- - lib/rails-data-explorer/data_type/categorical.rb
195
- - lib/rails-data-explorer/data_type/geo.rb
196
- - lib/rails-data-explorer/data_type/quantitative.rb
197
- - lib/rails-data-explorer/data_type/quantitative/decimal.rb
198
- - lib/rails-data-explorer/data_type/quantitative/integer.rb
199
- - lib/rails-data-explorer/data_type/quantitative/temporal.rb
200
- - lib/rails-data-explorer/engine.rb
201
- - lib/rails-data-explorer/exploration.rb
202
- - lib/rails-data-explorer/statistics/pearsons_chi_squared_independence_test.rb
203
- - lib/rails-data-explorer/statistics/rng_category.rb
204
- - lib/rails-data-explorer/statistics/rng_gaussian.rb
205
- - lib/rails-data-explorer/statistics/rng_power_law.rb
206
- - lib/rails-data-explorer/utils/color_scale.rb
207
- - lib/rails-data-explorer/utils/data_binner.rb
208
- - lib/rails-data-explorer/utils/data_encoder.rb
209
- - lib/rails-data-explorer/utils/data_quantizer.rb
210
- - lib/rails-data-explorer/utils/rde_table.rb
211
- - lib/rails-data-explorer/utils/value_formatter.rb
212
158
  - lib/rails_data_explorer.rb
159
+ - lib/rails_data_explorer/action_view_extension.rb
160
+ - lib/rails_data_explorer/active_record_extension.rb
161
+ - lib/rails_data_explorer/chart.rb
162
+ - lib/rails_data_explorer/chart/anova.rb
163
+ - lib/rails_data_explorer/chart/box_plot.rb
164
+ - lib/rails_data_explorer/chart/box_plot_group.rb
165
+ - lib/rails_data_explorer/chart/contingency_table.rb
166
+ - lib/rails_data_explorer/chart/descriptive_statistics_table.rb
167
+ - lib/rails_data_explorer/chart/descriptive_statistics_table_group.rb
168
+ - lib/rails_data_explorer/chart/histogram_categorical.rb
169
+ - lib/rails_data_explorer/chart/histogram_quantitative.rb
170
+ - lib/rails_data_explorer/chart/histogram_temporal.rb
171
+ - lib/rails_data_explorer/chart/multi_dimensional_charts.rb
172
+ - lib/rails_data_explorer/chart/parallel_coordinates.rb
173
+ - lib/rails_data_explorer/chart/parallel_set.rb
174
+ - lib/rails_data_explorer/chart/pie_chart.rb
175
+ - lib/rails_data_explorer/chart/scatterplot.rb
176
+ - lib/rails_data_explorer/chart/scatterplot_matrix.rb
177
+ - lib/rails_data_explorer/chart/stacked_bar_chart_categorical.rb
178
+ - lib/rails_data_explorer/chart/stacked_bar_chart_categorical_percent.rb
179
+ - lib/rails_data_explorer/chart/stacked_histogram_temporal.rb
180
+ - lib/rails_data_explorer/data_series.rb
181
+ - lib/rails_data_explorer/data_set.rb
182
+ - lib/rails_data_explorer/data_type.rb
183
+ - lib/rails_data_explorer/data_type/categorical.rb
184
+ - lib/rails_data_explorer/data_type/geo.rb
185
+ - lib/rails_data_explorer/data_type/quantitative.rb
186
+ - lib/rails_data_explorer/data_type/quantitative/decimal.rb
187
+ - lib/rails_data_explorer/data_type/quantitative/integer.rb
188
+ - lib/rails_data_explorer/data_type/quantitative/temporal.rb
189
+ - lib/rails_data_explorer/engine.rb
190
+ - lib/rails_data_explorer/exploration.rb
191
+ - lib/rails_data_explorer/statistics/pearsons_chi_squared_independence_test.rb
192
+ - lib/rails_data_explorer/statistics/rng_category.rb
193
+ - lib/rails_data_explorer/statistics/rng_gaussian.rb
194
+ - lib/rails_data_explorer/statistics/rng_power_law.rb
195
+ - lib/rails_data_explorer/utils/color_scale.rb
196
+ - lib/rails_data_explorer/utils/data_binner.rb
197
+ - lib/rails_data_explorer/utils/data_encoder.rb
198
+ - lib/rails_data_explorer/utils/data_quantizer.rb
199
+ - lib/rails_data_explorer/utils/rde_table.rb
200
+ - lib/rails_data_explorer/utils/value_formatter.rb
213
201
  - rails-data-explorer.gemspec
214
202
  - spec/helper.rb
215
203
  - spec/helper_no_rails.rb
216
- - spec/rails-data-explorer/data_series_spec.rb
217
- - spec/rails-data-explorer/data_type/categorical_spec.rb
218
- - spec/rails-data-explorer/exploration_spec.rb
219
- - spec/rails-data-explorer/utils/data_binner_spec.rb
220
- - spec/rails-data-explorer/utils/data_quantizer_spec.rb
204
+ - spec/rails_data_explorer/chart_spec.rb
205
+ - spec/rails_data_explorer/data_series_spec.rb
206
+ - spec/rails_data_explorer/data_set_spec.rb
207
+ - spec/rails_data_explorer/data_type/categorical_spec.rb
208
+ - spec/rails_data_explorer/data_type/quantitative/decimal_spec.rb
209
+ - spec/rails_data_explorer/data_type/quantitative/integer_spec.rb
210
+ - spec/rails_data_explorer/data_type/quantitative/temporal_spec.rb
211
+ - spec/rails_data_explorer/data_type/quantitative_spec.rb
212
+ - spec/rails_data_explorer/data_type_spec.rb
213
+ - spec/rails_data_explorer/exploration_spec.rb
214
+ - spec/rails_data_explorer/statistics/pearsons_chi_squared_independence_test_spec.rb
215
+ - spec/rails_data_explorer/utils/color_scale_spec.rb
216
+ - spec/rails_data_explorer/utils/data_binner_spec.rb
217
+ - spec/rails_data_explorer/utils/data_quantizer_spec.rb
218
+ - spec/rails_data_explorer/utils/value_formatter_spec.rb
221
219
  - vendor/assets/javascripts/packaged/rails-data-explorer.min.js
222
220
  - vendor/assets/javascripts/rails-data-explorer.js
223
221
  - vendor/assets/javascripts/sources/d3.boxplot.js
@@ -262,8 +260,19 @@ summary: A Rails engine plugin for exploring data in your app with charts and st
262
260
  test_files:
263
261
  - spec/helper.rb
264
262
  - spec/helper_no_rails.rb
265
- - spec/rails-data-explorer/data_series_spec.rb
266
- - spec/rails-data-explorer/data_type/categorical_spec.rb
267
- - spec/rails-data-explorer/exploration_spec.rb
268
- - spec/rails-data-explorer/utils/data_binner_spec.rb
269
- - spec/rails-data-explorer/utils/data_quantizer_spec.rb
263
+ - spec/rails_data_explorer/chart_spec.rb
264
+ - spec/rails_data_explorer/data_series_spec.rb
265
+ - spec/rails_data_explorer/data_set_spec.rb
266
+ - spec/rails_data_explorer/data_type/categorical_spec.rb
267
+ - spec/rails_data_explorer/data_type/quantitative/decimal_spec.rb
268
+ - spec/rails_data_explorer/data_type/quantitative/integer_spec.rb
269
+ - spec/rails_data_explorer/data_type/quantitative/temporal_spec.rb
270
+ - spec/rails_data_explorer/data_type/quantitative_spec.rb
271
+ - spec/rails_data_explorer/data_type_spec.rb
272
+ - spec/rails_data_explorer/exploration_spec.rb
273
+ - spec/rails_data_explorer/statistics/pearsons_chi_squared_independence_test_spec.rb
274
+ - spec/rails_data_explorer/utils/color_scale_spec.rb
275
+ - spec/rails_data_explorer/utils/data_binner_spec.rb
276
+ - spec/rails_data_explorer/utils/data_quantizer_spec.rb
277
+ - spec/rails_data_explorer/utils/value_formatter_spec.rb
278
+ has_rdoc:
@@ -1,14 +0,0 @@
1
- #
2
- # Adds rails-data-explorer methods to ActiveRecord::Base and sub classes.
3
- #
4
- class RailsDataExplorer
5
- module ActiveRecordExtension
6
-
7
- module ClassMethods
8
-
9
- protected
10
-
11
- end
12
-
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- class RailsDataExplorer
2
-
3
- GREATER_ZERO = 1.0 / 1_000_000 # The smallest value to use if we have to avoid zero (div by zero)
4
-
5
- end
@@ -1,156 +0,0 @@
1
- class RailsDataExplorer
2
- class DataSeries
3
-
4
- # TODO: Add concept of significant figures for rounding values when displaying them
5
- # http://en.wikipedia.org/wiki/Significant_figures
6
-
7
- attr_reader :data_type, :name, :values, :chart_roles
8
- delegate :available_chart_types, to: :data_type, prefix: false
9
- delegate :available_chart_roles, to: :data_type, prefix: false
10
-
11
- # Any data series with a dynamic range greater than this is considered
12
- # having a large dynamic range
13
- # We consider dynamic range the ratio between the largest and the smallest value.
14
- def self.large_dynamic_range_threshold
15
- 10000.0
16
- end
17
-
18
- # Any data series with more than this uniq vals is considered having many
19
- # uniq values.
20
- def self.many_uniq_vals_threshold
21
- 30
22
- end
23
-
24
- # options: :chart_roles, :data_type (all optional)
25
- def initialize(_name, _values, options={})
26
- options = { chart_roles: [], data_type: nil }.merge(options)
27
- @name = _name
28
- @values = _values
29
- @data_type = init_data_type(options[:data_type])
30
- @chart_roles = init_chart_roles(options[:chart_roles]) # after data_type!
31
- end
32
-
33
- # Returns descriptive_statistics as a flat Array
34
- def descriptive_statistics
35
- @data_type.descriptive_statistics(values)
36
- end
37
-
38
- # Returns descriptive_statistics as a renderable table structure
39
- def descriptive_statistics_table
40
- @data_type.descriptive_statistics_table(values)
41
- end
42
-
43
- def number_of_values
44
- values.length
45
- end
46
-
47
- def values_summary
48
- if values.length < 3 || values.inspect.length < 80
49
- values.inspect
50
- else
51
- "[#{ values.first } ... #{ values.last }]"
52
- end
53
- end
54
-
55
- def inspect(indent=1, recursive=1000)
56
- r = %(#<#{ self.class.to_s }\n)
57
- r << [
58
- "@name=#{ name.inspect }",
59
- "@data_type=#{ data_type.inspect }",
60
- "@chart_roles=#{ chart_roles.inspect }",
61
- "@values=<count: #{ values.count }, items: #{ values_summary }>",
62
- ].map { |e| "#{ ' ' * indent }#{ e }\n"}.join
63
- if recursive > 0
64
- # nothing to recurse
65
- end
66
- r << %(#{ ' ' * (indent-1) }>\n)
67
- end
68
-
69
- def axis_tick_format
70
- data_type.axis_tick_format(values)
71
- end
72
-
73
- # @param[Symbol] d3_or_vega :d3 or :vega
74
- def axis_scale(d3_or_vega)
75
- data_type.axis_scale(self, d3_or_vega)
76
- end
77
-
78
- def uniq_vals
79
- @uniq_vals ||= values.uniq
80
- end
81
-
82
- def uniq_vals_count
83
- @uniq_vals_count ||= uniq_vals.length
84
- end
85
-
86
- def min_val
87
- @min_val ||= values.compact.min
88
- end
89
-
90
- def max_val
91
- @max_val ||= values.compact.max
92
- end
93
-
94
- # Used to decide whether we can render certain chart types
95
- def has_many_uniq_vals?
96
- uniq_vals_count > self.class.many_uniq_vals_threshold
97
- end
98
-
99
- def dynamic_range
100
- # TODO: avoid division by zero
101
- max_val / [min_val, max_val].min.to_f
102
- end
103
-
104
- def has_large_dynamic_range?
105
- dynamic_range > self.class.large_dynamic_range_threshold
106
- end
107
-
108
- def label_sorter(label_val_key, value_sorter)
109
- data_type.label_sorter(label_val_key, self, value_sorter)
110
- end
111
-
112
- private
113
-
114
- # @param[Array<Symbol>] chart_role_overrides, :x, :y, :color
115
- # @return[Hash] keys are chart_classes, and values are arrays with roles
116
- def init_chart_roles(chart_role_overrides)
117
- r = if chart_role_overrides.any?
118
- available_chart_types.inject(Hash.new([])) { |m,chart_type|
119
- subset = chart_type[:chart_roles] & chart_role_overrides
120
- next m if subset.empty?
121
- m[chart_type[:chart_class]] += subset
122
- m[chart_type[:chart_class]].uniq!
123
- m
124
- }
125
- else
126
- available_chart_types.inject(Hash.new([])) { |m,chart_type|
127
- m[chart_type[:chart_class]] += chart_type[:chart_roles]
128
- m[chart_type[:chart_class]].uniq!
129
- m
130
- }
131
- end
132
- r.freeze
133
- end
134
-
135
- def init_data_type(data_type_override)
136
- if data_type_override.nil?
137
- first_value = values.detect { |e| !e.nil? }
138
- case first_value
139
- when Integer, Bignum, Fixnum
140
- DataType::Quantitative::Integer.new
141
- when Float
142
- DataType::Quantitative::Decimal.new
143
- when String
144
- DataType::Categorical.new
145
- when Time, DateTime, ActiveSupport::TimeWithZone
146
- DataType::Quantitative::Temporal.new
147
- else
148
- raise(ArgumentError.new("Can't infer data type for value: #{ values.first.class.inspect }"))
149
- end
150
- else
151
- data_type_override
152
- end
153
- end
154
-
155
- end
156
- end