diagrams-lib-1.4: Embedded domain-specific language for declarative graphics

Copyright(c) 2013 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Names

Contents

Description

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.

Synopsis

Names

data AName :: * #

Atomic names. AName is just an existential wrapper around things which are Typeable, Ord and Show.

Instances

Eq AName 

Methods

(==) :: AName -> AName -> Bool #

(/=) :: AName -> AName -> Bool #

Ord AName 

Methods

compare :: AName -> AName -> Ordering #

(<) :: AName -> AName -> Bool #

(<=) :: AName -> AName -> Bool #

(>) :: AName -> AName -> Bool #

(>=) :: AName -> AName -> Bool #

max :: AName -> AName -> AName #

min :: AName -> AName -> AName #

Show AName 

Methods

showsPrec :: Int -> AName -> ShowS #

show :: AName -> String #

showList :: [AName] -> ShowS #

IsName AName 

Methods

toName :: AName -> Name #

Each Name Name AName AName 

data Name :: * #

A (qualified) name is a (possibly empty) sequence of atomic names.

Instances

Eq Name 

Methods

(==) :: Name -> Name -> Bool #

(/=) :: Name -> Name -> Bool #

Ord Name 

Methods

compare :: Name -> Name -> Ordering #

(<) :: Name -> Name -> Bool #

(<=) :: Name -> Name -> Bool #

(>) :: Name -> Name -> Bool #

(>=) :: Name -> Name -> Bool #

max :: Name -> Name -> Name #

min :: Name -> Name -> Name #

Show Name 

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

Semigroup Name 

Methods

(<>) :: Name -> Name -> Name #

sconcat :: NonEmpty Name -> Name #

stimes :: Integral b => b -> Name -> Name #

Monoid Name 

Methods

mempty :: Name #

mappend :: Name -> Name -> Name #

mconcat :: [Name] -> Name #

IsName Name 

Methods

toName :: Name -> Name #

Qualifiable Name

Of course, names can be qualified using (.>).

Methods

(.>>) :: IsName a => a -> Name -> Name #

Wrapped Name 

Associated Types

type Unwrapped Name :: * #

Rewrapped Name Name 
Each Name Name AName AName 
Action Name (SubMap b v n m)

A name acts on a name map by qualifying every name in it.

Methods

act :: Name -> SubMap b v n m -> SubMap b v n m #

type Unwrapped Name 

class (Typeable * a, Ord a, Show a) => IsName a where #

Class for those types which can be used as names. They must support Typeable (to facilitate extracting them from existential wrappers), Ord (for comparison and efficient storage) and Show.

To make an instance of IsName, you need not define any methods, just declare it.

WARNING: it is not recommended to use GeneralizedNewtypeDeriving in conjunction with IsName, since in that case the underlying type and the newtype will be considered equivalent when comparing names. For example:

    newtype WordN = WordN Int deriving (Show, Ord, Eq, Typeable, IsName)
  

is unlikely to work as intended, since (1 :: Int) and (WordN 1) will be considered equal as names. Instead, use

    newtype WordN = WordN Int deriving (Show, Ord, Eq, Typeable, IsName)
    instance IsName WordN
  

Minimal complete definition

Nothing

Instances

IsName Bool 

Methods

toName :: Bool -> Name #

IsName Char 

Methods

toName :: Char -> Name #

IsName Double 

Methods

toName :: Double -> Name #

IsName Float 

Methods

toName :: Float -> Name #

IsName Int 

Methods

toName :: Int -> Name #

IsName Integer 

Methods

toName :: Integer -> Name #

IsName () 

Methods

toName :: () -> Name #

IsName AName 

Methods

toName :: AName -> Name #

IsName Name 

Methods

toName :: Name -> Name #

IsName a => IsName [a] 

Methods

toName :: [a] -> Name #

IsName a => IsName (Maybe a) 

Methods

toName :: Maybe a -> Name #

(IsName a, IsName b) => IsName (a, b) 

Methods

toName :: (a, b) -> Name #

(IsName a, IsName b, IsName c) => IsName (a, b, c) 

Methods

toName :: (a, b, c) -> Name #

