Skip to content

Commit 0ee67e3

Browse files
committed
plotlyjs v2.16: Add clustering options to scattermapbox (plotly/plotly.js#5827), add top level args for clustering
1 parent 3442112 commit 0ee67e3

File tree

8 files changed

+122
-9
lines changed

8 files changed

+122
-9
lines changed

src/Plotly.NET/ChartAPI/ChartMap.fs

+30
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,8 @@ module ChartMap =
11831183
/// <param name="LineDash">sets the drawing style of the line</param>
11841184
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
11851185
/// <param name="Below">Determines if this scattermapbox trace's layers are to be inserted before the layer with the specified ID. By default, scattermapbox layers are inserted above all the base layers. To place the scattermapbox layers above every other layer, set `below` to "''".</param>
1186+
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
1187+
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
11861188
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
11871189
[<Extension>]
11881190
static member ScatterMapbox
@@ -1210,6 +1212,8 @@ module ChartMap =
12101212
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle,
12111213
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
12121214
[<Optional; DefaultParameterValue(null)>] ?Below: string,
1215+
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
1216+
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
12131217
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
12141218
) =
12151219

@@ -1239,11 +1243,18 @@ module ChartMap =
12391243
?Width = LineWidth
12401244
)
12411245

1246+
let cluster =
1247+
Cluster
1248+
|> Option.defaultValue (MapboxCluster.init ())
1249+
|> MapboxCluster.style(
1250+
?Enabled = EnableClustering
1251+
)
12421252

12431253
TraceMapbox.initScatterMapbox (
12441254
TraceMapboxStyle.ScatterMapbox(
12451255
Lon = longitudes,
12461256
Lat = latitudes,
1257+
Cluster = cluster,
12471258
Mode = mode,
12481259
Marker = marker,
12491260
Line = line,
@@ -1291,6 +1302,8 @@ module ChartMap =
12911302
/// <param name="LineDash">sets the drawing style of the line</param>
12921303
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
12931304
/// <param name="Below">Determines if this scattermapbox trace's layers are to be inserted before the layer with the specified ID. By default, scattermapbox layers are inserted above all the base layers. To place the scattermapbox layers above every other layer, set `below` to "''".</param>
1305+
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
1306+
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
12941307
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
12951308
[<Extension>]
12961309
static member ScatterMapbox
@@ -1317,6 +1330,8 @@ module ChartMap =
13171330
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle,
13181331
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
13191332
[<Optional; DefaultParameterValue(null)>] ?Below: string,
1333+
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
1334+
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
13201335
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
13211336
) =
13221337

@@ -1346,6 +1361,8 @@ module ChartMap =
13461361
?LineDash = LineDash,
13471362
?Line = Line,
13481363
?Below = Below,
1364+
?EnableClustering = EnableClustering,
1365+
?Cluster = Cluster,
13491366
?UseDefaults = UseDefaults
13501367
)
13511368

@@ -1373,6 +1390,8 @@ module ChartMap =
13731390
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
13741391
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
13751392
/// <param name="Below">Determines if this scattermapbox trace's layers are to be inserted before the layer with the specified ID. By default, scattermapbox layers are inserted above all the base layers. To place the scattermapbox layers above every other layer, set `below` to "''".</param>
1393+
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
1394+
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
13761395
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
13771396
[<Extension>]
13781397
static member PointMapbox
@@ -1394,6 +1413,8 @@ module ChartMap =
13941413
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
13951414
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
13961415
[<Optional; DefaultParameterValue(null)>] ?Below: string,
1416+
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
1417+
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
13971418
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
13981419
) =
13991420

@@ -1419,6 +1440,8 @@ module ChartMap =
14191440
?MultiMarkerSymbol = MultiMarkerSymbol,
14201441
?Marker = Marker,
14211442
?Below = Below,
1443+
?EnableClustering = EnableClustering,
1444+
?Cluster = Cluster,
14221445
?UseDefaults = UseDefaults
14231446

14241447
)
@@ -1446,6 +1469,8 @@ module ChartMap =
14461469
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
14471470
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
14481471
/// <param name="Below">Determines if this scattermapbox trace's layers are to be inserted before the layer with the specified ID. By default, scattermapbox layers are inserted above all the base layers. To place the scattermapbox layers above every other layer, set `below` to "''".</param>
1472+
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
1473+
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
14491474
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
14501475
[<Extension>]
14511476
static member PointMapbox
@@ -1466,6 +1491,8 @@ module ChartMap =
14661491
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
14671492
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
14681493
[<Optional; DefaultParameterValue(null)>] ?Below: string,
1494+
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
1495+
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
14691496
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
14701497
) =
14711498

