Skip to content

Commit

Permalink
Merge pull request #472 from plotly/update-to-dynobj-v4
Browse files Browse the repository at this point in the history
update to DynamicObj v4
  • Loading branch information
kMutagene authored Oct 16, 2024
2 parents f16b6ae + dbdf8b6 commit 56cc563
Show file tree
Hide file tree
Showing 118 changed files with 3,637 additions and 3,894 deletions.
26 changes: 13 additions & 13 deletions docs/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,25 @@ double[] x = new double[] { 1, 2 };
double[] y = new double[] { 5, 10 };
LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "xAxis");
xAxis.SetValue("showgrid", false);
xAxis.SetValue("showline", true);
xAxis.SetProperty("title", "xAxis");
xAxis.SetProperty("showgrid", false);
xAxis.SetProperty("showline", true);
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "yAxis");
yAxis.SetValue("showgrid", false);
yAxis.SetValue("showline", true);
yAxis.SetProperty("title", "yAxis");
yAxis.SetProperty("showgrid", false);
yAxis.SetProperty("showline", true);
Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);
layout.SetValue("yaxis", yAxis);
layout.SetValue("showlegend", true);
layout.SetProperty("xaxis", xAxis);
layout.SetProperty("yaxis", yAxis);
layout.SetProperty("showlegend", true);
Trace trace = new Trace("scatter");
trace.SetValue("x", x);
trace.SetValue("y", y);
trace.SetValue("mode", "markers");
trace.SetValue("name", "Hello from C#");
trace.SetProperty("x", x);
trace.SetProperty("y", y);
trace.SetProperty("mode", "markers");
trace.SetProperty("name", "Hello from C#");
GenericChart
.ofTraceObject(true, trace)
Expand Down
11 changes: 6 additions & 5 deletions src/Plotly.NET.ImageExport/PuppeteerSharpRenderer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ type PuppeteerSharpRenderer() =

gChart
|> GenericChart.mapConfig (fun c ->
DynObj.setValue c "responsive" true
c)
c |> DynObj.withProperty "responsive" true
)
|> GenericChart.mapLayout (fun l ->
DynObj.setValue l "width" "100%"
DynObj.setValue l "height" "100%"
l)
l
|> DynObj.withProperty "width" "100%"
|> DynObj.withProperty "height" "100%"
)
|> GenericChart.toEmbeddedHTML
// this should be done via regex, as this only captures the default width and height.
|> fun html -> html.Replace("width: 600px; height: 600px;", "width: 100%; height: 100%;")
Expand Down
10 changes: 5 additions & 5 deletions src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ module GenericChartExtensions =
member this.withColorBar(colorbar: ColorBar) =
this
|> GenericChart.mapTrace (fun t ->
colorbar |> DynObj.setValue t "colorbar"
t)
t |> DynObj.withProperty "colorbar" colorbar
)

[<CompiledName("WithColorbar")>]
[<Extension>]
Expand Down Expand Up @@ -805,7 +805,7 @@ module GenericChartExtensions =

let updatedGrid =
let currentGrid =
match layout.TryGetTypedValue<LayoutGrid> "grid" with
match layout.TryGetTypedPropertyValue<LayoutGrid> "grid" with
| Some grid -> grid
| None -> LayoutGrid()

Expand Down Expand Up @@ -913,8 +913,8 @@ module GenericChartExtensions =
member this.WithTemplate(template: Template) =
this
|> GenericChart.mapLayout (fun l ->
template |> DynObj.setValue l "template"
l)
l |> DynObj.withProperty "template" template
)

// TODO: Include withLegend & withLegendStyle

Expand Down
108 changes: 52 additions & 56 deletions src/Plotly.NET/ChartAPI/Chart.fs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Plotly.NET/ChartAPI/GenericChart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type GenericChart =
/// <param name="gChart">the input GenericChart to get the layout size from</param>
static member tryGetLayoutSize gChart =
let layout = GenericChart.getLayout gChart
layout.TryGetTypedValue<int> "width", layout.TryGetTypedValue<int> "height"
layout.TryGetTypedPropertyValue<int> "width", layout.TryGetTypedPropertyValue<int> "height"

