Skip to content

Commit adaf9e3

Browse files
committed
Add parallel categories plot
1 parent e56f52e commit adaf9e3

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

Diff for: src/FSharp.Plotly/Chart.fs

+20-1
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,27 @@ type Chart =
473473
|> TraceStyle.Line(?Width=Width,?Color=Color,?Dash=Dash,?Colorscale=Colorscale)
474474
|> GenericChart.ofTraceObject
475475

476+
///Parallel categories diagram for multidimensional categorical data.
477+
static member ParallelCategories(dims:seq<'key*#seq<'values>>,?Range,?Constraintrange,?Color,?Colorscale,?Width,?Dash,?Domain,?Labelfont,?Tickfont,?Rangefont) =
478+
let dims' =
479+
dims |> Seq.map (fun (k,vals) ->
480+
Dimensions.init(vals)
481+
|> Dimensions.style(vals,?Range=Range,?Constraintrange=Constraintrange,Label=k)
482+
)
483+
Trace.initParallelCategories (
484+
TraceStyle.ParallelCategories(Dimensions=dims',?Domain=Domain,?Labelfont=Labelfont,?Tickfont=Tickfont,?Rangefont=Rangefont)
485+
)
486+
|> TraceStyle.Line(?Width=Width,?Color=Color,?Dash=Dash,?Colorscale=Colorscale)
487+
|> GenericChart.ofTraceObject
488+
489+
static member ParallelCategories(dims:seq<Dimensions>,?Color,?Colorscale,?Width,?Dash,?Domain,?Labelfont,?Tickfont,?Rangefont) =
490+
Trace.initParallelCategories (
491+
TraceStyle.ParallelCoord (Dimensions=dims,?Domain=Domain,?Labelfont=Labelfont,?Tickfont=Tickfont,?Rangefont=Rangefont)
492+
)
493+
|> TraceStyle.Line(?Width=Width,?Color=Color,?Dash=Dash,?Colorscale=Colorscale)
494+
|> GenericChart.ofTraceObject
476495

477-
/// Computes the choropleth map plot
496+
/// Computes the choropleth map plot
478497
static member ChoroplethMap(locations,z,?Text,?Locationmode,?Autocolorscale,?Colorscale,?Colorbar,?Marker,?Zmin,?Zmax) =
479498
Trace.initChoroplethMap (
480499
TraceStyle.ChoroplethMap (Locations=locations,Z=z,?Text=Text,?Locationmode=Locationmode,?Autocolorscale=Autocolorscale,

Diff for: src/FSharp.Plotly/TestScript.fsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ Chart.Spline(x,y',Name="spline")
3636
//|> GenericChart.toChartHtmlWithSize 500 500
3737

3838
//|> Chart.ShowAsImage StyleParam.ImageFormat.SVG
39-
|> Chart.ShowAsImage StyleParam.ImageFormat.SVG
39+
40+
let dims' =
41+
[
42+
Dimensions.init(["Cat1";"Cat1";"Cat1";"Cat1";"Cat2";"Cat2";"Cat3"],Label="A")
43+
Dimensions.init([0;1;0;1;0;0;0],Label="B",TickText=["YES","NO"])
44+
]
45+
46+
Chart.ParallelCategories(dims=dims',Color=[0.;1.;0.;1.;0.;0.;0.],Colorscale = StyleParam.Colorscale.Blackbody)
47+
|> Chart.Show
48+
4049

4150

4251

Diff for: src/FSharp.Plotly/Trace.fs

+26-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ module Trace =
5454
let initHistogram2d (applyStyle:Trace->Trace) =
5555
Trace("histogram2d") |> applyStyle
5656

57-
5857
/// Init trace for 2d-histogram contour
5958
let initHistogram2dContour (applyStyle:Trace->Trace) =
6059
Trace("histogram2dcontour") |> applyStyle
@@ -63,6 +62,10 @@ module Trace =
6362
let initParallelCoord (applyStyle:Trace->Trace) =
6463
Trace("parcoords") |> applyStyle
6564

65+
// Init trace for a parallel category plot
66+
let initParallelCategories (applyStyle: Trace -> Trace) =
67+
Trace("parcats") |> applyStyle
68+
6669
/// Init trace for a choropleth map
6770
let initChoroplethMap (applyStyle:Trace->Trace) =
6871
Trace("choropleth") |> applyStyle
@@ -884,7 +887,28 @@ module Trace =
884887
// out ->
885888
parcoords
886889
)
887-
890+
891+
static member ParallelCategories
892+
(
893+
?Dimensions : seq<Dimensions>,
894+
?Line ,
895+
?Domain ,
896+
?Labelfont ,
897+
?Tickfont : Font,
898+
?Rangefont : Font
899+
) =
900+
(fun (parcats:('T :> Trace)) ->
901+
902+
Dimensions |> DynObj.setValueOpt parcats "dimensions"
903+
Line |> DynObj.setValueOpt parcats "line"
904+
Domain |> DynObj.setValueOpt parcats "domain"
905+
Labelfont |> DynObj.setValueOpt parcats "labelfont"
906+
Tickfont |> DynObj.setValueOpt parcats "tickfont"
907+
Rangefont |> DynObj.setValueOpt parcats "rangefont"
908+
909+
// out ->
910+
parcats
911+
)
888912

889913
// Applies the styles of choropleth map plot to TraceObjects
890914
static member ChoroplethMap

0 commit comments

Comments
 (0)