Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module provides the core functionality of the ansigraph package: terminal-based graphing for vectors and matrices of real and complex numbers.
This is implemented via a Graphable
type class.
Ansigraph is intended to be used in on of two ways:
- By importing System.Console.Ansigraph. This provides all the functionality we typically use, including the FlexibleInstances extension which makes it easier to use graphing functions by allowing instances like 'Graphable [Double]'.
- By directly importing System.Console.Ansigraph.Core, which does not activate
FlexibleInstances but includes everything else provided by the other module. This just means
you must use one of a few newtype wrappers, namely:
Graph
,PosGraph
,CGraph
,Mat
,CMat
. They are also available from the standard module.
- class Graphable a where
- graph :: Graphable a => a -> IO ()
- animateWith :: Graphable a => GraphSettings -> [a] -> IO ()
- animate :: Graphable a => [a] -> IO ()
- transientAnim :: Graphable a => [a] -> IO ()
- transientAnimWith :: Graphable a => GraphSettings -> [a] -> IO ()
- data GraphSettings = GraphSettings {}
- graphDefaults :: GraphSettings
- blue :: AnsiColor
- pink :: AnsiColor
- white :: AnsiColor
- red :: AnsiColor
- green :: AnsiColor
- noColoring :: Coloring
- data AnsiColor = AnsiColor {}
- data Coloring = Coloring {}
- mkColoring :: AnsiColor -> AnsiColor -> Coloring
- fromFG :: AnsiColor -> Coloring
- fromBG :: AnsiColor -> Coloring
- realColors :: GraphSettings -> Coloring
- imagColors :: GraphSettings -> Coloring
- colorSets :: GraphSettings -> (Coloring, Coloring)
- invert :: Coloring -> Coloring
- interpAnsiColor :: ConsoleLayer -> AnsiColor -> SGR
- setColor :: ConsoleLayer -> AnsiColor -> IO ()
- clear :: IO ()
- clearLn :: IO ()
- applyColoring :: Coloring -> IO ()
- colorStr :: Coloring -> String -> IO ()
- colorStrLn :: Coloring -> String -> IO ()
- boldStr :: Coloring -> String -> IO ()
- boldStrLn :: Coloring -> String -> IO ()
- newtype Graph = Graph {}
- newtype CGraph = CGraph {}
- newtype PosGraph = PosGraph {
- unPosGraph :: [Double]
- newtype Mat = Mat {}
- newtype CMat = CMat {}
- displayPV :: GraphSettings -> [Double] -> IO ()
- displayRV :: GraphSettings -> [Double] -> IO ()
- displayCV :: GraphSettings -> [Complex Double] -> IO ()
- renderPV :: [Double] -> String
- renderRV :: [Double] -> (String, String)
- renderCV :: [Complex Double] -> (String, String, String, String)
- displayMat :: GraphSettings -> [[Double]] -> IO ()
- displayCMat :: GraphSettings -> [[Complex Double]] -> IO ()
- matShow :: [[Double]] -> [String]
- posGraph :: [Double] -> IO ()
- posAnim :: [[Double]] -> IO ()
Core Functionality
The Graphable class
class Graphable a where Source #
Things that ansigraph knows how to render at the terminal are instances of this class.
In general, when ANSI codes are involved, a graphWith
method should fush stdout when
finished, and whenever codes are invoked to i.e. change terminal colors. This is easily
handled by defining it in terms of colorStr
and colorStrLn
.
The graphHeight
function specifies how many vertical lines a graph occupies and is
needed for animations to work properly
graphWith :: GraphSettings -> a -> IO () Source #
Render a graph to standard output.
graphHeight :: a -> Int Source #
The number of vertical lines a graph occupies.
graph :: Graphable a => a -> IO () Source #
Invokes the Graphable
type class method graphWith
with the
default GraphSettings
record, graphDefaults
.
animateWith :: Graphable a => GraphSettings -> [a] -> IO () Source #
Any list of a Graphable
type can be made into an animation, by
graph
ing each element with a time delay and screen-clear after each.
GraphSettings
are used to determine the time delta and any coloring/scaling options.
animate :: Graphable a => [a] -> IO () Source #
Perform animateWith
using default options. Equivalent to graph
ing each member
of the supplied list with a short delay and screen-clear after each.
transientAnim :: Graphable a => [a] -> IO () Source #
Like animate
, only it does not leave the final frame of the animation visible.
transientAnimWith :: Graphable a => GraphSettings -> [a] -> IO () Source #
Like animateWith
, only it does not leave the final frame of the animation visible.
Graphing options
data GraphSettings Source #
Record that holds graphing options.
GraphSettings | |
|
Default options
graphDefaults :: GraphSettings Source #
Default graph settings.
ANSI data
ANSI colors are characterized by a Color
and a ColorIntensity
.
ANSI helpers
realColors :: GraphSettings -> Coloring Source #
Projection retrieving foreground and background colors
for real number graphs in the form of a Coloring
.
imagColors :: GraphSettings -> Coloring Source #
Projection retrieving foreground and background colors
for imaginary component of complex number graphs in the form of a Coloring
.
colorSets :: GraphSettings -> (Coloring, Coloring) Source #
Retrieves a pair of Coloring
s for real and imaginary graph components respectively.
interpAnsiColor :: ConsoleLayer -> AnsiColor -> SGR Source #
The SGR command corresponding to a particular ConsoleLayer
and AnsiColor
.
setColor :: ConsoleLayer -> AnsiColor -> IO () Source #
Set the given AnsiColor
on the given ConsoleLayer
.
applyColoring :: Coloring -> IO () Source #
Apply both foreground and background color contained in a Coloring
.
colorStr :: Coloring -> String -> IO () Source #
Use a particular ANSI Coloring
to print a string at the terminal (without a new line),
then clear all ANSI SGR codes and flush stdout.
colorStrLn :: Coloring -> String -> IO () Source #
Use a particular ANSI Coloring
to print a string at the terminal,
then clear all ANSI SGR codes, flush stdout and print a new line.
Graphable wrapper types
Wrapper type for graph of a real vector/function.
Wrapper type for graph of a complex vector/function.
Wrapper type for graph of a non-negative real vector/function.
PosGraph | |
|
Wrapper type for graph of a real two-index vector/two-argument function.
Wrapper type for graph of a complex two-index vector/two-argument function.
Graphing
Horizontal vector graphing (IO actions)
displayPV :: GraphSettings -> [Double] -> IO () Source #
ANSI based display for positive real vectors. Primarily invoked via graph
, graphWith
,
animate
, animateWith
.
displayRV :: GraphSettings -> [Double] -> IO () Source #
ANSI based display for real vectors. Primarily invoked via graph
, graphWith
,
animate
, animateWith
.
displayCV :: GraphSettings -> [Complex Double] -> IO () Source #
ANSI based display for complex vectors. Primarily invoked via graph
, graphWith
,
animate
, animateWith
.
Horizontal rendering logic (producing strings)
renderPV :: [Double] -> String Source #
Simple vector to String rendering that assumes positive input. Yields String of Unicode chars
representing graph bars varying in units of 1/8. The IO display
functions are preferable
for most use cases.
renderRV :: [Double] -> (String, String) Source #
Simple real vector rendering as a pair of strings. The IO display
functions are
preferable for most use cases.
renderCV :: [Complex Double] -> (String, String, String, String) Source #
Simple complex vector rendering as a pair of strings. The IO display
functions are
preferable for most use cases.
Matrix graphing
displayMat :: GraphSettings -> [[Double]] -> IO () Source #
Use ANSI coloring (specified by an GraphSettings
) to visually display a Real matrix.
displayCMat :: GraphSettings -> [[Complex Double]] -> IO () Source #
Use ANSI coloring (specified by an GraphSettings
) to visually display a Complex matrix.
matShow :: [[Double]] -> [String] Source #
Given a matrix of Doubles, return the list of strings illustrating the absolute value of each entry relative to the largest, via unicode chars that denote a particular density. Used for testing purposes.