happy-hour 0.0.0.3 → 0.0.0.4
raw patch · 4 files changed
+49/−48 lines, 4 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- changelog.md +11/−9
- happy-hour.cabal +5/−4
- library/Graphics/HappyHour.hs +28/−35
- readme.md +5/−0
changelog.md view
@@ -1,17 +1,19 @@-# Changelog--## v0.0.0.1 -- 2019 June 30--Initial release--## v0.0.0.2 -- 2020 Nov 09+### v0.0.0.4 -- 2022 Dec 29 -Added support for GHC 8.8+Metadata and doc changes only -## v0.0.0.3 -- 2022 March 14+### v0.0.0.3 -- 2022 March 14 Added support for: - bytestring-0.11 - base-4.14 (ghc 8.10) - base-4.15 (ghc 9.0)++### v0.0.0.2 -- 2020 Nov 09++Added support for GHC 8.8++### v0.0.0.1 -- 2019 June 30++Initial release
happy-hour.cabal view
@@ -1,7 +1,7 @@-cabal-version: 2.4+cabal-version: 3.0 name: happy-hour-version: 0.0.0.3+version: 0.0.0.4 category: Graphics synopsis: Generate simple okay-looking bar plots without much effort @@ -12,7 +12,7 @@ nicer. If happy-hour generates a plot for you that is not aesthetically pleasing, please let us know so that we may improve. -extra-source-files: changelog.md+extra-source-files: *.md copyright: 2019 Mission Valley Software LLC license: MIT@@ -27,11 +27,12 @@ library hs-source-dirs: library default-language: Haskell2010+ ghc-options: -Wall exposed-modules: Graphics.HappyHour build-depends:- base ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15+ base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 , Chart ^>= 1.9 , Chart-diagrams ^>= 1.9
library/Graphics/HappyHour.hs view
@@ -1,32 +1,27 @@-{-# OPTIONS_GHC -Wall #-}- module Graphics.HappyHour (writeBarGraphSvgFile) where --- base+import Data.Functor (void) import Data.List (genericLength)---- Chart import Graphics.Rendering.Chart.Easy hiding (bars)---- Chart-diagrams-import Graphics.Rendering.Chart.Backend.Diagrams (renderableToFile, FileOptions, fo_size)---- | Create an SVG file containing a bar graph.+import Graphics.Rendering.Chart.Backend.Diagrams+ (renderableToFile, FileOptions, fo_size) -writeBarGraphSvgFile- :: FilePath- -- ^ Where the file will be written. The containing directory must already exist. If there already exists a file at this path, it will be overwritten. If there exists a directory at this path, the action will fail.+-- | Create an SVG file containing a bar graph+writeBarGraphSvgFile ::+ FilePath -- ^ Where the file will be written. The containing directory+ -- must already exist. If there already exists a file at this path,+ -- it will be overwritten. If there exists a directory at this path,+ -- the action will fail. -> [(String, Int)]- -- ^ The data to visualize. Each list entry represents a bar on the plot, ordered from left to right. The @String@ is the label on the X axis, and the @Int@ is the height of the bar.+ -- ^ The data to visualize. Each list entry represents a bar on the+ -- plot, ordered from left to right. The @String@ is the label on the+ -- X axis, and the @Int@ is the height of the bar. -> IO ()--writeBarGraphSvgFile path bars =- do- let layout = applyBarPlot bars def :: Layout PlotIndex Int- let r = toRenderable layout :: Renderable ()- let fo = applyFileOptions bars def :: FileOptions- _ <- renderableToFile fo path r- return ()+writeBarGraphSvgFile path bars = void $ renderableToFile fo path r+ where+ layout = applyBarPlot bars def :: Layout PlotIndex Int+ r = toRenderable layout :: Renderable ()+ fo = applyFileOptions bars def :: FileOptions type Bars = [(String, Int)] @@ -41,29 +36,28 @@ where l = genericLength --- | Add a single bar plot to a layout, configure its X axis labels to match the data, and style the layout to look nice with a bar plot.+-- | Add a single bar plot to a layout, configure its X axis labels to+-- match the data, and style the layout to look nice with a bar plot applyBarPlot :: Bars -> Endo (Layout PlotIndex Int)-applyBarPlot bars =- foldEndo+applyBarPlot bars = foldEndo [ applyLayoutStyle , applyLabels bars , set layout_plots [plotBars (( applyBarStyle . applyValues bars ) def)] ] --- | Set the data values on a bar plot.+-- | Set the data values on a bar plot applyValues :: Bars -> Endo (PlotBars PlotIndex Int) applyValues bars = set plot_bars_values (addIndexes [ [y] | (_, y) <- bars ]) --- | Set up the X axis of a layout in preparation for adding the bar plot.+-- | Set up the X axis of a layout in preparation for adding the bar plot applyLabels :: Integral x => Bars -> Endo (Layout x y) applyLabels bars = set (layout_x_axis . laxis_generate) (autoIndexAxis [ x | (x, _) <- bars ]) --- | Set some layout styles that look nice.+-- | Set some layout styles that look nice applyLayoutStyle :: Endo (Layout x y)-applyLayoutStyle =- foldEndo+applyLayoutStyle = foldEndo [ set layout_margin 40 , setAxisLineWidth 5 , over yGridStyle (set line_width 5 . set line_dashes [40, 20])@@ -84,22 +78,21 @@ axisLabelSize :: Lens' (LayoutAxis x) Double axisLabelSize = laxis_style . axis_label_style . font_size --- | Set the line width on both axes.+-- | Set the line width on both axes setAxisLineWidth :: Double -> Endo (Layout x y) setAxisLineWidth v = foldEndo [ set l v | l <- [ layout_x_axis . axisLineWidth , layout_y_axis . axisLineWidth ] ] --- | Set the label size on both axes.+-- | Set the label size on both axes setAxisFontSize :: Double -> Endo (Layout x y) setAxisFontSize v = foldEndo [ set l v | l <- [ layout_x_axis . axisLabelSize , layout_y_axis . axisLabelSize ] ] --- | Set some bar styles that look nice.+-- | Set some bar styles that look nice applyBarStyle :: Endo (PlotBars x y)-applyBarStyle =- foldEndo+applyBarStyle = foldEndo [ set plot_bars_spacing (BarsFixGap 80 20) , set plot_bars_item_styles [(FillStyleSolid (opaque steelblue), Nothing)] ]
+ readme.md view
@@ -0,0 +1,5 @@+The purpose of this library is to generate okay-looking bar plots for you+without much effort on your part. The style of the plots may change in newer+releases as we find ways to make them look nicer. If happy-hour generates a plot+for you that is not aesthetically pleasing, please let us know so that we may+improve.