• This repository has been archived on 09/Nov/2017
  • Stars
    star
    446
  • Rank 94,295 (Top 2 %)
  • Language
    Clojure
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

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

Repository Details

simple graph and tree visualization

Rhizome is a library for visualizing graph and tree structures.

Usage

To include in your project, add this to your project.clj:

[rhizome "0.2.9"]

Use of this project requires that Graphviz is installed, which can be checked by running dot -V at the command line. If it's not installed, you can do the following:

platform directions
Linux install graphviz using your package manager
OS X use brew install graphiz or download the installer
Windows download the installer

There are two namespaces, rhizome.dot and rhizome.viz. The former will take a graph and return a string representation of a Graphviz dot file, the latter takes graphs and renders or displays them. In practice, you should only need to use rhizome.viz.

The core function is rhizome.viz/view-graph. It takes two parameters: nodes, which is a list of nodes in the graph, and adjacent, which is a function that takes a node and returns adjacent nodes. Nodes can be of any type you like, as long as the objects in nodes and the objects returned by adjacent are equivalent.

These can be followed by zero or more of the following keyword arguments:

name description
:directed? whether the graph should be rendered as a directed graph, defaults to true
:vertical? whether the graph should be rendered top-to-bottom, defaults to true
:node->descriptor takes a node, and returns a map of attributes onto values describing how the node should be rendered
:edge->descriptor takes the source and destination node, and returns a map of attributes onto values describing how the edge should be rendered
:options a map of attributes onto values describing how the graph should be rendered
:node->cluster takes a node and returns which cluster, if any, the node belongs to
:cluster->parent takes a cluster and returns which cluster, if any, it is contained within
:cluster->descriptor takes a cluster and returns a map of attributes onto values describing how the cluster should be rendered

The rendering attributes described by :node->descriptor, :edge->descriptor, :cluster->descriptor, and :options are described in detail here. String and keyword values are interchangeable.

The most commonly-used attributes are label, which describes the text overlaid on a node, edge, or cluster, and shape, the options for which are described here. For the :options, it's sometimes useful to adjust the dpi, which controls the size of the image.

An example:

> (use 'rhizome.viz)
nil
> (def g
    {:a [:b :c]
         :b [:c]
         :c [:a]})
#'g
> (view-graph (keys g) g
    :node->descriptor (fn [n] {:label n}))

Clusters are a way of grouping certain nodes together. They can be any object you like, including values also used by a node. Using :cluster->parent, they can be nested:

> (view-graph (keys g) g
    :cluster->descriptor (fn [n] {:label n})
    :node->cluster identity
    :cluster->parent {:b :c, :a :c})

While trees are a special case of graphs, using view-graph to visualize trees can be a little indirect. To make this simpler, there's a view-tree function, which is modeled after Clojure's tree-seq operator. This function takes three parameters, branch?, children, and root, followed by zero or more of the keyword arguments taken by view-graph. This can make it easy to visualize hierarchical structures:

> (def t [[1 [2 3]] [4 [5]]])
#'t
> (view-tree sequential? seq t
    :node->descriptor (fn [n] {:label (when (number? n) n)}))

If the value for label is not a string, typically it will be displayed as a string representation of the value. However, if the value is sequential, then the node will be displayed as a Record type:

> (def t '([1 2] ([3 4] ([5 6 7]))))
#'t
> (view-tree list? seq t
    :node->descriptor (fn [n] {:label (when (vector? n) n)}))

rhizome.viz/graph->svg can be used to render the graph as SVG.

License

Copyright Β© 2013 Zachary Tellman

Distributed under the MIT License

More Repositories

1

lamina

not under active development - event-driven workflows for clojure
Clojure
708
star
2

automat

better automata through combinators
Clojure
586
star
3

penumbra

not under active development - idiomatic opengl bindings for clojure
Clojure
353
star
4

virgil

your own personal JVM psychopomp
Clojure
274
star
5

vertigo

heterogeneous structs for clojure
Clojure
208
star
6

riddley

code-walking without caveats
Clojure
193
star
7

clj-tuple

efficient small collections for clojure
Java
179
star
8

narrator

expressive, composable stream analysis
Clojure
153
star
9

proteus

local. mutable. variables.
Clojure
111
star
10

sleight

whole-program transformations in clojure
Clojure
98
star
11

calx

not under active development - idiomatic opencl bindings for clojure
Clojure
84
star
12

collection-check

fuzz testing for alternate clojure data structures
Clojure
64
star
13

pushkin

shall we play a game?
Clojure
59
star
14

immutable-bitset

space-efficient immutable integer sets
Clojure
51
star
15

immutable-int-map

a map optimized for integer keys
Clojure
40
star
16

aloha

a simple, friendly webserver
Clojure
36
star
17

cambrian-collections

a veritable explosion of data structures
Clojure
29
star
18

cantor

not under active development - primitive math for clojure
Clojure
26
star
19

clj-radix

a persistent radix tree, for efficient nested maps
Clojure
21
star
20

lein-jammin

a window into your stuck process
Clojure
18
star
21

everything-will-flow

necessary code for my upcoming clojure/west 2015 talk
Clojure
17
star
22

duel

a testing ground for programs that play go
Clojure
10
star
23

bizarro-collections

you got your clojure semantics in my mutable hash-map
Java
7
star
24

ergo

a monte-carlo simulator for computer go
C++
5
star
25

scrawl

the graphical equivalent of the fibonacci sequence
Clojure
4
star
26

java9-failure

Clojure
1
star
27

aleph.io

static website for aleph
CSS
1
star