(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name infixr 5 #

Convenient operator for writing qualified names with atomic components of different types. Instead of writing toName a1 <> toName a2 <> toName a3 you can just write a1 .> a2 .> a3.

class Qualifiable q where #

Instances of Qualifiable are things which can be qualified by prefixing them with a name.

Instances

Qualifiable Name

Of course, names can be qualified using (.>).

Methods

(.>>) :: IsName a => a -> Name -> Name #

Qualifiable a => Qualifiable [a] 

Methods

(.>>) :: IsName a => a -> [a] -> [a] #

(Ord a, Qualifiable a) => Qualifiable (Set a) 

Methods

(.>>) :: IsName a => a -> Set a -> Set a #

Qualifiable a => Qualifiable (TransInv a) 

Methods

(.>>) :: IsName a => a -> TransInv a -> TransInv a #

Qualifiable a => Qualifiable (Located a) # 

Methods

(.>>) :: IsName a => a -> Located a -> Located a #

Qualifiable a => Qualifiable (b -> a) 

Methods

(.>>) :: IsName a => a -> (b -> a) -> b -> a #

(Qualifiable a, Qualifiable b) => Qualifiable (a, b) 

Methods

(.>>) :: IsName a => a -> (a, b) -> (a, b) #

Qualifiable a => Qualifiable (Map k a) 

Methods

(.>>) :: IsName a => a -> Map k a -> Map k a #

Qualifiable a => Qualifiable (Measured n a) 

Methods

(.>>) :: IsName a => a -> Measured n a -> Measured n a #

(Qualifiable a, Qualifiable b, Qualifiable c) => Qualifiable (a, b, c) 

Methods

(.>>) :: IsName a => a -> (a, b, c) -> (a, b, c) #

(Metric v, OrderedField n, Semigroup m) => Qualifiable (QDiagram b v n m)

Diagrams can be qualified so that all their named points can now be referred to using the qualification prefix.

Methods

(.>>) :: IsName a => a -> QDiagram b v n m -> QDiagram b v n m #

Qualifiable (SubMap b v n m)

SubMaps are qualifiable: if ns is a SubMap, then a |> ns is the same SubMap except with every name qualified by a.

Methods

(.>>) :: IsName a => a -> SubMap b v n m -> SubMap b v n m #

Subdiagrams

data Subdiagram b v n m :: * -> (* -> *) -> * -> * -> * #

A Subdiagram represents a diagram embedded within the context of a larger diagram. Essentially, it consists of a diagram paired with any accumulated information from the larger context (transformations, attributes, etc.).

Instances

Functor (Subdiagram b v n) 

Methods

fmap :: (a -> b) -> Subdiagram b v n a -> Subdiagram b v n b #

(<$) :: a -> Subdiagram b v n b -> Subdiagram b v n a #

(OrderedField n, Metric v, Monoid' m) => Enveloped (Subdiagram b v n m) 

Methods

getEnvelope :: Subdiagram b v n m -> Envelope (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) #

(OrderedField n, Metric v, Semigroup m) => Traced (Subdiagram b v n m) 

Methods

getTrace :: Subdiagram b v n m -> Trace (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) #

Transformable (Subdiagram b v n m) 

Methods

transform :: Transformation (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) -> Subdiagram b v n m -> Subdiagram b v n m #

(Metric v, OrderedField n) => HasOrigin (Subdiagram b v n m) 

Methods

moveOriginTo :: Point (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) -> Subdiagram b v n m -> Subdiagram b v n m #

type V (Subdiagram b v n m) 
type V (Subdiagram b v n m) = v
type N (Subdiagram b v n m) 
type N (Subdiagram b v n m) = n

mkSubdiagram :: QDiagram b v n m -> Subdiagram b v n m #

Turn a diagram into a subdiagram with no accumulated context.

subPoint :: (Metric v, OrderedField n) => Point v n -> Subdiagram b v n m #

Create a "point subdiagram", that is, a pointDiagram (with no content and a point envelope) treated as a subdiagram with local origin at the given point. Note this is not the same as mkSubdiagram . pointDiagram, which would result in a subdiagram with local origin at the parent origin, rather than at the given point.

getSub :: (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> QDiagram b v n m #

Turn a subdiagram into a normal diagram, including the enclosing context. Concretely, a subdiagram is a pair of (1) a diagram and (2) a "context" consisting of an extra transformation and attributes. getSub simply applies the transformation and attributes to the diagram to get the corresponding "top-level" diagram.

rawSub :: Subdiagram b v n m -> QDiagram b v n m #

Extract the "raw" content of a subdiagram, by throwing away the context.

location :: (Additive v, Num n) => Subdiagram b v n m -> Point v n #

Get the location of a subdiagram; that is, the location of its local origin with respect to the vector space of its parent diagram. In other words, the point where its local origin "ended up".

Subdiagram maps

data SubMap b v n m :: * -> (* -> *) -> * -> * -> * #

A SubMap is a map associating names to subdiagrams. There can be multiple associations for any given name.

Instances

Action Name (SubMap b v n m)

A name acts on a name map by qualifying every name in it.

Methods

act :: Name -> SubMap b v n m -> SubMap b v n m #

Functor (SubMap b v n) 

Methods

fmap :: (a -> b) -> SubMap b v n a -> SubMap b v n b #

(<$) :: a -> SubMap b v n b -> SubMap b v n a #

Semigroup (SubMap b v n m) 

Methods

(<>) :: SubMap b v n m -> SubMap b v n m -> SubMap b v n m #

sconcat :: NonEmpty (SubMap b v n m) -> SubMap b v n m #

stimes :: Integral b => b -> SubMap b v n m -> SubMap b v n m #

Monoid (SubMap b v n m)

SubMaps form a monoid with the empty map as the identity, and map union as the binary operation. No information is ever lost: if two maps have the same name in their domain, the resulting map will associate that name to the concatenation of the information associated with that name.

Methods

mempty :: SubMap b v n m #

mappend :: SubMap b v n m -> SubMap b v n m -> SubMap b v n m #

mconcat :: [SubMap b v n m] -> SubMap b v n m #

Qualifiable (SubMap b v n m)

SubMaps are qualifiable: if ns is a SubMap, then a |> ns is the same SubMap except with every name qualified by a.

Methods

(.>>) :: IsName a => a -> SubMap b v n m -> SubMap b v n m #

Transformable (SubMap b v n m) 

Methods

transform :: Transformation (V (SubMap b v n m)) (N (SubMap b v n m)) -> SubMap b v n m -> SubMap b v n m #

(OrderedField n, Metric v) => HasOrigin (SubMap b v n m) 

Methods

moveOriginTo :: Point (V (SubMap b v n m)) (N (SubMap b v n m)) -> SubMap b v n m -> SubMap b v n m #

Wrapped (SubMap b v n m) 

Associated Types

type Unwrapped (SubMap b v n m) :: * #

Methods

_Wrapped' :: Iso' (SubMap b v n m) (Unwrapped (SubMap b v n m)) #

Rewrapped (SubMap b v n m) (SubMap b' v' n' m') 
type V (SubMap b v n m) 
type V (SubMap b v n m) = v
type N (SubMap b v n m) 
type N (SubMap b v n m) = n
type Unwrapped (SubMap b v n m) 
type Unwrapped (SubMap b v n m) = Map Name [Subdiagram b v n m]

fromNames :: IsName a => [(a, Subdiagram b v n m)] -> SubMap b v n m #

Construct a SubMap from a list of associations between names and subdiagrams.

rememberAs :: IsName a => a -> QDiagram b v n m -> SubMap b v n m -> SubMap b v n m #

Add a name/diagram association to a submap.

lookupSub :: IsName nm => nm -> SubMap b v n m -> Maybe [Subdiagram b v n m] #

Look for the given name in a name map, returning a list of subdiagrams associated with that name. If no names match the given name exactly, return all the subdiagrams associated with names of which the given name is a suffix.

Naming things

named :: (IsName nm, Metric v, OrderedField n, Semigroup m) => nm -> QDiagram b v n m -> QDiagram b v n m Source #

Attach an atomic name to a diagram.

nameSub :: (IsName nm, Metric v, OrderedField n, Semigroup m) => (QDiagram b v n m -> Subdiagram b v n m) -> nm -> QDiagram b v n m -> QDiagram b v n m #

Attach an atomic name to a certain subdiagram, computed from the given diagram /with the mapping from name to subdiagram included/. The upshot of this knot-tying is that if d' = d # named x, then lookupName x d' == Just d' (instead of Just d).

namePoint :: (IsName nm, Metric v, OrderedField n, Semigroup m) => (QDiagram b v n m -> Point v n) -> nm -> QDiagram b v n m -> QDiagram b v n m Source #

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.

localize :: (Metric v, OrderedField n, Semigroup m) => QDiagram b v n m -> QDiagram b v n m #

"Localize" a diagram by hiding all the names, so they are no longer visible to the outside.

Querying by name

names :: (Metric v, Semigroup m, OrderedField n) => QDiagram b v n m -> [(Name, [Point v n])] #

Get a list of names of subdiagrams and their locations.

lookupName :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> QDiagram b v n m -> Maybe (Subdiagram b v n m) #

Lookup the most recent diagram associated with (some qualification of) the given name.

withName :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> (Subdiagram b v n m -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #

Given a name and a diagram transformation indexed by a subdiagram, perform the transformation using the most recent subdiagram associated with (some qualification of) the name, or perform the identity transformation if the name does not exist.

withNameAll :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #

Given a name and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the collection of all such subdiagrams associated with (some qualification of) the given name.

withNames :: (IsName nm, Metric v, Semigroup m, OrderedField n) => [nm] -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #

Given a list of names and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the list of most recent subdiagrams associated with (some qualification of) each name. Do nothing (the identity transformation) if any of the names do not exist.