2014-10-06 21:14:23 +00:00
|
|
|
{-# OPTIONS_HADDOCK ignore-exports #-}
|
|
|
|
|
2014-10-10 15:40:08 +00:00
|
|
|
module Graphics.Diagram.Plotter where
|
2014-09-30 22:05:29 +00:00
|
|
|
|
2014-10-14 19:24:21 +00:00
|
|
|
import Data.Monoid
|
|
|
|
import Diagrams.Prelude hiding ((<>))
|
2014-12-03 21:02:42 +00:00
|
|
|
import Graphics.Diagram.Core
|
2014-12-02 18:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- |Creates a Diagram that shows the coordinates from the points
|
|
|
|
-- as dots. The points and thickness of the dots can be controlled
|
|
|
|
-- via DiagProp.
|
|
|
|
coordPoints :: Diag
|
2014-12-07 03:41:45 +00:00
|
|
|
coordPoints = Diag f
|
2014-12-02 18:00:50 +00:00
|
|
|
where
|
2014-12-07 03:41:45 +00:00
|
|
|
f _ [] = mempty
|
|
|
|
f p [vt] = drawP vt (dotSize p) # fc black # lc black
|
|
|
|
f p vts = drawP (concat vts) (dotSize p) # fc black # lc black
|
2014-10-06 19:11:28 +00:00
|
|
|
|
|
|
|
|
2014-10-10 13:34:38 +00:00
|
|
|
-- |Show coordinates as text above all points.
|
2014-10-10 13:03:12 +00:00
|
|
|
coordPointsText :: Diag
|
2014-12-07 03:33:45 +00:00
|
|
|
coordPointsText = Diag f
|
2014-10-10 13:03:12 +00:00
|
|
|
where
|
2014-12-07 03:33:45 +00:00
|
|
|
f _ [] = mempty
|
|
|
|
f p [vt] = drawT vt p
|
|
|
|
f p vts = drawT (concat vts) p
|
2014-10-25 13:40:10 +00:00
|
|
|
drawT [] _ = mempty
|
|
|
|
drawT vt p
|
2014-12-03 00:36:12 +00:00
|
|
|
| showCoordText p = position $ zip vt (pointToTextCoord <$> vt)
|
2014-11-16 03:37:34 +00:00
|
|
|
# translate (r2 (0, 10))
|
2014-10-25 13:40:10 +00:00
|
|
|
| otherwise = mempty
|
2014-10-10 13:03:12 +00:00
|
|
|
|
|
|
|
|
2014-10-06 19:11:28 +00:00
|
|
|
-- |Creates a Diagram that shows an XAxis which is bound
|
2014-11-15 23:49:20 +00:00
|
|
|
-- by the dimensions given in xDimension from DiagProp.
|
2014-10-09 15:19:58 +00:00
|
|
|
xAxis :: Diag
|
2014-10-09 22:19:05 +00:00
|
|
|
xAxis =
|
2014-11-16 15:45:51 +00:00
|
|
|
Diag hRule
|
|
|
|
<> Diag segments
|
|
|
|
<> Diag labels
|
2014-10-06 19:11:28 +00:00
|
|
|
where
|
2014-12-03 00:36:12 +00:00
|
|
|
hRule p _ = arrowAt (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p))
|
|
|
|
(r2 (diagWidth p, 0))
|
|
|
|
segments p _ = hcat' (with & sep .~ squareSize p)
|
|
|
|
(replicate (floor . (/) (diagWidth p) $ squareSize p)
|
|
|
|
(vrule 10))
|
2014-11-16 03:37:34 +00:00
|
|
|
# moveTo (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p))
|
2014-12-03 20:20:46 +00:00
|
|
|
labels p _ = position . zip (mkPoint <$> xs)
|
|
|
|
$ ((\x -> (text . show $ x) # scale 10) <$> xs)
|
2014-10-09 22:19:05 +00:00
|
|
|
where
|
|
|
|
xs :: [Int]
|
2014-11-15 23:10:57 +00:00
|
|
|
xs = take (floor . (/) (diagWidth p) $ squareSize p)
|
|
|
|
(iterate (+(floor . squareSize $ p)) (floor . diagXmin $ p))
|
2014-10-11 11:49:53 +00:00
|
|
|
mkPoint x = p2 (fromIntegral x,
|
2014-11-15 23:10:57 +00:00
|
|
|
-15 + (if diagYmin p <= 0 then 0 else diagYmin p))
|
2014-10-06 19:11:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- |Creates a Diagram that shows an YAxis which is bound
|
2014-11-15 23:49:20 +00:00
|
|
|
-- by the dimensions given in yDimension from DiagProp.
|
2014-10-09 15:19:58 +00:00
|
|
|
yAxis :: Diag
|
2014-10-09 22:19:05 +00:00
|
|
|
yAxis =
|
2014-11-16 15:45:51 +00:00
|
|
|
Diag vRule
|
|
|
|
<> Diag segments
|
|
|
|
<> Diag labels
|
2014-10-06 19:11:28 +00:00
|
|
|
where
|
2014-12-03 20:20:46 +00:00
|
|
|
vRule p _ = arrowAt (p2 (if diagXmin p <= 0 then 0 else diagXmin p, diagYmin p))
|
|
|
|
(r2 (0, diagHeight p))
|
|
|
|
segments p _ = vcat' (with & sep .~ squareSize p)
|
|
|
|
(replicate (floor . (/) (diagHeight p) $ squareSize p)
|
|
|
|
(hrule 10))
|
2014-11-16 03:37:34 +00:00
|
|
|
# alignB
|
|
|
|
# moveTo (p2 (if diagXmin p <= 0 then 0 else diagXmin p, diagYmin p))
|
2014-12-03 20:20:46 +00:00
|
|
|
labels p _ = position . zip (mkPoint <$> ys)
|
|
|
|
$ ((\x -> (text . show $ x) # scale 10) <$> ys)
|
2014-10-09 19:37:45 +00:00
|
|
|
where
|
|
|
|
ys :: [Int]
|
2014-11-15 23:10:57 +00:00
|
|
|
ys = take (floor . (/) (diagHeight p) $ squareSize p)
|
|
|
|
(iterate (+(floor . squareSize $ p)) (floor . diagYmin $ p))
|
|
|
|
mkPoint y = p2 (-15 + (if diagXmin p <= 0 then 0 else diagXmin p),
|
2014-10-11 11:49:53 +00:00
|
|
|
fromIntegral y)
|
2014-10-06 19:11:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- |Creates a Diagram that shows a white rectangle which is a little
|
2014-10-10 15:40:08 +00:00
|
|
|
-- bit bigger than both X and Y axis dimensions from DiagProp.
|
2014-10-09 15:19:58 +00:00
|
|
|
whiteRectB :: Diag
|
2014-10-09 22:42:15 +00:00
|
|
|
whiteRectB = Diag rect'
|
2014-10-06 19:11:28 +00:00
|
|
|
where
|
2014-12-03 21:11:10 +00:00
|
|
|
rect' p _ = rect (diagWidth p + (diagWidth p / 10))
|
|
|
|
(diagHeight p + (diagHeight p / 10))
|
|
|
|
# lwG 0.00
|
|
|
|
# bg white
|
2014-12-03 20:20:46 +00:00
|
|
|
# moveTo (p2 (diagWidthOffset p, diagHeightOffset p))
|
2014-10-08 17:23:15 +00:00
|
|
|
where
|
2014-10-11 01:59:21 +00:00
|
|
|
|
2014-10-06 19:11:28 +00:00
|
|
|
|
2014-10-09 23:08:53 +00:00
|
|
|
-- |Create a grid across the whole diagram with squares of the
|
|
|
|
-- given size in DiagProp.
|
2014-10-09 16:45:37 +00:00
|
|
|
grid :: Diag
|
2014-10-14 19:24:21 +00:00
|
|
|
grid = Diag xGrid <> Diag yGrid
|
2014-10-09 16:45:37 +00:00
|
|
|
where
|
2014-10-25 13:40:10 +00:00
|
|
|
yGrid p _
|
2014-12-03 00:36:12 +00:00
|
|
|
| haveGrid p = hcat' (with & sep .~ squareSize p)
|
|
|
|
(replicate (floor . (/) (diagWidth p) $ squareSize p)
|
|
|
|
(vrule $ diagHeight p))
|
2014-11-16 03:37:34 +00:00
|
|
|
# moveTo (p2 (diagXmin p, diagHeightOffset p)) # lw ultraThin
|
2014-10-25 13:40:10 +00:00
|
|
|
| otherwise = mempty
|
|
|
|
xGrid p _
|
2014-12-03 00:36:12 +00:00
|
|
|
| haveGrid p = vcat' (with & sep .~ squareSize p)
|
|
|
|
(replicate (floor . (/) (diagHeight p) $ squareSize p)
|
|
|
|
(hrule $ diagWidth p))
|
2014-11-16 03:37:34 +00:00
|
|
|
# alignB # moveTo (p2 (diagWidthOffset p, diagYmin p)) # lw ultraThin
|
2014-10-25 13:40:10 +00:00
|
|
|
| otherwise = mempty
|
|
|
|
|
|
|
|
|
|
|
|
plotterBG :: Diag
|
|
|
|
plotterBG = mconcat [xAxis, yAxis, grid, whiteRectB]
|