{"id":13599416,"url":"https://github.com/KevinMarquette/PSGraph","last_synced_at":"2025-04-10T12:32:42.851Z","repository":{"id":154489573,"uuid":"78707701","full_name":"KevinMarquette/PSGraph","owner":"KevinMarquette","description":"A set of utilities for working with Graphviz in Powershell","archived":false,"fork":false,"pushed_at":"2020-09-11T20:30:13.000Z","size":3376,"stargazers_count":206,"open_issues_count":29,"forks_count":49,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-11-07T00:42:40.311Z","etag":null,"topics":["graphviz","powershell","powershell-modules"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","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/KevinMarquette.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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}},"created_at":"2017-01-12T04:12:35.000Z","updated_at":"2024-11-01T20:47:29.000Z","dependencies_parsed_at":"2023-07-06T15:45:51.881Z","dependency_job_id":null,"html_url":"https://github.com/KevinMarquette/PSGraph","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevinMarquette%2FPSGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevinMarquette%2FPSGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevinMarquette%2FPSGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KevinMarquette%2FPSGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KevinMarquette","download_url":"https://codeload.github.com/KevinMarquette/PSGraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217145,"owners_count":21066633,"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":["graphviz","powershell","powershell-modules"],"created_at":"2024-08-01T17:01:03.782Z","updated_at":"2025-04-10T12:32:37.833Z","avatar_url":"https://github.com/KevinMarquette.png","language":"PowerShell","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/cgo827o4f74lmf9w/branch/master?svg=true)](https://ci.appveyor.com/project/kevinmarquette/PSGraph/branch/master) [![Documentation Status](https://readthedocs.org/projects/psgraph/badge/?version=latest)](http://psgraph.readthedocs.io/en/latest/?badge=latest)\n    \n\n# PSGraph\n\nPSGraph is a helper module implemented as a DSL (Domain Specific Language) for generating GraphViz graphs. The goal is to make it easier to generate graphs using Powershell. The DSL adds these commands that are explained below.\n\n* [graph](http://psgraph.readthedocs.io/en/latest/Command-Graph/)\n* [edge](http://psgraph.readthedocs.io/en/latest/Command-Edge/)\n* [node](http://psgraph.readthedocs.io/en/latest/Command-Node/)\n* [subgraph](http://psgraph.readthedocs.io/en/latest/Command-SubGraph/)\n* [rank](http://psgraph.readthedocs.io/en/latest/Command-Rank-Advanced/)\n\n## What is GraphViz?\n\n[Graphviz](http://graphviz.org/) is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks. It has important applications in networking, bioinformatics,  software engineering, database and web design, machine learning, and in visual interfaces for other technical domains. \n\n## Project status?\nBeta release. The core module work and documentation is fleshed out. The simple features are implemented but there are other features of the DOT language that I have not used much myself. The command names and arguments of the existing commands should be stable now. As always, more testing still needs to be done.\n\n# GraphViz and the Dot format basics\nThe nice thing about GraphViz is that you can define nodes and edges with a simple text file in the Dot format. The GraphViz engine handles the layout, edge routing, rendering and creates an image for you. \n\nHere is a sample Dot file.\n\n    digraph g {\n        \"Start\"-\u003e\"Middle\"\n        \"Middle\"-\u003e\"End\"\n    }\n\nThis will produce a graph with 3 nodes with the names `Start`, `Middle` and `End`. There will be an edge line connecting them in order. Go checkout the [GraphViz Gallery](http://graphviz.org/Gallery.php) to see some examples of what you can do with it.\n\n## How PSGraph can help\nwe can create those Dot files with PSGraph in Powershell. Here is that same graph as above.\n\n    digraph g {\n        edge Start Middle\n        edge Middle End\n    }\n\nHere is a second way to approach it now.\n\n    $objects = @(\"Start\",\"Middle\",\"End\")\n    digraph g {\n        edge $objects\n    }\n\n The real value here is that I can specify a collection to process. This allows the graph to be data driven.\n\n# PSGraph Commands\nI tried to keep a syntax that was similar to GraphViz but offer the flexibility of Powershell. If you have worked with GraphViz before, then you should feel right at home.\n\n## Graph or digraph\nThis is the container that holds graph elements. Every valid GraphViz graph has one. `digraph` is just an alias of `graph` so I am going to use the shorter `graph` for the rest of the readme.\n\n    graph g {        \n    }\n\n## Edge\nThis defines an edge or connection between nodes. This command accepts a list of strings or an array of strings. It will connect them all in sequence. This should be placed inside a `graph` or `subgraph`. `-From` and `-To` parameters are available if you want more verbosity.\n\n    graph g {\n        edge -From first -To Second\n        edge one two three four\n        edge (1..5)\n    }\n\nIf you supply two arrays, it will cross multiply them. So each item on the left with have a path to each item on the right.\n\n    graph g {\n        edge (1,3) (2,4)\n    }\n    \nBecause this is Powershell, we can mix in normal commands. Take this example.\n\n    $folders = Get-ChildItem -Directory -Recurse\n    graph g {\n        $folders | %{edge $_.Name $_.Parent} \n    }\n\nI also support edge attributes that are defined in the DOT specification by using a hashtable.\n\n   graph g {\n       edge \"Point One\" \"Point Two\" @{label='A line'}\n   }\n\n## Node\nThe Node command allows you to introduce a node on the graph before an edge is created. This is used to give specific nodes different attributes or to place them in subgraphs. The node command will also accept an array of values and a hashtable of attributes.\n\n    graph g {\n        node start @{shape='house'}\n        node end @{shape='invhouse'}\n        edge start,middle,end\n    }\n\nThis is the exact Dot output generated those node commands.\n\n    digraph g {\n\n        \"start\" [shape=\"house\"]\n        \"end\" [shape=\"invhouse\"]\n        \"start\"-\u003e\"middle\" \n        \"middle\"-\u003e\"end\" \n    }\n\n## Rank\nThe rank command will place the specified nodes at the same level in the chart. The layout can get a bit wild sometime and gives you some control.\n\n    graph g {\n        rank 2 4 6 8\n        rank 1 3 5 7\n        edge (1..8)\n    }\n\n## SubGraph\nThis lets you box of and cluster nodes together in the graph. These can be nested. The catch is that you need to number them starting at 0. Attributes are supported with the `-Attributes` parameter.\n\n    graph g {\n        subgraph 0 -Attributes @{label='DMZ'} {\n            node Web1,Web2\n        }\n        edge web1 database\n        edge web1 database\n    }\n\n# More complex example\nWe can pull that all together and generate quite the data driven driven diagram.\n\n    $webServers = 'Web1','Web2','web3'\n    $apiServers = 'api1','api2'\n    $databaseServers = 'db1'\n\n    graph site1 {\n        # External/DMZ nodes\n        subgraph 0 -Attributes @{label='DMZ'} {\n            node 'loadbalancer' @{shape='house'}\n            rank $webServers\n            node $webServers @{shape='rect'}\n            edge 'loadbalancer' $webServers\n        }\n\n        subgraph 1 -Attributes @{label='Internal'} {\n            # Internal API servers\n            rank $apiServers\n            node $apiServers   \n            edge $webServers -to $apiServers\n        \n            # Database Servers\n            rank $databaseServers\n            node $databaseServers @{shape='octagon'}\n            edge $apiServers -to $databaseServers\n        }    \n    }\n\n\n\n# Installing PSGraph\nMake sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a hard requirement at the moment but I plan on using 5.0 features.\n\n    # Install GraphViz from the Chocolatey repo\n    Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/\n    Find-Package graphviz | Install-Package -ForceBootstrap\n\n    # Install PSGraph from the Powershell Gallery\n    Find-Module PSGraph | Install-Module\n\n    # Import Module\n    Import-Module PSGraph\n\nFor OSX, you can use brew to install graphviz.\n\n    brew install graphviz\n\n# Generating a graph image\nI am still working out the workflow for this, but for now just do this.\n\n    # Create graph in variable\n    $dot = graph g {\n        edge hello world\n    }\n\n    # Save to file\n    Set-Content -Path $env:temp\\hello.vz -Value $dot\n    \n    Export-PSGraph -Source $env:temp\\hello.vz -Destination $env:temp\\hello.png -ShowGraph\n\nThe export can be done more in line if needed.\n\n    graph g {\n        edge hello world\n    } | Export-PSGraph -ShowGraph","funding_links":[],"categories":["PowerShell","Content"],"sub_categories":["Graphical Interfaces"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKevinMarquette%2FPSGraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKevinMarquette%2FPSGraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKevinMarquette%2FPSGraph/lists"}