Skip to content

Commit

Permalink
port the rest of plotly.net core project to dynobj v4
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Oct 15, 2024
1 parent 5064b7b commit 831b59d
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 140 deletions.
8 changes: 4 additions & 4 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.withProperty t "colorbar"
t)
t |> DynObj.withProperty "colorbar" colorbar
)

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

// TODO: Include withLegend & withLegendStyle

Expand Down
18 changes: 9 additions & 9 deletions src/Plotly.NET/ChartAPI/Chart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Chart =
LinearAxis.init (ShowGrid = false, ShowLine = false, ShowTickLabels = false, ZeroLine = false)

let trace = Trace2D.initScatter (id)
trace.Remove("type") |> ignore
trace.RemoveProperty("type") |> ignore

GenericChart.ofTraceObject false trace
|> GenericChart.mapLayout (fun l ->
Expand Down Expand Up @@ -3228,8 +3228,8 @@ type Chart =
let allYAxes = Layout.getYAxes layout |> Seq.map fst

// remove all axes from layout. Only cartesian axis in each dimension is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allXAxes |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allYAxes |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allXAxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)
allYAxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let xAnchor, yAnchor =
if hasSharedAxes then
Expand All @@ -3252,7 +3252,7 @@ type Chart =
let allScenes = Layout.getScenes layout |> Seq.map fst

// remove all scenes from layout. Only one scene is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allScenes |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allScenes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let sceneAnchor =
StyleParam.SubPlotId.Scene(i + 1)
Expand All @@ -3270,7 +3270,7 @@ type Chart =
let allPolars = Layout.getPolars layout |> Seq.map fst

// remove all polar subplots from layout. Only one polar subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allPolars |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allPolars |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let polarAnchor =
StyleParam.SubPlotId.Polar(i + 1)
Expand All @@ -3290,7 +3290,7 @@ type Chart =
let allSmiths = Layout.getSmiths layout |> Seq.map fst

// remove all smith subplots from layout. Only one smith subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allSmiths |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allSmiths |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let polarAnchor =
StyleParam.SubPlotId.Smith(i + 1)
Expand All @@ -3309,7 +3309,7 @@ type Chart =
let allGeos = Layout.getGeos layout |> Seq.map fst

// remove all geo subplots from layout. Only one geo subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allGeos |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allGeos |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let geoAnchor =
StyleParam.SubPlotId.Geo(i + 1)
Expand All @@ -3329,7 +3329,7 @@ type Chart =
let allMapboxes = Layout.getMapboxes layout |> Seq.map fst

// remove all mapbox subplots from layout. Only one mapbox subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allMapboxes |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allMapboxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let geoAnchor =
StyleParam.SubPlotId.Geo(i + 1)
Expand All @@ -3354,7 +3354,7 @@ type Chart =
let allTernaries = Layout.getTernaries layout |> Seq.map fst

// remove all ternary subplots from layout. Only one ternary subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine.
allTernaries |> Seq.iter (fun propName -> layout.Remove(propName) |> ignore)
allTernaries |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore)

let ternaryAnchor =
StyleParam.SubPlotId.Ternary(i + 1)
Expand Down
89 changes: 39 additions & 50 deletions src/Plotly.NET/Config/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -262,57 +262,46 @@ type Config() =
) =
fun (config: Config) ->

StaticPlot |> DynObj.setOptionalProperty config "staticPlot"
TypesetMath |> DynObj.setOptionalProperty config "typesetMath"
PlotlyServerUrl |> DynObj.setOptionalProperty config "plotlyServerUrl"
Editable |> DynObj.setOptionalProperty config "editable"
Edits |> DynObj.setOptionalProperty config "edits"
EditSelection |> DynObj.setOptionalProperty config "editSelection"
Autosizable |> DynObj.setOptionalProperty config "autosizable"
Responsive |> DynObj.setOptionalProperty config "responsive"
FillFrame |> DynObj.setOptionalProperty config "fillFrame"
FrameMargins |> DynObj.setOptionalProperty config "frameMargins"
ScrollZoom |> DynObj.setOptionalPropertyBy config "scrollZoom" StyleParam.ScrollZoom.convert
DoubleClick |> DynObj.setOptionalPropertyBy config "doubleClick" StyleParam.DoubleClick.convert
DoubleClickDelay |> DynObj.setOptionalProperty config "doubleClickDelay"
ShowAxisDragHandles |> DynObj.setOptionalProperty config "showAxisDragHandles"
ShowAxisRangeEntryBoxes |> DynObj.setOptionalProperty config "showAxisRangeEntryBoxes"
ShowTips |> DynObj.setOptionalProperty config "showTips"
ShowLink |> DynObj.setOptionalProperty config "showLink"
LinkText |> DynObj.setOptionalProperty config "linkText"
SendData |> DynObj.setOptionalProperty config "sendData"
ShowSources |> DynObj.setOptionalProperty config "showSources"
DisplayModeBar |> DynObj.setOptionalProperty config "displayModeBar"
ShowSendToCloud |> DynObj.setOptionalProperty config "showSendToCloud"
ShowEditInChartStudio |> DynObj.setOptionalProperty config "showEditInChartStudio"

