Skip to content

Commit 7aef9ac

Browse files
muehlmuehl
authored andcommitted
Use case simplification (refactoring)
1 parent b568677 commit 7aef9ac

File tree

17 files changed

+652
-112
lines changed

17 files changed

+652
-112
lines changed

docs/content/line-scatter-plots.fsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
2121

2222

2323
(*** define-output:line1 ***)
24-
Chart.Line(x,y',Name="line")
25-
|> Chart.withLineStyle(Width=2,Dash=StyleOption.DrawingStyle.Dot)
24+
Chart.Line(x,y',Name="line",ShowMarkers=true,MarkerSymbol=StyleParam.Symbol.Square)
25+
|> Chart.withLineStyle(Width=2,Dash=StyleParam.DrawingStyle.Dot)
2626
(*** include-it:line1 ***)
2727

2828
(**
@@ -43,10 +43,10 @@ shown below.
4343

4444
(*** define-output:line3 ***)
4545
Chart.Spline(x,y',Name="spline")
46-
|> Chart.withLineStyle(Width=2,Dash=StyleOption.DrawingStyle.Dot)
47-
|> Chart.withLineStyle(Width=6,Dash=StyleOption.DrawingStyle.Dot)
46+
|> Chart.withLineStyle(Width=2,Dash=StyleParam.DrawingStyle.Dot)
47+
|> Chart.withLineStyle(Width=6,Dash=StyleParam.DrawingStyle.Dot)
4848
(*** include-it:line3 ***)
49-
49+
|> Chart.Show
5050

5151
(**
5252
@@ -60,16 +60,16 @@ If `TextPosition` is set the labels are drawn otherwise only shown when hovering
6060
let l = ["a";"b";"c";"d";"e";"f";"g";"h";"i";"j";]
6161

6262
(*** define-output:pointsWithLabels ***)
63-
Chart.Point(x,y',Name="points",Labels=l,TextPosition=StyleOption.TextPosition.TopRight)
63+
Chart.Point(x,y',Name="points",Labels=l,TextPosition=StyleParam.TextPosition.TopRight)
6464
(*** include-it:pointsWithLabels ***)
65-
|> Chart.Show
6665

6766

6867

6968

70-
(*** define-output:pointsWithErrorBars ***)
71-
Chart.Point(x,y',Name="points with errors")
72-
|> Chart.withXError(Options.Error(Array=[|0.2;0.3;0.2;0.1;0.2;0.4;0.2;0.08;0.2;0.1;|]))
73-
|> Chart.withYError(Options.Error(Array=[|0.3;0.2;0.1;0.4;0.2;0.4;0.1;0.18;0.02;0.2;|]))
74-
(*** include-it:pointsWithErrorBars ***)
75-
|> Chart.Show
69+
70+
//(*** define-output:pointsWithErrorBars ***)
71+
//Chart.Point(x,y',Name="points with errors")
72+
//|> Chart.withXError(Options.Error(Array=[|0.2;0.3;0.2;0.1;0.2;0.4;0.2;0.08;0.2;0.1;|]))
73+
//|> Chart.withYError(Options.Error(Array=[|0.3;0.2;0.1;0.4;0.2;0.4;0.1;0.18;0.02;0.2;|]))
74+
//(*** include-it:pointsWithErrorBars ***)
75+
//|> Chart.Show

src/FSharp.Plotly/Axis.fs

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,122 @@ module Axis =
88
inherit DynamicObj ()
99

1010
/// Init LinearAxis type
11-
static member init (applyStyle:LinearAxis->LinearAxis) =
12-
LinearAxis() |> applyStyle
11+
static member init
12+
(
13+
?AxisType ,
14+
?Title ,
15+
?Titlefont ,
16+
?Autorange ,
17+
?Rangemode ,
18+
?Range ,
19+
?Fixedrange ,
20+
?Tickmode ,
21+
?nTicks ,
22+
?Tick0 ,
23+
?dTick ,
24+
?Tickvals ,
25+
?Ticktext ,
26+
?Ticks ,
27+
?Mirror ,
28+
?Ticklen ,
29+
?Tickwidth ,
30+
?Tickcolor ,
31+
?Showticklabels ,
32+
?Tickfont ,
33+
?Tickangle ,
34+
?Tickprefix ,
35+
?Showtickprefix ,
36+
?Ticksuffix ,
37+
?Showticksuffix ,
38+
?Showexponent ,
39+
?Exponentformat ,
40+
?Tickformat ,
41+
?Hoverformat ,
42+
?Showline ,
43+
?Linecolor ,
44+
?Linewidth ,
45+
?Showgrid ,
46+
?Gridcolor ,
47+
?Gridwidth ,
48+
?Zeroline ,
49+
?Zerolinecolor ,
50+
?Zerolinewidth ,
51+
?Anchor ,
52+
?Side ,
53+
?Overlaying ,
54+
?Domain ,
55+
?Position ,
56+
?IsSubplotObj ,
57+
?Tickvalssrc ,
58+
?Ticktextsrc ,
59+
?Showspikes ,
60+
?Spikesides ,
61+
?Spikethickness ,
62+
?Spikecolor ,
63+
?Showbackground ,
64+
?Backgroundcolor,
65+
?Showaxeslabels
66+
) =
67+
LinearAxis()
68+
|> LinearAxis.style
69+
(
70+
?AxisType = AxisType ,
71+
?Title = Title ,
72+
?Titlefont = Titlefont ,
73+
?Autorange = Autorange ,
74+
?Rangemode = Rangemode ,
75+
?Range = Range ,
76+
?Fixedrange = Fixedrange ,
77+
?Tickmode = Tickmode ,
78+
?nTicks = nTicks ,
79+
?Tick0 = Tick0 ,
80+
?dTick = dTick ,
81+
?Tickvals = Tickvals ,
82+
?Ticktext = Ticktext ,
83+
?Ticks = Ticks ,
84+
?Mirror = Mirror ,
85+
?Ticklen = Ticklen ,
86+
?Tickwidth = Tickwidth ,
87+
?Tickcolor = Tickcolor ,
88+
?Showticklabels = Showticklabels ,
89+
?Tickfont = Tickfont ,
90+
?Tickangle = Tickangle ,
91+
?Tickprefix = Tickprefix ,
92+
?Showtickprefix = Showtickprefix ,
93+
?Ticksuffix = Ticksuffix ,
94+
?Showticksuffix = Showticksuffix ,
95+
?Showexponent = Showexponent ,
96+
?Exponentformat = Exponentformat ,
97+
?Tickformat = Tickformat ,
98+
?Hoverformat = Hoverformat ,
99+
?Showline = Showline ,
100+
?Linecolor = Linecolor ,
101+
?Linewidth = Linewidth ,
102+
?Showgrid = Showgrid ,
103+
?Gridcolor = Gridcolor ,
104+
?Gridwidth = Gridwidth ,
105+
?Zeroline = Zeroline ,
106+
?Zerolinecolor = Zerolinecolor ,
107+
?Zerolinewidth = Zerolinewidth ,
108+
?Anchor = Anchor ,
109+
?Side = Side ,
110+
?Overlaying = Overlaying ,
111+
?Domain = Domain ,
112+
?Position = Position ,
113+
?IsSubplotObj = IsSubplotObj ,
114+
?Tickvalssrc = Tickvalssrc ,
115+
?Ticktextsrc = Ticktextsrc ,
116+
?Showspikes = Showspikes ,
117+
?Spikesides = Spikesides ,
118+
?Spikethickness = Spikethickness ,
119+
?Spikecolor = Spikecolor ,
120+
?Showbackground = Showbackground ,
121+
?Backgroundcolor = Backgroundcolor,
122+
?Showaxeslabels = Showaxeslabels
123+
)
13124

14125
// Applies the styles to LinearAxis()
15-
static member LinearAxis
126+
static member style
16127
(
17128
?AxisType,
18129
?Title,

src/FSharp.Plotly/Bins.fs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ type Bins () =
66
inherit DynamicObj ()
77

88
// Init Bins()
9-
static member init (apply:Bins->Bins) =
10-
Bins () |> apply
9+
static member init
10+
(
11+
?StartBins ,
12+
?EndBins ,
13+
?Size
14+
) =
15+
Bins ()
16+
|> Bins.style
17+
(
18+
?StartBins = StartBins,
19+
?EndBins = EndBins ,
20+
?Size = Size
21+
)
1122

1223

1324
// Applies the styles to Bins()
1425
static member style
1526
(
1627
?StartBins:float,
17-
?EndBins:float,
28+
?EndBins :float,
1829
?Size
1930
) =
2031

src/FSharp.Plotly/Chart.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Chart =
5959
>> StyleParam.ModeUtils.showMarker (isShowMarker)
6060

6161
Trace.initScatter (
62-
TraceStyle.Scatter(X = x,Y = y, Mode=changeMode StyleParam.Markers) )
62+
TraceStyle.Scatter(X = x,Y = y, Mode=changeMode StyleParam.Lines) )
6363
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
6464
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
6565
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
@@ -215,7 +215,7 @@ type Chart =
215215
let marker =
216216
match Marker with
217217
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
218-
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
218+
| None -> FSharp.Plotly.Marker.init (?Color=Color)
219219

220220
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker))
221221
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
@@ -234,7 +234,7 @@ type Chart =
234234
let marker =
235235
match Marker with
236236
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
237-
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
237+
| None -> FSharp.Plotly.Marker.init (?Color=Color)
238238

239239
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker))
240240
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
@@ -254,7 +254,7 @@ type Chart =
254254
let marker =
255255
match Marker with
256256
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
257-
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
257+
| None -> FSharp.Plotly.Marker.init (?Color=Color)
258258
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker,Orientation = StyleParam.Orientation.Horizontal))
259259
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
260260
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
@@ -272,7 +272,7 @@ type Chart =
272272
let marker =
273273
match Marker with
274274
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
275-
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
275+
| None -> FSharp.Plotly.Marker.init (?Color=Color)
276276
Trace.initBar (TraceStyle.Bar(X = values,Y = keys,Marker=marker,Orientation = StyleParam.Orientation.Horizontal))
277277
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
278278
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
@@ -401,7 +401,7 @@ type Chart =
401401

402402
/// Uses points, line or both depending on the mode to represent 3d-data points
403403
static member Mesh3d(x, y, z, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
404-
Trace3d.initMesh3d (Trace3dStyle.Mesh3d(X = x,Y = y,Z=z,?Color=Color) )
404+
Trace3d.initMesh3d (Trace3dStyle.Mesh3d(X = x,Y = y,Z=z) )
405405
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
406406
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
407407
|> GenericChart.ofTraceObject

src/FSharp.Plotly/ChartExtensions.fs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ module ChartExtensions =
3737
/// Apply styling to the Marker(s) of the chart.
3838
static member withMarkerStyle(?Size,?Color,?Symbol,?Opacity) =
3939
let marker =
40-
Marker.init ( Marker.style
41-
(?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity)
40+
Marker.init (
41+
?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity
4242
)
4343
Chart.withMarker(marker)
4444

@@ -51,9 +51,9 @@ module ChartExtensions =
5151
/// Apply styling to the Line(s) of the chart.
5252
static member withLineStyle(?Width,?Color,?Shape,?Dash,?Smoothing,?Colorscale) =
5353
let line =
54-
Line.init ( Line.style
55-
(?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
56-
)
54+
Line.init (
55+
?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
56+
5757
Chart.withLine(line)
5858

5959
/// Apply styling to the xError(s) of the chart as Object
@@ -97,17 +97,17 @@ module ChartExtensions =
9797
| true ->
9898
let layout =
9999
Layout()
100-
|> Layout.style (Scene=Scene.init(Scene.style( xAxis=xAxis) ))
100+
|> Layout.style (Scene=Scene.init( xAxis=xAxis) )
101101
GenericChart.addLayout layout ch
102102
)
103103

104104

105105

106-
// // Sets x-Axis of 2d and 3d- Charts
107-
// static member withX_AxisStyle(title,?MinMax,?Showgrid) =
108-
// let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
109-
// let xaxis = Options.Axis(Title=title,?Range=range,?Showgrid=Showgrid)
110-
// Chart.withX_Axis(xaxis)
106+
// Sets x-Axis of 2d and 3d- Charts
107+
static member withX_AxisStyle(title,?MinMax,?Showgrid) =
108+
let range = if MinMax.IsSome then Some (StyleParam.RangeValues.MinMax (MinMax.Value)) else None
109+
let xaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid)
110+
Chart.withX_Axis(xaxis)
111111

112112

113113
// Sets y-Axis of 2d and 3d- Charts
@@ -129,15 +129,15 @@ module ChartExtensions =
129129
| true ->
130130
let layout =
131131
Layout()
132-
|> Layout.style(Scene=Scene.init(Scene.style (yAxis=yAxis) ))
132+
|> Layout.style(Scene=Scene.init(yAxis=yAxis) )
133133
GenericChart.addLayout layout ch
134134
)
135135

136-
// // Sets y-Axis of 3d- Charts
137-
// static member withY_AxisStyle(title,?MinMax,?Showgrid) =
138-
// let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
139-
// let yaxis = Options.Axis(Title=title,?Range=range,?Showgrid=Showgrid)
140-
// Chart.withY_Axis(yaxis)
136+
// Sets y-Axis of 3d- Charts
137+
static member withY_AxisStyle(title,?MinMax,?Showgrid) =
138+
let range = if MinMax.IsSome then Some (StyleParam.RangeValues.MinMax (MinMax.Value)) else None
139+
let yaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid)
140+
Chart.withY_Axis(yaxis)
141141

142142

143143

0 commit comments

Comments
 (0)