Data.purs 1.21 KB
Newer Older
Sudhir Kumar's avatar
Sudhir Kumar committed
1
module Gargantext.Components.Charts.Options.Data where
2

3 4 5 6
import Record.Unsafe (unsafeSet)
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
import Gargantext.Components.Charts.Options.Font (TextStyle, Icon, ItemStyle)
7

8
type DataLegend =
9 10 11 12 13
  { name :: String
  , icon :: Icon
  , textStyle :: TextStyle
  }

14 15
type DataAxis = Array String
  {- value :: String
16
  , textStyle :: TextStyle
17
  -}
18

19 20 21
type RequiredData v o =
  { value :: v
  | o
22
  }
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
type OptionalData =
  ( name       :: String
  , symbolSize :: Number
  , itemStyle  :: ItemStyle
    -- ^ the style setting about single data point(bubble).
  , label      :: { show :: Boolean }
  )

type DataSerie v = RequiredData v OptionalData

dataSerie :: forall v o. Optional o OptionalData => RequiredData v o -> DataSerie v
dataSerie = unsafeCoerce

dataSerieV :: forall v. v -> DataSerie v
dataSerieV value = dataSerie {value}

type DataD1 = DataSerie Number
type DataD2 = DataSerie (Array Number)

dataD1 :: forall o. Optional o OptionalData => Record o -> Number -> DataD1
dataD1 o x = unsafeCoerce (unsafeSet "value" x o)

dataD2 :: forall o. Optional o OptionalData => Record o -> Number -> Number -> DataD2
dataD2 o x y = unsafeCoerce (unsafeSet "value" [x,y] o)