@@ -1489,6 +1516,8 @@ module ChartMap =
14891516
?MultiMarkerSymbol = MultiMarkerSymbol,
14901517
?Marker = Marker,
14911518
?Below = Below,
1519+
?EnableClustering = EnableClustering,
1520+
?Cluster = Cluster,
14921521
?UseDefaults = UseDefaults
14931522
)
14941523

@@ -1723,6 +1752,7 @@ module ChartMap =
17231752
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
17241753
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
17251754
[<Optional; DefaultParameterValue(null)>] ?Below: string,
1755+
17261756
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
17271757
) =
17281758

src/Plotly.NET/ChartAPI/GenericChart.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module HTML =
1515
<head>
1616
<!-- Plotly.js -->
1717
<meta http-equiv="X-UA-Compatible" content="IE=11" >
18-
<script src="https://cdn.plot.ly/plotly-2.15.1.min.js"></script>
18+
<script src="https://cdn.plot.ly/plotly-2.16.5.min.js"></script>
1919
[ADDITIONAL_HEAD_TAGS]
2020
<style>
2121
.container {
@@ -58,7 +58,7 @@ module HTML =
5858
newScript.AppendLine(
5959
@"
6060
var renderPlotly_[SCRIPTID] = function() {
61-
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.15.1.min'}}) || require;
61+
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.16.5.min'}}) || require;
6262
fsharpPlotlyRequire(['plotly'], function(Plotly) {"
6363
)
6464
|> ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
namespace Plotly.NET.LayoutObjects
2+
3+
open Plotly.NET
4+
open DynamicObj
5+
open System
6+
open System.Runtime.InteropServices
7+
8+
/// <summary>Clustering options for points on mapbox traces</summary>
9+
type MapboxCluster() =
10+
11+
inherit DynamicObj()
12+
13+
/// <summary>
14+
/// Returns a new MapboxCluster object with the given styles
15+
/// </summary
16+
/// <param name="Color">Sets the color for each cluster step.</param>
17+
/// <param name="Enabled">Determines whether clustering is enabled or disabled.</param>
18+
/// <param name="MaxZoom">Sets the maximum zoom level. At zoom levels equal to or greater than this, points will never be clustered.</param>
19+
/// <param name="Opacity">Sets the marker opacity.</param>
20+
/// <param name="Size">Sets the size for each cluster step.</param>
21+
/// <param name="MultiSize">Sets the size for each cluster step.</param>
22+
/// <param name="Step">Sets how many points it takes to create a cluster or advance to the next cluster step. Use this in conjunction with arrays for `size` and / or `color`. If an integer, steps start at multiples of this number. If an array, each step extends from the given value until one less than the next value.</param>
23+
/// <param name="MultiStep">Sets how many points it takes to create a cluster or advance to the next cluster step. Use this in conjunction with arrays for `size` and / or `color`. If an integer, steps start at multiples of this number. If an array, each step extends from the given value until one less than the next value.</param>
24+
static member init
25+
(
26+
[<Optional; DefaultParameterValue(null)>] ?Color: Color,
27+
[<Optional; DefaultParameterValue(null)>] ?Enabled: bool,
28+
[<Optional; DefaultParameterValue(null)>] ?MaxZoom: float,
29+
[<Optional; DefaultParameterValue(null)>] ?Opacity: float,
30+
[<Optional; DefaultParameterValue(null)>] ?Size: int,
31+
[<Optional; DefaultParameterValue(null)>] ?MultiSize: seq<int>,
32+
[<Optional; DefaultParameterValue(null)>] ?Step: int,
33+
[<Optional; DefaultParameterValue(null)>] ?MultiStep: seq<int>
34+
) =
35+
MapboxCluster()
36+
|> MapboxCluster.style (
37+
?Color = Color ,
38+
?Enabled = Enabled ,
39+
?MaxZoom = MaxZoom ,
40+
?Opacity = Opacity ,
41+
?Size = Size ,
42+
?MultiSize = MultiSize ,
43+
?Step = Step ,
44+
?MultiStep = MultiStep
45+
)
46+
47+
/// <summary>
48+
/// Returns a function that applies the given styles to a MapboxCluster object.
49+
/// </summary>
50+
/// <param name="Color">Sets the color for each cluster step.</param>
51+
/// <param name="Enabled">Determines whether clustering is enabled or disabled.</param>
52+
/// <param name="MaxZoom">Sets the maximum zoom level. At zoom levels equal to or greater than this, points will never be clustered.</param>
53+
/// <param name="Opacity">Sets the marker opacity.</param>
54+
/// <param name="Size">Sets the size for each cluster step.</param>
55+
/// <param name="MultiSize">Sets the size for each cluster step.</param>
56+
/// <param name="Step">Sets how many points it takes to create a cluster or advance to the next cluster step. Use this in conjunction with arrays for `size` and / or `color`. If an integer, steps start at multiples of this number. If an array, each step extends from the given value until one less than the next value.</param>
57+
/// <param name="MultiStep">Sets how many points it takes to create a cluster or advance to the next cluster step. Use this in conjunction with arrays for `size` and / or `color`. If an integer, steps start at multiples of this number. If an array, each step extends from the given value until one less than the next value.</param>
58+
static member style
59+
(
60+
[<Optional; DefaultParameterValue(null)>] ?Color: Color,
61+
[<Optional; DefaultParameterValue(null)>] ?Enabled: bool,
62+
[<Optional; DefaultParameterValue(null)>] ?MaxZoom: float,
63+
[<Optional; DefaultParameterValue(null)>] ?Opacity: float,
64+
[<Optional; DefaultParameterValue(null)>] ?Size: int,
65+
[<Optional; DefaultParameterValue(null)>] ?MultiSize: seq<int>,
66+
[<Optional; DefaultParameterValue(null)>] ?Step: int,
67+
[<Optional; DefaultParameterValue(null)>] ?MultiStep: seq<int>
68+
69+
) =
70+
(fun (mapboxCluster: MapboxCluster) ->
71+
72+
Color |> DynObj.setValueOpt mapboxCluster "color"
73+
Enabled |> DynObj.setValueOpt mapboxCluster "enabled"
74+
MaxZoom |> DynObj.setValueOpt mapboxCluster "maxzoom"
75+
Opacity |> DynObj.setValueOpt mapboxCluster "opacity"
76+
(Size, MultiSize) |> DynObj.setSingleOrMultiOpt mapboxCluster "size"
77+
(Step, MultiStep) |> DynObj.setSingleOrMultiOpt mapboxCluster "step"
78+
79+
mapboxCluster)

src/Plotly.NET/Plotly.NET.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Layout\ObjectAbstractions\Map\Geo.fs" />
8080
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayerSymbol.fs" />
8181
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayer.fs" />
82+
<Compile Include="Layout\ObjectAbstractions\Map\MapboxCluster.fs" />
8283
<Compile Include="Layout\ObjectAbstractions\Map\Mapbox.fs" />
8384
<Compile Include="Layout\ObjectAbstractions\Ternary\Ternary.fs" />
8485
<Compile Include="Layout\ObjectAbstractions\3D\Camera.fs" />

src/Plotly.NET/Traces/TraceMapbox.fs

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type TraceMapboxStyle() =
6565
/// <param name="Ids">Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.</param>
6666
/// <param name="Lat">Sets the latitude coordinates (in degrees North).</param>
6767
/// <param name="Lon">Sets the longitude coordinates (in degrees East).</param>
68+
/// <param name="Cluster">Sets the clustering options for points on this trace.</param>
6869
/// <param name="Text">Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.</param>
6970
/// <param name="MultiText">Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.</param>
7071
/// <param name="TextPosition">Sets the positions of the `text` elements with respects to the (x,y) coordinates.</param>
@@ -104,6 +105,7 @@ type TraceMapboxStyle() =
104105
[<Optional; DefaultParameterValue(null)>] ?Ids: seq<#IConvertible>,
105106
[<Optional; DefaultParameterValue(null)>] ?Lat: #IConvertible seq,
106107
[<Optional; DefaultParameterValue(null)>] ?Lon: #IConvertible seq,
108+
[<Optional; DefaultParameterValue(null)>] ?Cluster: MapboxCluster,
107109
[<Optional; DefaultParameterValue(null)>] ?Text: #IConvertible,
108110
[<Optional; DefaultParameterValue(null)>] ?MultiText: seq<#IConvertible>,
109111
[<Optional; DefaultParameterValue(null)>] ?TextPosition: StyleParam.TextPosition,
@@ -144,6 +146,7 @@ type TraceMapboxStyle() =
144146
Ids |> DynObj.setValueOpt trace "ids"
145147
Lat |> DynObj.setValueOpt trace "lat"
146148
Lon |> DynObj.setValueOpt trace "lon"
149+
Cluster |> DynObj.setValueOpt trace "cluster"
147150
(Text, MultiText) |> DynObj.setSingleOrMultiOpt trace "text"
148151

149152
(TextPosition, MultiTextPosition)

0 commit comments

Comments
 (0)