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 preserve the layout, positioning and zoom level of org chart #395

Open
bisoladebiyi opened this issue Apr 30, 2024 · 3 comments
Open

Comments

@bisoladebiyi
Copy link

Hello! Currently i'm looking for a way to preserve the whole layout of the chart, so that upon refresh or component re-render, it doesn't fall back to the initial default state

Screen.Recording.2024-04-30.at.2.22.01.PM.mov

From the docs, I have seen there's a getChartState method that returns the state object and preserving this is no problem, but I'd like to know if there's any efficient way of setting the chart state upon render after retrieving this object from where its been stored.

@bumbeishvili
Copy link
Owner

Hi, an easy way to preserve which node was expanded is to save the data

dataToSave = chart.data()

Saving the layout itself is trickier, you need to get zoom behavior and when re-rendereing supply that zoom behavior. I only know this as theory, don't have time to implement it in practice

@christophdb
Copy link

Hey @bumbeishvili,

my understanding is that with getChartState you can get the zoomLevel like this, correct?

const attrs = chart.getChartState();
zoomLevel = attrs.lastTransform.k;

But how do you determine the current position of the chart? If the user moves the position of the chart with the mouse, how can you determine this? I didn't found anything in the source code.

@bumbeishvili
Copy link
Owner

bumbeishvili commented May 2, 2024

Yes, that's correct, lastTransfrom also has x and y properties and you can get a position with that. Alternatively, extract and parse the transform property of g.chart element

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

3 participants