Skip to content

Commit 0dd0eba

Browse files
authored
Add Icicle Chart/Trace and related objects (#210)
* Add Icicle Chart/Trace and related objects * add icicle docs * Add icicle tests
1 parent 7d3ea22 commit 0dd0eba

File tree

11 files changed

+450
-15
lines changed

11 files changed

+450
-15
lines changed

Diff for: Plotly.NET.sln

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7B09CC0A-F
8989
docs\09_0_parallel-categories.fsx = docs\09_0_parallel-categories.fsx
9090
docs\09_1_parallel-coords.fsx = docs\09_1_parallel-coords.fsx
9191
docs\09_2_sankey.fsx = docs\09_2_sankey.fsx
92+
docs\09_3_icicle.fsx = docs\09_3_icicle.fsx
9293
docs\10_0_ternary_line_scatter_plots.fsx = docs\10_0_ternary_line_scatter_plots.fsx
9394
docs\10_1_styling_ternary_layouts.fsx = docs\10_1_styling_ternary_layouts.fsx
9495
docs\11_1_carpet_line_scatter_plots.fsx = docs\11_1_carpet_line_scatter_plots.fsx

Diff for: docs/09_3_icicle.fsx

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(**
2+
---
3+
title: Icicle Charts
4+
category: Categorical Charts
5+
categoryindex: 10
6+
index: 4
7+
---
8+
*)
9+
10+
11+
(*** hide ***)
12+
13+
(*** condition: prepare ***)
14+
#r "nuget: Newtonsoft.JSON, 12.0.3"
15+
#r "nuget: DynamicObj"
16+
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
17+
18+
(*** condition: ipynb ***)
19+
#if IPYNB
20+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
21+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
22+
#endif // IPYNB
23+
24+
(**
25+
# Icicle charts
26+
27+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
28+
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
29+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
30+
31+
*Summary:* This example shows how to create icicle charts in F#.
32+
33+
Icicle charts visualize hierarchical data using rectangular sectors that cascade from root to leaves in one of four directions: up, down, left, or right.
34+
Similar to Sunburst charts and Treemaps charts, the hierarchy is defined by labels and parents attributes.
35+
Click on one sector to zoom in/out, which also displays a pathbar on the top of your icicle.
36+
To zoom out, you can click the parent sector or click the pathbar as well.
37+
*)
38+
39+
open Plotly.NET
40+
open Plotly.NET.TraceObjects
41+
42+
let character = ["Eve"; "Cain"; "Seth"; "Enos"; "Noam"; "Abel"; "Awan"; "Enoch"; "Azura"]
43+
let parent = [""; "Eve"; "Eve"; "Seth"; "Seth"; "Eve"; "Eve"; "Awan"; "Eve" ]
44+
45+
let icicle =
46+
Chart.Icicle(
47+
character,
48+
parent,
49+
ShowScale = true,
50+
ColorScale = StyleParam.Colorscale.Viridis,
51+
TilingOrientation = StyleParam.Orientation.Vertical, // wether the icicles will grow in the vertical (up/down) or horizontal (left/right) direction
52+
TilingFlip = StyleParam.TilingFlip.Y, // flip in the Y direction (grow up instead of down)
53+
PathBarEdgeShape = StyleParam.PathbarEdgeShape.BackSlash
54+
)
55+
56+
(*** condition: ipynb ***)
57+
#if IPYNB
58+
icicle
59+
#endif // IPYNB
60+
61+
(***hide***)
62+
icicle |> GenericChart.toChartHTML
63+
(***include-it-raw***)
64+

Diff for: src/Plotly.NET/ChartAPI/ChartDomain.fs

+123-1
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,126 @@ module ChartDomain =
559559
Gauge = gauge
560560
)
561561
)
562-
|> GenericChart.ofTraceObject
562+
|> GenericChart.ofTraceObject
563+
564+
/// creates table out of header sequence and row sequences
565+
[<Extension>]
566+
static member Icicle
567+
(
568+
labels : seq<#IConvertible>,
569+
parents : seq<#IConvertible>,
570+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
571+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
572+
[<Optional;DefaultParameterValue(null)>] ?Values : seq<#IConvertible>,
573+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
574+
[<Optional;DefaultParameterValue(null)>] ?MultiOpacity : seq<float>,
575+
[<Optional;DefaultParameterValue(null)>] ?Color : Color,
576+
[<Optional;DefaultParameterValue(null)>] ?ColorScale : StyleParam.Colorscale,
577+
[<Optional;DefaultParameterValue(null)>] ?ShowScale : bool,
578+
[<Optional;DefaultParameterValue(null)>] ?Marker : Marker,
579+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
580+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
581+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
582+
[<Optional;DefaultParameterValue(null)>] ?MultiTextPosition : seq<StyleParam.TextPosition>,
583+
[<Optional;DefaultParameterValue(null)>] ?Domain : Domain,
584+
[<Optional;DefaultParameterValue(null)>] ?BranchValues : StyleParam.BranchValues,
585+
[<Optional;DefaultParameterValue(null)>] ?Count : StyleParam.IcicleCount,
586+
[<Optional;DefaultParameterValue(null)>] ?TilingOrientation : StyleParam.Orientation,
587+
[<Optional;DefaultParameterValue(null)>] ?TilingFlip : StyleParam.TilingFlip,
588+
[<Optional;DefaultParameterValue(null)>] ?Tiling : IcicleTiling,
589+
[<Optional;DefaultParameterValue(null)>] ?PathBarEdgeShape : StyleParam.PathbarEdgeShape,
590+
[<Optional;DefaultParameterValue(null)>] ?PathBar : Pathbar
591+
) =
592+
593+
let tiling =
594+
Tiling
595+
|> Option.defaultValue(IcicleTiling.init())
596+
|> IcicleTiling.style(?Orientation = TilingOrientation, ?Flip = TilingFlip)
597+
598+
let pathbar =
599+
PathBar
600+
|> Option.defaultValue(Pathbar.init())
601+
|> Pathbar.style(?EdgeShape = PathBarEdgeShape)
602+
603+
TraceDomain.initIcicle(
604+
TraceDomainStyle.Icicle(
605+
?Name = Name ,
606+
?ShowLegend = ShowLegend ,
607+
?Opacity = Opacity ,
608+
Parents = parents ,
609+
?Values = Values ,
610+
Labels = labels ,
611+
?Text = Text ,
612+
?MultiText = MultiText ,
613+
?TextPosition = TextPosition ,
614+
?MultiTextPosition = MultiTextPosition ,
615+
?Domain = Domain ,
616+
?Marker = Marker ,
617+
?BranchValues = BranchValues ,
618+
?Count = Count ,
619+
Tiling = tiling ,
620+
PathBar = pathbar
621+
)
622+
>> TraceStyle.Marker (
623+
?Color = Color,
624+
?MultiOpacity = MultiOpacity,
625+
?Colorscale = ColorScale,
626+
?ShowScale = ShowScale
627+
)
628+
)
629+
|> GenericChart.ofTraceObject
630+
631+
/// creates table out of header sequence and row sequences
632+
[<Extension>]
633+
static member Icicle
634+
(
635+
labelsParents: seq<#IConvertible * #IConvertible>,
636+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
637+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
638+
[<Optional;DefaultParameterValue(null)>] ?Values : seq<#IConvertible>,
639+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
640+
[<Optional;DefaultParameterValue(null)>] ?MultiOpacity : seq<float>,
641+
[<Optional;DefaultParameterValue(null)>] ?Color : Color,
642+
[<Optional;DefaultParameterValue(null)>] ?ColorScale : StyleParam.Colorscale,
643+
[<Optional;DefaultParameterValue(null)>] ?ShowScale : bool,
644+
[<Optional;DefaultParameterValue(null)>] ?Marker : Marker,
645+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
646+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
647+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
648+
[<Optional;DefaultParameterValue(null)>] ?MultiTextPosition : seq<StyleParam.TextPosition>,
649+
[<Optional;DefaultParameterValue(null)>] ?Domain : Domain,
650+
[<Optional;DefaultParameterValue(null)>] ?BranchValues : StyleParam.BranchValues,
651+
[<Optional;DefaultParameterValue(null)>] ?Count : StyleParam.IcicleCount,
652+
[<Optional;DefaultParameterValue(null)>] ?TilingOrientation : StyleParam.Orientation,
653+
[<Optional;DefaultParameterValue(null)>] ?TilingFlip : StyleParam.TilingFlip,
654+
[<Optional;DefaultParameterValue(null)>] ?Tiling : IcicleTiling,
655+
[<Optional;DefaultParameterValue(null)>] ?PathBarEdgeShape : StyleParam.PathbarEdgeShape,
656+
[<Optional;DefaultParameterValue(null)>] ?PathBar : Pathbar
657+
) =
658+
659+
let labels, parents = Seq.unzip labelsParents
660+
661+
Chart.Icicle(
662+
labels, parents,
663+
?Name = Name ,
664+
?ShowLegend = ShowLegend ,
665+
?Values = Values ,
666+
?Opacity = Opacity ,
667+
?MultiOpacity = MultiOpacity ,
668+
?Color = Color ,
669+
?ColorScale = ColorScale ,
670+
?ShowScale = ShowScale ,
671+
?Marker = Marker ,
672+
?Text = Text ,
673+
?MultiText = MultiText ,
674+
?TextPosition = TextPosition ,
675+
?MultiTextPosition = MultiTextPosition ,
676+
?Domain = Domain ,
677+
?BranchValues = BranchValues ,
678+
?Count = Count ,
679+
?TilingOrientation = TilingOrientation ,
680+
?TilingFlip = TilingFlip ,
681+
?Tiling = Tiling ,
682+
?PathBarEdgeShape = PathBarEdgeShape ,
683+
?PathBar = PathBar
684+
)

