Commit 15ca83bf authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Chart] Simple Sankey.

parent 59f17f4b
...@@ -113,7 +113,9 @@ data2 = {name: "Favorites", icon: icon $ Shape Circle, textStyle: textStyle'} ...@@ -113,7 +113,9 @@ data2 = {name: "Favorites", icon: icon $ Shape Circle, textStyle: textStyle'}
data3 :: DataN 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 :: Array String -> XAxis
xAxis [] = unsafeCoerce {}
xAxis xs = { "data": xData xs xAxis xs = { "data": xData xs
, "type": "category" , "type": "category"
, axisTick: {alignWithLabel: true} , axisTick: {alignWithLabel: true}
......
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
...@@ -30,22 +31,23 @@ data SeriesShape = Line ...@@ -30,22 +31,23 @@ data SeriesShape = Line
| ThemeRiver | ThemeRiver
instance showSeriesShape :: Show SeriesShape where instance showSeriesShape :: Show SeriesShape where
show Line = "line"
show Bar = "bar" show Bar = "bar"
show Pie = "pie" show EffectScatter = "effectScatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-effect
show Sunburst = "sunburst"
show Funnel = "funnel" show Funnel = "funnel"
show Heatmap = "heatmap" show Heatmap = "heatmap"
show EffectScatter = "effectScatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-effect show Line = "line"
show Pie = "pie"
show Sankey = "sankey"
show Scatter = "scatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-simple show Scatter = "scatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-simple
show _ = "" show Sunburst = "sunburst"
show _ = "not implemented yet: should throw error here"
seriesType :: SeriesShape -> SeriesType seriesType :: SeriesShape -> SeriesType
seriesType = SeriesType <<< show seriesType = SeriesType <<< show
type Series = {} type Series = {}
data Serie = SeriesD1 D1 | SeriesD2 D2 data Serie = SeriesD1 D1 | SeriesD2 D2 | SeriesSankey Sankey
type D1 = type D1 =
{ name :: String { name :: String
...@@ -60,62 +62,32 @@ type D2 = ...@@ -60,62 +62,32 @@ type D2 =
, "type" :: SeriesType , "type" :: SeriesType
} }
toSeries :: Serie -> Series toSeries :: Serie -> Series
toSeries (SeriesD1 a) = unsafeCoerce a toSeries (SeriesD1 a) = unsafeCoerce a
toSeries (SeriesD2 a) = unsafeCoerce a toSeries (SeriesD2 a) = unsafeCoerce a
toSeries (SeriesSankey a) = unsafeCoerce a
-- | Sankey Chart
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple
type Sankey = { "type" :: SeriesType
, layout :: String
, "data" :: Array Node
, "links" :: Array Link
}
type Node = { name :: String}
type Link = { source :: String
, target :: String
, value :: Number
}
mkSankey :: Array Node -> Array Link -> Sankey
mkSankey ns ls = {"type" : seriesType Sankey
, layout : "none"
, "data" : ns
, "links" : ls
}
-- 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 --https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
...@@ -160,48 +132,3 @@ toSeries (SeriesD2 a) = unsafeCoerce a ...@@ -160,48 +132,3 @@ toSeries (SeriesD2 a) = unsafeCoerce a
...@@ -34,6 +34,7 @@ render dispatch _ state _ = [ ...@@ -34,6 +34,7 @@ render dispatch _ state _ = [
[ "Télécom Bretagne", "Mines Nantes", "Eurecom"] [ "Télécom Bretagne", "Mines Nantes", "Eurecom"]
) )
, chart scatterEx , chart scatterEx
, chart sankeyEx
] ]
where where
myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0} myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0}
...@@ -109,7 +110,26 @@ scatterEx :: Options ...@@ -109,7 +110,26 @@ 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 : [ SeriesD2 $ seriesD2 Scatter 10.0 [[2.0,3.0],[3.0,4.0]]
, SeriesD2 $ seriesD2 Scatter 5.0 [[1.0,3.0],[5.0,4.0]]
, SeriesD2 $ seriesD2 Scatter 10.0 [[10.0,3.0],[8.0,4.0]]
]
, yAxisFormat : (YAxisFormat { position : ""
, visible : true
})
, addZoom : false
}
sankeyEx :: Options
sankeyEx = Options { mainTitle : "Sankey"
, subTitle : "Sankey subtitle"
, xAxis : xAxis []
, yAxis : [ SeriesSankey $ mkSankey [{name : "a"}, {name : "b"}, {name:"c"}]
[{source : "a", target : "b", value :2.0}
, {source : "a", target : "c", value :1.0}
]
]
, yAxisFormat : (YAxisFormat { position : "" , yAxisFormat : (YAxisFormat { position : ""
, visible : true , visible : true
}) })
...@@ -117,5 +137,8 @@ scatterEx = Options { mainTitle : "Scatter test" ...@@ -117,5 +137,8 @@ scatterEx = Options { mainTitle : "Scatter test"
} }
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