-
Notifications
You must be signed in to change notification settings - Fork 81
/
09_3_icicle.fsx
112 lines (88 loc) · 3.27 KB
/
09_3_icicle.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(**
---
title: Icicle Charts
category: Categorical Charts
categoryindex: 10
index: 4
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 2.0.0"
#r "nuget: Giraffe.ViewEngine, 1.4.0"
#r "../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll"
Plotly.NET.Defaults.DefaultDisplayOptions <-
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# Icicle charts
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
*Summary:* This example shows how to create icicle charts in F#.
Icicle charts visualize hierarchical data using rectangular sectors that cascade from root to leaves in one of four directions: up, down, left, or right.
Similar to Sunburst charts and Treemaps charts, the hierarchy is defined by labels and parents attributes.
Click on one sector to zoom in/out, which also displays a pathbar on the top of your icicle.
To zoom out, you can click the parent sector or click the pathbar as well.
*)
open Plotly.NET
open Plotly.NET.TraceObjects
let character =
[ "Eve"; "Cain"; "Seth"; "Enos"; "Noam"; "Abel"; "Awan"; "Enoch"; "Azura" ]
let parent = [ ""; "Eve"; "Eve"; "Seth"; "Seth"; "Eve"; "Eve"; "Awan"; "Eve" ]
let icicle =
Chart.Icicle(
labels = character,
parents = parent,
ShowSectionColorScale = true,
SectionColorScale = StyleParam.Colorscale.Viridis,
TilingOrientation = StyleParam.Orientation.Vertical,
TilingFlip = StyleParam.TilingFlip.Y,
PathBarEdgeShape = StyleParam.PathbarEdgeShape.BackSlash
)
(*** condition: ipynb ***)
#if IPYNB
icicle
#endif // IPYNB
(***hide***)
icicle |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## More styled example
This example shows the usage of some of the styling possibility using `Chart.Icicle`.
For even more styling control, use the respective TraceStyle function `TraceDomainStyle.Icicle`
*)
let icicleStyled =
let labelsParents =
[ ("A", ""), 20
("B", ""), 1
("C", ""), 2
("D", ""), 3
("E", ""), 4
("AA", "A"), 15
("AB", "A"), 5
("BA", "B"), 1
("AAA", "AA"), 10
("AAB", "AA"), 5 ]
Chart.Icicle(
labelsparents = (labelsParents |> Seq.map fst),
Values = (labelsParents |> Seq.map snd),
BranchValues = StyleParam.BranchValues.Total, // branch values are the total of their childrens values
SectionColorScale = StyleParam.Colorscale.Viridis,
ShowSectionColorScale = true,
SectionOutlineColor = Color.fromKeyword Black,
Tiling = IcicleTiling.init (Flip = StyleParam.TilingFlip.XY),
UseDefaults = false
)
(*** condition: ipynb ***)
#if IPYNB
icicleStyled
#endif // IPYNB
(***hide***)
icicleStyled |> GenericChart.toChartHTML
(***include-it-raw***)