From cb7d5269a0090be09dce8bcaa0241ef187239835 Mon Sep 17 00:00:00 2001 From: hasufell Date: Fri, 10 Oct 2014 15:40:56 +0200 Subject: [PATCH] DIAGRAM: add maybeDiag convenience function --- Diagram.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Diagram.hs b/Diagram.hs index df5ca9e..ea3796b 100644 --- a/Diagram.hs +++ b/Diagram.hs @@ -92,6 +92,15 @@ yuD :: DiagProp -> Double yuD = snd . dY +-- |Returns the specified diagram if True is passed, +-- otherwise returns the empty diagram. This is just for convenience +-- to avoid if else constructs. +maybeDiag :: Bool -> Diag -> Diag +maybeDiag b d + | b = d + | otherwise = mempty + + -- |Creates a Diagram that shows the coordinates from the points -- as dots. The points and thickness of the dots can be controlled -- via DiagProp. @@ -253,17 +262,17 @@ diag :: DiagProp -> [PT] -> Diagram Cairo R2 diag p = case alg p of 0 -> mkDiag - (mconcat [if ct p then coordPointsText else mempty, + (mconcat [maybeDiag (ct p) coordPointsText, coordPoints, xAxis, yAxis, - (if gd p then grid else mempty),whiteRectB]) + maybeDiag (gd p) grid, whiteRectB]) p 1 -> mkDiag (mconcat - [if ct p then convexHullPointsText else mempty, + [maybeDiag (ct p) convexHullPointsText, convexHullPoints, convexHullLines, coordPoints, xAxis, yAxis, - (if gd p then grid else mempty), whiteRectB]) + maybeDiag (gd p) grid, whiteRectB]) p _ -> mempty