Git Product home page Git Product logo

diagrams'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's People

Contributors

byorgey avatar jeffreyrosenbluth avatar jhrcek avatar k0ral avatar mgsloan 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  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  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  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  avatar  avatar

diagrams's Issues

Fix order of import + LANGUAGE pragma in gallery examples

I am trying the example in the gallery page: http://projects.haskell.org/diagrams/gallery/Hilbert.html

I am using GHC 8.0.2

With and without the {-# LANGUAGE TypeFamilies #-} pragma I am getting this error when I compile:

  • Illegal equational constraint V t ~ V2
    (Use GADTs or TypeFamilies to permit this)
    • When checking the inferred type
      hilbert :: forall t a.
      (V t ~ V2, TrailLike t, Monoid t, Semigroup t, Num a,
      Transformable t, Eq a) =>
      a -> t

Sorry if this is due to my lack of knowing Haskell. I am new to this. Thank you.

Add Bug-reports field to all .cabal files

Prior to the 0.6 release someone should go through and add a Bug-reports field to the .cabal file of every diagrams-related package, linking to their respective issue trackers on github.

diagrams doesn't install with ghc 8.4.2

ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.2
cabal install -j5 diagrams
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: diagrams-1.4 (user goal)
[__1] trying: diagrams:+svg
[__2] trying: diagrams-svg-1.4.1.1 (dependency of diagrams +svg)
[__3] next goal: base (dependency of diagrams-svg)
[__3] rejecting: base-4.11.1.0/installed-4.1... (conflict: diagrams-svg =>
base>=4.3 && <4.11)
[__3] rejecting: base-4.11.1.0, base-4.11.0.0, base-4.10.1.0, base-4.10.0.0,
base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable
package requires installed instance)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, diagrams, diagrams-svg,
diagrams:svg, diagrams-cairo, diagrams-lib

Is this package actively maintained?

I see that it references older versions, for example diagrams-postscript is up to version 1.5 but this package does not pull it in.

If it is intended to keep this package active can you please bump the upper bounds? This would allow us to continue packaging it in gentoo.

Lens 4.4 breaks compilation

src/Diagrams/Parametric/Adjust.hs:59:11:
    Couldn't match type ‘Char’
                  with ‘template-haskell:Language.Haskell.TH.Syntax.Name’
    Expected type: [template-haskell:Language.Haskell.TH.Syntax.Name]
      Actual type: [Char]
    In the pattern: "_adjOptsvProxy__"
    In a case alternative: "_adjOptsvProxy__" -> Nothing
    In the expression:
      case label of {
        "_adjOptsvProxy__" -> Nothing
        _ -> Just (drop 1 label) }

src/Diagrams/Parametric/Adjust.hs:59:33:
    Couldn't match expected type ‘template-haskell:Language.Haskell.TH.Syntax.Name
                                  -> [Control.Lens.Internal.FieldTH.DefName]’
                with actual type ‘Maybe a0’
    In the expression: Nothing
    In a case alternative: "_adjOptsvProxy__" -> Nothing

src/Diagrams/Parametric/Adjust.hs:60:16:
    Couldn't match expected type ‘template-haskell:Language.Haskell.TH.Syntax.Name
                                  -> [Control.Lens.Internal.FieldTH.DefName]’
                with actual type ‘Maybe
                                    [template-haskell:Language.Haskell.TH.Syntax.Name]’
    Possible cause: ‘Just’ is applied to too many arguments
    In the expression: Just (drop 1 label)
    In a case alternative: _ -> Just (drop 1 label)

GHC 7.8.3 and the latest stable from Hackage

Formatted text

I've just converted a project from directly using the graphviz package to using diagrams-graphviz, and it's opened up a whole new world of options. But the one thing I'm missing is text formatting - my graphs have edges labelled by fairly complex logical expressions, which become much more readable with syntax highlighting.

After considering a few approaches, I've written a function for rendering a Diagram from a SimpleDocStream annotated with Styles, by splitting the text when formatting changes, and concatenating the resulting diagrams.

This approach is rather conceptually ugly, and only works well with monospace fonts. Seeing as I'm using the cairo backend, results would be nicer if I were able to more directly make use of pango.

