I am trying to create a zoomable chart that has a polylinear x-axis. Everything works as expected if I don't have the polylinear axis. However, when using the polylinear axis the panning (and zooming) is very distorted. If you drag the chart to pan you will see the points and x-axis distortions. The example uses the default D3js zoom behaviour. Any suggestions to get smooth panning/zooming would be appreciated.
I am using transforms to position the elements because I had some issues when specifying the cx and cy values (especially when adding new data to a panned or zoomed chart).
Here is the zoom function:
var onZoom = function () {
if (d3.event.scale == 1) { //panning
} else { //zooming
// don't scale points and lines
graph.selectAll(".point")
.attr("r", 10 / d3.event.scale)
.attr("stroke-width", 1 / d3.event.scale);
}
graph.selectAll(".point")
.attr("transform", function (d) { return "translate(" + xMap(d) + "," + yMap(d) + ")scale(" + d3.event.scale + ")"; });
graph.select(".xAxis.axis").call(xAxis);
graph.select(".yAxis.axis").call(yAxis);
};
See example: https://jsfiddle.net/deanb/spjn8zL7/