Skip to content

Commit 43ff986

Browse files
committed
Complete encoded scatter fields and error arrays
Summary: - add encoded typed-array inputs for Scatter ids, customdata, selectedpoints, and per-point text - add encoded typed-array inputs for Error.array and Error.arrayminus - keep the existing plain-array API surface intact while making the encoded path override the plain path on the same property - extend the low-level EncodedTypedArray tests with scatter override/integration cases, direct Error serialization coverage, and explicit arrayminus precedence checks - expand the PlotlyJS 2.28 upstream feature fixture to include a fully encoded scatter with encoded error bars and assert the end-to-end HTML output - add the matching FSharpConsole manual demo for the fully encoded scatter-with-error-bars path Files: - src/Plotly.NET/Traces/Trace2D.fs - src/Plotly.NET/Traces/ObjectAbstractions/Error.fs - tests/CoreTests/CoreTests/CommonAbstractions/EncodedTypedArray.fs - tests/Common/FSharpTestBase/TestCharts/UpstreamFeatures/2.28.fs - tests/CoreTests/CoreTests/UpstreamFeatures/2.28.fs - tests/ConsoleApps/FSharpConsole/Program.fs Verification: - .\\build.cmd runTestsCore - 725 tests passed
1 parent 62a9650 commit 43ff986

File tree

6 files changed

+267
-11
lines changed

6 files changed

+267
-11
lines changed

src/Plotly.NET/Traces/ObjectAbstractions/Error.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type Error() =
1818
/// <param name ="Symmetric">Determines whether or not the error bars have the same length in both direction (top/bottom for vertical bars, left/right for horizontal bars.</param>
1919
/// <param name ="Array">Sets the data corresponding the length of each error bar. Values are plotted relative to the underlying data.</param>
2020
/// <param name ="Arrayminus">Sets the data corresponding the length of each error bar in the bottom (left) direction for vertical (horizontal) bars Values are plotted relative to the underlying data.</param>
21+
/// <param name ="ArrayEncoded">Sets the error-bar lengths as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Array</c>.</param>
22+
/// <param name ="ArrayminusEncoded">Sets the negative-direction error-bar lengths as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Arrayminus</c>.</param>
2123
/// <param name ="Value">Sets the value of either the percentage (if `type` is set to "percent") or the constant (if `type` is set to "constant") corresponding to the lengths of the error bars.</param>
2224
/// <param name ="Valueminus">Sets the value of either the percentage (if `type` is set to "percent") or the constant (if `type` is set to "constant") corresponding to the lengths of the error bars in the bottom (left) direction for vertical (horizontal) bars</param>
2325
/// <param name ="Traceref"></param>
@@ -33,6 +35,8 @@ type Error() =
3335
?Symmetric: bool,
3436
?Array: seq<#IConvertible>,
3537
?Arrayminus: seq<#IConvertible>,
38+
?ArrayEncoded: EncodedTypedArray,
39+
?ArrayminusEncoded: EncodedTypedArray,
3640
?Value: float,
3741
?Valueminus: float,
3842
?Traceref: int,
@@ -49,6 +53,8 @@ type Error() =
4953
?Symmetric = Symmetric,
5054
?Array = Array,
5155
?Arrayminus = Arrayminus,
56+
?ArrayEncoded = ArrayEncoded,
57+
?ArrayminusEncoded = ArrayminusEncoded,
5258
?Value = Value,
5359
?Valueminus = Valueminus,
5460
?Traceref = Traceref,
@@ -67,6 +73,8 @@ type Error() =
6773
/// <param name ="Symmetric">Determines whether or not the error bars have the same length in both direction (top/bottom for vertical bars, left/right for horizontal bars.</param>
6874
/// <param name ="Array">Sets the data corresponding the length of each error bar. Values are plotted relative to the underlying data.</param>
6975
/// <param name ="Arrayminus">Sets the data corresponding the length of each error bar in the bottom (left) direction for vertical (horizontal) bars Values are plotted relative to the underlying data.</param>
76+
/// <param name ="ArrayEncoded">Sets the error-bar lengths as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Array</c>.</param>
77+
/// <param name ="ArrayminusEncoded">Sets the negative-direction error-bar lengths as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Arrayminus</c>.</param>
7078
/// <param name ="Value">Sets the value of either the percentage (if `type` is set to "percent") or the constant (if `type` is set to "constant") corresponding to the lengths of the error bars.</param>
7179
/// <param name ="Valueminus">Sets the value of either the percentage (if `type` is set to "percent") or the constant (if `type` is set to "constant") corresponding to the lengths of the error bars in the bottom (left) direction for vertical (horizontal) bars</param>
7280
/// <param name ="Traceref"></param>
@@ -82,6 +90,8 @@ type Error() =
8290
?Symmetric: bool,
8391
?Array: seq<#IConvertible>,
8492
?Arrayminus: seq<#IConvertible>,
93+
?ArrayEncoded: EncodedTypedArray,
94+
?ArrayminusEncoded: EncodedTypedArray,
8595
?Value: float,
8696
?Valueminus: float,
8797
?Traceref: int,
@@ -99,6 +109,8 @@ type Error() =
99109
|> DynObj.withOptionalProperty "symmetric" Symmetric
100110
|> DynObj.withOptionalProperty "array" Array
101111
|> DynObj.withOptionalProperty "arrayminus" Arrayminus
112+
|> DynObj.withOptionalProperty "array" ArrayEncoded
113+
|> DynObj.withOptionalProperty "arrayminus" ArrayminusEncoded
102114
|> DynObj.withOptionalProperty "value" Value
103115
|> DynObj.withOptionalProperty "valueminus" Valueminus
104116
|> DynObj.withOptionalProperty "traceref" Traceref

