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)
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
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
[1..200]
:noprettychart
: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"
(display, quit) <- startChartServer Nothing
display $ debugExample quadExample
xs = [0..9]
either Text.putStrLn (writeChartOptions "other/list1a.svg") $ anyChart (pack . show $ xs)
either Text.putStrLn (writeChartOptions "other/list1a.svg") $ anyChart (pack . show $ xs)
xs = sin <$> [0..2000]
either Text.putStrLn (writeChartOptions "other/list1b.svg") $ anyChart (pack . show $ xs)
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)
xs = [(1+) . sin <$> [0..8], (1+) . cos <$> [0..8]]
xs
either Text.putStrLn (writeChartOptions "other/dlista.svg") $ anyChart (pack . show $ xs)
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
either Text.putStrLn (writeChartOptions "other/dlistb.svg") $ anyChart (pack . show $ xs)
xs = zip (fmap (sin . (0.06*)) [1..100]) (fmap (cos . (0.06*)) [1..100])
:t xs
either Text.putStrLn (writeChartOptions "other/dtuple.svg") $ anyChart (pack . show $ xs)
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
either Text.putStrLn (writeChartOptions "other/dtupleb.svg") $ anyChart (pack . show $ xs)
xs = (\x -> (show x, x)) <$> [0..9]