Skip to content

Commit

Permalink
feat: add dashed lines to computed relations
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari committed Mar 6, 2024
1 parent aa4e459 commit e370485
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (g *dotEncodingGraph) AddOrGetNode(label string) graph.Node {
return n
}

func (g *dotEncodingGraph) AddEdge(from, to string, optionalHeadLabel string) graph.Line {
func (g *dotEncodingGraph) AddEdge(from, to string, optionalHeadLabel, optionalStyle string) graph.Line {
n1 := g.AddOrGetNode(from)
n2 := g.AddOrGetNode(to)
existingLinesIter := g.Lines(n1.ID(), n2.ID())
Expand All @@ -91,6 +91,7 @@ func (g *dotEncodingGraph) AddEdge(from, to string, optionalHeadLabel string) gr
g.DirectedGraph.SetLine(edge)
edge.attrs["label"] = strconv.Itoa(g.edgeCounter)
edge.attrs["headlabel"] = optionalHeadLabel
edge.attrs["style"] = optionalStyle
g.lines[edge.ID()] = edge.attrs
return &dotLine{
Line: edge,
Expand Down
10 changes: 5 additions & 5 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ func rewriteHandler(typesys *typesystem.TypeSystem, g *dotEncodingGraph, typeNam
if assignableRelationRef != "" {
assignableRelationNodeName := fmt.Sprintf("%s#%s", assignableType, assignableRelationRef)

g.AddEdge(assignableRelationNodeName, relationNodeName, "")
g.AddEdge(assignableRelationNodeName, relationNodeName, "", "")
}

wildcardRelationRef := assignableRelation.GetWildcard()
if wildcardRelationRef != nil {
wildcardRelationNodeName := fmt.Sprintf("%s:*", assignableType)

g.AddEdge(wildcardRelationNodeName, relationNodeName, "")
g.AddEdge(wildcardRelationNodeName, relationNodeName, "", "")
}
} else {
g.AddEdge(assignableType, relationNodeName, "")
g.AddEdge(assignableType, relationNodeName, "", "")
}
}
case *openfgav1.Userset_ComputedUserset:
Expand All @@ -93,7 +93,7 @@ func rewriteHandler(typesys *typesystem.TypeSystem, g *dotEncodingGraph, typeNam
}

rewrittenNodeName := fmt.Sprintf("%s#%s", typeName, rewritten.GetName())
g.AddEdge(rewrittenNodeName, relationNodeName, "")
g.AddEdge(rewrittenNodeName, relationNodeName, "", "dashed")
case *openfgav1.Userset_TupleToUserset:
tupleset := rw.TupleToUserset.GetTupleset().GetRelation()
rewrittenRelation := rw.TupleToUserset.GetComputedUserset().GetRelation()
Expand All @@ -113,7 +113,7 @@ func rewriteHandler(typesys *typesystem.TypeSystem, g *dotEncodingGraph, typeNam
rewrittenNodeName := fmt.Sprintf("%s#%s", assignableType, rewrittenRelation)
conditionedOnNodeName := fmt.Sprintf("(%s#%s)", typeName, tuplesetRel.GetName())

g.AddEdge(rewrittenNodeName, relationNodeName, conditionedOnNodeName)
g.AddEdge(rewrittenNodeName, relationNodeName, conditionedOnNodeName, "")
}
case *openfgav1.Userset_Union:
case *openfgav1.Userset_Intersection:
Expand Down

0 comments on commit e370485

Please sign in to comment.