ploterific 0.1.0.1 → 0.1.1.0
raw patch · 5 files changed
+41/−11 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Ploterific.Plot.Types: Facet :: Text -> Facet
+ Ploterific.Plot.Types: FacetNum :: Int -> FacetNum
+ Ploterific.Plot.Types: [_facetNum] :: Opts -> Maybe FacetNum
+ Ploterific.Plot.Types: [_facet] :: Opts -> Maybe Facet
+ Ploterific.Plot.Types: [unFacetNum] :: FacetNum -> Int
+ Ploterific.Plot.Types: [unFacet] :: Facet -> Text
+ Ploterific.Plot.Types: instance GHC.Read.Read Ploterific.Plot.Types.Facet
+ Ploterific.Plot.Types: instance GHC.Read.Read Ploterific.Plot.Types.FacetNum
+ Ploterific.Plot.Types: instance GHC.Show.Show Ploterific.Plot.Types.Facet
+ Ploterific.Plot.Types: instance GHC.Show.Show Ploterific.Plot.Types.FacetNum
+ Ploterific.Plot.Types: newtype Facet
+ Ploterific.Plot.Types: newtype FacetNum
+ Ploterific.Program.Options: [facetNum] :: Options -> Maybe Int <?> "(NOTHING | INT) The number of columns for the Trellis plot from --facet."
+ Ploterific.Program.Options: [facet] :: Options -> Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use to facet a plot into a Trellis plot. Add measurement according to --feature if needed."
- Ploterific.Plot.Types: Opts :: Maybe Color -> [Feature] -> Delimiter -> Maybe Input -> Maybe Output -> Mark -> Maybe Height -> Maybe Width -> Opts
+ Ploterific.Plot.Types: Opts :: Maybe Color -> [Feature] -> Maybe Facet -> Maybe FacetNum -> Delimiter -> Maybe Input -> Maybe Output -> Mark -> Maybe Height -> Maybe Width -> Opts
- Ploterific.Program.Options: Options :: (Maybe String <?> "([STDIN] | PATH) The path for the input data in tabular format, with row observations and column features.") -> (Maybe String <?> "([STDOUT] | PATH) HTML output path.") -> ([String] <?> "(COLUMN) A list of columns to use in the plot in the format --feature col1 --feature col2 etc. for axes X, Y, etc. To force a measurement, add `:` followed by `N`, `O`, `Q`, or `T` for nominal, ordinal, quantitiative, or temporal measurements, respectively. Full list of measurements located at https://vega.github.io/vega-lite/docs/type.html.") -> (Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use for colors. Add measurement according to --feature if needed.") -> (String <?> "(MARK) The mark type for the plot. Common types are Circle, Bar, Boxplot, and Line. See https://hackage.haskell.org/package/hvega-0.11.0.1/docs/Graphics-Vega-VegaLite.html#t:Mark for a list.") -> (Maybe Char <?> "([,] | CHAR) The delimiter for the table.") -> (Maybe Double <?> "(Nothing | DOUBLE) The height of the plot.") -> (Maybe Double <?> "(Nothing | Double) The width of the plot.") -> Options
+ Ploterific.Program.Options: Options :: (Maybe String <?> "([STDIN] | PATH) The path for the input data in tabular format, with row observations and column features.") -> (Maybe String <?> "([STDOUT] | PATH) HTML output path.") -> ([String] <?> "(COLUMN) A list of columns to use in the plot in the format --feature col1 --feature col2 etc. for axes X, Y, etc. To force a measurement, add `:` followed by `N`, `O`, `Q`, or `T` for nominal, ordinal, quantitiative, or temporal measurements, respectively. Full list of measurements located at https://vega.github.io/vega-lite/docs/type.html.") -> (Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use to facet a plot into a Trellis plot. Add measurement according to --feature if needed.") -> (Maybe Int <?> "(NOTHING | INT) The number of columns for the Trellis plot from --facet.") -> (Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use for colors. Add measurement according to --feature if needed.") -> (String <?> "(MARK) The mark type for the plot. Common types are Circle, Bar, Boxplot, and Line. See https://hackage.haskell.org/package/hvega-0.11.0.1/docs/Graphics-Vega-VegaLite.html#t:Mark for a list.") -> (Maybe Char <?> "([,] | CHAR) The delimiter for the table.") -> (Maybe Double <?> "(Nothing | DOUBLE) The height of the plot.") -> (Maybe Double <?> "(Nothing | Double) The width of the plot.") -> Options
Files
- app/Main.hs +2/−0
- ploterific.cabal +1/−1
- src/Ploterific/Plot/Plot.hs +30/−10
- src/Ploterific/Plot/Types.hs +4/−0
- src/Ploterific/Program/Options.hs +4/−0
app/Main.hs view
@@ -30,6 +30,8 @@ let opts = Opts { _color = fmap (Color . T.pack) . unHelpful . color $ options , _features = fmap (Feature . T.pack) . unHelpful . feature $ options+ , _facet = fmap (Facet . T.pack) . unHelpful . facet $ options+ , _facetNum = fmap FacetNum . unHelpful . facetNum $ options , _delimiter = Delimiter . fromMaybe ',' . unHelpful . delimiter $ options , _input = fmap Input . unHelpful . input $ options , _output = fmap Output . unHelpful . output $ options
ploterific.cabal view
@@ -1,5 +1,5 @@ name: ploterific-version: 0.1.0.1+version: 0.1.1.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
src/Ploterific/Plot/Plot.hs view
@@ -17,7 +17,8 @@ import Data.Char (ord) import Data.Either (rights) import Data.List (foldl')-import Data.Maybe (fromMaybe)+import Data.Maybe (fromMaybe, isJust)+import GHC.Natural (intToNatural) import qualified Control.Lens as L import qualified Data.ByteString.Lazy.Char8 as BL import qualified Data.ByteString.Char8 as B@@ -65,20 +66,29 @@ -- | Convert rows to data columns. rowsToDataColumns :: Maybe Color+ -> Maybe Facet -> [Feature] -> [Map.Map T.Text T.Text] -> [VL.DataColumn] -> VL.Data-rowsToDataColumns color fs rows =+rowsToDataColumns color facet fs rows = VL.dataFromColumns [] . maybe id- (\ (Color c)+ (\ (Color x) -> VL.dataColumn- (getColName c)- (numOrString (textToString c) c rows)+ (getColName x)+ (numOrString (textToString x) x rows) ) color+ . maybe+ id+ (\ (Facet x)+ -> VL.dataColumn+ (getColName x)+ (numOrString (textToString x) x rows)+ )+ facet . foldl' (\ acc (Feature x) -> VL.dataColumn@@ -158,22 +168,32 @@ mark' <- asks _mark color' <- asks _color features' <- asks _features+ facet' <- asks _facet+ facetNum' <- asks _facetNum delimiter' <- asks _delimiter contents <- liftIO input' let dataSet =- rowsToDataColumns color' features' . loadCsv delimiter' $ contents+ rowsToDataColumns color' facet' features' . loadCsv delimiter' $ contents+ facetSpec (Facet x) = [ VL.facetFlow+ $ [VL.FName . getColName $ x]+ <> maybe [] (\y -> [VL.FmType y]) (getColMeasurement x)+ ]+ plotSpec = [ enc color' features' []+ , VL.mark mark' []+ , VL.selection . VL.select "view" VL.Interval [VL.BindScales]+ $ []+ ] p = VL.toVegaLite $ [ dataSet []- , enc color' features' []- , VL.mark mark' [] , VL.theme VL.defaultConfig []- , VL.selection . VL.select "view" VL.Interval [VL.BindScales]- $ [] ]+ <> bool plotSpec [VL.specification . VL.asSpec $ plotSpec] (isJust facet') <> maybe [] (\(Height x) -> [VL.height x]) height' <> maybe [] (\(Width x) -> [VL.width x]) width'+ <> maybe [] facetSpec facet'+ <> maybe [] (\(FacetNum x) -> [VL.columns $ intToNatural x]) facetNum' liftIO . output' $ VL.toHtml p
src/Ploterific/Plot/Types.hs view
@@ -21,6 +21,8 @@ -- Basic newtype Color = Color { unColor :: T.Text } deriving (Read, Show) newtype Feature = Feature { unFeature :: T.Text } deriving (Read, Show)+newtype Facet = Facet { unFacet :: T.Text } deriving (Read, Show)+newtype FacetNum = FacetNum { unFacetNum :: Int } deriving (Read, Show) newtype Delimiter = Delimiter { unDelimiter :: Char } deriving (Read, Show) newtype Input = Input { unInput :: String } deriving (Read, Show) newtype Output = Output { unOutput :: String } deriving (Read, Show)@@ -30,6 +32,8 @@ -- Advanced data Opts = Opts { _color :: Maybe Color , _features :: [Feature]+ , _facet :: Maybe Facet+ , _facetNum :: Maybe FacetNum , _delimiter :: Delimiter , _input :: Maybe Input , _output :: Maybe Output
src/Ploterific/Program/Options.hs view
@@ -25,6 +25,8 @@ = Options { input :: Maybe String <?> "([STDIN] | PATH) The path for the input data in tabular format, with row observations and column features." , output :: Maybe String <?> "([STDOUT] | PATH) HTML output path." , feature :: [String] <?> "(COLUMN) A list of columns to use in the plot in the format --feature col1 --feature col2 etc. for axes X, Y, etc. To force a measurement, add `:` followed by `N`, `O`, `Q`, or `T` for nominal, ordinal, quantitiative, or temporal measurements, respectively. Full list of measurements located at https://vega.github.io/vega-lite/docs/type.html."+ , facet :: Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use to facet a plot into a Trellis plot. Add measurement according to --feature if needed."+ , facetNum :: Maybe Int <?> "(NOTHING | INT) The number of columns for the Trellis plot from --facet." , color :: Maybe String <?> "(NOTHING | COLUMN) The column containing a feature to use for colors. Add measurement according to --feature if needed." , mark :: String <?> "(MARK) The mark type for the plot. Common types are Circle, Bar, Boxplot, and Line. See https://hackage.haskell.org/package/hvega-0.11.0.1/docs/Graphics-Vega-VegaLite.html#t:Mark for a list." , delimiter :: Maybe Char <?> "([,] | CHAR) The delimiter for the table."@@ -38,6 +40,8 @@ short "input" = Just 'i' short "output" = Just 'o' short "feature" = Just 'f'+ short "facet" = Just 't'+ short "facet-num" = Just 'n' short "color" = Just 'c' short "mark" = Just 'm' short "delimiter" = Just 'd'