グラフに問題があります。ズームすると、線はキャンバス領域の端とx/y軸の上を移動します。私はclippathを追加しようとしましたが、うまくいかないようです。私がデバッガでDOMを調べると、私はclippathの四角形が正確に必要な位置にあることがわかります。グラフをプロットエリアの範囲外にズームします。
//The canvasGroup is the area between the axis
var clipGroup = canvasGroup.append("clipPath")
.attr("id", "canvasGroup-clipPath");
var clipRect = clipGroup.append("rect")
.attr("width", width)
.attr("height", height);
//Function that does the zooming
function doZoom()
{
paths.forEach(function(path)
{
path.attr("transform", d3.event.transform);
});
gX.call(xAxis.scale(d3.event.transform.rescaleX(xScale)));
gY.call(yAxis.scale(d3.event.transform.rescaleY(yScale)));
}
var zoom = d3.zoom()
.scaleExtent([1, 5])
.translateExtent([[0, 0], [width, height]])
.on("zoom", doZoom);
//Register the event listener
canvasGroup.call(zoom);
//now loop over the data sets and plot each one
//For brevity, I'm skipping the loop and only showing the call to create the line
var path = canvasGroup.append("path")
.attr("clip-path", "url(#canvasGroup-clipPath)")
.attr("fill", "steelblue")
.attr("class", "line")
.attr("id", lineId + "-line")
.style("stroke", lineColor)
.style("stroke-width", 1)
.style("fill", "none");
paths.push(path);
path.attr("d", function(d) { return plotline(i)});
が作成されます:あなたが提供不完全なコードを考えると、これは非常によく
canvasGroup
へのクリッピングパスを設定することでうまくいくかもしれませんか? – Dummy'canvasGroup.append(" clipPath ")。attr(" id "、" canvasGroup-clipPath ")'。 canvasGroupは、2つの軸の間の領域で、クリップパスとデータパス(プロット)を含みます。 – ventsyv
私の答えを確認してください – Dummy