Skip to content

Commit c9fa11f

Browse files
committed
Add add polar point, line, and spline charts
1 parent 86cf5f6 commit c9fa11f

File tree

2 files changed

+256
-40
lines changed

2 files changed

+256
-40
lines changed

src/Plotly.NET/Chart.fs

Lines changed: 216 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,9 @@ type Chart =
12611261

12621262

12631263
/// Uses points, line or both depending on the mode to represent data points in a polar chart
1264-
static member ScatterPolar(rt, mode,
1264+
static member ScatterPolar
1265+
(
1266+
rtheta, mode,
12651267
[<Optional;DefaultParameterValue(null)>] ?Name,
12661268
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
12671269
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
@@ -1271,23 +1273,222 @@ type Chart =
12711273
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
12721274
[<Optional;DefaultParameterValue(null)>] ?TextFont,
12731275
[<Optional;DefaultParameterValue(null)>] ?Dash,
1274-
[<Optional;DefaultParameterValue(null)>] ?Width) =
1276+
[<Optional;DefaultParameterValue(null)>] ?Width
1277+
) =
1278+
1279+
let r,t = Seq.unzip rtheta
1280+
1281+
Chart.ScatterPolar(
1282+
r, t, mode,
1283+
?Name=Name,
1284+
?Showlegend=Showlegend,
1285+
?MarkerSymbol=MarkerSymbol,
1286+
?Color=Color,
1287+
?Opacity=Opacity,
1288+
?Labels=Labels,
1289+
?TextPosition=TextPosition,
1290+
?TextFont=TextFont,
1291+
?Dash=Dash,
1292+
?Width=Width
1293+
)
1294+
1295+
///
1296+
static member PointPolar
1297+
(
1298+
r, theta,
1299+
[<Optional;DefaultParameterValue(null)>] ?Name,
1300+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1301+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1302+
[<Optional;DefaultParameterValue(null)>] ?Color,
1303+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1304+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1305+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1306+
[<Optional;DefaultParameterValue(null)>] ?TextFont
1307+
) =
1308+
1309+
let changeMode = StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
1310+
1311+
Trace.initScatterPolar (
1312+
TraceStyle.ScatterPolar(
1313+
R = r,
1314+
Theta = theta,
1315+
Mode = changeMode StyleParam.Mode.Markers
1316+
)
1317+
)
1318+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1319+
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
1320+
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
1321+
|> GenericChart.ofTraceObject
1322+
1323+
///
1324+
static member PointPolar
1325+
(
1326+
rtheta,
1327+
[<Optional;DefaultParameterValue(null)>] ?Name,
1328+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1329+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1330+
[<Optional;DefaultParameterValue(null)>] ?Color,
1331+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1332+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1333+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1334+
[<Optional;DefaultParameterValue(null)>] ?TextFont
1335+
) =
1336+
let r,t = Seq.unzip rtheta
1337+
1338+
Chart.PointPolar(
1339+
r, t,
1340+
?Name = Name,
1341+
?Showlegend = Showlegend,
1342+
?MarkerSymbol = MarkerSymbol,
1343+
?Color = Color,
1344+
?Opacity = Opacity,
1345+
?Labels = Labels,
1346+
?TextPosition = TextPosition,
1347+
?TextFont = TextFont
1348+
)
1349+
1350+
///
1351+
static member LinePolar
1352+
(
1353+
r, theta,
1354+
[<Optional;DefaultParameterValue(null)>] ?Name,
1355+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1356+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1357+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1358+
[<Optional;DefaultParameterValue(null)>] ?Color,
1359+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1360+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1361+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1362+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
1363+
[<Optional;DefaultParameterValue(null)>] ?Dash,
1364+
[<Optional;DefaultParameterValue(null)>] ?Width
1365+
) =
1366+
let changeMode =
1367+
let isShowMarker =
1368+
match ShowMarkers with
1369+
| Some isShow -> isShow
1370+
| Option.None -> false
1371+
StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
1372+
>> StyleParam.ModeUtils.showMarker (isShowMarker)
1373+
1374+
Trace.initScatterPolar (
1375+
TraceStyle.ScatterPolar(
1376+
R = r,
1377+
Theta = theta,
1378+
Mode = changeMode StyleParam.Mode.Lines
1379+
)
1380+
)
1381+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1382+
|> TraceStyle.Line(?Color=Color,?Dash=Dash,?Width=Width)
1383+
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
1384+
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
1385+
|> GenericChart.ofTraceObject
1386+
1387+
///
1388+
static member LinePolar
1389+
(
1390+
rtheta,
1391+
[<Optional;DefaultParameterValue(null)>] ?Name,
1392+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1393+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1394+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1395+
[<Optional;DefaultParameterValue(null)>] ?Color,
1396+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1397+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1398+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1399+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
1400+
[<Optional;DefaultParameterValue(null)>] ?Dash,
1401+
[<Optional;DefaultParameterValue(null)>] ?Width
1402+
) =
1403+
let r,t = Seq.unzip rtheta
1404+
1405+
Chart.LinePolar(
1406+
r, t,
1407+
?Name = Name,
1408+
?Showlegend = Showlegend,
1409+
?ShowMarkers = ShowMarkers,
1410+
?MarkerSymbol = MarkerSymbol,
1411+
?Color = Color,
1412+
?Opacity = Opacity,
1413+
?Labels = Labels,
1414+
?TextPosition = TextPosition,
1415+
?TextFont = TextFont,
1416+
?Dash = Dash,
1417+
?Width = Width
1418+
)
1419+
1420+
///
1421+
static member SplinePolar
1422+
(
1423+
r, theta,
1424+
[<Optional;DefaultParameterValue(null)>] ?Name,
1425+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1426+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1427+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1428+
[<Optional;DefaultParameterValue(null)>] ?Color,
1429+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1430+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1431+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1432+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
1433+
[<Optional;DefaultParameterValue(null)>] ?Smoothing,
1434+
[<Optional;DefaultParameterValue(null)>] ?Dash,
1435+
[<Optional;DefaultParameterValue(null)>] ?Width
1436+
) =
1437+
let changeMode =
1438+
let isShowMarker =
1439+
match ShowMarkers with
1440+
| Some isShow -> isShow
1441+
| Option.None -> false
1442+
StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
1443+
>> StyleParam.ModeUtils.showMarker (isShowMarker)
12751444

