Pick best port angles for edges.

This commit is contained in:
Robbie Gleichman 2016-12-01 22:11:11 -08:00
parent a250b479a5
commit eb6291b11d
3 changed files with 16 additions and 13 deletions

View File

@ -59,10 +59,10 @@ iconToDiagram (NestedApply args) = nestedApplyDia args
iconToDiagram (NestedPApp args) = nestedPAppDia args
applyPortAngles :: (Integral a, Floating n) => a -> [Angle n]
applyPortAngles x = case x of
0 -> [1/2 @@ turn]
1 -> [0 @@ turn]
_ -> fmap (@@ turn) [1/4, 3/4]
applyPortAngles x = fmap (@@ turn) $ case x of
0 -> [3/8, 5/8] -- TODO Add back an angle of 1/2 for non-nested icons
1 -> [0, 1/8, 7/8]
_ -> [1/4, 3/4]
guardPortAngles :: (Integral a, Floating n) => a -> [Angle n]
guardPortAngles port = case port of

View File

@ -143,6 +143,14 @@ findPortAngles (nodeName, nodeIcon) (NameAndPort diaName mPort) = case mPort of
mName = if nodeName == diaName then Nothing else Just diaName
foundAngles = portAngles nodeIcon port mName
-- TODO Clean up the Angle arithmatic
pickClosestAngle :: Angle Double -> Angle Double -> Angle Double -> [Angle Double] -> Angle Double
pickClosestAngle emptyCase target shaftAngle angles = case angles of
[] -> emptyCase
_ -> ((fst (minimumBy (compare `on` snd) $ fmap angleDiff angles) ^. rad) - (shaftAngle ^. rad)) @@ rad
where
angleDiff angle = (angle, angleBetween (angleV target) (angleV angle))
makeEdge :: (SpecialBackend b, ING.Graph gr) =>
gr (Name, Icon) Edge -> SpecialQDiagram b -> ING.LEdge Edge -> SpecialQDiagram b -> SpecialQDiagram b
makeEdge graph dia (node0, node1, edge@(Edge _ _ (namePort0, namePort1))) =
@ -152,12 +160,8 @@ makeEdge graph dia (node0, node1, edge@(Edge _ _ (namePort0, namePort1))) =
ING.lab graph node0
node1label = fromMaybeError ("node0 is not in graph. node1: " ++ show node1) $
ING.lab graph node1
icon0Angle = case findPortAngles node0label namePort0 of
[] -> 0 @@ turn
(x:_) -> ((x ^. turn) - (shaftAngle ^. turn)) @@ turn
icon1Angle = case findPortAngles node1label namePort1 of
[] -> 1/2 @@ turn
(x:_) -> ((x ^. turn) - (shaftAngle ^. turn)) @@ turn
icon0Angle = pickClosestAngle (0 @@ turn) shaftAngle shaftAngle $ findPortAngles node0label namePort0
icon1Angle = pickClosestAngle (1/2 @@ turn) ((shaftAngle ^. rad) + ((1/2 @@ turn) ^. rad) @@ rad) shaftAngle $ findPortAngles node1label namePort1
diaNamePointMap = names dia
port0Point = getPortPoint $ nameAndPortToName namePort0
@ -178,7 +182,7 @@ addEdges :: (SpecialBackend b, ING.Graph gr) =>
gr (Name, Icon) Edge -> SpecialQDiagram b -> SpecialQDiagram b
addEdges graph dia = applyAll connections dia
where
connections = fmap (makeEdge graph dia) $ ING.labEdges graph
connections = makeEdge graph dia <$> ING.labEdges graph
-- ROTATING/FLIPPING ICONS --

View File

@ -9,8 +9,7 @@
Fix the arrowheads being too big for SyntaxGraph darwings.
-- Visual todos:
Pick the best port angle
Fix the port angle of the function port of nested apply. It should be [1/4, 3/4], not [1/2]
Fix edges overlapping making it hard to match up the ends of the edges. Different edge colors for each source might fix this.
-- Consider putting the function name in nested apply and pattern apply in a colored box.
-- Make an icon font/library with labeled ports. E.g. the apply icon would have text labels "function", "result", "arg 0", "arg 1", etc.