src/Plotly.NET/Traces/Trace2D.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type Trace2DStyle() =
121121
/// <param name="Opacity">Sets the opacity of the trace.</param>
122122
/// <param name="Mode">Determines the drawing mode for this scatter trace. If the provided `mode` includes "text" then the `text` elements appear at the coordinates. Otherwise, the `text` elements appear on hover. If there are less than 20 points and the trace is not stacked then the default is "lines+markers". Otherwise, "lines".</param>
123123
/// <param name="Ids">Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.</param>
124+
/// <param name="IdsEncoded">Assigns id labels as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Ids</c>.</param>
124125
/// <param name="X">Sets the x coordinates.</param>
125126
/// <param name="MultiX">Sets the x coordinates.</param>
126127
/// <param name="X0">Alternate to `x`. Builds a linear space of x coordinates. Use with `dx` where `x0` is the starting coordinate and `dx` the step.</param>
@@ -131,6 +132,7 @@ type Trace2DStyle() =
131132
/// <param name="DY">Sets the y coordinate step. See `y0` for more info.</param>
132133
/// <param name="Text">Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.</param>
133134
/// <param name="MultiText">Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.</param>
135+
/// <param name="MultiTextEncoded">Sets the per-point text array as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>Text</c>/<c>MultiText</c>.</param>
134136
/// <param name="TextPosition">Sets the positions of the `text` elements with respects to the (x,y) coordinates.</param>
135137
/// <param name="MultiTextPosition">Sets the positions of the `text` elements with respects to the (x,y) coordinates.</param>
136138
/// <param name="TextTemplate">Template string used for rendering the information text that appear on points. Note that this will override `textinfo`. Variables are inserted using %{variable}, for example "y: %{y}". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.</param>
@@ -144,6 +146,7 @@ type Trace2DStyle() =
144146
/// <param name="YHoverFormat">Sets the hover text formatting rulefor `y` using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display "09~15~23.46"By default the values are formatted using `xaxis.hoverformat`.</param>
145147
/// <param name="Meta">Assigns extra meta information associated with this trace that can be used in various text attributes. Attributes such as trace `name`, graph, axis and colorbar `title.text`, annotation `text` `rangeselector`, `updatemenues` and `sliders` `label` text all support `meta`. To access the trace `meta` values in an attribute in the same trace, simply use `%{meta[i]}` where `i` is the index or key of the `meta` item in question. To access trace `meta` in layout attributes, use `%{data[n[.meta[i]}` where `i` is the index or key of the `meta` and `n` is the trace index.</param>
146148
/// <param name="CustomData">Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, "scatter" traces also appends customdata items in the markers DOM elements</param>
149+
/// <param name="CustomDataEncoded">Assigns extra data for each datum as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>CustomData</c>.</param>
147150
/// <param name="XAxis">Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If "x" (the default value), the x coordinates refer to `layout.xaxis`. If "x2", the x coordinates refer to `layout.xaxis2`, and so on.</param>
148151
/// <param name="YAxis">Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If "y" (the default value), the y coordinates refer to `layout.yaxis`. If "y2", the y coordinates refer to `layout.yaxis2`, and so on.</param>
149152
/// <param name="Orientation">Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used - including if `visible` is "legendonly" but not if it is `false`. Sets the stacking direction. With "v" ("h"), the y (x) values of subsequent traces are added. Also affects the default value of `fill`.</param>
@@ -163,6 +166,7 @@ type Trace2DStyle() =
163166
/// <param name="XError">Sets the x error of this trace.</param>
164167
/// <param name="YError">Sets the y error of this trace.</param>
165168
/// <param name="SelectedPoints">Array containing integer indices of selected points. Has an effect only for traces that support selections. Note that an empty array means an empty selection where the `unselected` are turned on for all points, whereas, any other non-array values means no selection all where the `selected` and `unselected` styles have no effect.</param>
169+
/// <param name="SelectedPointsEncoded">Sets the selected-point indices as a base64-encoded typed array (plotly.js &gt;= 2.28.0). If provided, overrides <c>SelectedPoints</c>.</param>
166170
/// <param name="Selected">Sets the style of selected points of this trace.</param>
167171
/// <param name="Unselected">Sets the style of unselected points of this trace.</param>
168172
/// <param name="ClipOnAxis">Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to "below traces".</param>
@@ -190,6 +194,7 @@ type Trace2DStyle() =
190194
?Opacity: float,
191195
?Mode: StyleParam.Mode,
192196
?Ids: seq<#IConvertible>,
197+
?IdsEncoded: EncodedTypedArray,
193198
?X: seq<#IConvertible>,
194199
?MultiX: seq<seq<#IConvertible>>,
195200
?X0: #IConvertible,
@@ -200,6 +205,7 @@ type Trace2DStyle() =
200205
?DY: #IConvertible,
201206
?Text: #IConvertible,
202207
?MultiText: seq<#IConvertible>,
208+
?MultiTextEncoded: EncodedTypedArray,
203209
?TextPosition: StyleParam.TextPosition,
204210
?MultiTextPosition: seq<StyleParam.TextPosition>,
205211
?TextTemplate: string,
@@ -213,6 +219,7 @@ type Trace2DStyle() =
213219
?YHoverFormat: string,
214220
?Meta: string,
215221
?CustomData: seq<#IConvertible>,
222+
?CustomDataEncoded: EncodedTypedArray,
216223
?XAxis: StyleParam.LinearAxisId,
217224
?YAxis: StyleParam.LinearAxisId,
218225
?Orientation: StyleParam.Orientation,
@@ -232,6 +239,7 @@ type Trace2DStyle() =
232239
?XError: Error,
233240
?YError: Error,
234241
?SelectedPoints: seq<#IConvertible>,
242+
?SelectedPointsEncoded: EncodedTypedArray,
235243
?Selected: TraceSelection,
236244
?Unselected: TraceSelection,
237245
?ClipOnAxis: bool,
@@ -260,6 +268,7 @@ type Trace2DStyle() =
260268
|> DynObj.withOptionalProperty "opacity" Opacity
261269
|> DynObj.withOptionalPropertyBy "mode" Mode StyleParam.Mode.convert
262270
|> DynObj.withOptionalProperty "ids" Ids
271+
|> DynObj.withOptionalProperty "ids" IdsEncoded
263272
|> DynObj.withOptionalSingleOrMultiProperty "x" (X, MultiX)
264273
|> DynObj.withOptionalProperty "x" XEncoded
265274
|> DynObj.withOptionalProperty "x0" X0
@@ -269,6 +278,7 @@ type Trace2DStyle() =
269278
|> DynObj.withOptionalProperty "y0" Y0
270279
|> DynObj.withOptionalProperty "dy" DY
271280
|> DynObj.withOptionalSingleOrMultiProperty "text" (Text, MultiText)
281+
|> DynObj.withOptionalProperty "text" MultiTextEncoded
272282
|> DynObj.withOptionalSingleOrMultiPropertyBy"textposition" (TextPosition, MultiTextPosition) StyleParam.TextPosition.convert
273283
|> DynObj.withOptionalSingleOrMultiProperty "texttemplate" (TextTemplate, MultiTextTemplate)
274284
|> DynObj.withOptionalSingleOrMultiProperty "hovertext" (HoverText, MultiHoverText)
@@ -278,6 +288,7 @@ type Trace2DStyle() =
278288
|> DynObj.withOptionalProperty "yhoverformat" YHoverFormat
279289
|> DynObj.withOptionalProperty "meta" Meta
280290
|> DynObj.withOptionalProperty "customdata" CustomData
291+
|> DynObj.withOptionalProperty "customdata" CustomDataEncoded
281292
|> DynObj.withOptionalPropertyBy "xaxis" XAxis StyleParam.LinearAxisId.convert
282293
|> DynObj.withOptionalPropertyBy "yaxis" YAxis StyleParam.LinearAxisId.convert
283294
|> DynObj.withOptionalPropertyBy "orientation" Orientation StyleParam.Orientation.convert
@@ -297,6 +308,7 @@ type Trace2DStyle() =
297308
|> DynObj.withOptionalProperty "error_x" XError
298309
|> DynObj.withOptionalProperty "error_y" YError
299310
|> DynObj.withOptionalProperty "selectedpoints" SelectedPoints
311+
|> DynObj.withOptionalProperty "selectedpoints" SelectedPointsEncoded
300312
|> DynObj.withOptionalProperty "selected" Selected
301313
|> DynObj.withOptionalProperty "unselected" Unselected
302314
|> DynObj.withOptionalProperty "cliponaxis" ClipOnAxis

