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

How to center screen on a specific hex? #100

Open
henrybzhang opened this issue Sep 3, 2022 · 1 comment
Open

How to center screen on a specific hex? #100

henrybzhang opened this issue Sep 3, 2022 · 1 comment

Comments

@henrybzhang
Copy link

I assume the Layout.origin should be used, but I can't seem to figure out the correct units to set it to. I currently have

const [hexagons, setHexagons] = useState(GridGenerator.hexagon(3));
...
<HexGrid width={windowWidth} height={windowHeight}>
  <Layout
    size={{ x: hexSize, y: hexSize }}
    flat={true}
    origin={{ x: -10, y: 0 }}
  >
    {hexagons.map((hex, i) => (
      <Hexagon key={i} q={hex.q} r={hex.r} s={hex.s} fill={'black'} />
    ))}
  </Layout>
</HexGrid>

Any help would be appreciated!

@jannikbuschke
Copy link
Collaborator

jannikbuschke commented Sep 5, 2022

try to use the viewBox prop on the HexGrid. The HexGrid is basically a svg component with the following default props

  width = 800,
  height = 600,
  viewBox = "-50 -50 100 100",

the first two values of the viewBox should allow you to "position" your element. I dont yet understand svg enough to explain it properly, but hope this helps

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

No branches or pull requests

2 participants