Diff for: src/Plotly.NET/CommonAbstractions/StyleParams.fs

+33-6
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,19 @@ module StyleParam =
11131113
//--------------------------
11141114
// #I#
11151115
//--------------------------
1116+
1117+
[<RequireQualifiedAccess>]
1118+
type IcicleCount =
1119+
| Branches | Leaves | BranchesLeaves
1120+
static member toString = function
1121+
| Branches -> "branches"
1122+
| Leaves -> "leaves"
1123+
| BranchesLeaves-> "branches+leaves"
1124+
1125+
static member convert = IcicleCount.toString >> box
1126+
override this.ToString() = this |> IcicleCount.toString
1127+
member this.Convert() = this |> IcicleCount.convert
1128+
11161129

11171130
[<RequireQualifiedAccess>]
11181131
type IndicatorMode =
@@ -1144,7 +1157,6 @@ module StyleParam =
11441157
static member convert = IndicatorAlignment.toString >> box
11451158
override this.ToString() = this |> IndicatorAlignment.toString
11461159
member this.Convert() = this |> IndicatorAlignment.convert
1147-
11481160
[<RequireQualifiedAccess>]
11491161
type IndicatorGaugeShape =
11501162
| Angular | Bullet
@@ -2216,7 +2228,22 @@ module StyleParam =
22162228
//--------------------------
22172229
// #T#
22182230
//--------------------------
2219-
2231+
2232+
[<RequireQualifiedAccess>]
2233+
type TilingFlip =
2234+
| X
2235+
| Y
2236+
| XY
2237+
2238+
static member toString = function
2239+
| X -> "x"
2240+
| Y -> "y"
2241+
| XY-> "x+y"
2242+
2243+
static member convert = TilingFlip.toString >> box
2244+
override this.ToString() = this |> TilingFlip.toString
2245+
member this.Convert() = this |> TilingFlip.convert
2246+
22202247
[<RequireQualifiedAccess>]
22212248
type TransitionEasing =
22222249
| Linear
@@ -2404,7 +2431,7 @@ module StyleParam =
24042431
member this.Convert() = this |> UnitMode.convert
24052432

