Commit e85e010f authored by Alexandre Delanoë's avatar Alexandre Delanoë
parents fe139c50 5d887c30
...@@ -43,5 +43,6 @@ ...@@ -43,5 +43,6 @@
"psc-package": "^0.3.2", "psc-package": "^0.3.2",
"pulp": "^12.3.0", "pulp": "^12.3.0",
"purescript": "^0.12.0" "purescript": "^0.12.0"
} },
"version": "0.0.0"
} }
module Gargantext.Components.Charts.Options.Color module Gargantext.Components.Charts.Options.Color
( ChartColor() ( Color
, chartColor , stringColor
, cssColor
, transparent , transparent
, red
, blue
, magenta
, violet
, black
) where ) where
import Prelude import Prelude
import CSS (Color, toHexString) import CSS as CSS
import Color (rgba) import Color (rgba)
import Unsafe.Coerce (unsafeCoerce)
newtype ChartColor = ChartColor String data Color
stringColor :: String -> Color
stringColor = unsafeCoerce
cssColor :: CSS.Color -> Color
cssColor = stringColor <<< CSS.toHexString
transparent :: Color transparent :: Color
transparent = rgba 255 255 255 0.0 transparent = cssColor $ rgba 255 255 255 0.0
red :: Color
red = stringColor "red"
blue :: Color
blue = stringColor "blue"
magenta :: Color
magenta = stringColor "magenta"
violet :: Color
violet = cssColor CSS.violet
chartColor :: Color -> ChartColor black :: Color
chartColor = ChartColor <<< toHexString black = stringColor "black"
...@@ -2,17 +2,17 @@ module Gargantext.Components.Charts.Options.ECharts where ...@@ -2,17 +2,17 @@ module Gargantext.Components.Charts.Options.ECharts where
import Prelude import Prelude
import CSS (black, italic, violet) import CSS (italic)
import CSS.Common (normal) import CSS.Common (normal)
import Data.Array (length) import Data.Array (length)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Gargantext.Components.Charts.Options.Color (chartColor, transparent) import Gargantext.Components.Charts.Options.Color (transparent, violet, black)
import Gargantext.Components.Charts.Options.Data (DataN, DataS, DataV) import Gargantext.Components.Charts.Options.Data (DataN, DataS, DataV)
import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), TextStyle, chartFontStyle, chartFontWeight, icon) import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), TextStyle, chartFontStyle, chartFontWeight, icon)
import Gargantext.Components.Charts.Options.Legend (legendType, LegendMode(..), PlainOrScroll(..), selectedMode, Orientation(..), orient) import Gargantext.Components.Charts.Options.Legend (legendType, LegendMode(..), PlainOrScroll(..), selectedMode, Orientation(..), orient)
import Gargantext.Components.Charts.Options.Position (Align(..), LeftRelativePosition(..), TopRelativePosition(..), numberPosition, percentPosition, relativePosition) import Gargantext.Components.Charts.Options.Position (Align(..), LeftRelativePosition(..), TopRelativePosition(..), numberPosition, percentPosition, relativePosition)
import Gargantext.Components.Charts.Options.Series (Serie(..), Series(..), toSeries, SeriesName, Chart(..), seriesType, D1, D2) import Gargantext.Components.Charts.Options.Series (Series, SeriesName, Chart(..), seriesType, seriesD1)
import Gargantext.Components.Charts.Options.Type (DataZoom, Echarts, Legend, Option, Title, Tooltip, XAxis, YAxis) import Gargantext.Components.Charts.Options.Type (DataZoom, Echarts, Legend, Option, Title, Tooltip, XAxis, YAxis, xAxis, yAxis)
import React (unsafeCreateElementDynamic) import React (unsafeCreateElementDynamic)
import React as R import React as R
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
...@@ -25,11 +25,12 @@ chart = echarts <<< chartWith <<< opts ...@@ -25,11 +25,12 @@ chart = echarts <<< chartWith <<< opts
chartWith :: Option -> Echarts chartWith :: Option -> Echarts
chartWith opts = { className : Nothing chartWith option =
{ option
, className : Nothing
, style : Nothing , style : Nothing
, theme : Nothing , theme : Nothing
, group : Nothing , group : Nothing
, option : opts
, initOpts : Nothing , initOpts : Nothing
, notMerge : Nothing , notMerge : Nothing
, lazyUpdate: Nothing , lazyUpdate: Nothing
...@@ -41,7 +42,7 @@ chartWith opts = { className : Nothing ...@@ -41,7 +42,7 @@ chartWith opts = { className : Nothing
} }
echarts :: Echarts -> R.ReactElement echarts :: Echarts -> R.ReactElement
echarts chart = unsafeCreateElementDynamic (unsafeCoerce eChartsClass) chart [] echarts c = unsafeCreateElementDynamic (unsafeCoerce eChartsClass) c []
type MainTitle = String type MainTitle = String
type SubTitle = String type SubTitle = String
...@@ -67,12 +68,12 @@ title mainTitle subTitle = ...@@ -67,12 +68,12 @@ title mainTitle subTitle =
,top: relativePosition (Relative Top) ,top: relativePosition (Relative Top)
,right: numberPosition 60.0 ,right: numberPosition 60.0
,bottom: percentPosition 40.0 ,bottom: percentPosition 40.0
,backgroundColor: chartColor transparent ,backgroundColor: transparent
,borderColor: chartColor transparent ,borderColor: transparent
,borderWidth: 0.0 ,borderWidth: 0.0
,borderRadius: 0.0 ,borderRadius: 0.0
,shadowBlur: 0.0 ,shadowBlur: 0.0
,shadowColor: chartColor transparent ,shadowColor: transparent
,shadowOffsetX: 0.0 ,shadowOffsetX: 0.0
,shadowOffsetY: 0.0 ,shadowOffsetY: 0.0
} }
...@@ -99,7 +100,7 @@ legend = ...@@ -99,7 +100,7 @@ legend =
, itemHeight: 14.0 , itemHeight: 14.0
, formatter: Nothing , formatter: Nothing
, selectedMode: selectedMode $ Bool true , selectedMode: selectedMode $ Bool true
, inactiveColor: chartColor violet , inactiveColor: violet
, selected: Nothing , selected: Nothing
, textStyle: textStyle , textStyle: textStyle
, "data": [data1] , "data": [data1]
...@@ -115,22 +116,10 @@ data3 :: DataN ...@@ -115,22 +116,10 @@ data3 :: DataN
data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'} data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'}
xAxis :: Array String -> XAxis
xAxis [] = unsafeCoerce {}
xAxis xs = { "data": xData xs
, "type": "category"
, axisTick: {alignWithLabel: true}
, show: if (length xs == 0) then false else true
}
where
xData :: Array String -> Array DataV
xData xs = map (\x -> {value : x, textStyle : textStyle'}) xs
yDataVoid :: YAxis yAxisVoid :: YAxis
yDataVoid = yAxisVoid = yAxis
{ { "type": ""
"type": ""
, name: "" , name: ""
, min: 0 , min: 0
, position: "" , position: ""
...@@ -138,10 +127,9 @@ yDataVoid = ...@@ -138,10 +127,9 @@ yDataVoid =
, show: false , show: false
} }
yData1 :: YAxis yAxis1 :: YAxis
yData1 = yAxis1 = yAxis
{ { "type": "value"
"type": "value"
, name: "data" , name: "data"
, min: 0 , min: 0
, position: "left" , position: "left"
...@@ -151,68 +139,65 @@ yData1 = ...@@ -151,68 +139,65 @@ yData1 =
tooltip' :: Tooltip tooltip' :: Tooltip
tooltip' = tooltip' =
{ { trigger: "axis"
trigger: "axis"
, formatter: Nothing , formatter: Nothing
} }
xAxis' :: Array String -> XAxis
series :: Chart -> SeriesName -> Array DataS -> D1 xAxis' [] = unsafeCoerce {}
series sh name ss = { name: name xAxis' xs = xAxis
, "type": seriesType sh { "data": xData xs
, "data": ss , "type": "category"
} , axisTick: {alignWithLabel: true}
, show: length xs /= 0
seriesD2 :: String -> Chart -> Number -> Array (Array Number) -> D2
seriesD2 n sh size ds = { "symbolSize" : size
, "data" : ds
, "type" : seriesType sh
, name : n
} }
where
xData :: Array String -> Array DataV
xData = map (\x -> {value : x, textStyle : textStyle'})
data YAxisFormat = YAxisFormat { position :: String
, visible :: Boolean -- TODO try to use Optional
yAxis' :: { position :: String
, show :: Boolean
} -> YAxis
yAxis' {position, show} = yAxis
{ "type": "value"
, name: "data"
, min: 0
, axisLabel: {formatter: "{value}"}
, position
, show
} }
data Options = Options { mainTitle :: MainTitle data Options = Options
{ mainTitle :: MainTitle
, subTitle :: SubTitle , subTitle :: SubTitle
, xAxis :: XAxis , xAxis :: XAxis
, yAxis :: Array Serie , yAxis :: YAxis
, yAxisFormat :: YAxisFormat , series :: Array Series
, addZoom :: Boolean , addZoom :: Boolean
} }
opts :: Options -> Option opts :: Options -> Option
opts (Options { mainTitle : mainTitle opts (Options { mainTitle
, subTitle : subTitle , subTitle
, xAxis : xs , xAxis
, yAxis : ss , yAxis
, yAxisFormat : (YAxisFormat { position : position , series
, visible : visible , addZoom
}) }) =
, addZoom : addZoom}) =
{ title: title mainTitle subTitle { title: title mainTitle subTitle
, legend : legend , legend
, tooltip: { trigger: "axis" , tooltip: { trigger: "axis"
, formatter: Nothing , formatter: Nothing
} }
, grid : {containLabel: true} , grid: {containLabel: true}
, xAxis : xs , series
, series : map toSeries $ ss , xAxis
, yAxis : { "type": "value" , yAxis
, name: "data"
, min: 0
, position: position
, axisLabel: {formatter: "{value}"}
, show: visible
}
, dataZoom: if addZoom then [zoom Slider, zoom Inside] else [] , dataZoom: if addZoom then [zoom Slider, zoom Inside] else []
, children : unsafeCoerce [] , children : unsafeCoerce [] -- TODO
} }
data Zoom = Slider | Inside data Zoom = Slider | Inside
instance showZoom :: Show Zoom where instance showZoom :: Show Zoom where
...@@ -229,10 +214,9 @@ zoom z = { ...@@ -229,10 +214,9 @@ zoom z = {
} }
seriesPie :: D1 seriesPie :: Series
seriesPie = seriesPie = seriesD1
{ { name: "Pie name"
name: "Pie name"
, "type": seriesType Pie , "type": seriesType Pie
, "data": [{name: "t1", value: 50.0}, , "data": [{name: "t1", value: 50.0},
{name: "t2", value: 45.0}, {name: "t2", value: 45.0},
...@@ -246,7 +230,7 @@ seriesPie = ...@@ -246,7 +230,7 @@ seriesPie =
textStyle2 :: TextStyle textStyle2 :: TextStyle
textStyle2 = textStyle2 =
{ {
color: chartColor black color: black
,fontStyle: chartFontStyle italic ,fontStyle: chartFontStyle italic
,fontWeight: chartFontWeight normal ,fontWeight: chartFontWeight normal
,fontFamily: "sans-serif" ,fontFamily: "sans-serif"
...@@ -256,10 +240,10 @@ textStyle2 = ...@@ -256,10 +240,10 @@ textStyle2 =
,lineHeight: percentPosition 0.0 ,lineHeight: percentPosition 0.0
,width: percentPosition 100.0 ,width: percentPosition 100.0
,height: percentPosition 100.0 ,height: percentPosition 100.0
,textBorderColor: chartColor black ,textBorderColor: black
,textBorderWidth: 0.0 ,textBorderWidth: 0.0
,textShadowColor: chartColor black ,textShadowColor: black
,textShadowBlur: chartColor black ,textShadowBlur: black
,textShadowOffsetX: 0.0 ,textShadowOffsetX: 0.0
,textShadowOffsetY: 0.0 ,textShadowOffsetY: 0.0
} }
...@@ -267,7 +251,7 @@ textStyle2 = ...@@ -267,7 +251,7 @@ textStyle2 =
textStyle' :: TextStyle textStyle' :: TextStyle
textStyle' = textStyle' =
{ {
color: chartColor black color: black
,fontStyle: chartFontStyle normal ,fontStyle: chartFontStyle normal
,fontWeight: chartFontWeight normal ,fontWeight: chartFontWeight normal
,fontFamily: "sans-serif" ,fontFamily: "sans-serif"
...@@ -277,10 +261,10 @@ textStyle' = ...@@ -277,10 +261,10 @@ textStyle' =
,lineHeight: percentPosition 0.0 ,lineHeight: percentPosition 0.0
,width: percentPosition 100.0 ,width: percentPosition 100.0
,height: percentPosition 100.0 ,height: percentPosition 100.0
,textBorderColor: chartColor black ,textBorderColor: black
,textBorderWidth: 1.0 ,textBorderWidth: 1.0
,textShadowColor: chartColor black ,textShadowColor: black
,textShadowBlur: chartColor black ,textShadowBlur: black
,textShadowOffsetX: 0.0 ,textShadowOffsetX: 0.0
,textShadowOffsetY: 0.0 ,textShadowOffsetY: 0.0
} }
...@@ -288,7 +272,7 @@ textStyle' = ...@@ -288,7 +272,7 @@ textStyle' =
textStyle :: TextStyle textStyle :: TextStyle
textStyle = textStyle =
{ {
color: chartColor black color: black
,fontStyle: chartFontStyle normal ,fontStyle: chartFontStyle normal
,fontWeight: chartFontWeight normal ,fontWeight: chartFontWeight normal
,fontFamily: "sans-serif" ,fontFamily: "sans-serif"
...@@ -298,10 +282,10 @@ textStyle = ...@@ -298,10 +282,10 @@ textStyle =
,lineHeight: percentPosition 0.0 ,lineHeight: percentPosition 0.0
,width: percentPosition 100.0 ,width: percentPosition 100.0
,height: percentPosition 100.0 ,height: percentPosition 100.0
,textBorderColor: chartColor black ,textBorderColor: black
,textBorderWidth: 1.0 ,textBorderWidth: 1.0
,textShadowColor: chartColor black ,textShadowColor: black
,textShadowBlur: chartColor black ,textShadowBlur: black
,textShadowOffsetX: 0.0 ,textShadowOffsetX: 0.0
,textShadowOffsetY: 0.0 ,textShadowOffsetY: 0.0
} }
...@@ -15,15 +15,15 @@ module Gargantext.Components.Charts.Options.Font ...@@ -15,15 +15,15 @@ module Gargantext.Components.Charts.Options.Font
import Prelude (Unit, ($), (<<<), (<>)) import Prelude (Unit, ($), (<<<), (<>))
import Data.Generic.Rep import Data.Generic.Rep
import Data.Generic.Rep.Show import Data.Generic.Rep.Show (genericShow)
import CSS (FontStyle(..), FontWeight(..), Prefixed(..), Value(..)) import CSS (FontStyle(..), FontWeight(..), Prefixed(..), Value(..))
import Data.String (toLower) import Data.String (toLower)
import Gargantext.Components.Charts.Options.Color (ChartColor) import Gargantext.Components.Charts.Options.Color (Color)
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition) import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)
type TextStyle = type TextStyle =
{ color :: ChartColor { color :: Color
, fontStyle :: ChartFontStyle , fontStyle :: ChartFontStyle
, fontWeight :: ChartFontWeight , fontWeight :: ChartFontWeight
, fontFamily :: String , fontFamily :: String
...@@ -33,10 +33,10 @@ type TextStyle = ...@@ -33,10 +33,10 @@ type TextStyle =
, lineHeight :: Position Unit , lineHeight :: Position Unit
, width :: Position Unit , width :: Position Unit
, height :: Position Unit , height :: Position Unit
, textBorderColor :: ChartColor , textBorderColor :: Color
, textBorderWidth :: Number , textBorderWidth :: Number
, textShadowColor :: ChartColor , textShadowColor :: Color
, textShadowBlur :: ChartColor , textShadowBlur :: Color
, textShadowOffsetX :: Number , textShadowOffsetX :: Number
, textShadowOffsetY :: Number , textShadowOffsetY :: Number
} }
......
module Gargantext.Components.Charts.Options.Series where module Gargantext.Components.Charts.Options.Series where
import Effect.Exception (error, Error(..))
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Prelude import Prelude
import Gargantext.Types (class Optional)
import Gargantext.Components.Charts.Options.Color (Color)
import Gargantext.Components.Charts.Options.Data (DataS) import Gargantext.Components.Charts.Options.Data (DataS)
data ItemStyle
type ItemStyleOptional =
( color :: Color
)
itemStyle :: forall o. Optional o ItemStyleOptional => Record o -> ItemStyle
itemStyle = unsafeCoerce
newtype SeriesType = SeriesType String newtype SeriesType = SeriesType String
type SeriesName = String type SeriesName = String
...@@ -48,36 +58,54 @@ seriesType :: Chart -> SeriesType ...@@ -48,36 +58,54 @@ seriesType :: Chart -> SeriesType
seriesType = SeriesType <<< show seriesType = SeriesType <<< show
type Series = {} data Series
data Serie = SeriesD1 D1 | SeriesD2 D2 | SerieSankey Sankey | SerieTree Tree
type D1 = unsafeSeries :: forall o. { | o } -> Series
{ name :: String unsafeSeries = unsafeCoerce
, "type" :: SeriesType
type RequiredD1 o =
{ "type" :: SeriesType
, "data" :: Array DataS , "data" :: Array DataS
| o
} }
-- | Scatter Dimension 2 data type OptionalD1 =
type D2 = ( name :: String
{ name :: String -- many more...
, "symbolSize" :: Number )
, "data" :: Array (Array Number)
seriesD1 :: forall o. Optional o OptionalD1 => RequiredD1 o -> Series
seriesD1 = unsafeSeries
seriesFunnelD1 :: forall o. Optional o OptionalD1 => Record o -> Array DataS -> Series
seriesFunnelD1 o ds = seriesD1 ((unsafeCoerce o :: RequiredD1 o) { "data" = ds, "type" = seriesType Funnel })
seriesBarD1 :: forall o. Optional o OptionalD1 => Record o -> Array DataS -> Series
seriesBarD1 o ds = seriesD1 ((unsafeCoerce o :: RequiredD1 o) { "data" = ds, "type" = seriesType Bar })
seriesPieD1 :: forall o. Optional o OptionalD1 => Record o -> Array DataS -> Series
seriesPieD1 o ds = seriesD1 ((unsafeCoerce o :: RequiredD1 o) { "data" = ds, "type" = seriesType Pie })
type RequiredD2 o =
{ "data" :: Array (Array Number)
, "type" :: SeriesType , "type" :: SeriesType
| o
} }
toSeries :: Serie -> Series -- | Scatter Dimension 2 data
toSeries (SeriesD1 a) = unsafeCoerce a type OptionalD2 =
toSeries (SeriesD2 a) = unsafeCoerce a ( name :: String
toSeries (SerieSankey a) = unsafeCoerce a , symbolSize :: Number
toSeries (SerieTree a) = unsafeCoerce a , itemStyle :: ItemStyle
-- many more...
)
-- | Sankey Chart seriesD2 :: forall o. Optional o OptionalD2 => RequiredD2 o -> Series
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple seriesD2 = unsafeSeries
type Sankey = { "type" :: SeriesType
, layout :: String seriesScatterD2 :: forall o. Optional o OptionalD2 => Record o -> Array (Array Number) -> Series
, "data" :: Array Node seriesScatterD2 o ds =
, "links" :: Array Link seriesD2 ((unsafeCoerce o :: RequiredD2 o) { "data" = ds, "type" = seriesType Scatter })
}
type Node = { name :: String} type Node = { name :: String}
type Link = { source :: String type Link = { source :: String
...@@ -85,13 +113,21 @@ type Link = { source :: String ...@@ -85,13 +113,21 @@ type Link = { source :: String
, value :: Number , value :: Number
} }
mkSankey :: Array Node -> Array Link -> Serie -- | Sankey Chart
mkSankey ns ls = SerieSankey { "type" : seriesType Sankey -- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple
, layout : "none" type RequiredSankey o =
, "data" : ns { "data" :: Array Node
, "links" : ls , links :: Array Link
| o
} }
type OptionalSankey =
( layout :: String
)
seriesSankey :: forall o. Optional o OptionalSankey => RequiredSankey o -> Series
seriesSankey o = unsafeSeries ((unsafeCoerce o) { "type" = seriesType Sankey })
-- | * Trees Chart -- | * Trees Chart
-- All these Trees are hierarchical Trees structure (or diagram) -- All these Trees are hierarchical Trees structure (or diagram)
-- https://en.wikipedia.org/wiki/Tree_structure -- https://en.wikipedia.org/wiki/Tree_structure
...@@ -115,13 +151,21 @@ instance showTrees :: Show Trees where ...@@ -115,13 +151,21 @@ instance showTrees :: Show Trees where
-- TreeMap example implementation: -- TreeMap example implementation:
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple -- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
type Tree = { "type" :: SeriesType type RequiredTree o =
{ "type" :: SeriesType
, "data" :: Array TreeData , "data" :: Array TreeData
, layout :: String | o
} }
mkTree :: Trees -> Array TreeData -> Serie type OptionalTree =
mkTree t ts = SerieTree { "type" : SeriesType (show t) ( layout :: String
)
seriesTree :: forall o. Optional o OptionalTree => RequiredTree o -> Series
seriesTree = unsafeSeries
mkTree :: Trees -> Array TreeData -> Series
mkTree t ts = seriesTree { "type" : SeriesType (show t)
, "data" : map toJsTree ts , "data" : map toJsTree ts
, layout : layout , layout : layout
} }
......
...@@ -2,17 +2,20 @@ module Gargantext.Components.Charts.Options.Type where ...@@ -2,17 +2,20 @@ module Gargantext.Components.Charts.Options.Type where
import Prelude import Prelude
import CSS (Color)
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Gargantext.Components.Charts.Options.Color (ChartColor) import Gargantext.Components.Charts.Options.Color (Color)
import Gargantext.Components.Charts.Options.Data (DataN, DataV) import Gargantext.Components.Charts.Options.Data (DataN, DataV)
import Gargantext.Components.Charts.Options.Font (TextStyle) import Gargantext.Components.Charts.Options.Font (TextStyle)
import Gargantext.Components.Charts.Options.Legend (LegendType, Orient, SelectedMode) import Gargantext.Components.Charts.Options.Legend (LegendType, Orient, SelectedMode)
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition) import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)
import Gargantext.Components.Charts.Options.Series (Series) import Gargantext.Components.Charts.Options.Series (Series)
import Gargantext.Types (class Optional)
import React as R import React as R
import Unsafe.Coerce (unsafeCoerce)
newtype ChartAlign = ChartAlign String newtype ChartAlign = ChartAlign String
-- TODO: Not sure that Maybe is working here => use Optional
type Echarts = type Echarts =
{ className :: Maybe String { className :: Maybe String
, style :: Maybe String -- objealect-black-altdarkmincnaquadahherry-blossomect, , style :: Maybe String -- objealect-black-altdarkmincnaquadahherry-blossomect,
...@@ -60,12 +63,12 @@ type Title = ...@@ -60,12 +63,12 @@ type Title =
, top :: Position TopRelativePosition -- default 'auto' , top :: Position TopRelativePosition -- default 'auto'
, right :: Position Unit -- default 'auto' , right :: Position Unit -- default 'auto'
, bottom :: Position Unit -- default 'auto' , bottom :: Position Unit -- default 'auto'
, backgroundColor :: ChartColor -- default 'transparent'' , backgroundColor :: Color -- default 'transparent''
, borderColor :: ChartColor -- default '#ccc' , borderColor :: Color -- default '#ccc'
, borderWidth :: Number -- default '1' , borderWidth :: Number -- default '1'
, borderRadius :: Number -- default 0; data NumberOrArray = Number | Array Number , borderRadius :: Number -- default 0; data NumberOrArray = Number | Array Number
, shadowBlur :: Number , shadowBlur :: Number
, shadowColor :: ChartColor , shadowColor :: Color
, shadowOffsetX :: Number , shadowOffsetX :: Number
, shadowOffsetY :: Number , shadowOffsetY :: Number
} }
...@@ -111,7 +114,7 @@ type Legend = ...@@ -111,7 +114,7 @@ type Legend =
, itemHeight :: Number , itemHeight :: Number
, formatter :: Maybe String , formatter :: Maybe String
, selectedMode :: SelectedMode , selectedMode :: SelectedMode
, inactiveColor :: ChartColor , inactiveColor :: Color
, selected :: Maybe String -- object , selected :: Maybe String -- object
, textStyle :: TextStyle , textStyle :: TextStyle
, "data" :: Array DataN , "data" :: Array DataN
...@@ -122,26 +125,39 @@ type Tooltip = ...@@ -122,26 +125,39 @@ type Tooltip =
, formatter :: Maybe String -- TODO function , formatter :: Maybe String -- TODO function
} }
type XAxis = type AxisTick =
{ "data" :: Array DataV { alignWithLabel :: Boolean
}
data XAxis
type XAxisOptional =
( "data" :: Array DataV
, "type" :: String , "type" :: String
, axisTick :: AxisTick , axisTick :: AxisTick
, name :: String
, min :: Int
, position :: String
, axisLabel :: AxisLabel
, show :: Boolean , show :: Boolean
} )
type AxisTick = xAxis :: forall o. Optional o XAxisOptional => Record o -> XAxis
{ xAxis = unsafeCoerce
alignWithLabel :: Boolean
} data YAxis
type YAxis = type YAxisOptional =
{ "type" :: String ( "type" :: String
, name :: String , name :: String
, min :: Int , min :: Int
, position :: String , position :: String
, axisLabel :: AxisLabel , axisLabel :: AxisLabel
, show :: Boolean , show :: Boolean
} )
yAxis :: forall o. Optional o YAxisOptional => Record o -> YAxis
yAxis = unsafeCoerce
type AxisLabel = type AxisLabel =
{ formatter :: String -- string or function { formatter :: String -- string or function
......
...@@ -3,9 +3,9 @@ module Gargantext.Components.GraphExplorer.Sigmajs where ...@@ -3,9 +3,9 @@ module Gargantext.Components.GraphExplorer.Sigmajs where
import Prelude import Prelude
import Effect (Effect) import Effect (Effect)
import Prim.Row (class Union)
import React (Children, ReactClass, ReactElement, createElement, unsafeCreateElement) import React (Children, ReactClass, ReactElement, createElement, unsafeCreateElement)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
foreign import edgeShapesClass :: forall props. ReactClass props foreign import edgeShapesClass :: forall props. ReactClass props
foreign import filterClass :: forall props. ReactClass props foreign import filterClass :: forall props. ReactClass props
...@@ -64,12 +64,6 @@ foreign import data SigmaNode :: Type ...@@ -64,12 +64,6 @@ foreign import data SigmaNode :: Type
foreign import data SigmaEdge :: Type foreign import data SigmaEdge :: Type
foreign import data SigmaSettings :: Type foreign import data SigmaSettings :: Type
-- | Proof that row `r` is a subset of row `s`
class Optional (r :: # Type) (s :: # Type)
instance srInstance :: Union r t s => Optional r s
type NeoCypherOptProps = type NeoCypherOptProps =
( producers :: String ( producers :: String
, onGraphLoaded :: Effect Unit , onGraphLoaded :: Effect Unit
......
...@@ -4,10 +4,8 @@ import Prelude hiding (div) ...@@ -4,10 +4,8 @@ import Prelude hiding (div)
import Data.Array (zip) import Data.Array (zip)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Components.Charts.Options.ECharts import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
import Gargantext.Components.Charts.Options.Series import Gargantext.Components.Charts.Options.Series
import Gargantext.Components.Charts.Options.Type (Option)
import Data.Unit (Unit)
import Data.Int (toNumber) import Data.Int (toNumber)
import React.DOM (div, h1, text) import React.DOM (div, h1, text)
import React.DOM.Props (className) import React.DOM.Props (className)
...@@ -29,21 +27,22 @@ render dispatch _ state _ = [ ...@@ -29,21 +27,22 @@ render dispatch _ state _ = [
, chart treeEx , chart treeEx
] ]
where where
myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0} myData = [seriesBarD1 {name: "Bar Data"}
[ {name: "val1", value: 50.0}
, {name: "val2", value: 70.0} , {name: "val2", value: 70.0}
, {name: "val3", value: 80.0} , {name: "val3", value: 80.0}
] ]
] ]
focus :: String -> Options focus :: String -> Options
focus school = Options { mainTitle : ("Focus " <> school) focus school = Options
{ mainTitle : "Focus " <> school
, subTitle : "Total scientific publications" , subTitle : "Total scientific publications"
, xAxis : xAxis ["2015", "2016", "2017"] , xAxis : xAxis' ["2015", "2016", "2017"]
, yAxis : myData , yAxis : yAxis' { position: "left"
, yAxisFormat : (YAxisFormat { position : "left" , show: true
, visible : true }
}) , series : myData
, addZoom : false , addZoom : false
} }
...@@ -58,13 +57,12 @@ naturePublis_y :: Array {name :: String, value :: Number} ...@@ -58,13 +57,12 @@ naturePublis_y :: Array {name :: String, value :: Number}
naturePublis_y = map (\(Tuple n v) -> {name: n, value: toNumber v }) (zip naturePublis_x naturePublis_y') naturePublis_y = map (\(Tuple n v) -> {name: n, value: toNumber v }) (zip naturePublis_x naturePublis_y')
naturePublis :: Options naturePublis :: Options
naturePublis = Options { mainTitle : "Nature of publications" naturePublis = Options
{ mainTitle : "Nature of publications"
, subTitle : "Distribution by type" , subTitle : "Distribution by type"
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [SeriesD1 $ series Funnel "Funnel Data" naturePublis_y] , yAxis : yAxis' { position: "left", show: false }
, yAxisFormat : (YAxisFormat { position : "left" , series : [seriesFunnelD1 { name: "Funnel Data" } naturePublis_y]
, visible : false
})
, addZoom : false , addZoom : false
} }
...@@ -77,15 +75,14 @@ globalPublis_y = [1,4,2,1,1,2,1,1,8,38,234,76,40,82,75,202,1475,1092,1827,2630,4 ...@@ -77,15 +75,14 @@ globalPublis_y = [1,4,2,1,1,2,1,1,8,38,234,76,40,82,75,202,1475,1092,1827,2630,4
globalPublis :: Options globalPublis :: Options
globalPublis = (Options { mainTitle : "Global Scientific Publications" globalPublis = Options
{ mainTitle : "Global Scientific Publications"
, subTitle : "Distribution of scientific publications by IMT's Schools over time" , subTitle : "Distribution of scientific publications by IMT's Schools over time"
, xAxis : xAxis (map show globalPublis_x) , xAxis : xAxis' (map show globalPublis_x)
, yAxis : [SeriesD1 $ series Bar "Number of publication of IMT / year" $ map (\n -> {name: "", value: toNumber n }) globalPublis_y] , yAxis : yAxis' { position: "left", show: true }
, yAxisFormat : (YAxisFormat { position : "left" , series : [seriesBarD1 {name: "Number of publication of IMT / year"} $ map (\n -> {name: "", value: toNumber n }) globalPublis_y]
, visible : true
})
, addZoom : true , addZoom : true
}) }
...@@ -94,49 +91,51 @@ distriBySchool_y = [Tuple "Télécom Bretagne" 1150,Tuple "Télécom SudParis" 9 ...@@ -94,49 +91,51 @@ distriBySchool_y = [Tuple "Télécom Bretagne" 1150,Tuple "Télécom SudParis" 9
,Tuple "Télécom Ecole de Management" 52,Tuple "Mines Albi-Carmaux" 6] ,Tuple "Télécom Ecole de Management" 52,Tuple "Mines Albi-Carmaux" 6]
distriBySchool :: Options distriBySchool :: Options
distriBySchool = Options { mainTitle : "School production in 2017" distriBySchool = Options
{ mainTitle : "School production in 2017"
, subTitle : "Distribution by school" , subTitle : "Distribution by school"
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [ SeriesD1 $ series Pie "Pie data" (map (\(Tuple n v) -> {name: n, value: toNumber v}) distriBySchool_y)] , yAxis : yAxis' { position : "", show: false }
, yAxisFormat : (YAxisFormat { position : "" , series : [ seriesPieD1 {name: "Pie data"} (map (\(Tuple n v) -> {name: n, value: toNumber v}) distriBySchool_y)]
, visible : false
})
, addZoom : false , addZoom : false
} }
scatterEx :: Options scatterEx :: Options
scatterEx = Options { mainTitle : "Scatter test" scatterEx = Options
{ mainTitle : "Scatter test"
, subTitle : "Scatter subtitle" , subTitle : "Scatter subtitle"
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [ SeriesD2 $ seriesD2 "name1" Scatter 10.0 [[2.0,3.0],[3.0,4.0]] , yAxis : yAxis' { position: "", show: true }
, SeriesD2 $ seriesD2 "name2" Scatter 5.0 [[1.0,3.0],[5.0,4.0]] , series : [ seriesScatterD2 {name: "name1", symbolSize: 10.0} [[2.0,3.0],[3.0,4.0]]
, SeriesD2 $ seriesD2 "name3" Scatter 10.0 [[10.0,3.0],[8.0,4.0]] , seriesScatterD2 {name: "name2", symbolSize: 5.0 } [[1.0,3.0],[5.0,4.0]]
] , seriesScatterD2 {name: "name3", symbolSize: 10.0} [[10.0,3.0],[8.0,4.0]]
, yAxisFormat : (YAxisFormat { position : "" ]
, visible : true
})
, addZoom : false , addZoom : false
} }
sankeyEx :: Options sankeyEx :: Options
sankeyEx = Options { mainTitle : "" sankeyEx = Options
{ mainTitle : ""
, subTitle : "" , subTitle : ""
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [ mkSankey [{name : "a"}, {name : "b"}, {name:"c"}, {name:"d"}] , yAxis : yAxis' { position: "", show: false }
[{source : "a", target : "b", value :2.0} , series :
[ seriesSankey
{ "data":
[ {name : "a"}, {name : "b"}
, {name:"c"}, {name:"d"} ]
, links:
[ {source : "a", target : "b", value :2.0}
, {source : "a", target : "c", value :1.0} , {source : "a", target : "c", value :1.0}
, {source : "b", target : "c", value :1.0} , {source : "b", target : "c", value :1.0}
, {source : "b", target : "d", value :3.0} , {source : "b", target : "d", value :3.0}
] ]
, layout: "none"
}
] ]
, yAxisFormat : (YAxisFormat { position : ""
, visible : false
})
, addZoom : false , addZoom : false
} }
treeData :: Array TreeData treeData :: Array TreeData
treeData = [ treeNode "nodeA" 10.0 [ treeLeaf "nodeAa" 4.0 treeData = [ treeNode "nodeA" 10.0 [ treeLeaf "nodeAa" 4.0
, treeLeaf "nodeAb" 5.0 , treeLeaf "nodeAb" 5.0
...@@ -183,28 +182,24 @@ treeData' = [ treeNode "nodeA" 10.0 [ treeLeaf "nodeAa" 4.0 ...@@ -183,28 +182,24 @@ treeData' = [ treeNode "nodeA" 10.0 [ treeLeaf "nodeAa" 4.0
treeMapEx :: Options treeMapEx :: Options
treeMapEx = Options { mainTitle : "" treeMapEx = Options
{ mainTitle : ""
, subTitle : "" , subTitle : ""
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [mkTree TreeMap treeData] , yAxis : yAxis' { position: "", show: false }
, yAxisFormat : (YAxisFormat { position : "" , series : [mkTree TreeMap treeData]
, visible : false
})
, addZoom : false , addZoom : false
} }
treeEx :: Options treeEx :: Options
treeEx = Options { mainTitle : "Tree" treeEx = Options
{ mainTitle : "Tree"
, subTitle : "Radial" , subTitle : "Radial"
, xAxis : xAxis [] , xAxis : xAxis' []
, yAxis : [mkTree TreeRadial treeData'] , yAxis : yAxis' { position: "", show: false }
, yAxisFormat : (YAxisFormat { position : "" , series : [mkTree TreeRadial treeData']
, visible : false
})
, addZoom : false , addZoom : false
} }
layoutDashboard :: Spec {} {} Void layoutDashboard :: Spec {} {} Void
layoutDashboard = simpleSpec defaultPerformAction render layoutDashboard = simpleSpec defaultPerformAction render
module Gargantext.Pages.Corpus.Metrics where module Gargantext.Pages.Corpus.Metrics where
import Data.Set as Set
import Data.Array (foldl) import Data.Array (foldl)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Map (fromFoldableWith, Map(), keys, lookup) import Data.Map as Map
import Data.Map (Map)
import Data.Argonaut (class DecodeJson, decodeJson, (.?)) import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Effect.Aff (Aff) import Effect.Aff (Aff)
...@@ -12,10 +12,12 @@ import Gargantext.Config.REST (get) ...@@ -12,10 +12,12 @@ import Gargantext.Config.REST (get)
import React (ReactClass, ReactElement, createElement) import React (ReactClass, ReactElement, createElement)
import Thermite (Spec, Render, defaultPerformAction, simpleSpec, createClass) import Thermite (Spec, Render, defaultPerformAction, simpleSpec, createClass)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Types (TermList) import Gargantext.Types (TermList(..))
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Components.Charts.Options.ECharts import Gargantext.Components.Charts.Options.ECharts
import Gargantext.Components.Charts.Options.Type
import Gargantext.Components.Charts.Options.Series import Gargantext.Components.Charts.Options.Series
import Gargantext.Components.Charts.Options.Color
type Path = type Path =
{ corpusId :: Int { corpusId :: Int
...@@ -59,25 +61,33 @@ loadedMetricsSpec = simpleSpec defaultPerformAction render ...@@ -59,25 +61,33 @@ loadedMetricsSpec = simpleSpec defaultPerformAction render
render dispatch {loaded} {} _ = [chart (scatterOptions loaded)] render dispatch {loaded} {} _ = [chart (scatterOptions loaded)]
scatterOptions :: Array Metric -> Options scatterOptions :: Array Metric -> Options
scatterOptions ds = Options scatterOptions metrics = Options
{ mainTitle : "TODO Scatter test" { mainTitle : "TODO Scatter test"
, subTitle : "TODO Scatter subtitle" , subTitle : "TODO Scatter subtitle"
, xAxis : xAxis [] -- $ SeriesD2 $ seriesD2 Scatter 5.0 (_.x <$> ds) , xAxis : xAxis { min: 0 }
, yAxis : map2series ( metric2map ds ) , yAxis : yAxis' { position : "", show: true }
, yAxisFormat : (YAxisFormat { position : "" , series : map2series $ metric2map metrics
, visible : true
})
, addZoom : false , addZoom : false
} }
where where
metric2map :: Array Metric -> Map TermList (Array (Array Number)) metric2map :: Array Metric -> Map TermList (Array Metric)
metric2map ds = fromFoldableWith (<>) $ map (\(Metric {x:x,y:y,cat:cat}) -> Tuple cat [[x,y]]) ds metric2map ds = Map.fromFoldableWith (<>) $ (\(Metric m) -> Tuple m.cat [Metric m]) <$> ds
--{- --{-
map2series :: Map TermList (Array (Array Number)) -> Array Serie map2series :: Map TermList (Array Metric) -> Array Series
map2series ms = map (\k -> maybe (toSeries k [[]]) (toSeries k) $ lookup k ms) ((Set.toUnfoldable $ keys ms) :: (Array TermList)) map2series ms = toSeries =<< Map.toUnfoldable ms
where where
toSeries k xs = SeriesD2 $ seriesD2 (show k) Scatter 5.0 xs -- TODO colors are not respected yet
toSeries (Tuple k ms) = toSeries' color <$> ms
where
color =
case k of
StopTerm -> red
GraphTerm -> blue
CandidateTerm -> magenta
toSeries' color (Metric {label,x,y}) =
seriesScatterD2 {name: label, symbolSize: 5.0, itemStyle: itemStyle {color}}
[[x,y]]
--} --}
getMetrics :: Path -> Aff Loaded getMetrics :: Path -> Aff Loaded
......
...@@ -5,6 +5,7 @@ import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJso ...@@ -5,6 +5,7 @@ import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJso
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Gargantext.Prelude import Gargantext.Prelude
import Prim.Row (class Union)
data TermSize = MonoTerm | MultiTerm data TermSize = MonoTerm | MultiTerm
...@@ -70,3 +71,6 @@ termLists = [ { desc: "All terms", mval: Nothing } ...@@ -70,3 +71,6 @@ termLists = [ { desc: "All terms", mval: Nothing }
, { desc: "Candidate terms", mval: Just CandidateTerm } , { desc: "Candidate terms", mval: Just CandidateTerm }
] ]
-- | Proof that row `r` is a subset of row `s`
class Optional (r :: # Type) (s :: # Type)
instance optionalInstance :: Union r t s => Optional r s
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment