Skip to content

Commit 0630664

Browse files
committed
Further unify Trace/Layout/Chart APIs
1 parent b3771dd commit 0630664

File tree

8 files changed

+258
-63
lines changed

8 files changed

+258
-63
lines changed

docs/02_7_heatmaps.fsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ let heat3 =
105105
matrix,
106106
ColorScale = StyleParam.Colorscale.Viridis
107107
)
108-
|> Chart.withColorBarStyle(
109-
Title.init("Im the ColorBar")
110-
)
108+
|> Chart.withColorBarStyle(TitleText = "Im the ColorBar")
111109

112110
(*** condition: ipynb ***)
113111
#if IPYNB

docs/05_2_choropleth-map.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ let choroplethMap2 =
126126
ShowOcean=true,
127127
OceanColor=Color.fromString "lightblue",
128128
ShowRivers=true)
129-
|> Chart.withColorBarStyle (Title.init("Alcohol consumption[l/y]"),Length=0.5)
129+
|> Chart.withColorBarStyle (TitleText = "Alcohol consumption[l/y]", Len=0.5)
130130

131131
(*** condition: ipynb ***)
132132
#if IPYNB

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 156 additions & 31 deletions
Large diffs are not rendered by default.

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3145,7 +3145,7 @@ module StyleParam =
31453145

31463146
static member toString =
31473147
function
3148-
| Toggle -> "toggleitem"
3148+
| ToggleItem -> "toggleitem"
31493149
| ToggleGroup -> "togglegroup"
31503150

31513151
static member convert = TraceGroupClickOptions.toString >> box

src/Plotly.NET/Layout/Layout.fs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ type Layout() =
224224
)
225225

226226
/// <summary>
227-
/// Returns a function ahat applies the given styles to a Layout object.
227+
/// Returns a function that applies the given styles to a Layout object.
228228
/// </summary>
229229
/// <param name="Title">Sets the title of the layout.</param>
230230
/// <param name="ShowLegend">Determines whether or not a legend is drawn. Default is `true` if there is a trace to show and any of these: a) Two or more traces would by default be shown in the legend. b) One pie trace is shown in the legend. c) One trace is explicitly given with `showlegend: true`.</param>
@@ -483,8 +483,8 @@ type Layout() =
483483
/// If there is no linear axis set, returns an empty LinearAxis object.
484484
/// </summary>
485485
/// <param name="id">The target axis id</param>
486-
static member getLinearAxisById (id: StyleParam.SubPlotId) (layout: Layout) =
487-
layout |> Layout.tryGetLinearAxisById id |> Option.defaultValue (LinearAxis.init ())
486+
static member getLinearAxisById(id: StyleParam.SubPlotId) =
487+
(fun (layout: Layout) -> layout |> Layout.tryGetLinearAxisById id |> Option.defaultValue (LinearAxis.init ()))
488488

489489
/// <summary>
490490
/// Sets a linear axis object on the layout as a dynamic property with the given axis id.
@@ -532,8 +532,8 @@ type Layout() =
532532
/// If there is no scene set, returns an empty Scene object.
533533
/// </summary>
534534
/// <param name="id">The target scene id</param>
535-
static member getSceneById (id: StyleParam.SubPlotId) (layout: Layout) =
536-
layout |> Layout.tryGetSceneById id |> Option.defaultValue (Scene.init ())
535+
static member getSceneById(id: StyleParam.SubPlotId) =
536+
(fun (layout: Layout) -> layout |> Layout.tryGetSceneById id |> Option.defaultValue (Scene.init ()))
537537

538538
/// <summary>
539539
/// Sets a scene object on the layout as a dynamic property with the given scene id.
@@ -573,8 +573,8 @@ type Layout() =
573573
/// If there is no geo set, returns an empty Geo object.
574574
/// </summary>
575575
/// <param name="id">The target geo id</param>
576-
static member getGeoById (id: StyleParam.SubPlotId) (layout: Layout) =
577-
layout |> Layout.tryGetGeoById id |> Option.defaultValue (Geo.init ())
576+
static member getGeoById(id: StyleParam.SubPlotId) =
577+
(fun (layout: Layout) -> layout |> Layout.tryGetGeoById id |> Option.defaultValue (Geo.init ()))
578578

