describe "d3 - selection - data" do after(:each) do D3.select("#test-area").html("") end let(:root) { D3.select("#test-area") } let(:html) { root.html } describe "list" do let(:data) {[ {name: "A", value: 10}, {name: "B", value: 20}, {name: "C", value: 30}, ]} it "enter" do root .append("ul") .select_all("li") .data(data) .enter .append("li") .html{|d| "#{d[:name]}"} .style("font-size"){|d| "#{d[:value]}px"} expect(html).to eq([ %Q[], ].join) end end describe "matrix" do let(:data) { [ [11975, 5871, 8916, 2868], [ 1951, 10048, 2060, 6171], [ 8010, 16145, 8090, 8045], [ 1013, 990, 940, 6907], ] } it do tr = root .append("table") .select_all("tr") .data(data) .enter .append("tr") tr.select_all("td") .data{|d| d} .enter .append("td") .text{|d| d} expect(html).to eq([ %Q[], %Q[], %Q[], %Q[], %Q[], %Q[
11975587189162868
19511004820606171
80101614580908045
10139909406907
], ].join) end end end