Git Product home page Git Product logo

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

Contributors

bergey avatar byorgey avatar jeffreyrosenbluth avatar johnlato avatar jonashaag avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diagrams-gtk's Issues

Failure to compile with GHC 8.6

This backend has an constraint on the version of base that prevents installation with base >= 4.12, distributed with GHC versions >= 8.6

Install fails

Here is the output of trying to install diagrams-gtk:

$ cabal install diagrams-gtk
Resolving dependencies...
Notice: installing into a sandbox located at
/home/sk/prg/diagrams/.cabal-sandbox
Configuring cairo-0.13.3.0...
Configuring glib-0.13.4.0...
Failed to install cairo-0.13.3.0
Build log ( /home/sk/prg/diagrams/.cabal-sandbox/logs/cairo-0.13.3.0.log ):
Failed to install glib-0.13.4.0
Build log ( /home/sk/prg/diagrams/.cabal-sandbox/logs/glib-0.13.4.0.log ):
cabal: Error: some packages failed to install:
cairo-0.13.3.0 failed during the configure step. The exception was:
user error ('/usr/bin/ghc' exited with an error:

/tmp/cabal-tmp-18504/cairo-0.13.3.0/dist/dist-sandbox-df16c69b/setup/setup.hs:5:8:
Could not find module ‘Gtk2HsSetup’
Use -v to see a list of the files searched for.
)
diagrams-cairo-1.3.0.6 depends on glib-0.13.4.0 which failed to install.
diagrams-gtk-1.3.0.1 depends on glib-0.13.4.0 which failed to install.
gio-0.13.3.0 depends on glib-0.13.4.0 which failed to install.
glib-0.13.4.0 failed during the configure step. The exception was:
user error ('/usr/bin/ghc' exited with an error:

/tmp/cabal-tmp-18505/glib-0.13.4.0/dist/dist-sandbox-df16c69b/setup/setup.hs:5:8:
Could not find module ‘Gtk2HsSetup’
Use -v to see a list of the files searched for.
)
gtk-0.14.4 depends on glib-0.13.4.0 which failed to install.
pango-0.13.3.0 depends on glib-0.13.4.0 which failed to install.

The log files are empty. I have tired this after successfully doing

$ cabal install cabal
$ cabal install diagrams

Actually I was forced to cabal install cabal as without there was a complaint about an outdated cabal library.

All this happened on an up-to-date Arch Linux.

gtk-0.13 compatibility

Hi,

gtk-0.13 has been uploaded to hackage, and is dependet upon by other projects. Please consider uploading a compatible package to hackage.

Thanks,
Joachim

Loosen version bounds on base (allow 4.16) for ghc 9.2

I've confirmed the package compiles successfully with:

  • ghc-9.2.5 / base-4.16.4.0
  • ghc-9.2.7 / base-4.16.4.0

And I've confirmed it works correctly in an actual program with:

  • ghc-9.2.5 / base-4.16.4.0

It'd probably be helpful to allow base-4.17 (ghc-9.4) too, though I don't have a working ghc 9.4 environment to test it with.

diagram upside down when rescaling when window resized

Sorry, I guess this example is pretty minimal, but it works..

If you replace the line marked FIRST with the line marked SECOND, then
the diagram flips upside down, and I have no idea why.

Any help would be helpful...
Stefan


> import Control.Monad.Trans ( liftIO )
> import Graphics.UI.Gtk
> import Diagrams.Backend.Cairo
> import Diagrams.Backend.Gtk
> import Diagrams.Prelude

> import           Diagrams.Prelude                hiding (height, width)
> import           Diagrams.Backend.Cairo.Internal
> import           Graphics.UI.Gtk
> import qualified Graphics.Rendering.Cairo        as CG



I was wondering why `defaultRender` requires a `DrawingArea` as
argument [1], but only gets a window from it to draw on [2].  In
contrast, `renderToGtk` is happy with a something of type
`DrawableClass dc => dc` [1].

Why is that?

