Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chart-diagrams: Port to diagrams-1.3 #83

Merged
merged 6 commits into from
Jun 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart-cairo/Chart-cairo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library
, colour >= 2.2.1 && < 2.4
, data-default-class < 0.1
, operational >= 0.2.2 && < 0.3
, lens >= 3.9 && < 4.10
, lens >= 3.9 && < 4.12
, Chart >= 1.3 && < 1.5

Exposed-modules:
Expand Down
15 changes: 8 additions & 7 deletions chart-diagrams/Chart-diagrams.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ library
Build-depends: base >= 3 && < 5
, old-locale
, time, mtl
, diagrams-core >= 1.2 && < 1.3
, diagrams-lib >= 1.2 && < 1.3
, diagrams-svg >= 1.1 && < 1.2
, diagrams-postscript >= 0.7 && < 1.2
, SVGFonts >= 1.4 && < 1.5
, diagrams-core >= 1.3 && < 1.4
, diagrams-lib >= 1.2 && < 1.4
, diagrams-svg >= 1.3.1 && < 1.4
, diagrams-postscript >= 0.7 && < 1.4
, SVGFonts >= 1.4 && < 1.6
, colour >= 2.2.1 && < 2.4
, blaze-svg >= 0.3.3
, blaze-markup >= 0.7 && < 0.8
, lucid-svg >= 0.4 && < 0.5
, 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.10
, lens >= 3.9 && < 4.12
, Chart >= 1.3 && < 1.5
, text
other-modules: Paths_Chart_diagrams
Expand Down
387 changes: 205 additions & 182 deletions chart-diagrams/Graphics/Rendering/Chart/Backend/Diagrams.hs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions chart-tests/Chart-tests.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Executable harness
time,
mtl,
colour >= 2.2.1 && < 2.4,
lens >= 3.9 && < 4.10,
lens >= 3.9 && < 4.12,
data-default-class < 0.1,
bytestring >= 0.9 && < 1.0,
blaze-svg >= 0.3.3,
lucid-svg >= 0.3.3,
random >= 1.0,
containers >= 0.4 && <0.6,
old-time >= 1.0,
Expand All @@ -38,11 +38,11 @@ Executable harness
Chart-diagrams >= 1.3 && < 1.5,
gtk >= 0.9.11,
cairo >= 0.9.11,
diagrams-cairo >= 1.2 && < 1.3,
diagrams-svg >= 1.1 && < 1.2,
diagrams-postscript >= 0.7 && < 1.2,
diagrams-lib >= 1.2 && < 1.3,
diagrams-core >= 1.2 && < 1.3
diagrams-cairo >= 1.2 && < 1.4,
diagrams-svg >= 1.1 && < 1.4,
diagrams-postscript >= 0.7 && < 1.4,
diagrams-lib >= 1.2 && < 1.4,
diagrams-core >= 1.2 && < 1.4
Main-is: Main.hs
Hs-Source-Dirs: tests
Ghc-Options: -threaded
Expand Down
4 changes: 2 additions & 2 deletions chart-tests/tests/CompareFonts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import qualified Graphics.Rendering.Chart.Backend.Diagrams as BD
import qualified Graphics.Rendering.Chart.Backend.Cairo as BC

import Diagrams.Core ( renderDia )
import Diagrams.TwoD ( SizeSpec2D(..) )
import Diagrams.Prelude ( dims, V2(..) )
import Diagrams.Backend.Cairo hiding ( renderCairo )
import Diagrams.Backend.Cairo.Internal

Expand Down Expand Up @@ -95,4 +95,4 @@ renderDiagramsCairo :: (Int, Int) -> ChartBackend () -> IO (C.Render ())
renderDiagramsCairo (w,h) m = do
env <- BD.defaultEnv bitmapAlignmentFns (fromIntegral w) (fromIntegral h)
let (d, _) = BD.runBackend env m
return $ snd $ renderDia Cairo (CairoOptions "" (Dims (fromIntegral w) (fromIntegral h)) PNG True) d
return $ snd $ renderDia Cairo (CairoOptions "" (dims $ V2 (fromIntegral w) (fromIntegral h)) PNG True) d
4 changes: 2 additions & 2 deletions chart-tests/tests/DiagramsCairo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Graphics.Rendering.Chart.Backend
import Graphics.Rendering.Chart.Backend.Diagrams

