Skip to content

Commit c29a2dc

Browse files
committed
Creating a Top 10 snippets graph
1 parent 312d5ff commit c29a2dc

File tree

10 files changed

+697
-104
lines changed

10 files changed

+697
-104
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: 53 additions & 82 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: 5 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
@@ -27,6 +31,7 @@ open FSharp.Azure.StorageTypeProvider
2731
#load "code/common/utils.fs"
2832
#load "code/common/filters.fs"
2933
#load "code/common/data.fs"
34+
#load "code/common/graphs.fs"
3035
#load "code/common/rssfeed.fs"
3136
#load "code/pages/home.fs"
3237
#load "code/pages/insert.fs"

code/common/graphs.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module FsSnip.Graphs
2+
3+
open System
4+
5+
type Graph =
6+
{ Id: string
7+
Script: string }

code/pages/tag.fs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ open System
77
open System.Web
88
open FsSnip.Utils
99
open FsSnip.Data
10+
open FsSnip.Graphs
11+
open XPlot.GoogleCharts
1012

1113
// -------------------------------------------------------------------------------------------------
1214
// Tag page - domain model
@@ -25,19 +27,44 @@ type TagModel =
2527
Snippets : seq<Snippet> }
2628

2729
type AllTagsModel =
28-
{ Taglinks: TagLinks}
30+
{ Taglinks: TagLinks
31+
Graph: Graph }
32+
33+
let Bolivia = ["2004/05", 165.; "2005/06", 135.; "2006/07", 157.; "2007/08", 139.; "2008/09", 136.]
34+
let Ecuador = ["2004/05", 938.; "2005/06", 1120.; "2006/07", 1167.; "2007/08", 1110.; "2008/09", 691.]
35+
let Madagascar = ["2004/05", 522.; "2005/06", 599.; "2006/07", 587.; "2007/08", 615.; "2008/09", 629.]
36+
let Average = ["2004/05", 614.6; "2005/06", 682.; "2006/07", 623.; "2007/08", 609.4; "2008/09", 569.6]
37+
38+
let series = [ "bars"; "bars"; "bars"; "lines" ]
39+
let inputs = [ Bolivia; Ecuador; Madagascar; Average ]
2940

3041
let getAllTags () =
31-
let links =
42+
let sorted =
3243
publicSnippets
3344
|> Seq.collect (fun s -> s.Tags)
3445
|> Seq.countBy id
3546
|> Seq.sortBy (fun (_, c) -> -c)
47+
|> Seq.cache
48+
49+
let links =
50+
sorted
3651
|> Seq.withSizeBy snd
3752
|> Seq.map (fun ((n,c),s) ->
3853
{ Text = n; Size = 80 + s; Count = c;
3954
Link = HttpUtility.UrlEncode(n) })
40-
{Taglinks = links}
55+
56+
let image =
57+
[ (sorted |> Seq.take 10) ]
58+
|> Chart.Bar
59+
|> Chart.WithOptions (Options(title = "Top 10 tags"))
60+
|> Chart.WithLabels ["Count"]
61+
|> Chart.WithLegend true
62+
|> Chart.WithSize (600, 250)
63+
64+
{ Taglinks = links
65+
Graph =
66+
{ Id = image.Id
67+
Script = image.Js }}
4168

4269
// -------------------------------------------------------------------------------------------------
4370
// Suave web parts
@@ -57,7 +84,7 @@ let showAll = delay (fun () ->
5784

5885
// Composed web part to be included in the top-level route
5986
let webPart =
60-
choose
87+
choose
6188
[ path "/tags/" >>= showAll
6289
pathScan "/tags/%s" showSnippets ]
6390

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/tags.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
<title>All Tags | F# Snippets</title>
44
{% endblock %}
55

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.Graph.Script }}
11+
</script>
12+
{% endblock %}
13+
14+
615
{% block content %}
716
<div class="row">
817
<div class="col-md-12"><h2>Snippets by Tag</h2></div>
918
</div>
1019
<div class="row">
1120
<div class="col-md-12">
21+
22+
<div id="{{ model.Graph.Id }}" style="width: 600px; height: 250px;"></div>
23+
1224
<p class="brief-listing">
1325
{% for it in model.TagLinks %}
1426
<a style="font-size:{{ it.Size }}%" href="/tags/{{ it.Link }}">{{ it.Text }}</a> ({{ it.Count }})

0 commit comments

Comments
 (0)