579579
/// <summary>
580580
/// Sets a geo object on the layout as a dynamic property with the given geo id.
@@ -616,8 +616,8 @@ type Layout() =
616616
/// If there is no mapbox set, returns an empty Mapbox object.
617617
/// </summary>
618618
/// <param name="id">The target mapbox id</param>
619-
static member getMapboxById (id: StyleParam.SubPlotId) (layout: Layout) =
620-
layout |> Layout.tryGetMapboxById id |> Option.defaultValue (Mapbox.init ())
619+
static member getMapboxById(id: StyleParam.SubPlotId) =
620+
(fun (layout: Layout) -> layout |> Layout.tryGetMapboxById id |> Option.defaultValue (Mapbox.init ()))
621621

622622
/// <summary>
623623
/// Sets a mapbox object on the layout as a dynamic property with the given mapbox id.
@@ -661,8 +661,8 @@ type Layout() =
661661
/// If there is no polar set, returns an empty Polar object.
662662
/// </summary>
663663
/// <param name="id">The target polar id</param>
664-
static member getPolarById (id: StyleParam.SubPlotId) (layout: Layout) =
665-
layout |> Layout.tryGetPolarById id |> Option.defaultValue (Polar.init ())
664+
static member getPolarById(id: StyleParam.SubPlotId) =
665+
(fun (layout: Layout) -> layout |> Layout.tryGetPolarById id |> Option.defaultValue (Polar.init ()))
666666

667667
/// <summary>
668668
/// Sets a polar object on the layout as a dynamic property with the given polar id.
@@ -706,8 +706,8 @@ type Layout() =
706706
/// If there is no color axis set, returns an empty ColorAxis object.
707707
/// </summary>
708708
/// <param name="id">The target color axis id</param>
709-
static member getColorAxisById (id: StyleParam.SubPlotId) (layout: Layout) =
710-
layout |> Layout.tryGetColorAxisById id |> Option.defaultValue (ColorAxis.init ())
709+
static member getColorAxisById(id: StyleParam.SubPlotId) =
710+
(fun (layout: Layout) -> layout |> Layout.tryGetColorAxisById id |> Option.defaultValue (ColorAxis.init ()))
711711

712712
/// <summary>
713713
/// Sets a ColorAxis object on the layout as a dynamic property with the given ColorAxis id.
@@ -751,8 +751,8 @@ type Layout() =
751751
/// If there is no ternary set, returns an empty Ternary object.
752752
/// </summary>
753753
/// <param name="id">The target ternary id</param>
754-
static member getTernaryById (id: StyleParam.SubPlotId) (layout: Layout) =
755-
layout |> Layout.tryGetTernaryById id |> Option.defaultValue (Ternary.init ())
754+
static member getTernaryById(id: StyleParam.SubPlotId) =
755+
(fun (layout: Layout) -> layout |> Layout.tryGetTernaryById id |> Option.defaultValue (Ternary.init ()))
756756

757757
/// <summary>
758758
/// Sets a Ternary object on the layout as a dynamic property with the given Ternary id.
@@ -816,7 +816,7 @@ type Layout() =
816816
/// <summary>
817817
/// Combines the given Legend object with the one already present on the layout.
818818
/// </summary>
819-
/// <param name="legend">The updated LayoutGrid object</param>
819+
/// <param name="legend">The updated Legend object</param>
820820
static member updateLegend(legend: Legend) =
821821
(fun (layout: Layout) ->
822822
let combined =

src/Plotly.NET/Traces/Trace.fs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ type Trace(traceTypeName: string) =
4242
trace.SetValue("marker", marker)
4343
trace)
4444

45+
/// <summary>
46+
/// Combines the given marker object with the one already present on the trace.
47+
/// </summary>
48+
/// <param name="marker">The updated Trace object</param>
49+
static member updateMarker(marker: Marker) =
50+
(fun (trace: #Trace) ->
51+
let combined =
52+
(DynObj.combine (trace |> Trace.getMarker) marker) :?> Marker
53+
54+
trace |> Trace.setMarker combined)
55+
4556
/// <summary>
4657
/// Returns the Line object of the given trace.
4758
///
@@ -60,6 +71,17 @@ type Trace(traceTypeName: string) =
6071
trace.SetValue("line", line)
6172
trace)
6273

