Skip to content

Commit 191a857

Browse files
author
Timo Mühlhaus
committed
Fix: TraceObject name property
1 parent 9fda3a8 commit 191a857

File tree

6 files changed

+123
-102
lines changed

6 files changed

+123
-102
lines changed

docs/content/contour-plots.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ z
4545
|> Chart.Contour
4646
|> Chart.withSize(600.,600.)
4747
(*** include-it:contour1 ***)
48+
|> Chart.Show
49+
4850

4951

docs/content/line-scatter-plots.fsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ shown below.
3636
// Drawing graph of a 'square' function
3737
[ for x in 1.0 .. 100.0 -> (x, x ** 2.0) ]
3838
|> Chart.Line
39-
(*** include-it:sq ***)
39+
(*** include-it:sq ***)
40+
|> Chart.Show

src/FSharp.Plotly/Chart.fs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -258,29 +258,29 @@ type Chart =
258258
// ?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos)
259259
//
260260
// GenericChart.Chart (trace,None)
261-
//
262-
// /// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
263-
// /// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
264-
// static member Heatmap(data:seq<#seq<#IConvertible>>,?ColNames,?RowNames, ?Name,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
265-
// let trace =
266-
// Heatmap()
267-
// |> Options.Colormap(Z=data,?X=ColNames, ?Y=RowNames,
268-
// TraceOptions=Options.Trace(?Name=Name),
269-
// ?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar
270-
// )
271-
// GenericChart.Chart (trace,None)
272-
//
273-
// /// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
274-
// static member Contour(data:seq<#seq<#IConvertible>>,?X,?Y, ?Name,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
275-
// let trace =
276-
// Contour()
277-
// |> Options.Colormap(Z=data,?X=X, ?Y=Y,
278-
// TraceOptions=Options.Trace(?Name=Name),
279-
// ?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar
280-
// )
281-
// GenericChart.Chart (trace,None)
282-
//
283-
//
261+
262+
/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
263+
/// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
264+
static member Heatmap(data:seq<#seq<#IConvertible>>,?ColNames,?RowNames, ?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
265+
let trace =
266+
Heatmap()
267+
|> Options.IColormap(Z=data,?X=ColNames, ?Y=RowNames,
268+
?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
269+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
270+
//|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
271+
GenericChart.Chart (trace,None)
272+
273+
/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
274+
static member Contour(data:seq<#seq<#IConvertible>>,?X,?Y, ?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
275+
let trace =
276+
Contour()
277+
|> Options.IColormap(Z=data,?X=X, ?Y=Y,
278+
?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
279+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
280+
//|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
281+
GenericChart.Chart (trace,None)
282+
283+
284284
// /// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data as a whole.
285285
// static member Pie(values,?labels,?Name,?Showlegend,?Color,?Hoverinfo,?Textinfo,?Textposition) =
286286
// let trace =
@@ -327,16 +327,6 @@ type Chart =
327327

328328

329329

330-
331-
// static member Point3D(x, y, z, ?Name,?ShowMarkers,?Showlegend,?Color,?Opacity,?Labels) =
332-
// let trace =
333-
// GenericTrace()
334-
// |> Helpers.ApplyTraceStyles("scatter",x = x,y = y, mode="markers", ?name=Name,
335-
// ?showlegend=Showlegend,?fillcolor=Color,?opacity=Opacity,?text=Labels)
336-
// GenericChart.Chart (trace,None)
337-
338-
339-
340330

341331

342332

src/FSharp.Plotly/Chart3d.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ type Chart3d =
1313
static member Scatter(x, y, z, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
1414
let trace =
1515
Trace3dObjects.Scatter3d()
16-
|> Options3d.Scatter3d(X = x,Y = y,Z=z, Mode=mode)
16+
|> Options.Scatter3d(X = x,Y = y,Z=z, Mode=mode)
1717
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1818
|> Options.ILine(Options.Line(?Color=Color,?Dash=Dash,?Width=Width))
1919
|> Options.IMarker(Options.Marker(?Color=Color,?Symbol=MarkerSymbol))
2020
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
2121
GenericChart3d.Chart (trace,None)
2222

2323

24+
25+
26+
// static member Point3D(x, y, z, ?Name,?ShowMarkers,?Showlegend,?Color,?Opacity,?Labels) =
27+
// let trace =
28+
// GenericTrace()
29+
// |> Helpers.ApplyTraceStyles("scatter",x = x,y = y, mode="markers", ?name=Name,
30+
// ?showlegend=Showlegend,?fillcolor=Color,?opacity=Opacity,?text=Labels)
31+
// GenericChart.Chart (trace,None)
32+
33+
34+

src/FSharp.Plotly/Options.fs

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -715,21 +715,30 @@ type Options() =
715715
)
716716

717717

718-
// Applies the styles to Heatmap() and Contour()
719-
static member Colormap
718+
// let mutable _z : seq<#seq<#System.IConvertible>> option = None
719+
// let mutable _x : seq<#System.IConvertible> option = None
720+
// let mutable _y : seq<#System.IConvertible> option = None
721+
// let mutable _transpose : bool option = None
722+
// let mutable _zauto : bool option = None
723+
// let mutable _zmin : float option = None
724+
// let mutable _zmax : float option = None
725+
// let mutable _colorscale : _ option = None
726+
// let mutable _autocolorscale : bool option = None
727+
// let mutable _reversescale : bool option = None
728+
// let mutable _showscale : bool option = None
729+
// let mutable _zsmooth : _ option = None
730+
// let mutable _colorbar : Colorbar option = None
731+
// let mutable _zsrc : string option = None
732+
// let mutable _xsrc : string option = None
733+
// let mutable _ysrc : string option = None
734+
735+
// // Applies the styles to TraceObjects with IColormap interface
736+
static member IColormap
720737
(
721-
?TraceOptions:TraceOptions<_>,
722738
?Z : seq<#seq<#IConvertible>>,
723739
?X : seq<#IConvertible>,
724-
?X0 ,
725-
?dX ,
726740
?Y : seq<#IConvertible>,
727-
?Y0 ,
728-
?dY ,
729-
?Text ,
730741
?Transpose ,
731-
?xType ,
732-
?yType ,
733742
?zAuto ,
734743
?zMin ,
735744
?zMax ,
@@ -738,50 +747,63 @@ type Options() =
738747
?Reversescale ,
739748
?Showscale ,
740749
?zSmooth ,
741-
?Connectgaps ,
742750
?Colorbar ,
743-
?xAxis ,
744-
?yAxis ,
745751
?Zsrc ,
746752
?Xsrc ,
747-
?Ysrc ,
748-
?Textsrc
753+
?Ysrc
754+
) =
755+
(fun (colorMap:('T :> IColormap)) ->
756+
757+
Z |> Option.iter colorMap.set_z
758+
X |> Option.iter colorMap.set_x
759+
Y |> Option.iter colorMap.set_y
760+
Transpose |> Option.iter colorMap.set_transpose
761+
zAuto |> Option.iter colorMap.set_zauto
762+
zMin |> Option.iter colorMap.set_zmin
763+
zMax |> Option.iter colorMap.set_zmax
764+
Colorscale |> Option.iter (StyleOption.ColorScale.convert >> colorMap.set_colorscale)
765+
Autocolorscale |> Option.iter colorMap.set_autocolorscale
766+
Reversescale |> Option.iter colorMap.set_reversescale
767+
Showscale |> Option.iter colorMap.set_showscale
768+
zSmooth |> Option.iter (StyleOption.SmoothAlg.convert >> colorMap.set_zsmooth)
769+
Colorbar |> Option.iter colorMap.set_colorbar
770+
Zsrc |> Option.iter colorMap.set_zsrc
771+
Xsrc |> Option.iter colorMap.set_xsrc
772+
Ysrc |> Option.iter colorMap.set_ysrc
773+
774+
// out ->
775+
colorMap
776+
)
749777

750778

751779

780+
// Applies the styles to Heatmap() and Contour()
781+
static member Colormap
782+
(
783+
?X0 ,
784+
?dX ,
785+
?Y0 ,
786+
?dY ,
787+
?xType ,
788+
?yType ,
789+
?Connectgaps ,
790+
?xAxis ,
791+
?yAxis
752792
) =
753793
(fun (colorMap:('T :> Colormap)) ->
754794

755-
// Z |> Option.iter colorMap.set_z -- temporarily
756-
// X |> Option.iter colorMap.set_x -- temporarily
757795
X0 |> Option.iter colorMap.set_x0
758796
dX |> Option.iter colorMap.set_dx
759-
// Y |> Option.iter colorMap.set_y -- temporarily
760797
Y0 |> Option.iter colorMap.set_y0
761798
dY |> Option.iter colorMap.set_dy
762-
// Text |> Option.iter colorMap.set_text -- temporarily
763-
// Transpose |> Option.iter colorMap.set_transpose -- temporarily
764799
xType |> Option.iter colorMap.set_xtype
765800
yType |> Option.iter colorMap.set_ytype
766-
// zAuto |> Option.iter colorMap.set_zauto -- temporarily
767-
// zMin |> Option.iter colorMap.set_zmin -- temporarily
768-
// zMax |> Option.iter colorMap.set_zmax -- temporarily
769-
// Colorscale |> Option.iter (StyleOption.ColorScale.convert >> colorMap.set_colorscale) -- temporarily
770-
// Autocolorscale |> Option.iter colorMap.set_autocolorscale -- temporarily
771-
// Reversescale |> Option.iter colorMap.set_reversescale -- temporarily
772-
// Showscale |> Option.iter colorMap.set_showscale -- temporarily
773-
// zSmooth |> Option.iter (StyleOption.SmoothAlg.convert >> colorMap.set_zsmooth) -- temporarily
774801
Connectgaps |> Option.iter colorMap.set_connectgaps
775-
// Colorbar |> Option.iter colorMap.set_colorbar
776802
xAxis |> Option.iter colorMap.set_xaxis
777803
yAxis |> Option.iter colorMap.set_yaxis
778-
// Zsrc |> Option.iter colorMap.set_zsrc -- temporarily
779-
// Xsrc |> Option.iter colorMap.set_xsrc -- temporarily
780-
// Ysrc |> Option.iter colorMap.set_ysrc -- temporarily
781-
// Textsrc |> Option.iter colorMap.set_textsrc -- temporarily
782-
804+
783805
// out ->
784-
colorMap |> (optApply TraceOptions)
806+
colorMap
785807
)
786808

787809

src/FSharp.Plotly/TraceObjects.fs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ module TraceObjects =
5353
abstract ShouldSerializemarker : unit -> bool
5454

5555
type IColormap =
56-
abstract z : seq<seq<System.IConvertible>> with get, set
57-
abstract x : seq<System.IConvertible> with get, set
58-
abstract y : seq<System.IConvertible> with get, set
56+
abstract z : obj with get, set
57+
abstract x : obj with get, set
58+
abstract y : obj with get, set
5959
abstract transpose : bool with get, set
6060
abstract zauto : bool with get, set
6161
abstract zmin : float with get, set
@@ -136,13 +136,6 @@ module TraceObjects =
136136
let mutable _ysrc: string option = None
137137
let mutable _rsrc: string option = None
138138
let mutable _tsrc: string option = None
139-
140-
141-
// member __.line
142-
// with get () = Option.get _line
143-
// and set value = _line <- Some value
144-
//
145-
// member __.ShouldSerializeline() = not _line.IsNone
146139

147140
/// Sets the x coordinates.
148141
member __.x
@@ -269,86 +262,86 @@ module TraceObjects =
269262
with get () = Option.get _type
270263
and set value = _type <- Some value
271264

272-
member __.ShouldSerializetype() = (__ :> ITrace).ShouldSerializetype()
273-
265+
member __.ShouldSerializetype() = not _type.IsNone
266+
274267
// Implictit ITraceInfo
275268
member __.name
276269
with get () = Option.get _name
277270
and set value = _name <- Some value
278-
member __.ShouldSerializeiname() = (__ :> ITraceInfo).ShouldSerializename() //temporalily
271+
member __.ShouldSerializename() = not _name.IsNone
279272

280273
member __.visible
281274
with get () = Option.get _visible
282275
and set value = _visible <- Some value
283-
member __.ShouldSerializevisible() = (__ :> ITraceInfo).ShouldSerializevisible()
276+
member __.ShouldSerializevisible() = not _visible.IsNone
284277

285278
member __.showlegend
286279
with get () = Option.get _showlegend
287280
and set value = _showlegend <- Some value
288-
member __.ShouldSerializeshowlegend() = (__ :> ITraceInfo).ShouldSerializeshowlegend()
281+
member __.ShouldSerializeshowlegend() = not _showlegend.IsNone
289282

290283
member __.legendgroup
291284
with get () = Option.get _legendgroup
292285
and set value = _legendgroup <- Some value
293-
member __.ShouldSerializelegendgroup() = (__ :> ITraceInfo).ShouldSerializelegendgroup()
286+
member __.ShouldSerializelegendgroup() = not _legendgroup.IsNone
294287

295288
member __.opacity
296289
with get () = Option.get _opacity
297290
and set value = _opacity <- Some value
298-
member __.ShouldSerializeopacity() = (__ :> ITraceInfo).ShouldSerializeopacity()
291+
member __.ShouldSerializeopacity() = not _opacity.IsNone
299292

300293
member __.uid
301294
with get () = Option.get _uid
302295
and set value = _uid <- Some value
303-
member __.ShouldSerializeuid() = (__ :> ITraceInfo).ShouldSerializeuid()
296+
member __.ShouldSerializeuid() = not _uid.IsNone
304297

305298
member __.hoverinfo
306299
with get () = Option.get _hoverinfo
307300
and set value = _hoverinfo <- Some value
308-
member __.ShouldSerializehoverinfo() = (__ :> ITraceInfo).ShouldSerializehoverinfo()
301+
member __.ShouldSerializehoverinfo() = not _hoverinfo.IsNone
309302

310303
member __.stream
311304
with get () = Option.get _stream
312305
and set value = _stream <- Some value
313-
member __.ShouldSerializestream() = (__ :> ITraceInfo).ShouldSerializestream()
306+
member __.ShouldSerializestream() = not _stream.IsNone
314307

315-
// Implictit ITextLabel
308+
// Implictit ITextLabel
316309
member __.text
317310
with get () = Option.get _text
318311
and set value = _text <- Some value
319-
member __.ShouldSerializetext() = (__ :> ITextLabel).ShouldSerializetext()
312+
member __.ShouldSerializetext() = not _text.IsNone
320313

321314
member __.textposition
322315
with get () = Option.get _textposition
323316
and set value = _textposition <- Some value
324-
member __.ShouldSerializetextposition() = (__ :> ITextLabel).ShouldSerializetextposition()
317+
member __.ShouldSerializetextposition() = not _textposition.IsNone
325318

326319
member __.textfont
327320
with get () = Option.get _textfont
328321
and set value = _textfont <- Some value
329-
member __.ShouldSerializetextfont() = (__ :> ITextLabel).ShouldSerializetextfont()
322+
member __.ShouldSerializetextfont() = not _textfont.IsNone
330323

331324
member __.textsrc
332325
with get () = Option.get _textsrc
333326
and set value = _textsrc <- Some value
334-
member __.ShouldSerializetextsrc() = (__ :> ITextLabel).ShouldSerializetextpositionsrc()
327+
member __.ShouldSerializetextsrc() = not _textsrc.IsNone
335328

336329
member __.textpositionsrc
337330
with get () = Option.get _textpositionsrc
338331
and set value = _textpositionsrc <- Some value
339-
member __.ShouldSerializetextpositionsrc() = (__ :> ITextLabel).ShouldSerializetextpositionsrc()
332+
member __.ShouldSerializetextpositionsrc() = not _textpositionsrc.IsNone
340333

341334
// Implictit ILine
342335
member __.line
343336
with get () = Option.get _line
344337
and set value = _line <- Some value
345-
member __.ShouldSerializeline() = (__ :> ILine).ShouldSerializeline()
338+
member __.ShouldSerializeline() = not _line.IsNone
346339

347340
// Implictit IMarker
348341
member __.marker
349342
with get () = Option.get _marker
350343
and set value = _marker <- Some value
351-
member __.ShouldSerializemarker() = (__ :> IMarker).ShouldSerializemarker()
344+
member __.ShouldSerializemarker() = not _marker.IsNone
352345

353346
interface ITrace with
354347
member __.``type``
@@ -1355,9 +1348,9 @@ module TraceObjects =
13551348
let mutable _textsrc: string option = None
13561349
let mutable _textpositionsrc: string option = None
13571350
// IColormap interface
1358-
let mutable _z : seq<#seq<#System.IConvertible>> option = None
1359-
let mutable _x : seq<#System.IConvertible> option = None
1360-
let mutable _y : seq<#System.IConvertible> option = None
1351+
let mutable _z : _ option = None //seq<#seq<#System.IConvertible>> option = None
1352+
let mutable _x : _ option = None// seq<#System.IConvertible> option = None
1353+
let mutable _y : _ option = None
13611354
let mutable _transpose : bool option = None
13621355
let mutable _zauto : bool option = None
13631356
let mutable _zmin : float option = None
@@ -1451,7 +1444,9 @@ module TraceObjects =
14511444
member __.name
14521445
with get () = Option.get _name
14531446
and set value = _name <- Some value
1454-
member __.ShouldSerializeiname() = (__ :> ITraceInfo).ShouldSerializename() //temporalily
1447+
1448+
member __.ShouldSerializename() = not _name.IsNone
1449+
// member __.ShouldSerializeiname() = (__ :> ITraceInfo).ShouldSerializename() //temporalily
14551450

14561451
member __.visible
14571452
with get () = Option.get _visible

0 commit comments

Comments
 (0)