Skip to content

Commit 508a3fb

Browse files
committed
Fix #165: Add Extend Dragmode and add ModeBarButton options to config
1 parent a51ffb1 commit 508a3fb

5 files changed

Lines changed: 233 additions & 73 deletions

File tree

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,32 @@ module StyleParam =
538538
/// default drag mode is 'rotate' which rotates the scene.
539539
[<RequireQualifiedAccess>]
540540
type DragMode =
541-
| Zoom | Pan | Rotate
542-
543-
static member toString = function
544-
| Zoom -> "zoom"
545-
| Pan -> "pan"
546-
| Rotate -> "rotate"
541+
| Zoom
542+
| Pan
543+
| Select
544+
| Lasso
545+
| DrawClosedPath
546+
| DrawOpenPath
547+
| DrawLine
548+
| DrawRect
549+
| DrawCircle
550+
| Orbit
551+
| TurnTable
552+
| False
553+
554+
static member toString = function
555+
| Zoom -> "zoom"
556+
| Pan -> "pan"
557+
| Select -> "select"
558+
| Lasso -> "lasso"
559+
| DrawClosedPath -> "drawclosedpath"
560+
| DrawOpenPath -> "drawopenpath"
561+
| DrawLine -> "drawline"
562+
| DrawRect -> "drawrect"
563+
| DrawCircle -> "drawcircle"
564+
| Orbit -> "orbit"
565+
| TurnTable -> "turntable"
566+
| False -> "False"
547567

548568
static member convert = DragMode.toString >> box
549569
override this.ToString() = this |> DragMode.toString
@@ -1123,6 +1143,96 @@ module StyleParam =
11231143
//--------------------------
11241144
// #M#
11251145
//--------------------------
1146+
1147+
[<RequireQualifiedAccess>]
1148+
type ModeBarButton =
1149+
1150+
| ToImage
1151+
| SendDataToCloud
1152+
| EditInChartStudio
1153+
| Zoom2d
1154+
| Pan2d
1155+
| Select2d
1156+
| Lasso2d
1157+
| DrawClosedPath
1158+
| DrawOpenPath
1159+
| DrawLine
1160+
| DrawRect
1161+
| DrawCircle
1162+
| EraseShape
1163+
| ZoomIn2d
1164+
| ZoomOut2d
1165+
| AutoScale2d
1166+
| ResetScale2d
1167+
| HoverClosestCartesian
1168+
| HoverCompareCartesian
1169+
| Zoom3d
1170+
| Pan3d
1171+
| OrbitRotation
1172+
| TableRotation
1173+
| ResetCameraDefault3d
1174+
| ResetCameraLastSave3d
1175+
| HoverClosest3d
1176+
| ZoomInGeo
1177+
| ZoomOutGeo
1178+
| ResetGeo
1179+
| HoverClosestGeo
1180+
| HoverClosestGl2d
1181+
| HoverClosestPie
1182+
| ResetSankeyGroup
1183+
| ToggleHover
1184+
| ResetViews
1185+
| ToggleSpikelines
1186+
| ResetViewMapbox
1187+
| ZoomInMapbox
1188+
| ZoomOutMapbox
1189+
1190+
static member toString = function
1191+
1192+
| ToImage -> "toImage"
1193+
| SendDataToCloud -> "sendDataToCloud"
1194+
| EditInChartStudio -> "editInChartStudio"
1195+
| Zoom2d -> "zoom2d"
1196+
| Pan2d -> "pan2d"
1197+
| Select2d -> "select2d"
1198+
| Lasso2d -> "lasso2d"
1199+
| DrawClosedPath -> "drawclosedpath"
1200+
| DrawOpenPath -> "drawopenpath"
1201+
| DrawLine -> "drawline"
1202+
| DrawRect -> "drawrect"
1203+
| DrawCircle -> "drawcircle"
1204+
| EraseShape -> "eraseshape"
1205+
| ZoomIn2d -> "zoomIn2d"
1206+
| ZoomOut2d -> "zoomOut2d"
1207+
| AutoScale2d -> "autoScale2d"
1208+
| ResetScale2d -> "resetScale2d"
1209+
| HoverClosestCartesian -> "hoverClosestCartesian"
1210+
| HoverCompareCartesian -> "hoverCompareCartesian"
1211+
| Zoom3d -> "zoom3d"
1212+
| Pan3d -> "pan3d"
1213+
| OrbitRotation -> "orbitRotation"
1214+
| TableRotation -> "tableRotation"
1215+
| ResetCameraDefault3d -> "resetCameraDefault3d"
1216+
| ResetCameraLastSave3d -> "resetCameraLastSave3d"
1217+
| HoverClosest3d -> "hoverClosest3d"
1218+
| ZoomInGeo -> "zoomInGeo"
1219+
| ZoomOutGeo -> "zoomOutGeo"
1220+
| ResetGeo -> "resetGeo"
1221+
| HoverClosestGeo -> "hoverClosestGeo"
1222+
| HoverClosestGl2d -> "hoverClosestGl2d"
1223+
| HoverClosestPie -> "hoverClosestPie"
1224+
| ResetSankeyGroup -> "resetSankeyGroup"
1225+
| ToggleHover -> "toggleHover"
1226+
| ResetViews -> "resetViews"
1227+
| ToggleSpikelines -> "toggleSpikelines"
1228+
| ResetViewMapbox -> "resetViewMapbox"
1229+
| ZoomInMapbox -> "zoomInMapbox"
1230+
| ZoomOutMapbox -> "zoomOutMapbox"
1231+
1232+
1233+
static member convert = ModeBarButton.toString >> box
1234+
override this.ToString() = this |> ModeBarButton.toString
1235+
member this.Convert() = this |> ModeBarButton.convert
11261236

