Skip to content

Commit

Permalink
plotlyjs v2.16: Add clustering options to scattermapbox (plotly/plotl…
Browse files Browse the repository at this point in the history
…y.js#5827), add top level args for clustering
  • Loading branch information
kMutagene committed Feb 9, 2023
1 parent 3442112 commit 0ee67e3
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 9 deletions.
30 changes: 30 additions & 0 deletions src/Plotly.NET/ChartAPI/ChartMap.fs
Expand Up @@ -1183,6 +1183,8 @@ module ChartMap =
/// <param name="LineDash">sets the drawing style of the line</param>
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
/// <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>
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member ScatterMapbox
Expand Down Expand Up @@ -1210,6 +1212,8 @@ module ChartMap =
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle,
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
[<Optional; DefaultParameterValue(null)>] ?Below: string,
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
) =

Expand Down Expand Up @@ -1239,11 +1243,18 @@ module ChartMap =
?Width = LineWidth
)

let cluster =
Cluster
|> Option.defaultValue (MapboxCluster.init ())
|> MapboxCluster.style(
?Enabled = EnableClustering
)

TraceMapbox.initScatterMapbox (
TraceMapboxStyle.ScatterMapbox(
Lon = longitudes,
Lat = latitudes,
Cluster = cluster,
Mode = mode,
Marker = marker,
Line = line,
Expand Down Expand Up @@ -1291,6 +1302,8 @@ module ChartMap =
/// <param name="LineDash">sets the drawing style of the line</param>
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
/// <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>
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member ScatterMapbox
Expand All @@ -1317,6 +1330,8 @@ module ChartMap =
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle,
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
[<Optional; DefaultParameterValue(null)>] ?Below: string,
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
) =

Expand Down Expand Up @@ -1346,6 +1361,8 @@ module ChartMap =
?LineDash = LineDash,
?Line = Line,
?Below = Below,
?EnableClustering = EnableClustering,
?Cluster = Cluster,
?UseDefaults = UseDefaults
)

Expand Down Expand Up @@ -1373,6 +1390,8 @@ module ChartMap =
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
/// <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>
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member PointMapbox
Expand All @@ -1394,6 +1413,8 @@ module ChartMap =
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
[<Optional; DefaultParameterValue(null)>] ?Below: string,
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
) =

Expand All @@ -1419,6 +1440,8 @@ module ChartMap =
?MultiMarkerSymbol = MultiMarkerSymbol,
?Marker = Marker,
?Below = Below,
?EnableClustering = EnableClustering,
?Cluster = Cluster,
?UseDefaults = UseDefaults

)
Expand Down Expand Up @@ -1446,6 +1469,8 @@ module ChartMap =
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
/// <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>
/// <param name="EnableClustering">Wether or not to enable clustering for points</param>
/// <param name="Cluster">Sets the clustering options (use this for more finegrained control than the other cluster-associated arguments)</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member PointMapbox
Expand All @@ -1466,6 +1491,8 @@ module ChartMap =
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
[<Optional; DefaultParameterValue(null)>] ?Below: string,
[<Optional; DefaultParameterValue(true)>] ?EnableClustering: bool,
[<Optional; DefaultParameterValue(true)>] ?Cluster: MapboxCluster,
[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
) =

Expand All @@ -1489,6 +1516,8 @@ module ChartMap =
?MultiMarkerSymbol = MultiMarkerSymbol,
?Marker = Marker,
?Below = Below,
?EnableClustering = EnableClustering,
?Cluster = Cluster,
?UseDefaults = UseDefaults
)

Expand Down Expand Up @@ -1723,6 +1752,7 @@ module ChartMap =
[<Optional; DefaultParameterValue(null)>] ?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
[<Optional; DefaultParameterValue(null)>] ?Marker: Marker,
[<Optional; DefaultParameterValue(null)>] ?Below: string,

[<Optional; DefaultParameterValue(true)>] ?UseDefaults: bool
) =

