Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SwiftDocOrg/GraphViz
A Swift package for working with GraphViz
https://github.com/SwiftDocOrg/GraphViz
graphviz graphviz-dot-language swift
Last synced: 3 months ago
JSON representation
A Swift package for working with GraphViz
- Host: GitHub
- URL: https://github.com/SwiftDocOrg/GraphViz
- Owner: SwiftDocOrg
- License: mit
- Archived: true
- Created: 2020-03-09T21:04:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-03T17:27:11.000Z (over 3 years ago)
- Last Synced: 2024-05-23T00:17:28.584Z (6 months ago)
- Topics: graphviz, graphviz-dot-language, swift
- Language: Swift
- Size: 196 KB
- Stars: 292
- Watchers: 10
- Forks: 30
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GraphViz
![CI][ci badge]
[![Documentation][documentation badge]][documentation]A Swift package for working with [GraphViz][graphviz].
## Requirements
- Swift 5.2+
- GraphViz## Usage
```swift
import GraphVizvar graph = Graph(directed: true)
let a = Node("a"), b = Node("b"), c = Node("c")
graph.append(Edge(from: a, to: b))
graph.append(Edge(from: a, to: c))var b_c = Edge(from: b, to: c)
b_c.constraint = false
graph.append(b_c)// Render image to SVG using dot layout algorithm
graph.render(using: .dot, to: .svg) { result in
guard .success(let data) = result,
let svg = String(data: data, encoding: .utf8)
else { return }print(svg)
}
``````dot
digraph {
a -> b
a -> c
b -> c [constraint=false]
}
```> **Note**:
> `render(using:to:)` and related methods require
> GraphViz to be installed on your system.### Using Function Builders, Custom Operators, and Fluent Attribute Setters
```swift
import GraphVizlet graph = Graph(directed: true) {
"a" --> "b"
"a" --> "c"
("b" --> "c").constraint(false)
}
```> **Note**:
> Swift 5.1 may require explicit typecast expressions in order to
> reconcile use of custom edge operators like `-->`.
> (`error: ambiguous reference to member '-->'`)## Installation
### System Dependencies
You can install GraphViz on your system by running the following command:
```terminal
# macOS
$ brew install graphviz# Linux (Ubuntu)
$ sudo apt-get install graphviz
```> **Important**:
> If you add GraphViz to your macOS app
> and installed system dependencies using Homebrew,
> Xcode may emit an error message like the following:
>
> ```
> Warning: Could not load "/usr/lib/graphviz/libgvplugin_gdk.so.6"
> It was found, so perhaps one of its dependents was not. Try ldd.
> ```
>
> One solution is to run the following commands to sign the dependencies
> (replacing `MyName (MyTeam)` with your developer account name and team name):
>
> ```terminal
> $ codesign -f -s "Apple Development: MyName (MyTeam)" /usr/local/opt/*/lib/*.dylib
> $ codesign -f -s "Apple Development: MyName (MyTeam)" /usr/local/Cellar/*/*/lib/*.dylib
> ```### Swift Package Manager
Add the GraphViz package to your target dependencies in `Package.swift`:
```swift
import PackageDescriptionlet package = Package(
name: "YourProject",
dependencies: [
.package(
url: "https://github.com/SwiftDocOrg/GraphViz",
from: "0.4.1"
),
]
)
```Add `GraphViz` as a dependency to your target(s):
```swift
targets: [
.target(
name: "YourTarget",
dependencies: ["GraphViz"]),
```## License
MIT
## Contact
Mattt ([@mattt](https://twitter.com/mattt))
[graphviz]: https://graphviz.org
[ci badge]: https://github.com/SwiftDocOrg/GraphViz/workflows/CI/badge.svg
[documentation badge]: https://github.com/SwiftDocOrg/GraphViz/workflows/Documentation/badge.svg
[documentation]: https://github.com/SwiftDocOrg/GraphViz/wiki