granite-0.4.0.0: Easy terminal plotting.
Copyright(c) 2025
LicenseMIT
Maintainermschavinda@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageGHC2021

Granite.Svg

Description

An SVG-based plotting backend that mirrors the API of Granite. Every chart function returns a self-contained SVG document as Text.

Basic Usage

{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as T
import Granite.Svg

main = do
  let chart = bars [("Q1",12),("Q2",18),("Q3",9),("Q4",15)]
                   defPlot { plotTitle = "Sales" }
  T.writeFile "chart.svg" chart
Synopsis

Re-exports from Granite

data Plot Source #

Plot configuration parameters.

Controls the appearance and layout of generated charts.

Constructors

Plot 

Fields

defPlot :: Plot Source #

Default plot configuration.

Creates a 60×20 character plot with reasonable defaults:

defPlot = Plot
  { widthChars   = 60
  , heightChars  = 20
  , leftMargin   = 6
  , bottomMargin = 2
  , titleMargin  = 1
  , xBounds      = (Nothing, Nothing)
  , yBounds      = (Nothing, Nothing)
  , plotTitle    = ""
  , legendPos    = LegendRight
  , colorPalette = [ BrightBlue, BrightMagenta, BrightCyan, BrightGreen, BrightYellow, BrightRed, BrightWhite, BrightBlack]
  , xFormatter   = \ _ _ v -> show v
  , yFormatter   = \ _ _ v -> show v
  , xNumTicks    = 2
  , yNumTicks    = 2
  }

data LegendPos Source #

Position of the legend in the plot.

Constructors

LegendRight

Display legend on the right side of the plot

LegendBottom

Display legend below the plot

LegendNone

Do not display legend.

Instances

Instances details
Show LegendPos Source # 
Instance details

Defined in Granite

Eq LegendPos Source # 
Instance details

Defined in Granite

data Color Source #

Supported ANSI colo(u)rs.

Instances

Instances details
Show Color Source # 
Instance details

Defined in Granite

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color Source # 
Instance details

Defined in Granite

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

data AxisEnv Source #

What the formatter gets to know about the axis/ticks

Constructors

AxisEnv 

Fields

type LabelFormatter Source #

Arguments

 = AxisEnv

Axis context (domain, tick index/count, etc)

-> Int

Slot width budget in characters for this tick.

-> Double

Raw data value for the tick

-> Text

Rendered label (if it doesn't fit in the slot it will be truncated)

Axis-aware, width-limited, tick-label formatter.

Given:

  • axis context
  • a per-tick width budget (in terminal cells)
  • and the raw tick value.

returns the label to render.

data Bins Source #

Defines the binning parameters.

Constructors

Bins 

Fields

Instances

Instances details
Show Bins Source # 
Instance details

Defined in Granite

Methods

showsPrec :: Int -> Bins -> ShowS #

show :: Bins -> String #

showList :: [Bins] -> ShowS #

Eq Bins Source # 
Instance details

Defined in Granite

Methods

(==) :: Bins -> Bins -> Bool #

(/=) :: Bins -> Bins -> Bool #

bins :: Int -> Double -> Double -> Bins Source #

Create a bin configuration for histograms.

bins 10 0 100  -- 10 bins from 0 to 100
bins 20 (-5) 5 -- 20 bins from -5 to 5

series Source #

Arguments

:: Text

Name of the series (appears in legend)

-> [(Double, Double)]

List of (x, y) data points

-> (Text, [(Double, Double)]) 

Create a named data series for multi-series plots.

let s1 = series "Dataset A" [(1,2), (2,4), (3,6)]
    s2 = series "Dataset B" [(1,3), (2,5), (3,7)]
    chart = scatter [s1, s2] defPlot

Chart types (SVG output)

scatter :: [(Text, [(Double, Double)])] -> Plot -> Text Source #

bars :: [(Text, Double)] -> Plot -> Text Source #

pie :: [(Text, Double)] -> Plot -> Text Source #

boxPlot :: [(Text, [Double])] -> Plot -> Text Source #