Skip to content

Commit 7187d07

Browse files
committed
Add Chart.Point3d, Chart.Line3d, Chart.Bubble3d
1 parent e19a91d commit 7187d07

File tree

2 files changed

+210
-17
lines changed

2 files changed

+210
-17
lines changed

src/Plotly.NET/Chart.fs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,195 @@ type Chart =
18891889
let x,y,z = Seq.unzip3 xyz
18901890
Chart.Scatter3d(x, y, z, mode, ?Name=Name,?Showlegend=Showlegend,?MarkerSymbol=MarkerSymbol,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Dash=Dash,?Width=Width)
18911891

1892+
///
1893+
static member Point3d
1894+
(
1895+
x, y, z,
1896+
[<Optional;DefaultParameterValue(null)>] ?Name,
1897+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1898+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1899+
[<Optional;DefaultParameterValue(null)>] ?Color,
1900+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1901+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1902+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1903+
[<Optional;DefaultParameterValue(null)>] ?TextFont
1904+
) =
1905+
// if text position or font is set, then show labels (not only when hovering)
1906+
let changeMode = StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
1907+
1908+
Chart.Scatter3d(
1909+
x = x,
1910+
y = y,
1911+
z = z,
1912+
mode = changeMode StyleParam.Mode.Markers,
1913+
?Name = Name,
1914+
?Showlegend = Showlegend,
1915+
?MarkerSymbol = MarkerSymbol,
1916+
?Color = Color,
1917+
?Opacity = Opacity,
1918+
?Labels = Labels,
1919+
?TextPosition = TextPosition,
1920+
?TextFont = TextFont
1921+
)
1922+
1923+
///
1924+
static member Point3d
1925+
(
1926+
xyz,
1927+
[<Optional;DefaultParameterValue(null)>] ?Name,
1928+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1929+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1930+
[<Optional;DefaultParameterValue(null)>] ?Color,
1931+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1932+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1933+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1934+
[<Optional;DefaultParameterValue(null)>] ?TextFont
1935+
) =
1936+
let x, y, z = Seq.unzip3 xyz
1937+
1938+
Chart.Point3d(
1939+
x, y, z,
1940+
?Name = Name,
1941+
?Showlegend = Showlegend,
1942+
?MarkerSymbol = MarkerSymbol,
1943+
?Color = Color,
1944+
?Opacity = Opacity,
1945+
?Labels = Labels,
1946+
?TextPosition = TextPosition,
1947+
?TextFont = TextFont
1948+
)
1949+
1950+
1951+
/// Uses points, line or both depending on the mode to represent 3d-data points
1952+
static member Line3d
1953+
(
1954+
x, y, z,
1955+
[<Optional;DefaultParameterValue(null)>] ?Name,
1956+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1957+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1958+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
1959+
[<Optional;DefaultParameterValue(null)>] ?Color,
1960+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
1961+
[<Optional;DefaultParameterValue(null)>] ?Labels,
1962+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
1963+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
1964+
[<Optional;DefaultParameterValue(null)>] ?Dash,
1965+
[<Optional;DefaultParameterValue(null)>] ?Width
1966+
) =
1967+
let changeMode =
1968+
let isShowMarker =
1969+
match ShowMarkers with
1970+
| Some isShow -> isShow
1971+
| Option.None -> false
1972+
StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
1973+
>> StyleParam.ModeUtils.showMarker (isShowMarker)
1974+
1975+
Chart.Scatter3d(
1976+
x = x,
1977+
y = y,
1978+
z = z,
1979+
mode = changeMode StyleParam.Mode.Lines,
1980+
?Name = Name ,
1981+
?Showlegend = Showlegend ,
1982+
?MarkerSymbol = MarkerSymbol,
1983+
?Color = Color ,
1984+
?Opacity = Opacity ,
1985+
?Labels = Labels ,
1986+
?TextPosition = TextPosition,
1987+
?TextFont = TextFont ,
1988+
?Dash = Dash ,
1989+
?Width = Width
1990+
)
1991+
1992+
/// Uses points, line or both depending on the mode to represent 3d-data points
1993+
static member Line3d
1994+
(
1995+
xyz,
1996+
[<Optional;DefaultParameterValue(null)>] ?Name,
1997+
[<Optional;DefaultParameterValue(null)>] ?ShowMarkers,
1998+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
1999+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
2000+
[<Optional;DefaultParameterValue(null)>] ?Color,
2001+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
2002+
[<Optional;DefaultParameterValue(null)>] ?Labels,
2003+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
2004+
[<Optional;DefaultParameterValue(null)>] ?TextFont,
2005+
[<Optional;DefaultParameterValue(null)>] ?Dash,
2006+
[<Optional;DefaultParameterValue(null)>] ?Width
2007+
) =
2008+
let x, y, z = Seq.unzip3 xyz
2009+
2010+
Chart.Line3d(
2011+
x, y, z,
2012+
?Name = Name ,
2013+
?ShowMarkers = ShowMarkers ,
2014+
?Showlegend = Showlegend ,
2015+
?MarkerSymbol = MarkerSymbol,
2016+
?Color = Color ,
2017+
?Opacity = Opacity ,
2018+
?Labels = Labels ,
2019+
?TextPosition = TextPosition,
2020+
?TextFont = TextFont ,
2021+
?Dash = Dash ,
2022+
?Width = Width
2023+
)
2024+
2025+
///
2026+
static member Bubble3d
2027+
(
2028+
x, y, z, sizes,
2029+
[<Optional;DefaultParameterValue(null)>] ?Name,
2030+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
2031+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
2032+
[<Optional;DefaultParameterValue(null)>] ?Color,
2033+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
2034+
[<Optional;DefaultParameterValue(null)>] ?Labels,
2035+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
2036+
[<Optional;DefaultParameterValue(null)>] ?TextFont
2037+
) =
2038+
let changeMode = StyleParam.ModeUtils.showText (TextPosition.IsSome || TextFont.IsSome)
2039+
2040+
Trace3d.initScatter3d (
2041+
Trace3dStyle.Scatter3d(
2042+
X = x,
2043+
Y = y,
2044+
Z = z,
2045+
Mode=changeMode StyleParam.Mode.Markers
2046+
)
2047+
)
2048+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
2049+
|> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol, MultiSizes=sizes)
2050+
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
2051+
|> GenericChart.ofTraceObject
2052+
2053+
///
2054+
static member Bubble3d
2055+
(
2056+
xyz, sizes,
2057+
[<Optional;DefaultParameterValue(null)>] ?Name,
2058+
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
2059+
[<Optional;DefaultParameterValue(null)>] ?MarkerSymbol,
2060+
[<Optional;DefaultParameterValue(null)>] ?Color,
2061+
[<Optional;DefaultParameterValue(null)>] ?Opacity,
2062+
[<Optional;DefaultParameterValue(null)>] ?Labels,
2063+
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
2064+
[<Optional;DefaultParameterValue(null)>] ?TextFont
2065+
) =
2066+
let x, y, z = Seq.unzip3 xyz
2067+
2068+
Chart.Bubble3d(
2069+
x, y, z, sizes,
2070+
?Name = Name,
2071+
?Showlegend = Showlegend,
2072+
?MarkerSymbol = MarkerSymbol,
2073+
?Color = Color,
2074+
?Opacity = Opacity,
2075+
?Labels = Labels,
2076+
?TextPosition = TextPosition,
2077+
?TextFont = TextFont
2078+
)
2079+
2080+
18922081
/// Uses points, line or both depending on the mode to represent 3d-data points
18932082
static member Surface(data:seq<#seq<#IConvertible>>,
18942083
[<Optional;DefaultParameterValue(null)>] ?X,

src/Plotly.NET/Playground.fsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,31 @@ open Deedle
7878
open FSharpAux
7979

8080
open System
81-
let lineChart =
82-
let c = [0. .. 0.5 .. 15.]
83-
84-
let x, y, z =
85-
c
86-
|> List.map (fun i ->
87-
let i' = float i
88-
let r = 10. * Math.Cos (i' / 10.)
89-
(r * Math.Cos i', r * Math.Sin i', i')
90-
)
91-
|> List.unzip3
9281

93-
Chart.Scatter3d(x, y, z, StyleParam.Mode.Lines_Markers)
94-
|> Chart.withXAxisStyle("x-axis", Id=StyleParam.SubPlotId.Scene 1)
95-
|> Chart.withYAxisStyle("y-axis", Id=StyleParam.SubPlotId.Scene 1)
96-
|> Chart.withZAxisStyle("z-axis")
97-
|> Chart.withSize(800., 800.)
82+
Chart.Point3d(
83+
[1,2,3; 4,5,6; 7,8,9],
84+
Labels = ["A"; "B"; "C"],
85+
TextPosition = StyleParam.TextPosition.BottomCenter
86+
)
87+
|> Chart.show
9888

99-
lineChart
89+
Chart.Line3d(
90+
[1,3,2; 6,5,4; 7,9,8],
91+
Labels = ["A"; "B"; "C"],
92+
TextPosition = StyleParam.TextPosition.BottomCenter,
93+
ShowMarkers = true
94+
)
10095
|> Chart.show
10196

97+
Chart.Bubble3d(
98+
[1,3,2; 6,5,4; 7,9,8],
99+
[20; 40; 30],
100+
Labels = ["A"; "B"; "C"],
101+
TextPosition = StyleParam.TextPosition.TopLeft
102+
)
103+
|> Chart.show
104+
105+
102106
let linspace (min,max,n) =
103107
if n <= 2 then failwithf "n needs to be larger then 2"
104108
let bw = float (max - min) / (float n - 1.)

0 commit comments

Comments
 (0)