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
File without changes
data/demo/config.ru ADDED
@@ -0,0 +1,39 @@
1
+ require "bundler"
2
+ Bundler.require
3
+
4
+ opal = Opal::Server.new do |s|
5
+ s.append_path "app"
6
+ s.append_path "assets"
7
+ end
8
+
9
+ map "/assets" do
10
+ run opal.sprockets
11
+ end
12
+
13
+ visualizations = {
14
+ elections_2016: "Elections 2016",
15
+ london_population: "London Population",
16
+ london_population_area: "London Population - Area Chart",
17
+ olympics_2016_medals: "Olympics 2016 Medals",
18
+ iphones: "iPhones",
19
+ polish_pms: "Polish Prime Ministers",
20
+ man_vs_horse: "Man versus Horse Marathon",
21
+ paradox: "Paradox Interactive Games",
22
+ weather_in_london: "Weather in London",
23
+ harry_potter: "Harry Potter Books",
24
+ mtg_modern_creatures: "MTG: Creatures in Modern",
25
+ mtg_modern_colors: "MTG: Spell Cards in Modern",
26
+ star_trek_voyager: "Star Trek: Voyager",
27
+ }
28
+
29
+ visualizations.each do |script, title|
30
+ get "/v/#{script}.html" do
31
+ erb :visualization, {}, {script: script, title: title}
32
+ end
33
+ end
34
+
35
+ get "/" do
36
+ erb :index, {}, {visualizations: visualizations}
37
+ end
38
+
39
+ run Sinatra::Application
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Demos</title>
6
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
7
+ <link rel="stylesheet" href="assets/style.css">
8
+ </head>
9
+ <body>
10
+ <div class="container">
11
+ <h1>opal-d3 demos</h1>
12
+ <ul>
13
+ <% visualizations.each do |script, title| %>
14
+ <li><a href="v/<%= script %>.html"><%= title %></a></li>
15
+ <% end %>
16
+ </ul>
17
+ <br>
18
+ <a href="https://github.com/taw/opal-d3"><code>opal-d3</code> source code</a>
19
+ </div>
20
+ </body>
21
+ </html>
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title><%= title %></title>
6
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
7
+ <link rel="stylesheet" href="assets/style.css">
8
+ <link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css' rel='stylesheet'/>
9
+ <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js'></script>
10
+ <script>hljs.initHighlightingOnLoad();</script>
11
+ </head>
12
+ <body>
13
+ <div class="container">
14
+ <h1><%= title %></h1>
15
+ <div id="visualization"></div>
16
+ <div id="code">
17
+ <h1>Code</h1>
18
+ <pre><code><%=
19
+ open("#{__dir__}/../app/#{script}.rb").read
20
+ %></code></pre>
21
+ </div>
22
+ <script src="../assets/d3.js"></script>
23
+ <script src="../assets/<%= script %>.js"></script>
24
+ <script>
25
+ window.onload = function() { Opal.load("<%= script %>"); }
26
+ </script>
27
+ </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,21 @@
1
+ module D3
2
+ class ArcGenerator
3
+ include D3::Native
4
+ def call(*args)
5
+ @native.call(*args)
6
+ end
7
+
8
+ attribute_d3_block :inner_radius, :innerRadius
9
+ attribute_d3_block :outer_radius, :outerRadius
10
+ attribute_d3_block :corner_radius, :cornerRadius
11
+ attribute_d3_block :start_angle, :startAngle
12
+ attribute_d3_block :end_angle, :endAngle
13
+ alias_native :centroid
14
+ end
15
+
16
+ class << self
17
+ def arc
18
+ D3::ArcGenerator.new @d3.JS.arc
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ module D3
2
+ class AreaGenerator
3
+ include D3::Native
4
+
5
+ def call(*args)
6
+ result = @native.call(*args)
7
+ `result === null ? nil : result`
8
+ end
9
+
10
+ attribute_d3_block :x
11
+ attribute_d3_block :x0
12
+ attribute_d3_block :x1
13
+ attribute_d3_block :y
14
+ attribute_d3_block :y0
15
+ attribute_d3_block :y1
16
+ attribute_d3_block :defined
17
+
18
+ def curve(new_value=`undefined`)
19
+ if `new_value === undefined`
20
+ D3::Curve.new @native.JS.curve
21
+ else
22
+ @native.JS.curve(new_value.to_n)
23
+ self
24
+ end
25
+ end
26
+
27
+ def line_x0
28
+ D3::LineGenerator.new @native.JS.lineX0
29
+ end
30
+
31
+ def line_x1
32
+ D3::LineGenerator.new @native.JS.lineX1
33
+ end
34
+
35
+ def line_y0
36
+ D3::LineGenerator.new @native.JS.lineY0
37
+ end
38
+
39
+ def line_y1
40
+ D3::LineGenerator.new @native.JS.lineY1
41
+ end
42
+ end
43
+
44
+ class << self
45
+ def area
46
+ D3::AreaGenerator.new @d3.JS.area
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,77 @@
1
+ module D3
2
+ # It might be better to rewrap the Scale every time, as we're duplicating it
3
+ class Axis
4
+ include D3::Native
5
+
6
+ def initialize(native, scale_obj)
7
+ raise unless native
8
+ raise unless scale_obj
9
+ @scale_obj = scale_obj
10
+ @native = native
11
+ end
12
+
13
+ attribute_d3 :tick_size_inner, :tickSizeInner
14
+ attribute_d3 :tick_size_outer, :tickSizeOuter
15
+ attribute_d3 :tick_size, :tickSize
16
+ attribute_d3 :tick_padding, :tickPadding
17
+ attribute_d3 :tick_arguments, :tickArguments
18
+ alias_native_chainable :ticks
19
+
20
+ def call(context)
21
+ @native.call(context.to_n)
22
+ self
23
+ end
24
+
25
+ def scale(v=`undefined`)
26
+ if `v === undefined`
27
+ @scale_obj
28
+ else
29
+ @scale_obj = v
30
+ @native.JS.scale(v.to_n)
31
+ self
32
+ end
33
+ end
34
+ alias_method :scale=, :scale
35
+
36
+ def tick_values(v=`undefined`)
37
+ if `v === undefined`
38
+ result = @native.JS.tickValues
39
+ `result === null ? nil : result`
40
+ else
41
+ @native.JS.tickValues(v == nil ? `null` : v)
42
+ self
43
+ end
44
+ end
45
+ alias_method :tick_values=, :tick_values
46
+
47
+ def tick_format(v=`undefined`, &block)
48
+ v = block if block_given?
49
+ if `v === undefined`
50
+ result = @native.JS.tickFormat
51
+ `result === null ? nil : result`
52
+ else
53
+ @native.JS.tickFormat(v == nil ? `null` : v)
54
+ self
55
+ end
56
+ end
57
+ alias_method :tick_format=, :tick_format
58
+ end
59
+
60
+ class << self
61
+ def axis_top(scale)
62
+ D3::Axis.new(@d3.JS.axisTop(scale.to_n), scale)
63
+ end
64
+
65
+ def axis_bottom(scale)
66
+ D3::Axis.new(@d3.JS.axisBottom(scale.to_n), scale)
67
+ end
68
+
69
+ def axis_right(scale)
70
+ D3::Axis.new(@d3.JS.axisRight(scale.to_n), scale)
71
+ end
72
+
73
+ def axis_left(scale)
74
+ D3::Axis.new(@d3.JS.axisLeft(scale.to_n), scale)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,29 @@
1
+ module D3
2
+ class BandScale
3
+ include D3::Native
4
+ def call(t)
5
+ v = @native.call(t)
6
+ `v === undefined ? nil : v`
7
+ end
8
+ attribute_d3 :domain
9
+ attribute_d3 :range
10
+ alias_native_new :copy
11
+ alias_native :bandwidth
12
+ alias_native :step
13
+ # this is really weirdo one, as it sets both paddings* but returns inner one
14
+ # All need to be in [0,1] range
15
+ attribute_d3 :padding
16
+ attribute_d3 :padding_inner, :paddingInner
17
+ attribute_d3 :padding_outer, :paddingOuter
18
+ attribute_d3 :align
19
+ attribute_d3 :round
20
+ # This requires argument, we might redo this not to
21
+ alias_native_chainable :range_round, :rangeRound
22
+ end
23
+
24
+ class << self
25
+ def scale_band(*args)
26
+ D3::BandScale.new @d3.JS.scaleBand(*args)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ module D3
2
+ class << self
3
+ alias_d3 :keys
4
+ alias_d3 :values
5
+
6
+ def entries(obj)
7
+ @d3.JS.entries(obj).map{|o| [`o.key`, `o.value`]}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,78 @@
1
+ module D3
2
+ class Color
3
+ include D3::Native
4
+ attr_reader :native
5
+ alias_native :to_s, :toString
6
+ alias_native_new :brighter
7
+ alias_native_new :darker
8
+ alias_native :displayable?, :displayable
9
+ alias_native_new :rgb
10
+
11
+ # Various subsets of these are valid depending on color - maybe we should properly subclass?
12
+ def a; `#@native.a` end
13
+ def b; `#@native.b` end
14
+ def c; `#@native.c` end
15
+ def g; `#@native.g` end
16
+ def h; `#@native.h` end
17
+ def l; `#@native.l` end
18
+ def r; `#@native.r` end
19
+ def s; `#@native.s` end
20
+ def opacity; `#@native.opacity` end
21
+ end
22
+
23
+ class <<self
24
+ def color(description)
25
+ color = @d3.JS.color(description)
26
+ if color
27
+ D3::Color.new(color)
28
+ else
29
+ raise ArgumentError, "Invalid color: #{description}"
30
+ end
31
+ end
32
+
33
+ def rgb(*args)
34
+ color = if args[0].is_a?(Color)
35
+ @d3.JS.rgb(args[0].native)
36
+ else
37
+ @d3.JS.rgb(*args)
38
+ end
39
+ D3::Color.new(color)
40
+ end
41
+
42
+ def hsl(*args)
43
+ color = if args[0].is_a?(Color)
44
+ @d3.JS.hsl(args[0].native)
45
+ else
46
+ @d3.JS.hsl(*args)
47
+ end
48
+ D3::Color.new(color)
49
+ end
50
+
51
+ def lab(*args)
52
+ color = if args[0].is_a?(Color)
53
+ @d3.JS.lab(args[0].native)
54
+ else
55
+ @d3.JS.lab(*args)
56
+ end
57
+ D3::Color.new(color)
58
+ end
59
+
60
+ def hcl(*args)
61
+ color = if args[0].is_a?(Color)
62
+ @d3.JS.hcl(args[0].native)
63
+ else
64
+ @d3.JS.hcl(*args)
65
+ end
66
+ D3::Color.new(color)
67
+ end
68
+
69
+ def cubehelix(*args)
70
+ color = if args[0].is_a?(Color)
71
+ @d3.JS.cubehelix(args[0].native)
72
+ else
73
+ @d3.JS.cubehelix(*args)
74
+ end
75
+ D3::Color.new(color)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,64 @@
1
+ module D3
2
+ class ContinuousScale
3
+ include D3::Native
4
+ def call(t)
5
+ @native.call(t)
6
+ end
7
+
8
+ alias_native :invert
9
+ attribute_d3 :domain
10
+ attribute_d3 :range
11
+ attribute_d3 :clamp
12
+ alias_native_chainable :nice
13
+ alias_native_new :copy
14
+ alias_native :ticks
15
+ alias_native :tick_format, :tickFormat
16
+ alias_native_chainable :range_round, :rangeRound
17
+ def interpolate(&block)
18
+ if block
19
+ @native.JS.interpolate(block)
20
+ self
21
+ else
22
+ @native.JS.interpolate
23
+ end
24
+ end
25
+ end
26
+
27
+ class PowScale < ContinuousScale
28
+ attribute_d3 :exponent
29
+ end
30
+
31
+ class LogScale < ContinuousScale
32
+ attribute_d3 :base
33
+ end
34
+
35
+ class << self
36
+ def scale_pow
37
+ D3::PowScale.new @d3.JS.scalePow
38
+ end
39
+
40
+ def scale_sqrt
41
+ D3::PowScale.new @d3.JS.scaleSqrt
42
+ end
43
+
44
+ def scale_linear
45
+ D3::ContinuousScale.new @d3.JS.scaleLinear
46
+ end
47
+
48
+ def scale_log
49
+ D3::LogScale.new @d3.JS.scaleLog
50
+ end
51
+
52
+ def scale_identity
53
+ D3::ContinuousScale.new @d3.JS.scaleIdentity
54
+ end
55
+
56
+ def scale_time
57
+ D3::ContinuousScale.new @d3.JS.scaleTime
58
+ end
59
+
60
+ def scale_utc
61
+ D3::ContinuousScale.new @d3.JS.scaleUtc
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module D3
2
+ class Creator
3
+ include D3::Native
4
+ end
5
+
6
+ class << self
7
+ def creator(name)
8
+ D3::Creator.new @d3.JS.creator(name)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,74 @@
1
+ module D3
2
+ class Curve
3
+ include D3::Native
4
+ end
5
+
6
+ class CurveBundle < Curve
7
+ alias_native_new :beta
8
+ end
9
+
10
+ class CurveCardinal < Curve
11
+ alias_native_new :tension
12
+ end
13
+
14
+ class CurveCatmullRom < Curve
15
+ alias_native_new :alpha
16
+ end
17
+
18
+ class << self
19
+ def curve_basis
20
+ D3::Curve.new `window.d3.curveBasis`
21
+ end
22
+ def curve_basis_closed
23
+ D3::Curve.new `window.d3.curveBasisClosed`
24
+ end
25
+ def curve_basis_open
26
+ D3::Curve.new `window.d3.curveBasisOpen`
27
+ end
28
+ def curve_bundle
29
+ D3::CurveBundle.new `window.d3.curveBundle`
30
+ end
31
+ def curve_cardinal
32
+ D3::CurveCardinal.new `window.d3.curveCardinal`
33
+ end
34
+ def curve_cardinal_closed
35
+ D3::CurveCardinal.new `window.d3.curveCardinalClosed`
36
+ end
37
+ def curve_cardinal_open
38
+ D3::CurveCardinal.new `window.d3.curveCardinalOpen`
39
+ end
40
+ def curve_catmull_rom
41
+ D3::CurveCatmullRom.new `window.d3.curveCatmullRom`
42
+ end
43
+ def curve_catmull_rom_closed
44
+ D3::CurveCatmullRom.new `window.d3.curveCatmullRomClosed`
45
+ end
46
+ def curve_catmull_rom_open
47
+ D3::CurveCatmullRom.new `window.d3.curveCatmullRomOpen`
48
+ end
49
+ def curve_linear
50
+ D3::Curve.new `window.d3.curveLinear`
51
+ end
52
+ def curve_linear_closed
53
+ D3::Curve.new `window.d3.curveLinearClosed`
54
+ end
55
+ def curve_monotone_x
56
+ D3::Curve.new `window.d3.curveMonotoneX`
57
+ end
58
+ def curve_monotone_y
59
+ D3::Curve.new `window.d3.curveMonotoneY`
60
+ end
61
+ def curve_natural
62
+ D3::Curve.new `window.d3.curveNatural`
63
+ end
64
+ def curve_step
65
+ D3::Curve.new `window.d3.curveStep`
66
+ end
67
+ def curve_step_after
68
+ D3::Curve.new `window.d3.curveStepAfter`
69
+ end
70
+ def curve_step_before
71
+ D3::Curve.new `window.d3.curveStepBefore`
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,103 @@
1
+ module D3
2
+ class DsvFormat
3
+ include D3::Native
4
+
5
+ def parse_rows(string, row=`undefined`, &block)
6
+ row = block if block_given?
7
+ if `row !== undefined`
8
+ @native.JS.parseRows(string, proc{|d|
9
+ result = row.call(d)
10
+ result == nil ? `null` : result
11
+ })
12
+ else
13
+ @native.JS.parseRows(string)
14
+ end
15
+ end
16
+
17
+ def parse(string, row=`undefined`, &block)
18
+ row = block if block_given?
19
+ if `row !== undefined`
20
+ @native.JS.parse(string, proc{|e|
21
+ result = row.call(`Opal.hash(e)`)
22
+ result == nil ? `null` : result
23
+ })
24
+ else
25
+ @native.JS.parse(string).map{|e| `Opal.hash(e)` }
26
+ end
27
+ end
28
+
29
+ alias_native :format_rows, :formatRows
30
+
31
+ alias_native :format
32
+ end
33
+
34
+ class << self
35
+ def dsv_format(separator)
36
+ D3::DsvFormat.new @d3.JS.dsvFormat(separator)
37
+ end
38
+
39
+ def csv_parse_rows(string, row=`undefined`, &block)
40
+ row = block if block_given?
41
+ if `row !== undefined`
42
+ @d3.JS.csvParseRows(string, proc{|d|
43
+ result = row.call(d)
44
+ result == nil ? `null` : result
45
+ })
46
+ else
47
+ @d3.JS.csvParseRows(string)
48
+ end
49
+ end
50
+
51
+ def tsv_parse_rows(string, row=`undefined`, &block)
52
+ row = block if block_given?
53
+ if `row !== undefined`
54
+ @d3.JS.tsvParseRows(string, proc{|d|
55
+ result = row.call(d)
56
+ result == nil ? `null` : result
57
+ })
58
+ else
59
+ @d3.JS.tsvParseRows(string)
60
+ end
61
+ end
62
+
63
+ def csv_format_rows(rows)
64
+ @d3.JS.csvFormatRows(rows)
65
+ end
66
+
67
+ def tsv_format_rows(rows)
68
+ @d3.JS.tsvFormatRows(rows)
69
+ end
70
+
71
+ def csv_parse(string, row=`undefined`, &block)
72
+ row = block if block_given?
73
+ if `row !== undefined`
74
+ @d3.JS.csvParse(string, proc{|e|
75
+ result = row.call(`Opal.hash(e)`)
76
+ result == nil ? `null` : result
77
+ })
78
+ else
79
+ @d3.JS.csvParse(string).map{|e| `Opal.hash(e)` }
80
+ end
81
+ end
82
+
83
+ def tsv_parse(string, row=`undefined`, &block)
84
+ row = block if block_given?
85
+ if `row !== undefined`
86
+ @d3.JS.tsvParse(string, proc{|e|
87
+ result = row.call(`Opal.hash(e)`)
88
+ result == nil ? `null` : result
89
+ })
90
+ else
91
+ @d3.JS.tsvParse(string).map{|e| `Opal.hash(e)` }
92
+ end
93
+ end
94
+
95
+ def csv_format(rows, columns=`undefined`)
96
+ @d3.JS.csvFormat(rows.to_n, columns)
97
+ end
98
+
99
+ def tsv_format(rows, columns=`undefined`)
100
+ @d3.JS.tsvFormat(rows.to_n, columns)
101
+ end
102
+ end
103
+ end