| 1 |
{-# LANGUAGE ConstraintKinds #-} |
| 2 |
{-# LANGUAGE FlexibleContexts #-} |
| 3 |
{-# LANGUAGE Rank2Types #-} |
| 4 |
{-# LANGUAGE TypeFamilies #-} |
| 5 |
|
| 6 |
{-# OPTIONS_GHC -fno-warn-unused-imports #-} |
| 7 |
-- for Data.Semigroup |
| 8 |
|
| 9 |
----------------------------------------------------------------------------- |
| 10 |
-- | |
| 11 |
-- Module : Diagrams.TwoD.Adjust |
| 12 |
-- Copyright : (c) 2011 diagrams-lib team (see LICENSE) |
| 13 |
-- License : BSD-style (see LICENSE) |
| 14 |
-- Maintainer : [email protected] |
| 15 |
-- |
| 16 |
-- A default diagram-adjustment implementation for two-dimensional |
| 17 |
-- diagrams, useful for backend implementors. |
| 18 |
-- |
| 19 |
----------------------------------------------------------------------------- |
| 20 |
|
| 21 |
module Diagrams.TwoD.Adjust |
| 22 |
( setDefault2DAttributes |
| 23 |
, adjustSize2D |
| 24 |
, adjustDia2D |
| 25 |
) where |
| 26 |
|
| 27 |
import Diagrams.Attributes |
| 28 |
import Diagrams.BoundingBox |
| 29 |
import Diagrams.Core |
| 30 |
import Diagrams.Size |
| 31 |
import Diagrams.TwoD.Attributes (lineTextureA) |
| 32 |
import Diagrams.TwoD.Types |
| 33 |
import Diagrams.Util (( # )) |
| 34 |
|
| 35 |
import Control.Lens (Lens', set, (^.)) |
| 36 |
import Data.Default |
| 37 |
import Data.Semigroup |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
setDefault2DAttributes :: (TypeableFloat n, Semigroup m) |
| 53 |
=> QDiagram b V2 n m -> QDiagram b V2 n m |
| 54 |
setDefault2DAttributes d |
| 55 |
= d # lineWidthM def |
| 56 |
# lineTextureA def |
| 57 |
# lineCap def |
| 58 |
# lineJoin def |
| 59 |
# lineMiterLimitA def |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
adjustSize2D |
| 69 |
:: (TypeableFloat n, Monoid' m) |
| 70 |
=> Lens' (Options b V2 n) (SizeSpec V2 n) |
| 71 |
-> b |
| 72 |
-> Options b V2 n |
| 73 |
-> QDiagram b V2 n m |
| 74 |
-> (Options b V2 n, Transformation V2 n, QDiagram b V2 n m) |
| 75 |
adjustSize2D szL _ opts d = (set szL spec opts, t, d # transform t) |
| 76 |
where |
| 77 |
spec = dims sz |
| 78 |
(sz, t) = sizeAdjustment (opts ^. szL) (boundingBox d) |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
adjustDia2D :: (TypeableFloat n, Monoid' m) |
| 98 |
=> Lens' (Options b V2 n) (SizeSpec V2 n) |
| 99 |
-> b -> Options b V2 n -> QDiagram b V2 n m |
| 100 |
-> (Options b V2 n, Transformation V2 n, QDiagram b V2 n m) |
| 101 |
adjustDia2D szL b opts d |
| 102 |
= adjustSize2D szL b opts (d # setDefault2DAttributes) |
| 103 |
|