{"id":17256631,"url":"https://github.com/princemaple/dg","last_synced_at":"2025-04-06T10:11:42.146Z","repository":{"id":37612697,"uuid":"455040763","full_name":"princemaple/dg","owner":"princemaple","description":"Elixir wrapper of :digraph with a pinch of protocols and sigils","archived":false,"fork":false,"pushed_at":"2025-03-08T04:58:11.000Z","size":82,"stargazers_count":42,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T09:07:43.332Z","etag":null,"topics":["digraph","elixir","livebook","mermaid"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/dg","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/princemaple.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-03T05:25:29.000Z","updated_at":"2025-03-26T04:40:19.000Z","dependencies_parsed_at":"2024-01-16T12:15:26.863Z","dependency_job_id":"93ea49fe-a52d-4c67-a04f-2cb3ffc67d6c","html_url":"https://github.com/princemaple/dg","commit_stats":{"total_commits":43,"total_committers":2,"mean_commits":21.5,"dds":0.2093023255813954,"last_synced_commit":"dc957c2c696def20ef0d9c715f051bba7b5c7b21"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princemaple%2Fdg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princemaple%2Fdg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princemaple%2Fdg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princemaple%2Fdg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/princemaple","download_url":"https://codeload.github.com/princemaple/dg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464222,"owners_count":20942970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["digraph","elixir","livebook","mermaid"],"created_at":"2024-10-15T07:14:54.762Z","updated_at":"2025-04-06T10:11:42.126Z","avatar_url":"https://github.com/princemaple.png","language":"Elixir","readme":"# DG\n\n\u003c!-- DOC --\u003e\n\nElixir wrapper of `:digraph` with a pinch of protocols and sigils\n\n## Installation\n\nThe package can be installed by adding `dg` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:dg, \"~\u003e 0.4\"},\n    ...\n  ]\nend\n```\n\n## Highlights\n\n### Inspect\n\n```elixir\ndg = DG.new()\nDG.add_vertex(dg, \"v1\")\nDG.add_vertex(dg, \"v2\", \"label 2\")\nDG.add_vertex(dg, \"v3\")\nDG.add_edge(dg, \"v1\", \"v2\")\nDG.add_edge(dg, \"v1\", \"v3\", \"1 to 3\")\n\nIO.inspect(dg)\n```\n\nOutputs `mermaid.js` format flowchart\n\n```\ngraph LR\n    v1--\u003ev2[label 2]\n    v1--1 to 3--\u003ev3\n```\n\nwhich can be put into livebook `mermaid` block and will display as\n\n```mermaid\ngraph LR\n    v1--\u003ev2[label 2]\n    v1--1 to 3--\u003ev3\n```\n\n### Collectable\n\nEasily add\n\n- vertices `[{:vertex, 1}, {:vertex, 2, \"label 2\"}, ...]`\n- or edges `[{:edge, 1, 2}, {:edge, \"a\", \"b\", \"label ab\"}, ...]`\n\nto the graph via `Enum.into/2`\n\n```elixir\ndg = DG.new()\n\n~w(a b c d e) |\u003e Enum.map(\u0026{:vertex, \u00261}) |\u003e Enum.into(dg)\n\n~w(a b c d e)\n|\u003e Enum.chunk_every(2, 1, :discard)\n|\u003e Enum.map(fn [f, t] -\u003e {:edge, f, t} end)\n|\u003e Enum.into(dg)\n\nIO.inspect(dg)\n```\n\noutputs\n\n```mermaid\ngraph LR\n    b--\u003ec\n    c--\u003ed\n    a--\u003eb\n    d--\u003ee\n```\n\n### Functions\n\n- Most functions from `:digraph` and `:digraph_utils` are mirrored under `DG`.\n- Some functions have their parameters re-arranged so that the graph is always the first parameter.\n  (namely `reachable/2`, `reachable_neighbours/2`, `reaching/2` and `reaching_neighbours/2`)\n- `new/{0,1,2,3}` returns `%DG{}` instead of an Erlang `digraph`\n- `new/2` and `new/3` are shortcuts that can add vertices and edges on creation,\n  which don't exist on `:digraph`\n\n### Sigils\n\n`~G` and `~g` are provided so you can copy `mermaid.js` flowchart and paste into Elixir to get a `%DG{}`\n\n```elixir\nimport DG.Sigil\n\ndg = ~G\"\"\"\ngraph LR\n  a[some label]\n  b[other label]\n  1--\u003e2\n  3[three] -- three to four --\u003e 4[four]\n  a --\u003e b\n\"\"\"\n```\n\n```elixir\n# With interpolation\n\nlabel = \"1 2 3\"\ndg = ~g\"\"\"\ngraph LR\n  a --#{label}--\u003e b\n\"\"\"\n```\n\n**caveat:** `:digraph` is stateful (using `ets`), don't use the sigil at compile time,\ne.g. as a module attribute, it won't carry over to runtime.\nOnly use it in runtime code, e.g. function body,\nand remember to clean up properly when it's no longer used, with `delete/1`.\n\n### Load from `libgraph`\n\n```elixir\ndg = DG.new()\nDG.from({:libgraph, graph})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincemaple%2Fdg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprincemaple%2Fdg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincemaple%2Fdg/lists"}