Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit d147bb8

Browse files
authored
Merge pull request #191 from github/fix-graph-vertex-ids
Include vertex IDs in JSON graph output and fix their format.
2 parents b4792db + 785ba4d commit d147bb8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Data/Graph.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ instance (Ord vertex, ToJSON vertex, VertexTag vertex) => ToJSON (Graph vertex)
111111
newtype Edge vertex = Edge (vertex, vertex)
112112

113113
instance (ToJSON vertex, VertexTag vertex) => ToJSON (Edge vertex) where
114-
toJSON (Edge (a, b)) = object ["source" .= uniqueTag a, "target" .= uniqueTag b]
115-
toEncoding (Edge (a, b)) = pairs ("source" .= uniqueTag a <> "target" .= uniqueTag b)
114+
toJSON (Edge (a, b)) = object ["source" .= show (uniqueTag a), "target" .= show (uniqueTag b)]
115+
toEncoding (Edge (a, b)) = pairs ("source" .= show (uniqueTag a) <> "target" .= show (uniqueTag b))

src/Data/Graph/ControlFlowVertex.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ instance Lower ControlFlowVertex where lowerBound = Package ""
8686
instance VertexTag ControlFlowVertex where uniqueTag = hash . vertexIdentifier
8787

8888
instance ToJSON ControlFlowVertex where
89-
toJSON v = object [ "name" .= vertexIdentifier v, "type" .= vertexToType v ]
89+
toJSON v = object [ "name" .= vertexIdentifier v
90+
, "type" .= vertexToType v
91+
, "id" .= show (uniqueTag v)
92+
]
93+
toEncoding v = pairs $ mconcat [ "name" .= vertexIdentifier v
94+
, "type" .= vertexToType v
95+
, "id" .= show (uniqueTag v)
96+
]
9097

9198
-- TODO: This is potentially valuable just to get name's out of declarable things.
9299
-- Typeclasses to create 'ControlFlowVertex's from 'Term's. Also extracts

0 commit comments

Comments
 (0)