-
Notifications
You must be signed in to change notification settings - Fork 394
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
Save/load graph JSON #63
base: master
Are you sure you want to change the base?
Conversation
Whoa! Thanks for taking a shot at this. This PR is pretty impressive, as it implements the feature without adding too much bloat. Nice work! A couple notes
Some blue-sky thinking: what if Zdog's save/load file structure was built out of SVG instead of JSON? I like SVG as it outputs a visual file that users can easily view. I don't this SVG is appropriate for saving/loading data as an SVG file as it would require building a parser and duplicating data in the file source code (like for path data). I'm spitballing here... what if the file was .svg, but it had the JSON embedded in a hidden node. So users sees a 'thumbnail' in the SVG, but the real data is in the JSON within the file? Maybe that's for a future feature. |
Thanks! I've removed The SVG idea is very cool—I will have to play around with it! Off the top of my head, I think the JSON could probably be stringified and embedded as a |
Re-thinking this: SVG filetype save/load can be a future feature. It still relies on JSON save/load so that should be the focus. Also: I think this feature would be better served as a plugin. I think you should build it out directly in Zdog for now, but I'll likely break it out into its own package when its ready for prime time. |
Thx @natemoo-e for cluing me in #63
I agree that it makes sense for this to be a plugin/extension, but for the sake of making it easy to implement, could we add just the In terms of using the svg as the saved format, I think it makes more sense for saving the 2D representation, as it doesn't inherently have the 3D information in it (neither does the canvas but you could save a 2D picture from it). |
#35 seemed like a fairly simple implementation, so I decided to take a crack at it.
I understand that you may have different plans for this feature, but I figured this would open up a conversation about the possible implementation.
Features
toJSON
method onAnchor
andVector
. This is natively called byJSON.stringify
, soJSON.stringify
ing an illustration will work as expected.Zdog.exportGraph
. It's really just callingJSON.parse(JSON.stringify(model))
but could be hand-rolled if you want.type
property to each Zdog primitive. There may be a cleaner way to do this, but the JSON needs to store the primitive type as a string so that it can be rehydrated.importGraph
option toAnchor
object. Users can pass inZdog.exportGraph
string
specifying a relative or absolute path to ajson
file. This seemed like a cool feature which would allow people to easily share models via url. It's just a simplefetch
call for modern browsers, but I realize that this may introduce some unwanted overhead for legacy browsers.In Progress