packages feed

Chart-diagrams 1.6 → 1.7

raw patch · 2 files changed

+45/−130 lines, 2 filesdep +svg-builderdep −lucid-svgdep ~Chartdep ~diagrams-svgPVP ok

version bump matches the API change (PVP)

Dependencies added: svg-builder

Dependencies removed: lucid-svg

Dependency ranges changed: Chart, diagrams-svg

API changes (from Hackage documentation)

- Graphics.Rendering.Chart.Backend.Diagrams: cBackendToEPSFile :: ChartBackend a -> DEnv Double -> FilePath -> IO a
- Graphics.Rendering.Chart.Backend.Diagrams: cBackendToEmbeddedFontSVG :: ChartBackend a -> DEnv Double -> (Svg (), a)
- Graphics.Rendering.Chart.Backend.Diagrams: cBackendToSVG :: ChartBackend a -> DEnv Double -> (Svg (), a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToEmbeddedFontSVG :: Renderable a -> Double -> Double -> IO (Svg (), PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToEmbeddedFontSVG' :: Renderable a -> DEnv Double -> (Svg (), PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToSVG :: Renderable a -> Double -> Double -> IO (Svg (), PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToSVG' :: Renderable a -> DEnv Double -> (Svg (), PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToSVGString :: Renderable a -> Double -> Double -> IO (ByteString, PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: renderableToSVGString' :: Renderable a -> DEnv Double -> (ByteString, PickFn a)
- Graphics.Rendering.Chart.Backend.Diagrams: cBackendToFile :: FileOptions -> ChartBackend a -> FilePath -> IO a
+ Graphics.Rendering.Chart.Backend.Diagrams: cBackendToFile :: FileOptions -> BackendProgram a -> FilePath -> IO a
- Graphics.Rendering.Chart.Backend.Diagrams: runBackend :: (Backend b V2 (N b), Renderable (Path V2 (N b)) b, TypeableFloat (N b), Metric (V b)) => DEnv (N b) -> ChartBackend a -> (QDiagram b V2 (N b) Any, a)
+ Graphics.Rendering.Chart.Backend.Diagrams: runBackend :: (Backend b V2 (N b), Renderable (Path V2 (N b)) b, TypeableFloat (N b), Metric (V b)) => DEnv (N b) -> BackendProgram a -> (QDiagram b V2 (N b) Any, a)

Files

Chart-diagrams.cabal view
@@ -1,5 +1,5 @@ Name: Chart-diagrams-Version: 1.6+Version: 1.7 License: BSD3 License-file: LICENSE Copyright: Jan Bracker, 2006-2014@@ -30,18 +30,18 @@                , time, mtl                , diagrams-core >= 1.3 && < 1.4                , diagrams-lib >= 1.2 && < 1.4-               , diagrams-svg >= 1.3.1 && < 1.4+               , diagrams-svg >= 1.4 && < 1.5                , diagrams-postscript >= 0.7 && < 1.4                , SVGFonts >= 1.4 && < 1.6                , colour >= 2.2.1 && < 2.4                , blaze-markup >= 0.7 && < 0.8-               , lucid-svg >= 0.4 && < 0.7+               , svg-builder >= 0.1 && < 0.2                , bytestring >= 0.9 && < 1.0                , operational >= 0.2.2 && < 0.3                , containers >= 0.4 && < 0.6                , data-default-class < 0.1                , lens >= 3.9 && < 4.14-               , Chart >= 1.6 && < 1.7+               , Chart >= 1.7 && < 1.8                , text   other-modules: Paths_Chart_diagrams   Exposed-modules:
Graphics/Rendering/Chart/Backend/Diagrams.hs view
@@ -21,21 +21,6 @@   , toFile   , cBackendToFile -  -- * EPS Utility Functions-  , cBackendToEPSFile--  -- * SVG Utility Functions-  , cBackendToSVG-  , cBackendToEmbeddedFontSVG-  , renderableToSVG-  , renderableToSVG'-  , renderableToSVGString-  , renderableToSVGString'--  -- * SVG Embedded Font Utility Functions-  , renderableToEmbeddedFontSVG-  , renderableToEmbeddedFontSVG'-   -- * Fonts   , loadSansSerifFonts   , loadCommonFonts@@ -76,8 +61,7 @@ import qualified Diagrams.Backend.Postscript as DEPS import qualified Diagrams.Backend.SVG as DSVG -import Lucid.Svg (renderBS)-import qualified Lucid.Svg as Svg+import qualified Graphics.Svg as Svg import qualified Text.Blaze.Renderer.Text as B  import qualified Graphics.SVGFonts as F@@ -132,108 +116,39 @@  -- | Generate an image file for the given drawing instructions, at the specified path. Size and -- format are set through the `FileOptions` parameter.-cBackendToFile :: FileOptions -> ChartBackend a -> FilePath -> IO a+cBackendToFile :: FileOptions -> BackendProgram a -> FilePath -> IO a cBackendToFile fo cb path = do-    fontSelector <- _fo_fonts fo-    let env = createEnv vectorAlignmentFns w h fontSelector-    case _fo_format fo of-      EPS -> do-        cBackendToEPSFile cb env path-      SVG -> do-        let (svg, a) = cBackendToSVG cb env-        BS.writeFile path (renderBS svg)-        return a-      SVG_EMBEDDED -> do-        let (svg,a) = cBackendToEmbeddedFontSVG cb env-        BS.writeFile path (renderBS svg)-        return a-  where-    (w,h) = _fo_size fo---- -------------------------------------------------------------------------- SVG Utility Functions--- --------------------------------------------------------------------------- | Output the given renderable to a string containing a SVG of the specifed size---   (in points) using the default environment.-renderableToSVGString :: Renderable a -> Double -> Double -> IO (BS.ByteString, PickFn a)-renderableToSVGString  r w h = do-  (svg, x) <- renderableToSVG r w h-  return (renderBS svg, x)---- | Output the given renderable to a string containing a SVG using the given environment.-renderableToSVGString' :: Renderable a -> DEnv Double -> (BS.ByteString, PickFn a)-renderableToSVGString'  r env =-  let (svg, x) = renderableToSVG' r env-  in (renderBS svg, x)---- | Output the given renderable as a SVG of the specifed size---   (in points) using the default environment.--renderableToSVG :: Renderable a -> Double -> Double -> IO (Svg.Svg (), PickFn a)-renderableToSVG r w h = do-   env <- defaultEnv vectorAlignmentFns w h-   return $ renderableToSVG' r env---- | Output the given renderable as a SVG using the given environment.-renderableToSVG' :: Renderable a -> DEnv Double -> (Svg.Svg (), PickFn a)-renderableToSVG' r env =-  let (w, h) = envOutputSize env-      (d, x) = runBackendR env r-      opts = DSVG.SVGOptions (D2.dims2D w h) Nothing T.empty-      svg = D.renderDia DSVG.SVG opts d-  in (svg, x)---- -------------------------------------------------------------------------- SVG Embedded Font Utility Functions--- --------------------------------------------------------------------------- | Output the given renderable as a SVG of the specifed size---   (in points) using the default environment.---   Font are embedded to save space.-renderableToEmbeddedFontSVG :: Renderable a -> Double -> Double -> IO (Svg.Svg (), PickFn a)-renderableToEmbeddedFontSVG r w h = do-  env <- defaultEnv vectorAlignmentFns w h-  return $ renderableToEmbeddedFontSVG' r env---- | Output the given renderable as a SVG using the given environment.---   Font are embedded to save space.-renderableToEmbeddedFontSVG' :: Renderable a -> DEnv Double -> (Svg.Svg (), PickFn a)-renderableToEmbeddedFontSVG' r env = cBackendToEmbeddedFontSVG (render r size) env-  where-    size = envOutputSize env--cBackendToEPSFile :: ChartBackend a -> DEnv Double -> FilePath -> IO a-cBackendToEPSFile cb env path = do-    let (w, h) = envOutputSize env-        (d, a) = runBackend env cb-        psOpts = DEPS.PostscriptOptions path (D2.dims2D w h) DEPS.EPS-    D.renderDia DEPS.Postscript psOpts d-    return a--cBackendToSVG :: ChartBackend a -> DEnv Double -> (Svg.Svg (), a)-cBackendToSVG cb env = (svg,a)-  where-    (w, h) = envOutputSize env-    (d, a) = runBackend env cb-    svg = D.renderDia DSVG.SVG (DSVG.SVGOptions (D2.dims2D w h) Nothing T.empty) d+  fontSelector <- _fo_fonts fo+  let env = createEnv vectorAlignmentFns w h fontSelector -cBackendToEmbeddedFontSVG :: ChartBackend a -> DEnv Double -> (Svg.Svg (), a)-cBackendToEmbeddedFontSVG cb env = (svg, x)+  case _fo_format fo of+    EPS -> do+      let (d, a) = runBackend env cb+          opts = DEPS.PostscriptOptions path (D2.dims2D w h) DEPS.EPS+      D.renderDia DEPS.Postscript opts d+      return a+    SVG -> do+      let (d, a) = runBackend env cb+          opts = DSVG.SVGOptions (D2.dims2D w h) Nothing T.empty [] True+          svg = D.renderDia DSVG.SVG opts d+      Svg.renderToFile path svg+      return a+    SVG_EMBEDDED -> do+      let+        (d, a, gs) = runBackendWithGlyphs env cb+        fontDefs = Just . Svg.toElement . B.renderMarkup+                   $ forM_ (M.toList gs) $ \((fFam, fSlant, fWeight), usedGs) -> do+                       let fs = envFontStyle env+                       let font = envSelectFont env $ fs { _font_name = fFam+                                                         , _font_slant = fSlant+                                                         , _font_weight = fWeight+                                                         }+                       makeSvgFont font usedGs+        svg = D.renderDia DSVG.SVG (DSVG.SVGOptions (D2.dims2D w h) fontDefs T.empty [] True) d+      Svg.renderToFile path svg+      return a   where-    (w, h) = envOutputSize env-    (d, x, gs) = runBackendWithGlyphs env cb-    fontDefs = Just . Svg.toHtml . B.renderMarkup-               $ forM_ (M.toList gs) $ \((fFam, fSlant, fWeight), usedGs) -> do-                   let fs = envFontStyle env-                   let font = envSelectFont env $ fs { _font_name = fFam-                                                     , _font_slant = fSlant-                                                     , _font_weight = fWeight-                                                     }-                   makeSvgFont font usedGs-                   -- M.Map (String, FontSlant, FontWeight) (S.Set String)-                   -- makeSvgFont :: (FontData, OutlineMap) -> Set.Set String -> S.Svg-    svg = D.renderDia DSVG.SVG (DSVG.SVGOptions (D2.dims2D w h) fontDefs T.empty) d+    (w,h) = _fo_size fo  -- ----------------------------------------------------------------------- -- Backend@@ -377,7 +292,7 @@ runBackend :: ( D.Backend b V2 (N b), D.Renderable (D.Path V2 (N b)) b               , D.TypeableFloat (N b), D.Metric (V b))            => DEnv (N b)        -- ^ Environment to start rendering with.-           -> ChartBackend a    -- ^ Chart render code.+           -> BackendProgram a    -- ^ Chart render code.            -> (D.QDiagram b V2 (N b) Any, a)    -- ^ The diagram. runBackend env m =   let (d, x) = evalState (runBackend' TextRenderSvg $ withDefaultStyle m) env@@ -389,7 +304,7 @@                         , D.Renderable (D2.Text (N b)) b                         , D.TypeableFloat (N b), D.Metric (V b))                      => DEnv (N b)        -- ^ Environment to start rendering with.-                     -> ChartBackend a    -- ^ Chart render code.+                     -> BackendProgram a    -- ^ Chart render code.                      -> ( D.QDiagram b V2 (N b) Any, a                         , M.Map (String, FontSlant, FontWeight) (S.Set String)) runBackendWithGlyphs env m =@@ -404,7 +319,7 @@   TextRenderSvg    :: TextRender b (D.Path V2 (N b))  runBackend' :: (D.Renderable (D.Path V2 (N b)) b, D.Renderable t b, D.TypeableFloat (N b))-            => TextRender b t -> ChartBackend a+            => TextRender b t -> BackendProgram a             -> DState (N b) (D.QDiagram b V2 (N b) Any, a) runBackend' tr m = eval tr $ view $ m   where@@ -425,7 +340,7 @@     eval tr (WithClipRegion r p :>>= f) = dWithClipRegion tr r  p <>= step tr f      step :: (D.Renderable (D.Path V2 (N b)) b, D.Renderable t b, D.TypeableFloat (N b))-         => TextRender b t -> (v -> ChartBackend a) -> v+         => TextRender b t -> (v -> BackendProgram a) -> v          -> DState (N b) (D.QDiagram b V2 (N b) Any, a)     step tr f v = runBackend' tr (f v) @@ -501,30 +416,30 @@          , D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)       => TextRender b t -> (DEnv (N b) -> DEnv (N b))       -> (D.QDiagram b V2 (N b) Any -> D.QDiagram b V2 (N b) Any)-      -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+      -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWith tr envF dF m = dLocal $ do   modify envF   (ma, a) <- runBackend' tr m   return (dF ma, a)  dWithTransform :: (D.TypeableFloat (N b), D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)-               => TextRender b t -> Matrix -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+               => TextRender b t -> Matrix -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWithTransform tr t = dWith tr id $ D.transform (toTransformation t)  dWithLineStyle :: (D.TypeableFloat (N b), D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)-               => TextRender b t -> LineStyle -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+               => TextRender b t -> LineStyle -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWithLineStyle tr ls = dWith tr id $ applyLineStyle ls  dWithFillStyle :: (D.TypeableFloat (N b), D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)-               => TextRender b t -> FillStyle -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+               => TextRender b t -> FillStyle -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWithFillStyle tr fs = dWith tr id $ applyFillStyle fs  dWithFontStyle :: (D.TypeableFloat (N b), D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)-               => TextRender b t -> FontStyle -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+               => TextRender b t -> FontStyle -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWithFontStyle tr fs = dWith tr (\e -> e { envFontStyle = fs }) $ id  dWithClipRegion :: (D.TypeableFloat (N b), D.Renderable (D.Path V2 (N b)) b, D.Renderable t b)-                => TextRender b t -> Rect -> ChartBackend a -> DState (N b) (D.QDiagram b V2 (N b) Any, a)+                => TextRender b t -> Rect -> BackendProgram a -> DState (N b) (D.QDiagram b V2 (N b) Any, a) dWithClipRegion tr clip = dWith tr id $ D2.clipBy (convertPath True $ rectPath clip)  -- -----------------------------------------------------------------------