-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
OxyPlot.fs
88 lines (73 loc) · 4.53 KB
/
OxyPlot.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2018-2019 Fabulous contributors. See LICENSE.md for license.
namespace Fabulous.XamarinForms
[<AutoOpen>]
module OxyPlotExtension =
open System
open Xamarin.Forms
open OxyPlot
open OxyPlot.Axes
open OxyPlot.Series
open OxyPlot.Xamarin.Forms
open Fabulous
let ModelAttribKey = AttributeKey<_> "OxyPlot_Model"
let ControllerAttribKey = AttributeKey<_> "OxyPlot_Controller"
type Fabulous.XamarinForms.View with
/// Describes a Map in the view
static member inline PlotView
(model: PlotModel, ?controller: PlotController,
// inherited attributes common to all views
?horizontalOptions, ?verticalOptions, ?margin, ?gestureRecognizers, ?anchorX, ?anchorY, ?backgroundColor, ?heightRequest,
?inputTransparent, ?isEnabled, ?isVisible, ?minimumHeightRequest, ?minimumWidthRequest, ?opacity,
?rotation, ?rotationX, ?rotationY, ?scale, ?style, ?translationX, ?translationY, ?widthRequest,
?resources, ?styles, ?styleSheets, ?classId, ?styleId, ?automationId, ?created, ?styleClass) =
// Count the number of additional attributes
let attribCount = 1
let attribCount = match controller with Some _ -> attribCount + 1 | None -> attribCount
// Populate the attributes of the base element
let attribs =
ViewBuilders.BuildView(attribCount, ?horizontalOptions=horizontalOptions, ?verticalOptions=verticalOptions,
?margin=margin, ?gestureRecognizers=gestureRecognizers, ?anchorX=anchorX, ?anchorY=anchorY,
?backgroundColor=backgroundColor, ?heightRequest=heightRequest, ?inputTransparent=inputTransparent,
?isEnabled=isEnabled, ?isVisible=isVisible, ?minimumHeightRequest=minimumHeightRequest,
?minimumWidthRequest=minimumWidthRequest, ?opacity=opacity, ?rotation=rotation,
?rotationX=rotationX, ?rotationY=rotationY, ?scale=scale, ?style=style,
?translationX=translationX, ?translationY=translationY, ?widthRequest=widthRequest,
?resources=resources, ?styles=styles, ?styleSheets=styleSheets, ?classId=classId, ?styleId=styleId,
?automationId=automationId, ?created=created, ?styleClass=styleClass)
// Add our own attributes.
attribs.Add(ModelAttribKey, model)
match controller with None -> () | Some v -> attribs.Add(ControllerAttribKey, v)
// The create method
let create () = PlotView()
// The update method
let update (prevOpt: ViewElement voption) (source: ViewElement) (target: PlotView) =
ViewBuilders.UpdateView (prevOpt, source, target)
source.UpdatePrimitive(prevOpt, target, ModelAttribKey, (fun target v -> target.Model <- v))
source.UpdatePrimitive(prevOpt, target, ControllerAttribKey, (fun target v -> target.Controller <- v))
// The element
ViewElement.Create(create, update, attribs)
#if DEBUG
module Sample1 =
let plotModelCos =
let model = PlotModel(Title = "Example 1")
model.Series.Add(new OxyPlot.Series.FunctionSeries(Math.Cos, 0.0, 10.0, 0.1, "cos(x)"))
model
let plotModelHeatMap =
let model = PlotModel (Title = "Heatmap")
model.Axes.Add(LinearColorAxis (Palette = OxyPalettes.Rainbow(100)))
let singleData = [ for x in 0 .. 99 -> Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0)) ]
let data = Array2D.init 100 100 (fun x y -> singleData.[x] * singleData.[(y + 30) % 100] * 100.0)
let heatMapSeries =
HeatMapSeries(X0 = 0.0, X1 = 99.0, Y0 = 0.0, Y1 = 99.0, Interpolate = true,
RenderMethod = HeatMapRenderMethod.Bitmap, Data = data)
model.Series.Add(heatMapSeries)
model
let plotModels = [ plotModelCos; plotModelHeatMap ]
let sample =
View.CarouselPage(children=
[ for m in plotModels ->
View.ContentPage(content =
View.PlotView(model=m,
horizontalOptions=LayoutOptions.FillAndExpand,
verticalOptions=LayoutOptions.FillAndExpand)) ])
#endif