packages feed

diagrams-lib-0.4.0.1 / src / Diagrams / TwoD / Model.hs

{-# LANGUAGE FlexibleContexts  #-}------------------------------------------------------------------------------- |-- Module      :  Diagrams.TwoD.Model-- Copyright   :  (c) 2011 diagrams-lib team (see LICENSE)-- License     :  BSD-style (see LICENSE)-- Maintainer  :  diagrams-discuss@googlegroups.com---- Tools for visualizing diagrams' internal model: local origins,-- bounding regions, etc.-------------------------------------------------------------------------------module Diagrams.TwoD.Model       ( -- * Showing the local origin         showOrigin       , showLabels       ) whereimport Graphics.Rendering.Diagramsimport Graphics.Rendering.Diagrams.Namesimport Diagrams.TwoD.Typesimport Diagrams.TwoD.Ellipseimport Diagrams.TwoD.Size    (size2D)import Diagrams.TwoD.Textimport Diagrams.Attributesimport Diagrams.Utilimport Control.Arrow (second)import Data.Monoidimport Data.AffineSpace ((.-.))import qualified Data.Map as Mimport Data.Colour.Names-------------------------------------------------------------- Marking the origin-------------------------------------------------------------- | Mark the origin of a diagram by placing a red dot 1/50th its size.showOrigin :: (Renderable Ellipse b, Backend b R2, Monoid m)           => AnnDiagram b R2 m -> AnnDiagram b R2 mshowOrigin d = o <> d  where o     = circle (max (w/50) (h/50))                # fc red                # lw 0                # fmap (const mempty)        (w,h) = size2D d-- data OriginOpts b m = OriginOpts { oDia   :: AnnDiagram b R2 m--                                  , oScale :: Double--                                  }-- showOrigin' (OriginOpts o s) d = o' <> d--   where o' = o # scale (max (w * s) (h * s))--         (w,h) = size2D d-------------------------------------------------------------- Labeling named points------------------------------------------------------------showLabels :: (Renderable Text b, Backend b R2)           => AnnDiagram b R2 m -> AnnDiagram b R2 AnyshowLabels d = (mconcat             . map (\(n,p) -> text (show n) # translate (p .-. origin))             . concatMap (\(n,ps) -> zip (repeat n) ps)             . (map . second . map) fst             . M.assocs             $ m)               `atop`               (fmap (const (Any False)) d)  where    NameMap m = names d-- XXX finish:--   Draw the separating lines between diagrams composed with 'beside'--   (or any combinators implemented in terms of 'beside', like '(|||)'--   or '(===)').-- showSep :: AnnDiagram b R2 m -> AnnDiagram b R2 m-- showSep d = s <> d--   where ... = case d of--                 AnnDiagram (Branch u ds children) -> ...