import Diagrams.Core ( renderDia )
import Diagrams.TwoD ( SizeSpec2D(..) )
import Diagrams.Prelude ( dims, V2(..) )
import Diagrams.Backend.Cairo
import Diagrams.Backend.Cairo.Internal
import Graphics.Rendering.Chart.Renderable ( render, Renderable )
Expand All @@ -26,5 +26,5 @@ main1 args = do
renderDiagram (n,(w,h),ir) = do
let env' = env { envOutputSize = (fromIntegral w, fromIntegral h) }
(d, _) = runBackendR env' (ir 1.0)
fst $ renderDia Cairo (CairoOptions (n ++ ".png") (Dims (fromIntegral w) (fromIntegral h)) PNG False) d
fst $ renderDia Cairo (CairoOptions (n ++ ".png") (dims $ V2 (fromIntegral w) (fromIntegral h)) PNG False) d
showTests (fmap (\(x,_,_) -> x) allTests) renderDiagram
3 changes: 1 addition & 2 deletions chart-tests/tests/DiagramsEPS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Graphics.Rendering.Chart.Backend
import Graphics.Rendering.Chart.Backend.Diagrams

import Diagrams.Core ( renderDia )
import Diagrams.TwoD ( SizeSpec2D(..) )
import Graphics.Rendering.Chart.Renderable ( render, Renderable )
import qualified Diagrams.Backend.Postscript as DEPS

Expand All @@ -24,7 +23,7 @@ main1 args = do
env0 <- defaultEnv bitmapAlignmentFns 0 0
showTests (fmap (\(x,_,_) -> x) allTests) (renderDiagram env0)
where
renderDiagram :: DEnv -> (String, (Int, Int), T.LineWidth -> Renderable ()) -> IO ()
renderDiagram :: DEnv Double -> (String, (Int, Int), T.LineWidth -> Renderable ()) -> IO ()
renderDiagram env0 (n,(w,h),ir) = do
let cr = render (ir 0.25) (fromIntegral w, fromIntegral h)
env = env0{ envOutputSize = (fromIntegral w, fromIntegral h) }
Expand Down
7 changes: 3 additions & 4 deletions chart-tests/tests/DiagramsSVG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import Graphics.Rendering.Chart.Backend.Diagrams
import qualified Data.ByteString.Lazy as BS

import Diagrams.Core ( renderDia )
import Diagrams.TwoD ( SizeSpec2D(..) )
import Diagrams.Backend.SVG
import Graphics.Rendering.Chart.Renderable ( render, Renderable )
import Text.Blaze.Svg.Renderer.Utf8 ( renderSvg )
import Lucid.Svg ( renderBS )

import System.Environment ( getArgs )

Expand All @@ -27,11 +26,11 @@ main1 args = do
env0 <- defaultEnv bitmapAlignmentFns 0 0
showTests (fmap (\(x,_,_) -> x) allTests) (renderDiagram env0)
where
renderDiagram :: DEnv -> (String, (Int, Int), T.LineWidth -> Renderable ()) -> IO ()
renderDiagram :: DEnv Double -> (String, (Int, Int), T.LineWidth -> Renderable ()) -> IO ()
renderDiagram env0 (n,(w,h),ir) = do
let cr = render (ir 0.25) (fromIntegral w, fromIntegral h)
env = env0{ envOutputSize = (fromIntegral w, fromIntegral h) }
(svg, _) = cBackendToSVG cr env
path = n ++ ".svg"
putStrLn (path ++ "...")
BS.writeFile path (renderSvg svg)
BS.writeFile path (renderBS svg)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Graphics.Rendering.Chart.Backend
import Graphics.Rendering.Chart.Backend.Diagrams

import Diagrams.Core ( renderDia )
import Diagrams.TwoD ( SizeSpec2D(..) )
import Diagrams.Prelude ( dims, V2(..) )
import Diagrams.Backend.Cairo
import Diagrams.Backend.Cairo.Internal