1276-
let r,t = Seq.unzip rt
1277-
1278-
Chart.ScatterPolar(r, t, mode,
1279-
?Name=Name,
1280-
?Showlegend=Showlegend,
1281-
?MarkerSymbol=MarkerSymbol,
1282-
?Color=Color,
1283-
?Opacity=Opacity,
1284-
?Labels=Labels,
1285-
?TextPosition=TextPosition,
1286-
?TextFont=TextFont,
1287-
?Dash=Dash,
1288-
?Width=Width
1445+
Trace.initScatterPolar (
1446+
TraceStyle.ScatterPolar(
1447+
R = r,
1448+
Theta = theta,
1449+
Mode = changeMode StyleParam.Mode.Lines
1450+
)
12891451
)
1452+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1453+
|> TraceStyle.Line(?Color=Color,?Dash=Dash,?Width=Width, Shape=StyleParam.Shape.Spline, ?Smoothing=Smoothing)
1454+
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
1455+
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
1456+
|> GenericChart.ofTraceObject
12901457

1458+
///
1459+
static member SplinePolar
1460+
(
1461+
rtheta,
1462+
[<Optional;DefaultParameterValue(null)>] ?Name,
1463+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1464+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1465+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1466+
[<Optional;DefaultParameterValue(null)>] ?Color,
1467+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1468+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1469+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1470+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
1471+
[<Optional;DefaultParameterValue(null)>] ?Smoothing,
1472+
[<Optional;DefaultParameterValue(null)>] ?Dash,
1473+
[<Optional;DefaultParameterValue(null)>] ?Width
1474+
) =
1475+
let r,t = Seq.unzip rtheta
1476+
1477+
Chart.SplinePolar(
1478+
r, t,
1479+
?Name = Name,
1480+
?Showlegend = Showlegend,
1481+
?ShowMarkers = ShowMarkers,
1482+
?MarkerSymbol = MarkerSymbol,
1483+
?Color = Color,
1484+
?Opacity = Opacity,
1485+
?Labels = Labels,
1486+
?TextPosition = TextPosition,
1487+
?TextFont = TextFont,
1488+
?Smoothing = Smoothing,
1489+
?Dash = Dash,
1490+
?Width = Width
1491+
)
12911492

12921493

12931494
//static member WindRose(r, t,

src/Plotly.NET/Playground.fsx

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,46 @@ open System.IO
7070
open Deedle
7171
open FSharpAux
7272

73-
let simpleChart =
74-
let xData = [0. .. 10.]
75-
let yData = [0. .. 10.]
76-
Chart.Point(xData, yData)
77-
|> Chart.withTitle "Hello world!"
78-
|> Chart.withX_AxisStyle ("xAxis", ShowGrid=false)
79-
|> Chart.withY_AxisStyle ("yAxis", ShowGrid=false)
80-
|> Chart.Show
81-
[
82-
Chart.Point([1,2;1,3])
83-
|> Chart.withY_AxisStyle("This title must")
73+
open System
8474

85-
Chart.Line([1,2;1,3])
86-
|> Chart.withY_AxisStyle("be set on the",ZeroLine=false)
87-
88-
Chart.Spline([1,2;1,3])
89-
|> Chart.withY_AxisStyle("respective subplots",ZeroLine=false)
90-
]
91-
|> Chart.SingleStack(Pattern= StyleParam.LayoutGridPattern.Coupled)
92-
//move xAxis to bottom and increase spacing between plots by using the withLayoutGridStyle function
93-
|> Chart.withLayoutGridStyle(YGap= 0.1)
94-
|> Chart.withTitle("Hi i am the new SingleStackChart")
95-
|> Chart.withX_AxisStyle("im the shared xAxis")
96-
|> Chart.Show
75+
let r = [ 1; 2; 3; 4; 5; 6; 7;] |> List.map ((*) 10000)
76+
let r2 = [ 5; 6; 7; 1; 2; 3; 4;] |> List.map ((*) 10000)
77+
let r3 = [ 3; 1; 5; 2; 8; 7; 5;] |> List.map ((*) 10000)
78+
79+
let t = [0; 45; 90; 135; 200; 320; 184;]
80+
81+
(**
82+
A polar chart is a graphical method of displaying multivariate data in the form of a two-dimensional chart
83+
of three or more quantitative variables represented on axes starting from the same point.
84+
The relative position and angle of the axes is typically uninformative.
85+
*)
9786

87+
let polar1 =
88+
[
89+
Chart.PointPolar(r,t,Name="PointPolar")
90+
Chart.LinePolar(r2,t,Name="LinePolar", ShowMarkers = true)
91+
Chart.SplinePolar(r3,t,Name="SplinePolar", ShowMarkers = true)
92+
]
93+
|> Chart.Combine
94+
|> Chart.withPolar(
95+
Polar.init(
96+
Sector= (0., 270.),
97+
Hole=0.1
98+
)
99+
)
100+
|> Chart.withAngularAxis(
101+
Axis.AngularAxis.init(
102+
Color="darkblue"
103+
)
104+
)
105+
|> Chart.withRadialAxis(
106+
Axis.RadialAxis.init(
107+
Title = Title.init("Hi, i am the radial axis"),
108+
Color="darkblue",
109+
SeparateThousands = true
110+
)
111+
)
112+
|> Chart.Show
98113
[
99114
[
100115
Chart.Point([1,2],Name="1,1")
@@ -374,8 +389,8 @@ let yAxis =
374389
Title = Title.init(Text="Y"),
375390
ShowLine = true,
376391
Range = StyleParam.Range.MinMax (0.0, 2.0),
377-
Tickvals = [0.0 .. 2.0],
378-
Ticktext = [ "zero"; "one"; "two" ]
392+
TickVals = [0.0 .. 2.0],
393+
TickText = [ "zero"; "one"; "two" ]
379394
)
380395

381396
Chart.Range(

0 commit comments

Comments
 (0)