Skip to content

Commit 338f16a

Browse files
author
Timo Mühlhaus
committed
Fix ApplyHelper get public properties with interface properties
1 parent bb11205 commit 338f16a

File tree

6 files changed

+168
-129
lines changed

6 files changed

+168
-129
lines changed

docs/content/area-plots.fsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
#r "../../bin/FSharp.Plotly.dll"
44

55
(**
6-
# FSharp.Plotly: Pie and Doughnut Charts
6+
# FSharp.Plotly: Area Charts
77
8-
*Summary:* This example shows how to create pie and doughnut charts in F#.
8+
*Summary:* This example shows how to create an area charts in F#.
99
10-
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11-
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12-
values.
10+
An area chart or area graph displays graphically quantitive data. It is based on the line chart.
11+
The area between axis and line are commonly emphasized with colors, textures and hatchings.
1312
*)
1413

1514
open FSharp.Plotly
1615

17-
let values = [19; 26; 55;]
18-
let labels = ["Residential"; "Non-Residential"; "Utility"]
16+
let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
17+
let y = [5.; 2.5; 5.; 7.5; 5.; 2.5; 7.5; 4.5; 5.5; 5.]
18+
//let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
1919

20-
(*** define-output:pie1 ***)
21-
Chart.Pie(values,labels)
22-
(*** include-it:pie1 ***)
20+
(*** define-output:area1 ***)
21+
Chart.Area(x,y)
22+
(*** include-it:area1 ***)
2323

2424

25+
26+
(*** define-output:area2 ***)
27+
Chart.SplineArea(x,y)
28+
(*** include-it:area2 ***)
29+
|> Chart.Show
30+

docs/content/line-scatter-plots.fsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ values of a simple function, f(x)=x^2. The values of the function are generated
3232
shown below.
3333
*)
3434

35-
(*** define-output:sq ***)
35+
(*** define-output:line2 ***)
3636
// Drawing graph of a 'square' function
3737
[ for x in 1.0 .. 100.0 -> (x, x ** 2.0) ]
3838
|> Chart.Line
39-
(*** include-it:sq ***)
39+
(*** include-it:line2 ***)
4040
|> Chart.Show
41+
42+
43+
44+
(*** define-output:line3 ***)
45+
Chart.Spline(x,y',Name="spline")
46+
|> Chart.withLineStyle(Width=2,Dash=StyleOption.DrawingStyle.Dot)
47+
|> Chart.withLineStyle(Width=6,Dash=StyleOption.DrawingStyle.Dot)
48+
(*** include-it:line3 ***)
49+
|> Chart.Show
50+

lib/FSharp.Care.dll

8.5 KB
Binary file not shown.

src/FSharp.Plotly/ApplyHelper.fs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module ApplyHelper =
4848
let property =
4949
getPublicProperties (o.GetType())
5050
|> Array.find (fun n -> n.Name = propName)
51-
printfn "%s" property.Name
51+
//printfn "%s" property.Name
5252
try
5353
property.SetValue(o, value, null)
5454
Some o
@@ -67,8 +67,14 @@ module ApplyHelper =
6767
/// Gets property value as 'a option using reflection. Cast to 'a
6868
let tryGetPropertyValueAs<'a> (o:obj) (propName:string) =
6969
try
70-
let v = (o.GetType().GetProperty(propName,BindingFlags.FlattenHierarchy).GetValue(o, null))
71-
Some (v :?> 'a)
70+
//let v = (o.GetType().GetProperty(propName,BindingFlags.FlattenHierarchy).GetValue(o, null))
71+
let propInfo =
72+
getPublicProperties (o.GetType())
73+
|> Array.tryFind (fun p -> p.Name = propName)
74+
match propInfo with
75+
| Some v -> Some (v.GetValue(o,null) :?> 'a)
76+
| None -> None
77+
//Some (v :?> 'a)
7278
with
7379
| :? System.Reflection.TargetInvocationException -> None
7480
| :? System.NullReferenceException -> None
@@ -82,7 +88,8 @@ module ApplyHelper =
8288
/// Updates property value by given function
8389
let tryUpdatePropertyValue (o:obj) (expr : Microsoft.FSharp.Quotations.Expr) (f: 'a -> 'a) =
8490
let propName = tryGetPropertyName expr
85-
let v = optBuildApply f (tryGetPropertyValueAs<'a> o propName.Value)
91+
let g = (tryGetPropertyValueAs<'a> o propName.Value)
92+
let v = optBuildApply f g
8693
trySetPropertyValue o propName.Value v
8794
//o
8895

0 commit comments

Comments
 (0)