-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLayout.fs
More file actions
501 lines (443 loc) · 22.5 KB
/
Copy pathLayout.fs
File metadata and controls
501 lines (443 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
namespace SigmaGraph.NET
open DynamicObj
open Newtonsoft.Json
// adjustSizes ?boolean false: should the node’s sizes be taken into account?
// barnesHutOptimize ?boolean false: whether to use the Barnes-Hut approximation to compute repulsion in O(n*log(n)) rather than default O(n^2), n being the number of nodes.
// barnesHutTheta ?number 0.5: Barnes-Hut approximation theta parameter.
// edgeWeightInfluence ?number 1: influence of the edge’s weights on the layout. To consider edge weight, don’t forget to pass weighted as true when applying the synchronous layout or when instantiating the worker.
// gravity ?number 1: strength of the layout’s gravity.
// linLogMode ?boolean false: whether to use Noack’s LinLog model.
// outboundAttractionDistribution ?boolean false
// scalingRatio ?number 1
// slowDown ?number 1
// strongGravityMode ?boolean false
/// <summary>
/// FA2Settings type for configuring the Force Atlas 2 algorithm settings.
/// </summary>
type FA2Settings() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of FA2Settings with optional parameters.
/// </summary>
/// <param name="AdjustSizes">Optional boolean to indicate if node sizes should be considered.</param>
/// <param name="BarnesHutOptimize">Optional boolean to use Barnes-Hut approximation for repulsion calculation.</param>
/// <param name="BarnesHutTheta">Optional float to set the Barnes-Hut approximation theta parameter.</param>
/// <param name="EdgeWeightInfluence">Optional integer to specify the influence of edge weights on the layout.</param>
/// <param name="Gravity">Optional integer to set the strength of the layout’s gravity.</param>
/// <param name="LinLogMode">Optional boolean to use Noack’s LinLog model.</param>
/// <param name="OutboundAttractionDistribution">Optional boolean to control outbound attraction distribution.</param>
/// <param name="ScalingRatio">Optional integer to set the scaling ratio.</param>
/// <param name="SlowDown">Optional integer to set the dampening factor for slowing down node movements.</param>
/// <param name="StrongGravityMode">Optional boolean to enable strong gravity mode.</param>
static member Init
(
?AdjustSizes : bool,
?BarnesHutOptimize : bool,
?BarnesHutTheta : float,
?EdgeWeightInfluence : int,
?Gravity : int,
?LinLogMode : bool,
?OutboundAttractionDistribution : bool,
?ScalingRatio : int,
?SlowDown : int,
?StrongGravityMode : bool
) =
FA2Settings()
|> FA2Settings.Style
(
?AdjustSizes = AdjustSizes,
?BarnesHutOptimize = BarnesHutOptimize,
?BarnesHutTheta = BarnesHutTheta,
?EdgeWeightInfluence = EdgeWeightInfluence,
?Gravity = Gravity,
?LinLogMode = LinLogMode,
?OutboundAttractionDistribution = OutboundAttractionDistribution,
?ScalingRatio = ScalingRatio,
?SlowDown = SlowDown,
?StrongGravityMode = StrongGravityMode
)
// Applies updates to FA2Settings()
/// <summary>
/// Applies updates to the FA2Settings instance based on the optional parameters.
/// </summary>
/// <param name="AdjustSizes">Optional boolean to indicate if node sizes should be considered.</param>
/// <param name="BarnesHutOptimize">Optional boolean to use Barnes-Hut approximation for repulsion calculation.</param>
/// <param name="BarnesHutTheta">Optional float to set the Barnes-Hut approximation theta parameter.</param>
/// <param name="EdgeWeightInfluence">Optional integer to specify the influence of edge weights on the layout.</param>
/// <param name="Gravity">Optional integer to set the strength of the layout’s gravity.</param>
/// <param name="LinLogMode">Optional boolean to use Noack’s LinLog model.</param>
/// <param name="OutboundAttractionDistribution">Optional boolean to control outbound attraction distribution.</param>
/// <param name="ScalingRatio">Optional integer to set the scaling ratio.</param>
/// <param name="SlowDown">Optional integer to set the dampening factor for slowing down node movements.</param>
/// <param name="StrongGravityMode">Optional boolean to enable strong gravity mode.</param>
static member Style
(
?AdjustSizes,
?BarnesHutOptimize,
?BarnesHutTheta,
?EdgeWeightInfluence,
?Gravity,
?LinLogMode,
?OutboundAttractionDistribution,
?ScalingRatio,
?SlowDown,
?StrongGravityMode
) =
(fun (opt:FA2Settings) ->
opt |> DynObj.setOptionalProperty "barnesHutOptimize" BarnesHutOptimize
opt |> DynObj.setOptionalProperty "barnesHutTheta" BarnesHutTheta
opt |> DynObj.setOptionalProperty "edgeWeightInfluence" EdgeWeightInfluence
opt |> DynObj.setOptionalProperty "gravity" Gravity
opt |> DynObj.setOptionalProperty "linLogMode" LinLogMode
opt |> DynObj.setOptionalProperty "outboundAttractionDistribution" OutboundAttractionDistribution
opt |> DynObj.setOptionalProperty "scalingRatio" ScalingRatio
opt |> DynObj.setOptionalProperty "slowDown" SlowDown
opt |> DynObj.setOptionalProperty "strongGravityMode" StrongGravityMode
// out ->
opt
)
//gridSize ?number 20: number of grid cells horizontally and vertically subdivising the graph’s space. This is used as an optimization scheme. Set it to 1 and you will have O(n²) time complexity, which can sometimes perform better with very few nodes.
//margin ?number 5: margin to keep between nodes.
//expansion ?number 1.1: percentage of current space that nodes could attempt to move outside of.
//ratio ?number 1.0: ratio scaling node sizes.
//speed ?number 3: dampening factor that will slow down node movements to ease the overall process.
/// <summary>
/// NoverlapSettings type for configuring the Noverlap algorithm settings.
/// </summary>
type NoverlapSettings() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of NoverlapSettings with optional parameters.
/// </summary>
/// <param name="GridSize">Optional integer specifying the number of grid cells horizontally and vertically.</param>
/// <param name="Margin">Optional integer to set the margin between nodes.</param>
/// <param name="Expansion">Optional float to specify the percentage of space nodes could move outside of.</param>
/// <param name="Ratio">Optional float to set the scaling ratio for node sizes.</param>
/// <param name="Speed">Optional integer to set the dampening factor for slowing down node movements.</param>
static member Init
(
?GridSize : int,
?Margin : int,
?Expansion : float,
?Ratio : float,
?Speed : int
) =
NoverlapSettings()
|> NoverlapSettings.Style
(
?GridSize = GridSize,
?Margin = Margin,
?Expansion = Expansion,
?Ratio = Ratio,
?Speed = Speed
)
// Applies updates to NoverlapSettings()
/// <summary>
/// Applies updates to the NoverlapSettings instance based on the optional parameters.
/// </summary>
/// <param name="GridSize">Optional integer specifying the number of grid cells horizontally and vertically.</param>
/// <param name="Margin">Optional integer to set the margin between nodes.</param>
/// <param name="Expansion">Optional float to specify the percentage of space nodes could move outside of.</param>
/// <param name="Ratio">Optional float to set the scaling ratio for node sizes.</param>
/// <param name="Speed">Optional integer to set the dampening factor for slowing down node movements.</param>
static member Style
(
?GridSize,
?Margin,
?Expansion,
?Ratio,
?Speed
) =
(fun (opt:NoverlapSettings) ->
opt |> DynObj.setOptionalProperty "gridSize" GridSize
opt |> DynObj.setOptionalProperty "margin" Margin
opt |> DynObj.setOptionalProperty "expansion" Expansion
opt |> DynObj.setOptionalProperty "ratio" Ratio
opt |> DynObj.setOptionalProperty "speed" Speed
// out ->
opt
)
//iterations number: number of iterations to perform.
//getEdgeWeight ?string|function weight: name of the edge weight attribute or getter function. Defaults to weight.
//settings ?object: the layout’s settings (see #settings).
/// <summary>
/// FA2Options type for configuring the Force Atlas 2 layout options.
/// </summary>
type FA2Options() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of FA2Options with optional parameters.
/// </summary>
/// <param name="Iterations">Optional integer to specify the number of iterations to perform.</param>
/// <param name="GetEdgeWeight">Optional string specifying the edge weight attribute or a getter function.</param>
/// <param name="Settings">Optional FA2Settings to configure the Force Atlas 2 algorithm settings.</param>
static member Init
(
?Iterations : int,
?GetEdgeWeight : string,
?Settings : FA2Settings
) =
FA2Options()
|> FA2Options.Style
(
?Iterations = Iterations,
?GetEdgeWeight = GetEdgeWeight,
?Settings = Settings
)
// Applies updates to FA2Options()
/// <summary>
/// Applies updates to the FA2Options instance based on the optional parameters.
/// </summary>
/// <param name="Iterations">Optional integer to specify the number of iterations to perform.</param>
/// <param name="GetEdgeWeight">Optional string specifying the edge weight attribute or a getter function.</param>
/// <param name="Settings">Optional FA2Settings to configure the Force Atlas 2 algorithm settings.</param>
static member Style
(
?Iterations,
?GetEdgeWeight,
?Settings
) =
(fun (opt:FA2Options) ->
opt|> DynObj.setOptionalProperty "iterations" Iterations
opt|> DynObj.setOptionalProperty "getEdgeWeight" GetEdgeWeight
opt|> DynObj.setOptionalProperty "settings" Settings
// out ->
opt
)
//maxIterations ?number 500: maximum number of iterations to perform before stopping. Note that the algorithm will also stop as soon as converged.
//inputReducer ?function: a function reducing each node attributes. This can be useful if the rendered positions/sizes of your graph are stored outside of the graph’s data. This is the case when using sigma.js for instance.
//outputReducer ?function: a function reducing node positions as computed by the layout algorithm. This can be useful to map back to a previous coordinates system. This is the case when using sigma.js for instance.
//settings ?object: the layout’s settings (see #settings).
/// <summary>
/// NoverlapOptions type for configuring the Noverlap layout options.
/// </summary>
type NoverlapOptions() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of NoverlapOptions with optional parameters.
/// </summary>
/// <param name="MaxIterations">Optional integer to specify the maximum number of iterations before stopping.</param>
/// <param name="InputReducer">Optional string specifying the function to reduce each node’s attributes.</param>
/// <param name="OutputReducer">Optional string specifying the function to reduce node positions as computed by the layout algorithm.</param>
/// <param name="Settings">Optional NoverlapSettings to configure the Noverlap algorithm settings.</param>
static member Init
(
?MaxIterations : int,
?InputReducer : string,
?OutputReducer : string,
?Settings : NoverlapSettings
) =
NoverlapOptions()
|> NoverlapOptions.Style
(
?MaxIterations = MaxIterations,
?InputReducer = InputReducer,
?OutputReducer = OutputReducer,
?Settings = Settings
)
// Applies updates to NoverlapOptions()
/// <summary>
/// Applies updates to the NoverlapOptions instance based on the optional parameters.
/// </summary>
/// <param name="MaxIterations">Optional integer to specify the maximum number of iterations before stopping.</param>
/// <param name="InputReducer">Optional string specifying the function to reduce each node’s attributes.</param>
/// <param name="OutputReducer">Optional string specifying the function to reduce node positions as computed by the layout algorithm.</param>
/// <param name="Settings">Optional NoverlapSettings to configure the Noverlap algorithm settings.</param>
static member Style
(
?MaxIterations,
?InputReducer,
?OutputReducer,
?Settings
) =
(fun (opt:NoverlapOptions) ->
opt|> DynObj.setOptionalProperty "maxIterations" MaxIterations
opt|> DynObj.setOptionalProperty "inputReducer" InputReducer
opt|> DynObj.setOptionalProperty "outputReducer" OutputReducer
opt|> DynObj.setOptionalProperty "settings" Settings
// out ->
opt
)
//dimensions ?array [‘x’, ‘y’]: dimensions of the layout. Cannot work with dimensions != 2.
//center ?number 0.5: center of the layout.
//scale ?number 1: scale of the layout.
/// <summary>
/// CircularOptions type for configuring the Circular layout options
/// </summary>
type CircularOptions() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of CircularOptions with optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions of the layout.</param>
/// <param name="Center">Optional float to set the center of the layout.</param>
/// <param name="Scale">Optional float to set the scale of the layout.</param>
static member Init
(
?Dimensions : string,
?Center : float,
?Scale : float
) =
CircularOptions()
|> CircularOptions.Style
(
?Dimensions = Dimensions,
?Center = Center,
?Scale = Scale
)
// Applies updates to CircularOptions()
///<summary>
/// Applies updates to the CircularOptions instance based on the optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions of the layout.</param>
/// <param name="Center">Optional float to set the center of the layout.</param>
/// <param name="Scale">Optional float to set the scale of the layout.</param>
static member Style
(
?Dimensions,
?Center,
?Scale
) =
(fun (opt:CircularOptions) ->
opt|> DynObj.setOptionalProperty "dimensions" Dimensions
opt|> DynObj.setOptionalProperty "center" Center
opt|> DynObj.setOptionalProperty "scale" Scale
// out ->
opt
)
//dimensions ?array [‘x’, ‘y’]: dimensions of the layout.
//center ?number 0.5: center of the layout.
//rng ?function Math.random: custom RNG function to use.
//scale ?number 1: scale of the layout.
/// <summary>
/// RandomOptions type for configuring the Random layout options
/// </summary>
type RandomOptions() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of RandomOptions with optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions of the layout.</param>
/// <param name="Center">Optional float to set the center of the layout.</param>
/// <param name="Scale">Optional integer to set the scale of the layout.</param>
static member Init
(
?Dimensions : string,
?Center : float,
?Scale : int
) =
RandomOptions()
|> RandomOptions.Style
(
?Dimensions = Dimensions,
?Center = Center,
?Scale = Scale
)
// Applies updates to RandomOptions()
/// <summary>
/// Applies updates to the RandomOptions instance based on the optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions of the layout.</param>
/// <param name="Center">Optional float to set the center of the layout.</param>
/// <param name="Scale">Optional integer to set the scale of the layout.</param>
static member Style
(
?Dimensions,
?Center,
?Scale
) =
(fun (opt:RandomOptions) ->
opt|> DynObj.setOptionalProperty "dimensions" Dimensions
opt|> DynObj.setOptionalProperty "center" Center
opt|> DynObj.setOptionalProperty "scale" Scale
// out ->
opt
)
//dimensions ?array [‘x’, ‘y’]: dimensions to use for the rotation. Cannot work with dimensions != 2.
//degrees ?boolean false: whether the given angle is in degrees.
//centeredOnZero ?boolean false: whether to rotate the graph around 0, rather than the graph’s center.
/// <summary>
/// RotationOptions contains options for configuring a Rotation layout algorithm.
///</summary>
type RotationOptions() =
inherit DynamicObj ()
/// <summary>
/// Initializes a new instance of RotationOptions with optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions for rotation.</param>
/// <param name="Degrees">Optional boolean to indicate if the angle is in degrees.</param>
/// <param name="CenteredOnZero">Optional boolean to rotate the graph around 0 instead of the graph’s center.</param>
static member Init
(
?Dimensions : string,
?Degrees : bool,
?CenteredOnZero : bool
) =
RotationOptions()
|> RotationOptions.Style
(
?Dimensions = Dimensions,
?Degrees = Degrees,
?CenteredOnZero = CenteredOnZero
)
// Applies updates to RotationOptions()
/// <summary>
/// Applies updates to the RotationOptions instance based on the optional parameters.
/// </summary>
/// <param name="Dimensions">Optional string array specifying the dimensions for rotation.</param>
/// <param name="Degrees">Optional boolean to indicate if the angle is in degrees.</param>
/// <param name="CenteredOnZero">Optional boolean to rotate the graph around 0 instead of the graph’s center.</param>
static member Style
(
?Dimensions,
?Degrees,
?CenteredOnZero
) =
(fun (opt:RotationOptions) ->
opt|> DynObj.setOptionalProperty "dimensions" Dimensions
opt|> DynObj.setOptionalProperty "degrees" Degrees
opt|> DynObj.setOptionalProperty "centeredOnZero" CenteredOnZero
// out ->
opt
)
// circlePack
//attributes ?object: attributes to map:
//x ?string x: name of the x position.
//y ?string y: name of the y position.
//center ?number 0: center of the layout.
//hierarchyAttributes ?list []: attributes used to group nodes.
//rng ?function Math.random: custom RNG function to use.
//scale ?number 1: scale of the layout.
// LayoutAlgorithmName
/// <summary>
/// Layout defines different layout algorithms for a graph and serializes them into JavaScript commands.
/// </summary>
type Layout =
| FA2 of FA2Options
| Noverlap of NoverlapOptions
| Circular of CircularOptions
| Random of RandomOptions
| Rotation of RotationOptions
with
/// <summary>
/// Serializes the selected layout into a JavaScript command string.
/// </summary>
/// <param name="layout">The Layout instance to serialize.</param>
/// <returns>A string representing the JavaScript command to apply the layout.</returns>
static member serialize (layout:Layout) =
match layout with
| FA2 opt ->
let stringOpt = opt |> JsonConvert.SerializeObject
sprintf "graphologyLibrary.layout.random.assign(graph); graphologyLibrary.layoutForceAtlas2.assign(graph, %s);" stringOpt
| Noverlap opt ->
let stringOpt = opt |> JsonConvert.SerializeObject
sprintf "graphologyLibrary.layout.random.assign(graph); graphologyLibrary.layoutNoverlap.assign(graph, %s);" stringOpt
| Circular opt ->
let stringOpt = opt |> JsonConvert.SerializeObject
sprintf "graphologyLibrary.layout.circular.assign(graph, %s);" stringOpt
| Random opt ->
let stringOpt = opt |> JsonConvert.SerializeObject
sprintf "graphologyLibrary.layout.random.assign(graph, %s);" stringOpt
| Rotation opt ->
let stringOpt = opt |> JsonConvert.SerializeObject
sprintf "graphologyLibrary.layout.rotation.assign(graph, %s);" stringOpt