Skip to content

Commit b50851a

Browse files
committed
Finish contour charts
1 parent 4600ffd commit b50851a

File tree

5 files changed

+327
-77
lines changed

5 files changed

+327
-77
lines changed

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,30 +2447,79 @@ module Chart2D =
24472447
)
24482448
|> GenericChart.ofTraceObject useDefaults
24492449

2450-
/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
2450+
/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format
24512451
[<Extension>]
2452-
static member Contour(data:seq<#seq<#IConvertible>>,
2453-
[<Optional;DefaultParameterValue(null)>] ?X,
2454-
[<Optional;DefaultParameterValue(null)>] ?Y,
2455-
[<Optional;DefaultParameterValue(null)>] ?Name,
2456-
[<Optional;DefaultParameterValue(null)>] ?ShowLegend,
2457-
[<Optional;DefaultParameterValue(null)>] ?Opacity,
2458-
[<Optional;DefaultParameterValue(null)>] ?Colorscale,
2459-
[<Optional;DefaultParameterValue(null)>] ?Showscale,
2460-
[<Optional;DefaultParameterValue(null)>] ?zSmooth,
2461-
[<Optional;DefaultParameterValue(null)>] ?ColorBar,
2462-
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
2452+
static member Contour
2453+
(
2454+
zData: seq<#seq<#IConvertible>>,
2455+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
2456+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
2457+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
2458+
[<Optional;DefaultParameterValue(null)>] ?X : seq<#IConvertible>,
2459+
[<Optional;DefaultParameterValue(null)>] ?Y : seq<#IConvertible>,
2460+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
2461+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
2462+
[<Optional;DefaultParameterValue(null)>] ?ColorBar : ColorBar,
2463+
[<Optional;DefaultParameterValue(null)>] ?ColorScale : StyleParam.Colorscale,
2464+
[<Optional;DefaultParameterValue(null)>] ?ShowScale : bool,
2465+
[<Optional;DefaultParameterValue(null)>] ?ReverseScale : bool,
2466+
[<Optional;DefaultParameterValue(null)>] ?Transpose : bool,
2467+
[<Optional;DefaultParameterValue(null)>] ?LineColor : Color,
2468+
[<Optional;DefaultParameterValue(null)>] ?LineDash : StyleParam.DrawingStyle,
2469+
[<Optional;DefaultParameterValue(null)>] ?Line : Line,
2470+
[<Optional;DefaultParameterValue(null)>] ?ContoursColoring : StyleParam.ContourColoring,
2471+
[<Optional;DefaultParameterValue(null)>] ?ContoursOperation : StyleParam.ConstraintOperation,
2472+
[<Optional;DefaultParameterValue(null)>] ?ContoursType : StyleParam.ContourType,
2473+
[<Optional;DefaultParameterValue(null)>] ?ShowContourLabels : bool,
2474+
[<Optional;DefaultParameterValue(null)>] ?ContourLabelFont : Font,
2475+
[<Optional;DefaultParameterValue(null)>] ?Contours : Contours,
2476+
[<Optional;DefaultParameterValue(null)>] ?FillColor : Color,
2477+
[<Optional;DefaultParameterValue(null)>] ?NContours : int,
2478+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
24632479
) =
24642480

24652481
let useDefaults = defaultArg UseDefaults true
24662482

2483+
let contours =
2484+
Contours
2485+
|> Option.defaultValue (TraceObjects.Contours.init())
2486+
|> TraceObjects.Contours.style(
2487+
?Coloring = ContoursColoring ,
2488+
?Operation = ContoursOperation,
2489+
?Type = ContoursType ,
2490+
?ShowLabels = ShowContourLabels,
2491+
?LabelFont = ContourLabelFont
2492+
)
2493+
2494+
let line =
2495+
Line
2496+
|> Option.defaultValue (Plotly.NET.Line.init())
2497+
|> Plotly.NET.Line.style(
2498+
?Color = LineColor,
2499+
?Dash = LineDash
2500+
)
2501+
24672502
Trace2D.initContour (
24682503
Trace2DStyle.Contour(
2469-
Z=data,?X=X, ?Y=Y,
2470-
?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?ColorBar=ColorBar
2504+
Z = zData ,
2505+
?Name = Name ,
2506+
?ShowLegend = ShowLegend ,
2507+
?Opacity = Opacity ,
2508+
?X = X ,
2509+
?Y = Y ,
2510+
?Text = Text ,
2511+
?MultiText = MultiText ,
2512+
?ColorBar = ColorBar ,
2513+
?ColorScale = ColorScale ,
2514+
?ShowScale = ShowScale ,
2515+
?ReverseScale = ReverseScale,
2516+
?Transpose = Transpose ,
2517+
?FillColor = FillColor ,
2518+
?NContours = NContours ,
2519+
Contours = contours ,
2520+
Line = line
24712521
)
24722522
)
2473-
|> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity)
24742523
|> GenericChart.ofTraceObject useDefaults
24752524