/// <summary>
/// Returns the config of a given GenericChart.
Expand Down
14 changes: 7 additions & 7 deletions src/Plotly.NET/CommonAbstractions/AutoRangeOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ type AutoRangeOptions() =
) =
(fun (autoRangeOptions: AutoRangeOptions) ->

ClipMax |> DynObj.setValueOpt autoRangeOptions "clipmax"
ClipMin |> DynObj.setValueOpt autoRangeOptions "clipmin"
Include |> DynObj.setValueOpt autoRangeOptions "include"
MaxAllowed |> DynObj.setValueOpt autoRangeOptions "maxallowed"
MinAllowed |> DynObj.setValueOpt autoRangeOptions "minallowed"

autoRangeOptions)
autoRangeOptions
|> DynObj.withOptionalProperty "clipmax" ClipMax
|> DynObj.withOptionalProperty "clipmin" ClipMin
|> DynObj.withOptionalProperty "include" Include
|> DynObj.withOptionalProperty "maxallowed" MaxAllowed
|> DynObj.withOptionalProperty "minallowed" MinAllowed
)
96 changes: 48 additions & 48 deletions src/Plotly.NET/CommonAbstractions/ColorBar.fs
Original file line number Diff line number Diff line change
Expand Up @@ -254,52 +254,52 @@ type ColorBar() =
) =

