packages feed

hyper-extra 0.2.0.2 → 0.3.0.0

raw patch · 3 files changed

+125/−37 lines, 3 filesdep +Chartdep +Chart-diagramsPVP ok

version bump matches the API change (PVP)

Dependencies added: Chart, Chart-diagrams

API changes (from Hackage documentation)

+ Hyper.Extra: chart :: ToRenderable a => a -> Graphic

Files

+ CHANGELOG.md view
@@ -0,0 +1,46 @@++# Revision history for `hyper-extra`++## v0.3.0.0 (2025-10-21)++Added++* The `chart` function plots charts created with the `Chart` package.++Changed++* The `dia` function now renders a diagram using absolute sizes, where one unit corresponds to `1px`. See+[#40](https://github.com/HeinrichApfelmus/hyper-haskell/issues/40).++## v0.2.0.2 (2025-10-19)++* Bump dependencies, modernize `.cabal` file.++## v0.2.0.1++* Bump dependencies++## v0.2.0.0++* Add preliminary support for the `svg-builder` package.+* Compatibility with GHC 8.8++## v0.1.1.0++* Add preliminary support for the `QuickCheck` package.++## v0.1.0.3++* Bump dependencies for compatibility with GHC 8.4++## v0.1.0.2++* Bump dependencies for compatibility with GHC 8.2++## v0.1.0.1++* Bump dependencies.++## v0.1.0.0++* Initial release.
hyper-extra.cabal view
@@ -1,45 +1,51 @@-cabal-version:      3.0-name:               hyper-extra-version:            0.2.0.2-synopsis:           Display instances for the HyperHaskell graphical Haskell interpreter+cabal-version: 3.0+name:          hyper-extra+version:       0.3.0.0+synopsis:+  Display instances for the HyperHaskell graphical Haskell interpreter+ description:   This package is part of the /HyperHaskell/ project and provides   visual representations for various data types, in particular   diagrams from the @diagrams@ package.   .-category:           Graphics, Pretty Printer-homepage:           https://github.com/HeinrichApfelmus/hyper-haskell-license:            BSD-3-Clause-license-file:       LICENSE -author:             Heinrich Apfelmus-maintainer:         Heinrich Apfelmus <apfelmus quantentunnel de>-copyright:          (c) Heinrich Apfelmus 2016-2024+category:      Graphics, Pretty Printer+homepage:      https://github.com/HeinrichApfelmus/hyper-haskell+license:       BSD-3-Clause+license-file:  LICENSE+author:        Heinrich Apfelmus+maintainer:    Heinrich Apfelmus <apfelmus quantentunnel de>+copyright:     (c) Heinrich Apfelmus 2016-2025+extra-doc-files:+  CHANGELOG.md -tested-with: -  , GHC == 8.10.7-  , GHC == 9.2.8-  , GHC == 9.4.7-  , GHC == 9.6.7-  , GHC == 9.8.4-  , GHC == 9.10.2-  , GHC == 9.12.2+tested-with:+  GHC ==8.10.7+   || ==9.2.8+   || ==9.4.7+   || ==9.6.7+   || ==9.8.4+   || ==9.10.2+   || ==9.12.2  source-repository head-  type:               git-  location:           https://github.com/HeinrichApfelmus/hyper-haskell.git-  subdir:             haskell/hyper-extra/+  type:     git+  location: https://github.com/HeinrichApfelmus/hyper-haskell.git+  subdir:   haskell/hyper-extra/  library-  hs-source-dirs:     src-  default-language:   Haskell2010+  hs-source-dirs:   src+  default-language: Haskell2010   build-depends:-    , base         >= 4.6     && < 4.22-    , diagrams-lib >= 1.3     && < 1.6-    , diagrams-svg >= 1.4     && < 1.6-    , hyper        >= 0.2     && < 0.3-    , QuickCheck   >= 2.3.0.2 && < 2.18-    , svg-builder  >= 0.1     && < 0.2-    , text         >= 0.11    && < 2.2-  exposed-modules:-    Hyper.Extra+    , base            >=4.6     && <4.22+    , Chart           >=1.8     && <2+    , Chart-diagrams  >=1.8     && <2+    , diagrams-lib    >=1.3     && <1.6+    , diagrams-svg    >=1.4     && <1.6+    , hyper           >=0.2     && <0.3+    , QuickCheck      >=2.3.0.2 && <2.18+    , svg-builder     >=0.1     && <0.2+    , text            >=0.11    && <2.2++  exposed-modules:  Hyper.Extra
src/Hyper/Extra.hs view
@@ -1,17 +1,20 @@ module Hyper.Extra (     -- * Synopsis     -- | Visual representation for various data types.-    +     -- * SVG     fromSvg,     -- * Diagrams     dia,+    -- * Charts+    chart,      -- * QuickCheck     hyperCheck,     ) where -import Hyper+import Hyper ( Graphic, html )+import System.IO.Unsafe ( unsafePerformIO )  import qualified Data.Text        as Text import qualified Data.Text.Lazy   as Text.Lazy@@ -20,20 +23,53 @@ import           Diagrams.Backend.SVG import qualified Graphics.Svg +import qualified Graphics.Rendering.Chart as Chart+ import qualified Test.QuickCheck  as Q+import qualified Graphics.Rendering.Chart.Backend.Diagrams as Chart  {-----------------------------------------------------------------------------     Integration of the `svg-builder` and `diagrams-svg` spackages ------------------------------------------------------------------------------} -- | Render a SVG document. -- This assumes that the argument is indeed a complete SVG document,--- i.e. an @<SVG>@ tag.s+-- i.e. an @<SVG>@ tag. fromSvg :: Graphics.Svg.Element -> Graphic fromSvg = html . Text.Lazy.toStrict . Graphics.Svg.renderText  -- | Render a diagram via SVG.+--+-- Uses absolute units:+-- one unit in the diagram corresponds to @1px@ in the rendered image.+--+-- To change the scale in your diagram before rendering, use 'scale'. dia :: QDiagram SVG V2 Double Any -> Graphic-dia = fromSvg . renderDia SVG (SVGOptions (mkWidth 250) Nothing (Text.pack "") [] True)+dia = fromSvg . renderDia SVG (SVGOptions sz Nothing (Text.pack "") [] True)+  where+    sz = mkSizeSpec2D Nothing Nothing++{-----------------------------------------------------------------------------+    Integration of the `Chart` package+------------------------------------------------------------------------------}+chartX, chartY, chartScale :: Double+chartScale = 1.3+chartX = 640 / chartScale+chartY = 480 / chartScale++-- | Create a global environment for rendering charts.+-- Essentially, this will load fonts.+globalChartEnv :: Chart.DEnv Double+globalChartEnv = unsafePerformIO $+    Chart.defaultEnv Chart.vectorAlignmentFns chartX chartY++-- | Render a chart via SVG.+--+-- The rendered image has size 640 x 480 px.+chart :: Chart.ToRenderable a => a -> Graphic+chart = dia+    . scale chartScale+    . fst . Chart.runBackend globalChartEnv+    . flip Chart.render (chartX, chartY) . Chart.toRenderable  {-----------------------------------------------------------------------------     Integration of the `QuickCheck` package