24762525
/// Creates an OHLC (open-high-low-close) chart. OHLC charts are typically used to illustrate movements in the price of a financial instrument over time.

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,87 @@ module StyleParam =
315315
//--------------------------
316316

317317

318+
[<RequireQualifiedAccess>]
319+
type ConstraintOperation =
320+
/// "="
321+
| Equal
322+
/// "<"
323+
| LesserThan
324+
/// "<="
325+
| LesserThanOrEqual
326+
/// ">"
327+
| GreaterThan
328+
/// ">="
329+
| GreaterThanOrEqual
330+
/// "[]"
331+
| InsideInclusiveInterval
332+
/// "[)"
333+
| InsideLeftInclusiveInterval
334+
/// "(]"
335+
| InsideRightInclusiveInterval
336+
/// "()"
337+
| InsideExclusiveInterval
338+
/// "]["
339+
| OutsideInclusiveInterval
340+
/// ")("
341+
| OutsideLeftInclusiveInterval
342+
/// "]("
343+
| OutsideRightInclusiveInterval
344+
/// "]("
345+
| OutsideExclusiveInterval
346+
347+
static member toString = function
348+
349+
350+
| Equal -> "="
351+
| LesserThan -> "<"
352+
| LesserThanOrEqual -> "<="
353+
| GreaterThan -> ">"
354+
| GreaterThanOrEqual -> ">="
355+
| InsideInclusiveInterval -> "[]"
356+
| InsideLeftInclusiveInterval -> "[)"
357+
| InsideRightInclusiveInterval -> "(]"
358+
| InsideExclusiveInterval -> "()"
359+
| OutsideInclusiveInterval -> "]["
360+
| OutsideLeftInclusiveInterval -> ")("
361+
| OutsideRightInclusiveInterval -> "]("
362+
| OutsideExclusiveInterval -> "]("
363+
364+
365+
static member convert = ConstraintOperation.toString >> box
366+
override this.ToString() = this |> ConstraintOperation.toString
367+
member this.Convert() = this |> ConstraintOperation.convert
368+
369+
[<RequireQualifiedAccess>]
370+
type ContourType =
371+
| Levels
372+
| Constraint
373+
374+
static member toString = function
375+
| Levels -> "levels"
376+
| Constraint -> "constraint"
377+
378+
static member convert = ContourType.toString >> box
379+
override this.ToString() = this |> ContourType.toString
380+
member this.Convert() = this |> ContourType.convert
381+
382+
[<RequireQualifiedAccess>]
383+
type ContourColoring =
384+
| Fill
385+
| Heatmap
386+
| Lines
387+
| NoColoring
388+
389+
static member toString = function
390+
| Fill -> "fill"
391+
| Heatmap -> "heatmap"
392+
| Lines -> "lines"
393+
| NoColoring -> "none"
394+
395+
static member convert = ContourColoring.toString >> box
396+
override this.ToString() = this |> ContourColoring.toString
397+
member this.Convert() = this |> ContourColoring.convert
398+
318399
[<RequireQualifiedAccess>]
319400
type CoordinateType =
320401
| Array