11271237
/// Determines if the axis lines or/and ticks are mirrored to the opposite side of the plotting area. If "true", the axis lines are mirrored.
11281238
/// If "ticks", the axis lines and ticks are mirrored. If "false", mirroring is disable. If "all", axis lines are mirrored on all shared-axes subplots. If "allticks", axis lines and ticks are mirrored on all shared-axes subplots.

src/Plotly.NET/Config/Config.fs

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
namespace Plotly.NET
22

3+
open Plotly.NET.ConfigObjects
34
open DynamicObj
45
open System.Runtime.InteropServices
56

6-
// missing config props:
7+
//missing:
78

9+
//var configAttributes = {
10+
// plotlyServerURL: {
11+
// valType: 'string',
12+
// dflt: '',
13+
// description: [
14+
// 'When set it determines base URL for',
15+
// 'the \'Edit in Chart Studio\' `showEditInChartStudio`/`showSendToCloud` mode bar button',
16+
// 'and the showLink/sendData on-graph link.',
17+
// 'To enable sending your data to Chart Studio Cloud, you need to',
18+
// 'set both `plotlyServerURL` to \'https://chart-studio.plotly.com\' and',
19+
// 'also set `showSendToCloud` to true.'
20+
// ].join(' ')
21+
// },
822
// fillFrame: {
923
// valType: 'boolean',
1024
// dflt: false,
@@ -94,7 +108,7 @@ open System.Runtime.InteropServices
94108
// valType: 'boolean',
95109
// dflt: false,
96110
// description: [
97-
// 'Determines whether a link to plot.ly is displayed',
111+
// 'Determines whether a link to Chart Studio Cloud is displayed',
98112
// 'at the bottom right corner of resulting graphs.',
99113
// 'Use with `sendData` and `linkText`.'
100114
// ].join(' ')
@@ -112,7 +126,7 @@ open System.Runtime.InteropServices
112126
// dflt: true,
113127
// description: [
114128
// 'If *showLink* is true, does it contain data',
115-
// 'just link to a plot.ly file?'
129+
// 'just link to a Chart Studio Cloud file?'
116130
// ].join(' ')
117131
// },
118132
// showSources: {
@@ -141,10 +155,10 @@ open System.Runtime.InteropServices
141155
// dflt: false,
142156
// description: [
143157
// 'Should we include a ModeBar button, labeled "Edit in Chart Studio",',
144-
// 'that sends this chart to plot.ly or another plotly server as specified',
145-
// 'by `plotlyServerURL` for editing, export, etc? Prior to version 1.43.0',
158+
// 'that sends this chart to chart-studio.plotly.com (formerly plot.ly) or another plotly server',
159+
// 'as specified by `plotlyServerURL` for editing, export, etc? Prior to version 1.43.0',
146160
// 'this button was included by default, now it is opt-in using this flag.',
147-
// 'Note that this button can (depending on `plotlyServerURL`) send your data',
161+
// 'Note that this button can (depending on `plotlyServerURL` being set) send your data',
148162
// 'to an external server. However that server does not persist your data',
149163
// 'until you arrive at the Chart Studio and explicitly click "Save".'
150164
// ].join(' ')
@@ -166,14 +180,6 @@ open System.Runtime.InteropServices
166180
// 'See ./components/modebar/buttons.js for the list of names.'
167181
// ].join(' ')
168182
// },
169-
// modeBarButtonsToAdd: {
170-
// valType: 'any',
171-
// dflt: [],
172-
// description: [
173-
// 'Add mode bar button using config objects',
174-
// 'See ./components/modebar/buttons.js for list of arguments.'
175-
// ].join(' ')
176-
// },
177183
// modeBarButtons: {
178184
// valType: 'any',
179185
// dflt: false,
@@ -184,15 +190,6 @@ open System.Runtime.InteropServices
184190
// 'See ./components/modebar/buttons.js for more info.'
185191
// ].join(' ')
186192
// },
187-
// toImageButtonOptions: {
188-
// valType: 'any',
189-
// dflt: {},
190-
// description: [
191-
// 'Statically override options for toImage modebar button',
192-
// 'allowed keys are format, filename, width, height, scale',
193-
// 'see ../components/modebar/buttons.js'
194-
// ].join(' ')
195-
// },
196193
// displaylogo: {
197194
// valType: 'boolean',
198195
// dflt: true,
@@ -256,7 +253,9 @@ open System.Runtime.InteropServices
256253
// },
257254

