|
| 1 | +module ChartMapTestCharts |
| 2 | + |
| 3 | +open Plotly.NET |
| 4 | +open Plotly.NET.TraceObjects |
| 5 | +open Plotly.NET.LayoutObjects |
| 6 | +open System |
| 7 | + |
| 8 | +open TestUtils.DataGeneration |
| 9 | +open Deedle |
| 10 | + |
| 11 | +module GeoBaseMap = |
| 12 | + |
| 13 | + let ``Base map only`` = |
| 14 | + Chart.PointGeo(locations = [], UseDefaults = false) // deliberately empty chart to show the base map only |
| 15 | + |> Chart.withMarginSize(0, 0, 0, 0) |
| 16 | + |
| 17 | + let ``styled base map only`` = |
| 18 | + let myGeo = |
| 19 | + Geo.init( |
| 20 | + Resolution=StyleParam.GeoResolution.R50, |
| 21 | + ShowCoastLines=true, |
| 22 | + CoastLineColor=Color.fromString "RebeccaPurple", |
| 23 | + ShowLand=true, |
| 24 | + LandColor=Color.fromString "LightGreen", |
| 25 | + ShowOcean=true, |
| 26 | + OceanColor=Color.fromString "LightBlue", |
| 27 | + ShowLakes=true, |
| 28 | + LakeColor=Color.fromString "Blue", |
| 29 | + ShowRivers=true, |
| 30 | + RiverColor=Color.fromString "Blue" |
| 31 | + ) |
| 32 | + Chart.PointGeo(locations = [], UseDefaults = false) |
| 33 | + |> Chart.withGeo myGeo |
| 34 | + |> Chart.withMarginSize(0, 0, 0, 0) |
| 35 | + |
| 36 | + let ``Base map country borders at 1:50m resolution`` = |
| 37 | + let countryGeo = |
| 38 | + Geo.init( |
| 39 | + Visible=false, |
| 40 | + Resolution=StyleParam.GeoResolution.R50, |
| 41 | + ShowCountries=true, |
| 42 | + CountryColor=Color.fromString "RebeccaPurple" |
| 43 | + ) |
| 44 | + Chart.PointGeo(locations = [], UseDefaults = false) |
| 45 | + |> Chart.withGeo countryGeo |
| 46 | + |> Chart.withMarginSize(0, 0, 0, 0) |
| 47 | + |
| 48 | +module ChoroplethMap = |
| 49 | + |
| 50 | + let ``ChoroplethMap chart of top beverage consumption countries`` = |
| 51 | + let locations,z = |
| 52 | + beverageConsumptionLocationData |
| 53 | + |> List.unzip |
| 54 | + |
| 55 | + Chart.ChoroplethMap( |
| 56 | + locations = locations,z = z, |
| 57 | + LocationMode=StyleParam.LocationFormat.CountryNames, |
| 58 | + UseDefaults = false |
| 59 | + ) |
| 60 | + |
| 61 | + let ``ChoroplethMap chart of top beverage consumption countries with styled map and projecton`` = |
| 62 | + let locations,z = |
| 63 | + beverageConsumptionLocationData |
| 64 | + |> List.unzip |
| 65 | + |
| 66 | + Chart.ChoroplethMap( |
| 67 | + locations = locations,z = z, |
| 68 | + LocationMode=StyleParam.LocationFormat.CountryNames, |
| 69 | + UseDefaults = false |
| 70 | + ) |
| 71 | + |> Chart.withGeoStyle( |
| 72 | + Projection=GeoProjection.init(projectionType=StyleParam.GeoProjectionType.Mollweide), |
| 73 | + ShowLakes=true, |
| 74 | + ShowOcean=true, |
| 75 | + OceanColor= Color.fromString "lightblue", |
| 76 | + ShowRivers=true) |
| 77 | + |> Chart.withColorBarStyle ( |
| 78 | + TitleText="Alcohol consumption[l/y]",Len=0.5 |
| 79 | + ) |
| 80 | + |
| 81 | +module ScatterGeo = () |
| 82 | + |
| 83 | +module PointGeo = |
| 84 | + |
| 85 | + let ``Point geo chart of canadian cities`` = |
| 86 | + |
| 87 | + let cityNames = [ |
| 88 | + "Montreal"; "Toronto"; "Vancouver"; "Calgary"; "Edmonton"; |
| 89 | + "Ottawa"; "Halifax"; "Victoria"; "Winnepeg"; "Regina" |
| 90 | + ] |
| 91 | + |
| 92 | + let lon = [ |
| 93 | + -73.57; -79.24; -123.06; -114.1; -113.28; |
| 94 | + -75.43; -63.57; -123.21; -97.13; -104.6 |
| 95 | + ] |
| 96 | + let lat = [ |
| 97 | + 45.5; 43.4; 49.13; 51.1; 53.34; 45.24; |
| 98 | + 44.64; 48.25; 49.89; 50.45 |
| 99 | + ] |
| 100 | + Chart.PointGeo( |
| 101 | + longitudes = lon, |
| 102 | + latitudes = lat, |
| 103 | + MultiText=cityNames, |
| 104 | + TextPosition=StyleParam.TextPosition.TopCenter, |
| 105 | + UseDefaults = false |
| 106 | + ) |
| 107 | + |> Chart.withGeoStyle( |
| 108 | + Scope=StyleParam.GeoScope.NorthAmerica, |
| 109 | + Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea), |
| 110 | + CountryColor = Color.fromString "lightgrey" |
| 111 | + ) |
| 112 | + |> Chart.withMarginSize(0, 0, 0, 0) |
| 113 | + |
| 114 | + |
| 115 | +module LineGeo = |
| 116 | + |
| 117 | + let ``LineGeo plot of feb. 2011 American Airline flights`` = |
| 118 | + let data = |
| 119 | + FlightData |
| 120 | + |> fun csv -> Frame.ReadCsvString(csv,true,separators=",") |
| 121 | + |
| 122 | + let opacityVals : float [] = data.["cnt"] |> Series.values |> fun s -> s |> Seq.map (fun v -> v/(Seq.max s)) |> Array.ofSeq |
| 123 | + let startCoords = Series.zipInner data.["start_lon"] data.["start_lat"] |
| 124 | + let endCoords = Series.zipInner data.["end_lon"] data.["end_lat"] |
| 125 | + let coords = Series.zipInner startCoords endCoords |> Series.values |
| 126 | + |
| 127 | + coords |
| 128 | + |> Seq.mapi (fun i (startCoords,endCoords) -> |
| 129 | + Chart.LineGeo( |
| 130 | + lonlat = [startCoords; endCoords], |
| 131 | + Opacity = opacityVals.[i], |
| 132 | + MarkerColor = Color.fromString "red", |
| 133 | + UseDefaults = false |
| 134 | + ) |
| 135 | + ) |
| 136 | + |> Chart.combine |
| 137 | + |> Chart.withLegend(false) |
| 138 | + |> Chart.withGeoStyle( |
| 139 | + Scope=StyleParam.GeoScope.NorthAmerica, |
| 140 | + Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea), |
| 141 | + ShowLand=true, |
| 142 | + LandColor = Color.fromString "lightgrey" |
| 143 | + ) |
| 144 | + |> Chart.withMarginSize(0,0,50,0) |
| 145 | + |> Chart.withTitle "Feb. 2011 American Airline flights" |
| 146 | + |
| 147 | +module MapboxBaseMap = |
| 148 | + let ``Open streetmap layer only`` = |
| 149 | + |
| 150 | + Chart.PointMapbox( |
| 151 | + longitudes = [], |
| 152 | + latitudes = [], |
| 153 | + UseDefaults = false |
| 154 | + ) |
| 155 | + // open street map is default layer |
| 156 | + |
| 157 | +module ScatterMapbox = () |
| 158 | + |
| 159 | +module PointMapbox = |
| 160 | + |
| 161 | + let ``Point mapbox chart of canadian cities`` = |
| 162 | + let cityNames = [ |
| 163 | + "Montreal"; "Toronto"; "Vancouver"; "Calgary"; "Edmonton"; |
| 164 | + "Ottawa"; "Halifax"; "Victoria"; "Winnepeg"; "Regina" |
| 165 | + ] |
| 166 | + |
| 167 | + let lon = [ |
| 168 | + -73.57; -79.24; -123.06; -114.1; -113.28; |
| 169 | + -75.43; -63.57; -123.21; -97.13; -104.6 |
| 170 | + ] |
| 171 | + |
| 172 | + let lat = [ |
| 173 | + 45.5; 43.4; 49.13; 51.1; 53.34; 45.24; |
| 174 | + 44.64; 48.25; 49.89; 50.45 |
| 175 | + ] |
| 176 | + |
| 177 | + Chart.PointMapbox( |
| 178 | + longitudes = lon, |
| 179 | + latitudes = lat, |
| 180 | + MultiText = cityNames, |
| 181 | + TextPosition = StyleParam.TextPosition.TopCenter, |
| 182 | + UseDefaults = false |
| 183 | + ) |
| 184 | + |> Chart.withMapbox( |
| 185 | + Mapbox.init( |
| 186 | + Center=(-104.6,50.45) |
| 187 | + ) |
| 188 | + ) |
| 189 | + |
| 190 | +module LineMapbox = |
| 191 | + |
| 192 | + let ``LineMapbox plot of feb. 2011 American Airline flights`` = |
| 193 | + |
| 194 | + let data = |
| 195 | + FlightData |
| 196 | + |> fun csv -> Frame.ReadCsvString(csv,true,separators=",") |
| 197 | + |
| 198 | + let opacityVals : float [] = data.["cnt"] |> Series.values |> fun s -> s |> Seq.map (fun v -> v/(Seq.max s)) |> Array.ofSeq |
| 199 | + let startCoords = Series.zipInner data.["start_lon"] data.["start_lat"] |
| 200 | + let endCoords = Series.zipInner data.["end_lon"] data.["end_lat"] |
| 201 | + let coords = Series.zipInner startCoords endCoords |> Series.values |
| 202 | + |
| 203 | + coords |
| 204 | + |> Seq.mapi (fun i (startCoords,endCoords) -> |
| 205 | + Chart.LineMapbox( |
| 206 | + lonlat = [startCoords; endCoords], |
| 207 | + Opacity = opacityVals.[i], |
| 208 | + LineColor = Color.fromString "red", |
| 209 | + UseDefaults = false |
| 210 | + ) |
| 211 | + ) |
| 212 | + |> Chart.combine |
| 213 | + |> Chart.withLegend(false) |
| 214 | + |> Chart.withMapbox( |
| 215 | + Mapbox.init( |
| 216 | + Center=(-97.0372,32.8959) |
| 217 | + ) |
| 218 | + ) |
| 219 | + |> Chart.withMarginSize(0,0,50,0) |
| 220 | + |> Chart.withTitle "Feb. 2011 American Airline flights" |
| 221 | + |
| 222 | + |
| 223 | +module BubbleMapbox = () |
| 224 | + |
| 225 | +module ChoroplethMapbox = () |
| 226 | + |
| 227 | +module DensityMapbox = |
| 228 | + |
| 229 | + let ``Density mapbox chart of earthquakes`` = |
| 230 | + let dataDensityMapbox = |
| 231 | + EarthquakeData |
| 232 | + |> fun d -> Frame.ReadCsvString(d,true,separators=",") |
| 233 | + |
| 234 | + let lon = dataDensityMapbox.["Longitude"] |> Series.values |
| 235 | + let lat= dataDensityMapbox.["Latitude"] |> Series.values |
| 236 | + let magnitudes = dataDensityMapbox.["Magnitude"] |> Series.values |
| 237 | + Chart.DensityMapbox( |
| 238 | + longitudes = lon, |
| 239 | + latitudes = lat, |
| 240 | + Z = magnitudes, |
| 241 | + Radius=8, |
| 242 | + ColorScale=StyleParam.Colorscale.Viridis, |
| 243 | + UseDefaults = false |
| 244 | + ) |
| 245 | + |> Chart.withMapbox( |
| 246 | + Mapbox.init( |
| 247 | + Style = StyleParam.MapboxStyle.StamenTerrain, |
| 248 | + Center = (60.,30.) |
| 249 | + ) |
| 250 | + ) |
0 commit comments