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

Convert save/load to dynamic URL #22

Open
csaladenes opened this issue Apr 15, 2021 · 1 comment
Open

Convert save/load to dynamic URL #22

csaladenes opened this issue Apr 15, 2021 · 1 comment

Comments

@csaladenes
Copy link
Owner

Vega-style, one should be able to a call the Sankey from the JSON string encoded directly into the URL parameter, too.

@rdtrimble
Copy link
Contributor

rdtrimble commented Apr 17, 2021

I think the only issue with this will be the 2048 URL character limit for some browsers.
Could base64 encode the JSON to make it shorter, but would need to also encodeURI it.
I think for this reason the Vega links are POST rather than GET? not too sure.
Maybe have two parameters,
j=URI encoded {sankey JSON stuff}
b=Base64 and URI encoded version of sankey stuff (should be shorter)

The b version could be used as a type of "permalink"
The j version would be useful for simple use cases where you have JSON in the right format and want to get a quick link to the data.

I still think having access to the text representation of the json is useful if you want to save it on your computer.

I don't know if I'll have time to do a proper pull request implementing these ideas, thank you for the great tool, I am busily downloading my set of 87 sankey charts and can finally visualise the flow of students between different bands for the last decade!

In case I don't get a chance to return to this the code below implements the "reading" of the 'j' parameter from the URL
Insert instead of line 335-336 in food.js

// check if graph definition passed in url
if ('URLSearchParams' in window) {
  // Browser supports URLSearchParams
  let url = new URL(window.location);  
  let params = new URLSearchParams(url.search.slice(1));
  if (params.has('j')) {
	  // yes there was, so load it
	  loadraw(decodeURI(params.get('j')));
  } else {
	  // check if there is any info stored in LocalStorage before first draw
	  loadLS();
  }
} else {
// check if there is any info stored in LocalStorage before first draw
loadLS();
}

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

No branches or pull requests

2 participants