Skip to content

Commit b568677

Browse files
muehlmuehl
authored andcommitted
Refactor object context
1 parent 63f9ea1 commit b568677

19 files changed

+521
-568
lines changed

docs/content/bar-charts.fsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ The following example shows how to create a stacked bar chart by combining bar c
3636

3737
(*** define-output:bar3 ***)
3838
[
39-
Chart.StackedBar(keys,values,Name="old");
40-
Chart.StackedBar(keys,[8; 21; 13;],Name="new")
39+
Chart.StackedBar(values,keys,Name="old");
40+
Chart.StackedBar([8; 21; 13;],keys,Name="new")
4141
]
4242
|> Chart.Combine
4343
(*** include-it:bar3 ***)
44+
|> Chart.Show
45+
46+
FSharp.Plotly.

docs/content/getting-started.fsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,26 @@
55
#r "../../lib/FSharp.Care.dll"
66

77
(**
8-
FSharp.Plotly
9-
======================
8+
Getting started...
9+
==================
1010
11-
The library FSharp.Plotly implements charting suitable for use from F# scripting. Once you load the library as followed, you can use the members of the `Chart` type to easily build charts.
11+
FSharp.Plotly implements charting suitable for use from F# scripting. Once you load the library as followed, you can use the members of the `Chart` type to easily build charts.
1212
13-
FSharp.Plotly is powered by popular JavaScript charting library [Plotly](https://plot.ly/). The library provides a complete mapping for the configuration options of the underlying library but empowers you to use the comfortable style known from the beautiful library [F# Charting](http://fslab.org/FSharp.Charting/). So you get a nice F# interface support with the full power of Plotly.
13+
The library provides a complete mapping for the configuration options of the underlying library but empowers you to use the comfortable style known from the beautiful library [F# Charting](http://fslab.org/FSharp.Charting/). So you get a nice F# interface support with the full power of Plotly.
1414
*)
1515

1616
#r "../../bin/FSharp.Plotly.dll"
1717
open FSharp.Plotly
1818

19-
let scatter =
20-
// let scatter =
21-
// Trace("scattergl")
22-
Trace.initScatter (fun scatter ->
23-
scatter?x <- [1; 2; 3; 4]
24-
scatter?y <- [1; 2; 3; 4]
25-
scatter?mode <- "lines+markers"
26-
scatter?name <- "lines and markers"
27-
scatter
28-
)
29-
30-
GenericChart.ofTraceObject scatter
19+
20+
Trace.initScatter (fun scatter ->
21+
scatter?x <- [1; 2; 3; 4]
22+
scatter?y <- [1; 2; 3; 4]
23+
scatter?mode <- "lines+markers"
24+
scatter?name <- "lines and markers"
25+
scatter
26+
)
27+
|> GenericChart.ofTraceObject
3128
|> Chart.Show
3229

3330

src/FSharp.Plotly/Axis.fs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,9 @@ module Axis =
77
type LinearAxis () =
88
inherit DynamicObj ()
99

10-
/// Radialaxis type inherits from dynamic object
11-
type RadialAxis () =
12-
inherit DynamicObj ()
13-
14-
/// Angularaxis type inherits from dynamic object
15-
type AngularAxis () =
16-
inherit DynamicObj ()
17-
18-
/// Init LinearAxis type
19-
let initLinearAxis (applyStyle:LinearAxis->LinearAxis) =
20-
LinearAxis() |> applyStyle
21-
22-
/// Init Radialaxis type
23-
let initRadialaxis (applyStyle:RadialAxis->RadialAxis) =
24-
RadialAxis() |> applyStyle
25-
26-
/// Init Angularaxis type
27-
let initAngularaxis (applyStyle:AngularAxis->AngularAxis) =
28-
AngularAxis() |> applyStyle
29-
30-
31-
/// Static function to apply styles to axis types
32-
type AxidStyle =
10+
/// Init LinearAxis type
11+
static member init (applyStyle:LinearAxis->LinearAxis) =
12+
LinearAxis() |> applyStyle
3313

3414
// Applies the styles to LinearAxis()
3515
static member LinearAxis
@@ -151,5 +131,21 @@ module Axis =
151131
)
152132

153133

134+
/// Radialaxis type inherits from dynamic object
135+
type RadialAxis () =
136+
inherit DynamicObj ()
137+
138+
/// Init Radialaxis type
139+
static member init (applyStyle:RadialAxis->RadialAxis) =
140+
RadialAxis() |> applyStyle
141+
142+
/// Angularaxis type inherits from dynamic object
143+
type AngularAxis () =
144+
inherit DynamicObj ()
145+
146+
/// Init Angularaxis type
147+
static member init (applyStyle:AngularAxis->AngularAxis) =
148+
AngularAxis() |> applyStyle
149+
154150

155151

src/FSharp.Plotly/Bins.fs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
namespace FSharp.Plotly
22

3-
/// Module containing plotly Bins
4-
module Bins =
53

6-
/// Bin type inherits from dynamic object
7-
type Bins () =
8-
inherit DynamicObj ()
4+
/// Bin type inherits from dynamic object
5+
type Bins () =
6+
inherit DynamicObj ()
97

10-
type BinsStyle =
8+
// Init Bins()
9+
static member init (apply:Bins->Bins) =
10+
Bins () |> apply
1111

12-
// Applies the styles to Bins()
13-
static member BinsStyle
14-
(
15-
?StartBins:float,
16-
?EndBins:float,
17-
?Size
18-
) =
12+
13+
// Applies the styles to Bins()
14+
static member style
15+
(
16+
?StartBins:float,
17+
?EndBins:float,
18+
?Size
19+
) =
1920

20-
(fun (bins:('T :> Bins)) ->
21-
StartBins |> DynObj.setValueOpt bins "start"
22-
EndBins |> DynObj.setValueOpt bins "end"
23-
Size |> DynObj.setValueOpt bins "size"
21+
(fun (bins:('T :> Bins)) ->
22+
StartBins |> DynObj.setValueOpt bins "start"
23+
EndBins |> DynObj.setValueOpt bins "end"
24+
Size |> DynObj.setValueOpt bins "size"
2425

25-
bins
26-
)
26+
bins
27+
)
28+
29+

src/FSharp.Plotly/Chart.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open FSharp.Care.Collections
77
open GenericChart
88
open Trace
99
open Trace3d
10-
open Layout
10+
1111

1212
/// Provides a set of static methods for creating charts.
1313
type Chart =
@@ -214,8 +214,8 @@ type Chart =
214214
static member Column(keys, values,?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
215215
let marker =
216216
match Marker with
217-
| Some marker -> marker |> FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color)
218-
| None -> FSharp.Plotly.Marker.initMarker (FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color))
217+
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
218+
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
219219

220220
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker))
221221
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
@@ -233,14 +233,14 @@ type Chart =
233233
static member StackedColumn(keys, values,?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
234234
let marker =
235235
match Marker with
236-
| Some marker -> marker |> FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color)
237-
| None -> FSharp.Plotly.Marker.initMarker (FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color))
236+
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
237+
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
238238

239239
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker))
240240
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
241241
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
242242
|> GenericChart.ofTraceObject
243-
|> GenericChart.setLayout (Layout.init (LayoutStyle.Apply(Barmode=StyleParam.Barmode.Stack)))
243+
|> GenericChart.setLayout (Layout.init (Layout.style(Barmode=StyleParam.Barmode.Stack)))
244244

