Font.purs 4.6 KB
Newer Older
Sudhir Kumar's avatar
Sudhir Kumar committed
1
module Gargantext.Components.Charts.Options.Font
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  ( ItemStyle
  , ItemStyleOptional
  , itemStyle
  , TextStyle
  , ChartFontStyle()
  , chartFontStyle
  , ChartFontWeight()
  , chartFontWeight
  , Icon()
  , ImageURL(..)
  , Shape(..)
  , IconOptions(..)
  , icon
  , Formatter
  , templateFormatter
  , Tooltip
  , TooltipOptional
  , mkTooltip
20 21 22 23 24 25 26
  , ToolBox
  , mkToolBox
  , Feature
  , DataView
  , MagicType
  , Save
  , Restore
27
  , Brush
28
  ) where
29

Sudhir Kumar's avatar
Sudhir Kumar committed
30 31
import Prelude (Unit, ($), (<<<), (<>))

32
import Data.Generic.Rep
33
import Data.Generic.Rep.Show (genericShow)
34
import CSS (FontStyle(..), FontWeight(..), Prefixed(..), Value(..))
35
import Data.String (toLower)
36
import Gargantext.Components.Charts.Options.Color (Color)
Sudhir Kumar's avatar
Sudhir Kumar committed
37
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)
38 39
import Gargantext.Types (class Optional)
import Unsafe.Coerce (unsafeCoerce)
Sudhir Kumar's avatar
Sudhir Kumar committed
40

41 42

type TextStyle =
43
  { color      :: Color
44 45 46 47 48 49 50 51 52
  , fontStyle  :: ChartFontStyle
  , fontWeight :: ChartFontWeight
  , fontFamily :: String
  , fontSize   :: Int
  , align      :: Position LeftRelativePosition
  , verticalAlign :: Position TopRelativePosition
  , lineHeight    :: Position Unit
  , width         :: Position Unit
  , height        :: Position Unit
53
  , textBorderColor :: Color
54
  , textBorderWidth :: Number
55 56
  , textShadowColor :: Color
  , textShadowBlur  :: Color
57 58 59 60
  , textShadowOffsetX :: Number
  , textShadowOffsetY :: Number
  }

61 62 63

newtype ChartFontStyle = ChartFontStyle String

64 65 66 67
chartFontStyle :: FontStyle -> ChartFontStyle
chartFontStyle (FontStyle (Value (Plain "italic"))) = ChartFontStyle "italic"
chartFontStyle (FontStyle (Value (Plain "oblique"))) = ChartFontStyle "oblique"
chartFontStyle _ = ChartFontStyle "normal"
68

69

70 71
newtype ChartFontWeight = ChartFontWeight String

72 73 74 75 76
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"
77 78 79 80 81 82 83


newtype Icon = Icon String

newtype ImageURL = ImageURL String

data Shape = Circle | Rect | RoundRect | Triangle | Diamond | Pin | Arrow
84
derive instance genericShape :: Generic Shape _
85 86 87 88

data IconOptions = Shape Shape | Image ImageURL

icon :: IconOptions -> Icon
89
icon (Shape s) = Icon <<< toLower $ genericShow s
90
icon (Image (ImageURL url)) = Icon $ "image://" <> url
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119


data ItemStyle

type ItemStyleOptional =
  ( color :: Color
  )

itemStyle :: forall o. Optional o ItemStyleOptional => Record o -> ItemStyle
itemStyle = unsafeCoerce

data Formatter

templateFormatter :: String -> Formatter
templateFormatter = unsafeCoerce

-- TODO callbackFormatter :: (...) -> Formatter

data Tooltip

type TooltipOptional =
  ( trigger   :: String
    -- ^ Not all tooltips support triggers.
    -- Grid and legend tooltips : yes
    -- Series : no
  , show      :: Boolean
  , formatter :: Formatter
  )

120 121 122
-----------------------------------------------------------------
-- | ToolBox
mkToolBox :: ToolBox
Alexandre Delanoë's avatar
Alexandre Delanoë committed
123 124
mkToolBox = { feature: { dataView    : { show: true, readOnly : false, title : "Data"}
                       , saveAsImage : { show : true, pixelRatio : 10, title : "Image"}
125
                       --, magicType   : { show : true, "type" : ["line", "bar", "pie", "stack", "tiled"], title : "Type"}
126
                       --, restore     : {show : true, title : "Restore"}
127
                       --, brush : {"type" : ["rect", "polygon", "lineX", "lineY", "keep", "clear"]}
128 129 130 131 132 133
                     }
            , orient : "vertical"
          }


---------------------------------------
134
type ToolBox = { feature :: Feature
135 136 137 138
               , orient  :: String}
type Feature = { dataView :: DataView
               , saveAsImage   :: Save
               --, magicType :: MagicType
139
               --, restore :: Restore
140
               --, brush :: Brush
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
               }

---------------------------------------
type Save = { show :: Boolean
            , pixelRatio :: Int
            , title :: String
          }

type Restore = { show :: Boolean
               , title :: String}

type MagicType = { show :: Boolean
                 , "type" :: Array String  -- TODO use line bar types
                 , title :: String
               }
---------------------------------------

type DataView = { show :: Boolean
                , readOnly :: Boolean
                , title :: String
              }

163
type Brush = { "type" :: Array String }
164 165
---------------------------------------

166 167
mkTooltip :: forall o. Optional o TooltipOptional => Record o -> Tooltip
mkTooltip = unsafeCoerce