Sha256: 0abba6f15183195d8ae90f48b3d40a20260a65b4fdcb084d42352cc1d7019054

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

require "react/test/utils" # just for mounting manually here, please ignore
require "data/elections_2016"

class ElectionComponent
  include Hyperloop::D3::Mixin

  render_with_selection('DIV') do |selection, election_data|
    list = selection.append("ul")
    max_votes = election_data.map(&:votes).max

    election_data.each do |candidate|
      item = list.append("li")
        .style("position", "relative")
      item.append("span")
        .style("background-color", candidate.color)
        .style("position", "absolute")
        .style("width", "#{100.0 * candidate.votes / max_votes}%")
        .style("height", "100%")
      item.append("span")
        .style("position", "absolute")
        .text("#{candidate.name} - #{candidate.votes} votes")
    end
  end
end

# manual mount of component, usually you would use the react_component view helper for example
React.render(React.create_element(ElectionComponent, data: Elections2016), `document.body.querySelector("#visualization")`)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyper-d3-1.0.0.lap28 spec/test_app/app/assets/javascripts/elections_2016.rb
hyper-d3-1.0.0.lap27 spec/test_app/app/assets/javascripts/elections_2016.rb
hyper-d3-1.0.0.lap26 spec/test_app/app/assets/javascripts/elections_2016.rb
hyper-d3-1.0.0.lap25 spec/test_app/app/assets/javascripts/elections_2016.rb
hyper-d3-1.0.0.lap24 spec/test_app/app/assets/javascripts/elections_2016.rb
hyper-d3-1.0.0.lap23 spec/test_app/app/assets/javascripts/elections_2016.rb