ModeBarButtonsToRemove
|> DynObj.setOptionalPropertyBy config "modeBarButtonsToRemove" (fun x ->
x |> Seq.map StyleParam.ModeBarButton.toString)

ModeBarButtonsToAdd
|> DynObj.setOptionalPropertyBy config "modeBarButtonsToAdd" (fun x ->
x |> Seq.map StyleParam.ModeBarButton.toString)

ModeBarButtons
|> DynObj.setOptionalPropertyBy config "modeBarButtons" (fun x ->
x |> Seq.map (Seq.map StyleParam.ModeBarButton.toString))

ToImageButtonOptions |> DynObj.setOptionalProperty config "toImageButtonOptions"
Displaylogo |> DynObj.setOptionalProperty config "displaylogo"
Watermark |> DynObj.setOptionalProperty config "watermark"
plotGlPixelRatio |> DynObj.setOptionalProperty config "plotGlPixelRatio"
SetBackground |> DynObj.setOptionalProperty config "setBackground"
TopojsonURL |> DynObj.setOptionalProperty config "topojsonURL"
MapboxAccessToken |> DynObj.setOptionalProperty config "mapboxAccessToken"
Logging |> DynObj.setOptionalProperty config "logging"
NotifyOnLogging |> DynObj.setOptionalProperty config "notifyOnLogging"
QueueLength |> DynObj.setOptionalProperty config "queueLength"
GlobalTransforms |> DynObj.setOptionalProperty config "globalTransforms"
Locale |> DynObj.setOptionalProperty config "locale"
Locales |> DynObj.setOptionalProperty config "locales"

config
|> DynObj.withOptionalProperty "staticPlot" StaticPlot
|> DynObj.withOptionalProperty "typesetMath" TypesetMath
|> DynObj.withOptionalProperty "plotlyServerUrl" PlotlyServerUrl
|> DynObj.withOptionalProperty "editable" Editable
|> DynObj.withOptionalProperty "edits" Edits
|> DynObj.withOptionalProperty "editSelection" EditSelection
|> DynObj.withOptionalProperty "autosizable" Autosizable
|> DynObj.withOptionalProperty "responsive" Responsive
|> DynObj.withOptionalProperty "fillFrame" FillFrame
|> DynObj.withOptionalProperty "frameMargins" FrameMargins
|> DynObj.withOptionalPropertyBy "scrollZoom" ScrollZoom StyleParam.ScrollZoom.convert
|> DynObj.withOptionalPropertyBy "doubleClick" DoubleClick StyleParam.DoubleClick.convert
|> DynObj.withOptionalProperty "doubleClickDelay" DoubleClickDelay
|> DynObj.withOptionalProperty "showAxisDragHandles" ShowAxisDragHandles
|> DynObj.withOptionalProperty "showAxisRangeEntryBoxes"ShowAxisRangeEntryBoxes
|> DynObj.withOptionalProperty "showTips" ShowTips
|> DynObj.withOptionalProperty "showLink" ShowLink
|> DynObj.withOptionalProperty "linkText" LinkText
|> DynObj.withOptionalProperty "sendData" SendData
|> DynObj.withOptionalProperty "showSources" ShowSources
|> DynObj.withOptionalProperty "displayModeBar" DisplayModeBar
|> DynObj.withOptionalProperty "showSendToCloud" ShowSendToCloud
|> DynObj.withOptionalProperty "showEditInChartStudio" ShowEditInChartStudio
|> DynObj.withOptionalPropertyBy "modeBarButtonsToRemove" ModeBarButtonsToRemove (fun x -> x |> Seq.map StyleParam.ModeBarButton.toString)
|> DynObj.withOptionalPropertyBy "modeBarButtonsToAdd" ModeBarButtonsToAdd (fun x -> x |> Seq.map StyleParam.ModeBarButton.toString)
|> DynObj.withOptionalPropertyBy "modeBarButtons" ModeBarButtons (fun x -> x |> Seq.map (Seq.map StyleParam.ModeBarButton.toString))
|> DynObj.withOptionalProperty "toImageButtonOptions" ToImageButtonOptions
|> DynObj.withOptionalProperty "displaylogo" Displaylogo
|> DynObj.withOptionalProperty "watermark" Watermark
|> DynObj.withOptionalProperty "plotGlPixelRatio" plotGlPixelRatio
|> DynObj.withOptionalProperty "setBackground" SetBackground
|> DynObj.withOptionalProperty "topojsonURL" TopojsonURL
|> DynObj.withOptionalProperty "mapboxAccessToken" MapboxAccessToken
|> DynObj.withOptionalProperty "logging" Logging
|> DynObj.withOptionalProperty "notifyOnLogging" NotifyOnLogging
|> DynObj.withOptionalProperty "queueLength" QueueLength
|> DynObj.withOptionalProperty "globalTransforms" GlobalTransforms
|> DynObj.withOptionalProperty "locale" Locale
|> DynObj.withOptionalProperty "locales" Locales

