Skip to content

Commit 2f94e87

Browse files
committed
plotly.js v2.19.0: Add label attribute to shapes (plotly/plotly.js#6454)
1 parent 5cc0143 commit 2f94e87

File tree

14 files changed

+231
-73
lines changed

14 files changed

+231
-73
lines changed

Diff for: src/Plotly.NET/CommonAbstractions/StyleParams.fs

+11
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,17 @@ module StyleParam =
30793079
//--------------------------
30803080
// #T#
30813081
//--------------------------
3082+
[<RequireQualifiedAccess>]
3083+
type TextAngle =
3084+
| Auto
3085+
| Degrees of float
3086+
3087+
static member convert =
3088+
function
3089+
| Auto -> box "auto"
3090+
| Degrees d -> box d
3091+
3092+
member this.Convert() = this |> TextAngle.convert
30823093

30833094
[<RequireQualifiedAccess>]
30843095
type TriangulationAlgorithm =

Diff for: src/Plotly.NET/Globals.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open Giraffe.ViewEngine
77

88
/// The plotly js version loaded from cdn in rendered html docs
99
[<Literal>]
10-
let PLOTLYJS_VERSION = "2.18.1"
10+
let PLOTLYJS_VERSION = "2.19.1"
1111

1212
[<Literal>]
1313
let SCRIPT_TEMPLATE =

Diff for: src/Plotly.NET/InternalUtils.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let getFullPlotlyJS () =
2525
Assembly.GetExecutingAssembly()
2626

2727
use str =
28-
assembly.GetManifestResourceStream("Plotly.NET.plotly-2.18.1.min.js")
28+
assembly.GetManifestResourceStream($"Plotly.NET.plotly-{Globals.PLOTLYJS_VERSION}.min.js")
2929

3030
use r = new StreamReader(str)
3131
r.ReadToEnd()

Diff for: src/Plotly.NET/Layout/ObjectAbstractions/Common/Shape.fs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Shape() =
1515
/// <param name="Editable">Determines whether the shape could be activated for edit or not. Has no effect when the older editable shapes mode is enabled via `config.editable` or `config.edits.shapePosition`.</param>
1616
/// <param name="FillColor">Sets the color filling the shape's interior. Only applies to closed shapes.</param>
1717
/// <param name="FillRule">Determines which regions of complex paths constitute the interior. For more info please visit https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule</param>
18+
/// <param name="Label">The text label of this shape.</param>
1819
/// <param name="Layer">Specifies whether shapes are drawn below or above traces.</param>
1920
/// <param name="Line">Sets the Shape outline</param>
2021
/// <param name="Name">When used in a template, named items are created in the output figure in addition to any items the figure already has in this array. You can modify these items in the output figure by making your own item with `templateitemname` matching this `name` alongside your modifications (including `visible: false` or `enabled: false` to hide it). Has no effect outside of a template.</param>
@@ -38,6 +39,7 @@ type Shape() =
3839
[<Optional; DefaultParameterValue(null)>] ?Editable: bool,
3940
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
4041
[<Optional; DefaultParameterValue(null)>] ?FillRule: StyleParam.FillRule,
42+
[<Optional; DefaultParameterValue(null)>] ?Label: ShapeLabel,
4143
[<Optional; DefaultParameterValue(null)>] ?Layer: StyleParam.Layer,
4244
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
4345
[<Optional; DefaultParameterValue(null)>] ?Name: string,
@@ -62,6 +64,7 @@ type Shape() =
6264
?Editable = Editable,
6365
?FillColor = FillColor,
6466
?FillRule = FillRule,
67+
?Label = Label,
6568
?Layer = Layer,
6669
?Line = Line,
6770
?Name = Name,
@@ -88,6 +91,7 @@ type Shape() =
8891
/// <param name="Editable">Determines whether the shape could be activated for edit or not. Has no effect when the older editable shapes mode is enabled via `config.editable` or `config.edits.shapePosition`.</param>
8992
/// <param name="FillColor">Sets the color filling the shape's interior. Only applies to closed shapes.</param>
9093
/// <param name="FillRule">Determines which regions of complex paths constitute the interior. For more info please visit https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule</param>
94+
/// <param name="Label">The text label of this shape.</param>
9195
/// <param name="Layer">Specifies whether shapes are drawn below or above traces.</param>
9296
/// <param name="Line">Sets the Shape outline</param>
9397
/// <param name="Name">When used in a template, named items are created in the output figure in addition to any items the figure already has in this array. You can modify these items in the output figure by making your own item with `templateitemname` matching this `name` alongside your modifications (including `visible: false` or `enabled: false` to hide it). Has no effect outside of a template.</param>
@@ -111,6 +115,7 @@ type Shape() =
111115
[<Optional; DefaultParameterValue(null)>] ?Editable: bool,
112116
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
113117
[<Optional; DefaultParameterValue(null)>] ?FillRule: StyleParam.FillRule,
118+
[<Optional; DefaultParameterValue(null)>] ?Label: ShapeLabel,
114119
[<Optional; DefaultParameterValue(null)>] ?Layer: StyleParam.Layer,
115120
[<Optional; DefaultParameterValue(null)>] ?Line: Line,
116121
[<Optional; DefaultParameterValue(null)>] ?Name: string,
@@ -135,6 +140,7 @@ type Shape() =
135140
Editable |> DynObj.setValueOpt shape "editable"
136141
FillColor |> DynObj.setValueOpt shape "fillcolor"
137142
FillRule |> DynObj.setValueOptBy shape "fillrule" StyleParam.FillRule.convert
143+
Label |> DynObj.setValueOpt shape "label"
138144
Layer |> DynObj.setValueOptBy shape "layer" StyleParam.Layer.convert
139145
Line |> DynObj.setValueOpt shape "line"
140146
Name |> DynObj.setValueOpt shape "name"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
namespace Plotly.NET.LayoutObjects
2+
3+
open Plotly.NET
4+
open DynamicObj
5+
open System
6+
open System.Runtime.InteropServices
7+
8+
9+
///<summary>
10+
///The label of a shape.
11+
///</summary>
12+
type ShapeLabel() =
13+
inherit DynamicObj()
14+
15+
/// <summary>
16+
/// Returns a new ShapeLabel object with the given styling.
17+
/// </summary>
18+
/// <param name="Font">Sets the shape label text font.</param>
19+
/// <param name="Padding">Sets padding (in px) between edge of label and edge of shape.</param>
20+
/// <param name="Text">Sets padding (in px) between edge of label and edge of shape.</param>
21+
/// <param name="TextAngle">Sets padding (in px) between edge of label and edge of shape.</param>
22+
/// <param name="TextPosition">Sets the position of the label text relative to the shape. Supported values for rectangles, circles and paths are "top left", "top center", "top right", "middle left", "middle center", "middle right", "bottom left", "bottom center", and "bottom right". Supported values for lines are "start", "middle", and "end". Default: "middle center" for rectangles, circles, and paths; "middle" for lines.</param>
23+
/// <param name="XAnchor">Sets the label's horizontal position anchor This anchor binds the specified `textposition` to the "left", "center" or "right" of the label text. For example, if `textposition` is set to "top right" and `xanchor` to "right" then the right-most portion of the label text lines up with the right-most edge of the shape.</param>
24+
/// <param name="YAnchor">Sets the label's vertical position anchor This anchor binds the specified `textposition` to the "top", "middle" or "bottom" of the label text. For example, if `textposition` is set to "top right" and `yanchor` to "top" then the top-most portion of the label text lines up with the top-most edge of the shape.</param>
25+
static member init
26+
(
27+
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
28+
[<Optional; DefaultParameterValue(null)>] ?Padding: int,
29+
[<Optional; DefaultParameterValue(null)>] ?Text: string,
30+
[<Optional; DefaultParameterValue(null)>] ?TextAngle: StyleParam.TextAngle,
31+
[<Optional; DefaultParameterValue(null)>] ?TextPosition: StyleParam.TextPosition,
32+
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
33+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition
34+
) =
35+
36+
ShapeLabel()
37+
|> ShapeLabel.style (
38+
?Font = Font,
39+
?Padding = Padding,
40+
?Text = Text,
41+
?TextAngle = TextAngle,
42+
?TextPosition = TextPosition,
43+
?XAnchor = XAnchor,
44+
?YAnchor = YAnchor
45+
)
46+
47+
/// <summary>
48+
/// Returns a function that applies the given styles to a ShapeLabel object
49+
/// </summary>
50+
/// <param name="Font">Sets the shape label text font.</param>
51+
/// <param name="Padding">Sets padding (in px) between edge of label and edge of shape.</param>
52+
/// <param name="Text">Sets padding (in px) between edge of label and edge of shape.</param>
53+
/// <param name="TextAngle">Sets padding (in px) between edge of label and edge of shape.</param>
54+
/// <param name="TextPosition">Sets the position of the label text relative to the shape. Supported values for rectangles, circles and paths are "top left", "top center", "top right", "middle left", "middle center", "middle right", "bottom left", "bottom center", and "bottom right". Supported values for lines are "start", "middle", and "end". Default: "middle center" for rectangles, circles, and paths; "middle" for lines.</param>
55+
/// <param name="XAnchor">Sets the label's horizontal position anchor This anchor binds the specified `textposition` to the "left", "center" or "right" of the label text. For example, if `textposition` is set to "top right" and `xanchor` to "right" then the right-most portion of the label text lines up with the right-most edge of the shape.</param>
56+
/// <param name="YAnchor">Sets the label's vertical position anchor This anchor binds the specified `textposition` to the "top", "middle" or "bottom" of the label text. For example, if `textposition` is set to "top right" and `yanchor` to "top" then the top-most portion of the label text lines up with the top-most edge of the shape.</param>
57+
static member style
58+
(
59+
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
60+
[<Optional; DefaultParameterValue(null)>] ?Padding: int,
61+
[<Optional; DefaultParameterValue(null)>] ?Text: string,
62+
[<Optional; DefaultParameterValue(null)>] ?TextAngle: StyleParam.TextAngle,
63+
[<Optional; DefaultParameterValue(null)>] ?TextPosition: StyleParam.TextPosition,
64+
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
65+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition
66+
) =
67+
68+
(fun (shapeLabel: ShapeLabel) ->
69+
70+
Font |> DynObj.setValueOpt shapeLabel "font"
71+
Padding |> DynObj.setValueOpt shapeLabel "padding"
72+
Text |> DynObj.setValueOpt shapeLabel "text"
73+
TextAngle |> DynObj.setValueOptBy shapeLabel "textangle" StyleParam.TextAngle.convert
74+
TextPosition |> DynObj.setValueOptBy shapeLabel "textposition" StyleParam.TextPosition.convert
75+
XAnchor |> DynObj.setValueOptBy shapeLabel "xanchor" StyleParam.XAnchorPosition.convert
76+
YAnchor |> DynObj.setValueOptBy shapeLabel "yanchor" StyleParam.YAnchorPosition.convert
77+
78+
shapeLabel
79+
)

Diff for: src/Plotly.NET/Plotly.NET.fsproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@
3333
<FsDocsLicenseLink>https://github.com/plotly/Plotly.NET/blob/dev/LICENSE</FsDocsLicenseLink>
3434
<FsDocsReleaseNotesLink>https://github.com/plotly/Plotly.NET/blob/dev/RELEASE_NOTES.md</FsDocsReleaseNotesLink>
3535
</PropertyGroup>
36+
<ItemGroup>
37+
<EmbeddedResource Remove="Layout\ObjectAbstractions\2D\**" />
38+
<EmbeddedResource Remove="Layout\ObjectAbstractions\Carpet\**" />
39+
</ItemGroup>
3640
<ItemGroup>
3741
<None Include="RELEASE_NOTES.md" />
3842
<None Include="..\..\docs\img\logo.png" Pack="true" PackagePath="\" />
39-
<EmbeddedResource Include="plotly-2.18.1.min.js" />
40-
<EmbeddedResource Include="plotly-2.18.1.min.js.LICENSE.txt" />
43+
<EmbeddedResource Include="plotly-2.19.1.min.js" />
44+
<EmbeddedResource Include="plotly-2.19.1.min.js.LICENSE.txt" />
4145
<Compile Include="Globals.fs" />
4246
<Compile Include="InternalUtils.fs" />
4347
<Compile Include="CommonAbstractions\ColorKeyword.fs" />
@@ -62,6 +66,7 @@
6266
<Compile Include="Layout\ObjectAbstractions\Common\Domain.fs" />
6367
<Compile Include="Layout\ObjectAbstractions\Common\ActiveShape.fs" />
6468
<Compile Include="Layout\ObjectAbstractions\Common\NewShape.fs" />
69+
<Compile Include="Layout\ObjectAbstractions\Common\ShapeLabel.fs" />
6570
<Compile Include="Layout\ObjectAbstractions\Common\Shape.fs" />
6671
<Compile Include="Layout\ObjectAbstractions\Common\ActiveSelection.fs" />
6772
<Compile Include="Layout\ObjectAbstractions\Common\NewSelection.fs" />
@@ -137,7 +142,6 @@
137142
<Compile Include="Traces\TraceDomain.fs" />
138143
<Compile Include="Traces\TraceSmith.fs" />
139144
<Compile Include="Traces\TraceID.fs" />
140-
<Folder Include="Layout\ObjectAbstractions\2D\" />
141145
<Compile Include="Config\ObjectAbstractions\Edits.fs" />
142146
<Compile Include="Config\ObjectAbstractions\ToImageButtonOptions.fs" />
143147
<Compile Include="Config\Config.fs" />
@@ -165,7 +169,4 @@
165169
<PackageReference Include="DynamicObj" Version="2.0.0" />
166170
<PackageReference Include="Giraffe.ViewEngine.StrongName" Version="2.0.0-alpha1" />
167171
</ItemGroup>
168-
<ItemGroup>
169-
<Folder Include="Layout\ObjectAbstractions\Carpet\" />
170-
</ItemGroup>
171172
</Project>

Diff for: src/Plotly.NET/plotly-2.18.1.min.js

-8
This file was deleted.

Diff for: src/Plotly.NET/plotly-2.19.1.min.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/Plotly.NET.CSharp.Tests/Plotly.NET.CSharp.Tests.csproj

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<Compile Remove="extensionmethods\**" />
10+
<EmbeddedResource Remove="extensionmethods\**" />
11+
<None Remove="extensionmethods\**" />
12+
</ItemGroup>
13+
814
<ItemGroup>
915
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
1016
<PackageReference Include="xunit" Version="2.4.1" />
@@ -22,8 +28,4 @@
2228
<ProjectReference Include="..\..\src\Plotly.NET.CSharp\Plotly.NET.CSharp.csproj" />
2329
</ItemGroup>
2430

25-
<ItemGroup>
26-
<Folder Include="extensionmethods\" />
27-
</ItemGroup>
28-
2931
</Project>

Diff for: tests/Plotly.NET.Tests.FSharpConsole/Program.fs

+35-44
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,39 @@ open Newtonsoft.Json
1111

1212
[<EntryPoint>]
1313
let main argv =
14-
Config.init(
15-
StaticPlot = false,
16-
TypesetMath = true,
17-
PlotlyServerUrl = "myserver.me.meme",
18-
Editable = true,
19-
Edits = Edits.init(AnnotationPosition = true, ShapePosition = true),
20-
EditSelection = true,
21-
Autosizable = true,
22-
Responsive = true,
23-
FillFrame = true,
24-
FrameMargins = 1.337,
25-
ScrollZoom = StyleParam.ScrollZoom.All,
26-
DoubleClick = StyleParam.DoubleClick.Reset,
27-
DoubleClickDelay = 1337,
28-
ShowAxisDragHandles = true,
29-
ShowAxisRangeEntryBoxes = true,
30-
ShowTips = true,
31-
ShowLink = true,
32-
LinkText = "never gonna give you up",
33-
SendData = true,
34-
ShowSources = true,
35-
DisplayModeBar = true,
36-
ShowSendToCloud = true,
37-
ShowEditInChartStudio = true,
38-
ModeBarButtonsToRemove = [StyleParam.ModeBarButton.AutoScale2d],
39-
ModeBarButtonsToAdd = [StyleParam.ModeBarButton.DrawCircle],
40-
ModeBarButtons = [[StyleParam.ModeBarButton.DrawClosedPath; StyleParam.ModeBarButton.DrawOpenPath];[StyleParam.ModeBarButton.OrbitRotation]],
41-
ToImageButtonOptions = ToImageButtonOptions.init(Format = StyleParam.ImageFormat.SVG, Filename="soos.svg"),
42-
Displaylogo = true,
43-
Watermark = true,
44-
plotGlPixelRatio = 1.0,
45-
SetBackground = box "function(x) => {return x}",
46-
TopojsonURL = "myserver.me.meme",
47-
MapboxAccessToken = "4Tw20BlzLT",
48-
Logging = 2,
49-
NotifyOnLogging = 2,
50-
QueueLength = 1337,
51-
GlobalTransforms = box "function(x) => {return x}",
52-
Locale = "de-DE",
53-
Locales = box """{"yes": "no"}"""
54-
)
55-
:> DynamicObj
56-
|> JsonConvert.SerializeObject
57-
|> printfn "%A"
14+
let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
15+
let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
16+
let s1 =
17+
Shape.init(
18+
ShapeType=StyleParam.ShapeType.Rectangle,
19+
X0=2.,X1=4.,Y0=3.,Y1=4.,
20+
Opacity=0.3,
21+
FillColor=Color.fromHex "#d3d3d3",
22+
Label = ShapeLabel.init(Text="Rectangle")
23+
)
24+
let s2 =
25+
Shape.init(
26+
ShapeType=StyleParam.ShapeType.Circle,
27+
X0=5.,X1=7.,Y0=3.,Y1=4.,
28+
Opacity=0.3,
29+
FillColor=Color.fromHex "#d3d3d3",
30+
Label = ShapeLabel.init(Text="Circle")
31+
)
32+
let s3 =
33+
Shape.init(
34+
ShapeType=StyleParam.ShapeType.Line,
35+
X0=1.,X1=2.,Y0=1.,Y1=2.,
36+
Opacity=0.3,
37+
FillColor=Color.fromHex "#d3d3d3",
38+
Label = ShapeLabel.init(Text="Line")
39+
)
40+
let s4 =
41+
Shape.init(
42+
ShapeType=StyleParam.ShapeType.SvgPath,
43+
Path=" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z",
44+
Label = ShapeLabel.init(Text="SVGPath", TextAngle = StyleParam.TextAngle.Degrees 33)
45+
)
46+
Chart.Line(x = x,y = y',Name="line", UseDefaults = false)
47+
|> Chart.withShapes([s1;s2;s3;s4])
48+
|> Chart.show
5849
0

0 commit comments

Comments
 (0)