Skip to content

Commit a6b99af

Browse files
committed
Finish the shape object abstraction and fix some related layout params
1 parent 7ed80eb commit a6b99af

File tree

8 files changed

+241
-44
lines changed

8 files changed

+241
-44
lines changed

src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ module GenericChartExtensions =
492492
[<Optional; DefaultParameterValue(null)>] ?Computed: string,
493493
[<Optional; DefaultParameterValue(null)>] ?Grid: LayoutGrid,
494494
[<Optional; DefaultParameterValue(null)>] ?Calendar: StyleParam.Calendar,
495-
[<Optional; DefaultParameterValue(null)>] ?NewShape: Shape,
495+
[<Optional; DefaultParameterValue(null)>] ?NewShape: NewShape,
496496
[<Optional; DefaultParameterValue(null)>] ?ActiveShape: ActiveShape,
497497
[<Optional; DefaultParameterValue(null)>] ?HideSources: bool,
498498
[<Optional; DefaultParameterValue(null)>] ?BarGap: float,

src/Plotly.NET/ChartAPI/Chart.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ type Chart =
852852
[<Optional; DefaultParameterValue(null)>] ?Computed: string,
853853
[<Optional; DefaultParameterValue(null)>] ?Grid: LayoutGrid,
854854
[<Optional; DefaultParameterValue(null)>] ?Calendar: StyleParam.Calendar,
855-
[<Optional; DefaultParameterValue(null)>] ?NewShape: Shape,
855+
[<Optional; DefaultParameterValue(null)>] ?NewShape: NewShape,
856856
[<Optional; DefaultParameterValue(null)>] ?ActiveShape: ActiveShape,
857857
[<Optional; DefaultParameterValue(null)>] ?HideSources: bool,
858858
[<Optional; DefaultParameterValue(null)>] ?BarGap: float,

src/Plotly.NET/CommonAbstractions/StyleParams.fs

+47
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,25 @@ module StyleParam =
931931

932932
member this.Convert() = this |> DragMode.convert
933933

934+
[<RequireQualifiedAccess>]
935+
type DrawDirection =
936+
| Ortho
937+
| Horizontal
938+
| Vertical
939+
| Diagonal
940+
941+
static member toString =
942+
function
943+
| Ortho -> "ortho"
944+
| Horizontal -> "horizontal"
945+
| Vertical -> "vertical"
946+
| Diagonal -> "diagonal"
947+
948+
static member convert = DrawDirection.toString >> box
949+
override this.ToString() = this |> DrawDirection.toString
950+
member this.Convert() = this |> DrawDirection.convert
951+
952+
934953
/// Sets the Delaunay axis, which is the axis that is perpendicular to the surface of the Delaunay triangulation.
935954
/// It has an effect if `i`, `j`, `k` are not provided and `alphahull` is set to indicate Delaunay triangulation.
936955
/// Default is "z"
@@ -1125,6 +1144,20 @@ module StyleParam =
11251144
override this.ToString() = this |> Fill.toString
11261145
member this.Convert() = this |> Fill.convert
11271146

1147+
[<RequireQualifiedAccess>]
1148+
type FillRule =
1149+
| EvenOdd
1150+
| NonZero
1151+
1152+
static member toString =
1153+
function
1154+
| EvenOdd -> "evenodd"
1155+
| NonZero -> "nonzero"
1156+
1157+
static member convert = FillRule.toString >> box
1158+
override this.ToString() = this |> FillRule.toString
1159+
member this.Convert() = this |> FillRule.convert
1160+
11281161
//--------------------------
11291162
// #G#
11301163
//--------------------------
@@ -2366,6 +2399,20 @@ module StyleParam =
23662399
// #S#
23672400
//--------------------------
23682401

2402+
[<RequireQualifiedAccess>]
2403+
type ShapeSizeMode =
2404+
| Scaled
2405+
| Pixel
2406+
2407+
static member toString =
2408+
function
2409+
| Scaled -> "scaled"
2410+
| Pixel -> "pixel"
2411+
2412+
static member convert = ShapeSizeMode.toString >> box
2413+
override this.ToString() = this |> ShapeSizeMode.toString
2414+
member this.Convert() = this |> ShapeSizeMode.convert
2415+
23692416
[<RequireQualifiedAccess>]
23702417
type SortAlgorithm =
23712418
| Forward