74+
/// <summary>
75+
/// Combines the given Line object with the one already present on the trace.
76+
/// </summary>
77+
/// <param name="line">The updated Line object</param>
78+
static member updateLine(line: Line) =
79+
(fun (trace: #Trace) ->
80+
let combined =
81+
(DynObj.combine (trace |> Trace.getLine) line) :?> Line
82+
83+
trace |> Trace.setLine combined)
84+
6385
/// <summary>
6486
/// Returns the Error object for the x dimension of the given trace.
6587
///
@@ -78,6 +100,17 @@ type Trace(traceTypeName: string) =
78100
trace.SetValue("error_x", error)
79101
trace)
80102

103+
/// <summary>
104+
/// Combines the given Error object for the x dimension with the one already present on the trace.
105+
/// </summary>
106+
/// <param name="error">The updated Error object</param>
107+
static member updateXError(error: Error) =
108+
(fun (trace: #Trace) ->
109+
let combined =
110+
(DynObj.combine (trace |> Trace.getXError) error) :?> Error
111+
112+
trace |> Trace.setXError combined)
113+
81114
/// <summary>
82115
/// Returns the Error object for the y dimension of the given trace.
83116
///
@@ -96,6 +129,17 @@ type Trace(traceTypeName: string) =
96129
trace.SetValue("error_y", error)
97130
trace)
98131

132+
/// <summary>
133+
/// Combines the given Error object for the y dimension with the one already present on the trace.
134+
/// </summary>
135+
/// <param name="error">The updated Error object</param>
136+
static member updateYError(error: Error) =
137+
(fun (trace: #Trace) ->
138+
let combined =
139+
(DynObj.combine (trace |> Trace.getYError) error) :?> Error
140+
141+
trace |> Trace.setYError combined)
142+
99143
/// <summary>
100144
/// Returns the Error object for the z dimension of the given trace.
101145
///
@@ -114,6 +158,17 @@ type Trace(traceTypeName: string) =
114158
trace.SetValue("error_z", error)
115159
trace)
116160

161+
/// <summary>
162+
/// Combines the given Error object for the z dimension with the one already present on the trace.
163+
/// </summary>
164+
/// <param name="error">The updated Error object</param>
165+
static member updateZError(error: Error) =
166+
(fun (trace: #Trace) ->
167+
let combined =
168+
(DynObj.combine (trace |> Trace.getZError) error) :?> Error
169+
170+
trace |> Trace.setZError combined)
171+
117172
/// <summary>
118173
/// Returns the color axis anchor of the given trace.
119174
///
@@ -159,6 +214,17 @@ type Trace(traceTypeName: string) =
159214
trace.SetValue("domain", domain)
160215
trace)
161216

217+
/// <summary>
218+
/// Combines the given Domain object with the one already present on the trace.
219+
/// </summary>
220+
/// <param name="domain">The updated Domain object</param>
221+
static member updateDomain(domain: Domain) =
222+
(fun (trace: #Trace) ->
223+
let combined =
224+
(DynObj.combine (trace |> Trace.getDomain) domain) :?> Domain
225+
226+
trace |> Trace.setDomain combined)
227+
162228
/// <summary>
163229
/// Returns the stackgroup of the given trace.
164230
///
@@ -196,6 +262,17 @@ type Trace(traceTypeName: string) =
196262
trace.SetValue("colorbar", colorBar)
197263
trace)
198264

265+
/// <summary>
266+
/// Combines the given ColorBar object with the one already present on the trace.
267+
/// </summary>
268+
/// <param name="colorBar">The updated ColorBar object</param>
269+
static member updateColorBar(colorBar: ColorBar) =
270+
(fun (trace: #Trace) ->
271+
let combined =
272+
(DynObj.combine (trace |> Trace.getColorBar) colorBar) :?> ColorBar
273+
274+
trace |> Trace.setColorBar combined)
275+
199276
//-------------------------------------------------------------------------------------------------------------------------------------------------
200277
/// Contains general, visualization-unspecific functions to style Trace objects.
201278
///
@@ -235,7 +312,7 @@ type TraceStyle() =
235312
trace)
236313

