Skip to content

Commit 5edcbb1

Browse files
committed
Add encoded scatter-derived helper support
Summary: - add XEncoded and YEncoded support to the scatter-derived Chart2D helper roots Point, Line, Spline, Bubble, Area, SplineArea, and StackedArea - add XEncoded, YEncoded, UpperEncoded, and LowerEncoded support to Chart.Range where the helper owns all four bound arrays - keep tuple-based convenience overloads delegating as before while extending only the raw-array helper roots - add chart-level helper serialization and precedence tests for encoded arrays, including Range upper/lower coverage - replace the console sample with a focused H1-B encoded Chart.Range demo - keep the current C# wrapper surface source-compatible by forwarding None through the new F# encoded parameters for now Verification: - .\\build.cmd runTestsCore - 809 tests passed Notes: - plans/EncodedArraySupport.md was updated locally before commit and intentionally left uncommitted
1 parent 37006fd commit 5edcbb1

File tree

4 files changed

+198
-16
lines changed

4 files changed

+198
-16
lines changed

src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public static GenericChart Point<XType, YType, TextType>(
181181
Plotly.NET.Chart2D.Chart.Point(
182182
x: x,
183183
y: y,
184+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
185+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
184186
Name: Name.ToOption(),
185187
ShowLegend: ShowLegend.ToOption(),
186188
Opacity: Opacity.ToOption(),
@@ -278,6 +280,8 @@ public static GenericChart Line<XType, YType, TextType>(
278280
Plotly.NET.Chart2D.Chart.Line(
279281
x: x,
280282
y: y,
283+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
284+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
281285
ShowMarkers: ShowMarkers.ToOption(),
282286
Name: Name.ToOption(),
283287
ShowLegend: ShowLegend.ToOption(),
@@ -387,6 +391,8 @@ public static GenericChart Spline<XType, YType, TextType>(
387391
Plotly.NET.Chart2D.Chart.Spline(
388392
x: x,
389393
y: y,
394+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
395+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
390396
ShowMarkers: ShowMarkers.ToOption(),
391397
Smoothing: Smoothing.ToOption(),
392398
Name: Name.ToOption(),
@@ -489,6 +495,8 @@ public static GenericChart Bubble<XType, YType, TextType>(
489495
x: x,
490496
y: y,
491497
sizes: sizes,
498+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
499+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
492500
Name: Name.ToOption(),
493501
ShowLegend: ShowLegend.ToOption(),
494502
Opacity: Opacity.ToOption(),
@@ -610,6 +618,10 @@ public static GenericChart Range<XType, YType, TextType>(
610618
upper: upper,
611619
lower: lower,
612620
mode: mode,
621+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
622+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
623+
UpperEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
624+
LowerEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
613625
Name: Name.ToOption(),
614626
GroupName: GroupName.ToOption(),
615627
ShowMarkers: ShowMarkers.ToOption(),
@@ -761,6 +773,8 @@ public static GenericChart Area<XType, YType, TextType>(
761773
Plotly.NET.Chart2D.Chart.Area<XType, YType, TextType>(
762774
x: x,
763775
y: y,
776+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
777+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
764778
ShowMarkers: ShowMarkers.ToOption(),
765779
Name: Name.ToOption(),
766780
ShowLegend: ShowLegend.ToOption(),
@@ -869,6 +883,8 @@ public static GenericChart SplineArea<XType, YType, TextType>(
869883
Plotly.NET.Chart2D.Chart.SplineArea<XType, YType, TextType>(
870884
x: x,
871885
y: y,
886+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
887+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
872888
ShowMarkers: ShowMarkers.ToOption(),
873889
Smoothing: Smoothing.ToOption(),
874890
Name: Name.ToOption(),
@@ -970,6 +986,8 @@ public static GenericChart StackedArea<XType, YType, TextType>(
970986
Plotly.NET.Chart2D.Chart.StackedArea<XType, YType, TextType>(
971987
x: x,
972988
y: y,
989+
XEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
990+
YEncoded: Microsoft.FSharp.Core.FSharpOption<Plotly.NET.EncodedTypedArray>.None,
973991
ShowMarkers: ShowMarkers.ToOption(),
974992
Name: Name.ToOption(),
975993
ShowLegend: ShowLegend.ToOption(),

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ module Chart2D =
386386
/// Creates a Point chart, which uses Points in a 2D space to visualize data.
387387
/// </summary>
388388
/// <param name="x">Sets the x coordinates of the plotted data.</param>
389+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
389390
/// <param name="y">Sets the y coordinates of the plotted data.</param>
391+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
390392
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
391393
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
392394
/// <param name="Opacity">Sets the opactity of the trace</param>
@@ -413,6 +415,8 @@ module Chart2D =
413415
(
414416
x: seq<#IConvertible>,
415417
y: seq<#IConvertible>,
418+
?XEncoded: EncodedTypedArray,
419+
?YEncoded: EncodedTypedArray,
416420
?Name: string,
417421
?ShowLegend: bool,
418422
?Opacity: float,
@@ -441,9 +445,11 @@ module Chart2D =
441445
StyleParam.ModeUtils.showText (TextPosition.IsSome || MultiTextPosition.IsSome)
442446

443447
Chart.Scatter(
444-
x = x,
445-
y = y,
446-
mode = changeMode StyleParam.Mode.Markers,
448+
X = x,
449+
Y = y,
450+
?XEncoded = XEncoded,
451+
?YEncoded = YEncoded,
452+
Mode = changeMode StyleParam.Mode.Markers,
447453
?Name = Name,
448454
?ShowLegend = ShowLegend,
449455
?Opacity = Opacity,
@@ -548,7 +554,9 @@ module Chart2D =
548554

549555
/// <summary> Creates a Line chart, which uses a Line plotted between the given datums in a 2D space to visualize typically an evolution of Y depending on X.</summary>
550556
/// <param name="x">Sets the x coordinates of the plotted data.</param>
557+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
551558
/// <param name="y">Sets the y coordinates of the plotted data.</param>
559+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
552560
/// <param name="ShowMarkers">Whether to show markers for the individual data points</param>
553561
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
554562
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
@@ -584,6 +592,8 @@ module Chart2D =
584592
(
585593
x: seq<#IConvertible>,
586594
y: seq<#IConvertible>,
595+
?XEncoded: EncodedTypedArray,
596+
?YEncoded: EncodedTypedArray,
587597
?ShowMarkers: bool,
588598
?Name: string,
589599
?ShowLegend: bool,
@@ -627,9 +637,11 @@ module Chart2D =
627637
>> StyleParam.ModeUtils.showMarker (isShowMarker)
628638

629639
Chart.Scatter(
630-
x = x,
631-
y = y,
632-
mode = changeMode StyleParam.Mode.Lines,
640+
X = x,
641+
Y = y,
642+
?XEncoded = XEncoded,
643+
?YEncoded = YEncoded,
644+
Mode = changeMode StyleParam.Mode.Lines,
633645
?Name = Name,
634646
?ShowLegend = ShowLegend,
635647
?Opacity = Opacity,
@@ -673,6 +685,8 @@ module Chart2D =
673685
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
674686
/// <param name="Text">Sets a text associated with each datum</param>
675687
/// <param name="MultiText">Sets individual text for each datum</param>
688+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
689+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
676690
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
677691
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
678692
/// <param name="MarkerColor">Sets the color of the marker</param>
@@ -809,6 +823,8 @@ module Chart2D =
809823
(
810824
x: seq<#IConvertible>,
811825
y: seq<#IConvertible>,
826+
?XEncoded: EncodedTypedArray,
827+
?YEncoded: EncodedTypedArray,
812828
?ShowMarkers: bool,
813829
?Smoothing: float,
814830
?Name: string,
@@ -883,7 +899,9 @@ module Chart2D =
883899
let style =
884900
Trace2DStyle.Scatter(
885901
X = x,
902+
?XEncoded = XEncoded,
886903
Y = y,
904+
?YEncoded = YEncoded,
887905
Mode = changeMode StyleParam.Mode.Lines,
888906
Marker = marker,
889907
Line = line,
@@ -922,6 +940,8 @@ module Chart2D =
922940
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
923941
/// <param name="Text">Sets a text associated with each datum</param>
924942
/// <param name="MultiText">Sets individual text for each datum</param>
943+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
944+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
925945
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
926946
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
927947
/// <param name="MarkerColor">Sets the color of the marker</param>
@@ -1057,6 +1077,8 @@ module Chart2D =
10571077
x: seq<#IConvertible>,
10581078
y: seq<#IConvertible>,
10591079
sizes: seq<int>,
1080+
?XEncoded: EncodedTypedArray,
1081+
?YEncoded: EncodedTypedArray,
10601082
?Name: string,
10611083
?ShowLegend: bool,
10621084
?Opacity: float,
@@ -1118,7 +1140,9 @@ module Chart2D =
11181140
let style =
11191141
Trace2DStyle.Scatter(
11201142
X = x,
1143+
?XEncoded = XEncoded,
11211144
Y = y,
1145+
?YEncoded = YEncoded,
11221146
Mode = changeMode StyleParam.Mode.Markers,
11231147
Marker = marker,
11241148
Line = line,
@@ -1240,9 +1264,13 @@ module Chart2D =
12401264
/// The mid Y value usually resembles some kind of central tendency and the upper/lower Y values some kind of spread.
12411265
/// </summary>
12421266
/// <param name="x">Sets the x coordinates of the plotted data.</param>
1267+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
12431268
/// <param name="y">Sets the y coordinates of the plotted data for the mid Y value.</param>
1269+
/// <param name="YEncoded">Sets the y coordinates of the plotted data for the mid Y value as an encoded typed array.</param>
12441270
/// <param name="upper">Sets the y coordinates of the plotted data for the upper Y value.</param>
1271+
/// <param name="UpperEncoded">Sets the y coordinates of the plotted data for the upper Y value as an encoded typed array.</param>
12451272
/// <param name="lower">Sets the y coordinates of the plotted data for the lower Y value.</param>
1273+
/// <param name="LowerEncoded">Sets the y coordinates of the plotted data for the lower Y value as an encoded typed array.</param>
12461274
/// <param name="mode">Determines the drawing mode for this scatter trace.</param>
12471275
/// <param name="Name">Sets the trace name of the mid Y values. The trace name appear as the legend item and on hover</param>
12481276
/// <param name="GroupName">Sets the name of the legendgroup for the three traces of this plot.</param>
@@ -1285,6 +1313,10 @@ module Chart2D =
12851313
upper: seq<#IConvertible>,
12861314
lower: seq<#IConvertible>,
12871315
mode: StyleParam.Mode,
1316+
?XEncoded: EncodedTypedArray,
1317+
?YEncoded: EncodedTypedArray,
1318+
?UpperEncoded: EncodedTypedArray,
1319+
?LowerEncoded: EncodedTypedArray,
12881320
?Name: string,
12891321
?GroupName: string,
12901322
?ShowMarkers: bool,
@@ -1338,9 +1370,11 @@ module Chart2D =
13381370

13391371
let trace =
13401372
Chart.Scatter(
1341-
x = x,
1342-
y = y,
1343-
mode = changeMode mode,
1373+
X = x,
1374+
Y = y,
1375+
?XEncoded = XEncoded,
1376+
?YEncoded = YEncoded,
1377+
Mode = changeMode mode,
13441378
?Name = Name,
13451379
?ShowLegend = ShowLegend,
13461380
?Text = Text,
@@ -1370,7 +1404,9 @@ module Chart2D =
13701404
Trace2D.initScatter (
13711405
Trace2DStyle.Scatter(
13721406
X = x,
1407+
?XEncoded = XEncoded,
13731408
Y = lower,
1409+
?YEncoded = LowerEncoded,
13741410
Mode = changeMode mode,
13751411
?FillColor = RangeColor,
13761412
?Name = Some lowerName,
@@ -1396,7 +1432,9 @@ module Chart2D =
13961432
Trace2D.initScatter (
13971433
Trace2DStyle.Scatter(
13981434
X = x,
1435+
?XEncoded = XEncoded,
13991436
Y = upper,
1437+
?YEncoded = UpperEncoded,
14001438
Mode = changeMode mode,
14011439
Fill = StyleParam.Fill.ToNext_y,
14021440
?FillColor = RangeColor,
@@ -1571,6 +1609,8 @@ module Chart2D =
15711609
/// <param name="MarkerOutline">Sets the outline of the marker</param>
15721610
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
15731611
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
1612+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
1613+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
15741614
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
15751615
/// <param name="LineColor">Sets the color of the line</param>
15761616
/// <param name="LineColorScale">Sets the colorscale of the line</param>
@@ -1592,6 +1632,8 @@ module Chart2D =
15921632
(
15931633
x: seq<#IConvertible>,
15941634
y: seq<#IConvertible>,
1635+
?XEncoded: EncodedTypedArray,
1636+
?YEncoded: EncodedTypedArray,
15951637
?ShowMarkers: bool,
15961638
?Name: string,
15971639
?ShowLegend: bool,
@@ -1632,6 +1674,8 @@ module Chart2D =
16321674
Chart.Line(
16331675
x = x,
16341676
y = y,
1677+
?XEncoded = XEncoded,
1678+
?YEncoded = YEncoded,
16351679
Fill = StyleParam.Fill.ToZero_y,
16361680
?ShowMarkers = ShowMarkers,
16371681
?Name = Name,
@@ -1682,6 +1726,8 @@ module Chart2D =
16821726
/// <param name="MarkerOutline">Sets the outline of the marker</param>
16831727
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
16841728
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
1729+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
1730+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
16851731
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
16861732
/// <param name="LineColor">Sets the color of the line</param>
16871733
/// <param name="LineColorScale">Sets the colorscale of the line</param>
@@ -1811,6 +1857,8 @@ module Chart2D =
18111857
(
18121858
x: seq<#IConvertible>,
18131859
y: seq<#IConvertible>,
1860+
?XEncoded: EncodedTypedArray,
1861+
?YEncoded: EncodedTypedArray,
18141862
?ShowMarkers: bool,
18151863
?Smoothing: float,
18161864
?Name: string,
@@ -1852,6 +1900,8 @@ module Chart2D =
18521900
Chart.Spline(
18531901
x = x,
18541902
y = y,
1903+
?XEncoded = XEncoded,
1904+
?YEncoded = YEncoded,
18551905
Fill = StyleParam.Fill.ToZero_y,
18561906
?ShowMarkers = ShowMarkers,
18571907
?Smoothing = Smoothing,
@@ -1903,6 +1953,8 @@ module Chart2D =
19031953
/// <param name="MarkerOutline">Sets the outline of the marker</param>
19041954
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
19051955
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
1956+
/// <param name="XEncoded">Sets the x coordinates of the plotted data as an encoded typed array.</param>
1957+
/// <param name="YEncoded">Sets the y coordinates of the plotted data as an encoded typed array.</param>
19061958
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
19071959
/// <param name="LineColor">Sets the color of the line</param>
19081960
/// <param name="LineColorScale">Sets the colorscale of the line</param>
@@ -2028,6 +2080,8 @@ module Chart2D =
20282080
(
20292081
x: seq<#IConvertible>,
20302082
y: seq<#IConvertible>,
2083+
?XEncoded: EncodedTypedArray,
2084+
?YEncoded: EncodedTypedArray,
20312085
?ShowMarkers: bool,
20322086
?Name: string,
20332087
?ShowLegend: bool,
@@ -2065,6 +2119,8 @@ module Chart2D =
20652119
Chart.Line(
20662120
x = x,
20672121
y = y,
2122+
?XEncoded = XEncoded,
2123+
?YEncoded = YEncoded,
20682124
Fill = StyleParam.Fill.ToNext_y,
20692125
?ShowMarkers = ShowMarkers,
20702126
?Name = Name,

tests/ConsoleApps/FSharpConsole/Program.fs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@ open Plotly.NET
44
[<EntryPoint>]
55
let main _ =
66

7-
let pointCount = 500
7+
let pointCount = 250
88
let xs = [| for i in 0 .. pointCount - 1 -> float i * 2.0 * Math.PI / float (pointCount - 1) |]
99
let ys = xs |> Array.map sin
10+
let band = xs |> Array.map (fun x -> 0.15 + 0.1 * abs (cos x))
11+
let upper = Array.map2 (+) ys band
12+
let lower = Array.map2 (-) ys band
1013

11-
let chartScatterEncodedPoC =
12-
Chart.Scatter(
14+
let chartRangeEncodedHelperPoC =
15+
Chart.Range(
16+
x = xs,
17+
y = ys,
18+
upper = upper,
19+
lower = lower,
1320
XEncoded = EncodedTypedArray.ofFloat64Array xs,
1421
YEncoded = EncodedTypedArray.ofFloat64Array ys,
15-
Mode = StyleParam.Mode.Lines_Markers,
16-
Name = "sin(x) via Chart.Scatter",
22+
UpperEncoded = EncodedTypedArray.ofFloat64Array upper,
23+
LowerEncoded = EncodedTypedArray.ofFloat64Array lower,
24+
mode = StyleParam.Mode.Lines,
25+
Name = "sin(x)",
26+
GroupName = "confidence band",
27+
RangeColor = Color.fromString "rgba(24,119,242,0.2)",
28+
LineColor = Color.fromString "#1877f2",
1729
UseDefaults = true
1830
)
19-
|> Chart.withTitle "H1 PoC: Chart.Scatter with encoded x/y"
31+
|> Chart.withTitle "H1-B: scatter-derived helper with encoded arrays"
2032

21-
chartScatterEncodedPoC |> Chart.show
33+
chartRangeEncodedHelperPoC |> Chart.show
2234

2335
0

0 commit comments

Comments
 (0)