Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explanation when .translate is at the end of Transform #192

Closed
Niekes opened this issue Sep 29, 2019 · 2 comments · Fixed by #214
Closed

Add explanation when .translate is at the end of Transform #192

Niekes opened this issue Sep 29, 2019 · 2 comments · Fixed by #214

Comments

@Niekes
Copy link

Niekes commented Sep 29, 2019

In the examples on https://observablehq.com/collection/@d3/d3-zoom I see that you are adding .translate twice and to the end:

d3.zoomIdentity.translate(width / 2, height / 2).scale(40).translate(-x, -y)

In the docs it says that the order matters. It would be nice to add an explanation to the docs.

Thanks for your amazing work!

@Fil
Copy link
Member

Fil commented May 29, 2020

I read "order of transformations matters" in the context of applying a transform as a css style or attribute: transform="translate(x,y) scale(k)".

In the notebook you're mentioning the explanation for the double call to translate is that, when we call transform.translate(x,y), the actual elements t.x, t.y of the transform t will be incremented by t.k×x, t.k×y, like so:

d3.zoomIdentity
  // translate
  .translate(300, 200) // { k:1, x: 300, y: 200 }
  // scale (and keep the translated point unchanged)
  .scale(40) // { k: 40, x: 300, y: 200 }
  // translate (taking into account the scale)
  .translate(-1, 1) // {k: 40, x: 260, y: 240}

The relationship between these numbers is described in the matrix https://github.com/d3/d3-zoom#zoom-transforms ; I'm not sure what to add to make this more explicit? Maybe in https://github.com/d3/d3-zoom#transform_translate?

@Fil
Copy link
Member

Fil commented May 29, 2020

So maybe https://github.com/d3/d3-zoom#transform_translate should read:

a transform whose translation tx1 and ty1 is equal to tx0 + tk x and ty0 + tk y, where tx0 and ty0 is this transform’s translation.

instead of

a transform whose translation tx1 and ty1 is equal to tx0 + x and ty0 + y, where tx0 and ty0 is this transform’s translation.

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants