Skip to content

Commit b4b6229

Browse files
author
Timo Mühlhaus
committed
FIx GenericChart
1 parent 7d2bef7 commit b4b6229

File tree

10 files changed

+1687
-1354
lines changed

10 files changed

+1687
-1354
lines changed

docs/tools/formatters.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let createFsiEvaluator root output =
4141
img.Save(output @@ "images" @@ file, System.Drawing.Imaging.ImageFormat.Png)
4242
Some [ Paragraph [DirectImage ("", (root + "/images/" + file, None))] ]
4343

44-
| :? GenericChart.GenericChart<_> as ch ->
44+
| :? GenericChart.GenericChart as ch ->
4545
// Just return the inline HTML for a Plotly chart
4646
let html = GenericChart.toChartHtmlWithSize 760 500 ch
4747
Some [InlineBlock <| html]

src/FSharp.Plotly.WPF/ChartWPF.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module ChartWPF =
1616
type Chart with
1717

1818

19-
static member ShowWPF (ch:GenericChart<_>) =
19+
static member ShowWPF (ch:GenericChart) =
2020
let guid = Guid.NewGuid().ToString()
2121
let html = GenericChart.toEmbeddedHTML ch
2222
ViewContainer.showHTML html

src/FSharp.Plotly/ApplyHelper.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open System
44

55

6-
module internal ApplyHelper =
6+
module ApplyHelper =
77

88
open System.Reflection
99

src/FSharp.Plotly/Chart.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ open GenericChart
1010
type Chart =
1111

1212
/// Uses points, line or both depending on the mode to represent data points
13-
static member Scatter(x, y, mode, ?Name,?Showlegend,?MakerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
13+
static member Scatter(x, y, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
1414
let trace =
1515
TraceObjects.Scatter()
1616
|> Options.Scatter(X = x,Y = y, Mode=mode,
1717
TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity), //
1818
Line=Options.Line(?Color=Color,?Dash=Dash,?Width=Width),
19-
Marker=Options.Marker(?Color=Color,?Symbol=MakerSymbol),
19+
Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol),
2020
?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
2121
GenericChart.Chart (trace,None)
2222

2323

2424
/// Uses points to represent data points.
25-
static member Point(x, y, ?Name,?Showlegend,?Color,?Opacity,?MakerSymbol,?Labels) =
25+
static member Point(x, y, ?Name,?Showlegend,?Color,?Opacity,?MarkerSymbol,?Labels) =
2626
let trace =
2727
TraceObjects.Scatter()
2828
|> Options.Scatter(X = x,Y = y, Mode=StyleOption.Markers,
2929
TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
30-
Marker=Options.Marker(?Color=Color,?Symbol=MakerSymbol),
30+
Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol),
3131
?Fillcolor=Color,?Text=Labels)
3232
GenericChart.Chart (trace,None)
3333

3434

3535
/// Uses points to represent data points.
36-
static member Point(xy, ?Name,?Showlegend,?Color,?Opacity,?MakerSymbol,?Labels) =
36+
static member Point(xy, ?Name,?Showlegend,?Color,?Opacity,?MarkerSymbol,?Labels) =
3737
let x,y = Seq.unzip xy
38-
Chart.Point(x,y, ?Name=Name,?Showlegend=Showlegend,?Color=Color,?Opacity=Opacity,?MakerSymbol=MakerSymbol,?Labels=Labels)
38+
Chart.Point(x,y, ?Name=Name,?Showlegend=Showlegend,?Color=Color,?Opacity=Opacity,?MarkerSymbol=MarkerSymbol,?Labels=Labels)
3939

4040

4141
/// Uses a line to connect the data points represented.
42-
static member Line(x, y,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MakerSymbol,?Labels) =
42+
static member Line(x, y,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MarkerSymbol,?Labels) =
4343
let mode' = match ShowMarkers with
4444
| Some show -> if show then StyleOption.Lines_Markers else StyleOption.Lines
4545
| None -> StyleOption.Lines_Markers // default
@@ -48,20 +48,20 @@ type Chart =
4848
|> Options.Scatter(X = x,Y = y, Mode=mode',
4949
TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
5050
Line=Options.Line(?Color=Color,?Dash=Dash,?Width=Width),
51-
Marker=Options.Marker(?Color=Color,?Symbol=MakerSymbol),
51+
Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol),
5252
?Fillcolor=Color,?Text=Labels)
5353
GenericChart.Chart (trace,None)
5454

5555

5656
/// Uses a line to connect the data points represented.
57-
static member Line(xy,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MakerSymbol,?Labels) =
57+
static member Line(xy,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MarkerSymbol,?Labels) =
5858
let x,y = Seq.unzip xy
5959
Chart.Line(x,y,?Name=Name,?ShowMarkers=ShowMarkers,?Dash=Dash,?Showlegend=Showlegend,
60-
?Width=Width,?Color=Color,?Opacity=Opacity,?MakerSymbol=MakerSymbol,?Labels=Labels)
60+
?Width=Width,?Color=Color,?Opacity=Opacity,?MarkerSymbol=MarkerSymbol,?Labels=Labels)
6161

6262

6363
/// A Line chart that plots a fitted curve through each data point in a series.
64-
static member Spline(x, y,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MakerSymbol,?Labels,?Smoothing) =
64+
static member Spline(x, y,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MarkerSymbol,?Labels,?Smoothing) =
6565
let mode' = match ShowMarkers with
6666
| Some show -> if show then StyleOption.Lines_Markers else StyleOption.Lines
6767
| None -> StyleOption.Lines_Markers // default
@@ -70,18 +70,18 @@ type Chart =
7070
|> Options.Scatter(X = x,Y = y, Mode=mode',
7171
TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
7272
Line=Options.Line(?Color=Color,?Dash=Dash,?Width=Width,Shape=StyleOption.Shape.Spline,?Smoothing=Smoothing),
73-
Marker=Options.Marker(?Color=Color,?Symbol=MakerSymbol),
73+
Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol),
7474
?Fillcolor=Color,?Text=Labels)
7575
GenericChart.Chart (trace,None)
7676

7777

7878
/// A variation of the Point chart type, where the data points are replaced by bubbles of different sizes.
79-
static member Bubble(x, y, sizes:seq<#IConvertible>,?Name,?Showlegend,?Color,?Opacity,?Labels,?MakerSymbol) =
79+
static member Bubble(x, y, sizes:seq<#IConvertible>,?Name,?Showlegend,?Color,?Opacity,?Labels,?MarkerSymbol) =
8080
let trace =
8181
TraceObjects.Scatter()
8282
|> Options.Scatter(X = x,Y = y, Mode=StyleOption.Markers,
8383
TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
84-
Marker=Options.Marker(?Color=Color,?Symbol=MakerSymbol,MultiSizes=sizes),
84+
Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol,MultiSizes=sizes),
8585
?Text=Labels)
8686
GenericChart.Chart (trace,None)
8787

src/FSharp.Plotly/ChartExtensions.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module ChartExtensions =
1616

1717
/// Set the name related properties of a trace
1818
static member withTraceName(?Name,?Showlegend,?Legendgroup,?Visible) =
19-
(fun (ch:GenericChart<_>) ->
19+
(fun (ch:GenericChart) ->
2020
ch |> mapiTrace (fun i trace ->
2121
let naming i name = name |> Option.map (fun v -> if i = 0 then v else sprintf "%s_%i" v i)
2222
trace |> Options.Trace(?Name=(naming i Name),?Showlegend=Showlegend,?Legendgroup=Legendgroup,?Visible=Visible))
@@ -32,7 +32,7 @@ module ChartExtensions =
3232

3333
// /// Apply styling to the Marker(s) of the chart as Object.
3434
// static member withMarkerOption(marker:Marker) =
35-
// (fun (ch:GenericChart<_>) ->
35+
// (fun (ch:GenericChart) ->
3636
// ch
3737
// |> mapTrace (fun trace ->
3838
// match box trace with
@@ -51,8 +51,8 @@ module ChartExtensions =
5151

5252
/// Apply styling to the Line(s) of the chart as Object.
5353
static member withLineOption(line:LineOptions) =
54-
(fun (ch:GenericChart<#Trace>) ->
55-
ch |> mapTrace (fun (trace:#Trace) ->
54+
(fun (ch:GenericChart) ->
55+
ch |> mapTrace (fun (trace) ->
5656
match (ApplyHelper.tryUpdatePropertyValueFromName trace "line" line) with
5757
| Some trace' -> trace' |> unbox
5858
| None -> trace |> unbox
@@ -68,44 +68,44 @@ module ChartExtensions =
6868
//
6969
// ####################### Apply to layout
7070
static member withX_Axis(xAxis:AxisOptions) =
71-
(fun (ch:GenericChart<_>) ->
71+
(fun (ch:GenericChart) ->
7272
let layout =
7373
Options.Layout(xAxis=xAxis)
7474
GenericChart.addLayout layout ch)
7575

7676
static member withX_AxisStyle(title,?MinMax) =
77-
(fun (ch:GenericChart<_>) ->
77+
(fun (ch:GenericChart) ->
7878
let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
7979
let xaxis = Options.Axis(Title=title,?Range=range)
8080
let layout = Options.Layout(xAxis=xaxis)
8181
GenericChart.addLayout layout ch)
8282

8383

8484
static member withY_Axis(yAxis:AxisOptions) =
85-
(fun (ch:GenericChart<_>) ->
85+
(fun (ch:GenericChart) ->
8686
let layout =
8787
Options.Layout(yAxis=yAxis)
8888
GenericChart.addLayout layout ch)
8989

9090
static member withY_AxisStyle(title,?MinMax) =
91-
(fun (ch:GenericChart<_>) ->
91+
(fun (ch:GenericChart) ->
9292
let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
9393
let yaxis = Options.Axis(Title=title,?Range=range)
9494
let layout = Options.Layout(yAxis=yaxis)
9595
GenericChart.addLayout layout ch)
9696

9797

9898
static member withLayout(layout:LayoutOptions) =
99-
(fun (ch:GenericChart<_>) ->
99+
(fun (ch:GenericChart) ->
100100
GenericChart.addLayout layout ch)
101101

102102
static member withSize(width,heigth) =
103-
(fun (ch:GenericChart<_>) ->
103+
(fun (ch:GenericChart) ->
104104
let layout = Options.Layout(Width=width,Height=heigth)
105105
GenericChart.addLayout layout ch)
106106

107107
static member withMargin(margin:MarginOptions) =
108-
(fun (ch:GenericChart<_>) ->
108+
(fun (ch:GenericChart) ->
109109
let layout = Options.Layout(Margin=margin)
110110
GenericChart.addLayout layout ch)
111111

@@ -126,11 +126,11 @@ module ChartExtensions =
126126

127127
// #######################
128128
/// Create a combined chart with the given charts merged
129-
static member Combine(gCharts:seq<GenericChart<_>>) =
129+
static member Combine(gCharts:seq<GenericChart>) =
130130
GenericChart.combine gCharts
131131

132132
/// Show chart in browser
133-
static member Show (ch:GenericChart<_>) =
133+
static member Show (ch:GenericChart) =
134134
let guid = Guid.NewGuid().ToString()
135135
let html = GenericChart.toEmbeddedHTML ch
136136
let tempPath = Path.GetTempPath()

src/FSharp.Plotly/GenericChart.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ module HTML =
3131

3232
/// Module
3333
module GenericChart =
34-
// 'T when 'T :> Trace
35-
type GenericChart<'T when 'T :> Trace> =
36-
| Chart of 'T * (Layout -> Layout) list option
37-
| MultiChart of 'T list * (Layout -> Layout) list option
34+
// 'T when 'T :> ITrace
35+
type GenericChart =
36+
| Chart of ITrace * (Layout -> Layout) list option
37+
| MultiChart of ITrace list * (Layout -> Layout) list option
3838

3939

4040

@@ -49,37 +49,37 @@ module GenericChart =
4949
| Some v' -> v'
5050
| None -> _default
5151
match gChart with
52-
| Chart (_,layout) -> optOrDefault [id] layout
53-
| MultiChart (_,layout) -> optOrDefault [id] layout
52+
| Chart (_,layout) -> optOrDefault [] layout
53+
| MultiChart (_,layout) -> optOrDefault [] layout
5454

5555

5656
// Adds a Layout function to the GenericChart
5757
let addLayout layout gChart =
5858
match gChart with
59-
| Chart (trace,l) ->
59+
| Chart (trace,_) ->
6060
let l' = getLayouts gChart
6161
Chart (trace,Some (layout::l'))
62-
| MultiChart (traces,l) ->
62+
| MultiChart (traces,_) ->
6363
let l' = getLayouts gChart
6464
MultiChart (traces, Some (layout::l'))
6565

6666
// Adds multiple Layout functions to the GenericChart
6767
let addLayouts layouts gChart =
6868
match gChart with
69-
| Chart (trace,l) ->
69+
| Chart (trace,_) ->
7070
let l' = getLayouts gChart
7171
Chart (trace,Some (layouts@l'))
72-
| MultiChart (traces,l) ->
72+
| MultiChart (traces,_) ->
7373
let l' = getLayouts gChart
7474
MultiChart (traces, Some (layouts@l'))
7575

7676
// Combines two GenericChart
77-
let combine(gCharts:seq<GenericChart<_>>) =
77+
let combine(gCharts:seq<GenericChart>) =
7878
let combineLayouts lLeft lRight =
7979
match lLeft,lRight with
8080
| None, None -> None
81-
| None, Some v -> lRight
82-
| Some v , None -> lLeft
81+
| None, Some _ -> lRight
82+
| Some _ , None -> lLeft
8383
| Some vL,Some vR -> Some (vL@vR)
8484

8585
gCharts
@@ -127,7 +127,7 @@ module GenericChart =
127127
html
128128

129129
/// Converts a GenericChart to it HTML representation and set the size of the div
130-
let toChartHtmlWithSize (width:int) (height:int) (gChart:GenericChart<#Trace>) =
130+
let toChartHtmlWithSize (width:int) (height:int) (gChart:GenericChart) =
131131
let guid = Guid.NewGuid().ToString()
132132
let tracesJson =
133133
getTraces gChart

src/FSharp.Plotly/Layout.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Layout =
2424
let mutable _xaxis: Xaxis option = None
2525
let mutable _xaxis1: Xaxis option = None
2626
let mutable _xaxis2: Xaxis option = None
27-
let mutable _yaxis: Yaxis option = None
27+
let mutable _yaxis: LinearAxis option = None
2828
let mutable _yaxis2: Yaxis option = None
2929
let mutable _scene: Scene option = None
3030
let mutable _geo: Geo option = None
@@ -127,7 +127,7 @@ module Layout =
127127

128128
member __.yaxis2
129129
with get () = Option.get _yaxis2
130-
and set value = _yaxis <- Some value
130+
and set value = _yaxis2 <- Some value
131131

132132
member __.scene
133133
with get () = Option.get _scene

src/FSharp.Plotly/Options.fs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open System
44
open ApplyHelper
55

6-
type TraceOptions<'T when 'T :> Trace> = 'T -> 'T
6+
type TraceOptions<'T when 'T :> ITrace> = 'T -> 'T
77
type FontOptions = Font -> Font
88
type LineOptions = Line -> Line
99
type MarkerOptions = Marker -> Marker
@@ -33,7 +33,7 @@ type Options() =
3333
?Stream: Stream
3434

3535
) =
36-
(fun (trace:('T :> Trace)) ->
36+
(fun (trace:('T :> ITrace)) ->
3737
Name |> Option.iter trace.set_name
3838
Visible |> Option.iter (StyleOption.Visible.toString >> trace.set_visible)
3939
Showlegend |> Option.iter trace.set_showlegend
@@ -121,8 +121,6 @@ type Options() =
121121
?Text : seq<#IConvertible>,
122122
?Textposition: StyleOption.TextPosition,
123123
?Textfont: FontOptions,
124-
125-
?Hoverinfo: string,
126124

127125
?Mode: StyleOption.Mode,
128126
?Line: LineOptions,
@@ -132,15 +130,12 @@ type Options() =
132130
?Fillcolor: string,
133131

134132

135-
?Uid: string, ?Stream: Stream, ?Connectgaps: bool, ?R: _, ?T: _,
133+
?Connectgaps: bool, ?R: _, ?T: _,
136134
?Error_y: ErrorOptions,
137135
?Error_x: ErrorOptions
138136
) =
139137
(fun (scatter:('T :> Scatter)) ->
140138
//scatter.set_type plotType
141-
Uid |> Option.iter scatter.set_uid
142-
Hoverinfo |> Option.iter scatter.set_hoverinfo
143-
Stream |> Option.iter scatter.set_stream
144139
X |> Option.iter scatter.set_x
145140
Y |> Option.iter scatter.set_y
146141
Text |> Option.iter scatter.set_text
@@ -171,23 +166,17 @@ type Options() =
171166
?X : seq<#IConvertible>,
172167
?Y : seq<#IConvertible>,
173168
?Text : seq<#IConvertible>,
174-
175-
?Hoverinfo: string,
169+
176170
?Marker: MarkerOptions,
177-
?Opacity: float,
178-
179-
?Uid: string, ?Stream: Stream, ?R: _, ?T: _,
171+
?R: _, ?T: _,
180172
?Error_y: ErrorOptions,
181173
?Error_x: ErrorOptions,
182174
//
183175
?Orientation
184176
) =
185177
(fun (bar:('T :> Bar)) ->
186178
//bar.set_type plotType
187-
Opacity |> Option.iter bar.set_opacity
188-
Uid |> Option.iter bar.set_uid
189-
Hoverinfo |> Option.iter bar.set_hoverinfo
190-
Stream |> Option.iter bar.set_stream
179+
191180
X |> Option.iter bar.set_x
192181
Y |> Option.iter bar.set_y
193182
Text |> Option.iter bar.set_text
@@ -589,7 +578,6 @@ type Options() =
589578
?TraceOptions:TraceOptions<_>,
590579
?Values,
591580
?Labels,
592-
?Opacity,
593581
?Label0,
594582
?dLabel,
595583
?Marker,
@@ -617,7 +605,6 @@ type Options() =
617605

618606
Values |> Option.iter pie.set_values
619607
Labels |> Option.iter pie.set_labels
620-
Opacity |> Option.iter pie.set_opacity
621608
Label0 |> Option.iter pie.set_label0
622609
dLabel |> Option.iter pie.set_dlabel
623610
Text |> Option.iter pie.set_text

0 commit comments

Comments
 (0)