245245

246246
/// Displays series of column chart type as stacked columns.
@@ -253,8 +253,8 @@ type Chart =
253253
static member Bar(keys, values,?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
254254
let marker =
255255
match Marker with
256-
| Some marker -> marker |> FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color)
257-
| None -> FSharp.Plotly.Marker.initMarker (FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color))
256+
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
257+
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?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)
@@ -271,13 +271,13 @@ type Chart =
271271
static member StackedBar(keys, values,?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
272272
let marker =
273273
match Marker with
274-
| Some marker -> marker |> FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color)
275-
| None -> FSharp.Plotly.Marker.initMarker (FSharp.Plotly.Marker.MarkerStyle.Apply(?Color=Color))
276-
Trace.initBar (TraceStyle.Bar(X = keys,Y = values,Marker=marker,Orientation = StyleParam.Orientation.Horizontal))
274+
| Some marker -> marker |> FSharp.Plotly.Marker.style(?Color=Color)
275+
| None -> FSharp.Plotly.Marker.init (FSharp.Plotly.Marker.style(?Color=Color))
276+
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)
279279
|> GenericChart.ofTraceObject
280-
|> GenericChart.setLayout (Layout.init (LayoutStyle.Apply(Barmode=StyleParam.Barmode.Stack)))
280+
|> GenericChart.setLayout (Layout.init (Layout.style(Barmode=StyleParam.Barmode.Stack)))
281281

