Skip to content

Commit

Permalink
[ENH] README + example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptit-Biscuit committed Jul 31, 2022
1 parent f07e127 commit 71c45ac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
50 changes: 44 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
# Graphiz [![](https://jitpack.io/v/Ptit-Biscuit/graphiz.svg)](https://jitpack.io/#Ptit-Biscuit/graphiz)
Graph manipulation and visualization using kotlin and openrndr.

## How to use
``` kotlin
val graph = Graph {
// declare vertices
val aud = Vertex("AUD")
val chf = Vertex("CHF")
val eur = Vertex("EUR")
val inr = Vertex("INR")
val jpy = Vertex("JPY")
val usd = Vertex("USD")
val krw = Vertex("KRW")

vertices { setOf(aud, chf, eur, inr, jpy, usd, krw) }

// create edges between vertices (weight is optional)
edges {
setOf(
aud edgeWith chf value 0.9661,
aud edgeWith jpy value 86.0305,
eur edgeWith chf value "1.2053",
eur edgeWith usd value 1.2989,
inr edgeWith jpy,
jpy edgeWith inr value 0.6571,
jpy edgeWith krw value 13.1151,
)
}

// Create inverse edges if needed
inverseEdges { edges ->
edges
.filter { !edges.contains(Edge(it.to, it.from, null)) }
.map { Edge(it.to, it.from, it.weight?.let { value -> "%.4f".format(1 / value.toString().toDouble()) }) }
.toSet()
}
}
```

## Features
[x] Create a generic graph
[x] Optional weights on edges
[x] Basic order, size, degree of graph
[x] Directed or undirected graph
[x] Vertex degree, adjacency, children
[x] Shortest path between two vertices
- [x] Create a generic graph
- [x] Inverse specific edges' weight
- [x] Optional weights on edges
- [x] Basic order, size, degree of graph
- [x] Directed or undirected graph
- [x] Vertex degree, adjacency, children
- [x] Shortest path between two vertices

## Visualisation
You can visualise graphs with the provided openrndr extension.
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/github/ptitbiscuit/example/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.openrndr.application

fun main() {
val graph = Graph {
// declare vertices
val aud = Vertex("AUD")
val chf = Vertex("CHF")
val eur = Vertex("EUR")
Expand All @@ -16,6 +17,7 @@ fun main() {

vertices { setOf(aud, chf, eur, inr, jpy, usd, krw) }

// create edges between vertices (weight is optional)
edges {
setOf(
aud edgeWith chf value 0.9661,
Expand All @@ -28,6 +30,7 @@ fun main() {
)
}

// Create inverse edges if needed
inverseEdges { edges ->
edges
.filter { !edges.contains(Edge(it.to, it.from, null)) }
Expand Down

0 comments on commit 71c45ac

Please sign in to comment.