dia-base 0.1 → 0.1.1
raw patch · 3 files changed
+59/−22 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Graphics/Diagrams.hs +51/−17
- Graphics/Diagrams/Types.hs +5/−4
- dia-base.cabal +3/−1
Graphics/Diagrams.hs view
@@ -1,16 +1,24 @@ -- | Diagrams user API module Graphics.Diagrams - ( Point+ ( -- * Points+ Point , (*.), (.*.), (.+.), (.-.)+ -- * Colors , Color , color, rgb , red, green, blue, black, white, gray, yellow+ -- * Diagrams , Diagram- , rect, rectangle, circle, polygon, (>-<), (~~), polyline- , textFrom, textTo, textAt, fontFamily, link+ -- ** Primitives+ , empty, rect, rectangle, circle, (>-<), (~~), polyline, polygon+ -- ** Texts+ , textFrom, textTo, textAt+ -- ** Transformations , move, rotate, scale, scaleXY, clip- , fill, stroke, strokeWidth- , union, (<|>), empty+ -- ** Styles+ , fill, stroke, strokeWidth, fontFamily, link+ -- ** Combining diagrams+ , union, (<|>) , pack ) where @@ -26,23 +34,29 @@ -------------------- +-- | empty diagram empty :: Diagram empty = EmptyDiagram +-- | line segment (>-<), (~~), line :: Point -> Point -> Diagram (>-<) = line (~~) = line line a b = polyline [a,b] +-- | rectangle given with width and height rect :: Double -> Double -> Diagram rect = Rect ++-- | rectangle given with two opposite corners rectangle :: Point -> Point -> Diagram-rectangle (a1,a2) (b1,b2) = rect (b1-a1) (b2-a2) `move` (a1+(b1-a1)/2, a2+(b2-a2)/2)+rectangle (a1,a2) (b1,b2) = rect (abs (b1-a1)) (abs (b2-a2)) `move` (a1+(b1-a1)/2, a2+(b2-a2)/2) --dot :: Diagram --dot = circle 0.5 `strokeWidth` 0 `fill` black +-- | circle with radius circle :: Double -> Diagram circle = Circle @@ -50,60 +64,82 @@ polygon = Polyline True polyline = Polyline False +-- | text in origo text :: Position -> String -> Diagram text x = TransformMatrix 0.1 0 0 (-0.1) 0 0 . Text x -textAt, textFrom, textTo :: String -> Point -> Diagram+-- | text; middle of text is fixed+textAt :: String -> Point -> Diagram textAt t x = text Middle t `move` x++-- | text; beginning of text is fixed+textFrom :: String -> Point -> Diagram textFrom t x = text Start t `move` x++-- | text; end of text is fixed+textTo :: String -> Point -> Diagram textTo t x = text End t `move` x +-- | set font family fontFamily :: Diagram -> String -> Diagram fontFamily = flip FontFamily +-- | add an html link link :: Diagram -> String -> Diagram link = flip Link -pack :: Diagram -> (Diagram -> Diagram) -> Diagram-pack = Pack-+-- | clip a rectangle region (give lower-left and upper-right corners) clip :: Point -> Point -> Diagram -> Diagram clip = Clip -(<|>) :: Diagram -> Diagram -> Diagram-(<|>) = Overlay - move :: Diagram -> Point -> Diagram x `move` p = Move p x +-- | rotate (degree) rotate :: Diagram -> Double -> Diagram x `rotate` d = Rotate d x +-- | scale differently at x and y axes scale :: Diagram -> Double -> Diagram x `scale` t = Scale t x scaleXY :: Diagram -> (Double, Double) -> Diagram d `scaleXY` (x, y) = ScaleXY x y d +-- | fill with color fill :: Diagram -> Color -> Diagram x `fill` c = Fill c x +-- | set stroke color stroke :: Diagram -> Color -> Diagram x `stroke` c = Stroke c x +-- | set stroke width strokeWidth :: Diagram -> Double -> Diagram x `strokeWidth` c = StrokeWidth c x +-- | overlay; the second diagram is over the first one+(<|>) :: Diagram -> Diagram -> Diagram+(<|>) = Overlay++-- | overlay generalized to several diagrams union :: [Diagram] -> Diagram union = foldr Overlay EmptyDiagram +-- | pack a diagram; (@pack d f@) is the more efficient version of (@let v=d in f v@).+pack :: Diagram -> (Diagram -> Diagram) -> Diagram+pack = Pack ++ ------------------------- +-- | named color color :: String -> Color color = Color +-- | RGB color (components are between 0 and 1) rgb :: Double -> Double -> Double -> Color rgb = RGB @@ -117,10 +153,7 @@ yellow = color "yellow" --- type Point = (Double, Double)---- | Point type as defined in the diagrams package--- Scalar multiplication.+-- | Scalar multiplication. (*.) :: Double -> Point -> Point s *. (x,y) = (s*x, s*y) @@ -129,6 +162,7 @@ (x1,y1) .+. (x2,y2) = (x1 + x2, y1 + y2) (x1,y1) .*. (x2,y2) = (x1 * x2, y1 * y2) a .-. b = a .+. ((-1) *. b)+
Graphics/Diagrams/Types.hs view
@@ -7,6 +7,7 @@ ----------------------- +-- | Point type as defined in the diagrams package type Point = (Double, Double) -- | Diagram data type@@ -20,7 +21,7 @@ | Move Point Diagram -- ^ move | Scale Double Diagram -- ^ scale | ScaleXY Double Double Diagram -- ^ scale differently at x and y axes- | Rotate Double Diagram -- ^ rotate (radian)+ | Rotate Double Diagram -- ^ rotate (degree) | TransformMatrix Double Double Double Double Double Double Diagram -- ^ used internally | Clip Point Point Diagram -- ^ clip a rectangle region (lower-left and upper-right corners) @@ -30,9 +31,9 @@ -- | StrokeOpacity Double Diagram -- ^ set stroke opacity | StrokeWidth Double Diagram -- ^ set stroke width | FontFamily String Diagram -- ^ set font family- | Link String Diagram -- ^ add a html link+ | Link String Diagram -- ^ add an html link - | Overlay Diagram Diagram -- ^ overlay (the second is diagram over the first one)+ | Overlay Diagram Diagram -- ^ overlay (the second diagram is over the first one) | Pack Diagram (Diagram -> Diagram) -- ^ pack a diagram (kind of let-construct to save resources) | Group Diagram Int Diagram -- ^ used internally@@ -47,7 +48,7 @@ -- | Text positions data Position- = Start -- ^ begginning of text is fixed+ = Start -- ^ beginning of text is fixed | Middle -- ^ middle of text is fixed | End -- ^ end of text is fixed deriving (Eq, Ord, Show, Data, Typeable)
dia-base.cabal view
@@ -1,5 +1,5 @@ name: dia-base-version: 0.1+version: 0.1.1 category: Graphics, Education synopsis: An EDSL for teaching Haskell with diagrams - data types description:@@ -9,6 +9,8 @@ See also the dia-functions package. . For exaples see <http://pnyf.inf.elte.hu/fp/Diagrams_en.xml>+ .+ Changes since 0.1: more documentation stability: alpha license: BSD3 license-file: LICENSE