Skip to content

Commit

Permalink
Merge pull request #26 from byorgey/master
Browse files Browse the repository at this point in the history
Rename `names` to `subMap`, and add new function `names`
  • Loading branch information
fryguybob committed Sep 19, 2012
2 parents 0adfe33 + 5fcb70f commit 19606ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Graphics/Rendering/Diagrams.hs
Expand Up @@ -113,7 +113,7 @@ module Graphics.Rendering.Diagrams

, QDiagram, mkQD, Diagram
, prims
, envelope, trace, names, query, sample
, envelope, trace, subMap, names, query, sample
, value, resetValue, clearValue

, named, nameSub, namePoint
Expand Down
19 changes: 12 additions & 7 deletions src/Graphics/Rendering/Diagrams/Core.hs
Expand Up @@ -47,7 +47,7 @@ module Graphics.Rendering.Diagrams.Core
-- * Operations on diagrams
-- ** Extracting information
, prims
, envelope, trace, names, query, sample
, envelope, trace, subMap, names, query, sample
, value, resetValue, clearValue

-- ** Combining diagrams
Expand Down Expand Up @@ -262,9 +262,14 @@ setTrace t = over QD ( D.applyUpre (inj . toDeletable $ t)
. D.applyUpost (inj (deleteR :: Deletable (Trace v)))
)

-- | Get the name map of a diagram.
names :: QDiagram b v m -> SubMap b v m
names = getU' . unQD
-- | Get the subdiagram map (*i.e.* an association from names to
-- subdiagrams) of a diagram.
subMap :: QDiagram b v m -> SubMap b v m
subMap = getU' . unQD

-- | Get a list of names of subdiagrams and their locations.
names :: HasLinearMap v => QDiagram b v m -> [(Name, [Point v])]
names = (map . second . map) location . M.assocs . unpack . subMap

-- | Attach an atomic name to a diagram.
named :: ( IsName n
Expand Down Expand Up @@ -295,7 +300,7 @@ nameSub s n d = over QD (D.applyUpre . inj $ fromNames [(n,s d)]) d
withName :: IsName n
=> n -> (Subdiagram b v m -> QDiagram b v m -> QDiagram b v m)
-> QDiagram b v m -> QDiagram b v m
withName n f d = maybe id f (lookupSub (toName n) (names d) >>= listToMaybe) d
withName n f d = maybe id f (lookupSub (toName n) (subMap d) >>= listToMaybe) d

-- | Given a name and a diagram transformation indexed by a list of
-- located envelopes, perform the transformation using the
Expand All @@ -304,7 +309,7 @@ withName n f d = maybe id f (lookupSub (toName n) (names d) >>= listToMaybe) d
withNameAll :: IsName n
=> n -> ([Subdiagram b v m] -> QDiagram b v m -> QDiagram b v m)
-> QDiagram b v m -> QDiagram b v m
withNameAll n f d = f (fromMaybe [] (lookupSub (toName n) (names d))) d
withNameAll n f d = f (fromMaybe [] (lookupSub (toName n) (subMap d))) d

-- | Given a list of names and a diagram transformation indexed by a
-- list of located envelopes, perform the transformation using the
Expand All @@ -315,7 +320,7 @@ withNames :: IsName n
=> [n] -> ([Subdiagram b v m] -> QDiagram b v m -> QDiagram b v m)
-> QDiagram b v m -> QDiagram b v m
withNames ns f d = maybe id f (T.sequence (map ((listToMaybe=<<) . ($nd) . lookupSub . toName) ns)) d
where nd = names d
where nd = subMap d

-- | Get the query function associated with a diagram.
query :: Monoid m => QDiagram b v m -> Query v m
Expand Down

0 comments on commit 19606ac

Please sign in to comment.