/
Names.hs
65 lines (48 loc) · 1.92 KB
/
Names.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- for Data.Semigroup
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams.Names
-- Copyright : (c) 2013 diagrams-lib team (see LICENSE)
-- License : BSD-style (see LICENSE)
-- Maintainer : diagrams-discuss@googlegroups.com
--
-- Names can be given to subdiagrams, and subdiagrams can later be
-- queried by name. This module exports types for representing names
-- and subdiagrams, and various functions for working with them.
--
-----------------------------------------------------------------------------
module Diagrams.Names
( -- * Names
AName, Name, IsName(..), (.>)
, Qualifiable(..)
-- * Subdiagrams
, Subdiagram, mkSubdiagram, subPoint, getSub, rawSub, location
-- * Subdiagram maps
, SubMap, fromNames, rememberAs, lookupSub
-- * Naming things
, named, nameSub, namePoint, localize
-- * Querying by name
, names
, lookupName
, withName, withNameAll, withNames
) where
import Data.Semigroup
import Data.Typeable
import Diagrams.Core (OrderedField, Point)
import Diagrams.Core.Names
import Diagrams.Core.Types
import Linear.Metric
-- | Attach an atomic name to a diagram.
named :: (IsName nm, Metric v, OrderedField n, Typeable n, Semigroup m)
=> nm -> QDiagram b v n m -> QDiagram b v n m
named = nameSub mkSubdiagram
-- | Attach an atomic name to a certain point (which may be computed
-- from the given diagram), treated as a subdiagram with no content
-- and a point envelope.
namePoint :: (IsName nm , Metric v, OrderedField n, Typeable n, Semigroup m)
=> (QDiagram b v n m -> Point v n) -> nm -> QDiagram b v n m -> QDiagram b v n m
namePoint p = nameSub (subPoint . p)