Expand All @@ -19,4 +19,4 @@ render :: FilePath -> Int -> Int -> ChartBackend a -> IO ()
render f w h m = do
env <- defaultEnv bitmapAlignmentFns (fromIntegral w) (fromIntegral h)
let (d, _) = runBackend env m
fst $ renderDia Cairo (CairoOptions f (Dims (fromIntegral w) (fromIntegral h)) PNG False) d
fst $ renderDia Cairo (CairoOptions f (dims $ V2 (fromIntegral w) (fromIntegral h)) PNG False) d
File renamed without changes.
2 changes: 1 addition & 1 deletion chart/Chart.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library
Build-depends: base >= 3 && < 5
, old-locale
, time, mtl, array
, lens >= 3.9 && < 4.10
, lens >= 3.9 && < 4.12
, colour >= 2.2.1 && < 2.4
, data-default-class < 0.1
, mtl >= 2.0 && < 2.3
Expand Down
57 changes: 28 additions & 29 deletions chart/Graphics/Rendering/Chart/Geometry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module : Graphics.Rendering.Chart.Geometry
-- Copyright : (c) Tim Docker 2006, 2014
-- License : BSD-style (see chart/COPYRIGHT)
--
--
module Graphics.Rendering.Chart.Geometry
( -- * Points and Vectors
Rect(..)
Expand All @@ -12,7 +12,7 @@ module Graphics.Rendering.Chart.Geometry

, RectSize
, Range

, pointToVec

, mkrect
Expand All @@ -29,18 +29,18 @@ module Graphics.Rendering.Chart.Geometry
, RectEdge(..)
, Limit(..)
, PointMapFn

-- * Paths
, Path(..)
, lineTo, moveTo
, lineTo', moveTo'
, arc, arc'
, arcNeg, arcNeg'
, close

, foldPath
, makeLinesExplicit

-- * Matrices
, transformP, scaleP, rotateP, translateP
, Matrix(..)
Expand Down Expand Up @@ -134,11 +134,11 @@ intersectRect LMax r = r
intersectRect r LMax = r
intersectRect LMin _ = LMin
intersectRect _ LMin = LMin
intersectRect (LValue (Rect (Point x11 y11) (Point x12 y12)))
intersectRect (LValue (Rect (Point x11 y11) (Point x12 y12)))
(LValue (Rect (Point x21 y21) (Point x22 y22))) =
let p1@(Point x1 y1) = Point (max x11 x21) (max y11 y21)
p2@(Point x2 y2) = Point (min x12 x22) (min y12 y22)
in if x2 < x1 || y2 < y1
in if x2 < x1 || y2 < y1
then LMin
else LValue $ Rect p1 p2

Expand All @@ -149,14 +149,14 @@ type RectSize = (Double,Double)
-- | Make a path from a rectangle.
rectPointPath :: Rect -> [Point]
rectPointPath (Rect p1@(Point x1 y1) p3@(Point x2 y2)) = [p1,p2,p3,p4,p1]
where
where
p2 = (Point x1 y2)
p4 = (Point x2 y1)
-}

-- | Make a path from a rectangle.
rectPath :: Rect -> Path
rectPath (Rect p1@(Point x1 y1) p3@(Point x2 y2)) =
rectPath (Rect p1@(Point x1 y1) p3@(Point x2 y2)) =
let p2 = Point x1 y2
p4 = Point x2 y1
in moveTo p1 <> lineTo p2 <> lineTo p3 <> lineTo p4 <> close
Expand All @@ -166,35 +166,35 @@ rectPath (Rect p1@(Point x1 y1) p3@(Point x2 y2)) =
-- -----------------------------------------------------------------------

-- | The path type used by Charts.
--
--
-- A path can consist of several subpaths. Each
-- is started by a 'MoveTo' operation. All subpaths
-- are open, except the last one, which may be closed
-- using the 'Close' operation. When filling a path
-- all subpaths are closed implicitly.
--
--
-- Closing a subpath means that a line is drawn from
-- the end point to the start point of the subpath.
--
--
-- If a 'Arc' (or 'ArcNeg') is drawn a implicit line
-- from the last end point of the subpath is drawn
-- to the beginning of the arc. Another implicit line
-- is drawn from the end of an arc to the beginning of
-- the next path segment.
--
--
-- The beginning of a subpath is either (0,0) or set
-- by a 'MoveTo' instruction. If the first subpath is started
-- with an arc the beginning of that subpath is the beginning
-- of the arc.
data Path = MoveTo Point Path
data Path = MoveTo Point Path
| LineTo Point Path
| Arc Point Double Double Double Path
| ArcNeg Point Double Double Double Path
| End
| End
| Close

