graphql-kit / graphql-voyager

🛰️ Represent any GraphQL API as an interactive graph
https://graphql-kit.com/graphql-voyager/
MIT License
7.73k stars 509 forks source link

Ability to save as SVG or Hi-Res PNG #62

Open ch3ckmat3 opened 6 years ago

ch3ckmat3 commented 6 years ago

Don't know if already planned but requesting anyways :)

IvanGoncharov commented 6 years ago

@ch3ckmat3 Sounds cool 👍

mjbcopland commented 6 years ago

I've branched from v1.0.0-rc.19 and added a 'Download SVG' button here.

I've branched from the latest release because the current master branch doesn't match what's currently live at https://apis.guru/graphql-voyager and also doesn't seem to work with custom schemas yet. Consequently I don't know how it would be merged in (releases branch seems out of date?) but you can run my branch locally to save the SVG. It adds a new button which looks like this:

graphql-voyager

Converting to PNG and other formats can then be done with external tools such as imagemagick.

edit

I've merged v1.0.0-rc.19 into my releases branch and branched from there instead, so we can more easily see the changes.

IvanGoncharov commented 6 years ago

releases branch seems out of date?

@mjbcopland You absolutely right. I just deleted it.

because the current master branch doesn't match what's currently live at apis.guru/graphql-voyager and also doesn't seem to work with custom schemas yet.

It's under heavy refactoring ATM and once we finish it we would push for 1.0.0 release.

Consequently I don't know how it would be merged in

You can open PR against master. Note: we don't have change schema button anymore so you should look some other place for "Download SVG" button.

IvanGoncharov commented 5 years ago

Just as a note for a future development I really like how screenshot button done in this demo: http://html2canvas.hertzen.com/documentation image image

robbyemmert commented 5 years ago

Moving my ideas here from #110 to keep everything in one place:

Desired functionality: As a viewer, I want to export the schema to a file.

Ideal options for file types:

For reference, the SVG option alone would be sufficient (at least to get started) for my own use case.

Another note: It might be useful to architect this so that there's an interface for adding your own export types. Something like the following:

GraphQLVoyager.init(document.getElementById('voyager'), {
  introspection: introspectionProvider,
  exportTypes: [
    { label: 'UML', description: 'Export UML for the old guard', editor: ExportUMLUI myCustomUMLExportProvider } 
  // myCustomUMLExportProvider is a function that accepts the rendered SVG element, introspection, (and any other necessary info) and returns a file blob or some equivalent format.
  // the 'editor' prop is an optional react component that provides an interface for configuring export settings. If not provided, the export provider could be run directly. An editor ui would only be *required* for formats like PNG that would need to know what resolution to export to, etc.
  ]
})

Common exporters could then be added in the core package for convenience, i.e.:

import {svgExporter, pngExporter} from 'graphql-voyager/exporters'
const settings = {
  exportTypes: [
    svgExporter, pngExporter
  ],
  //...etc
}

Thanks!

sanket-work commented 4 years ago

is this closed ?