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'}
data3 :: DataN
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}
......
module Gargantext.Components.Charts.Options.Series where
import Effect.Exception (error, Error(..))
import Unsafe.Coerce (unsafeCoerce)
import Prelude
......@@ -30,22 +31,23 @@ data SeriesShape = Line
| ThemeRiver
instance showSeriesShape :: Show SeriesShape where
show Line = "line"
show Bar = "bar"
show Pie = "pie"
show Sunburst = "sunburst"
show EffectScatter = "effectScatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-effect
show Funnel = "funnel"
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 _ = ""
show Sunburst = "sunburst"
show _ = "not implemented yet: should throw error here"
seriesType :: SeriesShape -> SeriesType
seriesType = SeriesType <<< show
type Series = {}
data Serie = SeriesD1 D1 | SeriesD2 D2
data Serie = SeriesD1 D1 | SeriesD2 D2 | SeriesSankey Sankey
type D1 =
{ name :: String
......@@ -60,62 +62,32 @@ type D2 =
, "type" :: SeriesType
}
toSeries :: Serie -> Series
toSeries (SeriesD1 a) = unsafeCoerce a
toSeries (SeriesD2 a) = unsafeCoerce a
toSeries (SeriesD1 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
-- ,
-- 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
-- }]
-- }
-- };
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=treemap-simple
......@@ -160,48 +132,3 @@ toSeries (SeriesD2 a) = unsafeCoerce a
......@@ -15,8 +15,8 @@ newtype ChartAlign = ChartAlign String
type Echarts =
{ className :: Maybe String
, style :: Maybe String -- objealect-black-altdarkmincnaquadahherry-blossomect,
, theme :: Maybe String
, style :: Maybe String -- objealect-black-altdarkmincnaquadahherry-blossomect,
, theme :: Maybe String
, group :: Maybe String
, option :: Option -- PropTypes.object.isRequired,
, initOpts :: Maybe String -- PropTypes.object,
......
......@@ -34,6 +34,7 @@ render dispatch _ state _ = [
[ "Télécom Bretagne", "Mines Nantes", "Eurecom"]
)
, chart scatterEx
, chart sankeyEx
]
where
myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0}
......@@ -109,7 +110,10 @@ scatterEx :: Options
scatterEx = Options { mainTitle : "Scatter test"
, subTitle : "Scatter subtitle"
, 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
})
......@@ -117,5 +121,24 @@ scatterEx = Options { mainTitle : "Scatter test"
}
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 : ""
, visible : true
})
, addZoom : false
}
layoutDashboard :: forall props. Spec State props Action
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