Skip to content

Instantly share code, notes, and snippets.

@levvsha
Created June 21, 2018 09:04
Show Gist options
  • Select an option

  • Save levvsha/e5a2c09b9f2bd0a15adabeac3b064d14 to your computer and use it in GitHub Desktop.

Select an option

Save levvsha/e5a2c09b9f2bd0a15adabeac3b064d14 to your computer and use it in GitHub Desktop.
function zoomed() {
const transformation = d3.event.transform;
const rightEdge = Math.abs(transformation.x) / transformation.k + width / transformation.k;
const bottomEdge = Math.abs(transformation.y) / transformation.k + height / transformation.k;
if (rightEdge > width) {
transformation.x = -(width * transformation.k - width);
}
if (bottomEdge > height) {
transformation.y = -(height * transformation.k - height);
}
rescaledX = transformation.rescaleX(x);
rescaledY = transformation.rescaleY(y);
xAxisElement.call(xAxis.scale(rescaledX));
yAxisElement.call(yAxis.scale(rescaledY));
linesContainer.selectAll('path')
.attr('d', regionId => {
return d3.line()
.defined(d => d.percent !== 0)
.x(d => rescaledX(d.date))
.y(d => rescaledY(d.percent))(regions[regionId].data);
});
voronoiGroup
.attr('transform', transformation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment