Skip to content

Commit

Permalink
Merge pull request #63 from hovsep/export
Browse files Browse the repository at this point in the history
Export
  • Loading branch information
hovsep authored Oct 12, 2024
2 parents 7d2cc32 + cd0a5e1 commit 144dbcd
Show file tree
Hide file tree
Showing 10 changed files with 661 additions and 268 deletions.
21 changes: 21 additions & 0 deletions component/activation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ type ActivationResult struct {
// ActivationResultCode denotes a specific info about how a component been activated or why not activated at all
type ActivationResultCode int

func (a ActivationResultCode) String() string {
switch a {
case ActivationCodeOK:
return "OK"
case ActivationCodeNoInput:
return "No input"
case ActivationCodeNoFunction:
return "Activation function is missing"
case ActivationCodeReturnedError:
return "Returned error"
case ActivationCodePanicked:
return "Panicked"
case ActivationCodeWaitingForInputsClear:
return "Component is waiting for input"
case ActivationCodeWaitingForInputsKeep:
return "Component is waiting for input and wants to keep all inputs till next cycle"
default:
return "Unsupported code"
}
}

const (
// ActivationCodeOK : component is activated and did not return any errors
ActivationCodeOK ActivationResultCode = iota
Expand Down
12 changes: 12 additions & 0 deletions cycle/cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
// Cycle contains the info about given activation cycle
type Cycle struct {
sync.Mutex
number int
activationResults component.ActivationResultCollection
}

Expand Down Expand Up @@ -43,3 +44,14 @@ func (cycle *Cycle) WithActivationResults(activationResults ...*component.Activa
cycle.activationResults = cycle.ActivationResults().Add(activationResults...)
return cycle
}

// Number returns sequence number
func (cycle *Cycle) Number() int {
return cycle.number
}

// WithNumber sets the sequence number
func (cycle *Cycle) WithNumber(number int) *Cycle {
cycle.number = number
return cycle
}
175 changes: 0 additions & 175 deletions export/dot.go

This file was deleted.

137 changes: 137 additions & 0 deletions export/dot/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package dot

import fmeshcomponent "github.com/hovsep/fmesh/component"

type attributesMap map[string]string

type ComponentConfig struct {
Subgraph attributesMap
SubgraphNodeBaseAttrs attributesMap
Node attributesMap
NodeDefaultLabel string
ErrorNode attributesMap
SubgraphAttributesByActivationResultCode map[fmeshcomponent.ActivationResultCode]attributesMap
}

type PortConfig struct {
Node attributesMap
}

type LegendConfig struct {
Subgraph attributesMap
Node attributesMap
}

type PipeConfig struct {
Edge attributesMap
}

type Config struct {
MainGraph attributesMap
Component ComponentConfig
Port PortConfig
Pipe PipeConfig
Legend LegendConfig
}

var (
defaultConfig = &Config{
MainGraph: attributesMap{
"layout": "dot",
"splines": "ortho",
},
Component: ComponentConfig{
Subgraph: attributesMap{
"cluster": "true",
"style": "rounded",
"color": "black",
"margin": "20",
"penwidth": "5",
},
SubgraphNodeBaseAttrs: attributesMap{
"fontname": "Courier New",
"width": "1.0",
"height": "1.0",
"penwidth": "2.5",
"style": "filled",
},
Node: attributesMap{
"shape": "rect",
"color": "#9dddea",
"style": "filled",
},
NodeDefaultLabel: "𝑓",
ErrorNode: nil,
SubgraphAttributesByActivationResultCode: map[fmeshcomponent.ActivationResultCode]attributesMap{
fmeshcomponent.ActivationCodeOK: {
"color": "green",
},
fmeshcomponent.ActivationCodeNoInput: {
"color": "yellow",
},
fmeshcomponent.ActivationCodeNoFunction: {
"color": "gray",
},
fmeshcomponent.ActivationCodeReturnedError: {
"color": "red",
},
fmeshcomponent.ActivationCodePanicked: {
"color": "pink",
},
fmeshcomponent.ActivationCodeWaitingForInputsClear: {
"color": "blue",
},
fmeshcomponent.ActivationCodeWaitingForInputsKeep: {
"color": "purple",
},
},
},
Port: PortConfig{
Node: attributesMap{
"shape": "circle",
},
},
Pipe: PipeConfig{
Edge: attributesMap{
"minlen": "3",
"penwidth": "2",
"color": "#e437ea",
},
},
Legend: LegendConfig{
Subgraph: attributesMap{
"style": "dashed,filled",
"fillcolor": "#e2c6fc",
},
Node: attributesMap{
"shape": "plaintext",
"color": "green",
"fontname": "Courier New",
},
},
}

legendTemplate = `
<table border="0" cellborder="0" cellspacing="10">
{{ if .meshDescription }}
<tr>
<td>Description:</td><td>{{ .meshDescription }}</td>
</tr>
{{ end }}
{{ if .cycleNumber }}
<tr>
<td>Cycle:</td><td>{{ .cycleNumber }}</td>
</tr>
{{ end }}
{{ if .stats }}
{{ range .stats }}
<tr>
<td>{{ .Name }}:</td><td>{{ .Value }}</td>
</tr>
{{ end }}
{{ end }}
</table>
`
)
Loading

0 comments on commit 144dbcd

Please sign in to comment.