module System.Console.Ansigraph.Internal.Horizontal (
displayRV
, displayCV
, displayPV
, renderPV
, renderRV
, renderCV
) where
import System.Console.Ansigraph.Internal.Core
import Data.Complex
import Control.Monad.IO.Class (MonadIO)
import Control.Applicative
barChars = "█▇▆▅▄▃▂▁ "
barVals :: [Double]
barVals = (+ 0.0625) . (/8) <$> [7,6..0]
bars, barsR :: [(Double,Char)]
bars = zip barVals barChars
barsR = zip barVals (reverse barChars)
selectBar, selectBarR :: Double -> Char
selectBar x = let l = filter (\p -> fst p < x) bars in
case l of
[] -> ' '
(p:_) -> snd p
selectBarR x = let l = filter (\p -> fst p < x) barsR in
case l of
[] -> '█'
(p:_) -> snd p
renderPV :: [Double] -> String
renderPV xs = let mx = maximum (filter (>= 0) $ 0:xs) in
(selectBar . (/mx)) <$> xs
renderRV :: [Double] -> (String,String)
renderRV l = let rp = l
rm = negate <$> rp
mx = maximum $ rp ++ rm
in (selectBar . (/mx) <$> rp,
selectBarR . (/mx) <$> rm)
renderCV :: [Complex Double] -> (String,String,String,String)
renderCV l = let rp = realPart <$> l
rm = negate <$> rp
ip = imagPart <$> l
im = negate <$> ip
mx = maximum $ rp ++ rm ++ ip ++ im
in (selectBar . (/mx) <$> rp,
selectBarR . (/mx) <$> rm,
selectBar . (/mx) <$> ip,
selectBarR . (/mx) <$> im)
displayPV :: MonadIO m => GraphSettings -> [Double] -> m ()
displayPV s l = let (rp,_) = renderRV l
rcol = realColors s in colorStrLn rcol rp
displayRV :: MonadIO m => GraphSettings -> [Double] -> m ()
displayRV s l = let (rp,rm) = renderRV l
rcol = realColors s
in do colorStrLn rcol rp
colorStrLn (invert rcol) rm
displayCV :: MonadIO m => GraphSettings -> [Complex Double] -> m ()
displayCV s l = let (rp,rm,ip,im) = renderCV l
(rcol,icol) = colorSets s
in do colorStrLn rcol rp
colorStrLn (invert rcol) rm
colorStrLn icol ip
colorStrLn (invert icol) im