Font.purs 4.55 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.Show.Generic (genericShow)
34 35
import CSS (FontWeight(..), Prefixed(..), Value(..))
import CSS.FontStyle (FontStyle(..))
36
import Data.String (toLower)
37
import Gargantext.Components.Charts.Options.Color (Color)
Sudhir Kumar's avatar
Sudhir Kumar committed
38
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)
39 40
import Gargantext.Types (class Optional)
import Unsafe.Coerce (unsafeCoerce)
Sudhir Kumar's avatar
Sudhir Kumar committed
41

42 43

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

62 63 64

newtype ChartFontStyle = ChartFontStyle String

65
chartFontStyle :: FontStyle -> ChartFontStyle
66 67
chartFontStyle Italic = ChartFontStyle "italic"
chartFontStyle (Oblique _) = ChartFontStyle "oblique"
68
chartFontStyle _ = ChartFontStyle "normal"
69

70

71 72
newtype ChartFontWeight = ChartFontWeight String

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


newtype Icon = Icon String

newtype ImageURL = ImageURL String

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

data IconOptions = Shape Shape | Image ImageURL

icon :: IconOptions -> Icon
90
icon (Shape s) = Icon <<< toLower $ genericShow s
91
icon (Image (ImageURL url)) = Icon $ "image://" <> url
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 120


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
  )

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


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

---------------------------------------
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
              }

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

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