Commit 3a403771 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Chart] TreeMap added (need to fixe rest of Echarts functions for axis for instance).

parent f0ce010f
......@@ -23,6 +23,10 @@ foreign import eChartsClass :: R.ReactClass Echarts
chart :: Options -> R.ReactElement
chart = echarts <<< chartWith <<< opts
chart' :: Options -> R.ReactElement
chart' = echarts <<< chartWith <<< opts'
chartWith :: Option -> Echarts
chartWith opts = { className : Nothing
, style : Nothing
......@@ -115,7 +119,7 @@ data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'}
xAxis :: Array String -> XAxis
--xAxis [] = unsafeCoerce {}
xAxis [] = unsafeCoerce {}
xAxis xs = { "data": xData xs
, "type": "category"
, axisTick: {alignWithLabel: true}
......@@ -211,6 +215,32 @@ opts (Options { mainTitle : mainTitle
}
opts' :: Options -> Option
opts' (Options { mainTitle : mainTitle
, subTitle : subTitle
, xAxis : xs
, yAxis : ss
, yAxisFormat : (YAxisFormat { position : position
, visible : visible
})
, addZoom : addZoom}) =
{ title: title mainTitle subTitle
, legend : legend
, tooltip: { trigger: "axis"
, formatter: Nothing
}
, grid : {containLabel: false}
, xAxis : unsafeCoerce {}
, series : map toSeries $ ss
, yAxis : unsafeCoerce {}
, dataZoom: if addZoom then [zoom Slider, zoom Inside] else []
, children : unsafeCoerce []
}
data Zoom = Slider | Inside
instance showZoom :: Show Zoom where
......
......@@ -38,6 +38,7 @@ instance showSeriesShape :: Show SeriesShape where
show Line = "line"
show Pie = "pie"
show Sankey = "sankey"
show TreeMap = "treemap"
show Scatter = "scatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-simple
show Sunburst = "sunburst"
show _ = "not implemented yet: should throw error here"
......@@ -47,7 +48,7 @@ seriesType = SeriesType <<< show
type Series = {}
data Serie = SeriesD1 D1 | SeriesD2 D2 | SeriesSankey Sankey
data Serie = SeriesD1 D1 | SeriesD2 D2 | SerieSankey Sankey | SerieTreeMap TreeMap
type D1 =
{ name :: String
......@@ -65,7 +66,8 @@ type D2 =
toSeries :: Serie -> Series
toSeries (SeriesD1 a) = unsafeCoerce a
toSeries (SeriesD2 a) = unsafeCoerce a
toSeries (SeriesSankey a) = unsafeCoerce a
toSeries (SerieSankey a) = unsafeCoerce a
toSeries (SerieTreeMap a) = unsafeCoerce a
-- | Sankey Chart
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple
......@@ -82,45 +84,49 @@ type Link = { source :: String
}
mkSankey :: Array Node -> Array Link -> Serie
mkSankey ns ls = SeriesSankey {"type" : seriesType Sankey
mkSankey ns ls = SerieSankey {"type" : seriesType Sankey
, layout : "none"
, "data" : ns
, "links" : ls
}
-- | TreeMap Chart
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
--
--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
-- }]
-- }]
-- }]
-- }]
--};
--
--
mkTreeMap :: Array TreeMapTree -> Serie
mkTreeMap ts = SerieTreeMap { "type" : seriesType TreeMap
, "data" : map toTreeMap ts
}
type TreeMap = { "type" :: SeriesType
, "data" :: Array TreeMapTree
}
data TreeMapTree = TreeMapLeaf TreeMapLeaf
| TreeMapNode TreeMapNode
toTreeMap :: TreeMapTree -> TreeMapTree
toTreeMap (TreeMapLeaf x) = unsafeCoerce x
toTreeMap (TreeMapNode x) = unsafeCoerce { name : x.name
, value : x.value
, children : (map toTreeMap x.children)
}
type TreeMapNode = { name :: String
, value :: Number
, children :: Array TreeMapTree
}
type TreeMapLeaf = { name :: String
, value :: Number
}
treeMapNode :: String -> Number -> Array TreeMapTree -> TreeMapTree
treeMapNode n v ts = TreeMapNode {name : n, value:v, children:ts}
treeMapLeaf :: String -> Number -> TreeMapTree
treeMapLeaf n v = TreeMapLeaf { name : n, value : v}
-- https://ecomfe.github.io/echarts-examples/public/data/asset/data/flare.json
......
......@@ -35,6 +35,7 @@ render dispatch _ state _ = [
)
, chart scatterEx
, chart sankeyEx
, chart' treeMapEx
]
where
myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0}
......@@ -139,6 +140,26 @@ sankeyEx = Options { mainTitle : ""
}
treeMapData = [ mkTreeMap [ treeMapNode "nodeA" 10.0 [ treeMapLeaf "nodeAa" 4.0
, treeMapLeaf "nodeAb" 5.0
, treeMapLeaf "nodeAc" 1.0
]
, treeMapNode "nodeB" 20.0 [ treeMapNode "nodeBb" 20.0 [treeMapLeaf "nodeBb1" 20.0]
]
]
]
treeMapEx :: Options
treeMapEx = Options { mainTitle : ""
, subTitle : ""
, xAxis : xAxis []
, yAxis : treeMapData
, yAxisFormat : (YAxisFormat { position : ""
, visible : false
})
, addZoom : false
}
layoutDashboard :: forall props. Spec State props Action
......
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