282282

283283
/// Displays series of tcolumn chart type as stacked bars.
@@ -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) )
404+
Trace3d.initMesh3d (Trace3dStyle.Mesh3d(X = x,Y = y,Z=z,?Color=Color) )
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: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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.initMarker ( Marker.MarkerStyle.Apply
40+
Marker.init ( Marker.style
4141
(?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity)
4242
)
4343
Chart.withMarker(marker)
@@ -51,7 +51,7 @@ 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.LineStyle.Apply
54+
Line.init ( Line.style
5555
(?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
5656
)
5757
Chart.withLine(line)
@@ -92,12 +92,12 @@ module ChartExtensions =
9292
| false ->
9393
let layout =
9494
GenericChart.getLayout ch
95-
|> Layout.LayoutStyle.Apply(xAxis=xAxis)
95+
|> Layout.style (xAxis=xAxis)
9696
GenericChart.setLayout layout ch
9797
| true ->
9898
let layout =
9999
Layout()
100-
|> Layout.LayoutStyle.Apply(Scene=Scene3d.init(Scene3d.SceneStyle.Apply( xAxis=xAxis) ))
100+
|> Layout.style (Scene=Scene.init(Scene.style( xAxis=xAxis) ))
101101
GenericChart.addLayout layout ch
102102
)
103103

@@ -124,12 +124,12 @@ module ChartExtensions =
124124
| false ->
125125
let layout =
126126
GenericChart.getLayout ch
127-
|> Layout.LayoutStyle.Apply(yAxis=yAxis)
127+
|> Layout.style(yAxis=yAxis)
128128
GenericChart.setLayout layout ch
129129
| true ->
130130
let layout =
131131
Layout()
132-
|> Layout.LayoutStyle.Apply(Scene=Scene3d.init(Scene3d.SceneStyle.Apply(yAxis=yAxis) ))
132+
|> Layout.style(Scene=Scene.init(Scene.style (yAxis=yAxis) ))
133133
GenericChart.addLayout layout ch
134134
)
135135

@@ -172,23 +172,22 @@ module ChartExtensions =
172172
(fun (ch:GenericChart) ->
173173
let layout =
174174
GenericChart.getLayout ch
175-
|> Layout.LayoutStyle.Apply(Width=width,Height=heigth)
175+
|> Layout.style (Width=width,Height=heigth)
176176
GenericChart.setLayout layout ch
177177
)
178178

179179
// Set the margin of a Chart
180-
static member withMargin(margin:Layout.Margin) =
180+
static member withMargin(margin:Margin) =
181181
(fun (ch:GenericChart) ->
182182
let layout =
183183
GenericChart.getLayout ch
184-
|> Layout.LayoutStyle.Apply(Margin=margin)
184+
|> Layout.style (Margin=margin)
185185
GenericChart.setLayout layout ch)
186186

187187
// Set the margin of a Chart
188188
static member withMarginSize(?Left,?Right,?Top,?Bottom,?Pad,?Autoexpand) =
189189
let margin =
190-
Layout.initMargin(Layout.LayoutStyle.Margin
191-
(?Left=Left,?Right=Right,?Top=Top,?Bottom=Bottom,?Pad=Pad,?Autoexpand=Autoexpand))
190+
Margin.init (Margin.style (?Left=Left,?Right=Right,?Top=Top,?Bottom=Bottom,?Pad=Pad,?Autoexpand=Autoexpand))
192191
Chart.withMargin(margin)
193192

194193

@@ -202,14 +201,14 @@ module ChartExtensions =
202201
(fun (ch:GenericChart) ->
203202
let layout =
204203
GenericChart.getLayout ch
205-
|> Layout.LayoutStyle.Apply(Shapes=[shape])
204+
|> Layout.style (Shapes=[shape])
206205
GenericChart.setLayout layout ch)
207206

208207
static member withShapes(shapes:Shape seq) =
209208
(fun (ch:GenericChart) ->
210209
let layout =
211210
GenericChart.getLayout ch
212-
|> Layout.LayoutStyle.Apply(Shapes=shapes)
211+
|> Layout.style (Shapes=shapes)
213212
GenericChart.setLayout layout ch)
214213

215214

0 commit comments

Comments
 (0)