Skip to content

Commit ccef436

Browse files
committed
Proof of concept to include xplot in FsSnip.WebSite
1 parent 312d5ff commit ccef436

File tree

9 files changed

+716
-99
lines changed

9 files changed

+716
-99
lines changed

App.config

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
55
</startup>
66
<runtime>
7-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8-
<dependentAssembly>
9-
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
10-
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" xmlns="urn:schemas-microsoft-com:asm.v1" />
11-
</dependentAssembly>
12-
</assemblyBinding>
13-
</runtime>
7+
8+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
9+
<dependentAssembly>
10+
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" xmlns="urn:schemas-microsoft-com:asm.v1" />
12+
</dependentAssembly>
13+
</assemblyBinding></runtime>
1414
</configuration>

FsSnip.WebSite.fsproj

Lines changed: 52 additions & 81 deletions
Large diffs are not rendered by default.

Google.DataTable.Net.Wrapper.XML

Lines changed: 565 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app.fsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#r "packages/Suave.DotLiquid/lib/net40/Suave.DotLiquid.dll"
66
#load "packages/FSharp.Azure.StorageTypeProvider/StorageTypeProvider.fsx"
77
#load "packages/FSharp.Formatting/FSharp.Formatting.fsx"
8+
#I "packages/Google.DataTable.Net.Wrapper/lib"
9+
#I "packages/XPlot.GoogleCharts/lib/net45"
10+
#r "XPlot.GoogleCharts.dll"
11+
open XPlot.GoogleCharts
812
open System
913
open System.Web
1014
open System.IO
@@ -37,6 +41,7 @@ open FSharp.Azure.StorageTypeProvider
3741
#load "code/pages/author.fs"
3842
#load "code/pages/tag.fs"
3943
#load "code/pages/rss.fs"
44+
#load "code/pages/xplot.fs"
4045
#load "code/api.fs"
4146
open FsSnip
4247
open FsSnip.Data
@@ -78,6 +83,9 @@ let app =
7883
// REST API and RSS feeds
7984
Api.webPart
8085
Rss.webPart
86+
87+
// Graphs
88+
XPlot.webPart
8189

8290
// Static files and fallback case
8391
browseStaticFiles

code/pages/xplot.fs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module FsSnip.Pages.XPlot
2+
3+
open Suave
4+
open Suave.Http
5+
open Suave.Http.Applicatives
6+
open System
7+
open FsSnip.Utils
8+
open FsSnip.Data
9+
open FsSnip.Rssfeed
10+
open FsSnip.Filters
11+
open XPlot.GoogleCharts
12+
13+
type GraphModel = {
14+
Id : string
15+
Script: string
16+
Graph: string
17+
}
18+
19+
let Bolivia = ["2004/05", 165.; "2005/06", 135.; "2006/07", 157.; "2007/08", 139.; "2008/09", 136.]
20+
let Ecuador = ["2004/05", 938.; "2005/06", 1120.; "2006/07", 1167.; "2007/08", 1110.; "2008/09", 691.]
21+
let Madagascar = ["2004/05", 522.; "2005/06", 599.; "2006/07", 587.; "2007/08", 615.; "2008/09", 629.]
22+
let Average = ["2004/05", 614.6; "2005/06", 682.; "2006/07", 623.; "2007/08", 609.4; "2008/09", 569.6]
23+
24+
let series = [ "bars"; "bars"; "bars"; "lines" ]
25+
let inputs = [ Bolivia; Ecuador; Madagascar; Average ]
26+
27+
let getGraph = delay (fun () ->
28+
let image =
29+
inputs
30+
|> Chart.Combo
31+
|> Chart.WithOptions
32+
(Options(title = "Coffee Production", series =
33+
[| for typ in series -> Series(typ) |]))
34+
|> Chart.WithLabels
35+
["Bolivia"; "Ecuador"; "Madagascar"; "Average"]
36+
|> Chart.WithLegend true
37+
|> Chart.WithSize (600, 250)
38+
39+
let model = {
40+
Id = image.Id
41+
Script = image.Js
42+
Graph = image.InlineHtml }
43+
44+
DotLiquid.page "graph.html" model)
45+
46+
let webPart = (path "/graph/" <|> path "/graph") >>= getGraph

