sym-plot 0.2.0 → 0.3.0
raw patch · 3 files changed
+59/−54 lines, 3 filesdep ~basedep ~diagrams-cairodep ~diagrams-lib
Dependency ranges changed: base, diagrams-cairo, diagrams-lib, sym
Files
- Math/Sym/Plot.hs +0/−51
- Sym/Plot.hs +53/−0
- sym-plot.cabal +6/−3
− Math/Sym/Plot.hs
@@ -1,51 +0,0 @@-{-# LANGUAGE NoMonomorphismRestriction #-}---- |--- Copyright : Anders Claesson 2013--- Maintainer : Anders Claesson <anders.claesson@gmail.com>------ Plot permutations.--module Math.Sym.Plot- (- Plot, plotPerm, plotPerms, savePlot- ) where--import Diagrams.Prelude-import Diagrams.Backend.Cairo-import Data.Perm (toList)-import Math.Sym---- | A plot is represented by Cairo diagram-type Plot = Diagram Cairo R2---- An n x n grid-grid :: Int -> Plot-grid n = stripes `atop` rotateBy (1/4) stripes- where - stripes = centerXY . hcat' with {sep = 1} . replicate n . vrule $ fromIntegral n---- | The plot of a permutation.-plotPerm :: Permutation a => a -> Plot-plotPerm w = centerXY plot `atop` grid n `atop` background- where- n = size w- v = map fromIntegral . toList $ st w- plot = position $ zip (zipWith (curry p2) [0..] v) dots- dots = repeat $ circle 0.2 # fc black- background = square (fromIntegral n) # fc whitesmoke # lc white---- Split a list into fixed length chunks-chunk :: Int -> [a] -> [[a]]-chunk k [] = []-chunk k xs = ys : chunk k zs where (ys, zs) = splitAt k xs---- | The plot of a list of permutations. The first argument specifies--- how many permutations are on each row.-plotPerms :: Permutation a => Int -> [a] -> Plot-plotPerms cols = vcat . map hcat . chunk cols . map (pad 1.1 . plotPerm)---- | Save plot as a png, ps, pdf, or svg (determined automatically from--- the file extension).-savePlot :: Double -> String -> Plot -> IO ()-savePlot width filePath = renderCairo filePath (Width width)
+ Sym/Plot.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE TypeFamilies #-}++-- |+-- Copyright : Anders Claesson 2013+-- Maintainer : Anders Claesson <anders.claesson@gmail.com>+--+-- Plot permutations.++module Sym.Plot+ (+ Plot, plotPerm, plotPerms, savePlot+ ) where++import Diagrams.Prelude hiding (size)+import Diagrams.Backend.Cairo+import Sym.Perm (toList)+import Sym++-- | A plot is represented by Cairo diagram+type Plot = Diagram Cairo++-- An n x n grid+grid :: Int -> Plot+grid n = stripes `atop` rotateBy (1/4) stripes+ where+ stripes = centerXY . hcat' (def {_sep=1}) . replicate n . vrule $ fromIntegral n++-- | The plot of a permutation.+plotPerm :: Permutation a => a -> Plot+plotPerm w = centerXY plot `atop` grid n `atop` background+ where+ n = size w+ v = map fromIntegral . toList $ st w+ plot = position $ zip (zipWith (curry p2) [0..] v) dots+ dots = repeat $ circle 0.2 # fc black+ background = square (fromIntegral n) # fc white # lc white++-- Split a list into fixed length chunks+chunk :: Int -> [a] -> [[a]]+chunk k [] = []+chunk k xs = ys : chunk k zs where (ys, zs) = splitAt k xs++-- | The plot of a list of permutations. The first argument specifies+-- how many permutations are on each row.+plotPerms :: Permutation a => Int -> [a] -> Plot+plotPerms cols = vcat . map hcat . chunk cols . map (pad 1.1 . plotPerm)++-- | Save plot as a png, ps, pdf, or svg (determined automatically from+-- the file extension).+savePlot :: Double -> String -> Plot -> IO ()+savePlot width filePath = renderCairo filePath (mkWidth width)
sym-plot.cabal view
@@ -1,5 +1,5 @@ name: sym-plot-version: 0.2.0+version: 0.3.0 synopsis: Plot permutations; an addition to the sym package description: This packade adds plots to the sym package. It has been factored out@@ -19,5 +19,8 @@ location: git://github.com/akc/sym-plot.git library- build-depends: base >= 3 && <= 4.7, sym >= 0.9, diagrams-lib, diagrams-cairo- Exposed-modules: Math.Sym.Plot+ build-depends: base >=4.7 && <=5,+ sym >=0.12,+ diagrams-lib >=1.4,+ diagrams-cairo >=1.4+ Exposed-modules: Sym.Plot