258255
// logging: {
259-
// valType: 'boolean',
256+
// valType: 'integer',
257+
// min: 0,
258+
// max: 2,
260259
// dflt: 1,
261260
// description: [
262261
// 'Turn all console logging on or off (errors will be thrown)',
@@ -268,6 +267,21 @@ open System.Runtime.InteropServices
268267
// ].join(' ')
269268
// },
270269

270+
// notifyOnLogging: {
271+
// valType: 'integer',
272+
// min: 0,
273+
// max: 2,
274+
// dflt: 0,
275+
// description: [
276+
// 'Set on-graph logging (notifier) level',
277+
// 'This should ONLY be set via Plotly.setPlotConfig',
278+
// 'Available levels:',
279+
// '0: no on-graph logs',
280+
// '1: warnings and errors, but not informational messages',
281+
// '2: verbose logs'
282+
// ].join(' ')
283+
// },
284+
271285
// queueLength: {
272286
// valType: 'integer',
273287
// min: 0,
@@ -319,42 +333,6 @@ open System.Runtime.InteropServices
319333
// ].join(' ')
320334
// }
321335
//};
322-
323-
type ToImageButtonOptions() =
324-
inherit DynamicObj()
325-
static member init
326-
(
327-
[<Optional;DefaultParameterValue(null)>] ?Format : StyleParam.ImageFormat,
328-
[<Optional;DefaultParameterValue(null)>] ?Filename : string,
329-
[<Optional;DefaultParameterValue(null)>] ?Width : float,
330-
[<Optional;DefaultParameterValue(null)>] ?Height : float,
331-
[<Optional;DefaultParameterValue(null)>] ?Scale : float
332-
) =
333-
ToImageButtonOptions()
334-
|> ToImageButtonOptions.style
335-
(
336-
?Format = Format ,
337-
?Filename = Filename,
338-
?Width = Width ,
339-
?Height = Height ,
340-
?Scale = Scale
341-
)
342-
343-
static member style
344-
(
345-
[<Optional;DefaultParameterValue(null)>] ?Format,
346-
[<Optional;DefaultParameterValue(null)>] ?Filename,
347-
[<Optional;DefaultParameterValue(null)>] ?Width,
348-
[<Optional;DefaultParameterValue(null)>] ?Height,
349-
[<Optional;DefaultParameterValue(null)>] ?Scale
350-
) =
351-
fun (btnConf:ToImageButtonOptions) ->
352-
Format |> Option.map StyleParam.ImageFormat.toString |> DynObj.setValueOpt btnConf "format"
353-
Filename |> DynObj.setValueOpt btnConf "filename"
354-
Width |> DynObj.setValueOpt btnConf "width"
355-
Height |> DynObj.setValueOpt btnConf "height"
356-
Scale |> DynObj.setValueOpt btnConf "scale"
357-
btnConf
358336
/// Config
359337
type Config() =
360338
inherit DynamicObj ()
@@ -368,7 +346,8 @@ type Config() =
368346
[<Optional;DefaultParameterValue(null)>] ?ShowEditInChartStudio : bool,
369347
[<Optional;DefaultParameterValue(null)>] ?ToImageButtonOptions : ToImageButtonOptions,
370348
[<Optional;DefaultParameterValue(null)>] ?Editable : bool,
371-
[<Optional;DefaultParameterValue(null)>] ?EditableAnnotations : seq<StyleParam.AnnotationEditOptions>
349+
[<Optional;DefaultParameterValue(null)>] ?EditableAnnotations : seq<StyleParam.AnnotationEditOptions>,
350+
[<Optional;DefaultParameterValue(null)>] ?ModeBarButtonsToAdd : seq<StyleParam.ModeBarButton>
372351
) =
373352
Config()
374353
|> Config.style
@@ -379,7 +358,8 @@ type Config() =
379358
?ToImageButtonOptions = ToImageButtonOptions,
380359
?ShowEditInChartStudio = ShowEditInChartStudio,
381360
?Editable = Editable,
382-
?EditableAnnotations = EditableAnnotations
361+
?EditableAnnotations = EditableAnnotations,
362+
?ModeBarButtonsToAdd = ModeBarButtonsToAdd
383363
)
384364