/// <summary>
/// Combines two Config objects.
Expand Down
21 changes: 10 additions & 11 deletions src/Plotly.NET/Config/ObjectAbstractions/Edits.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ type Edits() =
[<Optional; DefaultParameterValue(null)>] ?TitleText: bool
) =
fun (edits: Edits) ->
AnnotationPosition |> DynObj.setOptionalProperty edits "annotationPosition"
AnnotationTail |> DynObj.setOptionalProperty edits "annotationTail"
AnnotationText |> DynObj.setOptionalProperty edits "annotationText"
AxisTitleText |> DynObj.setOptionalProperty edits "axisTitleText"
ColorbarPosition |> DynObj.setOptionalProperty edits "colorbarPosition"
ColorbarTitleText |> DynObj.setOptionalProperty edits "colorbarTitleText"
LegendPosition |> DynObj.setOptionalProperty edits "legendPosition"
LegendText |> DynObj.setOptionalProperty edits "legendText"
ShapePosition |> DynObj.setOptionalProperty edits "shapePosition"
TitleText |> DynObj.setOptionalProperty edits "titleText"

edits
|> DynObj.withOptionalProperty "annotationPosition" AnnotationPosition
|> DynObj.withOptionalProperty "annotationTail" AnnotationTail
|> DynObj.withOptionalProperty "annotationText" AnnotationText
|> DynObj.withOptionalProperty "axisTitleText" AxisTitleText
|> DynObj.withOptionalProperty "colorbarPosition" ColorbarPosition
|> DynObj.withOptionalProperty "colorbarTitleText" ColorbarTitleText
|> DynObj.withOptionalProperty "legendPosition" LegendPosition
|> DynObj.withOptionalProperty "legendText" LegendText
|> DynObj.withOptionalProperty "shapePosition" ShapePosition
|> DynObj.withOptionalProperty "titleText" TitleText
10 changes: 5 additions & 5 deletions src/Plotly.NET/Config/ObjectAbstractions/ToImageButtonOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type ToImageButtonOptions() =
[<Optional; DefaultParameterValue(null)>] ?Scale
) =
fun (btnConf: ToImageButtonOptions) ->
Format |> Option.map StyleParam.ImageFormat.toString |> DynObj.setOptionalProperty btnConf "format"
Filename |> DynObj.setOptionalProperty btnConf "filename"
Width |> DynObj.setOptionalProperty btnConf "width"
Height |> DynObj.setOptionalProperty btnConf "height"
Scale |> DynObj.setOptionalProperty btnConf "scale"
btnConf
|> DynObj.withOptionalPropertyBy "format" Format StyleParam.ImageFormat.toString
|> DynObj.withOptionalProperty "filename" Filename
|> DynObj.withOptionalProperty "width" Width
|> DynObj.withOptionalProperty "height" Height
|> DynObj.withOptionalProperty "scale" Scale
1 change: 0 additions & 1 deletion src/Plotly.NET/Defaults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Plotly.NET
open Plotly.NET.LayoutObjects

open DynamicObj
open DynamicObj.Operators
open System.Runtime.InteropServices

open Giraffe.ViewEngine
Expand Down
Loading

0 comments on commit 831b59d

Please sign in to comment.