JSON.purs 4.75 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6
module Gargantext.Components.PhyloExplorer.JSON
  ( PhyloJSON(..)
  , GraphData(..)
  , NodeData(..), RawObject(..)
  , EdgeData(..), RawEdge(..)
  ) where
arturo's avatar
arturo committed
7 8 9 10 11 12 13 14 15 16 17

import Gargantext.Prelude

import Data.Generic.Rep (class Generic)
import Data.Generic.Rep as GR
import Data.Maybe (Maybe)
import Data.Show.Generic (genericShow)
import Gargantext.Utils.SimpleJSON (untaggedSumRep)
import Simple.JSON as JSON


arturo's avatar
arturo committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
newtype PhyloJSON = PhyloJSON
  { pd_corpusId       :: Int
  , pd_listId         :: Int
  , pd_data           ::
      { _subgraph_cnt     :: Int
      , directed          :: Boolean
      , edges             :: Array RawEdge
      , objects           :: Array RawObject
      , strict            :: Boolean
      | GraphData
      }
  }

derive instance Generic PhyloJSON _
derive instance Eq PhyloJSON
instance Show PhyloJSON where show = genericShow
derive newtype instance JSON.ReadForeign PhyloJSON

--------------------------------------------------

arturo's avatar
arturo committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
type GraphData =
  ( bb                :: String
  , color             :: String
  , fontsize          :: String
  , label             :: String
  , labelloc          :: String
  , lheight           :: String
  , lp                :: String
  , lwidth            :: String
  , name              :: String
  , nodesep           :: String
  , overlap           :: String
  , phyloBranches     :: String
  , phyloDocs         :: String
  , phyloFoundations  :: String
  , phyloGroups       :: String
  , phyloPeriods      :: String
  , phyloSources      :: String
  , phyloTerms        :: String
  , phyloTimeScale    :: String
  , rank              :: String
  , ranksep           :: String
  , ratio             :: String
  , splines           :: String
  , style             :: String
  )

--------------------------------------------------

type NodeData =
  ( height            :: String
  , label             :: String
  , name              :: String
  , nodeType          :: String
  , pos               :: String
  , shape             :: String
  , width             :: String
  )

arturo's avatar
arturo committed
77
data RawObject
arturo's avatar
arturo committed
78
  = GroupToNode
arturo's avatar
arturo committed
79 80 81 82 83 84 85 86 87 88
    { _gvid           :: Int
    , bId             :: String
    , branchId        :: String
    , fontname        :: String
    , foundation      :: String
    , frequence       :: String
    , from            :: String
    , lbl             :: String
    , penwidth        :: String
    , role            :: String
89 90
    -- @NOTE #219: not in API; but present in certain data (eg. "Knowledge
    --             visualisation")
arturo's avatar
arturo committed
91
    , seaLvl          :: Maybe String
arturo's avatar
arturo committed
92 93 94 95 96 97 98 99
    , source          :: String
    , strFrom         :: Maybe String
    , strTo           :: Maybe String
    , support         :: String
    , to              :: String
    , weight          :: String
    | NodeData
    }
arturo's avatar
arturo committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  | BranchToNode
    { _gvid           :: Int
    , age             :: String
    , bId             :: String
    , birth           :: String
    , branchId        :: String
    , branch_x        :: String
    , branch_y        :: String
    , fillcolor       :: String
    , fontname        :: String
    , fontsize        :: String
    , size            :: String
    , style           :: String
    | NodeData
    }
arturo's avatar
arturo committed
115 116 117 118 119 120 121 122 123
  | PeriodToNode
    { _gvid           :: Int
    , fontsize        :: String
    , from            :: String
    , strFrom         :: Maybe String
    , strTo           :: Maybe String
    , to              :: String
    | NodeData
    }
arturo's avatar
arturo committed
124 125 126 127 128 129
  | Layer
    { _gvid           :: Int
    , nodes           :: Array Int
    | GraphData
    }

arturo's avatar
arturo committed
130

arturo's avatar
arturo committed
131 132 133 134
derive instance Generic RawObject _
derive instance Eq RawObject
instance Show RawObject where show = genericShow
instance JSON.ReadForeign RawObject where
arturo's avatar
arturo committed
135 136 137 138 139 140 141 142 143 144 145 146
  readImpl f = GR.to <$> untaggedSumRep f

--------------------------------------------------

type EdgeData =
  ( color           :: String
  , head            :: Int
  , pos             :: String
  , tail            :: Int
  , width           :: String
  )

arturo's avatar
arturo committed
147
data RawEdge
arturo's avatar
arturo committed
148
  = GroupToAncestor
arturo's avatar
arturo committed
149
    { _gvid         :: Int
arturo's avatar
arturo committed
150
    , arrowhead     :: String
arturo's avatar
arturo committed
151 152 153
    , edgeType      :: String
    , lbl           :: String
    , penwidth      :: String
arturo's avatar
arturo committed
154
    , style         :: String
arturo's avatar
arturo committed
155 156
    | EdgeData
    }
arturo's avatar
arturo committed
157
  | GroupToGroup
arturo's avatar
arturo committed
158
    { _gvid         :: Int
arturo's avatar
arturo committed
159
    , constraint    :: String
arturo's avatar
arturo committed
160
    , edgeType      :: String
arturo's avatar
arturo committed
161 162
    , lbl           :: String
    , penwidth      :: String
arturo's avatar
arturo committed
163 164
    | EdgeData
    }
arturo's avatar
arturo committed
165
  | BranchToGroup
arturo's avatar
arturo committed
166 167
    { _gvid         :: Int
    , arrowhead     :: String
arturo's avatar
arturo committed
168
    , edgeType      :: String
arturo's avatar
arturo committed
169 170
    | EdgeData
    }
arturo's avatar
arturo committed
171
  | BranchToBranch
arturo's avatar
arturo committed
172 173 174 175 176 177 178 179 180 181
    { _gvid         :: Int
    , arrowhead     :: String
    , style         :: String
    | EdgeData
    }
  | PeriodToPeriod
    { _gvid         :: Int
    | EdgeData
    }

arturo's avatar
arturo committed
182 183 184 185
derive instance Generic RawEdge _
derive instance Eq RawEdge
instance Show RawEdge where show = genericShow
instance JSON.ReadForeign RawEdge where
arturo's avatar
arturo committed
186
  readImpl f = GR.to <$> untaggedSumRep f