packages feed

sym-plot (empty) → 0.1.0

raw patch · 4 files changed

+106/−0 lines, 4 filesdep +basedep +diagrams-cairodep +diagrams-coresetup-changed

Dependencies added: base, diagrams-cairo, diagrams-core, diagrams-lib, sym

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Anders Claesson++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Anders Claesson nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Math/Sym/Plot.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE NoMonomorphismRestriction #-}++-- |+-- Module      : Math.Sym.Plot+-- Copyright   : (c) Anders Claesson 2013+-- License     : BSD-style+-- Maintainer  : Anders Claesson <anders.claesson@gmail.com>+-- +-- Plot permutations.++module Math.Sym.Plot+    (+     plotPerm, plotPerms, savePNG+    ) where++import Diagrams.Prelude+import Graphics.Rendering.Diagrams.Core+import Diagrams.Backend.Cairo.Internal+import Math.Sym (Perm (..), st, toList, size)++type DC = Diagram Cairo R2++-- An n x n grid+grid :: Int -> DC+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 as a Cairo diagram.+plotPerm :: Perm a => a -> DC+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 as a Cairo diagram. The first+-- argument specifies how many permutations are on each row.+plotPerms :: Perm a => Int -> [a] -> DC+plotPerms cols = vcat . map hcat . chunk cols . map (pad 1.1 . plotPerm)++-- | Save a Cairo diagram as a PNG.+savePNG :: Double -> String -> DC -> IO ()+savePNG width filePath = fst . renderDia Cairo (CairoOptions filePath (Width width) PNG)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ sym-plot.cabal view
@@ -0,0 +1,23 @@+name:                sym-plot+version:             0.1.0+synopsis:            Plot permutations; an addition to the sym package+description:+  This packade adds plots to the sym package. It has been factored out+  of that package because diagrams is a heavy dependency.++homepage:            http://github.com/akc/sym-plot+license:             BSD3+license-file:        LICENSE+author:              Anders Claesson+maintainer:          anders.claesson@gmail.com+category:            Math+build-type:          Simple+cabal-version:       >=1.8++source-repository head+  type:                git+  location:            git://github.com/akc/sym-plot.git++library+  build-depends:       base ==4.5.*, sym, diagrams-core, diagrams-lib, diagrams-cairo+  Exposed-modules:     Math.Sym.Plot