数か月間 d3.js から離れていました...そして、他の誰かが始めた機能を備えた単純な米国の地図を継承しました。
機能は、さまざまなサイズの単純なドットで表されます。
マイク・ボストックによる古典的なオニオンの例に似た、各ドットに発散する同心円を追加したい: http://bl.ocks.org/mbostock/4503672 (それほど不吉な見た目ではないかもしれません)
ここにブロックを設定しました: http://bl.ocks.org/mbostock/4503672
(状態がブロックで正しくレンダリングされない理由はわかりませんが、おそらく問題にはなりません。)
マイクの例では点が 1 つしかないので、彼が行ったことを私が得たもの (多くの点) に変換する方法を理解するのに苦労しています。
これが私のスクリプトです:
/**
* Page initialization
*/
$(function() {
renderMap('#map-container');
});
function renderMap(container) {
var width = 960,
height = 500,
active;
var projection = d3.geo.albersUsa()
.scale(960)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var radius = d3.scale.sqrt()
.domain([0, 1e7])
.range([0, 10]);
var path2 = d3.geo.path()
.projection(projection);
// Remove svg, if already exist
d3.select(container).select('svg').remove();
var svg = d3.select(container).append("svg")
.attr("width", width)
.attr("height", height);
svg.append("rect")
.attr("width", width)
.attr("height", height);
//.on("click", reset);
var g = svg.append("g");
queue()
.defer(d3.json, "/mbostock/raw/4090846/us.json")
.defer(d3.json, "dots.json")
.await(function (error, us, centroid) {
g.append("g")
.attr("id", "states")
.selectAll("path")
.data(topojson.feature(us, us.objects.states).features)
.enter().append("path")
.attr("d", path)
.attr("class", "state");
//.on('click', click);
g.append('path')
.attr("id", "state-borders")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("d", path)
.attr("class", "mesh");
var dots = g.append("g")
.attr("id", "dots")
.selectAll("path")
.data(centroid.data)
.enter().append("path")
.attr("class", "dot")
.attr("d", path2.pointRadius(function(d) { return radius(d.properties.pool); }));
}
);
}
リングを作成するためのマイクの例の重要な部分は次のとおりです。
setInterval(function() {
svg.append("circle")
.attr("class", "ring")
.attr("transform", "translate(" + projection([100, -8]) + ")")
.attr("r", 6)
.style("stroke-width", 3)
.style("stroke", "red")
.transition()
.ease("linear")
.duration(6000)
.style("stroke-opacity", 1e-6)
.style("stroke-width", 1)
.style("stroke", "brown")
.attr("r", 160)
.remove();
}, 750);
リングをドットに配置するにはどうすればよいですか?