Git Product home page Git Product logo

diagrams-contrib's Introduction

Build Status

diagrams is a full-featured framework and domain-specific language (embedded in Haskell) for creating declarative vector graphics and animations.

This package is just a convenient wrapper around the diagrams-core, diagrams-lib, diagrams-svg, and diagrams-contrib packages, so they can be installed with a single cabal install --lib diagrams command.

The package also comes with flags to enable six different backends. The native SVG backend is enabled by the -fsvg flag and is enabled by default. If you don't want it, you must explicitly disable it with -f-svg.

The native postscript backend is disabled by default but can be enabled by the -fps flag.

The cairo backend is disabled by default but can be selected with the -fcairo flag. In addition, the GTK backend is based on the cairo backend (but split into a separate package to make installing the cairo backend easier). It can be selected with the fgtk flag.

The native rasterific backend which is disabled by default but can be selected with the -frasterific flag.

The native canvas backend which is disabled by default but can be selected with the -fcanvas flag.

Installation

cabal update && cabal install --lib diagrams

or, to get the postscript backend in addition to the SVG backend:

cabal update && cabal install --lib -fps diagrams

or, to get the cairo backend in addition to the SVG backend:

cabal update && cabal install gtk2hs-buildtools && cabal install --lib -fcairo diagrams

Reporting bugs

Issue trackers for all diagrams-related repositories are hosted under the diagrams organization on github. If you know the specific package containing the bug, report it in the issue tracker specific to that package (for example, diagrams-lib). Otherwise, just report the issue in the issue tracker for the general diagrams repository.

Further reading

For more information, including a gallery of examples, tutorial, and user manual, see the diagrams website. For help, join the #diagrams IRC channel on Freenode or the mailing list.

diagrams-contrib's People

Contributors

akhra avatar bergey avatar bgamari avatar byorgey avatar cchalmers avatar deepakjois avatar fryguybob avatar ggreif avatar idontgetoutmuch avatar isovector avatar jeffreyrosenbluth avatar mgsloan avatar nanonaren avatar nomeata avatar ocharles avatar phadej avatar pnutus avatar prash471 avatar ryanglscott avatar vaibhavsagar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diagrams-contrib's Issues

Turtle module produces double paths

This code:

import           Control.Monad             (replicateM_)
import           Diagrams.Prelude
import           Diagrams.TwoD.Path.Turtle
import           Text.Groom

main = putStrLn . groom $ mount 7 10

f d = forward (72 * d / 6)
r = right 90

draw p = sketchTurtle $ do
  setPenWidth 0.1
  p
  closeCurrent

mount w h = draw $ replicateM_ 2 $ do
  f (fromIntegral w * 6 + 1) ; r
  f (fromIntegral h * 6 + 1) ; r

produces this output:

Path{pathTrails =
       [Loc{loc = P (0.0 & 0.0),
            obj =
              Trail
                (Loop
                   (SegTree{getSegTree =
                              fromList
                                [Linear (OffsetClosed (516.0 & 0.0)),
                                 Linear (OffsetClosed (4.482207284879313e-14 & (-732.0))),
                                 Linear (OffsetClosed ((-516.0) & (-6.319177483600342e-14))),
                                 Linear (OffsetClosed ((-1.3446621854637937e-13) & 732.0))]})
                   (Linear OffsetOpen))},
        Loc{loc = P (0.0 & 0.0),
            obj =
              Trail
                (Line
                   (SegTree{getSegTree =
                              fromList
                                [Linear (OffsetClosed (516.0 & 0.0)),
                                 Linear (OffsetClosed (4.482207284879313e-14 & (-732.0))),
                                 Linear (OffsetClosed ((-516.0) & (-6.319177483600342e-14))),
                                 Linear (OffsetClosed ((-1.3446621854637937e-13) & 732.0))]}))}]}

As you can see this consists of a line and a loop tracing the same path.

Turtle stamp function

Hi, thanks for this library @mgsloan , it's really great!

I want a function which enables the turtle to render any diagram at its current location, with its current orientation.

I would call this function stamp, like the idea of using a rubber ink stamp on paper.

I think the stamp function should have this type signature?

stamp 
  :: (Renderable (Path V2 n) b, TypeableFloat n, OrderedField n, Monad m) 
  => QDiagram b V2 n Any 
  -> TurtleT n m ()

I'm going to try to write this stamp function. Do you know if anyone else has ever written it? Do you have any advice for writing it?

Reference:
http://hackage.haskell.org/package/diagrams-contrib-1.4.4/docs/Diagrams-TwoD-Path-Turtle.html