paket.dependencies

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ nuget FSharp.Data
77
nuget FSharp.Compiler.Service
88
nuget DotLiquid
99
nuget FSharp.Formatting >= 2.10.3
10-
nuget FSharp.Azure.StorageTypeProvider
10+
nuget FSharp.Azure.StorageTypeProvider
11+
nuget XPlot.GoogleCharts

paket.lock

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,28 @@ NUGET
1515
FSharpVSPowerTools.Core (1.9.0)
1616
FSharp.Compiler.Service (>= 0.0.90)
1717
FsPickler (1.3.7)
18-
Microsoft.Azure.KeyVault.Core (1.0.0) - framework: wpv8.0, >= net40
19-
Microsoft.Data.Edm (5.6.4)
20-
Microsoft.Data.OData (5.6.4) - framework: winv4.5, wpv8.1, wpv8.0, >= net40
18+
Google.DataTable.Net.Wrapper (3.1.2)
19+
Microsoft.Azure.KeyVault.Core (1.0.0) - framework: >= net40, wpv8.0
20+
Microsoft.Data.Edm (5.6.4) - framework: >= net40, winv4.5, wpv8.0
21+
Microsoft.Data.OData (5.6.4) - framework: >= net40, winv4.5, wpv8.0
2122
Microsoft.Data.Edm (5.6.4)
2223
System.Spatial (5.6.4)
2324
Microsoft.Data.Services.Client (5.6.4) - framework: >= net40
2425
Microsoft.Data.OData (5.6.4)
25-
Newtonsoft.Json (7.0.1) - framework: wpv8.0, >= net40
26+
Newtonsoft.Json (7.0.1)
2627
Suave (0.31.2)
2728
FSharp.Core (>= 3.1.2.5)
2829
FsPickler (>= 1.2.5)
2930
Suave.DotLiquid (0.31.2)
3031
DotLiquid (>= 1.8.0)
3132
Suave (>= 0.31.2)
32-
System.Spatial (5.6.4)
33+
System.Spatial (5.6.4) - framework: >= net40, winv4.5, wpv8.0
3334
WindowsAzure.Storage (5.0.2)
34-
Microsoft.Azure.KeyVault.Core (>= 1.0.0) - framework: wpv8.0, >= net40
35-
Microsoft.Data.OData (>= 5.6.4) - framework: winv4.5, wpv8.1, wpv8.0, >= net40
35+
Microsoft.Azure.KeyVault.Core (>= 1.0.0) - framework: >= net40, wpv8.0
36+
Microsoft.Data.OData (>= 5.6.4) - framework: >= net40, winv4.5, wpv8.0
3637
Microsoft.Data.Services.Client (>= 5.6.4) - framework: >= net40
37-
Newtonsoft.Json (>= 6.0.8) - framework: wpv8.0, >= net40
38+
Newtonsoft.Json (>= 6.0.8) - framework: >= net40, wpv8.0
39+
XPlot.GoogleCharts (1.2.2)
40+
Google.DataTable.Net.Wrapper
41+
Newtonsoft.Json
3842
Zlib.Portable (1.11.0) - framework: portable-net40+sl50+wp80+win80

paket.references

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Suave.DotLiquid
33
FSharp.Data
44
DotLiquid
55
FSharp.Formatting
6-
FSharp.Azure.StorageTypeProvider
6+
FSharp.Azure.StorageTypeProvider
7+
XPlot.GoogleCharts

templates/graph.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% extends "page.html" %}
2+
{% block head %}
3+
<title>Home page | F# Snippets</title>
4+
{% endblock %}
5+
6+
{% block customPageScripts %}
7+
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
8+
<script type="text/javascript">
9+
google.load("visualization", "1", { packages: ["corechart"] })
10+
{{ model.Script }}
11+
</script>
12+
{% endblock %}
13+
14+
{% block content %}
15+
<div class="row">
16+
<div class="col-md-12"><h2>Graph</h2></div>
17+
</div>
18+
19+
<div id="{{ model.Id }}" style="width: 600px; height: 250px;"></div>
20+
21+
{% endblock %}

0 commit comments

Comments
 (0)