opal-d3 0.0.20170205
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/README.md +7 -0
- data/Rakefile +31 -0
- data/d3.js +16393 -0
- data/demo/Gemfile +4 -0
- data/demo/README.md +7 -0
- data/demo/app/data/elections_2016.rb +10 -0
- data/demo/app/data/harry_potter.rb +19 -0
- data/demo/app/data/iphones.rb +29 -0
- data/demo/app/data/london_population.rb +26 -0
- data/demo/app/data/man_vs_horse.rb +55 -0
- data/demo/app/data/mtg_modern_colors.rb +96 -0
- data/demo/app/data/mtg_modern_creatures.rb +116 -0
- data/demo/app/data/olympics_2016_medals.rb +100 -0
- data/demo/app/data/paradox.rb +60 -0
- data/demo/app/data/polish_pms.rb +28 -0
- data/demo/app/data/star_trek_voyager.rb +183 -0
- data/demo/app/data/weather_in_london.rb +381 -0
- data/demo/app/elections_2016.rb +19 -0
- data/demo/app/harry_potter.rb +35 -0
- data/demo/app/iphones.rb +47 -0
- data/demo/app/london_population.rb +46 -0
- data/demo/app/london_population_area.rb +42 -0
- data/demo/app/man_vs_horse.rb +53 -0
- data/demo/app/mtg_modern_colors.rb +49 -0
- data/demo/app/mtg_modern_creatures.rb +63 -0
- data/demo/app/olympics_2016_medals.rb +54 -0
- data/demo/app/paradox.rb +57 -0
- data/demo/app/polish_pms.rb +53 -0
- data/demo/app/star_trek_voyager.rb +39 -0
- data/demo/app/weather_in_london.rb +62 -0
- data/demo/assets/d3.js +16393 -0
- data/demo/assets/style.css +0 -0
- data/demo/config.ru +39 -0
- data/demo/views/index.erb +21 -0
- data/demo/views/visualization.erb +29 -0
- data/lib/opal/d3/arc.rb +21 -0
- data/lib/opal/d3/area.rb +49 -0
- data/lib/opal/d3/axis.rb +77 -0
- data/lib/opal/d3/band_scale.rb +29 -0
- data/lib/opal/d3/collections.rb +10 -0
- data/lib/opal/d3/color.rb +78 -0
- data/lib/opal/d3/continuous_scale.rb +64 -0
- data/lib/opal/d3/creator.rb +11 -0
- data/lib/opal/d3/curve.rb +74 -0
- data/lib/opal/d3/dsv.rb +103 -0
- data/lib/opal/d3/ease.rb +319 -0
- data/lib/opal/d3/format.rb +97 -0
- data/lib/opal/d3/histograms.rb +44 -0
- data/lib/opal/d3/interpolate.rb +125 -0
- data/lib/opal/d3/line.rb +29 -0
- data/lib/opal/d3/map.rb +52 -0
- data/lib/opal/d3/misc.rb +15 -0
- data/lib/opal/d3/native.rb +84 -0
- data/lib/opal/d3/nest.rb +100 -0
- data/lib/opal/d3/ordinal_scale.rb +56 -0
- data/lib/opal/d3/path.rb +22 -0
- data/lib/opal/d3/pie.rb +23 -0
- data/lib/opal/d3/point_scale.rb +26 -0
- data/lib/opal/d3/polygon.rb +16 -0
- data/lib/opal/d3/quadtree.rb +95 -0
- data/lib/opal/d3/quantile_scale.rb +21 -0
- data/lib/opal/d3/quantize_scale.rb +23 -0
- data/lib/opal/d3/radial_area.rb +49 -0
- data/lib/opal/d3/radial_line.rb +29 -0
- data/lib/opal/d3/random.rb +12 -0
- data/lib/opal/d3/search.rb +28 -0
- data/lib/opal/d3/selection.rb +149 -0
- data/lib/opal/d3/sequential_scale.rb +96 -0
- data/lib/opal/d3/set.rb +33 -0
- data/lib/opal/d3/stack.rb +11 -0
- data/lib/opal/d3/statistics.rb +81 -0
- data/lib/opal/d3/symbol.rb +70 -0
- data/lib/opal/d3/threshold_scale.rb +23 -0
- data/lib/opal/d3/time_format.rb +48 -0
- data/lib/opal/d3/time_interval.rb +81 -0
- data/lib/opal/d3/transformations.rb +13 -0
- data/lib/opal/d3/version.rb +5 -0
- data/lib/opal/d3.rb +62 -0
- data/lib/opal-d3.rb +9 -0
- data/opal-d3.gemspec +20 -0
- data/spec/arc_spec.rb +86 -0
- data/spec/area_spec.rb +102 -0
- data/spec/axis_spec.rb +174 -0
- data/spec/band_scale_spec.rb +73 -0
- data/spec/color_spec.rb +74 -0
- data/spec/continuous_scale_spec.rb +217 -0
- data/spec/coverage_spec.rb +23 -0
- data/spec/creator_spec.rb +15 -0
- data/spec/curve_spec.rb +214 -0
- data/spec/dsv_spec.rb +194 -0
- data/spec/ease_spec.rb +370 -0
- data/spec/format_spec.rb +87 -0
- data/spec/histograms_spec.rb +61 -0
- data/spec/html/d3.js +16393 -0
- data/spec/html/index.html.erb +12 -0
- data/spec/interpolate_spec.rb +152 -0
- data/spec/line_spec.rb +58 -0
- data/spec/map_spec.rb +80 -0
- data/spec/misc_spec.rb +19 -0
- data/spec/nest_spec.rb +89 -0
- data/spec/objects_spec.rb +22 -0
- data/spec/ordinal_scale_spec.rb +59 -0
- data/spec/path_spec.rb +65 -0
- data/spec/pie_spec.rb +114 -0
- data/spec/point_scale_spec.rb +58 -0
- data/spec/polygon_spec.rb +51 -0
- data/spec/quadtree_spec.rb +128 -0
- data/spec/quantile_scale_spec.rb +24 -0
- data/spec/quantize_scale_spec.rb +40 -0
- data/spec/radial_area_spec.rb +127 -0
- data/spec/radial_line_spec.rb +54 -0
- data/spec/random_spec.rb +34 -0
- data/spec/search_spec.rb +69 -0
- data/spec/selection_data_spec.rb +71 -0
- data/spec/selection_manipulation_spec.rb +179 -0
- data/spec/selection_spec.rb +214 -0
- data/spec/sequential_scale_spec.rb +90 -0
- data/spec/set_spec.rb +57 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/stack_spec.rb +23 -0
- data/spec/statistics_spec.rb +65 -0
- data/spec/symbol_spec.rb +121 -0
- data/spec/threshold_scale_spec.rb +28 -0
- data/spec/time_format_spec.rb +99 -0
- data/spec/time_interval_spec.rb +304 -0
- data/spec/transformations_spec.rb +51 -0
- metadata +258 -0
data/spec/symbol_spec.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
describe "d3 - symbol" do
|
2
|
+
let(:path) { symbol.() }
|
3
|
+
let(:rounded) { path.gsub(/\d+\.\d+/){$&.to_f.round(2)} }
|
4
|
+
|
5
|
+
it "d3.symbol" do
|
6
|
+
expect(D3.symbol).to be_instance_of(D3::SymbolGenerator)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "basics" do
|
10
|
+
let(:symbol) { D3.symbol }
|
11
|
+
it do
|
12
|
+
expect(rounded).to eq("M4.51,0A4.51,4.51,0,1,1,-4.51,0A4.51,4.51,0,1,1,4.51,0")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "static size/type" do
|
17
|
+
let(:symbol) { D3.symbol.type(D3.symbol_triangle).size(1000) }
|
18
|
+
it do
|
19
|
+
expect(rounded).to eq("M0,-27.75L24.03,13.87L-24.03,13.87Z")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "fuctional size/type" do
|
24
|
+
let(:symbol) {
|
25
|
+
D3.symbol
|
26
|
+
.size{|d| d[:size]}
|
27
|
+
.type{|d| D3.symbols[d[:type]]}
|
28
|
+
}
|
29
|
+
let(:path) { symbol.(data) }
|
30
|
+
describe do
|
31
|
+
let(:data) {{ size: 100, type: 0 }}
|
32
|
+
it do
|
33
|
+
expect(rounded).to eq("M5.64,0A5.64,5.64,0,1,1,-5.64,0A5.64,5.64,0,1,1,5.64,0")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe do
|
37
|
+
let(:data) {{ size: 200, type: 0 }}
|
38
|
+
it do
|
39
|
+
expect(rounded).to eq("M7.98,0A7.98,7.98,0,1,1,-7.98,0A7.98,7.98,0,1,1,7.98,0")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe do
|
43
|
+
let(:data) {{ size: 100, type: 1 }}
|
44
|
+
it do
|
45
|
+
expect(rounded).to eq( "M-6.71,-2.24L-2.24,-2.24L-2.24,-6.71L2.24,-6.71L2.24,-2.24L6.71,-2.24L6.71,2.24L2.24,2.24L2.24,6.71L-2.24,6.71L-2.24,2.24L-6.71,2.24Z")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "d3.symbols" do
|
51
|
+
expect(D3.symbols.size).to eq(7)
|
52
|
+
D3.symbols.each do |sym|
|
53
|
+
expect(sym).to be_instance_of(D3::SymbolType)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "symbol types" do
|
58
|
+
let(:symbol) { D3.symbol.type(symbol_type) }
|
59
|
+
|
60
|
+
describe "d3.symbol_circle" do
|
61
|
+
let(:symbol_type) { D3.symbol_circle }
|
62
|
+
it do
|
63
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
64
|
+
expect(rounded).to eq("M4.51,0A4.51,4.51,0,1,1,-4.51,0A4.51,4.51,0,1,1,4.51,0")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "d3.symbol_cross" do
|
69
|
+
let(:symbol_type) { D3.symbol_cross }
|
70
|
+
it do
|
71
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
72
|
+
expect(rounded).to eq("M-5.37,-1.79L-1.79,-1.79L-1.79,-5.37L1.79,-5.37L1.79,-1.79L5.37,-1.79L5.37,1.79L1.79,1.79L1.79,5.37L-1.79,5.37L-1.79,1.79L-5.37,1.79Z")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "d3.symbol_diamond" do
|
77
|
+
let(:symbol_type) { D3.symbol_diamond }
|
78
|
+
it do
|
79
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
80
|
+
expect(rounded).to eq("M0,-7.44L4.3,0L0,7.44L-4.3,0Z")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "d3.symbol_square" do
|
85
|
+
let(:symbol_type) { D3.symbol_square }
|
86
|
+
it do
|
87
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
88
|
+
expect(rounded).to eq("M-4,-4h8v8h-8Z")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "d3.symbol_star" do
|
93
|
+
let(:symbol_type) { D3.symbol_star }
|
94
|
+
it do
|
95
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
96
|
+
expect(rounded).to eq("M0,-7.55L1.7,-2.33L7.18,-2.33L2.74,0.89L4.44,6.11L4.44e-16,2.88L-4.44,6.11L-2.74,0.89L-7.18,-2.33L-1.7,-2.33Z")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "d3.symbol_triangle" do
|
101
|
+
let(:symbol_type) { D3.symbol_triangle }
|
102
|
+
it do
|
103
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
104
|
+
expect(rounded).to eq("M0,-7.02L6.08,3.51L-6.08,3.51Z")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "d3.symbol_wye" do
|
109
|
+
let(:symbol_type) { D3.symbol_wye }
|
110
|
+
it do
|
111
|
+
expect(symbol_type).to be_instance_of(D3::SymbolType)
|
112
|
+
expect(rounded).to eq("M2.16,1.25L2.16,5.56L-2.16,5.56L-2.16,1.25L-5.9,-0.91L-3.74,-4.65L0,-2.49L3.74,-4.65L5.9,-0.91Z")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
__END__
|
119
|
+
|
120
|
+
symbol.context - set the rendering context.
|
121
|
+
symbolType.draw - draw this symbol to the given context.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe "d3 - threshold scale" do
|
2
|
+
let(:color) { D3.scale_threshold.domain([0, 1]).range(["red", "white", "green"]) }
|
3
|
+
it "d3.scale_threshold" do
|
4
|
+
expect(D3.scale_threshold).to be_instance_of(D3::ThresholdScale)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "basics" do
|
8
|
+
expect(color.(-1)).to eq("red")
|
9
|
+
expect(color.(0)).to eq("white")
|
10
|
+
expect(color.(0.5)).to eq("white")
|
11
|
+
expect(color.(1)).to eq("green")
|
12
|
+
expect(color.(1000)).to eq("green")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "invert_extent" do
|
16
|
+
expect(color.invert_extent("red")).to eq([nil, 0])
|
17
|
+
expect(color.invert_extent("white")).to eq([0, 1])
|
18
|
+
expect(color.invert_extent("green")).to eq([1, nil])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "copy" do
|
22
|
+
cc = color.copy.domain([0,10])
|
23
|
+
expect(cc.domain).to eq([0,10])
|
24
|
+
expect(cc.range).to eq(["red", "white", "green"])
|
25
|
+
expect(color.domain).to eq([0,1])
|
26
|
+
expect(color.range).to eq(["red", "white", "green"])
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
# Running these specs in weird timezone will fail because javascript timezones are pile of fail
|
4
|
+
describe "d3 - time format" do
|
5
|
+
let(:us) {{
|
6
|
+
date_time: "%x, %X",
|
7
|
+
date: "%-m/%-d/%Y",
|
8
|
+
time: "%-I:%M:%S %p",
|
9
|
+
periods: ["AM", "PM"],
|
10
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
11
|
+
short_days: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
12
|
+
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
13
|
+
short_months: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
14
|
+
}}
|
15
|
+
let(:pl) {{
|
16
|
+
date_time: "%A, %e %B %Y, %X",
|
17
|
+
date: "%d/%m/%Y",
|
18
|
+
time: "%H:%M:%S",
|
19
|
+
periods: ["AM", "PM"],
|
20
|
+
days: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"],
|
21
|
+
short_days: ["Niedz.", "Pon.", "Wt.", "Śr.", "Czw.", "Pt.", "Sob."],
|
22
|
+
months: ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"],
|
23
|
+
short_months: ["Stycz.", "Luty", "Marz.", "Kwie.", "Maj", "Czerw.", "Lipc.", "Sierp.", "Wrz.", "Paźdz.", "Listop.", "Grudz."],
|
24
|
+
}}
|
25
|
+
|
26
|
+
it "d3.time_format" do
|
27
|
+
f = D3.time_format("%B %d, %Y")
|
28
|
+
expect(f).to be_instance_of(Proc)
|
29
|
+
expect(f.(Time.parse("June 30, 2015"))).to eq("June 30, 2015")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "d3.time_parse" do
|
33
|
+
f = D3.time_parse("%B %d, %Y")
|
34
|
+
expect(f).to be_instance_of(Proc)
|
35
|
+
expect(f.("June 30, 2015")).to eq(Time.parse("June 30, 2015 00:00:00"))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "d3.utc_format" do
|
39
|
+
f = D3.utc_format("%B %d, %Y")
|
40
|
+
expect(f).to be_instance_of(Proc)
|
41
|
+
expect(f.(Time.parse("June 30, 2015 12:00:00"))).to eq("June 30, 2015")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "d3.utc_parse" do
|
45
|
+
f = D3.utc_parse("%B %d, %Y")
|
46
|
+
expect(f).to be_instance_of(Proc)
|
47
|
+
expect(f.("June 30, 2015")).to eq(Time.parse("June 30, 2015 00:00:00 UTC"))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "d3.iso_format / d3.iso_parse" do
|
51
|
+
t = Time.parse("June 30, 2015 12:30:45 UTC")
|
52
|
+
s = "2015-06-30T12:30:45.000Z"
|
53
|
+
expect(D3.iso_format(t)).to eq(s)
|
54
|
+
expect(D3.iso_parse(s)).to eq(t)
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "locale" do
|
58
|
+
let(:locale) { D3.time_format_locale(pl) }
|
59
|
+
|
60
|
+
it "d3.format" do
|
61
|
+
f = locale.format("%B %d, %Y")
|
62
|
+
expect(f).to be_instance_of(Proc)
|
63
|
+
expect(f.(Time.parse("June 30, 2015"))).to eq("Czerwiec 30, 2015")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "d3.parse" do
|
67
|
+
f = locale.parse("%B %d, %Y")
|
68
|
+
expect(f).to be_instance_of(Proc)
|
69
|
+
expect(f.("Czerwiec 30, 2015")).to eq(Time.parse("June 30, 2015 00:00:00"))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "d3.utc_format" do
|
73
|
+
f = locale.utc_format("%B %d, %Y")
|
74
|
+
expect(f).to be_instance_of(Proc)
|
75
|
+
expect(f.(Time.parse("June 30, 2015 12:00:00"))).to eq("Czerwiec 30, 2015")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "d3.utc_parse" do
|
79
|
+
f = locale.utc_parse("%B %d, %Y")
|
80
|
+
expect(f).to be_instance_of(Proc)
|
81
|
+
expect(f.("Czerwiec 30, 2015")).to eq(Time.parse("June 30, 2015 00:00:00 UTC"))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# This test affects global state, so we must be sure to restore it
|
86
|
+
it "d3.time_format_default_locale" do
|
87
|
+
t = Time.parse("June 30, 2015 12:30:00")
|
88
|
+
expect(D3.time_format("%c").(t)).to eq("6/30/2015, 12:30:00 PM")
|
89
|
+
|
90
|
+
locale_pl = D3.time_format_default_locale(pl)
|
91
|
+
expect(D3.time_format("%c").(t)).to eq("Wtorek, 30 Czerwiec 2015, 12:30:00")
|
92
|
+
|
93
|
+
locale_us = D3.time_format_default_locale(us)
|
94
|
+
expect(D3.time_format("%c").(t)).to eq("6/30/2015, 12:30:00 PM")
|
95
|
+
|
96
|
+
expect(locale_pl.format("%c").(t)).to eq("Wtorek, 30 Czerwiec 2015, 12:30:00")
|
97
|
+
expect(locale_us.format("%c").(t)).to eq("6/30/2015, 12:30:00 PM")
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,304 @@
|
|
1
|
+
describe "d3 - time interval" do
|
2
|
+
let(:a) { Time.at(1481073422.123678) } # 2016-12-07 01:17:02.123678
|
3
|
+
let(:b) { Time.at(1482781833.345345) } # 2016-12-26 19:50:33.345345
|
4
|
+
let(:c) { Time.at(1000000000 )} # 2001-09-09 02:46:40 +0100
|
5
|
+
|
6
|
+
it "time_interval.offset" do
|
7
|
+
expect(D3.time_year.offset(a).to_s).to eq("2017-12-07 01:17:02 -0000")
|
8
|
+
expect(D3.time_year.offset(a, 10).to_s).to eq("2026-12-07 01:17:02 -0000")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "time_interval.range" do
|
12
|
+
expect(D3.time_day.range(a, a+3*24*3600).map(&:to_s)).to eq([
|
13
|
+
"2016-12-08 00:00:00 -0000", "2016-12-09 00:00:00 -0000", "2016-12-10 00:00:00 -0000"
|
14
|
+
])
|
15
|
+
expect(D3.time_day.range(a, b, 5).map(&:to_s)).to eq([
|
16
|
+
"2016-12-08 00:00:00 -0000", "2016-12-13 00:00:00 -0000", "2016-12-18 00:00:00 -0000", "2016-12-23 00:00:00 -0000"
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
# It's not same as passing step to range
|
21
|
+
it "time_interval.every" do
|
22
|
+
expect(D3.time_day.every(5).range(a, b).map(&:to_s)).to eq([
|
23
|
+
"2016-12-11 00:00:00 -0000", "2016-12-16 00:00:00 -0000", "2016-12-21 00:00:00 -0000", "2016-12-26 00:00:00 -0000"
|
24
|
+
])
|
25
|
+
end
|
26
|
+
|
27
|
+
it "time_interval.filter" do
|
28
|
+
expect(D3.time_day.filter{|d| d.day % 5 == 1}.range(a, b).map(&:to_s)).to eq([
|
29
|
+
"2016-12-11 00:00:00 -0000", "2016-12-16 00:00:00 -0000", "2016-12-21 00:00:00 -0000", "2016-12-26 00:00:00 -0000"
|
30
|
+
])
|
31
|
+
end
|
32
|
+
|
33
|
+
it "time_interval.count" do
|
34
|
+
expect(D3.time_day.count(a, b)).to eq(19)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "d3.time_year" do
|
38
|
+
expect(D3.time_year.floor(a).to_s).to eq("2016-01-01 00:00:00 -0000")
|
39
|
+
expect(D3.time_year.round(a).to_s).to eq("2017-01-01 00:00:00 -0000")
|
40
|
+
expect(D3.time_year.ceil(a).to_s).to eq("2017-01-01 00:00:00 -0000")
|
41
|
+
end
|
42
|
+
it "d3.utc_year" do
|
43
|
+
expect(D3.utc_year.floor(a).to_s).to eq("2016-01-01 00:00:00 -0000")
|
44
|
+
expect(D3.utc_year.round(a).to_s).to eq("2017-01-01 00:00:00 -0000")
|
45
|
+
expect(D3.utc_year.ceil(a).to_s).to eq("2017-01-01 00:00:00 -0000")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "d3.time_month" do
|
49
|
+
expect(D3.time_month.floor(a).to_s).to eq("2016-12-01 00:00:00 -0000")
|
50
|
+
end
|
51
|
+
it "d3.utc_month" do
|
52
|
+
expect(D3.utc_month.floor(a).to_s).to eq("2016-12-01 00:00:00 -0000")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "d3.time_week" do
|
56
|
+
expect(D3.time_week.floor(a).to_s).to eq("2016-12-04 00:00:00 -0000")
|
57
|
+
end
|
58
|
+
it "d3.utc_week" do
|
59
|
+
expect(D3.utc_week.floor(a).to_s).to eq("2016-12-04 00:00:00 -0000")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "d3.time_monday" do
|
63
|
+
expect(D3.time_monday.floor(a).to_s).to eq("2016-12-05 00:00:00 -0000")
|
64
|
+
end
|
65
|
+
it "d3.utc_monday" do
|
66
|
+
expect(D3.utc_monday.floor(a).to_s).to eq("2016-12-05 00:00:00 -0000")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "d3.time_tuesday" do
|
70
|
+
expect(D3.time_tuesday.floor(a).to_s).to eq("2016-12-06 00:00:00 -0000")
|
71
|
+
end
|
72
|
+
it "d3.utc_tuesday" do
|
73
|
+
expect(D3.utc_tuesday.floor(a).to_s).to eq("2016-12-06 00:00:00 -0000")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "d3.time_wednesday" do
|
77
|
+
expect(D3.time_wednesday.floor(a).to_s).to eq("2016-12-07 00:00:00 -0000")
|
78
|
+
end
|
79
|
+
it "d3.utc_wednesday" do
|
80
|
+
expect(D3.utc_wednesday.floor(a).to_s).to eq("2016-12-07 00:00:00 -0000")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "d3.time_thursday" do
|
84
|
+
expect(D3.time_thursday.floor(a).to_s).to eq("2016-12-01 00:00:00 -0000")
|
85
|
+
end
|
86
|
+
it "d3.utc_thursday" do
|
87
|
+
expect(D3.utc_thursday.floor(a).to_s).to eq("2016-12-01 00:00:00 -0000")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "d3.time_friday" do
|
91
|
+
expect(D3.time_friday.floor(a).to_s).to eq("2016-12-02 00:00:00 -0000")
|
92
|
+
end
|
93
|
+
it "d3.utc_friday" do
|
94
|
+
expect(D3.utc_friday.floor(a).to_s).to eq("2016-12-02 00:00:00 -0000")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "d3.time_saturday" do
|
98
|
+
expect(D3.time_saturday.floor(a).to_s).to eq("2016-12-03 00:00:00 -0000")
|
99
|
+
end
|
100
|
+
it "d3.utc_saturday" do
|
101
|
+
expect(D3.utc_saturday.floor(a).to_s).to eq("2016-12-03 00:00:00 -0000")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "d3.time_sunday" do
|
105
|
+
expect(D3.time_sunday.floor(a).to_s).to eq("2016-12-04 00:00:00 -0000")
|
106
|
+
end
|
107
|
+
it "d3.utc_sunday" do
|
108
|
+
expect(D3.utc_sunday.floor(a).to_s).to eq("2016-12-04 00:00:00 -0000")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "d3.time_day" do
|
112
|
+
expect(D3.time_day.floor(a).to_s).to eq("2016-12-07 00:00:00 -0000")
|
113
|
+
end
|
114
|
+
it "d3.utc_day" do
|
115
|
+
expect(D3.utc_day.floor(a).to_s).to eq("2016-12-07 00:00:00 -0000")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "d3.time_hour" do
|
119
|
+
expect(D3.time_hour.floor(a).to_s).to eq("2016-12-07 01:00:00 -0000")
|
120
|
+
end
|
121
|
+
it "d3.utc_hour" do
|
122
|
+
expect(D3.utc_hour.floor(a).to_s).to eq("2016-12-07 01:00:00 -0000")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "d3.time_minute" do
|
126
|
+
expect(D3.time_minute.floor(a).to_s).to eq("2016-12-07 01:17:00 -0000")
|
127
|
+
end
|
128
|
+
it "d3.utc_minute" do
|
129
|
+
expect(D3.utc_minute.floor(a).to_s).to eq("2016-12-07 01:17:00 -0000")
|
130
|
+
end
|
131
|
+
|
132
|
+
it "d3.time_second" do
|
133
|
+
expect(D3.time_second.floor(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
134
|
+
expect(D3.utc_second.ceil(a).to_s).to eq("2016-12-07 01:17:03 -0000")
|
135
|
+
end
|
136
|
+
it "d3.utc_second" do
|
137
|
+
expect(D3.utc_second.floor(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
138
|
+
expect(D3.utc_second.ceil(a).to_s).to eq("2016-12-07 01:17:03 -0000")
|
139
|
+
end
|
140
|
+
|
141
|
+
# This looks like bug in D3, ceil should be 124000
|
142
|
+
it "d3.time_millisecond" do
|
143
|
+
expect(D3.time_millisecond.floor(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
144
|
+
expect(D3.time_millisecond.ceil(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
145
|
+
expect(D3.utc_millisecond.floor(a).usec).to eq(123000)
|
146
|
+
expect(D3.utc_millisecond.ceil(a).usec).to eq(123000)
|
147
|
+
end
|
148
|
+
it "d3.utc_millisecond" do
|
149
|
+
expect(D3.utc_millisecond.floor(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
150
|
+
expect(D3.utc_millisecond.ceil(a).to_s).to eq("2016-12-07 01:17:02 -0000")
|
151
|
+
expect(D3.utc_millisecond.floor(a).usec).to eq(123000)
|
152
|
+
expect(D3.utc_millisecond.ceil(a).usec).to eq(123000)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "d3.time_years" do
|
156
|
+
expect(D3.time_years(c,a).size).to eq(15)
|
157
|
+
expect(D3.time_years(c,a,2).size).to eq(8)
|
158
|
+
end
|
159
|
+
it "d3.utc_years" do
|
160
|
+
expect(D3.time_years(c,a).size).to eq(15)
|
161
|
+
expect(D3.time_years(c,a,2).size).to eq(8)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "d3.time_months" do
|
165
|
+
expect(D3.time_months(c,a).size).to eq(183)
|
166
|
+
expect(D3.time_months(c,a,12).size).to eq(16)
|
167
|
+
end
|
168
|
+
it "d3.utc_months" do
|
169
|
+
expect(D3.time_months(c,a).size).to eq(183)
|
170
|
+
expect(D3.time_months(c,a,12).size).to eq(16)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "d3.time_mondays" do
|
174
|
+
expect(D3.time_mondays(a,b).map(&:to_s)).to eq([
|
175
|
+
"2016-12-12 00:00:00 -0000", "2016-12-19 00:00:00 -0000", "2016-12-26 00:00:00 -0000"
|
176
|
+
])
|
177
|
+
end
|
178
|
+
it "d3.utc_mondays" do
|
179
|
+
expect(D3.utc_mondays(a,b).map(&:to_s)).to eq([
|
180
|
+
"2016-12-12 00:00:00 -0000", "2016-12-19 00:00:00 -0000", "2016-12-26 00:00:00 -0000"
|
181
|
+
])
|
182
|
+
end
|
183
|
+
|
184
|
+
it "d3.time_tuesdays" do
|
185
|
+
expect(D3.time_tuesdays(a,b).map(&:to_s)).to eq([
|
186
|
+
"2016-12-13 00:00:00 -0000", "2016-12-20 00:00:00 -0000"
|
187
|
+
])
|
188
|
+
end
|
189
|
+
it "d3.utc_tuesdays" do
|
190
|
+
expect(D3.utc_tuesdays(a,b).map(&:to_s)).to eq([
|
191
|
+
"2016-12-13 00:00:00 -0000", "2016-12-20 00:00:00 -0000"
|
192
|
+
])
|
193
|
+
end
|
194
|
+
|
195
|
+
it "d3.time_wednesdays" do
|
196
|
+
expect(D3.time_wednesdays(a,b).map(&:to_s)).to eq([
|
197
|
+
"2016-12-14 00:00:00 -0000", "2016-12-21 00:00:00 -0000"
|
198
|
+
])
|
199
|
+
end
|
200
|
+
it "d3.utc_wednesdays" do
|
201
|
+
expect(D3.utc_wednesdays(a,b).map(&:to_s)).to eq([
|
202
|
+
"2016-12-14 00:00:00 -0000", "2016-12-21 00:00:00 -0000"
|
203
|
+
])
|
204
|
+
end
|
205
|
+
|
206
|
+
it "d3.time_thursdays" do
|
207
|
+
expect(D3.time_thursdays(a,b).map(&:to_s)).to eq([
|
208
|
+
"2016-12-08 00:00:00 -0000", "2016-12-15 00:00:00 -0000", "2016-12-22 00:00:00 -0000"
|
209
|
+
])
|
210
|
+
end
|
211
|
+
it "d3.utc_thursdays" do
|
212
|
+
expect(D3.utc_thursdays(a,b).map(&:to_s)).to eq([
|
213
|
+
"2016-12-08 00:00:00 -0000", "2016-12-15 00:00:00 -0000", "2016-12-22 00:00:00 -0000"
|
214
|
+
])
|
215
|
+
end
|
216
|
+
|
217
|
+
it "d3.time_fridays" do
|
218
|
+
expect(D3.time_fridays(a,b).map(&:to_s)).to eq([
|
219
|
+
"2016-12-09 00:00:00 -0000", "2016-12-16 00:00:00 -0000", "2016-12-23 00:00:00 -0000"
|
220
|
+
])
|
221
|
+
end
|
222
|
+
it "d3.utc_fridays" do
|
223
|
+
expect(D3.utc_fridays(a,b).map(&:to_s)).to eq([
|
224
|
+
"2016-12-09 00:00:00 -0000", "2016-12-16 00:00:00 -0000", "2016-12-23 00:00:00 -0000"
|
225
|
+
])
|
226
|
+
end
|
227
|
+
|
228
|
+
it "d3.time_saturdays" do
|
229
|
+
expect(D3.time_saturdays(a,b).map(&:to_s)).to eq([
|
230
|
+
"2016-12-10 00:00:00 -0000", "2016-12-17 00:00:00 -0000", "2016-12-24 00:00:00 -0000"
|
231
|
+
])
|
232
|
+
end
|
233
|
+
it "d3.utc_saturdays" do
|
234
|
+
expect(D3.utc_saturdays(a,b).map(&:to_s)).to eq([
|
235
|
+
"2016-12-10 00:00:00 -0000", "2016-12-17 00:00:00 -0000", "2016-12-24 00:00:00 -0000"
|
236
|
+
])
|
237
|
+
end
|
238
|
+
|
239
|
+
it "d3.time_sundays" do
|
240
|
+
expect(D3.time_sundays(a,b).map(&:to_s)).to eq([
|
241
|
+
"2016-12-11 00:00:00 -0000", "2016-12-18 00:00:00 -0000", "2016-12-25 00:00:00 -0000"
|
242
|
+
])
|
243
|
+
end
|
244
|
+
it "d3.utc_sundays" do
|
245
|
+
expect(D3.utc_sundays(a,b).map(&:to_s)).to eq([
|
246
|
+
"2016-12-11 00:00:00 -0000", "2016-12-18 00:00:00 -0000", "2016-12-25 00:00:00 -0000"
|
247
|
+
])
|
248
|
+
end
|
249
|
+
|
250
|
+
it "d3.time_weeks" do
|
251
|
+
expect(D3.time_weeks(a,b).map(&:to_s)).to eq([
|
252
|
+
"2016-12-11 00:00:00 -0000", "2016-12-18 00:00:00 -0000", "2016-12-25 00:00:00 -0000"
|
253
|
+
])
|
254
|
+
end
|
255
|
+
it "d3.utc_weeks" do
|
256
|
+
expect(D3.utc_weeks(a,b).map(&:to_s)).to eq([
|
257
|
+
"2016-12-11 00:00:00 -0000", "2016-12-18 00:00:00 -0000", "2016-12-25 00:00:00 -0000"
|
258
|
+
])
|
259
|
+
end
|
260
|
+
|
261
|
+
it "d3.time_hours" do
|
262
|
+
expect(D3.time_hours(a,a+10000).map(&:to_s)).to eq([
|
263
|
+
"2016-12-07 02:00:00 -0000", "2016-12-07 03:00:00 -0000", "2016-12-07 04:00:00 -0000"
|
264
|
+
])
|
265
|
+
end
|
266
|
+
it "d3.utc_hours" do
|
267
|
+
expect(D3.utc_hours(a,a+10000).map(&:to_s)).to eq([
|
268
|
+
"2016-12-07 02:00:00 -0000", "2016-12-07 03:00:00 -0000", "2016-12-07 04:00:00 -0000"
|
269
|
+
])
|
270
|
+
end
|
271
|
+
|
272
|
+
it "d3.time_minutes" do
|
273
|
+
expect(D3.time_minutes(a,a+200).map(&:to_s)).to eq([
|
274
|
+
"2016-12-07 01:18:00 -0000", "2016-12-07 01:19:00 -0000", "2016-12-07 01:20:00 -0000"
|
275
|
+
])
|
276
|
+
end
|
277
|
+
it "d3.utc_minutes" do
|
278
|
+
expect(D3.utc_minutes(a,a+200).map(&:to_s)).to eq([
|
279
|
+
"2016-12-07 01:18:00 -0000", "2016-12-07 01:19:00 -0000", "2016-12-07 01:20:00 -0000"
|
280
|
+
])
|
281
|
+
end
|
282
|
+
|
283
|
+
it "d3.time_seconds" do
|
284
|
+
expect(D3.time_seconds(a,a+3).map(&:to_s)).to eq([
|
285
|
+
"2016-12-07 01:17:03 -0000", "2016-12-07 01:17:04 -0000", "2016-12-07 01:17:05 -0000"
|
286
|
+
])
|
287
|
+
end
|
288
|
+
it "d3.utc_seconds" do
|
289
|
+
expect(D3.utc_seconds(a,a+3).map(&:to_s)).to eq([
|
290
|
+
"2016-12-07 01:17:03 -0000", "2016-12-07 01:17:04 -0000", "2016-12-07 01:17:05 -0000"
|
291
|
+
])
|
292
|
+
end
|
293
|
+
|
294
|
+
it "d3.time_milliseconds" do
|
295
|
+
expect(D3.time_milliseconds(a,a+0.004).map(&:tv_usec)).to eq([
|
296
|
+
123000, 124000, 125000, 126000
|
297
|
+
])
|
298
|
+
end
|
299
|
+
it "d3.utc_milliseconds" do
|
300
|
+
expect(D3.utc_milliseconds(a,a+0.004).map(&:tv_usec)).to eq([
|
301
|
+
123000, 124000, 125000, 126000
|
302
|
+
])
|
303
|
+
end
|
304
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
describe "d3-array - transformations" do
|
2
|
+
it "d3.merge" do
|
3
|
+
expect(D3.merge([[1], [2, 3]])).to eq([1, 2, 3])
|
4
|
+
end
|
5
|
+
|
6
|
+
it "d3.pairs" do
|
7
|
+
expect(D3.pairs([1, 2, 3, 4])).to eq([[1, 2], [2, 3], [3, 4]])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "d3.permute" do
|
11
|
+
expect(D3.permute(["a", "b", "c"], [1, 2, 0])).to eq(["b", "c", "a"])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "d3.shuffle" do
|
15
|
+
a = (1..20).to_a
|
16
|
+
b = (1..20).to_a
|
17
|
+
D3.shuffle(b) # modifies in place
|
18
|
+
expect(a).not_to eq(b) # 61 bit chance of random test fail
|
19
|
+
expect(a.sort).to eq(b.sort)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "d3.ticks" do
|
23
|
+
expect(D3.ticks(1, 47, 5)).to eq([10, 20, 30, 40])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "d3.tick_step" do
|
27
|
+
expect(D3.tick_step(1, 47, 5)).to eq(10)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "d3.range" do
|
31
|
+
expect(D3.range(5)).to eq([0,1,2,3,4])
|
32
|
+
expect(D3.range(2, 7)).to eq([2,3,4,5,6])
|
33
|
+
expect(D3.range(10,50,5)).to eq([10,15,20,25,30,35,40,45])
|
34
|
+
expect(D3.range(0, 1, 0.2)).to eq([0, 0.2, 0.4, 0.6000000000000001, 0.8])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "d3.transpose" do
|
38
|
+
expect(D3.transpose([[1,2],[3,4]])).to eq([[1,3],[2,4]])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "d3.zip" do
|
42
|
+
expect(D3.zip([1, 2], [3, 4])).to eq([[1, 3], [2, 4]])
|
43
|
+
expect(D3.zip([1, 2, 5], [3, 4])).to eq([[1, 3], [2, 4]])
|
44
|
+
expect(D3.zip([1, 2], [3, 4, 5])).to eq([[1, 3], [2, 4]])
|
45
|
+
expect(D3.zip([1, 2], [3, 4], [5, 6])).to eq([[1, 3, 5], [2, 4, 6]])
|
46
|
+
expect(D3.zip([1, 2])).to eq([[1], [2]])
|
47
|
+
expect(D3.zip([1, 2], [])).to eq([])
|
48
|
+
expect(D3.zip([])).to eq([])
|
49
|
+
expect(D3.zip()).to eq([])
|
50
|
+
end
|
51
|
+
end
|