tests/Common/FSharpTestBase/TestCharts/UpstreamFeatures/2.28.fs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module PlotlyJS_2_28_TestCharts
22

33
open Plotly.NET
4+
open Plotly.NET.TraceObjects
45

56
module ``Encoded typed arrays`` =
67

@@ -17,3 +18,39 @@ module ``Encoded typed arrays`` =
1718
)
1819
)
1920
|> GenericChart.ofTraceObject true
21+
22+
let ``Scatter fully encoded with error bars`` =
23+
let xEncoded = EncodedTypedArray.ofFloat64Array [| 1.0; 2.0; 3.0 |]
24+
let yEncoded = EncodedTypedArray.ofFloat64Array [| 4.0; 5.0; 6.0 |]
25+
let idsEncoded = EncodedTypedArray.ofInt32Array [| 101; 102; 103 |]
26+
let customDataEncoded = EncodedTypedArray.ofFloat64Array [| 10.0; 20.0; 30.0 |]
27+
let selectedPointsEncoded = EncodedTypedArray.ofInt32Array [| 0; 2 |]
28+
let multiTextEncoded = EncodedTypedArray.ofFloat64Array [| 7.0; 8.0; 9.0 |]
29+
let xErrorEncoded = EncodedTypedArray.ofFloat64Array [| 0.1; 0.2; 0.3 |]
30+
let yErrorEncoded = EncodedTypedArray.ofFloat64Array [| 0.4; 0.5; 0.6 |]
31+
let yErrorMinusEncoded = EncodedTypedArray.ofFloat64Array [| 0.3; 0.2; 0.1 |]
32+
33+
Trace2D.initScatter (
34+
Trace2DStyle.Scatter(
35+
Name = "encoded scatter + error bars",
36+
Mode = StyleParam.Mode.Lines_Markers,
37+
XEncoded = xEncoded,
38+
YEncoded = yEncoded,
39+
IdsEncoded = idsEncoded,
40+
CustomDataEncoded = customDataEncoded,
41+
SelectedPointsEncoded = selectedPointsEncoded,
42+
MultiTextEncoded = multiTextEncoded,
43+
XError =
44+
Error.init(
45+
Type = StyleParam.ErrorType.Data,
46+
ArrayEncoded = xErrorEncoded
47+
),
48+
YError =
49+
Error.init(
50+
Type = StyleParam.ErrorType.Data,
51+
ArrayEncoded = yErrorEncoded,
52+
ArrayminusEncoded = yErrorMinusEncoded
53+
)
54+
)
55+
)
56+
|> GenericChart.ofTraceObject true

0 commit comments

Comments
 (0)