• This repository has been archived on 17/Oct/2021
  • Stars
    star
    291
  • Rank 142,563 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Swift package for working with GraphViz

GraphViz

CI Documentation

A Swift package for working with GraphViz.

Requirements

  • Swift 5.2+
  • GraphViz

Usage

import GraphViz

var 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)
}

Example GraphViz Output

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

import GraphViz

let 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:

# 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):

$ 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:

import PackageDescription

let 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):

targets: [
.target(
    name: "YourTarget",
    dependencies: ["GraphViz"]),

License

MIT

Contact

Mattt (@mattt)

More Repositories

1

swift-doc

A documentation generator for Swift projects
Swift
1,683
star
2

DocTest

An experimental tool for testing Swift example code in documentation.
Swift
358
star
3

SwiftSemantics

Uses SwiftSyntax to parse Swift code into its constituent declarations
Swift
224
star
4

swiftdoc.org

Auto-generated documentation for Swift. Command-click no more.
HTML
217
star
5

CommonMark

Create, parse, and render Markdown text according to the CommonMark specification
Swift
179
star
6

Markup

A Swift package for working with HTML, XML, and other markup languages, based on libxml2.
Swift
112
star
7

github-wiki-publish-action

GitHub Action that publishes the contents of a directory to your project's wiki
Shell
82
star
8

SwiftMarkup

Parses Swift documentation comments into structured entities
Swift
56
star
9

Git

A Swift package for working with Git, built on top of libgit2.
Swift
48
star
10

swiftdoc-parser

Header parsing and HTML generating utilities for SwiftDoc.org
JavaScript
42
star
11

TAP

A Swift package for the Test Anything Protocol (v13)
Swift
21
star
12

Swift-Semantic-Icons

Icons used by swift-doc to represent Swift code symbols.
20
star
13

DocSetUtil

Apple developer tool for working with .docset bundles
Makefile
19
star
14

StringLocationConverter

Converts String index values into their corresponding line & column numbers
Swift
16
star
15

SwiftPackageManifest

A package for decoding the output of `swift package dump-package`
Swift
15
star
16

Inflection

Swift
10
star
17

api.swiftdoc.org

A JSON API for SwiftDoc.org
JavaScript
8
star
18

swift-api-inventory

Swift
6
star
19

homebrew-formulae

Collection of Homebrew Formulae
Ruby
3
star
20

docsetutil-validate-action

JavaScript
2
star