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 ...@@ -23,6 +23,10 @@ foreign import eChartsClass :: R.ReactClass Echarts
chart :: Options -> R.ReactElement chart :: Options -> R.ReactElement
chart = echarts <<< chartWith <<< opts chart = echarts <<< chartWith <<< opts
chart' :: Options -> R.ReactElement
chart' = echarts <<< chartWith <<< opts'
chartWith :: Option -> Echarts chartWith :: Option -> Echarts
chartWith opts = { className : Nothing chartWith opts = { className : Nothing
, style : Nothing , style : Nothing
...@@ -115,7 +119,7 @@ data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'} ...@@ -115,7 +119,7 @@ data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'}
xAxis :: Array String -> XAxis xAxis :: Array String -> XAxis
--xAxis [] = unsafeCoerce {} xAxis [] = unsafeCoerce {}
xAxis xs = { "data": xData xs xAxis xs = { "data": xData xs
, "type": "category" , "type": "category"
, axisTick: {alignWithLabel: true} , axisTick: {alignWithLabel: true}
...@@ -211,6 +215,32 @@ opts (Options { mainTitle : mainTitle ...@@ -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 data Zoom = Slider | Inside
instance showZoom :: Show Zoom where instance showZoom :: Show Zoom where
......
...@@ -38,6 +38,7 @@ instance showSeriesShape :: Show SeriesShape where ...@@ -38,6 +38,7 @@ instance showSeriesShape :: Show SeriesShape where
show Line = "line" show Line = "line"
show Pie = "pie" show Pie = "pie"
show Sankey = "sankey" show Sankey = "sankey"
show TreeMap = "treemap"
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 Sunburst = "sunburst" show Sunburst = "sunburst"
show _ = "not implemented yet: should throw error here" show _ = "not implemented yet: should throw error here"
...@@ -47,7 +48,7 @@ seriesType = SeriesType <<< show ...@@ -47,7 +48,7 @@ seriesType = SeriesType <<< show
type Series = {} type Series = {}
data Serie = SeriesD1 D1 | SeriesD2 D2 | SeriesSankey Sankey data Serie = SeriesD1 D1 | SeriesD2 D2 | SerieSankey Sankey | SerieTreeMap TreeMap
type D1 = type D1 =
{ name :: String { name :: String
...@@ -63,9 +64,10 @@ type D2 = ...@@ -63,9 +64,10 @@ type D2 =
} }
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 toSeries (SerieSankey a) = unsafeCoerce a
toSeries (SerieTreeMap a) = unsafeCoerce a
-- | Sankey Chart -- | Sankey Chart
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple -- https://ecomfe.github.io/echarts-examples/public/editor.html?c=sankey-simple
...@@ -82,45 +84,49 @@ type Link = { source :: String ...@@ -82,45 +84,49 @@ type Link = { source :: String
} }
mkSankey :: Array Node -> Array Link -> Serie mkSankey :: Array Node -> Array Link -> Serie
mkSankey ns ls = SeriesSankey {"type" : seriesType Sankey mkSankey ns ls = SerieSankey {"type" : seriesType Sankey
, layout : "none" , layout : "none"
, "data" : ns , "data" : ns
, "links" : ls , "links" : ls
} }
-- | TreeMap Chart
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
-- mkTreeMap :: Array TreeMapTree -> Serie
--https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple mkTreeMap ts = SerieTreeMap { "type" : seriesType TreeMap
-- , "data" : map toTreeMap ts
--option = { }
-- series: [{
-- type: 'treemap', type TreeMap = { "type" :: SeriesType
-- data: [{ , "data" :: Array TreeMapTree
-- name: 'nodeA', // First tree }
-- value: 10,
-- children: [{ data TreeMapTree = TreeMapLeaf TreeMapLeaf
-- name: 'nodeAa', // First leaf of first tree | TreeMapNode TreeMapNode
-- value: 4
-- }, { toTreeMap :: TreeMapTree -> TreeMapTree
-- name: 'nodeAb', // Second leaf of first tree toTreeMap (TreeMapLeaf x) = unsafeCoerce x
-- value: 6 toTreeMap (TreeMapNode x) = unsafeCoerce { name : x.name
-- }] , value : x.value
-- }, { , children : (map toTreeMap x.children)
-- name: 'nodeB', // Second tree }
-- value: 20,
-- children: [{
-- name: 'nodeBa', // Son of first tree type TreeMapNode = { name :: String
-- value: 20, , value :: Number
-- children: [{ , children :: Array TreeMapTree
-- name: 'nodeBa1', // Granson of first tree }
-- value: 20
-- }] 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 -- https://ecomfe.github.io/echarts-examples/public/data/asset/data/flare.json
......
...@@ -35,6 +35,7 @@ render dispatch _ state _ = [ ...@@ -35,6 +35,7 @@ render dispatch _ state _ = [
) )
, chart scatterEx , chart scatterEx
, chart sankeyEx , chart sankeyEx
, chart' treeMapEx
] ]
where where
myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0} myData = [SeriesD1 $ series Bar "Bar Data" [ {name: "val1", value: 50.0}
...@@ -139,6 +140,26 @@ sankeyEx = Options { mainTitle : "" ...@@ -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 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