forked from Reldan/history
/
popup.coffee
60 lines (53 loc) · 1.69 KB
/
popup.coffee
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
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
###
Global variable containing the query we'd like to pass to Flickr. In this
case, kittens!
@type {string}
###
prepareData = (urls) ->
console.log urls
n = _.map urls, (el) -> parseUri(el.url).authority
res = _.groupBy n, (el) -> el
nRes = _.map res, (t) ->
console.log t[0]
label: t[0]
value: t.length
nRes = _.filter nRes, (el) -> el.value > 80
nRes = _.sortBy nRes, 'value'
console.log nRes
viz [
key: 'VizData'
values: nRes
]
viz = (data) ->
nv.addGraph
generate: ->
chart = nv.models.discreteBarChart().x((d) ->
d.label
).y((d) ->
d.value
).staggerLabels(true).tooltips(false).showValues(true)
d3.select('#chart svg').datum(data).attr(width: 1000, height: 500).transition().duration(500).call chart
nv.utils.windowResize chart.update
chart
callback: (graph) ->
window.onResize = ->
width = nv.utils.windowSize().width - 20
height = nv.utils.windowSize().height - 20
margin = graph.margin()
width = Math.max width, margin.left + margin.right + 20
height = Math.max height, margin.top + margin.bottom + 20
graph.width(width).height height
d3.select("#chart svg").attr("width", width).attr("height", height).call graph
chrome.history.search
text: ''
maxResults: 0
startTime: 0
, prepareData
# Run our kitten generation script as soon as the document's DOM is ready.
document.addEventListener 'DOMContentLoaded', ->
$('#myTab a').click (e) ->
e.preventDefault()
$(this).tab 'show'