385365

@@ -394,7 +374,8 @@ type Config() =
394374
[<Optional;DefaultParameterValue(null)>] ?ToImageButtonOptions : ToImageButtonOptions,
395375
[<Optional;DefaultParameterValue(null)>] ?ShowEditInChartStudio : bool,
396376
[<Optional;DefaultParameterValue(null)>] ?Editable : bool,
397-
[<Optional;DefaultParameterValue(null)>] ?EditableAnnotations : seq<StyleParam.AnnotationEditOptions>
377+
[<Optional;DefaultParameterValue(null)>] ?EditableAnnotations : seq<StyleParam.AnnotationEditOptions>,
378+
[<Optional;DefaultParameterValue(null)>] ?ModeBarButtonsToAdd : seq<StyleParam.ModeBarButton>
398379

399380
) =
400381
fun (config:Config) ->
@@ -404,6 +385,7 @@ type Config() =
404385
ToImageButtonOptions |> DynObj.setValueOpt config "toImageButtonOptions"
405386
ShowEditInChartStudio |> DynObj.setValueOpt config "showEditInChartStudio"
406387
Editable |> DynObj.setValueOpt config "editable"
388+
ModeBarButtonsToAdd |> DynObj.setValueOptBy config "modeBarButtonsToAdd" (fun x -> x |> Seq.map StyleParam.ModeBarButton.convert)
407389
EditableAnnotations
408390
|> Option.map
409391
(fun edits ->
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace Plotly.NET.ConfigObjects
2+
3+
open Plotly.NET
4+
open Plotly.NET.LayoutObjects
5+
open DynamicObj
6+
open System
7+
open System.Runtime.InteropServices
8+
9+
type ToImageButtonOptions() =
10+
inherit DynamicObj()
11+
static member init
12+
(
13+
[<Optional;DefaultParameterValue(null)>] ?Format : StyleParam.ImageFormat,
14+
[<Optional;DefaultParameterValue(null)>] ?Filename : string,
15+
[<Optional;DefaultParameterValue(null)>] ?Width : float,
16+
[<Optional;DefaultParameterValue(null)>] ?Height : float,
17+
[<Optional;DefaultParameterValue(null)>] ?Scale : float
18+
) =
19+
ToImageButtonOptions()
20+
|> ToImageButtonOptions.style
21+
(
22+
?Format = Format ,
23+
?Filename = Filename,
24+
?Width = Width ,
25+
?Height = Height ,
26+
?Scale = Scale
27+
)
28+
29+
static member style
30+
(
31+
[<Optional;DefaultParameterValue(null)>] ?Format,
32+
[<Optional;DefaultParameterValue(null)>] ?Filename,
33+
[<Optional;DefaultParameterValue(null)>] ?Width,
34+
[<Optional;DefaultParameterValue(null)>] ?Height,
35+
[<Optional;DefaultParameterValue(null)>] ?Scale
36+
) =
37+
fun (btnConf:ToImageButtonOptions) ->
38+
Format |> Option.map StyleParam.ImageFormat.toString |> DynObj.setValueOpt btnConf "format"
39+
Filename |> DynObj.setValueOpt btnConf "filename"
40+
Width |> DynObj.setValueOpt btnConf "width"
41+
Height |> DynObj.setValueOpt btnConf "height"
42+
Scale |> DynObj.setValueOpt btnConf "scale"
43+
btnConf

0 commit comments

Comments
 (0)