src/Plotly.NET/Templates/ChartTemplates.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ module ChartTemplates =
406406
ColorBar = ColorBar.init(
407407
OutlineWidth = 0., Ticks = StyleParam.TickOptions.Empty
408408
),
409-
Colorscale = StyleParam.Colorscale.Custom [
409+
ColorScale = StyleParam.Colorscale.Custom [
410410
0.0 , "#0d0887"
411411
0.1111111111111111 , "#46039f"
412412
0.2222222222222222 , "#7201a8"

src/Plotly.NET/Traces/ObjectAbstractions/Contours.fs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Plotly.NET.TraceObjects
22

33
open Plotly.NET
44
open Plotly.NET.LayoutObjects
5+
open Plotly.NET.TraceObjects
56
open DynamicObj
67
open System
78
open System.Runtime.InteropServices
@@ -113,9 +114,41 @@ type Contour () =
113114
type Contours () =
114115
inherit DynamicObj ()
115116

117+
static member init
118+
(
119+
[<Optional;DefaultParameterValue(null)>] ?Coloring : StyleParam.ContourColoring,
120+
[<Optional;DefaultParameterValue(null)>] ?End : float,
121+
[<Optional;DefaultParameterValue(null)>] ?LabelFont : Font,
122+
[<Optional;DefaultParameterValue(null)>] ?LabelFormat : string,
123+
[<Optional;DefaultParameterValue(null)>] ?Operation : StyleParam.ConstraintOperation,
124+
[<Optional;DefaultParameterValue(null)>] ?ShowLabels : bool,
125+
[<Optional;DefaultParameterValue(null)>] ?ShowLines : bool,
126+
[<Optional;DefaultParameterValue(null)>] ?Size : float,
127+
[<Optional;DefaultParameterValue(null)>] ?Start : float,
128+
[<Optional;DefaultParameterValue(null)>] ?Type : StyleParam.ContourType,
129+
[<Optional;DefaultParameterValue(null)>] ?Value : #IConvertible
130+
) =
131+
Contours ()
132+
|> Contours.style
133+
(
134+
?Coloring = Coloring ,
135+
?End = End ,
136+
?LabelFont = LabelFont ,
137+
?LabelFormat = LabelFormat,
138+
?Operation = Operation ,
139+
?ShowLabels = ShowLabels ,
140+
?ShowLines = ShowLines ,
141+
?Size = Size ,
142+
?Start = Start ,
143+
?Type = Type ,
144+
?Value = Value
145+
146+
)
147+
148+
116149
/// Initialized Contours object
117150
//[<CompiledName("init")>]
118-
static member init
151+
static member initSurface
119152
(
120153
[<Optional;DefaultParameterValue(null)>] ?X : Contour,
121154
[<Optional;DefaultParameterValue(null)>] ?Y : Contour,
@@ -133,16 +166,39 @@ type Contours () =
133166
//[<CompiledName("style")>]
134167
static member style
135168
(
136-
[<Optional;DefaultParameterValue(null)>] ?X : Contour,
137-
[<Optional;DefaultParameterValue(null)>] ?Y : Contour,
138-
[<Optional;DefaultParameterValue(null)>] ?Z : Contour
169+
[<Optional;DefaultParameterValue(null)>] ?X : Contour,
170+
[<Optional;DefaultParameterValue(null)>] ?Y : Contour,
171+
[<Optional;DefaultParameterValue(null)>] ?Z : Contour,
172+
[<Optional;DefaultParameterValue(null)>] ?Coloring : StyleParam.ContourColoring,
173+
[<Optional;DefaultParameterValue(null)>] ?End : float,
174+
[<Optional;DefaultParameterValue(null)>] ?LabelFont : Font,
175+
[<Optional;DefaultParameterValue(null)>] ?LabelFormat : string,
176+
[<Optional;DefaultParameterValue(null)>] ?Operation : StyleParam.ConstraintOperation,
177+
[<Optional;DefaultParameterValue(null)>] ?ShowLabels : bool,
178+
[<Optional;DefaultParameterValue(null)>] ?ShowLines : bool,
179+
[<Optional;DefaultParameterValue(null)>] ?Size : float,
180+
[<Optional;DefaultParameterValue(null)>] ?Start : float,
181+
[<Optional;DefaultParameterValue(null)>] ?Type : StyleParam.ContourType,
182+
[<Optional;DefaultParameterValue(null)>] ?Value : #IConvertible
139183
) =
140184

141185
(fun (contours:Contours) ->
142-
X |> DynObj.setValueOpt contours "x"
143-
Y |> DynObj.setValueOpt contours "y"
144-
Z |> DynObj.setValueOpt contours "z"
145-
186+
X |> DynObj.setValueOpt contours "x"
187+
Y |> DynObj.setValueOpt contours "y"
188+
Z |> DynObj.setValueOpt contours "z"
189+
Coloring |> DynObj.setValueOptBy contours "coloring" StyleParam.ContourColoring.convert
190+
End |> DynObj.setValueOpt contours "end"
191+
LabelFont |> DynObj.setValueOpt contours "labelfont"
192+
LabelFormat |> DynObj.setValueOpt contours "labelformat"
193+
Operation |> DynObj.setValueOptBy contours "operation" StyleParam.ConstraintOperation.convert
194+
ShowLabels |> DynObj.setValueOpt contours "showlabels"
195+
ShowLines |> DynObj.setValueOpt contours "showlines"
196+
Size |> DynObj.setValueOpt contours "size"
197+
Start |> DynObj.setValueOpt contours "start"
198+
Type |> DynObj.setValueOptBy contours "type" StyleParam.ContourType.convert
199+
Value |> DynObj.setValueOpt contours "value"
200+
201+
146202
contours
147203
)
148204

0 commit comments

Comments
 (0)