24062433
[<RequireQualifiedAccess>]
2407-
type TreemapEdgeShape =
2434+
type PathbarEdgeShape =
24082435
| ArrowRight | ArrowLeft | Straight | Slash | BackSlash
24092436

24102437
static member toString = function
@@ -2414,9 +2441,9 @@ module StyleParam =
24142441
| Slash -> "/"
24152442
| BackSlash -> """\"""
24162443

2417-
static member convert = TreemapEdgeShape.toString >> box
2418-
override this.ToString() = this |> TreemapEdgeShape.toString
2419-
member this.Convert() = this |> TreemapEdgeShape.convert
2444+
static member convert = PathbarEdgeShape.toString >> box
2445+
override this.ToString() = this |> PathbarEdgeShape.toString
2446+
member this.Convert() = this |> PathbarEdgeShape.convert
24202447

24212448
[<RequireQualifiedAccess>]
24222449
type TreemapTilingPacking =

Diff for: src/Plotly.NET/Playground.fsx

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#load "Error.fs"
9494
#load "Table.fs"
9595
#load "Indicator.fs"
96+
#load "Icicle.fs"
9697

9798
#I "Traces"
9899

@@ -160,6 +161,20 @@ open FSharpAux
160161
open System
161162
open System.IO
162163

164+
let character = ["Eve"; "Cain"; "Seth"; "Enos"; "Noam"; "Abel"; "Awan"; "Enoch"; "Azura"]
165+
let parent = [""; "Eve"; "Eve"; "Seth"; "Seth"; "Eve"; "Eve"; "Awan"; "Eve" ]
166+
167+
Chart.Icicle(
168+
character,
169+
parent,
170+
ShowScale = true,
171+
ColorScale = StyleParam.Colorscale.Viridis,
172+
TilingOrientation = StyleParam.Orientation.Vertical,
173+
TilingFlip = StyleParam.TilingFlip.Y,
174+
PathBarEdgeShape = StyleParam.PathbarEdgeShape.BackSlash
175+
)
176+
|> Chart.show
177+
163178
[
164179
Chart.Indicator(
165180
120., StyleParam.IndicatorMode.NumberDeltaGauge,

Diff for: src/Plotly.NET/Plotly.NET.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<Compile Include="Traces\ObjectAbstractions\Error.fs" />
102102
<Compile Include="Traces\ObjectAbstractions\Table.fs" />
103103
<Compile Include="Traces\ObjectAbstractions\Indicator.fs" />
104+
<Compile Include="Traces\ObjectAbstractions\Icicle.fs" />
104105
<Compile Include="Traces\Trace.fs" />
105106
<Compile Include="Traces\Trace2D.fs" />
106107
<Compile Include="Traces\Trace3D.fs" />

0 commit comments

Comments
 (0)