Commit 0747ebfd authored by Alexandre Delanoë's avatar Alexandre Delanoë

[TYPES] Heteregenous Series Array and uniformization before rending it (method).

parent 5507abf5
module Gargantext.Components.Charts.Options.Series where module Gargantext.Components.Charts.Options.Series where
import Unsafe.Coerce (unsafeCoerce)
import Prelude import Prelude
import Gargantext.Components.Charts.Options.Data (DataS) import Gargantext.Components.Charts.Options.Data (DataS)
newtype SeriesType = SeriesType String newtype SeriesType = SeriesType String
type SeriesName = String type SeriesName = String
...@@ -42,16 +44,164 @@ seriesType :: SeriesShape -> SeriesType ...@@ -42,16 +44,164 @@ seriesType :: SeriesShape -> SeriesType
seriesType = SeriesType <<< show seriesType = SeriesType <<< show
data Series = SeriesD1 D1 | SeriesD2 D2 type Series = {}
data Series' = SeriesD1 D1 | SeriesD2 D2
type D1 = type D1 =
{ name :: String { name :: String
, "data" :: Array DataS
, "type" :: SeriesType , "type" :: SeriesType
, "data" :: Array DataS
} }
-- | Scatter Dimension 2 data
type D2 = type D2 =
{ "symbolSize" :: Number { "symbolSize" :: Number
, "data" :: Array (Array Number) , "data" :: Array (Array Number)
, "type" :: SeriesType , "type" :: SeriesType
} }
toSeries :: Series' -> Series
toSeries (SeriesD1 a) = unsafeCoerce a
toSeries (SeriesD2 a) = unsafeCoerce a
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple
-- type Sankey = { "type" :: SeriesType
-- , "layout" :: String
-- ,
-- option = {
-- series: {
-- type: 'sankey',
-- layout:'none',
-- data: [{
-- name: 'a'
-- }, {
-- name: 'b'
-- }, {
-- name: 'a1'
-- }, {
-- name: 'a2'
-- }, {
-- name: 'b1'
-- }, {
-- name: 'c'
-- }],
-- links: [{
-- source: 'a',
-- target: 'a1',
-- value: 5
-- }, {
-- source: 'a',
-- target: 'a2',
-- value: 3
-- }, {
-- source: 'b',
-- target: 'b1',
-- value: 8
-- }, {
-- source: 'a',
-- target: 'b1',
-- value: 3
-- }, {
-- source: 'b1',
-- target: 'a1',
-- value: 1
-- }, {
-- source: 'b1',
-- target: 'c',
-- value: 2
-- }]
-- }
-- };
--
--https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
--
--option = {
-- series: [{
-- type: 'treemap',
-- data: [{
-- name: 'nodeA', // First tree
-- value: 10,
-- children: [{
-- name: 'nodeAa', // First leaf of first tree
-- value: 4
-- }, {
-- name: 'nodeAb', // Second leaf of first tree
-- value: 6
-- }]
-- }, {
-- name: 'nodeB', // Second tree
-- value: 20,
-- children: [{
-- name: 'nodeBa', // Son of first tree
-- value: 20,
-- children: [{
-- name: 'nodeBa1', // Granson of first tree
-- value: 20
-- }]
-- }]
-- }]
-- }]
--};
--
--
-- https://ecomfe.github.io/echarts-examples/public/data/asset/data/flare.json
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=tree-radial
-- https://ecomfe.github.io/echarts-examples/public/data/asset/data/life-expectancy-table.json
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter3D-dataset&gl=1
...@@ -33,19 +33,20 @@ render dispatch _ state _ = [ ...@@ -33,19 +33,20 @@ render dispatch _ state _ = [
, div [className "row"] (map (\school -> div [className "col-md-4 content"] [chart $ focus school]) , div [className "row"] (map (\school -> div [className "col-md-4 content"] [chart $ focus school])
[ "Télécom Bretagne", "Mines Nantes", "Eurecom"] [ "Télécom Bretagne", "Mines Nantes", "Eurecom"]
) )
--, chart scatterEx , chart scatterEx
] ]
where where
myData = [toSeries $ SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0}
, {name: "val2", value: 70.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 : [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0} , yAxis : myData
, {name: "val2", value: 70.0}
, {name: "val3", value: 80.0}
]
]
, yAxisFormat : (YAxisFormat { position : "left" , yAxisFormat : (YAxisFormat { position : "left"
, visible : true , visible : true
}) })
...@@ -53,7 +54,6 @@ render dispatch _ state _ = [ ...@@ -53,7 +54,6 @@ render dispatch _ state _ = [
, addZoom : false , addZoom : false
} }
----------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------
naturePublis_x = ["Com","Articles","Thèses","Reports"] naturePublis_x = ["Com","Articles","Thèses","Reports"]
...@@ -65,7 +65,7 @@ naturePublis :: Options ...@@ -65,7 +65,7 @@ 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 : [toSeries $ SeriesD1 $ series Funnel "Funnel Data" naturePublis_y]
, yAxisFormat : (YAxisFormat { position : "left" , yAxisFormat : (YAxisFormat { position : "left"
, visible : false , visible : false
}) })
...@@ -82,7 +82,7 @@ globalPublis :: Options ...@@ -82,7 +82,7 @@ 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 : [toSeries $ SeriesD1 $ series Bar "Number of publication of IMT / year" $ map (\n -> {name: "", value: toNumber n }) globalPublis_y]
, yAxisFormat : (YAxisFormat { position : "left" , yAxisFormat : (YAxisFormat { position : "left"
, visible : true , visible : true
}) })
...@@ -98,7 +98,7 @@ distriBySchool :: Options ...@@ -98,7 +98,7 @@ 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 : [ toSeries $ SeriesD1 $ series Pie "Pie data" (map (\(Tuple n v) -> {name: n, value: toNumber v}) distriBySchool_y)]
, yAxisFormat : (YAxisFormat { position : "" , yAxisFormat : (YAxisFormat { position : ""
, visible : false , visible : false
}) })
...@@ -109,41 +109,13 @@ scatterEx :: Options ...@@ -109,41 +109,13 @@ 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 Scatter 20.0 [[2.0,3.0],[3.0,4.0]]] , yAxis : [ toSeries $ SeriesD2 $ seriesD2 Scatter 20.0 [[2.0,3.0],[3.0,4.0]]]
, yAxisFormat : (YAxisFormat { position : "" , yAxisFormat : (YAxisFormat { position : ""
, visible : false , visible : true
}) })
, addZoom : false , addZoom : false
} }
--scatterEx :: Options
--scatterEx = { -- title: "title"
-- xAxis : {}
-- , yAxis : {}
-- , "data" : []
-- , series : [ { "symbolSize" : 20
-- , data : [[1,2]]
-- , "type" : "scatter"
-- }
-- ]
-- }
-- Option {mainTitle : "Scatter ex"
-- , subTitle : "Subtitle"
-- , xAxis : xAxis []
-- , yAxis : []
-- , yAxisFormat : (YAxisFormat { position : ""
-- , visible : false
-- })
-- --, series : [SeriesD2 20 [[2,2]] Scatter]
--
-- , addZoom : false
-- }
layoutDashboard :: forall props. Spec State props Action layoutDashboard :: forall props. Spec State props Action
layoutDashboard = simpleSpec performAction render layoutDashboard = simpleSpec performAction render
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