prettychart: Pretty print charts from ghci.

[ bsd3, graphics, library ] [ Propose Tags ] [ Report a vulnerability ]

Serve and print charts from ghci, with automatic formatting.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1.0, 0.1.2.0, 0.2.0.0, 0.2.2.0
Change log ChangeLog.md
Dependencies async (>=2.2.4 && <2.3), base (>=4.7 && <5), box (>=0.9 && <0.10), bytestring (>=0.11.3 && <0.13), chart-svg (>=0.6 && <0.8), containers (>=0.6 && <0.8), markup-parse (>=0.1 && <0.2), numhask-space (>=0.10 && <0.12), optics-core (>=0.4 && <0.5), text (>=1.2 && <2.2), time (>=1.9 && <1.15), web-rep (>=0.12.1 && <0.13) [details]
Tested with ghc ==9.10.1, ghc ==9.8.2, ghc ==9.6.5
License BSD-3-Clause
Copyright Tony Day (c) 2023
Author Tony Day
Maintainer tonyday567@gmail.com
Category graphics
Home page https://github.com/tonyday567/prettychart#readme
Bug tracker https://github.com/tonyday567/prettychart/issues
Source repo head: git clone https://github.com/tonyday567/prettychart
Uploaded by tonyday567 at 2024-10-13T01:34:07Z
Distributions LTSHaskell:0.2.2.0, Stackage:0.2.2.0
Downloads 239 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-10-20 [all 1 reports]

Readme for prettychart-0.2.2.0

[back to package description]

Table of Contents

  1. prettychart
  2. Usage
    1. live coding
    2. ghci integration
  3. Development
    1. live
  4. Prettychart.Any Examples
    1. single list
      1. 10 or less elements => bar chart
      2. >1000 elements => histogram
      3. < 1000 && > 10 => line chart
    2. double list
      1. < 4 lists && < 10 values per list => bar chart
      2. square => surface chart
    3. tuple list [(Double, Double)] => scatter
    4. double tuple list [(Double, Double)] => scatter
    5. (Text, Double) tuple list

prettychart

img img

This library contains:

  • A chart server, for use in conjunction with ghci, or other live coding situations. (See Chartpretty.Server)
  • anyChart, which attempts to convert text (of numbers) to a chart. (See Chartpretty.Any)
  • Some useful chart patterns that didn’t make the cut in chart-svg (See Chartpretty.Charts)

Usage

live coding

The server can be used to view and develop chart-svg charts.

> (display, quit) <- startChartServer (Just "prettychart")
Setting phaser>s  to stun... (port 9160) (ctrl-c to quit)

-- open localhost:9160
-- developing and sending a chart to the server

> import Chart.Examples
> display lineExample

> quit

ghci integration

Add this to your .ghci.conf file to automatically go into :prettychart mode.

-- :set -package prettychart
:{
:def! prettychart \_ -> pure $ unlines [
  "import Prettychart",
  "(sendChart, quitChartServer) <- startChartServer Nothing",
  "printc=printChart False sendChart",
  ":set -interactive-print printc"
  ]
:}

:{
:def! noprettychart \_ -> pure $ unlines [
  "quitChartServer",
  ":set -interactive-print print"
  ]
:}

:prettychart

ghci| ghci| ghci| ghci| ghci| ghci| ghci|
> ghci| ghci| ghci| ghci| ghci|
> Setting phasers to stun... (port 9160) (ctrl-c to quit)

[1..200]

:noprettychart

Development

:r
:set prompt "> "
:set -Wno-type-defaults
:set -Wno-name-shadowing
:set -XOverloadedStrings
:set -XTupleSections
:set -XOverloadedLabels
import Chart hiding (quantiles)
import Chart.Examples
import Optics.Core
import Prettychart.Charts
import Prettychart.Any
import Prettychart.ExampleData
import Prettychart.Server
import Data.Time.Calendar
import qualified Data.Map as Map
import Data.Text (Text,pack)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Data.Time
import qualified Data.List as List
import Control.Category ((>>>))
print "ok"

[3 of 5] Compiling Prettychart.ExampleData ( src/Prettychart/ExampleData.hs, interpreted ) [Flags changed]
[5 of 5] Compiling Prettychart      ( src/Prettychart.hs, interpreted ) [Flags changed]
Ok, five modules loaded.
>
ok

live

(display, quit) <- startChartServer Nothing

display $ debugExample quadExample

True

Prettychart.Any Examples

single list

10 or less elements => bar chart

xs = [0..9]

either Text.putStrLn (writeChartOptions "other/list1a.svg") $ anyChart (pack . show $ xs)

img

either Text.putStrLn (writeChartOptions "other/list1a.svg") $ anyChart (pack . show $ xs)

>1000 elements => histogram

xs = sin <$> [0..2000]

either Text.putStrLn (writeChartOptions "other/list1b.svg") $ anyChart (pack . show $ xs)

img

< 1000 && > 10 => line chart

In between goes for a line chartIn between goes for a line chart.

xs = sin . (/100) <$> [0..500]

either Text.putStrLn (writeChartOptions "other/list1c.svg") $ anyChart (pack . show $ xs)

img

double list

< 4 lists && < 10 values per list => bar chart

xs = [(1+) . sin <$> [0..8], (1+) . cos <$> [0..8]]
xs

[[1.0,1.8414709848078965,1.9092974268256817,1.1411200080598671,0.2431975046920718,4.1075725336861546e-2,0.7205845018010741,1.656986598718789,1.989358246623382],[2.0,1.5403023058681398,0.5838531634528576,1.0007503399554585e-2,0.34635637913638806,1.2836621854632262,1.960170286650366,1.7539022543433047,0.8544999661913865]]

either Text.putStrLn (writeChartOptions "other/dlista.svg") $ anyChart (pack . show $ xs)

img

square => surface chart

iter2 f xs ys = f <$> xs <&> flip fmap ys -- or (\a -> f a <$> ys) <$> xs
xs = iter2 (*) (fmap sin [1..20]) (fmap cos [1..20]) :: [[Double]]
:t xs
length xs
fmap length xs

xs :: [[Double]]
20
[20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20]

either Text.putStrLn (writeChartOptions "other/dlistb.svg") $ anyChart (pack . show $ xs)

img

tuple list [(Double, Double)] => scatter

xs = zip (fmap (sin . (0.06*)) [1..100]) (fmap (cos . (0.06*)) [1..100])
:t xs

xs
  :: (TrigField b1, TrigField b2, Fractional b1, Fractional b2,
      Enum b1, Enum b2) =>
     [(b1, b2)]

either Text.putStrLn (writeChartOptions "other/dtuple.svg") $ anyChart (pack . show $ xs)

img

double tuple list [(Double, Double)] => scatter

iter2 f xs ys = f <$> xs <&> flip fmap ys -- or (\a -> f a <$> ys) <$> xs


xs = iter2 (\s (x,y) -> (s*x, s*y)) ((0.1*) <$> [1..10]) (zip (fmap (sin . (0.06*)) [1..100]) (fmap (cos . (0.06*)) [1..100]))
:t xs

> >
xs :: (Fractional b, Enum b, TrigField b) => [[(b, b)]]

either Text.putStrLn (writeChartOptions "other/dtupleb.svg") $ anyChart (pack . show $ xs)

img

(Text, Double) tuple list

xs = (\x -> (show x, x)) <$> [0..9]

either Text.putStrLn (writeChartOptions "other/tdtuple.svg") $ anyChart (pack . show $ xs)

img