hyper-d3 1.0.0.lap27 → 1.0.0.lap28
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc439966c63817f058fd7d51e13405d0d2cfeb0ffbf92cf5002bb1118d91b85c
|
4
|
+
data.tar.gz: 5f94f38c30a145023a6b35d98f133c498c1996959b8a053c6448076a1a1c8e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec4d707f3523a864bd50d3bb3189516f67f4d3af3a7b8db9595d31e45e11a9547689a44098d90a9daf3a47697d66a0a2b492662cc56d09cdc0c9bb3436ce942
|
7
|
+
data.tar.gz: cabdedf31390553b524dba8fc6d41087309bc15ec7776b5e8920c46115aa83259d2a78c9e0b64d23bc1c4db8b215db098a427f0d324fc96a82db195a4148753e
|
data/lib/d3/selection.rb
CHANGED
data/lib/hyperloop/d3/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "react/test/utils" # just for mounting manually here, please ignore
|
2
|
+
require "data/elections_2016"
|
3
|
+
|
4
|
+
class ElectionComponent
|
5
|
+
include Hyperloop::D3::Mixin
|
6
|
+
|
7
|
+
render_with_selection('DIV') do |selection, election_data|
|
8
|
+
if selection.select("ul").empty?
|
9
|
+
list = selection.append("ul")
|
10
|
+
else
|
11
|
+
selection.select("ul").remove
|
12
|
+
list = selection.append("ul")
|
13
|
+
end
|
14
|
+
max_votes = election_data.map(&:votes).max
|
15
|
+
|
16
|
+
election_data.each do |candidate|
|
17
|
+
item = list.append("li")
|
18
|
+
.style("position", "relative")
|
19
|
+
item.append("span")
|
20
|
+
.style("background-color", candidate.color)
|
21
|
+
.style("position", "absolute")
|
22
|
+
.style("width", "#{100.0 * candidate.votes / max_votes}%")
|
23
|
+
.style("height", "100%")
|
24
|
+
item.append("span")
|
25
|
+
.style("position", "absolute")
|
26
|
+
.text("#{candidate.name} - #{candidate.votes} votes")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class OuterComponent
|
32
|
+
include Hyperloop::Component::Mixin
|
33
|
+
|
34
|
+
before_mount do
|
35
|
+
mutate.election_data Elections2016
|
36
|
+
end
|
37
|
+
|
38
|
+
render('DIV') do
|
39
|
+
ElectionComponent(data: state.election_data)
|
40
|
+
BUTTON { "Add Arnold" }.on(:click) do
|
41
|
+
arnold = { name: "Arnold Schwarzenegger", votes: 145655864, color: "#FFAdA6" }
|
42
|
+
Elections2016 << arnold unless Elections2016.include? arnold
|
43
|
+
mutate.election_data(Elections2016.map{|o| OpenStruct.new(o)})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
# manual mount of component, usually you would use the react_component view helper for example
|
48
|
+
React.render(React.create_element(OuterComponent), `document.body.querySelector("#visualization")`)
|
@@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
|
|
2
2
|
protect_from_forgery with: :exception
|
3
3
|
|
4
4
|
@@visualizations = {
|
5
|
+
event_elections_2016: "Elections 2016 with Event Handler",
|
5
6
|
elections_2016: "Elections 2016",
|
6
7
|
london_population: "London Population",
|
7
8
|
london_population_area: "London Population - Area Chart",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyper-d3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.lap28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann, Tomasz Wegrzanowski
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- spec/test_app/app/assets/javascripts/data/star_trek_voyager.rb
|
275
275
|
- spec/test_app/app/assets/javascripts/data/weather_in_london.rb
|
276
276
|
- spec/test_app/app/assets/javascripts/elections_2016.rb
|
277
|
+
- spec/test_app/app/assets/javascripts/event_elections_2016.rb
|
277
278
|
- spec/test_app/app/assets/javascripts/harry_potter.rb
|
278
279
|
- spec/test_app/app/assets/javascripts/iphones.rb
|
279
280
|
- spec/test_app/app/assets/javascripts/london_population.rb
|
@@ -443,6 +444,7 @@ test_files:
|
|
443
444
|
- spec/test_app/app/assets/javascripts/data/star_trek_voyager.rb
|
444
445
|
- spec/test_app/app/assets/javascripts/data/weather_in_london.rb
|
445
446
|
- spec/test_app/app/assets/javascripts/elections_2016.rb
|
447
|
+
- spec/test_app/app/assets/javascripts/event_elections_2016.rb
|
446
448
|
- spec/test_app/app/assets/javascripts/harry_potter.rb
|
447
449
|
- spec/test_app/app/assets/javascripts/iphones.rb
|
448
450
|
- spec/test_app/app/assets/javascripts/london_population.rb
|