@@ -7,6 +7,8 @@ open System
77open System.Web
88open FsSnip.Utils
99open 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
2729type 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
3041let 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
5986let webPart =
60- choose
87+ choose
6188 [ path " /tags/" >>= showAll
6289 pathScan " /tags/%s " showSnippets ]
6390
0 commit comments