Font.purs 2.23 KB
Newer Older
Sudhir Kumar's avatar
Sudhir Kumar committed
1
module Gargantext.Components.Charts.Options.Font
2
       (
3
         TextStyle,
4 5 6
         ChartFontStyle(),
         chartFontStyle,
         ChartFontWeight(),
7 8 9 10 11 12
         chartFontWeight,
         Icon(),
         ImageURL(..),
         Shape(..),
         IconOptions(..),
         icon
13
       ) where
14

Sudhir Kumar's avatar
Sudhir Kumar committed
15 16
import Prelude (Unit, ($), (<<<), (<>))

17 18
import Data.Generic.Rep
import Data.Generic.Rep.Show
19
import CSS (FontStyle(..), FontWeight(..), Prefixed(..), Value(..))
20
import Data.String (toLower)
Sudhir Kumar's avatar
Sudhir Kumar committed
21 22 23
import Gargantext.Components.Charts.Options.Color (ChartColor)
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

type TextStyle =
  { color      :: ChartColor
  , fontStyle  :: ChartFontStyle
  , fontWeight :: ChartFontWeight
  , fontFamily :: String
  , fontSize   :: Int
  , align      :: Position LeftRelativePosition
  , verticalAlign :: Position TopRelativePosition
  , lineHeight    :: Position Unit
  , width         :: Position Unit
  , height        :: Position Unit
  , textBorderColor :: ChartColor
  , textBorderWidth :: Number
  , textShadowColor :: ChartColor
  , textShadowBlur  :: ChartColor
  , textShadowOffsetX :: Number
  , textShadowOffsetY :: Number
  }

44 45 46

newtype ChartFontStyle = ChartFontStyle String

47 48 49 50
chartFontStyle :: FontStyle -> ChartFontStyle
chartFontStyle (FontStyle (Value (Plain "italic"))) = ChartFontStyle "italic"
chartFontStyle (FontStyle (Value (Plain "oblique"))) = ChartFontStyle "oblique"
chartFontStyle _ = ChartFontStyle "normal"
51

52

53 54
newtype ChartFontWeight = ChartFontWeight String

55 56 57 58 59
chartFontWeight :: FontWeight -> ChartFontWeight
chartFontWeight (FontWeight (Value (Plain "bold"))) = ChartFontWeight "bold"
chartFontWeight (FontWeight (Value (Plain "bolder"))) = ChartFontWeight "bolder"
chartFontWeight (FontWeight (Value (Plain "lighter"))) = ChartFontWeight "lighter"
chartFontWeight  _ = ChartFontWeight "normal"
60 61 62 63 64 65 66


newtype Icon = Icon String

newtype ImageURL = ImageURL String

data Shape = Circle | Rect | RoundRect | Triangle | Diamond | Pin | Arrow
67
derive instance genericShape :: Generic Shape _
68 69 70 71

data IconOptions = Shape Shape | Image ImageURL

icon :: IconOptions -> Icon
72
icon (Shape s) = Icon <<< toLower $ genericShow s
73
icon (Image (ImageURL url)) = Icon $ "image://" <> url