diagrams-core-1.5.1.1: Core libraries for diagrams EDSL

Copyright | (c) 2011-2015 diagrams-core team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None
Language | Haskell2010

Diagrams.Core.Style

Contents

- Attributes
  - Attributes prisms
  - Attributes utilities
- Styles
  - Making styles
  - Extracting attibutes from styles
  - Attibute lenses
  - Applying styles

Description

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

Synopsis

- class (Typeable a, Semigroup a) => AttributeClass a
- data Attribute (v :: Type -> Type) n where
  - Attribute :: forall a (v :: Type -> Type) n. AttributeClass a => a -> Attribute v n
  - MAttribute :: forall a n (v :: Type -> Type). AttributeClass a => Measured n a -> Attribute v n
  - TAttribute :: forall a (v :: Type -> Type) n. (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n
- _Attribute :: forall a (v :: Type -> Type) n. AttributeClass a => Prism' (Attribute v n) a
- _MAttribute :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Prism' (Attribute v n) (Measured n a)
- _TAttribute :: forall a (v :: Type -> Type) n. (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Prism' (Attribute v n) a
- unwrapAttribute :: forall a (v :: Type -> Type) n. AttributeClass a => Attribute v n -> Maybe a
- unmeasureAttribute :: forall n (v :: Type -> Type). Num n => n -> n -> Attribute v n -> Attribute v n
- attributeType :: forall (v :: Type -> Type) n. Attribute v n -> TypeRep
- newtype Style (v :: Type -> Type) n = Style (HashMap TypeRep (Attribute v n))
- attributeToStyle :: forall (v :: Type -> Type) n. Attribute v n -> Style v n
- getAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Style v n -> Maybe a
- unmeasureAttrs :: forall n (v :: Type -> Type). Num n => n -> n -> Style v n -> Style v n
- atAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Lens' (Style v n) (Maybe a)
- atMAttr :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a))
- atTAttr :: forall a (v :: Type -> Type) n. (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a)
- applyAttr :: (AttributeClass a, HasStyle d) => a -> d -> d
- applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n a -> d -> d
- applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d
- class HasStyle a where
  - applyStyle :: Style (V a) (N a) -> a -> a

