diagrams-core-1.4.1.1: Core libraries for diagrams EDSL

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

Diagrams.Core.Style

Contents

Description

A definition of styles for diagrams as extensible, heterogeneous collections of attributes.

Synopsis

Attributes

An attribute is anything that determines some aspect of a diagram's rendering. The standard diagrams library defines several standard attributes (line color, line width, fill color, etc.) but additional attributes may easily be created. Additionally, a given backend need not handle (or even know about) attributes used in diagrams it renders.

The attribute code is inspired by xmonad's Message type, which was in turn based on ideas in:

Simon Marlow. An Extensible Dynamically-Typed Hierarchy of Exceptions. Proceedings of the 2006 ACM SIGPLAN workshop on Haskell. http://research.microsoft.com/apps/pubs/default.aspx?id=67968.

class (Typeable a, Semigroup a) => AttributeClass a #

Every attribute must be an instance of AttributeClass, which simply guarantees Typeable and Semigroup constraints. The Semigroup instance for an attribute determines how it will combine with other attributes of the same type.

data Attribute (v :: * -> *) n :: * where #

An existential wrapper type to hold attributes. Some attributes are simply inert/static; some are affected by transformations; and some are affected by transformations and can be modified generically.

Constructors

Attribute :: AttributeClass a => a -> Attribute v n 
MAttribute :: AttributeClass a => Measured n a -> Attribute v n 
TAttribute :: (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n 
Instances
Show (Attribute v n) #

Shows the kind of attribute and the type contained in the attribute.

Instance details

Defined in Diagrams.Core.Style

Methods

showsPrec :: Int -> Attribute v n -> ShowS #

show :: Attribute v n -> String #

showList :: [Attribute v n] -> ShowS #

Typeable n => Semigroup (Attribute v n) #

Attributes form a semigroup, where the semigroup operation simply returns the right-hand attribute when the types do not match, and otherwise uses the semigroup operation specific to the (matching) types.

Instance details

Defined in Diagrams.Core.Style

Methods

(<>) :: Attribute v n -> Attribute v n -> Attribute v n #

sconcat :: NonEmpty (Attribute v n) -> Attribute v n #

stimes :: Integral b => b -> Attribute v n -> Attribute v n #

(Additive v, Traversable v, Floating n) => Transformable (Attribute v n) #

TAttributes are transformed directly, MAttributes have their local scale multiplied by the average scale of the transform. Plain Attributes are unaffected.

Instance details

Defined in Diagrams.Core.Style

Methods

transform :: Transformation (V (Attribute v n)) (N (Attribute v n)) -> Attribute v n -> Attribute v n #

Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') # 
Instance details

Defined in Diagrams.Core.Style

Methods

each :: Traversal (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') #

type N (Attribute v n) # 
Instance details

Defined in Diagrams.Core.Style

type N (Attribute v n) = n
type V (Attribute v n) # 
Instance details

Defined in Diagrams.Core.Style

type V (Attribute v n) = v

Attributes prisms

_Attribute :: AttributeClass a => Prism' (Attribute v n) a #

Prism onto an Attribute.

_MAttribute :: (AttributeClass a, Typeable n) => Prism' (Attribute v n) (Measured n a) #

Prism onto an MAttribute.

_TAttribute :: (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Prism' (Attribute v n) a #

Prism onto a TAttribute.

Attributes utilities

unwrapAttribute :: AttributeClass a => Attribute v n -> Maybe a #

Unwrap an unknown Attribute type, performing a dynamic (but safe) check on the type of the result. If the required type matches the type of the attribute, the attribute value is returned wrapped in Just; if the types do not match, Nothing is returned.

Measured attributes cannot be extrated from this function until they have been unmeasured with unmeasureAttribute. If you want a measured attibute use the _MAttribute prism.

unmeasureAttribute :: Num n => n -> n -> Attribute v n -> Attribute v n #

Turn an MAttribute into an Attribute using the given global and normalized scale.

attributeType :: Attribute v n -> TypeRep #

Type of an attribute that is stored with a style. Measured attributes return the type as if it where unmeasured.

Styles

A Style is a heterogeneous collection of attributes, containing at most one attribute of any given type. This is also based on ideas stolen from xmonad, specifically xmonad's implementation of user-extensible state.

newtype Style v n #

A Style is a heterogeneous collection of attributes, containing at most one attribute of any given type.

Constructors

Style (HashMap TypeRep (Attribute v n)) 
Instances
Show (Style v n) #

Show the attributes in the style.

Instance details

Defined in Diagrams.Core.Style

Methods

showsPrec :: Int -> Style v n -> ShowS #

show :: Style v n -> String #

showList :: [Style v n] -> ShowS #

Typeable n => Semigroup (Style v n) #

Combine a style by combining the attributes; if the two styles have attributes of the same type they are combined according to their semigroup structure.

Instance details

Defined in Diagrams.Core.Style

Methods

(<>) :: Style v n -> Style v n -> Style v n #

sconcat :: NonEmpty (Style v n) -> Style v n #

stimes :: Integral b => b -> Style v n -> Style v n #

Typeable n => Monoid (Style v n) #

The empty style contains no attributes.

Instance details

Defined in Diagrams.Core.Style

Methods

mempty :: Style v n #

mappend :: Style v n -> Style v n -> Style v n #

mconcat :: [Style v n] -> Style v n #

Ixed (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Methods

ix :: Index (Style v n) -> Traversal' (Style v n) (IxValue (Style v n)) #

At (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Methods

at :: Index (Style v n) -> Lens' (Style v n) (Maybe (IxValue (Style v n))) #

Wrapped (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Associated Types

type Unwrapped (Style v n) :: Type #

Methods

_Wrapped' :: Iso' (Style v n) (Unwrapped (Style v n)) #

(Additive v, Traversable v, Floating n) => Transformable (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Methods

transform :: Transformation (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n #

Typeable n => HasStyle (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n #

Action (Style v n) m #

Styles have no action on other monoids.

Instance details

Defined in Diagrams.Core.Style

Methods

act :: Style v n -> m -> m #

Rewrapped (Style v n) (Style v' n') # 
Instance details

Defined in Diagrams.Core.Style

Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') # 
Instance details

Defined in Diagrams.Core.Style

Methods

each :: Traversal (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') #

type Index (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

type Index (Style v n) = TypeRep
type IxValue (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

type IxValue (Style v n) = Attribute v n
type Unwrapped (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

type N (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

type N (Style v n) = n
type V (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

type V (Style v n) = v

Making styles

attributeToStyle :: Attribute v n -> Style v n #

Turn an attribute into a style. An easier way to make a style is to use the monoid instance and apply library functions for applying that attribute:

myStyle = mempty # fc blue :: Style V2 Double

Extracting attibutes from styles

getAttr :: forall a v n. AttributeClass a => Style v n -> Maybe a #

Extract an attribute from a style of a particular type. If the style contains an attribute of the requested type, it will be returned wrapped in Just; otherwise, Nothing is returned.

Trying to extract a measured attibute will fail. It either has to be unmeasured with unmeasureAttrs or use the atMAttr lens.

unmeasureAttrs :: Num n => n -> n -> Style v n -> Style v n #

Replace all MAttributes with Attributes using the global and normalized scales.

Attibute lenses

atAttr :: AttributeClass a => Lens' (Style v n) (Maybe a) #

Lens onto a plain attribute of a style.

atMAttr :: (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a)) #

Lens onto a measured attribute of a style.

atTAttr :: (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a) #

Lens onto a transformable attribute of a style.

Applying styles

applyAttr :: (AttributeClass a, HasStyle d) => a -> d -> d #

Apply an attribute to an instance of HasStyle (such as a diagram or a style). If the object already has an attribute of the same type, the new attribute is combined on the left with the existing attribute, according to their semigroup structure.

applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n a -> d -> d #

Apply a measured attribute to an instance of HasStyle (such as a diagram or a style). If the object already has an attribute of the same type, the new attribute is combined on the left with the existing attribute, according to their semigroup structure.

applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d #

Apply a transformable attribute to an instance of HasStyle (such as a diagram or a style). If the object already has an attribute of the same type, the new attribute is combined on the left with the existing attribute, according to their semigroup structure.

class HasStyle a where #

Type class for things which have a style.

Methods

applyStyle :: Style (V a) (N a) -> a -> a #

Apply a style by combining it (on the left) with the existing style.

Instances
HasStyle a => HasStyle [a] # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V [a]) (N [a]) -> [a] -> [a] #

(HasStyle a, Ord a) => HasStyle (Set a) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (Set a)) (N (Set a)) -> Set a -> Set a #

HasStyle b => HasStyle (a -> b) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (a -> b)) (N (a -> b)) -> (a -> b) -> a -> b #

(HasStyle a, HasStyle b, V a ~ V b, N a ~ N b) => HasStyle (a, b) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (a, b)) (N (a, b)) -> (a, b) -> (a, b) #

HasStyle a => HasStyle (Map k a) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (Map k a)) (N (Map k a)) -> Map k a -> Map k a #

HasStyle b => HasStyle (Measured n b) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (Measured n b)) (N (Measured n b)) -> Measured n b -> Measured n b #

Typeable n => HasStyle (Style v n) # 
Instance details

Defined in Diagrams.Core.Style

Methods

applyStyle :: Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n #

(Metric v, OrderedField n, Semigroup m) => HasStyle (QDiagram b v n m) # 
Instance details

Defined in Diagrams.Core.Types

Methods

applyStyle :: Style (V (QDiagram b v n m)) (N (QDiagram b v n m)) -> QDiagram b v n m -> QDiagram b v n m #