opal-d3 0.0.20170205

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +3 -0
  4. data/README.md +7 -0
  5. data/Rakefile +31 -0
  6. data/d3.js +16393 -0
  7. data/demo/Gemfile +4 -0
  8. data/demo/README.md +7 -0
  9. data/demo/app/data/elections_2016.rb +10 -0
  10. data/demo/app/data/harry_potter.rb +19 -0
  11. data/demo/app/data/iphones.rb +29 -0
  12. data/demo/app/data/london_population.rb +26 -0
  13. data/demo/app/data/man_vs_horse.rb +55 -0
  14. data/demo/app/data/mtg_modern_colors.rb +96 -0
  15. data/demo/app/data/mtg_modern_creatures.rb +116 -0
  16. data/demo/app/data/olympics_2016_medals.rb +100 -0
  17. data/demo/app/data/paradox.rb +60 -0
  18. data/demo/app/data/polish_pms.rb +28 -0
  19. data/demo/app/data/star_trek_voyager.rb +183 -0
  20. data/demo/app/data/weather_in_london.rb +381 -0
  21. data/demo/app/elections_2016.rb +19 -0
  22. data/demo/app/harry_potter.rb +35 -0
  23. data/demo/app/iphones.rb +47 -0
  24. data/demo/app/london_population.rb +46 -0
  25. data/demo/app/london_population_area.rb +42 -0
  26. data/demo/app/man_vs_horse.rb +53 -0
  27. data/demo/app/mtg_modern_colors.rb +49 -0
  28. data/demo/app/mtg_modern_creatures.rb +63 -0
  29. data/demo/app/olympics_2016_medals.rb +54 -0
  30. data/demo/app/paradox.rb +57 -0
  31. data/demo/app/polish_pms.rb +53 -0
  32. data/demo/app/star_trek_voyager.rb +39 -0
  33. data/demo/app/weather_in_london.rb +62 -0
  34. data/demo/assets/d3.js +16393 -0
  35. data/demo/assets/style.css +0 -0
  36. data/demo/config.ru +39 -0
  37. data/demo/views/index.erb +21 -0
  38. data/demo/views/visualization.erb +29 -0
  39. data/lib/opal/d3/arc.rb +21 -0
  40. data/lib/opal/d3/area.rb +49 -0
  41. data/lib/opal/d3/axis.rb +77 -0
  42. data/lib/opal/d3/band_scale.rb +29 -0
  43. data/lib/opal/d3/collections.rb +10 -0
  44. data/lib/opal/d3/color.rb +78 -0
  45. data/lib/opal/d3/continuous_scale.rb +64 -0
  46. data/lib/opal/d3/creator.rb +11 -0
  47. data/lib/opal/d3/curve.rb +74 -0
  48. data/lib/opal/d3/dsv.rb +103 -0
  49. data/lib/opal/d3/ease.rb +319 -0
  50. data/lib/opal/d3/format.rb +97 -0
  51. data/lib/opal/d3/histograms.rb +44 -0
  52. data/lib/opal/d3/interpolate.rb +125 -0
  53. data/lib/opal/d3/line.rb +29 -0
  54. data/lib/opal/d3/map.rb +52 -0
  55. data/lib/opal/d3/misc.rb +15 -0
  56. data/lib/opal/d3/native.rb +84 -0
  57. data/lib/opal/d3/nest.rb +100 -0
  58. data/lib/opal/d3/ordinal_scale.rb +56 -0
  59. data/lib/opal/d3/path.rb +22 -0
  60. data/lib/opal/d3/pie.rb +23 -0
  61. data/lib/opal/d3/point_scale.rb +26 -0
  62. data/lib/opal/d3/polygon.rb +16 -0
  63. data/lib/opal/d3/quadtree.rb +95 -0
  64. data/lib/opal/d3/quantile_scale.rb +21 -0
  65. data/lib/opal/d3/quantize_scale.rb +23 -0
  66. data/lib/opal/d3/radial_area.rb +49 -0
  67. data/lib/opal/d3/radial_line.rb +29 -0
  68. data/lib/opal/d3/random.rb +12 -0
  69. data/lib/opal/d3/search.rb +28 -0
  70. data/lib/opal/d3/selection.rb +149 -0
  71. data/lib/opal/d3/sequential_scale.rb +96 -0
  72. data/lib/opal/d3/set.rb +33 -0
  73. data/lib/opal/d3/stack.rb +11 -0
  74. data/lib/opal/d3/statistics.rb +81 -0
  75. data/lib/opal/d3/symbol.rb +70 -0
  76. data/lib/opal/d3/threshold_scale.rb +23 -0
  77. data/lib/opal/d3/time_format.rb +48 -0
  78. data/lib/opal/d3/time_interval.rb +81 -0
  79. data/lib/opal/d3/transformations.rb +13 -0
  80. data/lib/opal/d3/version.rb +5 -0
  81. data/lib/opal/d3.rb +62 -0
  82. data/lib/opal-d3.rb +9 -0
  83. data/opal-d3.gemspec +20 -0
  84. data/spec/arc_spec.rb +86 -0
  85. data/spec/area_spec.rb +102 -0
  86. data/spec/axis_spec.rb +174 -0
  87. data/spec/band_scale_spec.rb +73 -0
  88. data/spec/color_spec.rb +74 -0
  89. data/spec/continuous_scale_spec.rb +217 -0
  90. data/spec/coverage_spec.rb +23 -0
  91. data/spec/creator_spec.rb +15 -0
  92. data/spec/curve_spec.rb +214 -0
  93. data/spec/dsv_spec.rb +194 -0
  94. data/spec/ease_spec.rb +370 -0
  95. data/spec/format_spec.rb +87 -0
  96. data/spec/histograms_spec.rb +61 -0
  97. data/spec/html/d3.js +16393 -0
  98. data/spec/html/index.html.erb +12 -0
  99. data/spec/interpolate_spec.rb +152 -0
  100. data/spec/line_spec.rb +58 -0
  101. data/spec/map_spec.rb +80 -0
  102. data/spec/misc_spec.rb +19 -0
  103. data/spec/nest_spec.rb +89 -0
  104. data/spec/objects_spec.rb +22 -0
  105. data/spec/ordinal_scale_spec.rb +59 -0
  106. data/spec/path_spec.rb +65 -0
  107. data/spec/pie_spec.rb +114 -0
  108. data/spec/point_scale_spec.rb +58 -0
  109. data/spec/polygon_spec.rb +51 -0
  110. data/spec/quadtree_spec.rb +128 -0
  111. data/spec/quantile_scale_spec.rb +24 -0
  112. data/spec/quantize_scale_spec.rb +40 -0
  113. data/spec/radial_area_spec.rb +127 -0
  114. data/spec/radial_line_spec.rb +54 -0
  115. data/spec/random_spec.rb +34 -0
  116. data/spec/search_spec.rb +69 -0
  117. data/spec/selection_data_spec.rb +71 -0
  118. data/spec/selection_manipulation_spec.rb +179 -0
  119. data/spec/selection_spec.rb +214 -0
  120. data/spec/sequential_scale_spec.rb +90 -0
  121. data/spec/set_spec.rb +57 -0
  122. data/spec/spec_helper.rb +2 -0
  123. data/spec/stack_spec.rb +23 -0
  124. data/spec/statistics_spec.rb +65 -0
  125. data/spec/symbol_spec.rb +121 -0
  126. data/spec/threshold_scale_spec.rb +28 -0
  127. data/spec/time_format_spec.rb +99 -0
  128. data/spec/time_interval_spec.rb +304 -0
  129. data/spec/transformations_spec.rb +51 -0
  130. metadata +258 -0
