Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Jun 26, 2021
2 parents 83be596 + ba229d8 commit 478c45a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

> Convenient to use with `jq`
[![Go Reference](https://pkg.go.dev/badge/github.com/nikolaydubina/jsonl-graph.svg)](https://pkg.go.dev/github.com/nikolaydubina/jsonl-graph)

```bash
$ go install github.com/nikolaydubina/jsonl-graph
$ go install github.com/nikolaydubina/jsonl-graph@latest
# and get https://graphviz.org/download/
```

Graph is represented as JSONL of nodes and edges.

Node contains `id` with string and fields.
```json
Node contains `id` and any fields
```
{
"id": "github.com/gin-gonic/gin",
"can_get_git": true,
Expand All @@ -25,23 +27,33 @@ Node contains `id` with string and fields.
}
```

Edge contains `from` and `to` with node `id`s.
Edge contains `from` and `to` with node `id`s
```json
{
"from": "github.com/gin-gonic/gin",
"to": "golang.org/x/tools"
}
```

If you pass color scheme, then values will be colored.
## Why?

[JSONL](https://jsonlines.org/) is a perfect fit for storing graphs

- can append new nodes and endges by concatenating files
- nodes and edges can have any data
- schemaless
- any subset of lines is a valid graph

## Examples

To illustrate, I am using data from [import-graph](github.com/nikolaydubina/import-graph). If you pass color scheme, then values will be colored.
```bash
$ cat '
{"id":"github.com/gin-gonic/gin","can_get_git":true, ... }
{"id":"github.com/gin-contrib/sse","can_get_git":true,"can_run_tests":true ... }
...
{"from":"github.com/gin-gonic/gin","to":"golang.org/x/tools"}
{"from":"github.com/gin-gonic/gin","to":"github.com/go-playground/validator/v10"}
...
' | jsonl-graph -color-scheme=file://$PWD/docs/colors.json | dot -Tsvg > colored.svg
```
![gin-color](./docs/gin_color.svg)
Expand All @@ -54,7 +66,6 @@ $ cat '
...
{"from":"github.com/gin-gonic/gin","to":"golang.org/x/tools"}
{"from":"github.com/gin-gonic/gin","to":"github.com/go-playground/validator/v10"}
...
' | jsonl-graph | dot -Tsvg > basic.svg
```
![gin-nocolor](./docs/gin_nocolor.svg)
Expand All @@ -77,4 +88,4 @@ $ cat '
## TODO

- [ ] adjust node spacing when graph is large
- [ ] group subgraphs
- [ ] group subgraphs

0 comments on commit 478c45a

Please sign in to comment.