opal-d3 0.0.20170205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
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>
|
data/lib/opal/d3/arc.rb
ADDED
@@ -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
|
data/lib/opal/d3/area.rb
ADDED
@@ -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
|
data/lib/opal/d3/axis.rb
ADDED
@@ -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,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,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
|
data/lib/opal/d3/dsv.rb
ADDED
@@ -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
|