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

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

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

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

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

25
type OptionalData =
26 27 28 29 30 31 32 33 34
  ( name          :: String
  , symbolSize    :: Number
  , itemStyle     :: ItemStyle
  -- ^ the style setting about single data point(bubble).
  , label         :: { show :: Boolean }
  , emphasis      :: { itemStyle :: ItemStyle }
  , selectedMode  :: SelectedMode
  , select        :: { itemStyle :: ItemStyle }
  -- ^ need "selectedMode" to be defined
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  )

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)