Giter Club home page Giter Club logo

graphviz's Introduction

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)

graphviz's People

Contributors

compnerd avatar fwcd avatar jaapwijnen avatar mattt avatar natanrolnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphviz's Issues

Helper note: may need to code sign dylib dependencies if in macOS app

A cairn for anyone else using in macOS app on Big Sur, with graphviz installed via brew: you may encounter code signing warnings, and an error that dependencies of pango cannot be loaded. ("it could load, so perhaps one of its dependents was not. Try ldd.").

A solution appears to be to manually sign the dependencies. Probably do a better job of scoping to just the affected dirs, than this, but this pair should get you there:

codesign -f -s "Apple Development: MyName (MyTeam)" /usr/local/opt/*/lib/*.dylib
codesign -f -s "Apple Development: MyName (MyTeam)" /usr/local/Cellar/*/*/lib/*.dylib

Support for edge labels

Perhaps I'm missing something, but is there a specific reason why there's no Edge.Attribute.label property? The closest that I can see is exteriorLabel (= xlabel), however from my testing this appears to behave differently from label.

If the addition of label on Edge would be a welcome change, I'd be happy to submit a small PR to add it.

Could not find or use auto-linked library

Got this error when trying to run the target with the GraphViz package
GraphViz installed with Homebrew, works perfectly as cli in terminal

The issue is with M1 Macs only.

ld: warning: Could not find or use auto-linked library 'gvc'
ld: warning: Could not find or use auto-linked library 'cgraph'
Undefined symbols for architecture arm64:
  "_agerrors", referenced from:
      GraphViz.attempt<A>(throwing: () -> A) throws -> A in GraphViz.o
  "_aglasterr", referenced from:
      static GraphViz.Error.(lastErrorMessage in _24C6592C881063ABBFDC7A6D4D4AA881).getter : Swift.String? in GraphViz.o
  "_agmemread", referenced from:
      closure #1 () -> Swift.UnsafeMutablePointer<__C.Agraph_s>? in closure #1 (Swift.UnsafePointer<Swift.Int8>) throws -> Swift.UnsafeMutablePointer<__C.Agraph_s>? in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvContext", referenced from:
      closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvFreeContext", referenced from:
      $defer #1 () -> () in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvFreeLayout", referenced from:
      $defer #2 () -> () in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvFreeRenderData", referenced from:
      $defer #3 () -> () in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvLayout", referenced from:
      closure #1 () -> Swift.Int32 in closure #3 (Swift.UnsafePointer<Swift.Int8>) throws -> () in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvRenderData", referenced from:
      closure #1 () -> Swift.Int32 in closure #4 (Swift.UnsafePointer<Swift.Int8>) throws -> () in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
  "_gvToolTred", referenced from:
      closure #2 () -> Swift.Int32 in closure #1 () throws -> Foundation.Data in closure #1 () -> () in GraphViz.Renderer.render(dot: Swift.String, to: GraphViz.Format, on: __C.OS_dispatch_queue, completion: (Swift.Result<Foundation.Data, Swift.Error>) -> ()) -> () in GraphViz.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.