Why would I want it differently?  I want to have a window that
rescales the diagram contents when it gets resized.  I'm a GUI-noob,
so I took GTK integration from [3]:

> main :: IO ()
> main
>   = do initGUI
>        canvas <- drawingAreaNew
>        canvas `on` sizeRequest $ return (Requisition 200 200)
>        canvas `on` exposeEvent $ renderFigure myFigure   -- below
>        window <- windowNew
>        Graphics.UI.Gtk.set window [ containerChild := canvas]
>        onDestroy window mainQuit
>        widgetShowAll window
>        mainGUI

> renderFigure :: Diagram B -> EventM EExpose Bool
> renderFigure dia = do
>    win <- eventWindow

>    liftIO . renderToGtk win . toGtkCoords $ scale 15 dia     -- FIRST

Above line does not rescale the diagram when the window is resized, so
I wanted to have something like the following:

  >    liftIO . defaultRender' win . toGtkCoords $ dia   -- SECOND

>    return True


Having a look at the sources [2], I decided that I could build such a
`defaultRender'` on my own, basically simplifying `defaultRender` from
[2]:

> defaultRender' :: (Monoid' m, DrawableClass dc)
>                => dc -> QDiagram Cairo V2 Double m -> IO ()
> defaultRender' drawable diagram
>   = renderDoubleBuffered drawable opts diagram
>   where
>     opts w h
>       = CairoOptions
>         { _cairoFileName     = ""
>         , _cairoSizeSpec     = dims (V2 (fromIntegral w) (fromIntegral h))
>         , _cairoOutputType   = RenderOnly
>         , _cairoBypassAdjust = False
>         }

Now if you exchange the two lines marked FIRST and SECOND above, then
this diagram actually scales nicely.  But why on earth is it upside
down?  In case you do not see this: On my machine it is mirrored on
the horizontal line!




To make the example work, I also copied the following 4 functions
from [2]...

> renderDoubleBuffered ::
>   (Monoid' m, DrawableClass dc) =>
>   dc -- ^ drawable to render onto
>   -> (Int -> Int -> Options Cairo V2 Double) -- ^ options, depending on drawable width and height
>   -> QDiagram Cairo V2 Double m -- ^ Diagram
>   -> IO ()
> renderDoubleBuffered drawable renderOpts diagram = do
>   (w,h) <- drawableGetSize drawable
>   let opts = renderOpts w h
>       renderAction = delete w h >> snd (renderDia Cairo opts diagram)
>   renderWithDrawable drawable (doubleBuffer renderAction)
> 
> delete :: Int -> Int -> CG.Render ()
> delete w h = do
>   CG.setSourceRGB 1 1 1
>   CG.rectangle 0 0 (fromIntegral w) (fromIntegral h)
>   CG.fill

> doubleBuffer :: CG.Render () -> CG.Render ()
> doubleBuffer renderAction = do
>   CG.pushGroup
>   renderAction
>   CG.popGroupToSource
>   CG.paint

...and took an example from diagram's tutorial [4].

> node :: Int -> Diagram B
> node n = text (show n) # fontSizeL 1 # fc white <> circle 1 # fc green

> myFigure :: Diagram B
> myFigure = atPoints (trailVertices $ regPoly 6 5) $ map node [1..]


____________________
[1] https://s3.amazonaws.com/haddock.stackage.org/lts-6.1/diagrams-gtk-1.3.0.1/Diagrams-Backend-Gtk.html
[2] https://s3.amazonaws.com/haddock.stackage.org/lts-6.1/diagrams-gtk-1.3.0.1/src/Diagrams-Backend-Gtk.html#defaultRender
[3] http://stackoverflow.com/questions/11885373/how-do-i-use-the-diagrams-library-with-gtk-drawables
[4] http://projects.haskell.org/diagrams/doc/quickstart.html

Add to stackage?

Hi,

while other diagrams packages are part of stackage, this is not. Is there a specific reason?

Greetings,
Joachim

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.