Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmoraes committed Nov 14, 2020
1 parent d9e1528 commit c7f58cc
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default: true
MD025:
front_matter_title: ""
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
"Esep",
"Functors",
"Rects",
"Serializable",
"Stringn",
"Styleable",
"Tpng",
"edgehref",
"ediamond",
"emicklei",
"emicklei's",
"fontawesome",
"graphviz",
"headhref",
"icurve",
"labelhref",
Expand All @@ -35,7 +40,9 @@
"mosek",
"nojustify",
"nslimit",
"pymdownx",
"sortv",
"superfences",
"tailhref",
"voro",
"xdot",
Expand Down
1 change: 1 addition & 0 deletions Node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Node interface {
attributes.Identity
attributes.Styleable
attributes.Serializable

// Edge creates an Edge to a Node
Edge(to Node) Edge
// EdgeWithAttributes creates an Edge with the provided attributes to a Node
Expand Down
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ import (
func main() {
graph := dot.NewGraph()
graph.SetAttributeString("label", "an amazing graph")
clusterA := graph.Subgraph(&GraphOptions{ ID: "Cluster A", Cluster: true })
clusterA := graph.Subgraph(WithID("Cluster A"), WithCluster())
clusterA.SetAttributeString("label", "Cluster A")
clusterB := graph.Subgraph(&GraphOptions{ ID: "Cluster B", Cluster: true })
clusterB := graph.Subgraph(WithID("Cluster B"), WithCluster())
clusterB.SetAttributeString("label", "Cluster B")

clusterA.
Expand All @@ -99,24 +99,49 @@ func main() {
}
```

The attributes sub-package has all supported keys defined as variables, and can
The constants sub-package has all supported keys defined as variables, and can
be used instead of plain strings to avoid both duplication and errors:

```go
graph := dot.NewGraph()
graph.SetAttributeString(attributes.KeyLabel, "a graph")
node := graph.Node("n1")
node.SetAttributeString(attributes.KeyLabel, "a node")
edge := graph.Edge(graph.Node("n2"), graph.Node("n3"))
edge.SetAttributeString(attributes.KeyLabel, "a edge")
package main

import (
"os"
"github.com/wwmoraes/dot"
"github.com/wwmoraes/dot/constants"
)

func main() {
graph := dot.NewGraph()
graph.SetAttributeString(constants.KeyLabel, "a graph")
node := graph.Node("n1")
node.SetAttributeString(constants.KeyLabel, "a node")
edge := graph.Edge(graph.Node("n2"), graph.Node("n3"))
edge.SetAttributeString(constants.KeyLabel, "a edge")

fd, _ := os.Create("sample.dot")
graph.WriteTo(fd)
}
```

You can also set literals and HTML values using the helper functions:

```go
graph := dot.NewGraph()
graph.Node("n1").SetAttributeLiteral(attributes.KeyLabel, `a left label\l`)
graph.Node("n2").SetAttributeHTML(attributes.KeyLabel, `<b>a bold label</b>`)
package main

import (
"os"
"github.com/wwmoraes/dot"
"github.com/wwmoraes/dot/constants"
)

func main() {
graph := dot.NewGraph()
graph.Node("n1").SetAttributeLiteral(constants.KeyLabel, `a left label\l`)
graph.Node("n2").SetAttributeHTML(constants.KeyLabel, `<b>a bold label</b>`)
fd, _ := os.Create("sample.dot")
graph.WriteTo(fd)
}
```

## ✍️ Authors <a name = "authors"></a>
Expand Down
14 changes: 14 additions & 0 deletions docs/attributes/interfaces/Identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Identity
description: implemented by values that have an immutable identifier
---

# `Identity`

Implemented by values that have an immutable identifier

## source

```go
--8<-- "attributes/Identity.go"
```
14 changes: 14 additions & 0 deletions docs/attributes/interfaces/Reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Reader
description: implemented by attribute-based values that allows reading them
---

# `Reader`

Implemented by attribute-based values that allows reading them

## source

```go
--8<-- "attributes/Reader.go"
```
15 changes: 15 additions & 0 deletions docs/attributes/interfaces/Serializable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Serializable
description: implemented by values that can be printed as string or written directly into an IO device
---

# `Serializable`

Implemented by values that can be printed as string or written directly into an
IO device.

## source

```go
--8<-- "attributes/Serializable.go"
```
14 changes: 14 additions & 0 deletions docs/attributes/interfaces/Styleable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Styleable
description: implemented by values that support attributes
---

# `Styleable`

Implemented by values that support attributes

## source

```go
--8<-- "attributes/Styleable.go"
```
14 changes: 14 additions & 0 deletions docs/attributes/interfaces/Writer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Writer
description: implemented by attribute-based values that allows mutating them
---

# `Writer`

Implemented by attribute-based values that allows mutating them

## source

```go
--8<-- "attributes/Writer.go"
```
12 changes: 0 additions & 12 deletions docs/attributes/keys.md

This file was deleted.

15 changes: 15 additions & 0 deletions docs/constants/Key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Key
description: attribute key values
---

# `Key`

All Graphviz known attributes are mapped as `string` constants to prevent typos
and the creation of multiple string literals across the code.

## source

```go
--8<-- "constants/Key.go"
```
11 changes: 7 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
this package is a WIP and will introduce breaking changes while on major
version zero.

[![Status](https://img.shields.io/badge/status-active-success.svg)]()
[![Status](https://img.shields.io/badge/status-active-success.svg)](https://github.com/wwmoraes/dot)
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/wwmoraes/dot)
[![Go Report Card](https://goreportcard.com/badge/github.com/wwmoraes/dot)](https://goreportcard.com/report/github.com/wwmoraes/dot)
[![GoDoc](https://godoc.org/github.com/wwmoraes/dot?status.svg)](https://pkg.go.dev/github.com/wwmoraes/dot)
Expand All @@ -19,7 +19,7 @@ implementation focused on generating dot/gv files that [Graphviz](graphviz) can
then convert into any of its output formats supported (e.g. png, jpeg, svg, pdf).

Dot provides both interfaces and ready-to-use concrete types that represent
[dot language](dotlanguage) resources - namely Graphs, Nodes and Edges, plus all
[dot language](dot-language) resources - namely Graphs, Nodes and Edges, plus all
attributes.

This package was inspired/initially forked from [emicklei/dot](emicklei-dot),
Expand Down Expand Up @@ -51,10 +51,13 @@ func main() {

graph.Node("n1").SetAttributeString("label", "hello dot!")

graph.Write(os.Create("sample.dot"))
fd, _ := os.Create("sample.dot")
defer fd.Close()

graph.WriteTo(fd)
}
```

[graphviz]: https://graphviz.org
[dotlanguage]: http://www.graphviz.org/doc/info/lang.html
[dot-language]: http://www.graphviz.org/doc/info/lang.html
[emicklei-dot]: https://github.com/emicklei/dot
14 changes: 14 additions & 0 deletions docs/interfaces/StyledEdge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: StyledEdge
description: implemented by edge values with convenience styling methods
---

# `StyledEdge`

Implemented by dot-compatible edge values which have convenience styling methods

## source

```go
--8<-- "StyledEdge.go"
```
9 changes: 8 additions & 1 deletion docs/interfaces/edge.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Edge
---
title: Edge
description: implemented by dot-compatible edge values
---

# `Edge`

Implemented by dot-compatible edge values, with support for attributes.

## source

```go
--8<-- "Edge.go"
```
12 changes: 11 additions & 1 deletion docs/interfaces/graph.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Graph
---
title: Graph
description: implemented by dot-compatible graph values
---

# `Graph`

Implemented by dot-compatible graph values, with support for attributes.
Extends attributes' [Identity](../attributes/interfaces/Identity.md),
[Styleable](../attributes/interfaces/Styleable.md) and
[Serializable](../attributes/interfaces/Serializable.md) interfaces.

## source

```go
--8<-- "Graph.go"
Expand Down
9 changes: 8 additions & 1 deletion docs/interfaces/node.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Node
---
title: Node
description: implemented by dot-compatible node values
---

# `Node`

Implemented by dot-compatible node values, with support for attributes.

## source

```go
--8<-- "Node.go"
```
50 changes: 50 additions & 0 deletions docs/types/GraphOptionFn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: GraphOptionFn
description: functor that mutates graph options
---

# `GraphOptionFn`

Implemented by functor values that set properties on a `GraphOptions` instance,
which are then used by `Graph`s `NewGraph`/`Graph.Subgraph` to configure new
[sub]graphs.

A `nil` error is expected as a return value if the functor has successfully set
the options it is intended to.

These functors are usually returned by `With*` functions that are free to accept
any parameters to be used within the functor, e.g.

```go
func WithMyOptions(id string) GraphOptionFn {
return func(options GraphOptions) error {
// use the given id
options.SetID(id)
// always create as strict
options.SetStrict(true)
// use undirected (graph) instead of the default directed (digraph)
options.SetType(GraphTypeUndirected)

return nil
}
}
```

then it can be used as

```go
graph, _ := dot.NewGraph(WithMyOptions("some-id"))
```

## implementation

```go
// GraphOptionFn is a functor that mutates graph options
type GraphOptionFn func(GraphOptions) error
```

## source

```go
--8<-- "Graph.go"
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ theme:
- navigation.instant
- navigation.tabs
markdown_extensions:
- meta
- admonition
- pymdownx.tabbed
- pymdownx.superfences
Expand Down

0 comments on commit c7f58cc

Please sign in to comment.