私はBostock's Quantile Choroplethのバリエーションで作業しています。D3 Choroplethにフィルタとメッシュを適用する方法
私は投影法を正しくスケーリングし、自分のデータを統合しました。私は現在、状態IDが48から始まる郡IDだけを含むようにjson郡データをフィルタリングしています。
しかし、私はまだ完全に機能しますが、辺境の郡の間で弧を結合するにはまだ.mesh関数を適用する必要があります。さもなければ、私がホバリングの影響を加えると、私は変な不均一なボーダーを得るでしょう。
データコールをデータム(メッシュ)呼び出しで置き換えようとしましたが(コメントアウトされた行のを参照)、動作しませんでした。ここで
は私の作業コードです:
function ready(error, us) {
if (error) throw error;
//define the feature of the states from the topojson file, then filter so only state 48 (texas) shows
var states = topojson.feature(us, us.objects.states),
state = states.features.filter(function(d) { return d.id === 48; })[0];
//define the features for the counties and filter based on number (starting with 48)
var counties = topojson.feature(us, us.objects.counties),
mycounties = counties.features.filter(function(d) { if(d.id >= 48000 && d.id <=49000) return d.id; });
//initiate the class for the state, and add an outline path
svg.append("path")
.datum(state)
.attr("class", "outline")
.attr("d", path);
//initiate the g object for the counties
svg.append("g")
.attr("class", "counties")
.selectAll("path")
//.datum(topojson.mesh(us, us.objects.counties, function(a, b) { return a !== b; }))
// ^I tried adding this to replace the following line, but it does not work
.data(mycounties)
.enter().append("path")
.attr("fill", function(d) { return color(d.establishments = centralTexas.get(d.id)); })
.attr("d", path)
.append("title")
.text(function(d) { var obj2 = jsonCounties[d.id]; if (typeof obj2 != "undefined") {return obj2.countyName + ": " + d.establishments + " Active Establishments";} });
}
は、どのように私はこれについて行くべきか?それは.mesh関数内で、より複雑なフィルタのクエリを実行し、完全に私の
VAR郡は= topojson.feature(私たち、us.objects.counties)、mycounties = counties.featuresの必要性を排除することができます.filter(function(d){if(d.id> = 48000 & & d.id < = 49000)return d.id;});
コード?
または、その変数で別の構文でメッシュ関数を実行する必要がありますか?メッシュは「のためのメッシュを表すにGeoJSON MultiLineStringのジオメトリオブジェクトを返します - エリアを追加しませんdatum.append(メッシュ)を使用して
:
あなたの例では、mouseoutとmouseover関数がうまくいきます。私の間違いの一部は、単純にCSSを使用していたということでした:輪郭を追加するには、ホバーです。 – Keith
1つの質問:あなたの例では、郡のIDでデータをフィルタリングすることはできますか?それとも、レイヤーの選択やマウスオーバーイベントに影響しますか? – Keith
郡をフィルタリングすることはできますが、あなたは、ただのaffです。いくつの要素が入力されるかを知り、.attrや.onのメソッドには問題ではないはずです –