2025-01-12 14:59:32 +01:00
|
|
|
// Edge implement Item interface
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: handle arc__ and details__ fields
|
|
|
|
type Edge struct {
|
|
|
|
Id string `yaml:"id" json:"id"`
|
|
|
|
Source string `yaml:"source" json:"source"`
|
|
|
|
Target string `yaml:"target" json:"target"`
|
|
|
|
MainStat string `yaml:"mainstat,omitempty" json:"mainstat,omitempty"`
|
|
|
|
MainStatQuery string `yaml:"mainstatquery,omitempty" json:"mainstatquery,omitempty"`
|
|
|
|
MainStatFormat string `yaml:"mainstatformat,omitempty" json:"mainstatformat,omitempty"`
|
|
|
|
SecondaryStat string `yaml:"secondarystat,omitempty" json:"secondarystat,omitempty"`
|
|
|
|
SecondaryStatQuery string `yaml:"secondarystatquery,omitempty" json:"secondarystatquery,omitempty"`
|
|
|
|
SecondaryStatFormat string `yaml:"secondarystatformat,omitempty" json:"secondarystatformat,omitempty"`
|
|
|
|
Color string `yaml:"color,omitempty" json:"color,omitempty"`
|
|
|
|
Thickness int `yaml:"thickness,omitempty" json:"thickness,omitempty"`
|
2025-01-12 21:00:25 +01:00
|
|
|
ThicknessQuery string `yaml:"thicknessquery,omitempty" json:"thicknessquery,omitempty"`
|
|
|
|
Highlighted bool `yaml:"highlighted,omitempty" json:"hightlighted,omitempty"`
|
|
|
|
HighlightedQuery string `yaml:"highlightedquery,omitempty" json:"highlightedquery,omitempty"`
|
2025-01-12 14:59:32 +01:00
|
|
|
StrokeDashArray float32 `yaml:"strokeDasharray,omitempty" json:"strokeDasharray,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetId() string {
|
|
|
|
return e.Id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetMainStat() string {
|
|
|
|
return e.MainStat
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetSecondaryStat() string {
|
|
|
|
return e.SecondaryStat
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetMainStatQuery() string {
|
|
|
|
return e.MainStatQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetSecondaryStatQuery() string {
|
|
|
|
return e.SecondaryStatQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetMainStatFormat() string {
|
|
|
|
return e.MainStatFormat
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Edge) GetSecondaryStatFormat() string {
|
|
|
|
return e.SecondaryStatFormat
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Edge) SetMainStat(stat string) {
|
|
|
|
e.MainStat = fmt.Sprintf("%s", stat)
|
|
|
|
}
|
|
|
|
|
2025-01-12 21:00:25 +01:00
|
|
|
func (e *Edge) GetThicknessQuery() string {
|
|
|
|
return e.ThicknessQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Edge) SetThickness(thickness float64) {
|
|
|
|
e.Thickness = int(thickness)
|
|
|
|
}
|
|
|
|
|
2025-01-12 14:59:32 +01:00
|
|
|
func (e *Edge) SetSecondaryStat(stat string) {
|
|
|
|
e.SecondaryStat = fmt.Sprintf("%s", stat)
|
|
|
|
}
|
|
|
|
|
2025-01-12 21:00:25 +01:00
|
|
|
func (e *Edge) GetHighlightedQuery() string {
|
|
|
|
return e.HighlightedQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Edge) SetHighlighted(highlighted bool) {
|
|
|
|
e.Highlighted = highlighted
|
|
|
|
}
|
|
|
|
|
2025-01-12 14:59:32 +01:00
|
|
|
// Custom marshaler to not send (main|secondary)statquery
|
|
|
|
func (e Edge) MarshalJSON() ([]byte, error) {
|
|
|
|
jsonRes := `{"id":"` + e.Id + `","source":"` + e.Source + `","target":"` + e.Target + `"`
|
|
|
|
if len(e.MainStat) > 0 {
|
|
|
|
jsonRes += `,"mainstat":"` + e.MainStat + `"`
|
|
|
|
}
|
|
|
|
if len(e.SecondaryStat) > 0 {
|
|
|
|
jsonRes += `,"secondarystat":"` + e.SecondaryStat + `"`
|
|
|
|
}
|
|
|
|
if len(e.Color) > 0 {
|
|
|
|
jsonRes += `,"color":"` + e.Color + `"`
|
|
|
|
}
|
|
|
|
if e.Thickness > 0 {
|
|
|
|
jsonRes += `,"thickness":` + strconv.Itoa(e.Thickness)
|
|
|
|
}
|
2025-01-12 21:00:25 +01:00
|
|
|
if e.Highlighted {
|
2025-01-12 14:59:32 +01:00
|
|
|
jsonRes += `,"highlighted":true`
|
|
|
|
}
|
|
|
|
// TODO : e.StrokeDashArray
|
|
|
|
jsonRes += `}`
|
|
|
|
|
|
|
|
return []byte(jsonRes), nil
|
|
|
|
}
|