Possibly related: #5

union does not produce expected result when endpoints of a polygon overlap

In the following code ex4 unexpectedly produces an empty diagram.

{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.TwoD.Polygons
import qualified Diagrams.TwoD.Path.Boolean as B

rose n r1 r2 = polygon $ with
  & polyType   .~ PolyPolar (replicate n $ 1/8 @@ turn) (cycle [r1, r2])
  & polyOrient .~ NoOrient

roseWithNoOverlap = rose 7
roseWithOverlap   = rose 8

roseWithNoOverlapOrthoginal = roseWithNoOverlap 3 1
roseWithNoOverlapDiagonal   = roseWithNoOverlap 1 3
roseWithOverlapOrthoginal   = roseWithOverlap   3 1
roseWithOverlapDiagonal     = roseWithOverlap   1 3

ex d = stroke $ B.union Winding $ d <> circle 2

ex1, ex2, ex3, ex4, dia :: Diagram Cairo
ex1 = ex roseWithNoOverlapOrthoginal  -- works
ex2 = ex roseWithNoOverlapDiagonal    -- works: equiv to (ex1 # rotate (1/8 @@ turn))
ex3 = ex roseWithOverlapOrthoginal    -- works: equiv to ex1
ex4 = ex roseWithOverlapDiagonal      -- broken: produces nothing, expected quiv to ex2

dia = (ex1 ||| ex2) === (ex3 ||| ex4)
main = mainWith dia

Fix default monoidal annotation for closed 2D paths

(Imported from http://code.google.com/p/diagrams/issues/detail?id=17. Original issue from [email protected] on April 2, 2011, 06:13:46 PM UTC)

The stroke and strokeT methods create diagrams from paths and trails respectively. Currently the monoidal annotation they assign is (const (Any False)). However, for closed 2D paths the default annotation ought to test whether a given point lies inside the path. This is non-trivial but well-studied so there ought to be some existing algorithms that can be easily ported.

This is quite critical since pretty much every shape is ultimately based on paths, and without this the whole monoidal annotation scheme is quite useless.

Metafont velocity function

I found out by spending to long time debugging, that metafont has set 4 as an upper limit to the
velocity function. I compared my code with yours, and I found that your code doesn't have the limit either (if I am not mistaken).

cycles with directions are not symmetric

These should produce the same result, but do not.

"(-3,0){1,0}..{1,0}(3,0)..(3,0.75)..(0,2)..(-3,0.75)..cycle"
"(0,0)..{1,0}(3,0)..(3,0.75)..(0,2)..(-3,0.75)..(-3,0){1,0}..cycle"

Orphan instance Wrapped (Point v)

There's a Wrapped instance for Points that clearly doesn't belong in diagrams-contrib, but I'm not sure where it belongs. I've considered:

  • It belongs in vector-space-points, where it's not an orphan, but adds a lens dependency.
  • It belongs in Diagrams.Core.Points (as I do in diagrams/diagrams-core@08257dd)
  • There shouldn't be a Wrapped instance, because we want people to think harder about the semantics of .-. origin. There should be an Iso with some more descriptive name.

Preferences?

Can't compile Diagrams/TwoD/Path/Follow.hs: No instance for Semigroup.

Steps to reproduce:

% stack init
% stack build
% cabal sandbox init
% cabal install
% # Alright?

Expected:

The package diagrams-contrib 1.4.2 builds, either with stack or cabal sandbox, preferably with both.

Actual:

The following error (amidst a bunch of warnings):

src/Diagrams/TwoD/Path/Follow.hs:64:21: error:
     No instance for (Semigroup (Semi (Trail' Line V2 n) (Angle n)))
        arising from the 'deriving' clause of a data type declaration
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
     When deriving the instance for (Semigroup (Following n))
   |
64 |   deriving (Monoid, Semigroup)
   |                     ^^^^^^^^^

-- Arises with either cabal sandbox or stack snapshot.

The stack snapshot chosen by stack init is lts-10.4.

Program versions:

% ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.2
% stack --version
Version 1.7.0, Git revision 2631803b9c502fa5225eac3536acda9d1d314aa7 (5619 commits) x86_64 hpack-0.20.0
% cabal --version
cabal-install version 2.0.0.1
compiled using version 2.0.1.1 of the Cabal library
% git log --oneline | head -n 1
c5617c7 specify cabal-version >= 1.18 for extra-doc-files

Build failure for new lens code

Configuring diagrams-contrib-0.6.0.1...
Dependency base ==4.5.1.0: using base-4.5.1.0
Dependency colour ==2.3.3: using colour-2.3.3
Dependency containers ==0.4.2.1: using containers-0.4.2.1
Dependency data-default ==0.5.0: using data-default-0.5.0
Dependency diagrams-lib ==0.6.0.1: using diagrams-lib-0.6.0.1
Dependency force-layout ==0.2: using force-layout-0.2
Dependency lens ==3.8.1: using lens-3.8.1
Dependency mtl ==2.1.2: using mtl-2.1.2
Dependency vector-space ==0.8.6: using vector-space-0.8.6
Using Cabal-1.16.0.3 compiled by ghc-7.4
Using compiler: ghc-7.4.2
Using install prefix: /var/lib/jenkins/jobs/stackage/workspace/.cabal
Binaries installed in: /var/lib/jenkins/jobs/stackage/workspace/sandbox/bin
Libraries installed in:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/lib/diagrams-contrib-0.6.0.1/ghc-7.4.2
Private binaries installed in:
/var/lib/jenkins/jobs/stackage/workspace/.cabal/libexec
Data files installed in:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/share/diagrams-contrib-0.6.0.1
Documentation installed in:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/share/doc/diagrams-contrib-0.6.0.1
Using alex version 3.0.2 found on system at:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/bin/alex
Using ar found on system at: /usr/bin/ar
No c2hs found
Using cpphs version 1.15 found on system at:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/bin/cpphs
No ffihugs found
Using gcc version 4.6 found on system at: /usr/bin/gcc
Using ghc version 7.4.2 found on system at: /opt/ghc-7.4.2/bin/ghc
Using ghc-pkg version 7.4.2 found on system at: /opt/ghc-7.4.2/bin/ghc-pkg
No greencard found
Using haddock version 2.11.0 found on system at: /opt/ghc-7.4.2/bin/haddock
Using happy version 1.18.10 found on system at:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/bin/happy
No hmake found
Using hpc version 0.6 found on system at: /opt/ghc-7.4.2/bin/hpc
Using hsc2hs version 0.67 found on system at: /opt/ghc-7.4.2/bin/hsc2hs
Using hscolour version 1.20 found on system at:
/var/lib/jenkins/jobs/stackage/workspace/sandbox/bin/HsColour
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
No nhc98 found
Using pkg-config version 0.26 found on system at: /usr/bin/pkg-config
Using ranlib found on system at: /usr/bin/ranlib
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /bin/tar
No uhc found
creating dist/build
creating dist/build/autogen
Building diagrams-contrib-0.6.0.1...
Preprocessing library diagrams-contrib-0.6.0.1...
Building library...
creating dist/build
/opt/ghc-7.4.2/bin/ghc --make -fbuilding-cabal-package -O -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -package-name diagrams-contrib-0.6.0.1 -hide-all-packages -no-user-package-conf -package-conf /var/lib/jenkins/jobs/stackage/workspace/sandbox/package-db -package-conf dist/package.conf.inplace -package-id base-4.5.1.0-66f22db3dfcd87541c9c7e50e7095d26 -package-id colour-2.3.3-91bd43851dbd747d8aaeee02fcf27c27 -package-id containers-0.4.2.1-75f143aa39a3e77a1ce2300025bdd8ce -package-id data-default-0.5.0-3f2342d47b82639c0ef7a179feefe779 -package-id diagrams-lib-0.6.0.1-6ea5ae4be5c427f03062726bc597724f -package-id force-layout-0.2-84494cf07d6a2cf3a20665870a435a35 -package-id lens-3.8.1-6a142fdbb4caa4c54c50c8db48d12eb1 -package-id mtl-2.1.2-02e701f9b1590ee88a0b5b0bd5d93a29 -package-id vector-space-0.8.6-7c842f3485b31276d26fae24664ca41e -XHaskell2010 Diagrams.Layout.Wrap Diagrams.TwoD.Tilings Diagrams.TwoD.Apollonian Diagrams.TwoD.Layout.Tree Diagrams.TwoD.Path.Turtle Diagrams.TwoD.Path.Turtle.Aliases Diagrams.TwoD.Path.Turtle.Internal -Wall
[1 of 7] Compiling Diagrams.TwoD.Path.Turtle.Internal ( src/Diagrams/TwoD/Path/Turtle/Internal.hs, dist/build/Diagrams/TwoD/Path/Turtle/Internal.o )
[2 of 7] Compiling Diagrams.TwoD.Path.Turtle ( src/Diagrams/TwoD/Path/Turtle.hs, dist/build/Diagrams/TwoD/Path/Turtle.o )
[3 of 7] Compiling Diagrams.TwoD.Path.Turtle.Aliases ( src/Diagrams/TwoD/Path/Turtle/Aliases.hs, dist/build/Diagrams/TwoD/Path/Turtle/Aliases.o )
[4 of 7] Compiling Diagrams.TwoD.Layout.Tree ( src/Diagrams/TwoD/Layout/Tree.hs, dist/build/Diagrams/TwoD/Layout/Tree.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.0 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package extensible-exceptions-0.1.1.4 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package MonadCatchIO-transformers-0.3.0.0 ... linking ... done.
Loading package nats-0.1 ... linking ... done.
Loading package semigroups-0.9 ... linking ... done.
Loading package comonad-3.0.1.1 ... linking ... done.
Loading package contravariant-0.2.0.2 ... linking ... done.
Loading package semigroupoids-3.0.1 ... linking ... done.
Loading package bifunctors-3.0.3 ... linking ... done.
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package transformers-compat-0.1 ... linking ... done.
Loading package distributive-0.3 ... linking ... done.
Loading package comonad-transformers-3.0.1 ... linking ... done.
Loading package mtl-2.1.2 ... linking ... done.
Loading package comonads-fd-3.0.1 ... linking ... done.
Loading package filepath-1.3.0.0 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package generic-deriving-1.4.0 ... linking ... done.
Loading package text-0.11.2.3 ... linking ... done.
Loading package hashable-1.1.2.5 ... linking ... done.
Loading package parallel-3.2.0.3 ... linking ... done.
Loading package tagged-0.4.4 ... linking ... done.
Loading package profunctors-3.2 ... linking ... done.
Loading package groupoids-3.0.1.1 ... linking ... done.
Loading package semigroupoid-extras-3.0.1 ... linking ... done.
Loading package profunctor-extras-3.3 ... linking ... done.
Loading package split-0.2.1.1 ... linking ... done.
Loading package unordered-containers-0.2.3.0 ... linking ... done.
Loading package primitive-0.5.0.1 ... linking ... done.
Loading package vector-0.10.0.1 ... linking ... done.
Loading package lens-3.8.1 ... linking ... done.
Loading package newtype-0.2 ... linking ... done.
Loading package Boolean-0.1.2 ... linking ... done.
Loading package void-0.5.11 ... linking ... done.
Loading package MemoTrie-0.6.1 ... linking ... done.
Loading package NumInstances-1.0 ... linking ... done.
Loading package vector-space-0.8.6 ... linking ... done.
Loading package vector-space-points-0.1.2.0 ... linking ... done.
Loading package force-layout-0.2 ... linking ... done.
Loading package active-0.1.0.3 ... linking ... done.
Loading package colour-2.3.3 ... linking ... done.
Loading package dlist-0.5 ... linking ... done.
Loading package old-locale-1.0.0.4 ... linking ... done.
Loading package data-default-0.5.0 ... linking ... done.
Loading package monoid-extras-0.2.2.2 ... linking ... done.
Loading package dual-tree-0.1.0.1 ... linking ... done.
Loading package diagrams-core-0.6.0.1 ... linking ... done.
Loading package diagrams-lib-0.6.0.1 ... linking ... done.

src/Diagrams/TwoD/Layout/Tree.hs:480:25:
    Ambiguous occurrence `moveTo'
    It could refer to either `Control.Lens.moveTo',
                             imported from `Control.Lens' at src/Diagrams/TwoD/Layout/Tree.hs:112:1-29
                             (and originally defined in `Control.Lens.Internal.Zipper')
                          or `Diagrams.Prelude.moveTo',
                             imported from `Diagrams.Prelude' at src/Diagrams/TwoD/Layout/Tree.hs:124:1-55
                             (and originally defined in `diagrams-core-0.6.0.1:Diagrams.Core.HasOrigin')

Namespace conflict in Diagrams.TwoD.Layout.Tree

D:\diagrams-contrib\src\Diagrams\TwoD\Layout\Tree.hs: line 187, column 18:
  Ambiguous occurrence `Empty'
    It could refer to either `Diagrams.TwoD.Layout.Tree.Empty',
                             defined at src\Diagrams\TwoD\Layout\Tree.hs:182:16
                          or `Diagrams.Prelude.Empty',
                             imported from `Diagrams.Prelude' at src\Diagrams\TwoD\Layout\Tree.hs:163:1-33
                             (and originally defined in `Control.Lens.Empty')
D:\diagrams-contrib\src\Diagrams\TwoD\Layout\Tree.hs: line 187, column 24:
  Ambiguous occurrence `Empty'
    It could refer to either `Diagrams.TwoD.Layout.Tree.Empty',
                             defined at src\Diagrams\TwoD\Layout\Tree.hs:182:16
                          or `Diagrams.Prelude.Empty',
                             imported from `Diagrams.Prelude' at src\Diagrams\TwoD\Layout\Tree.hs:163:1-33
                             (and originally defined in `Control.Lens.Empty')

Empty is both defined locally (for the BTree type) and imported from lens via Diagrams.Prelude. This breaks compilation for me, both from Hackage (1.3.0.6) and GitHub (1.3.1).

diagrams-contrib 1.1.0.1 fails to compile due to missing Default instance

[18 of 20] Compiling Diagrams.TwoD.Layout.Tree ( src/Diagrams/TwoD/Layout/Tree.hs, dist/dist-sandbox-14ce8ad3/build/Diagrams/TwoD/Layout/Tree.o )

src/Diagrams/TwoD/Layout/Tree.hs:448:26:
    No instance for (Default (ForceLayoutOpts R2))
      arising from a use of `def'
    Possible fix:
      add an instance declaration for (Default (ForceLayoutOpts R2))
    In the `_forceLayoutOpts' field of a record
    In the expression:
      FLTOpts
        {_forceLayoutOpts = def, _edgeLen = sqrt 2, _springK = 0.05,
         _staticK = 0.1}
    In an equation for `def':
        def
          = FLTOpts
              {_forceLayoutOpts = def, _edgeLen = sqrt 2, _springK = 0.05,
               _staticK = 0.1}
Failed to install diagrams-contrib-1.1.0.1

GHC 8.2 compatible release

After 4f554eb this package builds with GHC 8.2.

Unfortunately bumping cubicbezier made this package depend transitively (through MemoTrie) on newtype-generic.

After jcristovao/newtype-generics#14 is resolved (the maintainer hasn't responded to one pull request from Jan 2017 yet), this package builds and passes tests.

I think it should be safe to make the release anyway since MemoTrie doesn't put an upper bound on newtype-generics: https://hackage.haskell.org/package/MemoTrie

Name conflict with lens over `#`

src/Diagrams/TwoD/Layout/Tree.hs:480:23:
Ambiguous occurrence #' It could refer to eitherControl.Lens.#',
imported from Control.Lens' at src/Diagrams/TwoD/Layout/Tree.hs:112:1-54 (and originally defined inControl.Lens.Review')
or Diagrams.Prelude.#', imported fromDiagrams.Prelude' at src/Diagrams/TwoD/Layout/Tree.hs:124:1-55
(and originally defined in `Diagrams.Util')
Failed to install diagrams-contrib-0.6.0.2
cabal: Error: some packages failed to install:
diagrams-contrib-0.6.0.2 failed during the building phase. The exception was:
ExitFailure 1

Memory leak using gridWithHalves

I tried to make an nearly empty grid 1000 by 1000 cells, but after it used 40 GB of system memory I had to kill it. Sample code:

{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

module Main where

import Control.Lens hiding ((#))
import Data.Default
import Data.List
import Data.List.Split
import Data.Typeable
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
import Diagrams.TwoD

default (Int)

example :: Int -> Int -> [((Int, Int), (Double, Double), Colour Double)]
        -> Diagram B
example n m =
    foldr (\((x, y), (w, h), c) -> situate x y w h c)
        $ gridWithHalves n m
  where
    situate x y w h c =
        flip placeDiagramOnGrid [((x*2)+1, (y*2)+1) :: (Int, Int)]
            $ rect (w / fromIntegral n) (h / fromIntegral m)
                # alignTL
                # lc c
                # fc c

main :: IO ()
main = mainWith $ example 1000 1000 shapes
  where
    shapes = [ ((3, 4), (2, 2), black)
             , ((5, 7), (3, 1), red)
             ]

union does not produce expected result when used with difference

In the following code ex3 should be the union of the the star with the ring, but instead union just returns the equivilent of ex2.

{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.TwoD.Polygons
import qualified Diagrams.TwoD.Path.Boolean as B

rose r1 r2 = polygon $ with
  & polyType   .~ PolyPolar (replicate 7 $ 1/8 @@ turn) (cycle [r1, r2])
  & polyOrient .~ NoOrient

ex1, ex2, ex3 :: Diagram Cairo
ex1 = stroke $ B.union Winding $ rose 1 3 <> circle 2                                     -- works
ex2 = stroke $ rose 1 3 <> B.difference Winding (circle 2) (circle 1.9)                   -- works
ex3 = stroke $ B.union Winding $ rose 1 3 <> B.difference Winding (circle 2) (circle 1.9) -- broken

main = mainWith (ex1 ||| ex2 ||| ex3)

parser does not handle much of Plain Metafont

{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings         #-}

import           Diagrams.Backend.SVG.CmdLine
import           Diagrams.Coordinates
import           Diagrams.Prelude
import qualified Diagrams.TwoD.Path.Metafont  as MF

import           Data.Text

main =
   case (MF.fromString "(0,100)..(50,0)---(180,0)...{up}(200,100)") of
     Left err -> print err
     Right d  -> defaultMain (d # lw 1)

Support GHC 9.2

Currently, the lens constraint (<5.1) at first blocks the Cabal build with GHC 9.2.

Please allow diagrams-core-1.5

Since dhe diagrams-core has updated to version 1.5, diagrams-contrib should allow diagrams-core-1.5 in its dependencies.

Build error

Building diagrams-contrib inside a cabal sandbox gives me this error:

src/Diagrams/TwoD/Path/Metafont/Types.hs:36:15:
    Not in scope: type constructor or class `V2'
    Perhaps you meant one of these:
      `P2' (imported from Diagrams.TwoD.Types),
      `R2' (imported from Diagrams.TwoD.Types),
      `T2' (imported from Diagrams.TwoD.Types)

Let me know if you need additonal information. The commands I am running are simply:

cabal sandbox init
cabal install --only-dependencies -j4
cabal install arithmoi -f -llvm
cabal build

OS X 10.9, GHC v7.6.3

MetaFont: symmetric points result in non-symmetric spline

Consider the following path:

curve_trail = metafont path
  where
    z5 = p2 ( 10  , -12   )
    z6 = p2 (  7.5,  -7.5 )
    z7 = p2 (  4  ,  -7.5 )
    z8 = p2 (  7.5,  -7.5 )
    z9 = p2 ( 10  ,  -3   )
    path =
       z5 .--.
       z6 .- up -.
       z7 .--.
       z8 .--.
       endpt z9
    up = arriving $ V2 0 (-1)

it is vertically symmetric around z7. The MetaFont executable produces the following output:

MetaFont_beta_test

However, with this library, I get a lopsided result:

MetaFont_beta_test_diagrams

I know this library isn't aiming to replicate the exact MetaFont algorithm (that's of course fine), but I think it's producing an incorrect result here.

Iterated path intersection producing an empty path

Consider this code:

{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeFamilies              #-}

import           Diagrams.Backend.Rasterific.CmdLine
import           Diagrams.Path                       (pathPoints)
import           Diagrams.Prelude
import qualified Diagrams.TwoD.Path.Boolean          as B

circles :: [Path V2 Double]
circles = iterateN 3 (rotateBy (1/3)) (circle 1 # translateX 0.5)

circlesDia :: Diagram B
circlesDia = circles # mconcat # stroke

lensPath :: Path V2 Double
lensPath = B.intersection Winding (circles !! 0) (circles !! 1)

-- This path is empty, but shouldn't be
errorPath :: Path V2 Double
errorPath = B.intersection Winding lensPath (circles !! 2)

circlesDia looks like this:

intersecttest

lensPath, where we intersect two of the circles, seems to work just fine:

ghci> lensPath
Path [Trail (loopFromSegments [bézier3  (V2 0.0 0.5522847537627503) (V2 0.4477152358979708 0.9999999896607211) (V2 0.9999999896607211 0.9999999896607211),bézier3  (V2 2.5473641729772234e-2 0.0) (V2 5.0724894523808295e-2 (-9.525295140588863e-4)) (V2 7.572001755463481e-2 (-2.8238477147032315e-3)),bézier3  (V2 1.4118009150652533e-2 (-2.0710720954396966e-2)) (V2 2.7568578289016044e-2 (-4.210254217512088e-2)) (V2 4.030539915390208e-2 (-6.41634426386184e-2)),bézier3  (V2 9.092210446573079e-2 (-0.15748182886766793)) (V2 0.13414150901098587 (-0.32941456727689056)) (V2 0.13414150901098587 (-0.49906617986433355)),bézier3  (V2 0.0 (-0.3456025147218976)) (V2 (-0.1793561302610085) (-0.6817390198057306)) (V2 (-0.500166923134703) (-0.8669592239201048)),bézier3  (V2 (-0.1812747129406237) (-0.10465899252872746)) (V2 (-0.38169673076101307) (-0.14611212622688918)) (V2 (-0.57574692308545) (-0.13119745106074954))] (openCubic (V2 (-0.10994154936770223) 0.1605951373654329) (V2 (-0.17425306916009092) 0.354892307082874))) `at` P (V2 (-0.49999999483036056) 0.0)]

lens

But intersecting the resulting lensPath with the third circle produces the empty path:

ghci> errorPath
Path []

But it shouldn't be empty; we should get the Reuleaux triangle in the middle.

Tree rendering broken (or bad default for symmLayout)

Here's what is rendered using the default symmLayout (SVG) (code):

screen shot 2014-03-18 at 16 44 09

EDIT: Sorry, this shows seperators of 0.5, 1.5, 2.5, 3.5, 4.5, and 5.5. The default is 1, thus a mixture of the first and second trees in that picture.

This default should be so that it actually looks like a tree, not a bunch of nodes. In my case, it didn't even show more than one node because they all overlapped.

Btw, there seems to be something wrong with how a tree's envelope is calculated: When I annotate each of these trees using === ("some" # text), then this is the result (without the black line):

screen shot 2014-03-18 at 16 44 21
screen shot 2014-03-18 at 16 44 39

High-level library for constructing (Bezier-based) paths

(Imported from http://code.google.com/p/diagrams/issues/detail?id=18. Original issue from [email protected] on April 2, 2011, 06:25:22 PM UTC)

It is currently possible to construct a path with Bezier segments by specifying the control points directly. But it would be much nicer to have a higher-level interface for constructing them. For example:

  • Take a path with linear segments and "round off" the corners
  • Specify starting point, ending point, and "waypoints" possibly with a desired slope at each waypoint, and perhaps some notion of "tightness" to control the curves. See Metapost for some inspiration in this regard.
  • Other methods...?

diagrams-contrib install error on Haskell Platform 2013.2.0.0 on Windows

I am sorry for first posting this issue in diagrams/diagrams, but I guess diagrams/diagrams-contrib (here) is better, so here goes.

My quite fresh haskell platform works in every other way, I have several projects compiling and running fine with a lot of dependencies. However, on cabal install diagrams-contrib (or just diagrams) I have an error I haven't been able to resolve:

cabal install diagrams-contrib
[..several lines..]
[10 of 12] Compiling Diagrams.TwoD.Layout.Tree (src\Diagrams\TwoD\Layout\Tree.hs, dist\build\Diagrams\TwoD\Layout\Tree.o)
Loading package ghc-prim ... linking ... done.
[lots of more Loading package...]
Loading package numeric-extras-0.0.3 ... linking ... ghc.exe: C:\Users\syvken\AppData\Roaming\cabal\numeric-extras-0.0.3\ghc-7.6.3\HSnumeric-extras-0.0.3.o: 
unknown symbol _expm1'
ghc.exe: unable to load packagenumeric-extras-0.0.3'
Failed to install diagrams-contrib-0.7
cabal: Error: some packages failed to install:
diagrams-contrib-0.7 failed during the building phase. The exception was:
ExitFailure 1

Could anyone shed some light on this? diagrams-core and diagrams-lib installed fine, as well as svgfonts.

Can not build with stack

Hello.

I have a small project. I tried to build it with stack and I get the following error

[15 of 28] Compiling Diagrams.TwoD.Path.Follow ( src/Diagrams/TwoD/Path/Follow.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Diagrams/TwoD/Path/Follow.o )
    
    /tmp/stack30251/diagrams-contrib-1.4.3/src/Diagrams/TwoD/Path/Follow.hs:64:21: error:
        • No instance for (Semigroup (Semi (Trail' Line V2 n) (Angle n)))
            arising from the 'deriving' clause of a data type declaration
          Possible fix:
            use a standalone 'deriving instance' declaration,
              so you can specify the instance context yourself
        • When deriving the instance for (Semigroup (Following n))
       |
    64 |   deriving (Monoid, Semigroup)

Here is the stack.yaml

# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
#  name: custom-snapshot
#  location: "./custom-snapshot.yaml"
# resolver: lts-11.12
resolver: lts-10.10  # changed from the up


# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
#    git: https://github.com/commercialhaskell/stack.git
#    commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#   extra-dep: true
#  subdirs:
#  - auto-update
#  - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- .


# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:

- diagrams-1.4
- diagrams-core-1.4.1
- diagrams-lib-1.4.2.2
- diagrams-solve-0.1.1
- dual-tree-0.2.2
- diagrams-contrib-1.4.3
- diagrams-svg-1.4.2
- cubicbezier-0.6.0.5
- mfsolve-0.3.2.0
- fast-math-1.0.2
- newtype-generics-0.5.3


# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.6"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

and here is the package.yaml
name:                heathsim
version:             0.1.0.0
github:              "jdevoto/heathsim"
license:             BSD3
author:              "Jorge A. Devoto"
maintainer:          "[email protected]"
copyright:           "GNU"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            programing

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/jdevoto/heathsim#readme>

dependencies:
- base >= 4.7 && < 5
- diagrams # added

library:
  source-dirs: src

executables:
  heathsim-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - heathsim

tests:
  heathsim-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - heathsim

Thanks for any help

Remove arithmoi dependency

arithmoi is causing problems for diagrams builds, because it now enables LLVM by default, so it fails to install for anyone who doesn't have LLVM installed (i.e. almost everyone). However, we only use it for factoring very small numbers, which is kind of like shooting a fly with a Howitzer at close range. We should just remove arithmoi and write our own (simple, brute-force) factoring method.

Metafont broken

The following curve produces a diagram with sharp edges.

testCurve :: Path V2 Double
testCurve = metafont $
    (0 ^& 0) .--.  (1 ^& 0) .--.  (2 ^& 1) .--.  (0 ^& 2) .--.  cyclePath

It produces this image: http://i.imgur.com/1quade2.png

Ability to generate any PathLike with Turtle module

It used to be possible to generate any PathLike thing using the Turtle module. Now that it supports pen width and color, however, it outputs only diagrams. It would be nice to expose another function which ignores the pen width and color settings and simply outputs any PathLike, to make it possible to create paths using the turtle interface.

Build errors (ghc 7.6.3, haskell-platform 2013.2.0.0, Debian)

This is on Debian testing, ghc 7.6.3, haskell-platform 2013.2.0.0:

$ mkdir /tmp/test-diagrams
$ cd /tmp/test-diagrams
$ cabal sandbox init
Writing a default package environment file to
/tmp/test-diagrams/cabal.sandbox.config
Creating a new sandbox at /tmp/test-diagrams/.cabal-sandbox
$ cabal install diagrams
[stuff happening...]
[stuff happening...]

[18 of 20] Compiling Diagrams.TwoD.Layout.Tree ( src/Diagrams/TwoD/Layout/Tree.hs, dist/dist-sandbox-ec70b94b/build/Diagrams/TwoD/Layout/Tree.o )

src/Diagrams/TwoD/Layout/Tree.hs:448:26:
    No instance for (Default (ForceLayoutOpts R2))
      arising from a use of `def'
    Possible fix:
      add an instance declaration for (Default (ForceLayoutOpts R2))
    In the `_forceLayoutOpts' field of a record
    In the expression:
      FLTOpts
        {_forceLayoutOpts = def, _edgeLen = sqrt 2, _springK = 0.05,
         _staticK = 0.1}
    In an equation for `def':
        def
          = FLTOpts
              {_forceLayoutOpts = def, _edgeLen = sqrt 2, _springK = 0.05,
               _staticK = 0.1}
Failed to install diagrams-contrib-1.1.1.4
Configuring diagrams-svg-1.0.2.1...
Building diagrams-svg-1.0.2.1...
Preprocessing library diagrams-svg-1.0.2.1...

[stuff happening...]
[stuff happening...]

[3 of 3] Compiling Diagrams.Backend.SVG.CmdLine ( src/Diagrams/Backend/SVG/CmdLine.hs, dist/dist-sandbox-ec70b94b/build/Diagrams/Backend/SVG/CmdLine.o )
In-place registering diagrams-svg-1.0.2.1...
Creating package registration file: /tmp/pkgConf-diagrams-svg-1.0.21739.1
Installing library in
/tmp/test-diagrams/.cabal-sandbox/lib/x86_64-linux-ghc-7.6.3/diagrams-svg-1.0.2.1
Registering diagrams-svg-1.0.2.1...
Installed diagrams-svg-1.0.2.1
cabal: Error: some packages failed to install:
diagrams-1.1.0.1 depends on diagrams-contrib-1.1.1.4 which failed to install.
diagrams-contrib-1.1.1.4 failed during the building phase. The exception was:
ExitFailure 1

org-mode babel support

I'm wondering, if someone has thought about creating an org-mode babel plugin;
which could let you specify drawings inline org-documents.

In reports, I use org-mode and R a lot to plot stuff.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.