Giter Site home page Giter Site logo

pyviz's Introduction

PyViz

A framework for designing python tools using UML and graphviz.

Requirements

In order to render diagrams, you must have Graphviz >= 2.40.1 installed. If you only wish to use this library to generate .dot files, there is no need to install any external dependencies. You can install Graphviz by visiting https://graphviz.org/download/ or by running:

apt-get update -y && apt-get install -y graphviz || yum install -y graphviz || dnf install -y graphviz || brew install -y graphviz

Example

The following code can be used to generate a .dot file compatible with Graphviz. Use Graphviz to render diagrams into several formats from a .dot file.

Diagram

Render the following diagram (requires Graphviz) by running:

dot -Tpng -o docs/source/diagrams/simple_example.png docs/source/diagrams/simple_example.dot

Example Diagram

Code

from pyviz import uml, Graph

Country = uml.UMLClass(
    "Country", properties=[uml.UMLProperty("name", "str"), uml.UMLProperty("population", "int")]
)
IPerson = uml.UMLClass(
    "IPerson", properties=[uml.UMLProperty("name", "str"), uml.UMLProperty("age", "int")]
)
Citizen = uml.UMLClass("Citizen", properties=[])

Citizen.implements(IPerson)
Country.depends_on(Citizen)

g = Graph(label="Test Graph")
g.add_nodes([Country, IPerson, Citizen])

print(g.render())

Generated Dot File

digraph g {
	label="Test Graph"

	// Objects
	Country [label=< {<B>Country</B>
		|<B>Properties</B>
			<BR/><BR/>name: <FONT COLOR="mediumseagreen">str</FONT>
			<BR ALIGN="LEFT"/>population: <FONT COLOR="mediumseagreen">int</FONT>
	} > shape="record"];

	IPerson [label=< {<B>IPerson</B>
		|<B>Properties</B>
			<BR/><BR/>name: <FONT COLOR="mediumseagreen">str</FONT>
			<BR ALIGN="LEFT"/>age: <FONT COLOR="mediumseagreen">int</FONT>
	} > shape="record"];

	Citizen [label=< {<B>Citizen</B>
	} > shape="record"];


	// Dependencies
	edge [style=dashed]

	Country -> Citizen;

	// Inheritance
	edge [style=dashed arrowhead=empty]

	Citizen -> IPerson;
}

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.