hyper-d3 1.0.0.lap27 → 1.0.0.lap28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85365c8d6bd72c3069f1e9b2bad3834c0fcd3937780ae54c9193dc3c9c18add1
4
- data.tar.gz: 33eef336e28a538e9befaefa18158ce892072223b9ae745c1cda2bf82eed9b60
3
+ metadata.gz: dc439966c63817f058fd7d51e13405d0d2cfeb0ffbf92cf5002bb1118d91b85c
4
+ data.tar.gz: 5f94f38c30a145023a6b35d98f133c498c1996959b8a053c6448076a1a1c8e4c
5
5
  SHA512:
6
- metadata.gz: fb14b43123dcac84f50cdcf7565d49ca1183a6f1a6185185ca795d33792d26e3a0855370f4f3c49776fed8ecf4d7f3aa439c067a7b556350a6c35e4bc119baf6
7
- data.tar.gz: eb989e398dfac64538f30b9ad5efb638863267ddc689a17dad232c9b79bd111faf1e2cb431dfe57d69c51495e9be148c511ab1141517a430070f1b55b52df53b
6
+ metadata.gz: 8ec4d707f3523a864bd50d3bb3189516f67f4d3af3a7b8db9595d31e45e11a9547689a44098d90a9daf3a47697d66a0a2b492662cc56d09cdc0c9bb3436ce942
7
+ data.tar.gz: cabdedf31390553b524dba8fc6d41087309bc15ec7776b5e8920c46115aa83259d2a78c9e0b64d23bc1c4db8b215db098a427f0d324fc96a82db195a4148753e
@@ -2,7 +2,7 @@ module D3
2
2
  class Selection
3
3
  include D3::Native
4
4
  aliases_native %i[size]
5
- alias_native_new :empty?, :empty
5
+ alias_native :empty?, :empty
6
6
  alias_native_new :node
7
7
  alias_native_new :nodes
8
8
  alias_native_new :remove
@@ -1,5 +1,5 @@
1
1
  module Hyperloop
2
2
  module D3
3
- VERSION = "1.0.0.lap27"
3
+ VERSION = "1.0.0.lap28"
4
4
  end
5
5
  end
@@ -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.lap27
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