------------------------------------------------------------------------------- |-- Module : Graphics.Rendering.Diagrams.Attributes-- Copyright : (c) Brent Yorgey 2008-- License : BSD-style (see LICENSE)-- Maintainer : byorgey@gmail.com-- Stability : experimental-- Portability : portable---- Attributes which can be added as annotations to a 'Diagram',-- implemented via instances of 'AttrClass'.-------------------------------------------------------------------------------moduleGraphics.Rendering.Diagrams.Attributes(defaultAttributes,fillColor,fc,lineColor,lc,lineWidth,lw,lineCap,C.LineCap(..),lineJoin,C.LineJoin(..),dashing,typeface,tf,stretch,scale,scaleX,scaleY,translate,translateX,translateY,rotate,rotateR)whereimportGraphics.Rendering.Diagrams.TypesimportqualifiedGraphics.Rendering.CairoasC-- Fill color ------------------------ | Specify the default fill color for a 'Diagram'.newtypeFill=FillSomeColorinstanceAttrClassFillwhererenderAttr(Fill(SomeColorf))=return(setEnvFillColorf)-- | Draw a diagram using the given fill color. Note that the new-- color only applies to parts of the diagram which are not-- otherwise colored; subdiagrams which already have an explicit-- fill color will not be affected. The default fill color is-- completely transparent.fillColor::Colorc=>c->Diagram->DiagramfillColor=Ann.Attr.Fill.SomeColor-- | 'fc' is provided as a convenient short synonym for 'fillColor'.fc::Colorc=>c->Diagram->Diagramfc=fillColor-- Stroke color ------------------------ | Specify the default stroke color for a 'Diagram'.newtypeStroke=StrokeSomeColorinstanceAttrClassStrokewhererenderAttr(Stroke(SomeColorsc))=return(setEnvStrokeColorsc)-- | Draw a diagram using the given color for lines. Note that the new-- color only applies to parts of the diagram which are not-- otherwise colored; subdiagrams which already have an explicit-- line color will not be affected. The default line color is black.lineColor::Colorc=>c->Diagram->DiagramlineColor=Ann.Attr.Stroke.SomeColor-- | 'lc' is provided as a convenient short synonym for 'lineColor'.lc::Colorc=>c->Diagram->Diagramlc=lineColor-- Stroke width -------------------------------- | The stroke width to be used in drawing lines or shape outlines.-- Note that the stroke width is measured in /device coordinates/,-- so a stroke width of a certain size will look the same under any-- uniform scaling. Under non-uniform (i.e. different in the x and-- y axes) scaling, however, strokes may look distorted.newtypeStrokeWidth=StrokeWidthDoublederiving(Eq,Show,Read)instanceAttrClassStrokeWidthwhererenderAttr(StrokeWidthw)=return(setEnvStrokeWidthw)-- | Draw shape outlines and lines with the given width. Note that-- the line width is invariant under uniform scaling, although under-- non-uniform scaling (scaling by different amounts in the x and y-- axes) lines can become distorted. The default line width is 1.lineWidth::Double->Diagram->DiagramlineWidth=Ann.Attr.StrokeWidth-- | 'lw' is provided as a convenient short synonym for 'lineWidth'.lw::Double->Diagram->Diagramlw=lineWidth-- Fonts ------------------------------- | Set the typeface for a text diagramnewtypeTypeface=TypefaceStringderiving(Eq,Show,Read)instanceAttrClassTypefacewhererenderAttr(Typefacefontname)=c$C.selectFontFacefontnameC.FontSlantNormalC.FontWeightNormal>>returnid-- | Change the default typeface to one named.typeface::String->Diagram->Diagramtypefacefontname=Ann(Attr(Typefacefontname))-- | Convenience function to change the typeface.tf::String->Diagram->Diagramtf=typeface-- Rotate ------------------------------ | Rotate a diagram clockwise through a certain number of radians.newtypeRotate=RotateDoublederiving(Eq,Show,Read)instanceAttrClassRotatewhererenderAttr(Rotated)=c$C.rotated>>returnid-- | @rotateR r@ rotates a diagram clockwise by @r@ radians.rotateR::Double->Diagram->DiagramrotateRr=Ann(Attr(Rotater))-- | @rotate f@ rotates a diagram clockwise by fraction @f@ of a-- complete revolution. @rotate f@ is equivalent to @rotateR-- (2*pi*f)@.rotate::Double->Diagram->Diagramrotatef=rotateR(2*pi*f)-- Translate ----------------------------- | Translate a diagram by the given offset.newtypeTranslate=TranslatePointderiving(Eq,Show,Read)instanceAttrClassTranslatewhererenderAttr(Translate(x,y))=c$C.translatexy>>returnid-- | Translate a diagram by the given relative offsets in the x and y-- directions. Note that the positive x-axis is to the right, while-- the positive y-axis points downwards.translate::Double->Double->Diagram->Diagramtranslate00=idtranslatedxdy=Ann(Attr(Translate(dx,dy)))-- | Translate a diagram along the x-axis only. @translateX x@ is-- equivalent to @translate x 0@.translateX::Double->Diagram->DiagramtranslateXdx=translatedx0-- | Translate a diagram along the y-axis only. @translateY y@ is-- equivalent to @translate 0 y@.translateY::Double->Diagram->DiagramtranslateYdy=translate0dy-- Scale ---------------------------------- | Scale a diagram by the given scaling factors in the x and y axes,-- respectively.newtypeScale=ScalePointderiving(Eq,Show,Read)instanceAttrClassScalewhereattrSize(Scalek)s=k.*.srenderAttr(Scale(x,y))=c$C.scalexy>>returnid-- | Stretch a diagram by a separate scaling factor for each axis.-- @stretch w h@ scales by a factor of @w@ in the x direction and-- a factor of @h@ in the y direction.stretch::Double->Double->Diagram->Diagramstretchsxsy=Ann(Attr(Scale(sx,sy)))-- | Scale by the same scaling factor in both dimensions, so the diagram-- retains its aspect ratio.scale::Double->Diagram->Diagramscale1=idscales=stretchss-- | Scale a diagram along the x-axis only. @scaleX s@ is equivalent-- to @stretch s 1@.scaleX::Double->Diagram->DiagramscaleXsx=stretchsx1-- | Scale a diagram along the y-axis only. @scaleY s@ is equivalent-- to @stretch 1 s@.scaleY::Double->Diagram->DiagramscaleYsy=stretch1sy-- Stroke styles ----------------------------------newtypeLCap=LCapC.LineCapinstanceAttrClassLCapwhererenderAttr(LCaplcap)=c$C.setLineCaplcap>>returnid-- | Set the line cap style. Valid values for 'LineCap' are-- @LineCapButt@, @LineCapRound@, and @LineCapSquare@.lineCap::C.LineCap->Diagram->DiagramlineCap=Ann.Attr.LCapnewtypeLJoin=LJoinC.LineJoininstanceAttrClassLJoinwhererenderAttr(LJoinlj)=c$C.setLineJoinlj>>returnid-- | Set the line join style. Valid values for 'LineJoin' are-- @LineJoinMiter@, @LineJoinRound@, and @LineJoinBevel@.lineJoin::C.LineJoin->Diagram->DiagramlineJoin=Ann.Attr.LJoindataDashing=Dashing[Double]DoubleinstanceAttrClassDashingwhererenderAttr(Dashingdsoffs)=c$C.setDashdsoffs>>returnid-- | Set the line dashing pattern.dashing::[Double]-- ^ a list specifying alternate lengths of on-- and off portions of the stroke. The empty-- list indicates no dashing.->Double-- ^ an offset into the dash pattern at which the-- stroke should start->Diagram->Diagramdashingdsoffs=Ann(Attr(Dashingdsoffs))-- | Apply all the default attributes to a 'Diagram'.defaultAttributes::Diagram->DiagramdefaultAttributes=casedefaultDiaRenderEnvof(DREnv(SomeColorfillC)(SomeColorstrokeC)strokeW)->lcstrokeC.lwstrokeW.lineCapC.LineCapButt.lineJoinC.LineJoinMiter.dashing[]0.fcfillC