Giter VIP home page Giter VIP logo

gviz's Introduction

Gviz

Build Status

Ruby's interface of graphviz. It generate a dot file with simple ruby's syntax. Some implementations of Gviz are inspired by Ryan Davis's Graph.

Installation

Add this line to your application's Gemfile:

gem 'gviz'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gviz

Usage

A simple example.

# add nodes and edges(route method)
# save to files with dot and png formats(save method)
require "gviz"

Graph do
  route :main => [:init, :parse, :cleanup, :printf]
  route :init => :make, :parse => :execute
  route :execute => [:make, :compare, :printf]

  save(:sample1, :png)
end

Graph is a shortcut for Gviz.new.graph.

This outputs sample1.dot and sample1.png files shown as below.

sample1

Add some attributes to the graph, nodes, edges.

## add color to all nodes with color set(nodes, nodeset and node methods)
## add color & styles to all edges(edges method)
## add color & styles to a edge(edge method)
## add bgcolor to a graph(global method)
require "gviz"

Graph do
  route :main => [:init, :parse, :cleanup, :printf]
  route :init => :make, :parse => :execute
  route :execute => [:make, :compare, :printf]

  nodes(colorscheme:'piyg8', style:'filled')
  nodeset.each.with_index(1) { |nd, i| node(nd.id, fillcolor:i) }
  edges(arrowhead:'onormal', style:'bold', color:'magenta4')
  edge(:main_printf, arrowtail:'diamond', dir:'both', color:'#3355FF')
  global(bgcolor:'powderblue')

  save(:sample2, :png)
end

This outputs below.

sample2

Modify some.

## define specific edge port(node label & edge method)
## adjust node positions(rank method)
## define subgraph(subgraph method) 
require "gviz"

Graph do
  route :main => [:init, :parse, :cleanup, :printf]
  route :init => :make, :parse => :execute
  route :execute => [:make, :compare, :printf]

  nodes colorscheme:'piyg8', style:'filled'
  nodeset.each.with_index(1) { |nd, i| node nd.id, fillcolor:i }
  edges arrowhead:'onormal', style:'bold', color:'magenta4'
  edge :main_printf, arrowtail:'diamond', dir:'both', color:'#3355FF'
  global bgcolor:'powderblue'

  node :execute, shape:'Mrecord', label:'{<x>execute | {a | b | c}}'
  node :printf, shape:'Mrecord', label:'{printf |<y> format}'
  edge 'execute:x_printf:y'
  rank :same, :cleanup, :execute
  subgraph do
    global label:'SUB'
    node :init
    node :make
  end

  save(:sample3, :png)
end

This outputs below.

sample3

Use for Drawing

Gviz helps you easily to draw shapes on an exact position using shape-named methods.

require "gviz"

Graph do
  line :a, from:[-100,0], to:[100,0]
  line :b, from:[0,-100], to:[0,100]
  circle :c
  rect :d, x:50, y:50, fillcolor:"green", label:"Rect"
  triangle :e, x:50, y:-50, fillcolor:"cyan"
  diamond :f, x:-50, y:50, fillcolor:"magenta"
  egg :g, x:-50, y:-50, fillcolor:"yellow", label:"Egg"

  save :draw
end

This outputs below(consider a scale if save to output formats).

sample4

Another examples are at examples directory

gviz command

It comes with a gviz command. This works with a graph spec file. If 'graph.ru' file exist on a directory of the execution, it will be automatically loaded as a graph spec file.

Example of graph.ru:

  route :main => [:init, :parse, :cleanup, :printf]
  route :init => :make, :parse => :execute
  route :execute => [:make, :compare, :printf]

  save(:sample, :png)

Usage:

  gviz build [FILE] [options]

where [options] are:

--name,   -n :   Graph name (default: G)
--type,   -t :   Graph type (default: digraph)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

gviz's People

Contributors

melborne avatar otahi avatar makimoto avatar

Stargazers

Stanislav Mekhonoshin avatar  avatar Yuma avatar moyashi avatar Hiroshi Ueki avatar itosho avatar Shreyas Balakrishna avatar Tomohiro Hashidate avatar Sho Nakatani avatar Kohta Kunishima avatar Fumitaka Yamane avatar Angus H. avatar kyontan avatar Kosuke Takami avatar epy0n0ff avatar misoobu avatar  avatar Shirasaka avatar  avatar hiroshiro avatar akira yamada avatar Masahiro Nakanishi avatar k-ta-yamada avatar Kwon Kiheng avatar Katsunori Nakanishi avatar kazufusa avatar Daegwon Nacyot Kim avatar Ken’ichiro Oyama avatar Roberto Salas avatar  avatar  avatar  avatar hara_yu avatar Tatsuya Takamura avatar Shuhei KONDO avatar yuuki arisawa avatar Masahito Yoshida avatar Naohiro Hasegawa avatar KIKUNAGA Hisashi avatar Daisuke Masuyama avatar kayak avatar Yuya Yabe avatar Tomohiro Nishimura avatar Thomas Yang avatar Kazuhiko UENO avatar  avatar  avatar  avatar Atsuo Fukaya avatar zucay avatar Linda_pp avatar Masahiro Saito avatar Wataru MIYAGUNI avatar kp avatar yuiseki avatar Masaki Yatsu avatar Akira Matsuda avatar takkaw avatar

Watchers

 avatar moyashi avatar James Cloos avatar  avatar

gviz's Issues

rankDir

@melborne Wonderful gem!

However, What is the correct syntax to activate rankDIR='LR'?

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.