Legend.purs 1.25 KB
Newer Older
Sudhir Kumar's avatar
Sudhir Kumar committed
1
module Gargantext.Components.Charts.Options.Legend
2
       (
3
         LegendType(..),
4 5 6 7
         PlainOrScroll(..),
         legendType,
         Orient(),
         Orientation(..),
8 9 10 11
         orient,
         SelectedMode(),
         LegendMode(..),
         selectedMode
12 13
       ) where

Sudhir Kumar's avatar
Sudhir Kumar committed
14 15
import Prelude (class Show, show, (<<<))

16
import Data.Generic.Rep (class Generic)
17
import Data.Generic.Rep.Show
18
import Data.String (toLower)
19
import Unsafe.Coerce (unsafeCoerce)
20 21 22 23

newtype LegendType = LegendType String

data PlainOrScroll = Plain | Scroll
24 25 26
instance showPlainOrScroll :: Show PlainOrScroll where
  show (Plain) = "plain"
  show (Scroll) = "scroll"
27 28

legendType :: PlainOrScroll -> LegendType
29
legendType = LegendType <<< toLower <<< show
30 31 32 33 34


newtype Orient = Orient String

data Orientation = Horizontal | Vertical
35
derive instance genericOrientation :: Generic Orientation _
36 37

orient :: Orientation -> Orient
38
orient = Orient <<< toLower <<< genericShow
39 40 41 42 43


foreign import data SelectedMode :: Type

data LegendMode = Bool Boolean | Single | Multiple
44
derive instance genericLegendMode :: Generic LegendMode _
45 46 47 48 49

selectedMode :: LegendMode -> SelectedMode
selectedMode (Bool b) = unsafeCoerce b
selectedMode (Single) = unsafeCoerce "single"
selectedMode (Multiple) = unsafeCoerce "multiple"