Skip to content

Commit 18b5698

Browse files
committed
Add full support for the Geo object.
Add functions to style geo traces: Chart.withMap, Chart.withMapStyle, Chart.withMapProjection
1 parent 64c603f commit 18b5698

File tree

8 files changed

+681
-17
lines changed

8 files changed

+681
-17
lines changed

Diff for: src/FSharp.Plotly/ChartExtensions.fs

+172
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,178 @@ module ChartExtensions =
372372
|> Layout.SetLayoutGrid layoutGrid
373373
GenericChart.setLayout layout ch)
374374

375+
/// Sets a map for the given chart (will only work with traces supporting geo, e.g. choropleth, scattergeo)
376+
[<CompiledName("WithMap")>]
377+
static member withMap(map:Geo,[<Optional;DefaultParameterValue(null)>] ?Id ) =
378+
(fun (ch:GenericChart) ->
379+
let layout =
380+
let id = defaultArg Id 1
381+
GenericChart.getLayout ch
382+
|> Layout.UpdateMapById(id,map)
383+
GenericChart.setLayout layout ch
384+
)
385+
386+
/// Sets the map style for the given chart (will only work with traces supporting geo, e.g. choropleth, scattergeo)
387+
///
388+
/// Parameters :
389+
///
390+
/// FitBounds : Determines if and how this subplot's view settings are auto-computed to fit trace data
391+
///
392+
/// Resolution : Sets the resolution of the base layers
393+
///
394+
/// Scope : Set the scope of the map.
395+
///
396+
/// Projection : Determines the type of projection used to display the map
397+
///
398+
/// Center : Sets the (lon,lat) coordinates of the map's center. By default, the map's longitude center lies at the middle of the longitude range for scoped projection and above `projection.rotation.lon` otherwise. For all projection types, the map's latitude center lies at the middle of the latitude range by default.
399+
///
400+
/// Visible : Wether or not the base layers are visible
401+
///
402+
/// Domain : The domain of this geo subplot
403+
///
404+
/// ShowCoastLine : Sets whether or not the coastlines are drawn.
405+
///
406+
/// CoastLineColor : Sets the coastline color.
407+
///
408+
/// CoastLineWidth : Sets the coastline stroke width (in px).
409+
///
410+
/// ShowLand : Sets whether or not land masses are filled in color.
411+
///
412+
/// LandColor : Sets the land mass color.
413+
///
414+
/// ShowOcean : Sets whether or not oceans are filled in color.
415+
///
416+
/// OceanColor : Sets the ocean color
417+
///
418+
/// ShowLakes : Sets whether or not lakes are drawn.
419+
///
420+
/// LakeColor : Sets the color of the lakes.
421+
///
422+
/// ShowRivers : Sets whether or not rivers are drawn.
423+
///
424+
/// RiverColor : Sets color of the rivers.
425+
///
426+
/// RiverWidth : Sets the stroke width (in px) of the rivers.
427+
///
428+
/// ShowCountries : Sets whether or not country boundaries are drawn.
429+
///
430+
/// CountryColor : Sets line color of the country boundaries.
431+
///
432+
/// CountryWidth : Sets line width (in px) of the country boundaries.
433+
///
434+
/// ShowSubunits : Sets whether or not boundaries of subunits within countries (e.g. states, provinces) are drawn.
435+
///
436+
/// SubunitColor : Sets the color of the subunits boundaries.
437+
///
438+
/// SubunitWidth : Sets the stroke width (in px) of the subunits boundaries.
439+
///
440+
/// ShowFrame : Sets whether or not a frame is drawn around the map.
441+
///
442+
/// FrameColor : Sets the color the frame.
443+
///
444+
/// FrameWidth : Sets the stroke width (in px) of the frame.
445+
///
446+
/// BgColor : Set the background color of the map
447+
///
448+
/// LatAxis : Sets the latitudinal axis for this geo trace
449+
///
450+
/// LonAxis : Sets the longitudinal axis for this geo trace
451+
[<CompiledName("WithMapStyle")>]
452+
static member withMapStyle([<Optional;DefaultParameterValue(null)>] ?Id,
453+
[<Optional;DefaultParameterValue(null)>]?FitBounds : StyleParam.GeoFitBounds,
454+
[<Optional;DefaultParameterValue(null)>]?Resolution : StyleParam.GeoResolution,
455+
[<Optional;DefaultParameterValue(null)>]?Scope : StyleParam.GeoScope,
456+
[<Optional;DefaultParameterValue(null)>]?Projection : GeoProjection,
457+
[<Optional;DefaultParameterValue(null)>]?Center : (float*float),
458+
[<Optional;DefaultParameterValue(null)>]?Visible : bool,
459+
[<Optional;DefaultParameterValue(null)>]?Domain : Domain,
460+
[<Optional;DefaultParameterValue(null)>]?ShowCoastLines : bool,
461+
[<Optional;DefaultParameterValue(null)>]?CoastLineColor,
462+
[<Optional;DefaultParameterValue(null)>]?CoastLineWidth : float,
463+
[<Optional;DefaultParameterValue(null)>]?ShowLand : bool,
464+
[<Optional;DefaultParameterValue(null)>]?LandColor,
465+
[<Optional;DefaultParameterValue(null)>]?ShowOcean : bool,
466+
[<Optional;DefaultParameterValue(null)>]?OceanColor,
467+
[<Optional;DefaultParameterValue(null)>]?ShowLakes : bool,
468+
[<Optional;DefaultParameterValue(null)>]?LakeColor,
469+
[<Optional;DefaultParameterValue(null)>]?ShowRivers : bool,
470+
[<Optional;DefaultParameterValue(null)>]?RiverColor,
471+
[<Optional;DefaultParameterValue(null)>]?RiverWidth : float,
472+
[<Optional;DefaultParameterValue(null)>]?ShowCountries : bool,
473+
[<Optional;DefaultParameterValue(null)>]?CountryColor,
474+
[<Optional;DefaultParameterValue(null)>]?CountryWidth : float,
475+
[<Optional;DefaultParameterValue(null)>]?ShowSubunits : bool,
476+
[<Optional;DefaultParameterValue(null)>]?SubunitColor,
477+
[<Optional;DefaultParameterValue(null)>]?SubunitWidth : float,
478+
[<Optional;DefaultParameterValue(null)>]?ShowFrame : bool,
479+
[<Optional;DefaultParameterValue(null)>]?FrameColor,
480+
[<Optional;DefaultParameterValue(null)>]?FrameWidth : float,
481+
[<Optional;DefaultParameterValue(null)>]?BgColor,
482+
[<Optional;DefaultParameterValue(null)>]?LatAxis : Axis.LinearAxis,
483+
[<Optional;DefaultParameterValue(null)>]?LonAxis : Axis.LinearAxis
484+
) =
485+
(fun (ch:GenericChart) ->
486+
487+
let map =
488+
Geo.init(
489+
?FitBounds = FitBounds ,
490+
?Resolution = Resolution ,
491+
?Scope = Scope ,
492+
?Projection = Projection ,
493+
?Center = Center ,
494+
?Visible = Visible ,
495+
?Domain = Domain ,
496+
?ShowCoastLines = ShowCoastLines,
497+
?CoastLineColor = CoastLineColor,
498+
?CoastLineWidth = CoastLineWidth,
499+
?ShowLand = ShowLand ,
500+
?LandColor = LandColor ,
501+
?ShowOcean = ShowOcean ,
502+
?OceanColor = OceanColor ,
503+
?ShowLakes = ShowLakes ,
504+
?LakeColor = LakeColor ,
505+
?ShowRivers = ShowRivers ,
506+
?RiverColor = RiverColor ,
507+
?RiverWidth = RiverWidth ,
508+
?ShowCountries = ShowCountries ,
509+
?CountryColor = CountryColor ,
510+
?CountryWidth = CountryWidth ,
511+
?ShowSubunits = ShowSubunits ,
512+
?SubunitColor = SubunitColor ,
513+
?SubunitWidth = SubunitWidth ,
514+
?ShowFrame = ShowFrame ,
515+
?FrameColor = FrameColor ,
516+
?FrameWidth = FrameWidth ,
517+
?BgColor = BgColor ,
518+
?LatAxis = LatAxis ,
519+
?LonAxis = LonAxis
520+
)
521+
let id = defaultArg Id 1
522+
ch |> Chart.withMap(map,id)
523+
)
524+
525+
[<CompiledName("WithMapProjection")>]
526+
static member withMapProjection(projectionType : StyleParam.GeoProjectionType,
527+
[<Optional;DefaultParameterValue(null)>]?Rotation ,
528+
[<Optional;DefaultParameterValue(null)>]?Parallels,
529+
[<Optional;DefaultParameterValue(null)>]?Scale ,
530+
[<Optional;DefaultParameterValue(null)>]?Id
531+
) =
532+
(fun (ch:GenericChart) ->
533+
534+
let projection =
535+
GeoProjection.init(
536+
projectionType = projectionType,
537+
?Rotation = Rotation ,
538+
?Parallels = Parallels ,
539+
?Scale = Scale
540+
)
541+
542+
let map = Geo.init(Projection = projection)
543+
let id = defaultArg Id 1
544+
ch |> Chart.withMap(map,id)
545+
)
546+
375547
// Set the LayoutGrid options of a Chart
376548
[<CompiledName("WithLayoutGridStyle")>]
377549
static member withLayoutGridStyle([<Optional;DefaultParameterValue(null)>]?SubPlots : StyleParam.AxisId [] [],

Diff for: src/FSharp.Plotly/FSharp.Plotly.fsproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<Compile Include="Dimensions.fs" />
3939
<Compile Include="Domain.fs" />
4040
<Compile Include="Line.fs" />
41-
<Compile Include="WaterfallConnector.fs" />
4241
<Compile Include="Box.fs" />
4342
<Compile Include="Meanline.fs" />
4443
<Compile Include="Marker.fs" />
@@ -53,6 +52,8 @@
5352
<Compile Include="Table.fs" />
5453
<Compile Include="Trace.fs" />
5554
<Compile Include="Trace3d.fs" />
55+
<Compile Include="GeoProjection.fs" />
56+
<Compile Include="Geo.fs" />
5657
<Compile Include="LayoutGrid.fs" />
5758
<Compile Include="Layout.fs" />
5859
<Compile Include="Config.fs" />

0 commit comments

Comments
 (0)