# 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 :: Type -> Type) 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 :: forall a (v :: Type -> Type) n. AttributeClass a => a -> Attribute v n |
MAttribute :: forall a n (v :: Type -> Type). AttributeClass a => Measured n a -> Attribute v n |
TAttribute :: forall a (v :: Type -> Type) n. (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n |

#### Instances

Instances details

(Additive v, Traversable v, Floating n) => Transformable (Attribute v n) Source # | `TAttribute`s are transformed directly, `MAttribute`s have their local scale multiplied by the average scale of the transform. Plain `Attribute`s 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 Source #
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.
Instance details Defined in Diagrams.Core.Style Methods (<>) :: Attribute v n -> Attribute v n -> Attribute v n Source # sconcat :: NonEmpty (Attribute v n) -> Attribute v n Source # stimes :: Integral b => b -> Attribute v n -> Attribute v n Source #
Show (Attribute v n) Source # | 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 Source # show :: Attribute v n -> String Source # showList :: [Attribute v n] -> ShowS Source #
Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source # |
Instance details Defined in Diagrams.Core.Style Methods each :: Traversal (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source #
type N (Attribute v n) Source # |
Instance details Defined in Diagrams.Core.Style type N (Attribute v n) = n
type V (Attribute v n) Source # |
Instance details Defined in Diagrams.Core.Style type V (Attribute v n) = v

## Attributes prisms

_Attribute :: forall a (v :: Type -> Type) n. AttributeClass a => Prism' (Attribute v n) a Source #

Prism onto an `Attribute`.

_MAttribute :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Prism' (Attribute v n) (Measured n a) Source #

Prism onto an `MAttribute`.

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

Prism onto a `TAttribute`.

## Attributes utilities

unwrapAttribute :: forall a (v :: Type -> Type) n. 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 :: forall n (v :: Type -> Type). 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 :: forall (v :: Type -> Type) n. 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 :: Type -> Type) 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

Instances details

Typeable n => HasStyle (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n Source #
(Additive v, Traversable v, Floating n) => Transformable (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style Methods transform :: Transformation (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n Source #
Typeable n => Monoid (Style v n) Source # | The empty style contains no attributes.
Instance details Defined in Diagrams.Core.Style Methods mempty :: Style v n Source # mappend :: Style v n -> Style v n -> Style v n Source # mconcat :: [Style v n] -> Style v n Source #
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.
Instance details Defined in Diagrams.Core.Style Methods (<>) :: Style v n -> Style v n -> Style v n Source # sconcat :: NonEmpty (Style v n) -> Style v n Source # stimes :: Integral b => b -> Style v n -> Style v n Source #
Show (Style v n) Source # | Show the attributes in the style.
Instance details Defined in Diagrams.Core.Style Methods showsPrec :: Int -> Style v n -> ShowS Source # show :: Style v n -> String Source # showList :: [Style v n] -> ShowS Source #
At (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style Methods at :: Index (Style v n) -> Lens' (Style v n) (Maybe (IxValue (Style v n))) Source #
Ixed (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style Methods ix :: Index (Style v n) -> Traversal' (Style v n) (IxValue (Style v n)) Source #
Wrapped (Style v n) Source # |

Instance details

Defined in Diagrams.Core.Style

Associated Types

type Unwrapped (Style v n) |
Instance details Defined in Diagrams.Core.Style type Unwrapped (Style v n) = HashMap TypeRep (Attribute v n)

Methods

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

Action (Style v n) m Source # | Styles have no action on other monoids.
Instance details Defined in Diagrams.Core.Style Methods act :: Style v n -> m -> m Source #
Rewrapped (Style v n) (Style v' n') Source # |
Instance details Defined in Diagrams.Core.Style
Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source # |
Instance details Defined in Diagrams.Core.Style Methods each :: Traversal (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') Source #
type N (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style type N (Style v n) = n
type V (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style type V (Style v n) = v
type Index (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style type Index (Style v n) = TypeRep
type IxValue (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style type IxValue (Style v n) = Attribute v n
type Unwrapped (Style v n) Source # |
Instance details Defined in Diagrams.Core.Style type Unwrapped (Style v n) = HashMap TypeRep (Attribute v n)

## Making styles

attributeToStyle :: forall (v :: Type -> Type) n. 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 :: Type -> Type) 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 :: forall n (v :: Type -> Type). Num n => n -> n -> Style v n -> Style v n Source #

Replace all `MAttribute`s with `Attribute`s using the `global` and `normalized` scales.

## Attibute lenses

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

Lens onto a plain attribute of a style.

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

Lens onto a measured attribute of a style.

atTAttr :: forall a (v :: Type -> Type) n. (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.

Methods

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

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

#### Instances

Instances details

(HasStyle a, Ord a) => HasStyle (Set a) Source # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V (Set a)) (N (Set a)) -> Set a -> Set a Source #
HasStyle a => HasStyle [a] Source # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V [a]) (N [a]) -> [a] -> [a] Source #
HasStyle a => HasStyle (Map k a) Source # |
Instance details Defined in Diagrams.Core.Style 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 # |
Instance details Defined in Diagrams.Core.Style 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 # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n Source #
(HasStyle a, HasStyle b, V a ~ V b, N a ~ N b) => HasStyle (a, b) Source # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V (a, b)) (N (a, b)) -> (a, b) -> (a, b) Source #
HasStyle b => HasStyle (a -> b) Source # |
Instance details Defined in Diagrams.Core.Style Methods applyStyle :: Style (V (a -> b)) (N (a -> b)) -> (a -> b) -> a -> b Source #
(Metric v, OrderedField n, Semigroup m) => HasStyle (QDiagram b v n m) Source # |
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 Source #