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
handful of newtype wrappers, namely:
Graph
,PosGraph
,CGraph
,Mat
,CMat
. These wrappers are also available from the standard module.
- class Graphable a where
- graphWith :: AGSettings -> a -> IO ()
- graph :: Graphable a => a -> IO ()
- animateWith :: Graphable a => AGSettings -> [a] -> IO ()
- animate :: Graphable a => [a] -> IO ()
- data AGSettings = AGSettings {}
- graphDefaults :: AGSettings
- defaultScaling :: Int -> Int
- blue :: AnsiColor
- pink :: AnsiColor
- white :: AnsiColor
- data AnsiColor = AnsiColor ColorIntensity Color
- data Coloring = Coloring AnsiColor AnsiColor
- realColors :: AGSettings -> Coloring
- imagColors :: AGSettings -> Coloring
- colorSets :: AGSettings -> (Coloring, Coloring)
- invert :: Coloring -> Coloring
- setFG :: AnsiColor -> SGR
- setBG :: AnsiColor -> SGR
- lineClear :: IO ()
- applyColor :: Coloring -> IO ()
- withColoring :: Coloring -> IO () -> IO ()
- newtype Graph = Graph {}
- newtype CGraph = CGraph {}
- newtype PosGraph = PosGraph {
- unPosGraph :: [Double]
- newtype Mat = Mat {}
- newtype CMat = CMat {}
- displayRV :: AGSettings -> [Double] -> IO ()
- displayCV :: AGSettings -> [Complex Double] -> IO ()
- simpleRender :: [Double] -> String
- simpleRenderR :: [Double] -> String
- matShow :: [[Double]] -> [String]
- displayMat :: AGSettings -> [[Double]] -> IO ()
- displayCMat :: AGSettings -> [[Complex Double]] -> IO ()
- 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.
graphWith :: AGSettings -> a -> IO () Source
graph :: Graphable a => a -> IO () Source
Invokes the Graphable
type class method graphWith
with the
default AGSettings
record, graphDefaults
.
animateWith :: Graphable a => AGSettings -> [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.
AGSettings
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.
Graphing options
data AGSettings Source
Record that holds graphing options.
AGSettings | |
|
Default options
defaultScaling :: Int -> Int Source
Default scaling function.
ANSI data
ANSI colors are characterized by a Color
and a ColorIntensity
. This
data type holds one of each.
Holds two AnsiColor
s representing foreground and background colors for display via ANSI.
ANSI helpers
realColors :: AGSettings -> Coloring Source
Projection retrieving foreground and background colors
for real number graphs in the form of a Coloring
.
imagColors :: AGSettings -> Coloring Source
Projection retrieving foreground and background colors
for imaginary component of complex number graphs in the form of a Coloring
.
colorSets :: AGSettings -> (Coloring, Coloring) Source
Retrieves a pair of Coloring
s for real and imaginary graph components respectively.
applyColor :: Coloring -> IO () Source
Apply both foreground and background color.
withColoring :: Coloring -> IO () -> IO () Source
Apply the supplied foreground and background coloring, then perform the supplied IO action, before reverting color settings and printing 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
displayRV :: AGSettings -> [Double] -> IO () Source
ANSI based display for real vectors. To be primarily invoked via graph
, graphWith
,
animate
, animateWith
.
displayCV :: AGSettings -> [Complex Double] -> IO () Source
ANSI based display for complex vectors. To be primarily invoked via graph
, graphWith
,
animate
, animateWith
.
simpleRender :: [Double] -> String Source
Simple vector rendering. Yields a string of unicode chars representing graph bars
varying in units of 1/8. To be primarily invoked via graph
, graphWith
,
animate
, animateWith
.
simpleRenderR :: [Double] -> String Source
Simple vector rendering – inverted version. Rarely used directly. It is needed to render negative graph regions.
Matrix graphing
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.
displayMat :: AGSettings -> [[Double]] -> IO () Source
Use ANSI coloring (specified by an AGSettings
) to visually display a Real matrix.
displayCMat :: AGSettings -> [[Complex Double]] -> IO () Source
Use ANSI coloring (specified by an AGSettings
) to visually display a Complex matrix.