There seem two major options:

  • Expose pango's rendering functionality directly in diagrams-cairo with a function along the lines of SomeOptionsType -> [PangoItem] -> Diagram Cairo. pango is already a dependency, but much of its power seems to be unused.
  • Add an annotated text type to diagrams-core, perhaps along the lines of prettyprinter's SimpleDocStream (mentioned above). Many of the other backends could probably implement rendering in a sensible way.

Edit: I meant to say, I'd be very interested in working on this as a PR if you think it's feasible.

cabal install needs the --lib flag

$ ~/hs$ cabal install diagrams
Resolving dependencies...
Up to date
Warning: You asked to install executables, but there are no executables in
target: diagrams. Perhaps you want to use --lib to install libraries instead.

Installs successfullyu with

$ cabal install --lib diagrams
Build profile: -w ghc-8.8.3 -O1

diagrams doesn't install with ghc 8.8.1

diagrams doesn't install with ghc 8.8.1, with --allow-new I get:

[71 of 73] Compiling Diagrams.Backend.CmdLine ( src/Diagrams/Backend/CmdLine.hs, dist/build/Diagrams/Backend/CmdLine.o )

src/Diagrams/Backend/CmdLine.hs:314:56: error:
• Could not deduce (MonadFail m) arising from a use of ‘hex’
from the context: Monad m
bound by the type signature for:
readHexColor :: forall (m :: * -> ).
(Applicative m, Monad m) =>
String -> m (AlphaColour Double)
at src/Diagrams/Backend/CmdLine.hs:306:1-76
Possible fix:
add (MonadFail m) to the context of
the type signature for:
readHexColor :: forall (m :: * -> ).
(Applicative m, Monad m) =>
String -> m (AlphaColour Double)
• In the second argument of ‘(<$>)’, namely ‘hex a b’
In the first argument of ‘(<
>)’, namely ‘sRGB <$> hex a b’
In the first argument of ‘(<
>)’, namely
‘sRGB <$> hex a b <> hex c d’
|
314 | [a,b,c,d,e,f,g,h] -> withOpacity <$> (sRGB <$> hex a b <
> hex c d <> hex e f) <> hex g h
| ^^^^^^^
cabal: Failed to build diagrams-lib-1.4.2.3 (which is required by
diagrams-1.4). See the build log above for details.

interactive diagrams

Just wanted to share here some thought on diagrams.
When I was using diagrams, the biggest hurdle was to get the right values and positions for objects.
For instance, the homepage example is:

hilbert 0 = mempty
hilbert n = hilbert' (n-1) # reflectY <> vrule 1
         <> hilbert  (n-1) <> hrule 1
         <> hilbert  (n-1) <> vrule (-1)
         <> hilbert' (n-1) # reflectX
  where
    hilbert' m = hilbert m # rotateBy (1/4)

diagram :: Diagram B
diagram = strokeT (hilbert 6) # lc silver
                              # opacity 0.3

How can I adjust the values (1/4, 0.3) quickly?

My first idea is to use ghcid integration, for a quick feedback loop.
I now use ghcid for all my projects. It can be configured to show you the resulting image, updated as soon as you change the code.

Another idea is to introduce some input control framework in the code.
For example:

hilbert' m = do
   value <- sliderWidget
   hilbert m # rotateBy value

This would give the user a slider widget, allowing him to change the angle of rotation "live".

Can't find Cocoa

Hello,
On Mac.

When building it fails because it can't find the Cocoa Framework. Any ideas?

diagrams-lib        > <command line>: can't load framework: Cocoa (not found)

Mac Big Sur

funny build error with cabal-install head (probably related to cabal-install rather than diagrams)

hey all,
when i cabal-install diagrams everything works fine till i hit installing the diagrams master package:

Building diagrams-0.6...
Preprocessing library diagrams-0.6...
In-place registering diagrams-0.6...
setup-Cabal-1.17.0-x86_64-osx-ghc-7.6.2: diagrams-0.6: Warning:
haddock-interfaces:
/private/var/folders/py/wgp_hj9d2rl3cx48yym_ynj00000gn/T/diagrams-0.6-92307/diagrams-0.6/dist/doc/html/diagrams/diagrams.haddock
doesn't exist or isn't a file
diagrams-0.6: Warning: haddock-html:
/private/var/folders/py/wgp_hj9d2rl3cx48yym_ynj00000gn/T/diagrams-0.6-92307/diagrams-0.6/dist/doc/html/diagrams
doesn't exist or isn't a directory
diagrams-0.6: cannot find libHSdiagrams-0.6.a on library path (use --force to
override)

