@ robert-longsonの答えを拡張すると、SVGの楕円弧コマンドを使用して、直定規のlinetoコマンドと組み合わせてコーナーを作成できます。これらはパス要素で使用されます。考えられる実装の1つは次のとおりです。
// Returns path data for a rectangle with rounded right corners.
// The top-left corner is ⟨x,y⟩.
function rightRoundedRect(x, y, width, height, radius) {
return "M" + x + "," + y
+ "h" + (width - radius)
+ "a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius
+ "v" + (height - 2 * radius)
+ "a" + radius + "," + radius + " 0 0 1 " + -radius + "," + radius
+ "h" + (radius - width)
+ "z";
}
次に、この関数を呼び出して「d」属性を計算できます。例えば:
rects.enter().append("path")
.attr("d", function(d) {
return rightRoundedRect(x(0), y(d.name), x(d.value) - x(0), y.rangeBand(), 10);
});
実例:
オプション:必要に応じて、多くの引数を取るのではなく、rightRoundedRect関数をリファクタリングして構成可能にすることができます。このアプローチは、D3の組み込みシェイプジェネレーターに似ています。たとえば、次のようなrectジェネレータを使用できます。
rects.enter().append("path")
.attr("d", rightRoundedRect()
.x(x(0))
.y(function(d) { return y(d.name); })
.width(function(d) { return x(d.value) - x(0); })
.height(y.rangeBand())
.radius(10));
このアプローチの詳細については、構成可能な関数のチュートリアルを参照してください。