Skip to content

Commit 7b33a33

Browse files
committed
Improve type constraints and code formatting
1 parent 73e2ce1 commit 7b33a33

File tree

8 files changed

+105
-85
lines changed

8 files changed

+105
-85
lines changed

src/FSharp.Plotly/Bins.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Bins () =
2929
?Size
3030
) =
3131

32-
(fun (bins:('T :> Bins)) ->
32+
(fun (bins:Bins) ->
3333
StartBins |> DynObj.setValueOpt bins "start"
3434
EndBins |> DynObj.setValueOpt bins "end"
3535
Size |> DynObj.setValueOpt bins "size"

src/FSharp.Plotly/Chart.fs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ type Chart =
419419
>> StyleParam.ModeUtils.showMarker (isShowMarker)
420420

421421
Trace.initScatter (
422-
TraceStyle.Scatter(X = x,Y = y, Mode=changeMode StyleParam.Mode.Lines,Fill=StyleParam.ToZero_y) )
422+
TraceStyle.Scatter(X = x,Y = y, Mode=changeMode StyleParam.Mode.Lines,Fill=StyleParam.Fill.ToZero_y) )
423423
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
424424
|> TraceStyle.Line(?Color=Color,?Dash=Dash,?Width=Width, Shape=StyleParam.Shape.Spline, ?Smoothing=Smoothing)
425425
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
@@ -623,7 +623,8 @@ type Chart =
623623

624624

625625
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
626-
static member BoxPlot(
626+
static member BoxPlot
627+
(
627628
[<Optional;DefaultParameterValue(null)>] ?x,
628629
[<Optional;DefaultParameterValue(null)>] ?y,
629630
[<Optional;DefaultParameterValue(null)>] ?Name,
@@ -636,13 +637,14 @@ type Chart =
636637
[<Optional;DefaultParameterValue(null)>] ?Boxmean,
637638
[<Optional;DefaultParameterValue(null)>] ?Jitter,
638639
[<Optional;DefaultParameterValue(null)>] ?Pointpos,
639-
[<Optional;DefaultParameterValue(null)>] ?Orientation) =
640-
Trace.initBoxPlot (TraceStyle.BoxPlot(?X=x, ?Y = y,
640+
[<Optional;DefaultParameterValue(null)>] ?Orientation
641+
) =
642+
Trace.initBoxPlot (TraceStyle.BoxPlot(?X=x, ?Y = y,
641643
?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,
642644
?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation,?Fillcolor=Fillcolor) )
643-
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
644-
|> TraceStyle.Marker(?Color=Color)
645-
|> GenericChart.ofTraceObject
645+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
646+
|> TraceStyle.Marker(?Color=Color)
647+
|> GenericChart.ofTraceObject
646648

647649

648650
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
@@ -663,7 +665,8 @@ type Chart =
663665

664666

665667
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
666-
static member Violin(
668+
static member Violin
669+
(
667670
[<Optional;DefaultParameterValue(null)>] ?x,
668671
[<Optional;DefaultParameterValue(null)>] ?y,
669672
[<Optional;DefaultParameterValue(null)>] ?Name,
@@ -674,12 +677,13 @@ type Chart =
674677
[<Optional;DefaultParameterValue(null)>] ?Points,
675678
[<Optional;DefaultParameterValue(null)>] ?Jitter,
676679
[<Optional;DefaultParameterValue(null)>] ?Pointpos,
677-
[<Optional;DefaultParameterValue(null)>] ?Orientation) =
678-
Trace.initViolin (TraceStyle.Violin(?X=x, ?Y = y,?Points=Points,
680+
[<Optional;DefaultParameterValue(null)>] ?Orientation
681+
) =
682+
Trace.initViolin (TraceStyle.Violin(?X=x, ?Y = y,?Points=Points,
679683
?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation,?Fillcolor=Fillcolor) )
680-
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
681-
|> TraceStyle.Marker(?Color=Color)
682-
|> GenericChart.ofTraceObject
684+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
685+
|> TraceStyle.Marker(?Color=Color)
686+
|> GenericChart.ofTraceObject
683687

684688

685689
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
@@ -1203,8 +1207,8 @@ type Chart =
12031207
| Option.None -> Option.None
12041208

12051209
TraceStyle.Table (
1206-
Header = TableHeader.init (headerValues|> Seq.map seq, ?Align=AlignHeader, ?Fill=HeaderFilling, ?Font=FontHeader, ?Height=HeightHeader, ?Line=LineHeader),
1207-
Cells = TableCells.init(cellValues |> Seq.transpose, ?Align=AlignCells, ?Fill=CellFilling, ?Font=FontCells, ?Height=HeightCells, ?Line=LineCells),
1210+
header = TableHeader.init (headerValues|> Seq.map seq, ?Align=AlignHeader, ?Fill=HeaderFilling, ?Font=FontHeader, ?Height=HeightHeader, ?Line=LineHeader),
1211+
cells = TableCells.init(cellValues |> Seq.transpose, ?Align=AlignCells, ?Fill=CellFilling, ?Font=FontCells, ?Height=HeightCells, ?Line=LineCells),
12081212
?ColumnWidth = ColumnWidth,
12091213
?ColumnOrder = ColumnOrder
12101214
)

src/FSharp.Plotly/ChartExtensions.fs

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,39 @@ module ChartExtensions =
2626

2727
/// Set the name related properties of a trace
2828
[<CompiledName("WithTraceName")>]
29-
static member withTraceName(
29+
static member withTraceName
30+
(
3031
[<Optional;DefaultParameterValue(null)>] ?Name,
3132
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
3233
[<Optional;DefaultParameterValue(null)>] ?Legendgroup,
33-
[<Optional;DefaultParameterValue(null)>] ?Visible) =
34-
(fun (ch:GenericChart) ->
35-
ch |> mapiTrace (fun i trace ->
36-
let naming i name = name |> Option.map (fun v -> if i = 0 then v else sprintf "%s_%i" v i)
37-
trace
38-
|> TraceStyle.TraceInfo(?Name=(naming i Name),?Showlegend=Showlegend,?Legendgroup=Legendgroup,?Visible=Visible)
39-
)
40-
)
34+
[<Optional;DefaultParameterValue(null)>] ?Visible
35+
) =
36+
fun (ch:GenericChart) ->
37+
ch |> mapiTrace (fun i trace ->
38+
let naming i name = name |> Option.map (fun v -> if i = 0 then v else sprintf "%s_%i" v i)
39+
trace
40+
|> TraceStyle.TraceInfo(?Name=(naming i Name),?Showlegend=Showlegend,?Legendgroup=Legendgroup,?Visible=Visible)
41+
)
42+
4143

4244
/// Set the axis anchor id the trace is belonging to
4345
[<CompiledName("WithAxisAnchor")>]
44-
static member withAxisAnchor(
46+
static member withAxisAnchor
47+
(
4548
[<Optional;DefaultParameterValue(null)>] ?X,
4649
[<Optional;DefaultParameterValue(null)>] ?Y,
47-
[<Optional;DefaultParameterValue(null)>] ?Z) =
48-
let idx = if X.IsSome then Some (StyleParam.AxisAnchorId.X X.Value) else None
49-
let idy = if Y.IsSome then Some (StyleParam.AxisAnchorId.Y Y.Value) else None
50-
let idz = if Z.IsSome then Some (StyleParam.AxisAnchorId.Z Z.Value) else None
50+
[<Optional;DefaultParameterValue(null)>] ?Z
51+
) =
52+
let idx = if X.IsSome then Some (StyleParam.AxisAnchorId.X X.Value) else None
53+
let idy = if Y.IsSome then Some (StyleParam.AxisAnchorId.Y Y.Value) else None
54+
let idz = if Z.IsSome then Some (StyleParam.AxisAnchorId.Z Z.Value) else None
5155

52-
(fun (ch:GenericChart) ->
53-
ch |> mapTrace (fun trace ->
54-
trace
55-
|> TraceStyle.SetAxisAnchor(?X=idx,?Y=idy,?Z=idz)
56-
)
57-
)
56+
fun (ch:GenericChart) ->
57+
ch |> mapTrace (fun trace ->
58+
trace
59+
|> TraceStyle.SetAxisAnchor(?X=idx,?Y=idy,?Z=idz)
60+
)
61+
5862

5963
/// Apply styling to the Marker(s) of the chart as Object.
6064
[<CompiledName("WithMarker")>]
@@ -65,16 +69,18 @@ module ChartExtensions =
6569

6670
/// Apply styling to the Marker(s) of the chart.
6771
[<CompiledName("WithMarkerStyle")>]
68-
static member withMarkerStyle(
72+
static member withMarkerStyle
73+
(
6974
[<Optional;DefaultParameterValue(null)>] ?Size,
7075
[<Optional;DefaultParameterValue(null)>] ?Color,
7176
[<Optional;DefaultParameterValue(null)>] ?Symbol,
72-
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
73-
let marker =
74-
Marker.init (
75-
?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity
76-
)
77-
Chart.withMarker(marker)
77+
[<Optional;DefaultParameterValue(null)>] ?Opacity
78+
) =
79+
let marker =
80+
Marker.init (
81+
?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity
82+
)
83+
Chart.withMarker(marker)
7884

7985
/// Apply styling to the Line(s) of the chart as Object.
8086
[<CompiledName("WithLine")>]
@@ -85,18 +91,20 @@ module ChartExtensions =
8591

8692
/// Apply styling to the Line(s) of the chart.
8793
[<CompiledName("WithLineStyle")>]
88-
static member withLineStyle(
94+
static member withLineStyle
95+
(
8996
[<Optional;DefaultParameterValue(null)>] ?Width,
9097
[<Optional;DefaultParameterValue(null)>] ?Color,
9198
[<Optional;DefaultParameterValue(null)>] ?Shape,
9299
[<Optional;DefaultParameterValue(null)>] ?Dash,
93100
[<Optional;DefaultParameterValue(null)>] ?Smoothing,
94-
[<Optional;DefaultParameterValue(null)>] ?Colorscale) =
95-
let line =
96-
Line.init (
97-
?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
101+
[<Optional;DefaultParameterValue(null)>] ?Colorscale
102+
) =
103+
let line =
104+
Line.init (
105+
?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
98106

99-
Chart.withLine(line)
107+
Chart.withLine(line)
100108

101109
/// Apply styling to the xError(s) of the chart as Object
102110
[<CompiledName("WithXError")>]
@@ -107,15 +115,17 @@ module ChartExtensions =
107115

108116
/// Apply styling to the xError(s) of the chart as Object
109117
[<CompiledName("WithXErrorStyle")>]
110-
static member withXErrorStyle(
118+
static member withXErrorStyle
119+
(
111120
[<Optional;DefaultParameterValue(null)>] ?Array,
112121
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
113122
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
114123
[<Optional;DefaultParameterValue(null)>] ?Color,
115124
[<Optional;DefaultParameterValue(null)>] ?Thickness,
116-
[<Optional;DefaultParameterValue(null)>] ?Width) =
117-
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
118-
Chart.withXError error
125+
[<Optional;DefaultParameterValue(null)>] ?Width
126+
) =
127+
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
128+
Chart.withXError error
119129

120130
/// Apply styling to the yError(s) of the chart as Object
121131
[<CompiledName("WithYError")>]
@@ -126,15 +136,17 @@ module ChartExtensions =
126136

127137
/// Apply styling to the yError(s) of the chart as Object
128138
[<CompiledName("WithYErrorStyle")>]
129-
static member withYErrorStyle(
139+
static member withYErrorStyle
140+
(
130141
[<Optional;DefaultParameterValue(null)>] ?Array,
131142
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
132143
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
133144
[<Optional;DefaultParameterValue(null)>] ?Color,
134145
[<Optional;DefaultParameterValue(null)>] ?Thickness,
135-
[<Optional;DefaultParameterValue(null)>] ?Width) =
136-
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
137-
Chart.withYError error
146+
[<Optional;DefaultParameterValue(null)>] ?Width
147+
) =
148+
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
149+
Chart.withYError error
138150

139151
/// Apply styling to the zError(s) of the chart as Object
140152
[<CompiledName("WithZError")>]
@@ -145,15 +157,17 @@ module ChartExtensions =
145157

146158
/// Apply styling to the zError(s) of the chart as Object
147159
[<CompiledName("WithZErrorStyle")>]
148-
static member withZErrorStyle(
160+
static member withZErrorStyle
161+
(
149162
[<Optional;DefaultParameterValue(null)>] ?Array,
150163
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
151164
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
152165
[<Optional;DefaultParameterValue(null)>] ?Color,
153166
[<Optional;DefaultParameterValue(null)>] ?Thickness,
154-
[<Optional;DefaultParameterValue(null)>] ?Width) =
155-
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
156-
Chart.withZError error
167+
[<Optional;DefaultParameterValue(null)>] ?Width
168+
) =
169+
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
170+
Chart.withZError error
157171

158172

159173
// ############################################################
@@ -369,13 +383,15 @@ module ChartExtensions =
369383

370384
// Set the margin of a Chart
371385
[<CompiledName("WithMarginSize")>]
372-
static member withMarginSize(
373-
[<Optional;DefaultParameterValue(null)>] ?Left,
374-
[<Optional;DefaultParameterValue(null)>] ?Right,
375-
[<Optional;DefaultParameterValue(null)>] ?Top,
376-
[<Optional;DefaultParameterValue(null)>] ?Bottom,
377-
[<Optional;DefaultParameterValue(null)>] ?Pad,
378-
[<Optional;DefaultParameterValue(null)>] ?Autoexpand) =
386+
static member withMarginSize
387+
(
388+
[<Optional;DefaultParameterValue(null)>] ?Left,
389+
[<Optional;DefaultParameterValue(null)>] ?Right,
390+
[<Optional;DefaultParameterValue(null)>] ?Top,
391+
[<Optional;DefaultParameterValue(null)>] ?Bottom,
392+
[<Optional;DefaultParameterValue(null)>] ?Pad,
393+
[<Optional;DefaultParameterValue(null)>] ?Autoexpand
394+
) =
379395
let margin =
380396
Margin.init ( ?Left=Left,?Right=Right,?Top=Top,?Bottom=Bottom,?Pad=Pad,?Autoexpand=Autoexpand )
381397
Chart.withMargin(margin)

src/FSharp.Plotly/Contours.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Contour () =
4848

4949
) =
5050

51-
(fun (contour:('T :> Contour)) ->
51+
(fun (contour:Contour) ->
5252
Show |> DynObj.setValueOpt contour "show"
5353
//?Project |> DynObj.setValueOpt contour "project"
5454
Color |> DynObj.setValueOpt contour "color"
@@ -140,7 +140,7 @@ type Contours () =
140140

141141
) =
142142

143-
(fun (contours:('T :> Contours)) ->
143+
(fun (contours: Contours) ->
144144
let xyzContour =
145145
Contour.init (?Show=Show,?Color=Color,?Usecolor=Usecolor, ?Width=Width,
146146
?Highlight=Highlight, ?Highlightcolor=Highlightcolor, ?Highlightwidth=Highlightwidth)

src/FSharp.Plotly/Cumulative.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Cumulative () =
4040
?Currentbin
4141
) =
4242

43-
(fun (cumulative:('T :> Cumulative)) ->
43+
(fun (cumulative: Cumulative) ->
4444
Enabled |> DynObj.setValueOpt cumulative "enabled"
4545
Direction |> DynObj.setValueOptBy cumulative "direction" StyleParam.CumulativeDirection.convert
4646
Currentbin |> DynObj.setValueOptBy cumulative "currentbin" StyleParam.Currentbin.convert

src/FSharp.Plotly/Light.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module Ligth =
9090
?Z : int
9191
) =
9292

93-
(fun (lightposition:('T :> Lightposition)) ->
93+
(fun (lightposition: Lightposition) ->
9494
X |> DynObj.setValueOpt lightposition "x"
9595
Y |> DynObj.setValueOpt lightposition "y"
9696
Z |> DynObj.setValueOpt lightposition "z"

src/FSharp.Plotly/Table.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type TableHeader () =
3535
/// Initialized Header object
3636
static member init
3737
(
38-
Values ,
38+
values ,
3939
?Align ,
4040
?Height,
4141
?Fill ,
@@ -46,7 +46,7 @@ type TableHeader () =
4646
TableHeader ()
4747
|> TableHeader.style
4848
(
49-
Values = Values,
49+
values = values,
5050
?Align = Align ,
5151
?Height = Height,
5252
?Fill = Fill ,
@@ -58,7 +58,7 @@ type TableHeader () =
5858
/// Applies the styles to TableHeader()
5959
static member style
6060
(
61-
Values : seq<#seq<#IConvertible>> ,
61+
values : seq<#seq<#IConvertible>> ,
6262
?Align : seq<StyleParam.HorizontalAlign>,
6363
?Height ,
6464
?Fill ,
@@ -68,7 +68,7 @@ type TableHeader () =
6868
) =
6969
(fun (header: TableHeader) ->
7070

71-
Values |> DynObj.setValue header "values"
71+
values |> DynObj.setValue header "values"
7272
Align |> DynObj.setValueOptBy header "align" (Seq.map StyleParam.HorizontalAlign.convert)
7373
Height |> DynObj.setValueOpt header "height"
7474
Fill |> DynObj.setValueOpt header "fill"
@@ -84,7 +84,7 @@ type TableCells () =
8484
/// Initialized Cells object
8585
static member init
8686
(
87-
Values ,
87+
values ,
8888
?Align ,
8989
?Height,
9090
?Fill ,
@@ -95,7 +95,7 @@ type TableCells () =
9595
TableCells ()
9696
|> TableCells.style
9797
(
98-
Values = Values,
98+
values = values,
9999
?Align = Align ,
100100
?Height = Height,
101101
?Fill = Fill ,
@@ -107,7 +107,7 @@ type TableCells () =
107107
//Applies the styles to TableCells()
108108
static member style
109109
(
110-
Values : seq<#seq<#IConvertible>> ,
110+
values : seq<#seq<#IConvertible>> ,
111111
?Align : seq<StyleParam.HorizontalAlign>,
112112
?Height ,
113113
?Fill ,
@@ -117,7 +117,7 @@ type TableCells () =
117117
) =
118118
(fun (cells: TableCells) ->
119119

120-
Values |> DynObj.setValue cells "values"
120+
values |> DynObj.setValue cells "values"
121121
Align |> DynObj.setValueOptBy cells "align" (Seq.map StyleParam.HorizontalAlign.convert)
122122
Height |> DynObj.setValueOpt cells "height"
123123
Fill |> DynObj.setValueOpt cells "fill"

0 commit comments

Comments
 (0)