hyper-d3 1.0.0.lap23
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 +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +313 -0
- data/README.md +118 -0
- data/Rakefile +31 -0
- data/hyper-d3.gemspec +27 -0
- data/lib/d3.rb +68 -0
- data/lib/d3/arc.rb +29 -0
- data/lib/d3/area.rb +53 -0
- data/lib/d3/axis.rb +79 -0
- data/lib/d3/band_scale.rb +30 -0
- data/lib/d3/collections.rb +9 -0
- data/lib/d3/color.rb +76 -0
- data/lib/d3/color_schemes.rb +34 -0
- data/lib/d3/continuous_scale.rb +60 -0
- data/lib/d3/creator.rb +11 -0
- data/lib/d3/curve.rb +74 -0
- data/lib/d3/dsv.rb +103 -0
- data/lib/d3/ease.rb +319 -0
- data/lib/d3/format.rb +95 -0
- data/lib/d3/histograms.rb +46 -0
- data/lib/d3/interpolate.rb +125 -0
- data/lib/d3/line.rb +27 -0
- data/lib/d3/map.rb +48 -0
- data/lib/d3/misc.rb +15 -0
- data/lib/d3/native.rb +112 -0
- data/lib/d3/nest.rb +100 -0
- data/lib/d3/ordinal_scale.rb +39 -0
- data/lib/d3/path.rb +24 -0
- data/lib/d3/pie.rb +25 -0
- data/lib/d3/point_scale.rb +27 -0
- data/lib/d3/polygon.rb +18 -0
- data/lib/d3/quadtree.rb +89 -0
- data/lib/d3/quantile_scale.rb +19 -0
- data/lib/d3/quantize_scale.rb +20 -0
- data/lib/d3/radial_area.rb +55 -0
- data/lib/d3/radial_line.rb +27 -0
- data/lib/d3/random.rb +14 -0
- data/lib/d3/search.rb +30 -0
- data/lib/d3/selection.rb +151 -0
- data/lib/d3/sequential_scale.rb +31 -0
- data/lib/d3/set.rb +30 -0
- data/lib/d3/source/d3-drag.js +234 -0
- data/lib/d3/source/d3-scale-chromatic.js +484 -0
- data/lib/d3/source/d3.js +17178 -0
- data/lib/d3/stack.rb +13 -0
- data/lib/d3/statistics.rb +81 -0
- data/lib/d3/symbol.rb +70 -0
- data/lib/d3/threshold_scale.rb +22 -0
- data/lib/d3/time_format.rb +47 -0
- data/lib/d3/time_interval.rb +85 -0
- data/lib/d3/transformations.rb +16 -0
- data/lib/hyper-d3.rb +17 -0
- data/lib/hyperloop/d3/component.rb +12 -0
- data/lib/hyperloop/d3/mixin.rb +59 -0
- data/lib/hyperloop/d3/version.rb +5 -0
- data/spec/arc_spec.rb +80 -0
- data/spec/area_spec.rb +98 -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 +16 -0
- data/spec/creator_spec.rb +15 -0
- data/spec/curve_spec.rb +206 -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/index.html.erb +11 -0
- data/spec/interpolate_spec.rb +152 -0
- data/spec/line_spec.rb +54 -0
- data/spec/map_spec.rb +80 -0
- data/spec/misc_spec.rb +21 -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 +123 -0
- data/spec/radial_line_spec.rb +50 -0
- data/spec/random_spec.rb +34 -0
- data/spec/search_spec.rb +69 -0
- data/spec/selection_data_spec.rb +64 -0
- data/spec/selection_manipulation_spec.rb +166 -0
- data/spec/selection_spec.rb +187 -0
- data/spec/sequential_scale_spec.rb +90 -0
- data/spec/set_spec.rb +57 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/stack_spec.rb +5 -0
- data/spec/statistics_spec.rb +65 -0
- data/spec/symbol_spec.rb +116 -0
- data/spec/test_app/.gitignore +23 -0
- data/spec/test_app/Gemfile +7 -0
- data/spec/test_app/Gemfile.lock +206 -0
- data/spec/test_app/README.md +9 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/config/manifest.js +3 -0
- data/spec/test_app/app/assets/images/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/application.js +13 -0
- data/spec/test_app/app/assets/javascripts/cable.js +13 -0
- data/spec/test_app/app/assets/javascripts/channels/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/data/elections_2016.rb +10 -0
- data/spec/test_app/app/assets/javascripts/data/harry_potter.rb +19 -0
- data/spec/test_app/app/assets/javascripts/data/iphones.rb +29 -0
- data/spec/test_app/app/assets/javascripts/data/london_population.rb +26 -0
- data/spec/test_app/app/assets/javascripts/data/man_vs_horse.rb +55 -0
- data/spec/test_app/app/assets/javascripts/data/mtg_modern_colors.rb +96 -0
- data/spec/test_app/app/assets/javascripts/data/mtg_modern_creatures.rb +116 -0
- data/spec/test_app/app/assets/javascripts/data/olympics_2016_medals.rb +100 -0
- data/spec/test_app/app/assets/javascripts/data/paradox.rb +60 -0
- data/spec/test_app/app/assets/javascripts/data/polish_pms.rb +28 -0
- data/spec/test_app/app/assets/javascripts/data/star_trek_voyager.rb +183 -0
- data/spec/test_app/app/assets/javascripts/data/weather_in_london.rb +381 -0
- data/spec/test_app/app/assets/javascripts/elections_2016.rb +27 -0
- data/spec/test_app/app/assets/javascripts/harry_potter.rb +42 -0
- data/spec/test_app/app/assets/javascripts/iphones.rb +54 -0
- data/spec/test_app/app/assets/javascripts/london_population.rb +53 -0
- data/spec/test_app/app/assets/javascripts/london_population_area.rb +49 -0
- data/spec/test_app/app/assets/javascripts/man_vs_horse.rb +60 -0
- data/spec/test_app/app/assets/javascripts/mtg_modern_colors.rb +56 -0
- data/spec/test_app/app/assets/javascripts/mtg_modern_creatures.rb +70 -0
- data/spec/test_app/app/assets/javascripts/olympics_2016_medals.rb +62 -0
- data/spec/test_app/app/assets/javascripts/paradox.rb +64 -0
- data/spec/test_app/app/assets/javascripts/polish_pms.rb +60 -0
- data/spec/test_app/app/assets/javascripts/star_trek_voyager.rb +44 -0
- data/spec/test_app/app/assets/javascripts/weather_in_london.rb +69 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/test_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +27 -0
- data/spec/test_app/app/controllers/concerns/.keep +0 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/jobs/application_job.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/models/application_record.rb +3 -0
- data/spec/test_app/app/models/concerns/.keep +0 -0
- data/spec/test_app/app/views/application/index.erb +18 -0
- data/spec/test_app/app/views/application/visualization.erb +28 -0
- data/spec/test_app/app/views/layouts/application.html.erb +13 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +4 -0
- data/spec/test_app/bin/rake +4 -0
- data/spec/test_app/bin/setup +38 -0
- data/spec/test_app/bin/update +29 -0
- data/spec/test_app/bin/yarn +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +18 -0
- data/spec/test_app/config/boot.rb +3 -0
- data/spec/test_app/config/cable.yml +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +91 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/test_app/config/initializers/assets.rb +14 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +33 -0
- data/spec/test_app/config/puma.rb +56 -0
- data/spec/test_app/config/routes.rb +5 -0
- data/spec/test_app/config/secrets.yml +32 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/lib/assets/.keep +0 -0
- data/spec/test_app/lib/tasks/.keep +0 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/package.json +5 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/test_app/public/apple-touch-icon.png +0 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/public/robots.txt +1 -0
- data/spec/test_app/test/application_system_test_case.rb +5 -0
- data/spec/test_app/test/controllers/.keep +0 -0
- data/spec/test_app/test/fixtures/.keep +0 -0
- data/spec/test_app/test/fixtures/files/.keep +0 -0
- data/spec/test_app/test/helpers/.keep +0 -0
- data/spec/test_app/test/integration/.keep +0 -0
- data/spec/test_app/test/mailers/.keep +0 -0
- data/spec/test_app/test/models/.keep +0 -0
- data/spec/test_app/test/system/.keep +0 -0
- data/spec/test_app/test/test_helper.rb +10 -0
- data/spec/test_app/tmp/.keep +0 -0
- data/spec/test_app/vendor/.keep +0 -0
- data/spec/threshold_scale_spec.rb +28 -0
- data/spec/time_format_spec.rb +100 -0
- data/spec/time_interval_spec.rb +314 -0
- data/spec/transformations_spec.rb +51 -0
- data/startrekvoyager.png +0 -0
- metadata +529 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "bundler"
|
|
2
|
+
Bundler.require
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
|
|
5
|
+
require "opal/rspec/rake_task"
|
|
6
|
+
Opal::RSpec::RakeTask.new(:test) do |server, task|
|
|
7
|
+
ENV["SPEC_OPTS"] = "--color --require spec_helper"
|
|
8
|
+
server.index_path = "spec/html/index.html.erb"
|
|
9
|
+
server.append_path "lib"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
desc "Create static snapshot of the demo page"
|
|
13
|
+
task :snapshot do
|
|
14
|
+
dir = Pathname("snapshot")
|
|
15
|
+
system "trash", dir.to_s if dir.exist?
|
|
16
|
+
dir.mkpath
|
|
17
|
+
Dir.chdir(dir) do
|
|
18
|
+
system "wget --mirror -np http://localhost:9292/"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc "Build gem"
|
|
23
|
+
task "gem:build" do
|
|
24
|
+
system "gem build opal-d3.gemspec"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc "Upload gem"
|
|
28
|
+
task "gem:push" => "gem:build" do
|
|
29
|
+
gem_file = Dir["opal-d3-*.gem"][-1] or raise "No gem found"
|
|
30
|
+
system "gem", "push", gem_file
|
|
31
|
+
end
|
data/hyper-d3.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative "lib/hyperloop/d3/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = "hyper-d3"
|
|
5
|
+
s.version = Hyperloop::D3::VERSION
|
|
6
|
+
s.author = "Jan Biedermann, Tomasz Wegrzanowski"
|
|
7
|
+
s.email = "jan@kursator.de"
|
|
8
|
+
s.homepage = "https://github.com/janbiedermann/hyper-d3"
|
|
9
|
+
s.summary = "Ruby bindings for D3 as a Ruby Haperloop Component"
|
|
10
|
+
s.description = "Write React Components in ruby to show graphics created with D3.js"
|
|
11
|
+
|
|
12
|
+
s.files = `git ls-files`.split("\n")
|
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
+
s.require_paths = ["lib"]
|
|
16
|
+
|
|
17
|
+
s.add_runtime_dependency "opal", "~> 0.11.0"
|
|
18
|
+
s.add_runtime_dependency "opal-activesupport", "~> 0.3.1"
|
|
19
|
+
s.add_runtime_dependency "hyper-component", "~> 1.0.0.lap23"
|
|
20
|
+
s.add_runtime_dependency "hyperloop-config", "~> 1.0.0.lap23"
|
|
21
|
+
s.add_development_dependency "hyperloop", "~> 1.0.0.lap23"
|
|
22
|
+
s.add_development_dependency "hyper-spec", "~> 1.0.0.lap23"
|
|
23
|
+
s.add_development_dependency "listen"
|
|
24
|
+
s.add_development_dependency "rake", ">= 11.3.0"
|
|
25
|
+
s.add_development_dependency "rails", ">= 5.1.0"
|
|
26
|
+
s.add_development_dependency "sqlite3"
|
|
27
|
+
end
|
data/lib/d3.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require "opal"
|
|
2
|
+
|
|
3
|
+
require 'active_support/core_ext/string'
|
|
4
|
+
|
|
5
|
+
class Module
|
|
6
|
+
def aliases_d3(native_names)
|
|
7
|
+
native_names.each do |native_name|
|
|
8
|
+
alias_d3(native_name.underscore, native_name)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def alias_d3(ruby_name, js_name=ruby_name)
|
|
13
|
+
define_method(ruby_name) do |*args|
|
|
14
|
+
@d3.JS[js_name].JS.apply(@d3, `Opal.to_a(args)`)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module D3
|
|
20
|
+
@d3 = `window.d3`
|
|
21
|
+
class << self
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
# Metaclass:
|
|
25
|
+
require "d3/native"
|
|
26
|
+
|
|
27
|
+
# Everything else:
|
|
28
|
+
require "d3/arc"
|
|
29
|
+
require "d3/area"
|
|
30
|
+
require "d3/axis"
|
|
31
|
+
require "d3/band_scale"
|
|
32
|
+
require "d3/collections"
|
|
33
|
+
require "d3/color"
|
|
34
|
+
require "d3/color_schemes"
|
|
35
|
+
require "d3/continuous_scale"
|
|
36
|
+
require "d3/creator"
|
|
37
|
+
require "d3/curve"
|
|
38
|
+
require "d3/dsv"
|
|
39
|
+
require "d3/ease"
|
|
40
|
+
require "d3/format"
|
|
41
|
+
require "d3/histograms"
|
|
42
|
+
require "d3/interpolate"
|
|
43
|
+
require "d3/line"
|
|
44
|
+
require "d3/map"
|
|
45
|
+
require "d3/misc"
|
|
46
|
+
require "d3/nest"
|
|
47
|
+
require "d3/ordinal_scale"
|
|
48
|
+
require "d3/path"
|
|
49
|
+
require "d3/pie"
|
|
50
|
+
require "d3/point_scale"
|
|
51
|
+
require "d3/polygon"
|
|
52
|
+
require "d3/quadtree"
|
|
53
|
+
require "d3/quantile_scale"
|
|
54
|
+
require "d3/quantize_scale"
|
|
55
|
+
require "d3/radial_area"
|
|
56
|
+
require "d3/radial_line"
|
|
57
|
+
require "d3/random"
|
|
58
|
+
require "d3/search"
|
|
59
|
+
require "d3/selection"
|
|
60
|
+
require "d3/sequential_scale"
|
|
61
|
+
require "d3/set"
|
|
62
|
+
require "d3/stack"
|
|
63
|
+
require "d3/statistics"
|
|
64
|
+
require "d3/symbol"
|
|
65
|
+
require "d3/threshold_scale"
|
|
66
|
+
require "d3/time_format"
|
|
67
|
+
require "d3/time_interval"
|
|
68
|
+
require "d3/transformations"
|
data/lib/d3/arc.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class ArcGenerator
|
|
3
|
+
include D3::Native
|
|
4
|
+
def call(*args)
|
|
5
|
+
@native.call(*args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
attributes_d3_block %i[
|
|
9
|
+
innerRadius
|
|
10
|
+
outerRadius
|
|
11
|
+
cornerRadius
|
|
12
|
+
padRadius
|
|
13
|
+
startAngle
|
|
14
|
+
endAngle
|
|
15
|
+
padAngle
|
|
16
|
+
]
|
|
17
|
+
alias_native_new :centroid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class << self
|
|
21
|
+
def arc(prop_hash = nil)
|
|
22
|
+
if prop_hash
|
|
23
|
+
D3::ArcGenerator.new @d3.JS.arc(prop_hash.to_n)
|
|
24
|
+
else
|
|
25
|
+
D3::ArcGenerator.new @d3.JS.arc
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/d3/area.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
attributes_d3_block %i[
|
|
11
|
+
x x0 x1 y y0 y1 defined
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def curve(new_value=`undefined`)
|
|
15
|
+
if `new_value === undefined`
|
|
16
|
+
D3::Curve.new @native.JS.curve
|
|
17
|
+
else
|
|
18
|
+
@native.JS.curve(new_value.to_n)
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def area_radial(data = nil)
|
|
24
|
+
D3::RadialAreaGenerator.radial_area(data)
|
|
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(data = nil)
|
|
46
|
+
if data
|
|
47
|
+
D3::AreaGenerator.new @d3.JS.area(data.to_n)
|
|
48
|
+
else
|
|
49
|
+
D3::AreaGenerator.new @d3.JS.area
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/d3/axis.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
attributes_d3 %i[
|
|
14
|
+
tickSizeInner
|
|
15
|
+
tickSizeOuter
|
|
16
|
+
tickSize
|
|
17
|
+
tickPadding
|
|
18
|
+
tickArguments
|
|
19
|
+
]
|
|
20
|
+
alias_native_chainable :ticks
|
|
21
|
+
|
|
22
|
+
def call(context)
|
|
23
|
+
@native.call(context.to_n)
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def scale(v=`undefined`)
|
|
28
|
+
if `v === undefined`
|
|
29
|
+
@scale_obj
|
|
30
|
+
else
|
|
31
|
+
@scale_obj = v
|
|
32
|
+
@native.JS.scale(v.to_n)
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
alias_method :scale=, :scale
|
|
37
|
+
|
|
38
|
+
def tick_values(v=`undefined`)
|
|
39
|
+
if `v === undefined`
|
|
40
|
+
result = @native.JS.tickValues
|
|
41
|
+
`result === null ? nil : result`
|
|
42
|
+
else
|
|
43
|
+
@native.JS.tickValues(v == nil ? `null` : v)
|
|
44
|
+
self
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
alias_method :tick_values=, :tick_values
|
|
48
|
+
|
|
49
|
+
def tick_format(v=`undefined`, &block)
|
|
50
|
+
v = block if block_given?
|
|
51
|
+
if `v === undefined`
|
|
52
|
+
result = @native.JS.tickFormat
|
|
53
|
+
`result === null ? nil : result`
|
|
54
|
+
else
|
|
55
|
+
@native.JS.tickFormat(v == nil ? `null` : v)
|
|
56
|
+
self
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
alias_method :tick_format=, :tick_format
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class << self
|
|
63
|
+
def axis_top(scale)
|
|
64
|
+
D3::Axis.new(@d3.JS.axisTop(scale.to_n), scale)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def axis_bottom(scale)
|
|
68
|
+
D3::Axis.new(@d3.JS.axisBottom(scale.to_n), scale)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def axis_right(scale)
|
|
72
|
+
D3::Axis.new(@d3.JS.axisRight(scale.to_n), scale)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def axis_left(scale)
|
|
76
|
+
D3::Axis.new(@d3.JS.axisLeft(scale.to_n), scale)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
9
|
+
attributes_d3 %i[
|
|
10
|
+
domain
|
|
11
|
+
range
|
|
12
|
+
rangeRound
|
|
13
|
+
padding
|
|
14
|
+
paddingInner
|
|
15
|
+
paddingOuter
|
|
16
|
+
align
|
|
17
|
+
round
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
alias_native_new :copy
|
|
21
|
+
|
|
22
|
+
aliases_native %i[bandwidth step]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class << self
|
|
26
|
+
def scale_band(*args)
|
|
27
|
+
D3::BandScale.new @d3.JS.scaleBand(*args)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/d3/color.rb
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class Color
|
|
3
|
+
include D3::Native
|
|
4
|
+
attr_reader :native
|
|
5
|
+
aliases_native_new %i[brighter darker]
|
|
6
|
+
alias_native :displayable?, :displayable
|
|
7
|
+
alias_native :to_s, :toString
|
|
8
|
+
|
|
9
|
+
# Various subsets of these are valid depending on color - maybe we should properly subclass?
|
|
10
|
+
def a; `#@native.a` end
|
|
11
|
+
def b; `#@native.b` end
|
|
12
|
+
def c; `#@native.c` end
|
|
13
|
+
def g; `#@native.g` end
|
|
14
|
+
def h; `#@native.h` end
|
|
15
|
+
def l; `#@native.l` end
|
|
16
|
+
def r; `#@native.r` end
|
|
17
|
+
def s; `#@native.s` end
|
|
18
|
+
def opacity; `#@native.opacity` end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class <<self
|
|
22
|
+
def color(description)
|
|
23
|
+
color = @d3.JS.color(description)
|
|
24
|
+
if color
|
|
25
|
+
D3::Color.new(color)
|
|
26
|
+
else
|
|
27
|
+
raise ArgumentError, "Invalid color: #{description}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def rgb(*args)
|
|
32
|
+
color = if args[0].is_a?(Color)
|
|
33
|
+
@d3.JS.rgb(args[0].native)
|
|
34
|
+
else
|
|
35
|
+
@d3.JS.rgb(*args)
|
|
36
|
+
end
|
|
37
|
+
D3::Color.new(color)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def hsl(*args)
|
|
41
|
+
color = if args[0].is_a?(Color)
|
|
42
|
+
@d3.JS.hsl(args[0].native)
|
|
43
|
+
else
|
|
44
|
+
@d3.JS.hsl(*args)
|
|
45
|
+
end
|
|
46
|
+
D3::Color.new(color)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def lab(*args)
|
|
50
|
+
color = if args[0].is_a?(Color)
|
|
51
|
+
@d3.JS.lab(args[0].native)
|
|
52
|
+
else
|
|
53
|
+
@d3.JS.lab(*args)
|
|
54
|
+
end
|
|
55
|
+
D3::Color.new(color)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def hcl(*args)
|
|
59
|
+
color = if args[0].is_a?(Color)
|
|
60
|
+
@d3.JS.hcl(args[0].native)
|
|
61
|
+
else
|
|
62
|
+
@d3.JS.hcl(*args)
|
|
63
|
+
end
|
|
64
|
+
D3::Color.new(color)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def cubehelix(*args)
|
|
68
|
+
color = if args[0].is_a?(Color)
|
|
69
|
+
@d3.JS.cubehelix(args[0].native)
|
|
70
|
+
else
|
|
71
|
+
@d3.JS.cubehelix(*args)
|
|
72
|
+
end
|
|
73
|
+
D3::Color.new(color)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
# requires d3-scale-chromatic
|
|
3
|
+
|
|
4
|
+
class << self
|
|
5
|
+
%w[Category10 Category20 Category20b Category20c
|
|
6
|
+
Accent Dark2 Paired Pastel1 Pastel2 Set1 Set2 Set3].each do |native_category|
|
|
7
|
+
define_method("scheme_#{native_category.underscore.sub(/[123]/,'_\0')}") do
|
|
8
|
+
`window.d3`.JS["scheme#{native_category}"]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
%w[Blues Greens Greys Oranges Purples Reds
|
|
13
|
+
BrBG BuGn BuPu GnBu OrRd PRGn PiYG PuBu PuBuGn PuOr PuRd
|
|
14
|
+
RdBu RdPu RdGy RdYlBu RdYlGn YlGn YlGnBu YlOrBr YlOrRd
|
|
15
|
+
Spectral].each do |native_category|
|
|
16
|
+
define_method("interpolate_#{native_category.underscore}") do |k|
|
|
17
|
+
`window.d3`.JS["interpolate#{native_category}"].JS.apply(`window.d3`, `Opal.to_a(k)`)
|
|
18
|
+
end
|
|
19
|
+
define_method("scheme_#{native_category.underscore}") do |k=nil|
|
|
20
|
+
if k
|
|
21
|
+
`window.d3`.JS["scheme#{native_category}"][k]
|
|
22
|
+
else
|
|
23
|
+
`window.d3`.JS["scheme#{native_category}"]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
%w[Cool CubehelixDefault Inferno Magma Plasma Rainbow Viridis Warm].each do |native_category|
|
|
29
|
+
define_method("interpolate_#{native_category.underscore}") do |k|
|
|
30
|
+
`window.d3`.JS["interpolate#{native_category}"].JS.apply(`window.d3`, `Opal.to_a(k)`)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|