Expand Down
4 changes: 2 additions & 2 deletions src/Plotly.NET/ChartAPI/GenericChart.fs
Expand Up @@ -15,7 +15,7 @@ module HTML =
<head>
<!-- Plotly.js -->
<meta http-equiv="X-UA-Compatible" content="IE=11" >
<script src="https://cdn.plot.ly/plotly-2.15.1.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.16.5.min.js"></script>
[ADDITIONAL_HEAD_TAGS]
<style>
.container {
Expand Down Expand Up @@ -58,7 +58,7 @@ module HTML =
newScript.AppendLine(
@"
var renderPlotly_[SCRIPTID] = function() {
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.15.1.min'}}) || require;
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.16.5.min'}}) || require;
fsharpPlotlyRequire(['plotly'], function(Plotly) {"
)
|> ignore
Expand Down
79 changes: 79 additions & 0 deletions src/Plotly.NET/Layout/ObjectAbstractions/Map/MapboxCluster.fs
@@ -0,0 +1,79 @@
namespace Plotly.NET.LayoutObjects

open Plotly.NET
open DynamicObj
open System
open System.Runtime.InteropServices

/// <summary>Clustering options for points on mapbox traces</summary>
type MapboxCluster() =

inherit DynamicObj()

/// <summary>
/// Returns a new MapboxCluster object with the given styles
/// </summary
/// <param name="Color">Sets the color for each cluster step.</param>
/// <param name="Enabled">Determines whether clustering is enabled or disabled.</param>
/// <param name="MaxZoom">Sets the maximum zoom level. At zoom levels equal to or greater than this, points will never be clustered.</param>
/// <param name="Opacity">Sets the marker opacity.</param>
/// <param name="Size">Sets the size for each cluster step.</param>
/// <param name="MultiSize">Sets the size for each cluster step.</param>
/// <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>
/// <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>
static member init
(
[<Optional; DefaultParameterValue(null)>] ?Color: Color,
[<Optional; DefaultParameterValue(null)>] ?Enabled: bool,
[<Optional; DefaultParameterValue(null)>] ?MaxZoom: float,
[<Optional; DefaultParameterValue(null)>] ?Opacity: float,
[<Optional; DefaultParameterValue(null)>] ?Size: int,
[<Optional; DefaultParameterValue(null)>] ?MultiSize: seq<int>,
[<Optional; DefaultParameterValue(null)>] ?Step: int,
[<Optional; DefaultParameterValue(null)>] ?MultiStep: seq<int>
) =
MapboxCluster()
|> MapboxCluster.style (
?Color = Color ,
?Enabled = Enabled ,
?MaxZoom = MaxZoom ,
?Opacity = Opacity ,
?Size = Size ,
?MultiSize = MultiSize ,
?Step = Step ,
?MultiStep = MultiStep
)

/// <summary>
/// Returns a function that applies the given styles to a MapboxCluster object.
/// </summary>
/// <param name="Color">Sets the color for each cluster step.</param>
/// <param name="Enabled">Determines whether clustering is enabled or disabled.</param>
/// <param name="MaxZoom">Sets the maximum zoom level. At zoom levels equal to or greater than this, points will never be clustered.</param>
/// <param name="Opacity">Sets the marker opacity.</param>
/// <param name="Size">Sets the size for each cluster step.</param>
/// <param name="MultiSize">Sets the size for each cluster step.</param>
/// <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>
/// <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>
static member style
(
[<Optional; DefaultParameterValue(null)>] ?Color: Color,
[<Optional; DefaultParameterValue(null)>] ?Enabled: bool,
[<Optional; DefaultParameterValue(null)>] ?MaxZoom: float,
[<Optional; DefaultParameterValue(null)>] ?Opacity: float,
[<Optional; DefaultParameterValue(null)>] ?Size: int,
[<Optional; DefaultParameterValue(null)>] ?MultiSize: seq<int>,
[<Optional; DefaultParameterValue(null)>] ?Step: int,
[<Optional; DefaultParameterValue(null)>] ?MultiStep: seq<int>

) =
(fun (mapboxCluster: MapboxCluster) ->

Color |> DynObj.setValueOpt mapboxCluster "color"
Enabled |> DynObj.setValueOpt mapboxCluster "enabled"
MaxZoom |> DynObj.setValueOpt mapboxCluster "maxzoom"
Opacity |> DynObj.setValueOpt mapboxCluster "opacity"
(Size, MultiSize) |> DynObj.setSingleOrMultiOpt mapboxCluster "size"
(Step, MultiStep) |> DynObj.setSingleOrMultiOpt mapboxCluster "step"

mapboxCluster)
1 change: 1 addition & 0 deletions src/Plotly.NET/Plotly.NET.fsproj
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Layout\ObjectAbstractions\Map\Geo.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayerSymbol.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxLayer.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\MapboxCluster.fs" />
<Compile Include="Layout\ObjectAbstractions\Map\Mapbox.fs" />
<Compile Include="Layout\ObjectAbstractions\Ternary\Ternary.fs" />
<Compile Include="Layout\ObjectAbstractions\3D\Camera.fs" />
Expand Down
3 changes: 3 additions & 0 deletions src/Plotly.NET/Traces/TraceMapbox.fs
Expand Up @@ -65,6 +65,7 @@ type TraceMapboxStyle() =
/// <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>
/// <param name="Lat">Sets the latitude coordinates (in degrees North).</param>
/// <param name="Lon">Sets the longitude coordinates (in degrees East).</param>
/// <param name="Cluster">Sets the clustering options for points on this trace.</param>
/// <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>
/// <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>
/// <param name="TextPosition">Sets the positions of the `text` elements with respects to the (x,y) coordinates.</param>
Expand Down Expand Up @@ -104,6 +105,7 @@ type TraceMapboxStyle() =
[<Optional; DefaultParameterValue(null)>] ?Ids: seq<#IConvertible>,
[<Optional; DefaultParameterValue(null)>] ?Lat: #IConvertible seq,
[<Optional; DefaultParameterValue(null)>] ?Lon: #IConvertible seq,
[<Optional; DefaultParameterValue(null)>] ?Cluster: MapboxCluster,
[<Optional; DefaultParameterValue(null)>] ?Text: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MultiText: seq<#IConvertible>,
[<Optional; DefaultParameterValue(null)>] ?TextPosition: StyleParam.TextPosition,
Expand Down Expand Up @@ -144,6 +146,7 @@ type TraceMapboxStyle() =
Ids |> DynObj.setValueOpt trace "ids"
Lat |> DynObj.setValueOpt trace "lat"
Lon |> DynObj.setValueOpt trace "lon"
Cluster |> DynObj.setValueOpt trace "cluster"
(Text, MultiText) |> DynObj.setSingleOrMultiOpt trace "text"

(TextPosition, MultiTextPosition)
Expand Down

0 comments on commit 0ee67e3

Please sign in to comment.