src/Plotly.NET/Layout/Layout.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type Layout() =
115115
[<Optional; DefaultParameterValue(null)>] ?Computed: string,
116116
[<Optional; DefaultParameterValue(null)>] ?Grid: LayoutGrid,
117117
[<Optional; DefaultParameterValue(null)>] ?Calendar: StyleParam.Calendar,
118-
[<Optional; DefaultParameterValue(null)>] ?NewShape: Shape,
118+
[<Optional; DefaultParameterValue(null)>] ?NewShape: NewShape,
119119
[<Optional; DefaultParameterValue(null)>] ?ActiveShape: ActiveShape,
120120
[<Optional; DefaultParameterValue(null)>] ?HideSources: bool,
121121
[<Optional; DefaultParameterValue(null)>] ?BarGap: float,
@@ -329,7 +329,7 @@ type Layout() =
329329
[<Optional; DefaultParameterValue(null)>] ?Computed: string,
330330
[<Optional; DefaultParameterValue(null)>] ?Grid: LayoutGrid,
331331
[<Optional; DefaultParameterValue(null)>] ?Calendar: StyleParam.Calendar,
332-
[<Optional; DefaultParameterValue(null)>] ?NewShape: Shape,
332+
[<Optional; DefaultParameterValue(null)>] ?NewShape: NewShape,
333333
[<Optional; DefaultParameterValue(null)>] ?ActiveShape: ActiveShape,
334334
[<Optional; DefaultParameterValue(null)>] ?HideSources: bool,
335335
[<Optional; DefaultParameterValue(null)>] ?BarGap: float,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace Plotly.NET.LayoutObjects
2+
3+
open Plotly.NET
4+
open DynamicObj
5+
open System
6+
open System.Runtime.InteropServices
7+
8+
type NewShape() =
9+
inherit DynamicObj()
10+
/// <summary>
11+
/// Returns a new NewShape object with the given styling.
12+
/// </summary>
13+
///<param name="DrawDirection">When `dragmode` is set to "drawrect", "drawline" or "drawcircle" this limits the drag to be horizontal, vertical or diagonal. Using "diagonal" there is no limit e.g. in drawing lines in any direction. "ortho" limits the draw to be either horizontal or vertical. "horizontal" allows horizontal extend. "vertical" allows vertical extend.</param>
14+
///<param name="FillColor">Sets the color filling new shapes' interior. Please note that if using a fillcolor with alpha greater than half, drag inside the active shape starts moving the shape underneath, otherwise a new shape could be started over.</param>
15+
///<param name="FillRule">Determines the path's interior. For more info please visit https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule</param>
16+
///<param name="Layer">Specifies whether new shapes are drawn below or above traces.</param>
17+
///<param name="Line">Sets the outline of new shapes.</param>
18+
///<param name="Opacity">Sets the opacity of new shapes.</param>
19+
static member init
20+
(
21+
[<Optional; DefaultParameterValue(null)>] ?DrawDirection: StyleParam.DrawDirection,
22+
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
23+
[<Optional; DefaultParameterValue(null)>] ?FillRule: StyleParam.FillRule,
24+
[<Optional; DefaultParameterValue(null)>] ?Layer: StyleParam.Layer,
25+
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
26+
[<Optional; DefaultParameterValue(null)>] ?Opacity: float
27+
28+
) =
29+
NewShape()
30+
|> NewShape.style (
31+
?DrawDirection= DrawDirection,
32+
?FillColor = FillColor,
33+
?FillRule = FillRule,
34+
?Layer = Layer,
35+
?Line = Line,
36+
?Opacity = Opacity
37+
)
38+
39+
/// <summary>
40+
/// Returns a function that applies the given styles to a NewShape object
41+
/// </summary>
42+
///<param name="DrawDirection">When `dragmode` is set to "drawrect", "drawline" or "drawcircle" this limits the drag to be horizontal, vertical or diagonal. Using "diagonal" there is no limit e.g. in drawing lines in any direction. "ortho" limits the draw to be either horizontal or vertical. "horizontal" allows horizontal extend. "vertical" allows vertical extend.</param>
43+
///<param name="FillColor">Sets the color filling new shapes' interior. Please note that if using a fillcolor with alpha greater than half, drag inside the active shape starts moving the shape underneath, otherwise a new shape could be started over.</param>
44+
///<param name="FillRule">Determines the path's interior. For more info please visit https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule</param>
45+
///<param name="Layer">Specifies whether new shapes are drawn below or above traces.</param>
46+
///<param name="Line">Sets the outline of new shapes.</param>
47+
///<param name="Opacity">Sets the opacity of new shapes.</param>
48+
static member style
49+
(
50+
[<Optional; DefaultParameterValue(null)>] ?DrawDirection: StyleParam.DrawDirection,
51+
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
52+
[<Optional; DefaultParameterValue(null)>] ?FillRule: StyleParam.FillRule,
53+
[<Optional; DefaultParameterValue(null)>] ?Layer: StyleParam.Layer,
54+
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
55+
[<Optional; DefaultParameterValue(null)>] ?Opacity: float
56+
) =
57+
(fun (newShape: NewShape) ->
58+
59+
DrawDirection |> DynObj.setValueOptBy newShape "drawdirection" StyleParam.DrawDirection.convert
60+
FillColor |> DynObj.setValueOpt newShape "fillcolor"
61+
FillRule |> DynObj.setValueOptBy newShape "fillrule" StyleParam.FillRule.convert
62+
Layer |> DynObj.setValueOptBy newShape "layer" StyleParam.Layer.convert
63+
Line |> DynObj.setValueOpt newShape "line"
64+
Opacity |> DynObj.setValueOpt newShape "opacity"
65+
66+
newShape)
67+
68+

0 commit comments

Comments
 (0)