Allow more control over the dimensions
This commit is contained in:
parent
6e2873ece1
commit
197dc99058
30
Diagram.hs
30
Diagram.hs
@ -13,27 +13,41 @@ instance Def DiagProp where
|
|||||||
|
|
||||||
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
|
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
|
||||||
data DiagProp = MkProp {
|
data DiagProp = MkProp {
|
||||||
-- |Get the thickness of the dot.
|
-- |The thickness of the dots.
|
||||||
t :: Double
|
t :: Double,
|
||||||
|
-- |The dimensions of the x-axis.
|
||||||
|
dX :: (Double, Double),
|
||||||
|
-- |The dimensions of the y-axis.
|
||||||
|
dY :: (Double, Double)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- |The default properties of the Diagram.
|
-- |The default properties of the Diagram.
|
||||||
defaultProp :: DiagProp
|
defaultProp :: DiagProp
|
||||||
defaultProp = MkProp 2
|
defaultProp = MkProp 2 (0,500) (0,500)
|
||||||
|
|
||||||
|
|
||||||
-- |Create the Diagram from the VTable.
|
-- |Create the Diagram from the VTable.
|
||||||
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
|
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
|
||||||
diagFromVTable prop vt
|
diagFromVTable prop vt
|
||||||
= position (zip (map mkPoint . filter (inRange 0 500) $ vt)
|
= position (zip (map mkPoint . filter (inRange (dX prop) (dY prop)) $ vt)
|
||||||
(repeat dot)) # moveTo (p2(-250, -250))
|
(repeat dot)) # moveTo (p2(xOffset, yOffset))
|
||||||
`atop` hrule 500 # centerX # moveTo (p2(0, -250))
|
`atop` hrule (xuD - xlD) # centerX # moveTo (p2(0, yOffset))
|
||||||
`atop` vrule 500 # centerY # moveTo (p2(-250, 0))
|
`atop` vrule (yuD - ylD) # centerY # moveTo (p2(xOffset, 0))
|
||||||
`atop` square 550 # lwG 0.00 # bg white
|
`atop` rect (xuD - xlD + 50)
|
||||||
|
(yuD - ylD + 50) # lwG 0.00 # bg white
|
||||||
where dot = (circle $
|
where dot = (circle $
|
||||||
t prop :: Diagram Cairo R2) # fc black
|
t prop :: Diagram Cairo R2) # fc black
|
||||||
mkPoint (x,y) = p2 (x,y)
|
mkPoint (x,y) = p2 (x,y)
|
||||||
|
xlD = fst $ dX prop
|
||||||
|
xuD = snd $ dX prop
|
||||||
|
ylD = fst $ dY prop
|
||||||
|
yuD = snd $ dY prop
|
||||||
|
-- 'Diagrams' sets (0,0) to be in the middle of the
|
||||||
|
-- drawing area, so we need to shift it depending
|
||||||
|
-- on the given dimensions.
|
||||||
|
xOffset = (negate xlD / 2) - (xuD / 2)
|
||||||
|
yOffset = (negate ylD / 2) - (yuD / 2)
|
||||||
|
|
||||||
|
|
||||||
-- |Create the Diagram from a String which is supposed to be the contents
|
-- |Create the Diagram from a String which is supposed to be the contents
|
||||||
|
15
Util.hs
15
Util.hs
@ -1,14 +1,15 @@
|
|||||||
module Util where
|
module Util where
|
||||||
|
|
||||||
|
|
||||||
-- |Checks whether the Coordinates are in a given range.
|
-- |Checks whether the Coordinates are in a given dimension.
|
||||||
inRange :: Double -- ^ min
|
inRange :: (Double, Double) -- ^ X dimension
|
||||||
-> Double -- ^ max
|
-> (Double, Double) -- ^ Y dimension
|
||||||
-> (Double, Double) -- ^ Coordinates to check
|
-> (Double, Double) -- ^ Coordinates
|
||||||
-> Bool -- ^ result
|
-> Bool -- ^ result
|
||||||
inRange min' max' (x, y)
|
inRange (xlD, xuD) (ylD, yuD) (x,y)
|
||||||
| x <= max' && x >= min' && y <= max' && y >= min' = True
|
| x <= xuD && x >= xlD &&
|
||||||
| otherwise = False
|
y <= yuD && y >= ylD = True
|
||||||
|
| otherwise = False
|
||||||
|
|
||||||
|
|
||||||
-- |Compare the extension of a file with the given String.
|
-- |Compare the extension of a file with the given String.
|
||||||
|
Loading…
Reference in New Issue
Block a user