237314
/// <summary>
238-
/// Returns a function that applies the given styles to the trace's marker object.
315+
/// Returns a function that applies the given styles to the trace's marker object. Overwrites attributes with the same name that are already set.
239316
/// </summary>
240317
/// <param name="AutoColorScale">Determines whether the colorscale is a default palette (`autocolorscale: true`) or the palette determined by `marker.colorscale`. Has an effect only if in `marker.color`is set to a numerical array. In case `colorscale` is unspecified or `autocolorscale` is true, the default palette will be chosen according to whether numbers in the `color` array are all positive, all negative or mixed.</param>
241318
/// <param name="CAuto">Determines whether or not the color domain is computed with respect to the input data (here in `marker.color`) or the bounds set in `marker.cmin` and `marker.cmax` Has an effect only if in `marker.color`is set to a numerical array. Defaults to `false` when `marker.cmin` and `marker.cmax` are set by the user.</param>
@@ -337,7 +414,7 @@ type TraceStyle() =
337414
trace |> Trace.setMarker (marker))
338415

339416
/// <summary>
340-
/// Returns a function that applies the given styles to the trace's line object.
417+
/// Returns a function that applies the given styles to the trace's line object. Overwrites attributes with the same name that are already set.
341418
/// </summary>
342419
/// <param name="AutoColorScale">Determines whether the colorscale is a default palette (`autocolorscale: true`) or the palette determined by `line.colorscale`. Has an effect only if in `line.color`is set to a numerical array. In case `colorscale` is unspecified or `autocolorscale` is true, the default palette will be chosen according to whether numbers in the `color` array are all positive, all negative or mixed.</param>
343420
/// <param name="CAuto">Determines whether or not the color domain is computed with respect to the input data (here in `line.color`) or the bounds set in `line.cmin` and `line.cmax` Has an effect only if in `line.color`is set to a numerical array. Defaults to `false` when `line.cmin` and `line.cmax` are set by the user.</param>
@@ -409,7 +486,7 @@ type TraceStyle() =
409486
trace |> Trace.setLine (line))
410487

411488
/// <summary>
412-
/// Returns a function that applies the given styles to the trace's Error object for the x dimension.
489+
/// Returns a function that applies the given styles to the trace's Error object for the x dimension. Overwrites attributes with the same name that are already set.
413490
/// </summary>
414491
/// <param name ="Visible">Determines whether or not this set of error bars is visible.</param>
415492
/// <param name ="Type">Determines the rule used to generate the error bars. If "constant`, the bar lengths are of a constant value. Set this constant in `value`. If "percent", the bar lengths correspond to a percentage of underlying data. Set this percentage in `value`. If "sqrt", the bar lengths correspond to the square of the underlying data. If "data", the bar lengths are set with data set `array`.</param>
@@ -463,7 +540,7 @@ type TraceStyle() =
463540
trace |> Trace.setXError (xerror))
464541

465542
/// <summary>
466-
/// Returns a function that applies the given styles to the trace's Error object for the y dimension.
543+
/// Returns a function that applies the given styles to the trace's Error object for the y dimension. Overwrites attributes with the same name that are already set.
467544
/// </summary>
468545
/// <param name ="Visible">Determines whether or not this set of error bars is visible.</param>
469546
/// <param name ="Type">Determines the rule used to generate the error bars. If "constant`, the bar lengths are of a constant value. Set this constant in `value`. If "percent", the bar lengths correspond to a percentage of underlying data. Set this percentage in `value`. If "sqrt", the bar lengths correspond to the square of the underlying data. If "data", the bar lengths are set with data set `array`.</param>

tests/Plotly.NET.Tests/HtmlCodegen/GeoMapCharts.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ let choroplethMap2Chart =
245245
OceanColor= Color.fromString "lightblue",
246246
ShowRivers=true)
247247
|> Chart.withColorBarStyle (
248-
Title.init(Text="Alcohol consumption[l/y]")
249-
,Length=0.5
248+
TitleText="Alcohol consumption[l/y]",Len=0.5
250249
)
251250

252251
[<Tests>]

tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,7 @@ let heatmapStyledChart =
517517
)
518518
|> Chart.withSize(700.,500.)
519519
|> Chart.withMarginSize(Left=200.)
520-
|> Chart.withColorBarStyle(
521-
Title.init(
522-
Text = "Im the Colorbar"
523-
)
524-
)
520+
|> Chart.withColorBarStyle(TitleText = "Im the Colorbar")
525521

526522
let annotatedheatmap =
527523
Chart.AnnotatedHeatmap(

0 commit comments

Comments
 (0)