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
@@ -0,0 +1,149 @@
1
+ module D3
2
+ class Selection
3
+ include D3::Native
4
+ alias_native :size
5
+ alias_native :empty?, :empty
6
+ alias_native :node
7
+ alias_native :nodes
8
+
9
+ def inspect
10
+ `#@native.toString()`
11
+ end
12
+
13
+ attribute_d3_block :text
14
+ attribute_d3_block :html
15
+
16
+ def data(data=nil,key=nil,&block)
17
+ if block
18
+ self.class.new @native.JS.data(block)
19
+ elsif key != nil
20
+ self.class.new @native.JS.data(data,key)
21
+ elsif data != nil
22
+ self.class.new @native.JS.data(data)
23
+ else
24
+ @native.JS.data
25
+ end
26
+ end
27
+
28
+ def append(name=`undefined`, &block)
29
+ raise if `name !== undefined` and block_given?
30
+ name = block if block_given?
31
+ D3::Selection.new @native.JS.append(name.to_n)
32
+ end
33
+
34
+ def insert(name=`undefined`, before=`undefined`, &block)
35
+ if `name === undefined`
36
+ raise unless block_given?
37
+ D3::Selection.new @native.JS.insert(block.to_n)
38
+ elsif `before === undefined`
39
+ if block_given?
40
+ D3::Selection.new @native.JS.insert(name.to_n, block.to_n)
41
+ else
42
+ D3::Selection.new @native.JS.insert(name.to_n)
43
+ end
44
+ else
45
+ raise if block_given?
46
+ D3::Selection.new @native.JS.insert(name.to_n, before.to_n)
47
+ end
48
+ end
49
+
50
+ alias_native_new :remove
51
+ alias_native_new :select
52
+ alias_native_new :select_all, :selectAll
53
+ alias_native_new :enter
54
+ alias_native_new :exit
55
+ alias_native :call
56
+ alias_native_chainable :raise
57
+ alias_native_chainable :lower
58
+
59
+ def merge(other)
60
+ D3::Selection.new @native.JS.merge(other.to_n)
61
+ end
62
+
63
+ def classed(classes, yesno=`undefined`, &block)
64
+ if block_given?
65
+ @native.JS.classed(classes, block)
66
+ self
67
+ elsif `yesno !== undefined`
68
+ @native.JS.classed(classes, yesno)
69
+ self
70
+ else
71
+ @native.JS.classed(classes)
72
+ end
73
+ end
74
+
75
+ def filter(other=`undefined`,&block)
76
+ if block_given?
77
+ D3::Selection.new @native.JS.filter(block)
78
+ else
79
+ D3::Selection.new @native.JS.filter(other)
80
+ end
81
+ end
82
+
83
+ def each(other=`undefined`,&block)
84
+ if block_given?
85
+ @native.JS.each(block)
86
+ else
87
+ @native.JS.each(other)
88
+ end
89
+ self
90
+ end
91
+
92
+ def property(key, value=`undefined`)
93
+ if `value === undefined`
94
+ @native.JS.property(key)
95
+ else
96
+ @native.JS.property(key, value)
97
+ self
98
+ end
99
+ end
100
+
101
+ # Usage:
102
+ # style("foo")
103
+ # style("foo"){ value }
104
+ # style("foo", value)
105
+ # style("foo", value, priority)
106
+ def style(name, value=`undefined`, priority=`undefined`, &block)
107
+ if block
108
+ raise if `name === undefined` or `priority !== undefined` or `value !== undefined`
109
+ Selection.new @native.JS.style(name, block)
110
+ elsif `value === undefined`
111
+ @native.JS.style(name)
112
+ else
113
+ value = `value === nil ? null : value`
114
+ Selection.new @native.JS.style(name, value, priority)
115
+ end
116
+ end
117
+
118
+ # nil means something specific (reset value),
119
+ # so we need another special value
120
+ def attr(name, value=`undefined`, &block)
121
+ if block
122
+ @native.JS.attr(name, block)
123
+ self
124
+ elsif `value == undefined`
125
+ @native.JS.attr(name)
126
+ elsif value == nil
127
+ @native.JS.attr(name, `null`)
128
+ self
129
+ else
130
+ @native.JS.attr(name, value)
131
+ self
132
+ end
133
+ end
134
+ end
135
+
136
+ class << self
137
+ def selection
138
+ D3::Selection.new(@d3.JS.selection)
139
+ end
140
+
141
+ def select(selector)
142
+ D3::Selection.new(@d3.JS.select(selector))
143
+ end
144
+
145
+ def select_all(selector)
146
+ D3::Selection.new(@d3.JS.selectAll(selector))
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,96 @@
1
+ module D3
2
+ class SequentialScale
3
+ include D3::Native
4
+
5
+ def call(t)
6
+ @native.call(t)
7
+ end
8
+
9
+ attribute_d3 :domain
10
+ attribute_d3 :clamp
11
+
12
+ def copy
13
+ self.class.new @native.JS.copy
14
+ end
15
+
16
+ def interpolator(&block)
17
+ if block_given?
18
+ @native.JS.interpolator(block)
19
+ self
20
+ else
21
+ @native.JS.interpolator
22
+ end
23
+ end
24
+ end
25
+
26
+ class << self
27
+ def scale_sequential(&block)
28
+ raise unless block_given?
29
+ SequentialScale.new @d3.JS.scaleSequential(block)
30
+ end
31
+
32
+ def interpolate_viridis(t=nil)
33
+ if t
34
+ @d3.JS.interpolateViridis(t)
35
+ else
36
+ `#@d3.interpolateViridis`
37
+ end
38
+ end
39
+
40
+ def interpolate_inferno(t=nil)
41
+ if t
42
+ @d3.JS.interpolateInferno(t)
43
+ else
44
+ `#@d3.interpolateInferno`
45
+ end
46
+ end
47
+
48
+ def interpolate_magma(t=nil)
49
+ if t
50
+ @d3.JS.interpolateMagma(t)
51
+ else
52
+ `#@d3.interpolateMagma`
53
+ end
54
+ end
55
+
56
+ def interpolate_plasma(t=nil)
57
+ if t
58
+ @d3.JS.interpolatePlasma(t)
59
+ else
60
+ `#@d3.interpolatePlasma`
61
+ end
62
+ end
63
+
64
+ def interpolate_warm(t=nil)
65
+ if t
66
+ @d3.JS.interpolateWarm(t)
67
+ else
68
+ `#@d3.interpolateWarm`
69
+ end
70
+ end
71
+
72
+ def interpolate_cool(t=nil)
73
+ if t
74
+ @d3.JS.interpolateCool(t)
75
+ else
76
+ `#@d3.interpolateCool`
77
+ end
78
+ end
79
+
80
+ def interpolate_rainbow(t=nil)
81
+ if t
82
+ @d3.JS.interpolateRainbow(t)
83
+ else
84
+ `#@d3.interpolateRainbow`
85
+ end
86
+ end
87
+
88
+ def interpolate_cubehelix_default(t=nil)
89
+ if t
90
+ @d3.JS.interpolateCubehelixDefault(t)
91
+ else
92
+ `#@d3.interpolateCubehelixDefault`
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,33 @@
1
+ module D3
2
+ class Set
3
+ include D3::Native
4
+ alias_native :empty?, :empty
5
+ alias_native :has?, :has
6
+ alias_native :size
7
+ alias_native :values
8
+ alias_native_chainable :add
9
+ alias_native_chainable :clear
10
+ alias_native_chainable :remove
11
+
12
+ def each(&block)
13
+ @native.JS.each(block)
14
+ self
15
+ end
16
+
17
+ def inspect
18
+ "#<D3::Set: {#{ values.join(", ") }}>"
19
+ end
20
+ end
21
+
22
+ class << self
23
+ def set(array=nil, &block)
24
+ if block_given?
25
+ D3::Set.new @d3.JS.set(array, proc{|x| yield(x)})
26
+ elsif array
27
+ D3::Set.new @d3.JS.set(array)
28
+ else
29
+ D3::Set.new @d3.JS.set()
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ module D3
2
+ class StackGenerator
3
+ include D3::Native
4
+ end
5
+
6
+ class << self
7
+ def stack
8
+ D3::StackGenerator.new @d3.JS.stack
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,81 @@
1
+ module D3
2
+ class << self
3
+ def min(data, &block)
4
+ if block
5
+ @d3.JS.min(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
6
+ else
7
+ @d3.JS.min(data.compact)
8
+ end
9
+ end
10
+
11
+ def max(data, &block)
12
+ if block
13
+ @d3.JS.max(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
14
+ else
15
+ @d3.JS.max(data.compact)
16
+ end
17
+ end
18
+
19
+ def sum(data, &block)
20
+ if block
21
+ @d3.JS.sum(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
22
+ else
23
+ @d3.JS.sum(data.compact)
24
+ end
25
+ end
26
+
27
+ def mean(data, &block)
28
+ result = if block
29
+ @d3.JS.mean(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
30
+ else
31
+ @d3.JS.mean(data.compact)
32
+ end
33
+ `result === undefined ? nil : result`
34
+ end
35
+
36
+ def median(data, &block)
37
+ result = if block
38
+ @d3.JS.median(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
39
+ else
40
+ @d3.JS.median(data.compact)
41
+ end
42
+ `result === undefined ? nil : result`
43
+ end
44
+
45
+ def deviation(data, &block)
46
+ result = if block
47
+ @d3.JS.deviation(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
48
+ else
49
+ @d3.JS.deviation(data.compact)
50
+ end
51
+ `result === undefined ? nil : result`
52
+ end
53
+
54
+ def variance(data, &block)
55
+ result = if block
56
+ @d3.JS.variance(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
57
+ else
58
+ @d3.JS.variance(data.compact)
59
+ end
60
+ `result === undefined ? nil : result`
61
+ end
62
+
63
+ def quantile(data, p, &block)
64
+ result = if block
65
+ @d3.JS.quantile(data, p, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
66
+ else
67
+ @d3.JS.quantile(data.compact, p)
68
+ end
69
+ `result === undefined ? nil : result`
70
+ end
71
+
72
+ def extent(data, &block)
73
+ (a,b) = if block
74
+ @d3.JS.extent(data, proc{|x| y=yield(x); y.nil? ? `undefined` : y})
75
+ else
76
+ @d3.JS.extent(data.compact)
77
+ end
78
+ [`a === undefined ? nil : a`, `b === undefined ? nil : b`]
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,70 @@
1
+ module D3
2
+ class SymbolGenerator
3
+ include D3::Native
4
+
5
+ def call(*args)
6
+ @native.call(*args)
7
+ end
8
+
9
+ attribute_d3_block :size
10
+
11
+ def type(new_value=`undefined`, &block)
12
+ if block_given?
13
+ @native.JS.type{|*args| yield(*args).to_n}
14
+ self
15
+ elsif `new_value === undefined`
16
+ D3::SymbolType.new @native.JS.type
17
+ else
18
+ @native.JS.type(new_value.to_n)
19
+ self
20
+ end
21
+ end
22
+
23
+ def type=(new_value)
24
+ @native.type(new_value.to_n)
25
+ self
26
+ end
27
+ end
28
+
29
+ class SymbolType
30
+ include D3::Native
31
+ end
32
+
33
+ class << self
34
+ def symbol
35
+ D3::SymbolGenerator.new @d3.JS.symbol
36
+ end
37
+
38
+ def symbols
39
+ `window.d3.symbols`.map{|st| D3::SymbolType.new(st)}
40
+ end
41
+
42
+ def symbol_circle
43
+ D3::SymbolType.new `window.d3.symbolCircle`
44
+ end
45
+
46
+ def symbol_cross
47
+ D3::SymbolType.new `window.d3.symbolCross`
48
+ end
49
+
50
+ def symbol_diamond
51
+ D3::SymbolType.new `window.d3.symbolDiamond`
52
+ end
53
+
54
+ def symbol_square
55
+ D3::SymbolType.new `window.d3.symbolSquare`
56
+ end
57
+
58
+ def symbol_star
59
+ D3::SymbolType.new `window.d3.symbolStar`
60
+ end
61
+
62
+ def symbol_triangle
63
+ D3::SymbolType.new `window.d3.symbolTriangle`
64
+ end
65
+
66
+ def symbol_wye
67
+ D3::SymbolType.new `window.d3.symbolWye`
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,23 @@
1
+ module D3
2
+ class ThresholdScale
3
+ include D3::Native
4
+ attribute_d3 :domain
5
+ attribute_d3 :range
6
+ alias_native_new :copy
7
+
8
+ def call(t)
9
+ @native.call(t)
10
+ end
11
+
12
+ def invert_extent(t)
13
+ a,b = @native.JS.invertExtent(t)
14
+ [`a === undefined ? nil : a`, `b === undefined ? nil : b`]
15
+ end
16
+ end
17
+
18
+ class << self
19
+ def scale_threshold
20
+ D3::ThresholdScale.new @d3.JS.scaleThreshold
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ module D3
2
+ class TimeFormatLocale
3
+ include D3::Native
4
+ alias_native :format, :format
5
+ alias_native :parse, :parse
6
+ alias_native :utc_format, :utcFormat
7
+ alias_native :utc_parse, :utcParse
8
+ end
9
+
10
+ class << self
11
+ alias_d3 :time_format, :timeFormat
12
+ alias_d3 :time_parse, :timeParse
13
+ alias_d3 :utc_format, :utcFormat
14
+ alias_d3 :utc_parse, :utcParse
15
+ alias_d3 :iso_format, :isoFormat
16
+ alias_d3 :iso_parse, :isoParse
17
+
18
+ def time_format_locale(spec={})
19
+ D3::TimeFormatLocale.new @d3.JS.timeFormatLocale(
20
+ {
21
+ dateTime: spec.fetch(:date_time, "%x, %X"),
22
+ date: spec.fetch(:date, "%-m/%-d/%Y"),
23
+ time: spec.fetch(:time, "%-I:%M:%S %p"),
24
+ periods: spec.fetch(:periods, ["AM", "PM"]),
25
+ days: spec.fetch(:days, ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]),
26
+ shortDays: spec.fetch(:short_days, ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]),
27
+ months: spec.fetch(:months, ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]),
28
+ shortMonths: spec.fetch(:short_months, ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]),
29
+ }.to_n
30
+ )
31
+ end
32
+
33
+ def time_format_default_locale(spec={})
34
+ D3::TimeFormatLocale.new @d3.JS.timeFormatDefaultLocale(
35
+ {
36
+ dateTime: spec.fetch(:date_time, "%x, %X"),
37
+ date: spec.fetch(:date, "%-m/%-d/%Y"),
38
+ time: spec.fetch(:time, "%-I:%M:%S %p"),
39
+ periods: spec.fetch(:periods, ["AM", "PM"]),
40
+ days: spec.fetch(:days, ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]),
41
+ shortDays: spec.fetch(:short_days, ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]),
42
+ months: spec.fetch(:months, ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]),
43
+ shortMonths: spec.fetch(:short_months, ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]),
44
+ }.to_n
45
+ )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,81 @@
1
+ module D3
2
+ class TimeInterval
3
+ include D3::Native
4
+
5
+ alias_native :round
6
+ alias_native :floor
7
+ alias_native :ceil
8
+ alias_native :offset
9
+ alias_native :range
10
+ alias_native :count
11
+ alias_native_new :every
12
+
13
+ def filter(&block)
14
+ D3::TimeInterval.new(@native.JS.filter(block))
15
+ end
16
+ end
17
+
18
+ class << self
19
+ def time_year; D3::TimeInterval.new(`window.d3.timeYear`); end
20
+ def utc_year; D3::TimeInterval.new(`window.d3.utcYear`); end
21
+ def time_month; D3::TimeInterval.new(`window.d3.timeMonth`); end
22
+ def utc_month; D3::TimeInterval.new(`window.d3.utcMonth`); end
23
+ def time_week; D3::TimeInterval.new(`window.d3.timeWeek`); end
24
+ def utc_week; D3::TimeInterval.new(`window.d3.utcWeek`); end
25
+ def time_monday; D3::TimeInterval.new(`window.d3.timeMonday`); end
26
+ def utc_monday; D3::TimeInterval.new(`window.d3.utcMonday`); end
27
+ def time_tuesday; D3::TimeInterval.new(`window.d3.timeTuesday`); end
28
+ def utc_tuesday; D3::TimeInterval.new(`window.d3.utcTuesday`); end
29
+ def time_wednesday; D3::TimeInterval.new(`window.d3.timeWednesday`); end
30
+ def utc_wednesday; D3::TimeInterval.new(`window.d3.utcWednesday`); end
31
+ def time_thursday; D3::TimeInterval.new(`window.d3.timeThursday`); end
32
+ def utc_thursday; D3::TimeInterval.new(`window.d3.utcThursday`); end
33
+ def time_friday; D3::TimeInterval.new(`window.d3.timeFriday`); end
34
+ def utc_friday; D3::TimeInterval.new(`window.d3.utcFriday`); end
35
+ def time_saturday; D3::TimeInterval.new(`window.d3.timeSaturday`); end
36
+ def utc_saturday; D3::TimeInterval.new(`window.d3.utcSaturday`); end
37
+ def time_sunday; D3::TimeInterval.new(`window.d3.timeSunday`); end
38
+ def utc_sunday; D3::TimeInterval.new(`window.d3.utcSunday`); end
39
+ def time_day; D3::TimeInterval.new(`window.d3.timeDay`); end
40
+ def utc_day; D3::TimeInterval.new(`window.d3.utcDay`); end
41
+ def time_hour; D3::TimeInterval.new(`window.d3.timeHour`); end
42
+ def utc_hour; D3::TimeInterval.new(`window.d3.utcHour`); end
43
+ def time_minute; D3::TimeInterval.new(`window.d3.timeMinute`); end
44
+ def utc_minute; D3::TimeInterval.new(`window.d3.utcMinute`); end
45
+ def time_second; D3::TimeInterval.new(`window.d3.timeSecond`); end
46
+ def utc_second; D3::TimeInterval.new(`window.d3.utcSecond`); end
47
+ def time_millisecond; D3::TimeInterval.new(`window.d3.timeMillisecond`); end
48
+ def utc_millisecond; D3::TimeInterval.new(`window.d3.utcMillisecond`); end
49
+
50
+ alias_d3 :time_years, :timeYears
51
+ alias_d3 :utc_years, :utcYears
52
+ alias_d3 :time_milliseconds, :timeMilliseconds
53
+ alias_d3 :utc_milliseconds, :utcMilliseconds
54
+ alias_d3 :time_seconds, :timeSeconds
55
+ alias_d3 :utc_seconds, :utcSeconds
56
+ alias_d3 :time_minutes, :timeMinutes
57
+ alias_d3 :utc_minutes, :utcMinutes
58
+ alias_d3 :time_hours, :timeHours
59
+ alias_d3 :utc_hours, :utcHours
60
+ alias_d3 :time_days, :timeDays
61
+ alias_d3 :utc_days, :utcDays
62
+ alias_d3 :time_weeks, :timeWeeks
63
+ alias_d3 :utc_weeks, :utcWeeks
64
+ alias_d3 :time_sundays, :timeSundays
65
+ alias_d3 :utc_sundays, :utcSundays
66
+ alias_d3 :time_mondays, :timeMondays
67
+ alias_d3 :utc_mondays, :utcMondays
68
+ alias_d3 :time_tuesdays, :timeTuesdays
69
+ alias_d3 :utc_tuesdays, :utcTuesdays
70
+ alias_d3 :time_wednesdays, :timeWednesdays
71
+ alias_d3 :utc_wednesdays, :utcWednesdays
72
+ alias_d3 :time_thursdays, :timeThursdays
73
+ alias_d3 :utc_thursdays, :utcThursdays
74
+ alias_d3 :time_fridays, :timeFridays
75
+ alias_d3 :utc_fridays, :utcFridays
76
+ alias_d3 :time_saturdays, :timeSaturdays
77
+ alias_d3 :utc_saturdays, :utcSaturdays
78
+ alias_d3 :time_months, :timeMonths
79
+ alias_d3 :utc_months, :utcMonths
80
+ end
81
+ end
@@ -0,0 +1,13 @@
1
+ module D3
2
+ class << self
3
+ alias_d3 :merge
4
+ alias_d3 :pairs
5
+ alias_d3 :permute
6
+ alias_d3 :shuffle
7
+ alias_d3 :ticks
8
+ alias_d3 :tick_step, :tickStep
9
+ alias_d3 :range
10
+ alias_d3 :transpose
11
+ alias_d3 :zip
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module D3
3
+ VERSION = "0.0.20170205"
4
+ end
5
+ end
data/lib/opal/d3.rb ADDED
@@ -0,0 +1,62 @@
1
+ require "opal"
2
+ require "opal-parser"
3
+
4
+ class Module
5
+ def alias_d3(ruby_name, js_name=ruby_name)
6
+ eval <<-EOF
7
+ def #{ruby_name}(*args)
8
+ @d3.JS.#{js_name}(*args)
9
+ end
10
+ EOF
11
+ end
12
+ end
13
+
14
+ module D3
15
+ @d3 = `window.d3`
16
+ class << self
17
+ end
18
+ end
19
+ # Metaclass:
20
+ require_relative "d3/native"
21
+
22
+ # Everything else:
23
+ require_relative "d3/arc"
24
+ require_relative "d3/area"
25
+ require_relative "d3/axis"
26
+ require_relative "d3/band_scale"
27
+ require_relative "d3/collections"
28
+ require_relative "d3/color"
29
+ require_relative "d3/continuous_scale"
30
+ require_relative "d3/creator"
31
+ require_relative "d3/curve"
32
+ require_relative "d3/dsv"
33
+ require_relative "d3/ease"
34
+ require_relative "d3/format"
35
+ require_relative "d3/histograms"
36
+ require_relative "d3/interpolate"
37
+ require_relative "d3/line"
38
+ require_relative "d3/map"
39
+ require_relative "d3/misc"
40
+ require_relative "d3/nest"
41
+ require_relative "d3/ordinal_scale"
42
+ require_relative "d3/path"
43
+ require_relative "d3/pie"
44
+ require_relative "d3/point_scale"
45
+ require_relative "d3/polygon"
46
+ require_relative "d3/quadtree"
47
+ require_relative "d3/quantile_scale"
48
+ require_relative "d3/quantize_scale"
49
+ require_relative "d3/radial_area"
50
+ require_relative "d3/radial_line"
51
+ require_relative "d3/random"
52
+ require_relative "d3/search"
53
+ require_relative "d3/selection"
54
+ require_relative "d3/sequential_scale"
55
+ require_relative "d3/set"
56
+ require_relative "d3/stack"
57
+ require_relative "d3/statistics"
58
+ require_relative "d3/symbol"
59
+ require_relative "d3/threshold_scale"
60
+ require_relative "d3/time_format"
61
+ require_relative "d3/time_interval"
62
+ require_relative "d3/transformations"
data/lib/opal-d3.rb ADDED
@@ -0,0 +1,9 @@
1
+ if RUBY_ENGINE == 'opal'
2
+ require_relative "opal/d3"
3
+ else
4
+ require "opal"
5
+ require_relative "opal/d3/version"
6
+
7
+ # This seems to be needed by sprockets somehow
8
+ Opal.append_path __dir__.untaint
9
+ end