mirror of
https://github.com/atom/atom.git
synced 2026-02-07 13:14:55 -05:00
fix scales
This commit is contained in:
@@ -5,6 +5,8 @@ _ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class EditorStatsView extends ScrollView
|
||||
hours = 2
|
||||
|
||||
time = (date) ->
|
||||
date.setTime(date.getTime() + 6e4)
|
||||
hour = date.getHours()
|
||||
@@ -12,7 +14,7 @@ class EditorStatsView extends ScrollView
|
||||
"#{hour}:#{minute}"
|
||||
|
||||
d3 = require 'd3.v3'
|
||||
x = d3.scale.ordinal().domain d3.range(60)
|
||||
x = d3.scale.ordinal().domain d3.range(hours * 60)
|
||||
y = d3.scale.linear()
|
||||
|
||||
@activate: (rootView, state) ->
|
||||
@@ -32,25 +34,25 @@ class EditorStatsView extends ScrollView
|
||||
@command 'core:cancel', @detach
|
||||
|
||||
date = new Date()
|
||||
future = new Date(date.getTime() + 36e5)
|
||||
future = new Date(date.getTime() + (36e5 * hours))
|
||||
@eventlog[time(date)] = 0
|
||||
|
||||
while date <= future
|
||||
while date < future
|
||||
@eventlog[time(date)] = 0
|
||||
|
||||
console.log @eventlog
|
||||
@rootView.on 'keydown', @track
|
||||
@rootView.on 'mouseup', @track
|
||||
|
||||
draw: ->
|
||||
w = @.width()
|
||||
h = @.height()
|
||||
[pt, pl, pb, pr] = [0,0,0,0]
|
||||
[pt, pl, pb, pr] = [5,0,0,0]
|
||||
|
||||
data = d3.entries @eventlog
|
||||
max = d3.max data, (d) -> d.value
|
||||
|
||||
x.rangeRoundBands [0, w - pl - pr], 0.1
|
||||
y.domain([0, max]).range [h, 0]
|
||||
y.range [h, 0]
|
||||
|
||||
vis = d3.select(@.get(0)).append('svg')
|
||||
.attr('width', w)
|
||||
@@ -61,17 +63,16 @@ class EditorStatsView extends ScrollView
|
||||
bars = vis.selectAll('rect.bar')
|
||||
.data(data)
|
||||
.enter().append('rect')
|
||||
.attr('x', (d, i) => x i)
|
||||
.attr('x', (d, i) -> console.log x(0); x(i))
|
||||
.attr('y', (d) -> y d.value)
|
||||
.attr('height', (d) -> h - y(d.value))
|
||||
.attr('width', x.rangeBand())
|
||||
.attr('class', 'bar')
|
||||
|
||||
update = =>
|
||||
newdata = d3.entries @eventlog
|
||||
max = d3.max newdata, (d) -> d.value
|
||||
|
||||
x.rangeRoundBands [0, w - pl - pr], 0.1
|
||||
y.domain([0, max]).range [h, 0]
|
||||
y.domain [0, max]
|
||||
|
||||
bars.data(newdata).transition()
|
||||
.attr('height', (d, i) -> h - y(d.value))
|
||||
@@ -84,8 +85,7 @@ class EditorStatsView extends ScrollView
|
||||
times = time date
|
||||
@eventlog[times] ||= 0
|
||||
@eventlog[times] += 1
|
||||
|
||||
@eventlog.shift() if @eventlog.length > 59
|
||||
@eventlog.shift() if @eventlog.length > (hours * 60)
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
|
||||
Reference in New Issue
Block a user