Skip to content

Commit 1a35c02

Browse files
committed
Add Chart.Image
1 parent bdcbd52 commit 1a35c02

3 files changed

Lines changed: 104 additions & 2 deletions

File tree

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,78 @@ module Chart2D =
14361436
Chart.renderHeatmapTrace useWebGL style
14371437

14381438

1439+
[<Extension>]
1440+
static member Image
1441+
(
1442+
[<Optional;DefaultParameterValue(null)>] ?Z : seq<#seq<#seq<int>>>,
1443+
[<Optional;DefaultParameterValue(null)>] ?Source : string,
1444+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
1445+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
1446+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
1447+
[<Optional;DefaultParameterValue(null)>] ?Ids : seq<#IConvertible>,
1448+
[<Optional;DefaultParameterValue(null)>] ?X : seq<#IConvertible>,
1449+
[<Optional;DefaultParameterValue(null)>] ?Y : seq<#IConvertible>,
1450+
[<Optional;DefaultParameterValue(null)>] ?ColorModel : StyleParam.ColorModel,
1451+
[<Optional;DefaultParameterValue(null)>] ?ZMax : StyleParam.ColorComponentBound,
1452+
[<Optional;DefaultParameterValue(null)>] ?ZMin : StyleParam.ColorComponentBound,
1453+
[<Optional;DefaultParameterValue(null)>] ?ZSmooth : StyleParam.SmoothAlg
1454+
) =
1455+
1456+
Trace2D.initImage (
1457+
Trace2DStyle.Image (
1458+
?Z = Z ,
1459+
?Source = Source ,
1460+
?Name = Name ,
1461+
?ShowLegend = ShowLegend,
1462+
?Opacity = Opacity ,
1463+
?Ids = Ids ,
1464+
?X = X ,
1465+
?Y = Y ,
1466+
?ColorModel = ColorModel,
1467+
?ZMax = ZMax ,
1468+
?ZMin = ZMin ,
1469+
?ZSmooth = ZSmooth
1470+
)
1471+
)
1472+
|> GenericChart.ofTraceObject
1473+
1474+
[<Extension>]
1475+
static member Image
1476+
(
1477+
z : seq<#seq<ARGB>>,
1478+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
1479+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
1480+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
1481+
[<Optional;DefaultParameterValue(null)>] ?Ids : seq<#IConvertible>,
1482+
[<Optional;DefaultParameterValue(null)>] ?X : seq<#IConvertible>,
1483+
[<Optional;DefaultParameterValue(null)>] ?Y : seq<#IConvertible>,
1484+
[<Optional;DefaultParameterValue(null)>] ?ZMax : StyleParam.ColorComponentBound,
1485+
[<Optional;DefaultParameterValue(null)>] ?ZMin : StyleParam.ColorComponentBound,
1486+
[<Optional;DefaultParameterValue(null)>] ?ZSmooth : StyleParam.SmoothAlg
1487+
) =
1488+
1489+
let z' =
1490+
z
1491+
|> Seq.map (Seq.map (fun argb -> seq{int argb.R; int argb.G; int argb.B; int argb.A;}))
1492+
1493+
1494+
Trace2D.initImage (
1495+
Trace2DStyle.Image (
1496+
Z = z' ,
1497+
?Name = Name ,
1498+
?ShowLegend = ShowLegend,
1499+
?Opacity = Opacity ,
1500+
?Ids = Ids ,
1501+
?X = X ,
1502+
?Y = Y ,
1503+
ColorModel = StyleParam.ColorModel.RGBA,
1504+
?ZMax = ZMax ,
1505+
?ZMin = ZMin ,
1506+
?ZSmooth = ZSmooth
1507+
)
1508+
)
1509+
|> GenericChart.ofTraceObject
1510+
14391511
/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
14401512
[<Extension>]
14411513
static member Contour(data:seq<#seq<#IConvertible>>,

src/Plotly.NET/Playground.fsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#load "Margin.fs"
2828
#load "Domain.fs"
2929
#load "Shape.fs"
30+
#load "Hoverlabel.fs"
3031
#load "Annotation.fs"
3132
#load "LayoutGrid.fs"
3233
#load "Legend.fs"
33-
#load "Hoverlabel.fs"
3434
#load "TickFormatStop.fs"
3535
#load "ColorBar.fs"
3636
#load "Rangebreak.fs"
@@ -153,6 +153,36 @@ open FSharpAux
153153
open System
154154
open System.IO
155155

156+
let imagebase64 =
157+
System.Convert.ToBase64String(File.ReadAllBytes(@"C:\Users\schne\Pictures\Untitled.jpg"))
158+
159+
Chart.Image(
160+
Source=($"data:image/jpg;base64,{imagebase64}")
161+
)
162+
|> Chart.show
163+
164+
let colors = [
165+
[[0 ;0 ;255]; [255;255;0 ]; [0 ;0 ;255]]
166+
[[255;0 ;0 ]; [255;0 ;255]; [255;0 ;255]]
167+
[[0 ;255;0 ]; [0 ;255;255]; [255;0 ;0 ]]
168+
]
169+
170+
Chart.Image(
171+
Z=colors
172+
)
173+
|> Chart.show
174+
175+
let argbs = [
176+
[(0 ,0 ,255); (0 ,255,255); (0 ,0 ,255)] |> List.map (fun (r,g,b) -> ARGB.fromRGB r g b )
177+
[(255,0 ,0 ); (255,0 ,255); (0 ,0 ,0 )] |> List.map (fun (r,g,b) -> ARGB.fromRGB r g b )
178+
[(0 ,255,0 ); (255,255,0 ); (0 ,0 ,255)] |> List.map (fun (r,g,b) -> ARGB.fromRGB r g b )
179+
]
180+
181+
Chart.Image(
182+
argbs
183+
)
184+
|> Chart.show
185+
156186
Chart.ScatterTernary(
157187
A = [1; 2; 3],
158188
B = [3; 2; 1],

src/Plotly.NET/Traces/Trace2D.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ type Trace2DStyle() =
964964
[<Optional;DefaultParameterValue(null)>] ?Y : seq<#IConvertible>,
965965
[<Optional;DefaultParameterValue(null)>] ?Y0 : #IConvertible,
966966
[<Optional;DefaultParameterValue(null)>] ?DY : #IConvertible,
967-
[<Optional;DefaultParameterValue(null)>] ?Z : seq<#seq<#IConvertible>>,
967+
[<Optional;DefaultParameterValue(null)>] ?Z : #seq<#seq<#seq<int>>>,
968968
[<Optional;DefaultParameterValue(null)>] ?Source : string,
969969
[<Optional;DefaultParameterValue(null)>] ?Text : seq<#IConvertible>,
970970
[<Optional;DefaultParameterValue(null)>] ?HoverText : string,

0 commit comments

Comments
 (0)