-- | Paths are monoids. After a path is closed you can not append
-- anything to it anymore. The empty path is open.
-- anything to it anymore. The empty path is open.
-- Use 'close' to close a path.
instance Monoid Path where
mappend p1 p2 = case p1 of
Expand All @@ -214,7 +214,7 @@ moveTo p = MoveTo p mempty
moveTo' :: Double -> Double -> Path
moveTo' x y = moveTo $ Point x y

-- | Move the paths pointer to the given location and draw a straight
-- | Move the paths pointer to the given location and draw a straight
-- line while doing so.
lineTo :: Point -> Path
lineTo p = LineTo p mempty
Expand All @@ -230,7 +230,7 @@ lineTo' x y = lineTo $ Point x y
-- is smaller then the start angle it is increased by multiples of
-- @2 * pi@ until is is greater or equal.
arc :: Point -- ^ Center point of the circle arc.
-> Double -- ^ Redius of the circle.
-> Double -- ^ Radius of the circle.
-> Double -- ^ Angle to start drawing at, in radians.
-> Double -- ^ Angle to stop drawing at, in radians.
-> Path
Expand Down Expand Up @@ -262,9 +262,9 @@ foldPath :: (Monoid m)
-> m -- ^ Close
-> Path -- ^ Path to fold
-> m
foldPath moveTo_ lineTo_ arc_ arcNeg_ close_ path =
foldPath moveTo_ lineTo_ arc_ arcNeg_ close_ path =
let restF = foldPath moveTo_ lineTo_ arc_ arcNeg_ close_
in case path of
in case path of
MoveTo p rest -> moveTo_ p <> restF rest
LineTo p rest -> lineTo_ p <> restF rest
Arc p r a1 a2 rest -> arc_ p r a1 a2 <> restF rest
Expand All @@ -276,25 +276,25 @@ foldPath moveTo_ lineTo_ arc_ arcNeg_ close_ path =
-- that otherwise would be implicit. See 'Path' for details
-- about what lines in paths are implicit.
makeLinesExplicit :: Path -> Path
makeLinesExplicit (Arc c r s e rest) =
makeLinesExplicit (Arc c r s e rest) =
Arc c r s e $ makeLinesExplicit' rest
makeLinesExplicit (ArcNeg c r s e rest) =
makeLinesExplicit (ArcNeg c r s e rest) =
ArcNeg c r s e $ makeLinesExplicit' rest
makeLinesExplicit path = makeLinesExplicit' path

-- | Utility for 'makeLinesExplicit'.
makeLinesExplicit' :: Path -> Path
makeLinesExplicit' End = End
makeLinesExplicit' Close = Close
makeLinesExplicit' (Arc c r s e rest) =
makeLinesExplicit' (Arc c r s e rest) =
let p = translateP (pointToVec c) $ rotateP s $ Point r 0
in lineTo p <> arc c r s e <> makeLinesExplicit' rest
makeLinesExplicit' (ArcNeg c r s e rest) =
makeLinesExplicit' (ArcNeg c r s e rest) =
let p = translateP (pointToVec c) $ rotateP s $ Point r 0
in lineTo p <> arcNeg c r s e <> makeLinesExplicit' rest
makeLinesExplicit' (MoveTo p0 rest) =
makeLinesExplicit' (MoveTo p0 rest) =
MoveTo p0 $ makeLinesExplicit' rest
makeLinesExplicit' (LineTo p0 rest) =
makeLinesExplicit' (LineTo p0 rest) =
LineTo p0 $ makeLinesExplicit' rest

-- -----------------------------------------------------------------------
Expand Down Expand Up @@ -345,12 +345,12 @@ instance Num Matrix where
negate = pointwise negate
abs = pointwise abs
signum = pointwise signum

fromInteger n = Matrix (fromInteger n) 0 0 (fromInteger n) 0 0

-- | Copied from Graphics.Rendering.Cairo.Matrix
{-# INLINE pointwise #-}
pointwise :: (Double -> Double) -> Matrix -> Matrix
pointwise :: (Double -> Double) -> Matrix -> Matrix
pointwise f (Matrix xx_ yx_ xy_ yy_ x0_ y0_) =
Matrix (f xx_) (f yx_) (f xy_) (f yy_) (f x0_) (f y0_)

Expand Down Expand Up @@ -392,4 +392,3 @@ adjoint (Matrix a b c d tx ty) =
invert :: Matrix -> Matrix
invert m@(Matrix xx_ yx_ xy_ yy_ _ _) = scalarMultiply (recip det) $ adjoint m
where det = xx_*yy_ - yx_*xy_