https://github.com/csicar/purescript-generic-graphviz
library for generating graphviz visualizations using purescript generics
https://github.com/csicar/purescript-generic-graphviz
dot-lang graphviz purescript purescript-generics
Last synced: 8 months ago
JSON representation
library for generating graphviz visualizations using purescript generics
- Host: GitHub
- URL: https://github.com/csicar/purescript-generic-graphviz
- Owner: csicar
- License: mit
- Created: 2017-11-20T20:28:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-03-27T14:50:31.000Z (about 5 years ago)
- Last Synced: 2025-10-22T11:58:56.616Z (8 months ago)
- Topics: dot-lang, graphviz, purescript, purescript-generics
- Language: PureScript
- Homepage:
- Size: 84 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Generic Graphviz
====
documentation can be found on [pursuit](https://pursuit.purescript.org/packages/purescript-generic-graphviz/)
consists of 3 parts (which probably *now are* seperate modules..):
1. Dot-Lang typed representation and Dot-Lang code-generator. [here](https://github.com/csicar/purescript-dotlang)
2. Generic Graph generator (takes an arbituary ADT and generates a graph for it) (this repository)
3. Bindings for Graphviz [here](https://github.com/csicar/purescript-graphviz)
Example
---
```purescript
-- your data type
data Tree' a = Leaf' | Node' (Tree' a) a (Tree' a)
-- derive generic
derive instance treeGeneric :: Generic (Tree' a) _
-- create instances for the needed type classes
instance treeEdges :: Edges a => Edges (Tree' a) where
edges x = genericEdges x
instance treeDotRepr :: Edges a => GraphRepr (Tree' a) where
toGraph = genericToGraph
example :: String
example = renderToSvg Dot $ toGraph $
Node' Leaf' 3 (Node' (Node' Leaf' 5 Leaf') 4 Leaf')
-- example = "............"
```
`example` will be:

see [full example](./test/Example.purs) for imports
see [todo mvc example](https://github.com/csicar/generic-graphviz-todomvc) for a larger example
Features
--------
- generic graph generation
- after `npm install`: usable from nodejs backend
- graphviz-images can be rendered to Chrome's WebDev Console (using console.log)
TODOs
-----
- Refactor into multiple libraries
- support entire DOT language in data model
- allow custom edges in GenericGraph
- add effects to console.image
- move viz.js call into a WebWorker
Testing
-------
run tests:
```bash
$ pulp test
```