Skip to content

Latest commit

 

History

History
62 lines (54 loc) · 1.68 KB

README.md

File metadata and controls

62 lines (54 loc) · 1.68 KB

Graphiz

Graph manipulation and visualization using kotlin and openrndr.

How to use

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

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

Visualisation

You can visualise graphs with the provided openrndr extension.

application {
    program {
        val fontUrl = "src/main/resources/Roboto-Light.ttf"
        extend(Graphiz(graph, fontUrl))
    }
}

example.png