(fun (colorBar: ColorBar) ->
colorBar
|> DynObj.withOptionalProperty "bgcolor" BGColor
|> DynObj.withOptionalProperty "bordercolor" BorderColor
|> DynObj.withOptionalProperty "borderwidth" BorderWidth
|> DynObj.withOptionalProperty "dtick" DTick
|> DynObj.withOptionalPropertyBy "exponentformat" ExponentFormat StyleParam.ExponentFormat.convert
|> DynObj.withOptionalProperty "labelalias" LabelAlias
|> DynObj.withOptionalProperty "len" Len
|> DynObj.withOptionalPropertyBy "lenmode" LenMode StyleParam.UnitMode.convert
|> DynObj.withOptionalProperty "min3xponent" MinExponent
|> DynObj.withOptionalProperty "nticks" NTicks
|> DynObj.withOptionalPropertyBy "orientation" Orientation StyleParam.Orientation.convert
|> DynObj.withOptionalProperty "outlinecolor" OutlineColor
|> DynObj.withOptionalProperty "outlinewidth" OutlineWidth
|> DynObj.withOptionalProperty "separatethousands" SeparateThousands
|> DynObj.withOptionalPropertyBy "showexponent" ShowExponent StyleParam.ShowExponent.convert
|> DynObj.withOptionalProperty "showticklabels" ShowTickLabels
|> DynObj.withOptionalPropertyBy "showtickprefix" ShowTickPrefix StyleParam.ShowTickOption.convert
|> DynObj.withOptionalPropertyBy "showticksuffix" ShowTickSuffix StyleParam.ShowTickOption.convert
|> DynObj.withOptionalProperty "thickness" Thickness
|> DynObj.withOptionalPropertyBy "thicknessmode" ThicknessMode StyleParam.UnitMode.convert
|> DynObj.withOptionalProperty "tick0" Tick0
|> DynObj.withOptionalProperty "tickangle" TickAngle
|> DynObj.withOptionalProperty "tickcolor" TickColor
|> DynObj.withOptionalProperty "tickfont" TickFont
|> DynObj.withOptionalProperty "tickformat" TickFormat
|> DynObj.withOptionalProperty "tickformatstops" TickFormatStops
|> DynObj.withOptionalPropertyBy "ticklabeloverflow" TickLabelOverflow StyleParam.TickLabelOverflow.convert
|> DynObj.withOptionalPropertyBy "ticklabelposition" TickLabelPosition StyleParam.TickLabelPosition.convert
|> DynObj.withOptionalProperty "ticklabelstep" TickLabelStep
|> DynObj.withOptionalProperty "ticklen" TickLen
|> DynObj.withOptionalPropertyBy "tickmode" TickMode StyleParam.TickMode.convert
|> DynObj.withOptionalProperty "tickprefix" TickPrefix
|> DynObj.withOptionalPropertyBy "ticks" Ticks StyleParam.TickOptions.convert
|> DynObj.withOptionalProperty "ticksuffix" TickSuffix
|> DynObj.withOptionalProperty "ticktext" TickText
|> DynObj.withOptionalProperty "tickvals" TickVals
|> DynObj.withOptionalProperty "tickwidth" TickWidth
|> DynObj.withOptionalProperty "title" Title
|> DynObj.withOptionalProperty "x" X
|> DynObj.withOptionalPropertyBy "xanchor" XAnchor StyleParam.HorizontalAlign.convert
|> DynObj.withOptionalProperty "xpad" XPad
|> DynObj.withOptionalProperty "xref" XRef
|> DynObj.withOptionalProperty "y" Y
|> DynObj.withOptionalPropertyBy "yanchor" YAnchor StyleParam.VerticalAlign.convert
|> DynObj.withOptionalProperty "ypad" YPad
|> DynObj.withOptionalProperty "yref" YRef

BGColor |> DynObj.setValueOpt colorBar "bgcolor"
BorderColor |> DynObj.setValueOpt colorBar "bordercolor"
BorderWidth |> DynObj.setValueOpt colorBar "borderwidth"
DTick |> DynObj.setValueOpt colorBar "dtick"
ExponentFormat |> DynObj.setValueOptBy colorBar "exponentformat" StyleParam.ExponentFormat.convert
LabelAlias |> DynObj.setValueOpt colorBar "labelalias"
Len |> DynObj.setValueOpt colorBar "len"
LenMode |> DynObj.setValueOptBy colorBar "lenmode" StyleParam.UnitMode.convert
MinExponent |> DynObj.setValueOpt colorBar "min3xponent"
NTicks |> DynObj.setValueOpt colorBar "nticks"
Orientation |> DynObj.setValueOptBy colorBar "orientation" StyleParam.Orientation.convert
OutlineColor |> DynObj.setValueOpt colorBar "outlinecolor"
OutlineWidth |> DynObj.setValueOpt colorBar "outlinewidth"
SeparateThousands |> DynObj.setValueOpt colorBar "separatethousands"
ShowExponent |> DynObj.setValueOptBy colorBar "showexponent" StyleParam.ShowExponent.convert
ShowTickLabels |> DynObj.setValueOpt colorBar "showticklabels"
ShowTickPrefix |> DynObj.setValueOptBy colorBar "showtickprefix" StyleParam.ShowTickOption.convert
ShowTickSuffix |> DynObj.setValueOptBy colorBar "showticksuffix" StyleParam.ShowTickOption.convert
Thickness |> DynObj.setValueOpt colorBar "thickness"
ThicknessMode |> DynObj.setValueOptBy colorBar "thicknessmode" StyleParam.UnitMode.convert
Tick0 |> DynObj.setValueOpt colorBar "tick0"
TickAngle |> DynObj.setValueOpt colorBar "tickangle"
TickColor |> DynObj.setValueOpt colorBar "tickcolor"
TickFont |> DynObj.setValueOpt colorBar "tickfont"
TickFormat |> DynObj.setValueOpt colorBar "tickformat"
TickFormatStops |> DynObj.setValueOpt colorBar "tickformatstops"
TickLabelOverflow |> DynObj.setValueOptBy colorBar "ticklabeloverflow" StyleParam.TickLabelOverflow.convert
TickLabelPosition |> DynObj.setValueOptBy colorBar "ticklabelposition" StyleParam.TickLabelPosition.convert
TickLabelStep |> DynObj.setValueOpt colorBar "ticklabelstep"
TickLen |> DynObj.setValueOpt colorBar "ticklen"
TickMode |> DynObj.setValueOptBy colorBar "tickmode" StyleParam.TickMode.convert
TickPrefix |> DynObj.setValueOpt colorBar "tickprefix"
Ticks |> DynObj.setValueOptBy colorBar "ticks" StyleParam.TickOptions.convert
TickSuffix |> DynObj.setValueOpt colorBar "ticksuffix"
TickText |> DynObj.setValueOpt colorBar "ticktext"
TickVals |> DynObj.setValueOpt colorBar "tickvals"
TickWidth |> DynObj.setValueOpt colorBar "tickwidth"
Title |> DynObj.setValueOpt colorBar "title"
X |> DynObj.setValueOpt colorBar "x"
XAnchor |> DynObj.setValueOptBy colorBar "xanchor" StyleParam.HorizontalAlign.convert
XPad |> DynObj.setValueOpt colorBar "xpad"
XRef |> DynObj.setValueOpt colorBar "xref"
Y |> DynObj.setValueOpt colorBar "y"
YAnchor |> DynObj.setValueOptBy colorBar "yanchor" StyleParam.VerticalAlign.convert
YPad |> DynObj.setValueOpt colorBar "ypad"
YRef |> DynObj.setValueOpt colorBar "yref"

colorBar)
)
11 changes: 5 additions & 6 deletions src/Plotly.NET/CommonAbstractions/Font.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ type Font() =
[<Optional; DefaultParameterValue(null)>] ?Color: Color
) =
(fun (font: Font) ->

Family |> DynObj.setValueOptBy font "family" StyleParam.FontFamily.toString
Size |> DynObj.setValueOpt font "size"
Color |> DynObj.setValueOpt font "color"

font)
font
|> DynObj.withOptionalPropertyBy "family" Family StyleParam.FontFamily.toString
|> DynObj.withOptionalProperty "size" Size
|> DynObj.withOptionalProperty "color" Color
)
43 changes: 22 additions & 21 deletions src/Plotly.NET/CommonAbstractions/Line.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,26 @@ type Line() =
[<Optional; DefaultParameterValue(null)>] ?OutlierWidth: float
) =
(fun (line: Line) ->
BackOff |> DynObj.setValueOptBy line "backoff" StyleParam.BackOff.convert
Color |> DynObj.setValueOpt line "color"
(Width, MultiWidth) |> DynObj.setSingleOrMultiOpt line "width"
Shape |> DynObj.setValueOptBy line "shape" StyleParam.Shape.convert
Smoothing |> DynObj.setValueOpt line "smoothing"
Dash |> DynObj.setValueOptBy line "dash" StyleParam.DrawingStyle.convert
OutlierColor |> DynObj.setValueOpt line "outliercolor"
OutlierWidth |> DynObj.setValueOpt line "outlierwidth"
AutoColorScale |> DynObj.setValueOpt line "autocolorscale"
CAuto |> DynObj.setValueOpt line "cauto"
CMax |> DynObj.setValueOpt line "cmax"
CMid |> DynObj.setValueOpt line "cmid"
CMin |> DynObj.setValueOpt line "cmin"
Color |> DynObj.setValueOpt line "color"
ColorAxis |> DynObj.setValueOptBy line "coloraxis" StyleParam.SubPlotId.convert
Colorscale |> DynObj.setValueOptBy line "colorscale" StyleParam.Colorscale.convert
ReverseScale |> DynObj.setValueOpt line "reversescale"
ShowScale |> DynObj.setValueOpt line "showscale"
ColorBar |> DynObj.setValueOpt line "colorbar"
Simplify |> DynObj.setValueOpt line "simplify"
line
|> DynObj.withOptionalPropertyBy "backoff" BackOff StyleParam.BackOff.convert
|> DynObj.withOptionalProperty "color" Color
|> DynObj.withOptionalSingleOrMultiProperty "width" (Width, MultiWidth)
|> DynObj.withOptionalPropertyBy "shape" Shape StyleParam.Shape.convert
|> DynObj.withOptionalProperty "smoothing" Smoothing
|> DynObj.withOptionalPropertyBy "dash" Dash StyleParam.DrawingStyle.convert
|> DynObj.withOptionalProperty "outliercolor" OutlierColor
|> DynObj.withOptionalProperty "outlierwidth" OutlierWidth
|> DynObj.withOptionalProperty "autocolorscale" AutoColorScale
|> DynObj.withOptionalProperty "cauto" CAuto
|> DynObj.withOptionalProperty "cmax" CMax
|> DynObj.withOptionalProperty "cmid" CMid
|> DynObj.withOptionalProperty "cmin" CMin
|> DynObj.withOptionalProperty "color" Color
|> DynObj.withOptionalPropertyBy "coloraxis" ColorAxis StyleParam.SubPlotId.convert
|> DynObj.withOptionalPropertyBy "colorscale" Colorscale StyleParam.Colorscale.convert
|> DynObj.withOptionalProperty "reversescale" ReverseScale
|> DynObj.withOptionalProperty "showscale" ShowScale
|> DynObj.withOptionalProperty "colorbar" ColorBar
|> DynObj.withOptionalProperty "simplify" Simplify

line)
)
11 changes: 6 additions & 5 deletions src/Plotly.NET/CommonAbstractions/Padding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type Padding() =
[<Optional; DefaultParameterValue(null)>] ?T: int
) =
(fun (padding: Padding) ->
B |> DynObj.setValueOpt padding "b"
L |> DynObj.setValueOpt padding "l"
R |> DynObj.setValueOpt padding "r"
T |> DynObj.setValueOpt padding "t"
padding)
padding
|> DynObj.withOptionalProperty "b" B
|> DynObj.withOptionalProperty "l" L
|> DynObj.withOptionalProperty "r" R
|> DynObj.withOptionalProperty "t" T
)
15 changes: 7 additions & 8 deletions src/Plotly.NET/CommonAbstractions/TickFormatStop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ type TickFormatStop() =
) =
(fun (tickFormatStop: TickFormatStop) ->

Enabled |> DynObj.setValueOpt tickFormatStop "enabled"
DTickRange |> DynObj.setValueOpt tickFormatStop "dtickrange"
Value |> DynObj.setValueOpt tickFormatStop "value"
Name |> DynObj.setValueOpt tickFormatStop "name"
TemplateItemName |> DynObj.setValueOpt tickFormatStop "templateitemname"


tickFormatStop)
tickFormatStop
|> DynObj.withOptionalProperty "enabled" Enabled
|> DynObj.withOptionalProperty "dtickrange" DTickRange
|> DynObj.withOptionalProperty "value" Value
|> DynObj.withOptionalProperty "name" Name
|> DynObj.withOptionalProperty "templateitemname" TemplateItemName
)
31 changes: 15 additions & 16 deletions src/Plotly.NET/CommonAbstractions/Title.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,18 @@ type Title() =
// For colorbar titles
[<Optional; DefaultParameterValue(null)>] ?Side: StyleParam.Side
) =
(fun (title: Title) ->

Text |> DynObj.setValueOpt title "text"
Font |> DynObj.setValueOpt title "font"
AutoMargin |> DynObj.setValueOpt title "automargin"
Pad |> DynObj.setValueOpt title "pad"
X |> DynObj.setValueOpt title "x"
XAnchor |> DynObj.setValueOptBy title "xanchor" StyleParam.XAnchorPosition.convert
XRef |> DynObj.setValueOpt title "xref"
Y |> DynObj.setValueOpt title "y"
YAnchor |> DynObj.setValueOptBy title "yanchor" StyleParam.YAnchorPosition.convert
YRef |> DynObj.setValueOpt title "yref"
Standoff |> DynObj.setValueOpt title "standoff"
Side |> DynObj.setValueOptBy title "side" StyleParam.Side.convert

title)
(fun (title: Title) ->
title
|> DynObj.withOptionalProperty "text" Text
|> DynObj.withOptionalProperty "font" Font
|> DynObj.withOptionalProperty "automargin" AutoMargin
|> DynObj.withOptionalProperty "pad" Pad
|> DynObj.withOptionalProperty "x" X
|> DynObj.withOptionalPropertyBy "xanchor" XAnchor StyleParam.XAnchorPosition.convert
|> DynObj.withOptionalProperty "xref" XRef
|> DynObj.withOptionalProperty "y" Y
|> DynObj.withOptionalPropertyBy "yanchor" YAnchor StyleParam.YAnchorPosition.convert
|> DynObj.withOptionalProperty "yref" YRef
|> DynObj.withOptionalProperty "standoff" Standoff
|> DynObj.withOptionalPropertyBy "side" Side StyleParam.Side.convert
)
Loading

0 comments on commit 56cc563

Please sign in to comment.