diagrams-core-1.4: 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 Source #

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 Source #

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) Source #

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

Methods

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

show :: Attribute v n -> String #

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

Typeable * n => Semigroup (Attribute v n) Source #

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.

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) Source #

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

Methods

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

Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source # 

Methods

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

type N (Attribute v n) Source # 
type N (Attribute v n) = n
type V (Attribute v n) Source # 
type V (Attribute v n) = v

Attributes prisms

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

Prism onto a TAttribute.

Attributes utilities

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

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 Source #

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

attributeType :: Attribute v n -> TypeRep Source #

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 Source #

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) Source #

Show the attributes in the style.

Methods

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

show :: Style v n -> String #

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

Typeable * n => Semigroup (Style v n) Source #

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.

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) Source #

The empty style contains no attributes.

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) Source # 

Methods

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

At (Style v n) Source # 

Methods

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

Wrapped (Style v n) Source # 

Associated Types

type Unwrapped (Style v n) :: * #

Methods

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

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

Methods

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

Typeable * n => HasStyle (Style v n) Source # 

Methods

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

Action (Style v n) m Source #

Styles have no action on other monoids.

Methods

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

Rewrapped (Style v n) (Style v' n') Source # 
Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source # 

Methods

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

type Index (Style v n) Source # 
type Index (Style v n) = TypeRep
type IxValue (Style v n) Source # 
type IxValue (Style v n) = Attribute v n
type Unwrapped (Style v n) Source # 
type N (Style v n) Source # 
type N (Style v n) = n
type V (Style v n) Source # 
type V (Style v n) = v

Making styles

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

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 Source #

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 Source #

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

Attibute lenses

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

Lens onto a plain attribute of a style.

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

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) Source #

Lens onto a transformable attribute of a style.

Applying styles

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

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 Source #

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 Source #

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 Source #

Type class for things which have a style.

Minimal complete definition

applyStyle

Methods

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

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

Instances

HasStyle a => HasStyle [a] Source # 

Methods

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

(HasStyle a, Ord a) => HasStyle (Set a) Source # 

Methods

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

HasStyle b => HasStyle (a -> b) Source # 

Methods

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

(HasStyle a, HasStyle b, (~) (* -> *) (V a) (V b), (~) * (N a) (N b)) => HasStyle (a, b) Source # 

Methods

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

HasStyle a => HasStyle (Map k a) Source # 

Methods

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

HasStyle b => HasStyle (Measured n b) Source # 

Methods

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

Typeable * n => HasStyle (Style v n) Source # 

Methods

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

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

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 Source #