likewise, when i try to run

cabal install diagrams -fcairo

i get a funny cabal build / type error as follows:

carter ~/.ghc » cabal install diagrams -fcairo                                                                                                    1 ↵
Resolving dependencies...
Downloading cairo-0.12.4...
Configuring cairo-0.12.4...
Failed to install cairo-0.12.4
Last 10 lines of the build log ( /Users/carter/.cabal/logs/cairo-0.12.4.log ):cabal: Error: some packages failed to install:
cairo-0.12.4 failed during the configure step. The exception was:
user error (
/var/folders/py/wgp_hj9d2rl3cx48yym_ynj00000gn/T/cairo-0.12.4-94576/cairo-0.12.4/SetupWrapper.hs:100:9:
Couldn't match expected type `(Compiler,
Distribution.System.Platform,
ProgramConfiguration)'
with actual type `(t0, ProgramConfiguration)'
In the pattern: (comp, conf)
In a stmt of a 'do' block:
(comp, conf) <- configCompiler
(Just GHC) Nothing Nothing defaultProgramConfiguration verbosity
In the second argument of `($)', namely
`do { debug verbosity "Setup script is out of date, compiling...";
(comp, conf) <- configCompiler
(Just GHC) Nothing Nothing defaultProgramConfiguration verbosity;
cabalLibVersion <- cabalLibVersionToUse comp conf;
let cabalPkgid
= PackageIdentifier (PackageName "Cabal") cabalLibVersion;
.... }'
)
diagrams-0.6 depends on cairo-0.12.4 which failed to install.
diagrams-cairo-0.6 depends on cairo-0.12.4 which failed to install.

these seem more cabal / cabal-install HEAD issues, but I've only encountered them thus far via diagrams, so I thought i'd at least report it here first because they impact diagrams possible users

Export Angle constructor

Since an angle is really and truly just a number, I think the Radians constructor should be exposed. I also think you should expose more instances:

deriving instance Num n => Num (Angle n)
deriving instance Real n => Real (Angle n)
deriving instance Fractional n => Fractional (Angle n)
deriving instance RealFrac n => RealFrac (Angle n)
deriving instance RealFloat n => RealFloat (Angle n)

Stack

Hi!
What is the status of using stack in Diagrams?
It would make things easier.

Stack import diagrams

When using stack

dependencies:
 - diagrams

in the package.yaml doesn't work and one has to depend on every diagrams

dependencies:
- diagrams
- diagrams-lib
- diagrams-contrib
- diagrams-svg
- diagrams-core

(thanks commercialhaskell/stack#3964 for the fix)

Is there a way to improve this situation on the diagrams side?
Mentioning this in the tutorial would also be nice.

Doc: links to Haddock

Just a small comment: it would be nice to have all functions in the tutorial as links to their Haddock documentation.
This would ease the navigation. Currently I have to Hoogle every function in the docs :)

Any references on the theory behind diagrams?

Hey, this package is amazing. I'm developing something similar for my PhD. I'd love to learn more about the theory behind the package. I'm developing something more math oriented, yet, since this is in Haskell, I imagine that there has been a lot of thought behind the category theoretical aspects of the package.

Hence, I was wondering if there is a paper or something besides the docs that go into more theoretical aspects.

Label beside arrow

I have some difficulty placing a label near the center of an arrow. I tried:

arrowBetween' (with & headLength .~ normal) (p2 (x1, y1)) (p2  (x2, y2)) ||| text "MyLabel"

However, the label is placed close to the origin, not close to the arrow.
Thanks

Allow diagrams-core 1.5

Seems there are no issues with compilation currently, but would maybe require a major version bump?

Diagrams doedn't compile with last version of Stackage

I tried to put this in my stack.yaml:

$ cat stack.yaml
resolver: lts-18.12
packages:
- .
extra-deps:
- diagrams-1.4
- diagrams-contrib-1.4
- diagrams-core-1.4
- diagrams-lib-1.4
- diagrams-svg-1.4

But it is not compiling (many version out of bound). It would be nice to have instructions on how to compile with stack :)
And which stackage LTS versions are compatible.
It seems that you are publishing V1.5 in this moment, right?

interactive (in the sense of JS-y stuff) diagrams?

Hi, this looks like a great library. Was just wondering: is it possible to use this to produce interactive, reactive diagrams that allow for things like:

  • redrawing dynamically when a user, e.g., clicks on a button in a browser
  • getting (customized) hover mouseovers over specific parts of the diagram

(This qn has some overlap with #28, but is, I think, really its own topic.)

Strangely deep <g> tags for a single SVG object

\begin{code}
{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine

blue_dotted :: Diagram B R2
blue_dotted = circle 1 # fc blue
                   # lw veryThick
                   # lc purple
                   # dashingG [0.2,0.05] 0

green_circle :: Diagram B R2
green_circle = circle 1 # fc green # lw none

red_circle :: Diagram B R2
red_circle = circle 1 # fc red # lw none

double_circle :: Diagram B R2
double_circle = green_circle ||| red_circle

square_one :: Diagram B R2
square_one = square 1 # fc aqua `atop` circle 1

example = square_one ||| double_circle ||| circle 1 # showOrigin
main = mainWith example
\end{code}

Produces the expected SVG visually, but the tags for individual circles seem to get fairly deep. Currently compiling diagrams from dev libraries in Debian 8. Version is 1.2-2: https://packages.debian.org/sid/libghc-diagrams-dev

Is this a known problem or even a problem at all?

Fancy L-systems

Do you have any plans for generalizing your L-system implementation to allow stochastic and parametric systems?

I have tinkered with this a bit, but got stuck when I tried to go 3D. I am not an experience Haskeller, but if you want to see my approach, here is a link to my github repo. I've mostly abandoned the project and would be happy to see it be of use to someone.

Unable to build dependencies

I following the quickstart tutorial and am unable to proceed past the build step due to the dependency JuicyPixels. Here is the build log.

Failed to build JuicyPixels-3.3.8.
Build log (
C:\cabal\logs\ghc-9.4.8\JuicyPixels-3.3.8-d0b6acc90ba048eb509563860bb12107f072db48.log
):
Preprocessing library for JuicyPixels-3.3.8..
Building library for JuicyPixels-3.3.8..
[ 1 of 30] Compiling Codec.Picture.InternalHelper ( src\Codec\Picture\InternalHelper.hs, dist\build\Codec\Picture\InternalHelper.o )
[ 2 of 30] Compiling Codec.Picture.Metadata.Exif ( src\Codec\Picture\Metadata\Exif.hs, dist\build\Codec\Picture\Metadata\Exif.o )
[ 3 of 30] Compiling Codec.Picture.Metadata ( src\Codec\Picture\Metadata.hs, dist\build\Codec\Picture\Metadata.o )
[ 4 of 30] Compiling Codec.Picture.Tiff.Internal.Types ( src\Codec\Picture\Tiff\Internal\Types.hs, dist\build\Codec\Picture\Tiff\Internal\Types.o )
[ 5 of 30] Compiling Codec.Picture.Tiff.Internal.Metadata ( src\Codec\Picture\Tiff\Internal\Metadata.hs, dist\build\Codec\Picture\Tiff\Internal\Metadata.o )
[ 6 of 30] Compiling Codec.Picture.Types ( src\Codec\Picture\Types.hs, dist\build\Codec\Picture\Types.o )
ghc-9.4.8.exe: C:\cabal\store\ghc-9.4.8\zlib-0.6.3.0-d7b05d7718523872fdadd1c222d053c479e70007\lib\libHSzlib-0.6.3.0-d7b05d7718523872fdadd1c222d053c479e70007.a(#6:Stream.o): Not a x86_64 PE+ file.
ghc-9.4.8.exe: Unknown COFF 4 type in getHeaderInfo.

: error:
loadArchive "C:\cabal\store\ghc-9.4.8\zlib-0.6.3.0-d7b05d7718523872fdadd1c222d053c479e70007\lib\libHSzlib-0.6.3.0-d7b05d7718523872fdadd1c222d053c479e70007.a": failed
cabal-3.6.2.0-p1.exe: Failed to build JuicyPixels-3.3.8 (which is required by
exe:Diagrams from Diagrams-0.1.0.0). See the build log above for details.

diagrams-contrib install error on Haskell Platform 2013.2.0.0 on Windows

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.

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.