mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-09 13:15:37 +03:00
Pull out editor-stats package into a separate repo
This commit is contained in:
parent
235078be8e
commit
bdefff6abe
@ -12,7 +12,6 @@
|
||||
"mkdirp": "0.3.5",
|
||||
"git-utils": "0.19.0",
|
||||
"underscore": "1.4.4",
|
||||
"d3": "3.0.8",
|
||||
"coffee-cache": "0.1.0",
|
||||
"pegjs": "0.7.0",
|
||||
"async": "0.2.6",
|
||||
@ -69,6 +68,7 @@
|
||||
"archive-view": "0.1.0",
|
||||
"autoflow": "0.1.0",
|
||||
"command-logger": "0.1.0",
|
||||
"editor-stats": "0.1.0",
|
||||
"gfm": "0.1.0",
|
||||
"git-diff": "0.1.0",
|
||||
"gists": "0.1.0",
|
||||
|
@ -1,2 +0,0 @@
|
||||
'body':
|
||||
'meta-alt-s': 'editor-stats:toggle'
|
@ -1,103 +0,0 @@
|
||||
ScrollView = require 'scroll-view'
|
||||
d3 = require 'd3'
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class EditorStatsView extends ScrollView
|
||||
@activate: ->
|
||||
new EditorStatsView
|
||||
|
||||
@content: ->
|
||||
@div class: 'editor-stats-wrapper', tabindex: -1, =>
|
||||
@div class: 'editor-stats', outlet: 'editorStats'
|
||||
|
||||
pt: 15
|
||||
pl: 10
|
||||
pb: 3
|
||||
pr: 25
|
||||
|
||||
initialize: ->
|
||||
super
|
||||
|
||||
resizer = =>
|
||||
return unless @isOnDom()
|
||||
@draw()
|
||||
@update()
|
||||
@subscribe $(window), 'resize', _.debounce(resizer, 300)
|
||||
|
||||
draw: ->
|
||||
@editorStats.empty()
|
||||
@x ?= d3.scale.ordinal().domain d3.range(@stats.hours * 60)
|
||||
@y ?= d3.scale.linear()
|
||||
w = rootView.vertical.width()
|
||||
h = @height()
|
||||
data = d3.entries @stats.eventLog
|
||||
max = d3.max data, (d) -> d.value
|
||||
|
||||
@x.rangeBands [0, w - @pl - @pr], 0.2
|
||||
@y.domain([0, max]).range [h - @pt - @pb, 0]
|
||||
|
||||
@xaxis ?= d3.svg.axis().scale(@x).orient('top')
|
||||
.tickSize(-h + @pt + @pb)
|
||||
.tickFormat (d) =>
|
||||
d = new Date(@stats.startDate.getTime() + (d * 6e4))
|
||||
mins = d.getMinutes()
|
||||
mins = "0#{mins}" if mins <= 9
|
||||
"#{d.getHours()}:#{mins}"
|
||||
|
||||
vis = d3.select(@editorStats.get(0)).append('svg')
|
||||
.attr('width', w)
|
||||
.attr('height', h)
|
||||
.append('g')
|
||||
.attr('transform', "translate(#{@pl},#{@pt})")
|
||||
|
||||
vis.append('g')
|
||||
.attr('class', 'x axis')
|
||||
.call(@xaxis)
|
||||
.selectAll('g')
|
||||
.classed('minor', (d, i) -> i % 5 == 0 && i % 15 != 0)
|
||||
.style 'display', (d, i) ->
|
||||
if i % 15 == 0 || i % 5 == 0 || i == data.length - 1
|
||||
'block'
|
||||
else
|
||||
'none'
|
||||
|
||||
@bars = vis.selectAll('rect.bar')
|
||||
.data(data)
|
||||
.enter().append('rect')
|
||||
.attr('x', (d, i) => @x i)
|
||||
.attr('height', (d, i) => h - @y(d.value) - @pt - @pb)
|
||||
.attr('y', (d) => @y(d.value))
|
||||
.attr('width', @x.rangeBand())
|
||||
.attr('class', 'bar')
|
||||
|
||||
clearInterval(@updateInterval)
|
||||
updater = => @update() if @isOnDom()
|
||||
setTimeout(updater, 100)
|
||||
@updateInterval = setInterval(updater, 5000)
|
||||
|
||||
update: ->
|
||||
newData = d3.entries @stats.eventLog
|
||||
max = d3.max newData, (d) -> d.value
|
||||
@y.domain [0, max]
|
||||
h = @height()
|
||||
@bars.data(newData).transition()
|
||||
.attr('height', (d, i) => h - @y(d.value) - @pt - @pb)
|
||||
.attr('y', (d, i) => @y(d.value))
|
||||
@bars.classed('max', (d, i) -> d.value == max)
|
||||
|
||||
toggle: (@stats) ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
attach: ->
|
||||
rootView.vertical.append(this)
|
||||
@draw()
|
||||
|
||||
detach: ->
|
||||
super
|
||||
clearInterval(@updateInterval)
|
||||
rootView.focus()
|
@ -1,19 +0,0 @@
|
||||
StatsTracker = require './stats-tracker'
|
||||
|
||||
module.exports =
|
||||
stats: null
|
||||
editorStatsView: null
|
||||
|
||||
activate: ->
|
||||
@stats = new StatsTracker()
|
||||
rootView.command 'editor-stats:toggle', => @createView().toggle(@stats)
|
||||
|
||||
deactivate: ->
|
||||
@editorStatsView = null
|
||||
@stats = null
|
||||
|
||||
createView: ->
|
||||
unless @editorStatsView
|
||||
EditorStatsView = require './editor-stats-view'
|
||||
@editorStatsView = new EditorStatsView()
|
||||
@editorStatsView
|
@ -1,32 +0,0 @@
|
||||
module.exports =
|
||||
class StatsTracker
|
||||
startDate: new Date
|
||||
hours: 6
|
||||
eventLog: {}
|
||||
|
||||
constructor: ->
|
||||
date = new Date(@startDate)
|
||||
future = new Date(date.getTime() + (36e5 * @hours))
|
||||
@eventLog[@time(date)] = 0
|
||||
|
||||
while date < future
|
||||
@eventLog[@time(date)] = 0
|
||||
|
||||
rootView.on 'keydown', => @track()
|
||||
rootView.on 'mouseup', => @track()
|
||||
|
||||
clear: ->
|
||||
@eventLog = {}
|
||||
|
||||
track: ->
|
||||
date = new Date
|
||||
times = @time date
|
||||
@eventLog[times] ?= 0
|
||||
@eventLog[times] += 1
|
||||
@eventLog.shift() if @eventLog.length > (@hours * 60)
|
||||
|
||||
time: (date) ->
|
||||
date.setTime(date.getTime() + 6e4)
|
||||
hour = date.getHours()
|
||||
minute = date.getMinutes()
|
||||
"#{hour}:#{minute}"
|
@ -1,2 +0,0 @@
|
||||
'main': './lib/editor-stats'
|
||||
'description': 'Display a graph of keyboard and mouse usage for the last 6 hours.'
|
@ -1,38 +0,0 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
RootView = require 'root-view'
|
||||
EditorStats = require 'editor-stats/lib/editor-stats-view'
|
||||
|
||||
describe "EditorStats", ->
|
||||
[editorStats] = []
|
||||
|
||||
simulateKeyUp = (key) ->
|
||||
e = $.Event "keydown", keyCode: key.charCodeAt(0)
|
||||
rootView.trigger(e)
|
||||
|
||||
simulateClick = ->
|
||||
e = $.Event "mouseup"
|
||||
rootView.trigger(e)
|
||||
|
||||
beforeEach ->
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
editorStats = atom.activatePackage('editor-stats').mainModule.stats
|
||||
|
||||
describe "when a keyup event is triggered", ->
|
||||
beforeEach ->
|
||||
expect(_.values(editorStats.eventLog)).not.toContain 1
|
||||
expect(_.values(editorStats.eventLog)).not.toContain 2
|
||||
|
||||
it "records the number of times a keyup is triggered", ->
|
||||
simulateKeyUp('a')
|
||||
expect(_.values(editorStats.eventLog)).toContain 1
|
||||
simulateKeyUp('b')
|
||||
expect(_.values(editorStats.eventLog)).toContain 2
|
||||
|
||||
describe "when a mouseup event is triggered", ->
|
||||
it "records the number of times a mouseup is triggered", ->
|
||||
simulateClick()
|
||||
expect(_.values(editorStats.eventLog)).toContain 1
|
||||
simulateClick()
|
||||
expect(_.values(editorStats.eventLog)).toContain 2
|
@ -1,32 +0,0 @@
|
||||
module.exports =
|
||||
class StatsTracker
|
||||
startDate: new Date
|
||||
hours: 6
|
||||
eventLog: []
|
||||
|
||||
constructor: ->
|
||||
date = new Date(@startDate)
|
||||
future = new Date(date.getTime() + (36e5 * @hours))
|
||||
@eventLog[@time(date)] = 0
|
||||
|
||||
while date < future
|
||||
@eventLog[@time(date)] = 0
|
||||
|
||||
rootView.on 'keydown', => @track()
|
||||
rootView.on 'mouseup', => @track()
|
||||
|
||||
clear: ->
|
||||
@eventLog = []
|
||||
|
||||
track: ->
|
||||
date = new Date
|
||||
times = @time date
|
||||
@eventLog[times] ?= 0
|
||||
@eventLog[times] += 1
|
||||
@eventLog.shift() if @eventLog.length > (@hours * 60)
|
||||
|
||||
time: (date) ->
|
||||
date.setTime(date.getTime() + 6e4)
|
||||
hour = date.getHours()
|
||||
minute = date.getMinutes()
|
||||
"#{hour}:#{minute}"
|
@ -1,44 +0,0 @@
|
||||
.editor-stats-wrapper {
|
||||
padding: 5px;
|
||||
box-sizing: border-box;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.editor-stats {
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
background: #1d1f21;
|
||||
border: 1px solid rgba(0, 0, 0, 0.3);
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-right: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.bar {
|
||||
fill: rgba(255, 255, 255, 0.2);
|
||||
shape-rendering: crispedges;
|
||||
|
||||
&.max {
|
||||
fill: rgba(0, 163, 255, 1);
|
||||
}
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 10px;
|
||||
fill: rgba(255, 255, 255, 0.2);
|
||||
font-family: Courier;
|
||||
}
|
||||
|
||||
.minor text {
|
||||
display: none;
|
||||
}
|
||||
|
||||
line {
|
||||
stroke: #ccc;
|
||||
stroke-opacity: 0.05;
|
||||
stroke-width: 1px;
|
||||
shape-rendering: crispedges;
|
||||
}
|
||||
|
||||
path.domain {
|
||||
display: none;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user