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/lib/d3/random.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class << self
|
|
3
|
+
# These return functions in d3,
|
|
4
|
+
# which doesn't feel very Ruby, so we call the functions
|
|
5
|
+
aliases_d3 %i[
|
|
6
|
+
randomUniform
|
|
7
|
+
randomNormal
|
|
8
|
+
randomLogNormal
|
|
9
|
+
randomBates
|
|
10
|
+
randomIrwinHall
|
|
11
|
+
randomExponential
|
|
12
|
+
]
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/d3/search.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# all these methods return indexes not values
|
|
2
|
+
module D3
|
|
3
|
+
class Bisector
|
|
4
|
+
include D3::Native
|
|
5
|
+
alias_native_new :left
|
|
6
|
+
alias_native_new :right
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
aliases_d3 %i[
|
|
11
|
+
ascending
|
|
12
|
+
descending
|
|
13
|
+
bisect
|
|
14
|
+
bisectLeft
|
|
15
|
+
bisectRight
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
def scan(array, &block)
|
|
19
|
+
if block_given?
|
|
20
|
+
@d3.JS.scan(array, block)
|
|
21
|
+
else
|
|
22
|
+
@d3.JS.scan(array)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def bisector(&block)
|
|
27
|
+
D3::Bisector.new @d3.JS.bisector(block)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/d3/selection.rb
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class Selection
|
|
3
|
+
include D3::Native
|
|
4
|
+
aliases_native %i[size]
|
|
5
|
+
alias_native_new :empty?, :empty
|
|
6
|
+
alias_native_new :node
|
|
7
|
+
alias_native_new :nodes
|
|
8
|
+
alias_native_new :remove
|
|
9
|
+
alias_native_new :select
|
|
10
|
+
alias_native_new :select_all, :selectAll
|
|
11
|
+
alias_native_new :enter
|
|
12
|
+
alias_native_new :exit
|
|
13
|
+
alias_native_chainable :raise
|
|
14
|
+
alias_native_chainable :lower
|
|
15
|
+
|
|
16
|
+
def inspect
|
|
17
|
+
`#@native.toString()`
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
attributes_d3_block %i[text html]
|
|
21
|
+
|
|
22
|
+
def data(data=nil,key=nil,&block)
|
|
23
|
+
if block
|
|
24
|
+
self.class.new @native.JS.data(block)
|
|
25
|
+
elsif key != nil
|
|
26
|
+
self.class.new @native.JS.data(data,key)
|
|
27
|
+
elsif data != nil
|
|
28
|
+
self.class.new @native.JS.data(data)
|
|
29
|
+
else
|
|
30
|
+
@native.JS.data
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def append(name=`undefined`, &block)
|
|
35
|
+
raise if `name !== undefined` and block_given?
|
|
36
|
+
name = block if block_given?
|
|
37
|
+
D3::Selection.new @native.JS.append(name.to_n)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def insert(name=`undefined`, before=`undefined`, &block)
|
|
41
|
+
if `name === undefined`
|
|
42
|
+
raise unless block_given?
|
|
43
|
+
D3::Selection.new @native.JS.insert(block.to_n)
|
|
44
|
+
elsif `before === undefined`
|
|
45
|
+
if block_given?
|
|
46
|
+
D3::Selection.new @native.JS.insert(name.to_n, block.to_n)
|
|
47
|
+
else
|
|
48
|
+
D3::Selection.new @native.JS.insert(name.to_n)
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
raise if block_given?
|
|
52
|
+
D3::Selection.new @native.JS.insert(name.to_n, before.to_n)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def call(context)
|
|
57
|
+
@native.JS.call(context.to_n)
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def merge(other)
|
|
62
|
+
D3::Selection.new @native.JS.merge(other.to_n)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def classed(classes, yesno=`undefined`, &block)
|
|
66
|
+
if block_given?
|
|
67
|
+
@native.JS.classed(classes, block)
|
|
68
|
+
self
|
|
69
|
+
elsif `yesno !== undefined`
|
|
70
|
+
@native.JS.classed(classes, yesno)
|
|
71
|
+
self
|
|
72
|
+
else
|
|
73
|
+
@native.JS.classed(classes)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def filter(other=`undefined`,&block)
|
|
78
|
+
if block_given?
|
|
79
|
+
D3::Selection.new @native.JS.filter(block)
|
|
80
|
+
else
|
|
81
|
+
D3::Selection.new @native.JS.filter(other)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def each(other=`undefined`,&block)
|
|
86
|
+
if block_given?
|
|
87
|
+
@native.JS.each(block)
|
|
88
|
+
else
|
|
89
|
+
@native.JS.each(other)
|
|
90
|
+
end
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def property(key, value=`undefined`)
|
|
95
|
+
if `value === undefined`
|
|
96
|
+
@native.JS.property(key)
|
|
97
|
+
else
|
|
98
|
+
@native.JS.property(key, value)
|
|
99
|
+
self
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Usage:
|
|
104
|
+
# style("foo")
|
|
105
|
+
# style("foo"){ value }
|
|
106
|
+
# style("foo", value)
|
|
107
|
+
# style("foo", value, priority)
|
|
108
|
+
def style(name, value=`undefined`, priority=`undefined`, &block)
|
|
109
|
+
if block
|
|
110
|
+
raise if `name === undefined` or `priority !== undefined` or `value !== undefined`
|
|
111
|
+
Selection.new @native.JS.style(name, block)
|
|
112
|
+
elsif `value === undefined`
|
|
113
|
+
@native.JS.style(name)
|
|
114
|
+
else
|
|
115
|
+
value = `value === nil ? null : value`
|
|
116
|
+
Selection.new @native.JS.style(name, value, priority)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# nil means something specific (reset value),
|
|
121
|
+
# so we need another special value
|
|
122
|
+
def attr(name, value=`undefined`, &block)
|
|
123
|
+
if block
|
|
124
|
+
@native.JS.attr(name, block)
|
|
125
|
+
self
|
|
126
|
+
elsif `value == undefined`
|
|
127
|
+
@native.JS.attr(name)
|
|
128
|
+
elsif value == nil
|
|
129
|
+
@native.JS.attr(name, `null`)
|
|
130
|
+
self
|
|
131
|
+
else
|
|
132
|
+
@native.JS.attr(name, value)
|
|
133
|
+
self
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
class << self
|
|
139
|
+
def selection
|
|
140
|
+
D3::Selection.new(@d3.JS.selection)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def select(selector)
|
|
144
|
+
D3::Selection.new(@d3.JS.select(selector))
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def select_all(selector)
|
|
148
|
+
D3::Selection.new(@d3.JS.selectAll(selector))
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class SequentialScale
|
|
3
|
+
include D3::Native
|
|
4
|
+
|
|
5
|
+
def call(t)
|
|
6
|
+
@native.call(t)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
attributes_d3 %i[domain clamp]
|
|
10
|
+
|
|
11
|
+
def copy
|
|
12
|
+
self.class.new @native.JS.copy
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def interpolator(&block)
|
|
16
|
+
if block_given?
|
|
17
|
+
@native.JS.interpolator(block)
|
|
18
|
+
self
|
|
19
|
+
else
|
|
20
|
+
@native.JS.interpolator
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class << self
|
|
26
|
+
def scale_sequential(&block)
|
|
27
|
+
raise unless block_given?
|
|
28
|
+
SequentialScale.new @d3.JS.scaleSequential(block)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/d3/set.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module D3
|
|
2
|
+
class Set
|
|
3
|
+
include D3::Native
|
|
4
|
+
alias_native :empty?, :empty
|
|
5
|
+
alias_native :has?, :has
|
|
6
|
+
aliases_native %i[size values]
|
|
7
|
+
aliases_native_chainable %i[add clear remove]
|
|
8
|
+
|
|
9
|
+
def each(&block)
|
|
10
|
+
@native.JS.each(block)
|
|
11
|
+
self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def inspect
|
|
15
|
+
"#<D3::Set: {#{ values.join(", ") }}>"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
def set(array=nil, &block)
|
|
21
|
+
if block_given?
|
|
22
|
+
D3::Set.new @d3.JS.set(array, proc{|x| yield(x)})
|
|
23
|
+
elsif array
|
|
24
|
+
D3::Set.new @d3.JS.set(array)
|
|
25
|
+
else
|
|
26
|
+
D3::Set.new @d3.JS.set()
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// https://d3js.org/d3-drag/ Version 1.2.1. Copyright 2017 Mike Bostock.
|
|
2
|
+
(function (global, factory) {
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-dispatch'), require('d3-selection')) :
|
|
4
|
+
typeof define === 'function' && define.amd ? define(['exports', 'd3-dispatch', 'd3-selection'], factory) :
|
|
5
|
+
(factory((global.d3 = global.d3 || {}),global.d3,global.d3));
|
|
6
|
+
}(this, (function (exports,d3Dispatch,d3Selection) { 'use strict';
|
|
7
|
+
|
|
8
|
+
function nopropagation() {
|
|
9
|
+
d3Selection.event.stopImmediatePropagation();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var noevent = function() {
|
|
13
|
+
d3Selection.event.preventDefault();
|
|
14
|
+
d3Selection.event.stopImmediatePropagation();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var nodrag = function(view) {
|
|
18
|
+
var root = view.document.documentElement,
|
|
19
|
+
selection = d3Selection.select(view).on("dragstart.drag", noevent, true);
|
|
20
|
+
if ("onselectstart" in root) {
|
|
21
|
+
selection.on("selectstart.drag", noevent, true);
|
|
22
|
+
} else {
|
|
23
|
+
root.__noselect = root.style.MozUserSelect;
|
|
24
|
+
root.style.MozUserSelect = "none";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function yesdrag(view, noclick) {
|
|
29
|
+
var root = view.document.documentElement,
|
|
30
|
+
selection = d3Selection.select(view).on("dragstart.drag", null);
|
|
31
|
+
if (noclick) {
|
|
32
|
+
selection.on("click.drag", noevent, true);
|
|
33
|
+
setTimeout(function() { selection.on("click.drag", null); }, 0);
|
|
34
|
+
}
|
|
35
|
+
if ("onselectstart" in root) {
|
|
36
|
+
selection.on("selectstart.drag", null);
|
|
37
|
+
} else {
|
|
38
|
+
root.style.MozUserSelect = root.__noselect;
|
|
39
|
+
delete root.__noselect;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var constant = function(x) {
|
|
44
|
+
return function() {
|
|
45
|
+
return x;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch$$1) {
|
|
50
|
+
this.target = target;
|
|
51
|
+
this.type = type;
|
|
52
|
+
this.subject = subject;
|
|
53
|
+
this.identifier = id;
|
|
54
|
+
this.active = active;
|
|
55
|
+
this.x = x;
|
|
56
|
+
this.y = y;
|
|
57
|
+
this.dx = dx;
|
|
58
|
+
this.dy = dy;
|
|
59
|
+
this._ = dispatch$$1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
DragEvent.prototype.on = function() {
|
|
63
|
+
var value = this._.on.apply(this._, arguments);
|
|
64
|
+
return value === this._ ? this : value;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Ignore right-click, since that should open the context menu.
|
|
68
|
+
function defaultFilter() {
|
|
69
|
+
return !d3Selection.event.button;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function defaultContainer() {
|
|
73
|
+
return this.parentNode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function defaultSubject(d) {
|
|
77
|
+
return d == null ? {x: d3Selection.event.x, y: d3Selection.event.y} : d;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function defaultTouchable() {
|
|
81
|
+
return "ontouchstart" in this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var drag = function() {
|
|
85
|
+
var filter = defaultFilter,
|
|
86
|
+
container = defaultContainer,
|
|
87
|
+
subject = defaultSubject,
|
|
88
|
+
touchable = defaultTouchable,
|
|
89
|
+
gestures = {},
|
|
90
|
+
listeners = d3Dispatch.dispatch("start", "drag", "end"),
|
|
91
|
+
active = 0,
|
|
92
|
+
mousedownx,
|
|
93
|
+
mousedowny,
|
|
94
|
+
mousemoving,
|
|
95
|
+
touchending,
|
|
96
|
+
clickDistance2 = 0;
|
|
97
|
+
|
|
98
|
+
function drag(selection) {
|
|
99
|
+
selection
|
|
100
|
+
.on("mousedown.drag", mousedowned)
|
|
101
|
+
.filter(touchable)
|
|
102
|
+
.on("touchstart.drag", touchstarted)
|
|
103
|
+
.on("touchmove.drag", touchmoved)
|
|
104
|
+
.on("touchend.drag touchcancel.drag", touchended)
|
|
105
|
+
.style("touch-action", "none")
|
|
106
|
+
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function mousedowned() {
|
|
110
|
+
if (touchending || !filter.apply(this, arguments)) return;
|
|
111
|
+
var gesture = beforestart("mouse", container.apply(this, arguments), d3Selection.mouse, this, arguments);
|
|
112
|
+
if (!gesture) return;
|
|
113
|
+
d3Selection.select(d3Selection.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
|
|
114
|
+
nodrag(d3Selection.event.view);
|
|
115
|
+
nopropagation();
|
|
116
|
+
mousemoving = false;
|
|
117
|
+
mousedownx = d3Selection.event.clientX;
|
|
118
|
+
mousedowny = d3Selection.event.clientY;
|
|
119
|
+
gesture("start");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function mousemoved() {
|
|
123
|
+
noevent();
|
|
124
|
+
if (!mousemoving) {
|
|
125
|
+
var dx = d3Selection.event.clientX - mousedownx, dy = d3Selection.event.clientY - mousedowny;
|
|
126
|
+
mousemoving = dx * dx + dy * dy > clickDistance2;
|
|
127
|
+
}
|
|
128
|
+
gestures.mouse("drag");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function mouseupped() {
|
|
132
|
+
d3Selection.select(d3Selection.event.view).on("mousemove.drag mouseup.drag", null);
|
|
133
|
+
yesdrag(d3Selection.event.view, mousemoving);
|
|
134
|
+
noevent();
|
|
135
|
+
gestures.mouse("end");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function touchstarted() {
|
|
139
|
+
if (!filter.apply(this, arguments)) return;
|
|
140
|
+
var touches = d3Selection.event.changedTouches,
|
|
141
|
+
c = container.apply(this, arguments),
|
|
142
|
+
n = touches.length, i, gesture;
|
|
143
|
+
|
|
144
|
+
for (i = 0; i < n; ++i) {
|
|
145
|
+
if (gesture = beforestart(touches[i].identifier, c, d3Selection.touch, this, arguments)) {
|
|
146
|
+
nopropagation();
|
|
147
|
+
gesture("start");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function touchmoved() {
|
|
153
|
+
var touches = d3Selection.event.changedTouches,
|
|
154
|
+
n = touches.length, i, gesture;
|
|
155
|
+
|
|
156
|
+
for (i = 0; i < n; ++i) {
|
|
157
|
+
if (gesture = gestures[touches[i].identifier]) {
|
|
158
|
+
noevent();
|
|
159
|
+
gesture("drag");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function touchended() {
|
|
165
|
+
var touches = d3Selection.event.changedTouches,
|
|
166
|
+
n = touches.length, i, gesture;
|
|
167
|
+
|
|
168
|
+
if (touchending) clearTimeout(touchending);
|
|
169
|
+
touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
|
|
170
|
+
for (i = 0; i < n; ++i) {
|
|
171
|
+
if (gesture = gestures[touches[i].identifier]) {
|
|
172
|
+
nopropagation();
|
|
173
|
+
gesture("end");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function beforestart(id, container, point, that, args) {
|
|
179
|
+
var p = point(container, id), s, dx, dy,
|
|
180
|
+
sublisteners = listeners.copy();
|
|
181
|
+
|
|
182
|
+
if (!d3Selection.customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
|
|
183
|
+
if ((d3Selection.event.subject = s = subject.apply(that, args)) == null) return false;
|
|
184
|
+
dx = s.x - p[0] || 0;
|
|
185
|
+
dy = s.y - p[1] || 0;
|
|
186
|
+
return true;
|
|
187
|
+
})) return;
|
|
188
|
+
|
|
189
|
+
return function gesture(type) {
|
|
190
|
+
var p0 = p, n;
|
|
191
|
+
switch (type) {
|
|
192
|
+
case "start": gestures[id] = gesture, n = active++; break;
|
|
193
|
+
case "end": delete gestures[id], --active; // nobreak
|
|
194
|
+
case "drag": p = point(container, id), n = active; break;
|
|
195
|
+
}
|
|
196
|
+
d3Selection.customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
drag.filter = function(_) {
|
|
201
|
+
return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), drag) : filter;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
drag.container = function(_) {
|
|
205
|
+
return arguments.length ? (container = typeof _ === "function" ? _ : constant(_), drag) : container;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
drag.subject = function(_) {
|
|
209
|
+
return arguments.length ? (subject = typeof _ === "function" ? _ : constant(_), drag) : subject;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
drag.touchable = function(_) {
|
|
213
|
+
return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), drag) : touchable;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
drag.on = function() {
|
|
217
|
+
var value = listeners.on.apply(listeners, arguments);
|
|
218
|
+
return value === listeners ? drag : value;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
drag.clickDistance = function(_) {
|
|
222
|
+
return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
return drag;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
exports.drag = drag;
|
|
229
|
+
exports.dragDisable = nodrag;
|
|
230
|
+
exports.dragEnable = yesdrag;
|
|
231
|
+
|
|
232
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
233
|
+
|
|
234
|
+
})));
|