data/spec/ease_spec.rb ADDED
@@ -0,0 +1,370 @@
1
+ describe "d3-ease" do
2
+ let(:range) { (0..20).map{|x| x / 20 }}
3
+ let(:curve) { range.map{|t| D3.send(ease, t).round(4) }}
4
+ let(:f) { D3.send(ease) }
5
+ let(:curve_f) { range.map{|t| f.call(t).round(4) } }
6
+ describe "d3.ease_linear" do
7
+ let(:ease) { :ease_linear }
8
+ it do
9
+ expect(curve).to eq(curve_f)
10
+ expect(curve).to eq([0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1])
11
+ end
12
+ end
13
+
14
+ describe "d3.ease_quad" do
15
+ let(:ease) { :ease_quad }
16
+ it do
17
+ expect(curve).to eq(curve_f)
18
+ expect(curve).to eq([0, 0.005, 0.02, 0.045, 0.08, 0.125, 0.18, 0.245, 0.32, 0.405, 0.5, 0.595, 0.68, 0.755, 0.82, 0.875, 0.92, 0.955, 0.98, 0.995, 1])
19
+ end
20
+ end
21
+
22
+ describe "d3.ease_quad_in" do
23
+ let(:ease) { :ease_quad_in }
24
+ it do
25
+ expect(curve).to eq(curve_f)
26
+ expect(curve).to eq([0, 0.0025, 0.01, 0.0225, 0.04, 0.0625, 0.09, 0.1225, 0.16, 0.2025, 0.25, 0.3025, 0.36, 0.4225, 0.49, 0.5625, 0.64, 0.7225, 0.81, 0.9025, 1])
27
+ end
28
+ end
29
+
30
+ describe "d3.ease_quad_out" do
31
+ let(:ease) { :ease_quad_out }
32
+ it do
33
+ expect(curve).to eq(curve_f)
34
+ expect(curve).to eq([0, 0.0975, 0.19, 0.2775, 0.36, 0.4375, 0.51, 0.5775, 0.64, 0.6975, 0.75, 0.7975, 0.84, 0.8775, 0.91, 0.9375, 0.96, 0.9775, 0.99, 0.9975, 1])
35
+ end
36
+ end
37
+
38
+ describe "d3.ease_quad_in_out" do
39
+ let(:ease) { :ease_quad_in_out }
40
+ it do
41
+ expect(curve).to eq(curve_f)
42
+ expect(curve).to eq([0, 0.005, 0.02, 0.045, 0.08, 0.125, 0.18, 0.245, 0.32, 0.405, 0.5, 0.595, 0.68, 0.755, 0.82, 0.875, 0.92, 0.955, 0.98, 0.995, 1])
43
+ end
44
+ end
45
+
46
+ describe "d3.ease_cubic" do
47
+ let(:ease) { :ease_cubic }
48
+ it do
49
+ expect(curve).to eq(curve_f)
50
+ expect(curve).to eq([0, 0.0005, 0.004, 0.0135, 0.032, 0.0625, 0.108, 0.1715, 0.256, 0.3645, 0.5, 0.6355, 0.744, 0.8285, 0.892, 0.9375, 0.968, 0.9865, 0.996, 0.9995, 1])
51
+ end
52
+ end
53
+
54
+ describe "d3.ease_cubic_in" do
55
+ let(:ease) { :ease_cubic_in }
56
+ it do
57
+ expect(curve).to eq(curve_f)
58
+ expect(curve).to eq([0, 0.0001, 0.001, 0.0034, 0.008, 0.0156, 0.027, 0.0429, 0.064, 0.0911, 0.125, 0.1664, 0.216, 0.2746, 0.343, 0.4219, 0.512, 0.6141, 0.729, 0.8574, 1])
59
+ end
60
+ end
61
+
62
+ describe "d3.ease_cubic_out" do
63
+ let(:ease) { :ease_cubic_out }
64
+ it do
65
+ expect(curve).to eq(curve_f)
66
+ expect(curve).to eq([0, 0.1426, 0.271, 0.3859, 0.488, 0.5781, 0.657, 0.7254, 0.784, 0.8336, 0.875, 0.9089, 0.936, 0.9571, 0.973, 0.9844, 0.992, 0.9966, 0.999, 0.9999, 1])
67
+ end
68
+ end
69
+
70
+ describe "d3.ease_cubic_in_out" do
71
+ let(:ease) { :ease_cubic_in_out }
72
+ it do
73
+ expect(curve).to eq(curve_f)
74
+ expect(curve).to eq([0, 0.0005, 0.004, 0.0135, 0.032, 0.0625, 0.108, 0.1715, 0.256, 0.3645, 0.5, 0.6355, 0.744, 0.8285, 0.892, 0.9375, 0.968, 0.9865, 0.996, 0.9995, 1])
75
+ end
76
+ end
77
+
78
+ describe "d3.ease_sin" do
79
+ let(:ease) { :ease_sin }
80
+ it do
81
+ expect(curve).to eq(curve_f)
82
+ expect(curve).to eq([0, 0.0062, 0.0245, 0.0545, 0.0955, 0.1464, 0.2061, 0.273, 0.3455, 0.4218, 0.5, 0.5782, 0.6545, 0.727, 0.7939, 0.8536, 0.9045, 0.9455, 0.9755, 0.9938, 1])
83
+ end
84
+ end
85
+
86
+ describe "d3.ease_sin_in" do
87
+ let(:ease) { :ease_sin_in }
88
+ it do
89
+ expect(curve).to eq(curve_f)
90
+ expect(curve).to eq([0, 0.0031, 0.0123, 0.0276, 0.0489, 0.0761, 0.109, 0.1474, 0.191, 0.2396, 0.2929, 0.3506, 0.4122, 0.4775, 0.546, 0.6173, 0.691, 0.7666, 0.8436, 0.9215, 1])
91
+ end
92
+ end
93
+
94
+ describe "d3.ease_sin_out" do
95
+ let(:ease) { :ease_sin_out }
96
+ it do
97
+ expect(curve).to eq(curve_f)
98
+ expect(curve).to eq([0, 0.0785, 0.1564, 0.2334, 0.309, 0.3827, 0.454, 0.5225, 0.5878, 0.6494, 0.7071, 0.7604, 0.809, 0.8526, 0.891, 0.9239, 0.9511, 0.9724, 0.9877, 0.9969, 1])
99
+ end
100
+ end
101
+
102
+ describe "d3.ease_sin_in_out" do
103
+ let(:ease) { :ease_sin_in_out }
104
+ it do
105
+ expect(curve).to eq(curve_f)
106
+ expect(curve).to eq([0, 0.0062, 0.0245, 0.0545, 0.0955, 0.1464, 0.2061, 0.273, 0.3455, 0.4218, 0.5, 0.5782, 0.6545, 0.727, 0.7939, 0.8536, 0.9045, 0.9455, 0.9755, 0.9938, 1])
107
+ end
108
+ end
109
+
110
+ describe "d3.ease_exp" do
111
+ let(:ease) { :ease_exp }
112
+ it do
113
+ expect(curve).to eq(curve_f)
114
+ expect(curve).to eq([0.0005, 0.001, 0.002, 0.0039, 0.0078, 0.0156, 0.0313, 0.0625, 0.125, 0.25, 0.5, 0.75, 0.875, 0.9375, 0.9688, 0.9844, 0.9922, 0.9961, 0.998, 0.999, 0.9995])
115
+ end
116
+ end
117
+
118
+ describe "d3.ease_exp_in" do
119
+ let(:ease) { :ease_exp_in }
120
+ it do
121
+ expect(curve).to eq(curve_f)
122
+ expect(curve).to eq([0.001, 0.0014, 0.002, 0.0028, 0.0039, 0.0055, 0.0078, 0.011, 0.0156, 0.0221, 0.0313, 0.0442, 0.0625, 0.0884, 0.125, 0.1768, 0.25, 0.3536, 0.5, 0.7071, 1])
123
+ end
124
+ end
125
+
126
+ describe "d3.ease_exp_out" do
127
+ let(:ease) { :ease_exp_out }
128
+ it do
129
+ expect(curve).to eq(curve_f)
130
+ expect(curve).to eq([0, 0.2929, 0.5, 0.6464, 0.75, 0.8232, 0.875, 0.9116, 0.9375, 0.9558, 0.9688, 0.9779, 0.9844, 0.989, 0.9922, 0.9945, 0.9961, 0.9972, 0.998, 0.9986, 0.999])
131
+ end
132
+ end
133
+
134
+ describe "d3.ease_exp_in_out" do
135
+ let(:ease) { :ease_exp_in_out }
136
+ it do
137
+ expect(curve).to eq(curve_f)
138
+ expect(curve).to eq([0.0005, 0.001, 0.002, 0.0039, 0.0078, 0.0156, 0.0313, 0.0625, 0.125, 0.25, 0.5, 0.75, 0.875, 0.9375, 0.9688, 0.9844, 0.9922, 0.9961, 0.998, 0.999, 0.9995])
139
+ end
140
+ end
141
+
142
+ describe "d3.ease_circle" do
143
+ let(:ease) { :ease_circle }
144
+ it do
145
+ expect(curve).to eq(curve_f)
146
+ expect(curve).to eq([0, 0.0025, 0.0101, 0.023, 0.0417, 0.067, 0.1, 0.1429, 0.2, 0.2821, 0.5, 0.7179, 0.8, 0.8571, 0.9, 0.933, 0.9583, 0.977, 0.9899, 0.9975, 1])
147
+ end
148
+ end
149
+
150
+ describe "d3.ease_circle_in" do
151
+ let(:ease) { :ease_circle_in }
152
+ it do
153
+ expect(curve).to eq(curve_f)
154
+ expect(curve).to eq([0, 0.0013, 0.005, 0.0113, 0.0202, 0.0318, 0.0461, 0.0633, 0.0835, 0.107, 0.134, 0.1648, 0.2, 0.2401, 0.2859, 0.3386, 0.4, 0.4732, 0.5641, 0.6878, 1])
155
+ end
156
+ end
157
+
158
+ describe "d3.ease_circle_out" do
159
+ let(:ease) { :ease_circle_out }
160
+ it do
161
+ expect(curve).to eq(curve_f)
162
+ expect(curve).to eq([0, 0.3122, 0.4359, 0.5268, 0.6, 0.6614, 0.7141, 0.7599, 0.8, 0.8352, 0.866, 0.893, 0.9165, 0.9367, 0.9539, 0.9682, 0.9798, 0.9887, 0.995, 0.9987, 1])
163
+ end
164
+ end
165
+
166
+ describe "d3.ease_circle_in_out" do
167
+ let(:ease) { :ease_circle_in_out }
168
+ it do
169
+ expect(curve).to eq(curve_f)
170
+ expect(curve).to eq([0, 0.0025, 0.0101, 0.023, 0.0417, 0.067, 0.1, 0.1429, 0.2, 0.2821, 0.5, 0.7179, 0.8, 0.8571, 0.9, 0.933, 0.9583, 0.977, 0.9899, 0.9975, 1])
171
+ end
172
+ end
173
+
174
+ describe "d3.ease_bounce" do
175
+ let(:ease) { :ease_bounce }
176
+ it do
177
+ expect(curve).to eq(curve_f)
178
+ expect(curve).to eq([0, 0.0189, 0.0756, 0.1702, 0.3025, 0.4727, 0.6806, 0.9264, 0.91, 0.8189, 0.7656, 0.7502, 0.7725, 0.8327, 0.9306, 0.9727, 0.94, 0.9452, 0.9881, 0.9845, 1])
179
+ end
180
+ end
181
+
182
+ describe "d3.ease_bounce_in" do
183
+ let(:ease) { :ease_bounce_in }
184
+ it do
185
+ expect(curve).to eq(curve_f)
186
+ expect(curve).to eq([0, 0.0155, 0.0119, 0.0548, 0.06, 0.0273, 0.0694, 0.1673, 0.2275, 0.2498, 0.2344, 0.1811, 0.09, 0.0736, 0.3194, 0.5273, 0.6975, 0.8298, 0.9244, 0.9811, 1])
187
+ end
188
+ end
189
+
190
+ describe "d3.ease_bounce_out" do
191
+ let(:ease) { :ease_bounce_out }
192
+ it do
193
+ expect(curve).to eq(curve_f)
194
+ expect(curve).to eq([0, 0.0189, 0.0756, 0.1702, 0.3025, 0.4727, 0.6806, 0.9264, 0.91, 0.8189, 0.7656, 0.7502, 0.7725, 0.8327, 0.9306, 0.9727, 0.94, 0.9452, 0.9881, 0.9845, 1])
195
+ end
196
+ end
197
+
198
+ describe "d3.ease_bounce_in_out" do
199
+ let(:ease) { :ease_bounce_in_out }
200
+ it do
201
+ expect(curve).to eq(curve_f)
202
+ expect(curve).to eq([0, 0.0059, 0.03, 0.0347, 0.1138, 0.1172, 0.045, 0.1597, 0.3488, 0.4622, 0.5, 0.5378, 0.6512, 0.8403, 0.955, 0.8828, 0.8863, 0.9653, 0.97, 0.9941, 1])
203
+ end
204
+ end
205
+
206
+ describe "d3.ease_poly_in" do
207
+ let(:ease) { :ease_poly_in }
208
+ it do
209
+ expect(curve).to eq(curve_f)
210
+ expect(curve).to eq([0, 0.0001, 0.001, 0.0034, 0.008, 0.0156, 0.027, 0.0429, 0.064, 0.0911, 0.125, 0.1664, 0.216, 0.2746, 0.343, 0.4219, 0.512, 0.6141, 0.729, 0.8574, 1])
211
+ end
212
+
213
+ describe "custom exponent" do
214
+ let(:f) { D3.send(ease).exponent(2) }
215
+ it do
216
+ expect(curve_f).to eq([0, 0.0025, 0.01, 0.0225, 0.04, 0.0625, 0.09, 0.1225, 0.16, 0.2025, 0.25, 0.3025, 0.36, 0.4225, 0.49, 0.5625, 0.64, 0.7225, 0.81, 0.9025, 1])
217
+ end
218
+ end
219
+ end
220
+
221
+ describe "d3.ease_poly_out" do
222
+ let(:ease) { :ease_poly_out }
223
+ it do
224
+ expect(curve).to eq(curve_f)
225
+ expect(curve).to eq([0, 0.1426, 0.271, 0.3859, 0.488, 0.5781, 0.657, 0.7254, 0.784, 0.8336, 0.875, 0.9089, 0.936, 0.9571, 0.973, 0.9844, 0.992, 0.9966, 0.999, 0.9999, 1])
226
+ end
227
+
228
+ describe "custom exponent" do
229
+ let(:f) { D3.send(ease).exponent(2) }
230
+ it do
231
+ expect(curve_f).to eq([0, 0.0975, 0.19, 0.2775, 0.36, 0.4375, 0.51, 0.5775, 0.64, 0.6975, 0.75, 0.7975, 0.84, 0.8775, 0.91, 0.9375, 0.96, 0.9775, 0.99, 0.9975, 1])
232
+ end
233
+ end
234
+ end
235
+
236
+ describe "d3.ease_poly_in_out" do
237
+ let(:ease) { :ease_poly_in_out }
238
+ it do
239
+ expect(curve).to eq(curve_f)
240
+ expect(curve).to eq([0, 0.0005, 0.004, 0.0135, 0.032, 0.0625, 0.108, 0.1715, 0.256, 0.3645, 0.5, 0.6355, 0.744, 0.8285, 0.892, 0.9375, 0.968, 0.9865, 0.996, 0.9995, 1])
241
+ end
242
+
243
+ describe "custom exponent" do
244
+ let(:f) { D3.send(ease).exponent(2) }
245
+ it do
246
+ expect(curve_f).to eq([0, 0.005, 0.02, 0.045, 0.08, 0.125, 0.18, 0.245, 0.32, 0.405, 0.5, 0.595, 0.68, 0.755, 0.82, 0.875, 0.92, 0.955, 0.98, 0.995, 1])
247
+ end
248
+ end
249
+ end
250
+
251
+ describe "d3.ease_back_in" do
252
+ let(:ease) { :ease_back_in }
253
+ it do
254
+ expect(curve).to eq(curve_f)
255
+ expect(curve).to eq([0, -0.0039, -0.0143, -0.0292, -0.0465, -0.0641, -0.0802, -0.0926, -0.0994, -0.0984, -0.0877, -0.0653, -0.029, 0.023, 0.0929, 0.1826, 0.2942, 0.4297, 0.5912, 0.7806, 1])
256
+ end
257
+
258
+ describe "custom overshoot" do
259
+ let(:f) { D3.send(ease).overshoot(4) }
260
+ it do
261
+ expect(curve_f).to eq([0, -0.0094, -0.035, -0.0731, -0.12, -0.1719, -0.225, -0.2756, -0.32, -0.3544, -0.375, -0.3781, -0.36, -0.3169, -0.245, -0.1406, 0, 0.1806, 0.405, 0.6769, 1])
262
+ end
263
+ end
264
+ end
265
+
266
+ describe "d3.ease_back_out" do
267
+ let(:ease) { :ease_back_out }
268
+ it do
269
+ expect(curve).to eq(curve_f)
270
+ expect(curve).to eq([0, 0.2194, 0.4088, 0.5703, 0.7058, 0.8174, 0.9071, 0.977, 1.029, 1.0653, 1.0877, 1.0984, 1.0994, 1.0926, 1.0802, 1.0641, 1.0465, 1.0292, 1.0143, 1.0039, 1])
271
+ end
272
+
273
+ describe "custom overshoot" do
274
+ let(:f) { D3.send(ease).overshoot(4) }
275
+ it do
276
+ expect(curve_f).to eq([0, 0.3231, 0.595, 0.8194, 1, 1.1406, 1.245, 1.3169, 1.36, 1.3781, 1.375, 1.3544, 1.32, 1.2756, 1.225, 1.1719, 1.12, 1.0731, 1.035, 1.0094, 1])
277
+ end
278
+ end
279
+ end
280
+
281
+ describe "d3.ease_back" do
282
+ let(:ease) { :ease_back }
283
+ it do
284
+ expect(curve).to eq(curve_f)
285
+ expect(curve).to eq([0, -0.0072, -0.0232, -0.0401, -0.0497, -0.0438, -0.0145, 0.0464, 0.1471, 0.2956, 0.5, 0.7044, 0.8529, 0.9536, 1.0145, 1.0438, 1.0497, 1.0401, 1.0232, 1.0072, 1])
286
+ end
287
+
288
+ describe "custom overshoot" do
289
+ let(:f) { D3.send(ease).overshoot(4) }
290
+ it do
291
+ expect(curve_f).to eq([0, -0.0175, -0.06, -0.1125, -0.16, -0.1875, -0.18, -0.1225, 0, 0.2025, 0.5, 0.7975, 1, 1.1225, 1.18, 1.1875, 1.16, 1.1125, 1.06, 1.0175, 1])
292
+ end
293
+ end
294
+ end
295
+
296
+ describe "d3.ease_back_in_out" do
297
+ let(:ease) { :ease_back_in_out }
298
+ it do
299
+ expect(curve).to eq(curve_f)
300
+ expect(curve).to eq([0, -0.0072, -0.0232, -0.0401, -0.0497, -0.0438, -0.0145, 0.0464, 0.1471, 0.2956, 0.5, 0.7044, 0.8529, 0.9536, 1.0145, 1.0438, 1.0497, 1.0401, 1.0232, 1.0072, 1])
301
+ end
302
+
303
+ describe "custom overshoot" do
304
+ let(:f) { D3.send(ease).overshoot(4) }
305
+ it do
306
+ expect(curve_f).to eq([0, -0.0175, -0.06, -0.1125, -0.16, -0.1875, -0.18, -0.1225, 0, 0.2025, 0.5, 0.7975, 1, 1.1225, 1.18, 1.1875, 1.16, 1.1125, 1.06, 1.0175, 1])
307
+ end
308
+ end
309
+ end
310
+
311
+ describe "d3.ease_elastic_in" do
312
+ let(:ease) { :ease_elastic_in }
313
+ it do
314
+ expect(curve).to eq(curve_f)
315
+ expect(curve).to eq([-0.0005, 0.0007, 0.002, 0.0014, -0.002, -0.0055, -0.0039, 0.0055, 0.0156, 0.011, -0.0156, -0.0442, -0.0313, 0.0442, 0.125, 0.0884, -0.125, -0.3536, -0.25, 0.3536, 1])
316
+ end
317
+
318
+ describe "custom amplitude/period" do
319
+ let(:f) { D3.send(ease).amplitude(2).period(0.2) }
320
+ it do
321
+ expect(curve_f).to eq([0.001, -0.0024, -0.002, 0.0048, 0.0039, -0.0096, -0.0078, 0.0191, 0.0156, -0.0383, -0.0313, 0.0765, 0.0625, -0.1531, -0.125, 0.3062, 0.25, -0.6124, -0.5, 1.2247, 1])
322
+ end
323
+ end
324
+ end
325
+
326
+ describe "d3.ease_elastic_out" do
327
+ let(:ease) { :ease_elastic_out }
328
+ it do
329
+ expect(curve).to eq(curve_f)
330
+ expect(curve).to eq([0, 0.6464, 1.25, 1.3536, 1.125, 0.9116, 0.875, 0.9558, 1.0313, 1.0442, 1.0156, 0.989, 0.9844, 0.9945, 1.0039, 1.0055, 1.002, 0.9986, 0.998, 0.9993, 1.0005])
331
+ end
332
+
333
+ describe "custom amplitude/period" do
334
+ let(:f) { D3.send(ease).amplitude(2).period(0.2) }
335
+ it do
336
+ expect(curve_f).to eq([0, -0.2247, 1.5, 1.6124, 0.75, 0.6938, 1.125, 1.1531, 0.9375, 0.9235, 1.0313, 1.0383, 0.9844, 0.9809, 1.0078, 1.0096, 0.9961, 0.9952, 1.002, 1.0024, 0.999])
337
+ end
338
+ end
339
+ end
340
+
341
+ describe "d3.ease_elastic" do
342
+ let(:ease) { :ease_elastic }
343
+ it do
344
+ expect(curve).to eq(curve_f)
345
+ expect(curve).to eq([0, 0.6464, 1.25, 1.3536, 1.125, 0.9116, 0.875, 0.9558, 1.0313, 1.0442, 1.0156, 0.989, 0.9844, 0.9945, 1.0039, 1.0055, 1.002, 0.9986, 0.998, 0.9993, 1.0005])
346
+ end
347
+
348
+ describe "custom amplitude/period" do
349
+ let(:f) { D3.send(ease).amplitude(2).period(0.2) }
350
+ it do
351
+ expect(curve_f).to eq([0, -0.2247, 1.5, 1.6124, 0.75, 0.6938, 1.125, 1.1531, 0.9375, 0.9235, 1.0313, 1.0383, 0.9844, 0.9809, 1.0078, 1.0096, 0.9961, 0.9952, 1.002, 1.0024, 0.999])
352
+ end
353
+ end
354
+ end
355
+
356
+ describe "d3.ease_elastic_in_out" do
357
+ let(:ease) { :ease_elastic_in_out }
358
+ it do
359
+ expect(curve).to eq(curve_f)
360
+ expect(curve).to eq([-0.0002, 0.001, -0.001, -0.002, 0.0078, -0.0078, -0.0156, 0.0625, -0.0625, -0.125, 0.5, 1.125, 1.0625, 0.9375, 1.0156, 1.0078, 0.9922, 1.002, 1.001, 0.999, 1.0002])
361
+ end
362
+
363
+ describe "custom amplitude/period" do
364
+ let(:f) { D3.send(ease).amplitude(2).period(0.2) }
365
+ it do
366
+ expect(curve_f).to eq([0.0005, -0.001, 0.002, -0.0039, 0.0078, -0.0156, 0.0313, -0.0625, 0.125, -0.25, 0.5, 1.25, 0.875, 1.0625, 0.9688, 1.0156, 0.9922, 1.0039, 0.998, 1.001, 0.9995])
367
+ end
368
+ end
369
+ end
370
+ end
@@ -0,0 +1,87 @@
1
+ describe "d3 - format" do
2
+ it "d3.format" do
3
+ expect(D3.format(".2").(42)).to eq("42")
4
+ expect(D3.format(".2").(4.2)).to eq("4.2")
5
+ expect(D3.format(".1").(42)).to eq("4e+1")
6
+ expect(D3.format(".1").(4.2)).to eq("4")
7
+ expect(D3.format(".0%").(0.123)).to eq("12%")
8
+ expect(D3.format("($.2f").(-3.5)).to eq("($3.50)")
9
+ expect(D3.format("+20").(42)).to eq(" +42")
10
+ expect(D3.format(".^20").(42)).to eq(".........42.........")
11
+ expect(D3.format(".2s").(42e6)).to eq("42M")
12
+ expect(D3.format("#x").(48879)).to eq("0xbeef")
13
+ expect(D3.format(",.2r").(4223)).to eq("4,200")
14
+ end
15
+
16
+ it "d3.format_prefix" do
17
+ f = D3.format_prefix(",.0", 1e-6)
18
+ expect(f.(0.0042)).to eq("4,200µ")
19
+ expect(f.(0.00042)).to eq("420µ")
20
+ end
21
+
22
+ it "d3.format_specifier" do
23
+ expect(D3.format_specifier("s")).to be_instance_of(D3::FormatSpecifier)
24
+ expect(D3.format_specifier("s").to_h).to eq({
25
+ fill: " ",
26
+ align: ">",
27
+ sign: "-",
28
+ symbol: "",
29
+ zero: false,
30
+ width: nil,
31
+ comma: false,
32
+ precision: nil,
33
+ type: "s",
34
+ })
35
+ s = D3.format_specifier("f")
36
+ s.precision = D3.precision_fixed(0.01)
37
+ f = D3.format(s)
38
+ expect(f.(42)).to eq("42.00")
39
+ end
40
+
41
+ it "d3.precision_fixed" do
42
+ expect(D3.precision_fixed(0.5)).to eq(1)
43
+ end
44
+
45
+ it "d3.precision_prefix" do
46
+ expect(D3.precision_prefix(1e5, 1.3e6)).to eq(1)
47
+ end
48
+
49
+ it "d3.precision_round" do
50
+ expect(D3.precision_round(0.01, 1.01)).to eq(3)
51
+ end
52
+
53
+ let(:pl) {{
54
+ decimal: ",",
55
+ thousands: ".",
56
+ grouping: [3],
57
+ currency: ["", "zł"],
58
+ }}
59
+ let(:us) {{
60
+ decimal: ".",
61
+ thousands: ",",
62
+ grouping: [3],
63
+ currency: ["$", ""],
64
+ }}
65
+ it "d3.format_locale" do
66
+ locale = D3.format_locale(pl)
67
+ expect(locale).to be_instance_of(D3::FormatLocale)
68
+ expect(locale.format("$.2f").(-3.5)).to eq("-3,50zł")
69
+ expect(locale.format("$.2f").(123456.789)).to eq("123456,79zł")
70
+ expect(locale.format(",.2r").(4223)).to eq("4.200")
71
+ expect(locale.format_prefix(",.0", 1e-3).(123456.789012)).to eq("123.456.789m")
72
+ end
73
+
74
+ # This test affects global state, so we must be sure to restore it
75
+ it "d3.format_default_locale" do
76
+ expect(D3.format(",.2r").(4223)).to eq("4,200")
77
+
78
+ locale_pl = D3.format_default_locale(pl)
79
+ expect(D3.format(",.2r").(4223)).to eq("4.200")
80
+ expect(locale_pl.format(",.2r").(4223)).to eq("4.200")
81
+
82
+ locale_us = D3.format_default_locale(us)
83
+ expect(D3.format(",.2r").(4223)).to eq("4,200")
84
+ expect(locale_pl.format(",.2r").(4223)).to eq("4.200")
85
+ expect(locale_us.format(",.2r").(4223)).to eq("4,200")
86
+ end
87
+ end
@@ -0,0 +1,61 @@
1
+ describe "d3-array - histograms" do
2
+ it "d3.histogram" do
3
+ expect(D3.histogram).to be_a(D3::Histogram)
4
+ end
5
+
6
+ describe "histogram.thresholds" do
7
+ let(:data) { (1..10).to_a }
8
+ let(:h) { D3.histogram }
9
+ it "block" do
10
+ h.thresholds{|*args| D3.threshold_sturges(*args) }
11
+ expect(h.(data)).to eq([
12
+ [1],
13
+ [2,3],
14
+ [4,5],
15
+ [6,7],
16
+ [8,9,10]
17
+ ])
18
+ end
19
+
20
+ it "symbol" do
21
+ h.thresholds(:scott)
22
+ expect(h.(data)).to eq([
23
+ [1,2,3,4],
24
+ [5,6,7,8,9,10],
25
+ ])
26
+ end
27
+
28
+ it "number" do
29
+ h.thresholds(2)
30
+ expect(h.(data)).to eq([
31
+ [1, 2, 3, 4],
32
+ [5, 6, 7, 8, 9, 10]
33
+ ])
34
+ end
35
+ end
36
+
37
+ it "histogram.call" do
38
+ h = D3.histogram
39
+ expect(h.([1,2,1,2,1,3])).to eq([
40
+ [1,1,1],
41
+ [],
42
+ [2,2],
43
+ [3],
44
+ ])
45
+ end
46
+
47
+ it "d3.threshold_freedman_diaconis" do
48
+ data = (0..10).to_a
49
+ expect(D3.threshold_freedman_diaconis(data,0,10)).to eq(3)
50
+ end
51
+
52
+ it "d3.threshold_scott" do
53
+ data = (0..10).to_a
54
+ expect(D3.threshold_scott(data,0,10)).to eq(2)
55
+ end
56
+
57
+ it "d3.threshold_sturges" do
58
+ data = (0..10).to_a
59
+ expect(D3.threshold_sturges(data,0,10)).to eq(5)
60
+ end
61
+ end