packages feed

ploterific 0.1.1.0 → 0.2.0.0

raw patch · 3 files changed

+40/−11 lines, 3 filesdep +colourdep +palette

Dependencies added: colour, palette

Files

ploterific.cabal view
@@ -1,5 +1,5 @@ name:                ploterific-version:             0.1.1.0+version:             0.2.0.0 synopsis:            Basic plotting of tabular data for the command line. description:         A quick and easy way to plot tabular data from the command line. Meant for quick visualizations, not too customizable. homepage:            http://github.com/GregorySchwartz/ploterific#readme@@ -21,12 +21,14 @@   build-depends:       base >= 4.7 && < 5                      , bytestring                      , cassava+                     , colour                      , containers                      , hvega                      , hvega-theme                      , lens                      , mtl                      , optparse-generic+                     , palette                      , text   ghc-options:         -O2   default-language:    Haskell2010
src/Ploterific/Plot/Plot.hs view
@@ -15,6 +15,9 @@ import Control.Monad.Reader (ReaderT (..), asks, liftIO) import Data.Bool (bool) import Data.Char (ord)+import Data.Colour.Palette.BrewerSet ( brewerSet, ColorCat (..) )+import Data.Colour.Palette.Harmony (colorRamp)+import Data.Colour.SRGB (sRGB24show) import Data.Either (rights) import Data.List (foldl') import Data.Maybe (fromMaybe, isJust)@@ -26,6 +29,7 @@ import qualified Data.Csv as CSV import qualified Data.Foldable as F import qualified Data.Map.Strict as Map+import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Read as T@@ -117,18 +121,32 @@                            )     textToString x = VL.Strings . fmap (fromMaybe "" . Map.lookup (getColName x)) +-- | Get color encoding for color ramps.+labelColorScale :: [ColorLabel] -> VL.MarkChannel+labelColorScale cs = VL.MScale [ VL.SDomain (VL.DStrings labels)+                               , VL.SRange (VL.RStrings colors)+                               ]+  where+    labels =+      Set.toAscList . Set.fromList . fmap unColorLabel $ cs+    colors =+      fmap (T.pack . sRGB24show) . colorRamp (length labels) . brewerSet Set1 $ 9+ -- | Get the encoding.-enc :: Maybe Color -> [Feature] -> [VL.EncodingSpec] -> VL.PropertySpec-enc color fs =+enc :: Maybe (Color, [ColorLabel])+    -> [Feature]+    -> [VL.EncodingSpec]+    -> VL.PropertySpec+enc colorInfo fs =   VL.encoding     . maybe         id-        (\ (Color c)-        -> VL.color ( [VL.MName . getColName $ c]+        (\ (Color c, ls)+        -> VL.color ( [VL.MName . getColName $ c, labelColorScale ls]                    <> maybe [] (\x -> [VL.MmType x]) (getColMeasurement c)                     )         )-        color+        colorInfo     . VL.tooltips         ( fmap (\ (Feature !f)                -> [ VL.TName . getColName $ f ]@@ -137,11 +155,11 @@           fs        <> [ maybe               []-              (\ (Color c)+              (\ (Color c, _)               -> [VL.TName . getColName $ c]               <> maybe [] (\x -> [VL.TmType x]) (getColMeasurement c)               )-              color+              colorInfo           ]         )     . foldl'@@ -174,13 +192,21 @@    contents <- liftIO input' -  let dataSet =-        rowsToDataColumns color' facet' features' . loadCsv delimiter' $ contents+  let rows = loadCsv delimiter' contents+      dataSet =+        rowsToDataColumns color' facet' features' $ rows+      colorLabels =+        fmap+          (\ (Color c)+          -> fmap (ColorLabel . fromMaybe "" . Map.lookup (getColName c)) rows+          )+          color'+      colorInfo = (,) <$> color' <*> colorLabels       facetSpec (Facet x) = [ VL.facetFlow                             $ [VL.FName . getColName $ x]                            <> maybe [] (\y -> [VL.FmType y]) (getColMeasurement x)                             ]-      plotSpec = [ enc color' features' []+      plotSpec = [ enc colorInfo features' []                  , VL.mark mark' []                  , VL.selection . VL.select "view" VL.Interval [VL.BindScales]                  $ []
src/Ploterific/Plot/Types.hs view
@@ -28,6 +28,7 @@ newtype Output = Output { unOutput :: String } deriving (Read, Show) newtype Height = Height { unHeight :: Double } deriving (Read, Show) newtype Width = Width { unWidth :: Double } deriving (Read, Show)+newtype ColorLabel = ColorLabel { unColorLabel :: T.Text } deriving (Read, Show)  -- Advanced data Opts = Opts { _color :: Maybe Color