Skip to content

Commit

Permalink
Merge pull request #2 from jessp01/minor-fixes-and-ci
Browse files Browse the repository at this point in the history
Minor fixes and ci
  • Loading branch information
MrIceman committed Oct 30, 2023
2 parents 5eab256 + 9e084c0 commit 8083dfe
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on: [push, pull_request]

defaults:
run:
shell: 'bash -Eeuo pipefail -x {0}'

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: cd sequence && go build -v
- name: Test
run: |
set -e
go install github.com/go-critic/go-critic/cmd/gocritic@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/lint/golint@latest
go install github.com/gordonklaus/ineffassign@latest
pip install pre-commit
pre-commit install
pre-commit run --all-files
# go test -v
#- name: Test
#run: go test -v
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/jessp01/pre-commit-golang.git
rev: v0.5.4
hooks:
- id: go-fmt
- id: go-imports
#- id: go-vet
- id: go-lint
- id: go-critic
- id: go-ineffassign
- id: shellcheck
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# go-uml

[![CI][badge-build]][build]
[![GoDoc][go-docs-badge]][go-docs]
[![GoReportCard][go-report-card-badge]][go-report-card]
[![License][badge-license]][license]

Just a little tool to create UML Diagrams built in Go. You can use it already to build simple sequence diagrams, however, this project is still under development
and you won't find some functionalities yet such as

- provide conditional flows

The generated diagram is saved as .PNG file

So far, you can create only sequence diagrams and add Participants, directional and undirectional Edges, labels for Edges and set a Title for the diagram.
So far, you can create only sequence diagrams and add Participants, directional and non-directional Edges, labels for Edges and set a Title for the diagram.
I'll be updating this repository whenever I need the tool to support more functionality, feel free to create an Issue with a feature request. Since I just started this project, contributing should also be quite easy (I appreciate any contribution).

You don't need to download any dependencies such as plantUML or Graphviz, which is what most of the tools out there require and what was also my motivation to start this project. go-uml is using a 2D graphics engine written 100% in Go https://github.com/fogleman/gg
You don't need to download any dependencies such as plantUML or Graphviz, which is what most of the tools out there require and what was also my motivation to start this project. go-uml is using a [2D graphics engine](https://github.com/fogleman/gg) written 100% in Go

# How to install

Expand All @@ -26,7 +32,7 @@ first

# Example

```
```go
d := sequence.NewDiagram("user_starts_chatting")

client := "Client"
Expand Down Expand Up @@ -55,7 +61,7 @@ first
d.Render()

```
Result PNG file:
Resulting PNG file:
![Sequence Diagram generated based on above code](./examples/user_starts_chatting.png)

Some more examples:
Expand All @@ -65,3 +71,12 @@ Some more examples:
## Warning - AI not welcome here
Because of my own personal philosophy regarding technology and AI, all the code in this repository that was written by me - I wrote 100% on my own. There is and will be no usage of Github Co-Pilot or any other AI tool. I became a software developer because of my passion for our craft - Software Engineering. I build this tool because I enjoy programming. Every single line of code you'll read in this repo, that was written by me, is produced first in my mind and then manifested into reality through my hands. I encourage any contributor to follow the same principle, though I can't and don't want to put any restrictions on this.
Just like people stopped walking because they commute by cars and trains, which caused an increase in obesity and illness, I believe that the massive usage of AI will cause people to stop thinking and using their minds and the resulting havoc is unthinkable.

[license]: ./LICENSE
[badge-license]: https://img.shields.io/github/license/MrIceman/go-uml.svg
[go-docs-badge]: https://godoc.org/github.com/MrIceman/go-uml?status.svg
[go-docs]: https://godoc.org/github.com/MrIceman/go-uml
[go-report-card-badge]: https://goreportcard.com/badge/github.com/MrIceman/go-uml
[go-report-card]: https://goreportcard.com/report/github.com/MrIceman/go-uml
[badge-build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml/badge.svg
[build]: https://github.com/MrIceman/go-uml/actions/workflows/go.yml
5 changes: 4 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package main
import "github.com/mriceman/go-uml/sequence"

func main() {
userStartsChatting()
userBIsNotPartOfChat()
userBIsPartOfChat()
userJoinsChat()
}

Expand Down Expand Up @@ -33,7 +36,7 @@ func userJoinsChat() {
d.Render()
}

func UserBIsPartOfChat() {
func userBIsPartOfChat() {
d := sequence.NewDiagram("on_new_message_for_user_b")

usrA := "User A"
Expand Down
10 changes: 9 additions & 1 deletion sequence/diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package sequence

import (
"fmt"
"github.com/fogleman/gg"
"image/color"
"log"

"github.com/fogleman/gg"
)

const (
Expand All @@ -21,6 +22,7 @@ const (
height = 1000
)

// Diagram represents a diagram
type Diagram struct {
participants []participant
edges []edge
Expand All @@ -32,6 +34,7 @@ type Diagram struct {
filename string
}

// NewDiagram init function
func NewDiagram(filename string) *Diagram {
coordMap := make(map[string]participantCoord)

Expand All @@ -41,6 +44,7 @@ func NewDiagram(filename string) *Diagram {
}
}

// Render generates an image from a `Diagram` object
func (d *Diagram) Render() {
d.dc = gg.NewContext(width, height)
d.dc.DrawRectangle(0, 0, width, height)
Expand Down Expand Up @@ -188,6 +192,7 @@ func (d *Diagram) renderEdges() {
}
}

// AddParticipants sets the `participant` array on the Diagram object
func (d *Diagram) AddParticipants(name ...string) {
for _, n := range name {
for i := range d.participants {
Expand All @@ -199,6 +204,7 @@ func (d *Diagram) AddParticipants(name ...string) {
}
}

// AddDirectionalEdge adds a connection (renders as an arrowed line) between two participants
func (d *Diagram) AddDirectionalEdge(from, to string, label string) error {
var fromPar *participant
var toPar *participant
Expand All @@ -221,6 +227,7 @@ func (d *Diagram) AddDirectionalEdge(from, to string, label string) error {
return nil
}

// AddUndirectionalEdge adds a connection (renders as a line) between two participants
func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error {
var fromPar *participant
var toPar *participant
Expand All @@ -240,6 +247,7 @@ func (d *Diagram) AddUndirectionalEdge(from, to string, label string) error {
return nil
}

// SetTitle sets the diagram's title
func (d *Diagram) SetTitle(s string) {
d.title = s
}

0 comments on commit 8083dfe

Please sign in to comment.