ansigraph-0.1.0.0: Terminal-based graphing via ANSI and Unicode

Safe HaskellSafe
LanguageHaskell2010

System.Console.Ansigraph.Core

Contents

Description

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.

Synopsis

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.

Methods

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 graphing 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 graphing 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.

Constructors

AGSettings 

Fields

realColor :: AnsiColor

Foreground color for real number component

imagColor :: AnsiColor

Foreground color for imaginary number component.

realBG :: AnsiColor

Background color for real number component.

imagBG :: AnsiColor

Background color for imaginary number component.

framerate :: Int

Framerate in fps.

scaling :: Int -> Int

How to rescale the size of a vector before displaying it (which is not implemented yet).

Default options

defaultScaling :: Int -> Int Source

Default scaling function.

ANSI data

data AnsiColor Source

ANSI colors are characterized by a Color and a ColorIntensity. This data type holds one of each.

Instances

data Coloring Source

Holds two AnsiColors representing foreground and background colors for display via ANSI.

Instances

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 Colorings for real and imaginary graph components respectively.

invert :: Coloring -> Coloring Source

Swaps foreground and background colors within a Coloring.

setFG :: AnsiColor -> SGR Source

SGR command to set the foreground to the specified AnsiColor.

setBG :: AnsiColor -> SGR Source

SGR command to set the background to the specified AnsiColor.

lineClear :: IO () Source

Clear any SGR color settings and then print a new line.

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

newtype Graph Source

Wrapper type for graph of a real vector/function

Constructors

Graph 

Fields

unGraph :: [Double]
 

newtype CGraph Source

Wrapper type for graph of a complex vector/function

Constructors

CGraph 

Fields

unCGraph :: [Complex Double]
 

newtype PosGraph Source

Wrapper type for graph of a non-negative real vector/function

Constructors

PosGraph 

Fields

unPosGraph :: [Double]
 

newtype Mat Source

Wrapper type for graph of a real two-index vector/two-argument function

Constructors

Mat 

Fields

unMat :: [[Double]]
 

Instances

newtype CMat Source

Wrapper type for graph of a complex two-index vector/two-argument function

Constructors

CMat 

Fields

unCMat :: [[Complex Double]]
 

Instances

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.

Simple (non-ANSI) graphing for strictly-positive data

posgraph :: [Double] -> IO () Source

Display a graph of the supplied (non-negative) real vector.

posanim :: [[Double]] -> IO () Source

Display an animation of the supplied list of (non-negative) real vectors.