an example rendering and apps building

This commit is contained in:
Radek Stepan 2013-08-15 18:12:12 +01:00
parent b36f11846b
commit 7aaad2ed8a
19 changed files with 135 additions and 519 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
node_modules/
.idea/
*.log
*.log
src/components/
build/

View File

@ -1,481 +0,0 @@
{
"1003692": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0004110",
"symbol": "tin",
"secondaryIdentifier": "CG7895"
},
"identifiers": {
"tinman": [
"MATCH"
]
},
"type": "Gene"
},
"1005232": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0000099",
"symbol": "ap",
"secondaryIdentifier": "CG8376"
},
"identifiers": {
"FBgn0000099": [
"MATCH"
]
},
"type": "Gene"
},
"1005584": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0000166",
"symbol": "bcd",
"secondaryIdentifier": "CG1034"
},
"identifiers": {
"CG1034": [
"MATCH"
]
},
"type": "Gene"
},
"1006039": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0001150",
"symbol": "gt",
"secondaryIdentifier": "CG7952"
},
"identifiers": {
"gt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"1006967": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003300",
"symbol": "run",
"secondaryIdentifier": "CG1849"
},
"identifiers": {
"runt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"1007192": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0000606",
"symbol": "eve",
"secondaryIdentifier": "CG2328"
},
"identifiers": {
"CG2328": [
"MATCH"
]
},
"type": "Gene"
},
"1007568": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003870",
"symbol": "ttk",
"secondaryIdentifier": "CG1856"
},
"identifiers": {
"tramtrack": [
"DUPLICATE"
]
},
"type": "Gene"
},
"1008149": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0040765",
"symbol": "luna",
"secondaryIdentifier": "CG33473"
},
"identifiers": {
"CG33473": [
"MATCH"
]
},
"type": "Gene"
},
"1012064": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003866",
"symbol": "tsh",
"secondaryIdentifier": "CG1374"
},
"identifiers": {
"CG1374": [
"MATCH"
]
},
"type": "Gene"
},
"1013634": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003720",
"symbol": "tll",
"secondaryIdentifier": "CG1378"
},
"identifiers": {
"tll": [
"MATCH"
]
},
"type": "Gene"
},
"1017495": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0000028",
"symbol": "acj6",
"secondaryIdentifier": "CG9151"
},
"identifiers": {
"CG9151": [
"MATCH"
]
},
"type": "Gene"
},
"1019651": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0011655",
"symbol": "Med",
"secondaryIdentifier": "CG1775"
},
"identifiers": {
"CG1775": [
"MATCH"
]
},
"type": "Gene"
},
"1020845": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0024250",
"symbol": "brk",
"secondaryIdentifier": "CG9653"
},
"identifiers": {
"FBgn0024250": [
"MATCH"
]
},
"type": "Gene"
},
"1021556": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0041111",
"symbol": "lilli",
"secondaryIdentifier": "CG8817"
},
"identifiers": {
"CG8817": [
"MATCH"
]
},
"type": "Gene"
},
"1022210": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0011766",
"symbol": "E2f",
"secondaryIdentifier": "CG6376"
},
"identifiers": {
"E2f": [
"MATCH"
]
},
"type": "Gene"
},
"1023733": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0011648",
"symbol": "Mad",
"secondaryIdentifier": "CG12399"
},
"identifiers": {
"Mad": [
"MATCH"
]
},
"type": "Gene"
},
"1029518": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003460",
"symbol": "so",
"secondaryIdentifier": "CG11121"
},
"identifiers": {
"so": [
"MATCH"
]
},
"type": "Gene"
},
"1033140": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0025800",
"symbol": "Smox",
"secondaryIdentifier": "CG2262"
},
"identifiers": {
"CG2262": [
"MATCH"
]
},
"type": "Gene"
},
"1035180": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0001325",
"symbol": "Kr",
"secondaryIdentifier": "CG3340"
},
"identifiers": {
"FBgn0001251": [
"OTHER"
]
},
"type": "Gene"
},
"1036625": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003430",
"symbol": "slp1",
"secondaryIdentifier": "CG16738"
},
"identifiers": {
"CG16738": [
"MATCH"
]
},
"type": "Gene"
},
"1042703": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0001180",
"symbol": "hb",
"secondaryIdentifier": "CG9786"
},
"identifiers": {
"CG9786": [
"MATCH"
]
},
"type": "Gene"
},
"1045695": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0010433",
"symbol": "ato",
"secondaryIdentifier": "CG7508"
},
"identifiers": {
"FBgn0010433": [
"MATCH"
],
"ato": [
"MATCH"
]
},
"type": "Gene"
},
"1065292": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0004915",
"symbol": "TfIIB",
"secondaryIdentifier": "CG5193"
},
"identifiers": {
"TfIIB": [
"MATCH"
]
},
"type": "Gene"
},
"1068009": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0000157",
"symbol": "Dll",
"secondaryIdentifier": "CG3629"
},
"identifiers": {
"CG3629": [
"MATCH"
]
},
"type": "Gene"
},
"1077315": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0001077",
"symbol": "ftz",
"secondaryIdentifier": "CG2047"
},
"identifiers": {
"ftz": [
"MATCH"
]
},
"type": "Gene"
},
"1145128": {
"summary": {
"organism.name": "Drosophila melanogaster",
"primaryIdentifier": "FBgn0003900",
"symbol": "twi",
"secondaryIdentifier": "CG2956"
},
"identifiers": {
"TWIST_DROME": [
"TYPE_CONVERTED"
]
},
"type": "Gene"
},
"6000138": {
"summary": {
"organism.name": "Drosophila pseudoobscura",
"primaryIdentifier": "FBgn0075017",
"symbol": "Dpse\ttk",
"secondaryIdentifier": "GA14992"
},
"identifiers": {
"tramtrack": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7000252": {
"summary": {
"organism.name": "Drosophila simulans",
"primaryIdentifier": "FBgn0193021",
"symbol": "Dsim\ttk",
"secondaryIdentifier": "GD21596"
},
"identifiers": {
"tramtrack": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7000255": {
"summary": {
"organism.name": "Drosophila yakuba",
"primaryIdentifier": "FBgn0228787",
"symbol": "Dyak\ttk",
"secondaryIdentifier": "GE10957"
},
"identifiers": {
"tramtrack": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7010773": {
"summary": {
"organism.name": "Drosophila simulans",
"primaryIdentifier": "FBgn0016352",
"symbol": "Dsim\run",
"secondaryIdentifier": "GD17500"
},
"identifiers": {
"runt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7513758": {
"summary": {
"organism.name": "Drosophila erecta",
"primaryIdentifier": "FBgn0085118",
"symbol": "Dere\run",
"secondaryIdentifier": "GG19696"
},
"identifiers": {
"runt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7878354": {
"summary": {
"organism.name": "Drosophila virilis",
"primaryIdentifier": "FBgn0013920",
"symbol": "Dvir\run",
"secondaryIdentifier": "GJ19252"
},
"identifiers": {
"runt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"7918344": {
"summary": {
"organism.name": "Drosophila yakuba",
"primaryIdentifier": "FBgn0084618",
"symbol": "Dyak\run",
"secondaryIdentifier": "GE17894"
},
"identifiers": {
"runt": [
"DUPLICATE"
]
},
"type": "Gene"
},
"17023535": {
"summary": {
"organism.name": "Mus musculus",
"primaryIdentifier": "MGI:95866",
"symbol": "gt",
"secondaryIdentifier": null
},
"identifiers": {
"gt": [
"DUPLICATE"
]
},
"type": "Gene"
}
}

View File

@ -2,22 +2,18 @@
<html>
<head>
<meta charset="utf-8">
<title>component-400</title>
<title>GitHub Burndown Chart</title>
<link href="/build.css" media="all" rel="stylesheet" type="text/css" />
<script src="/build.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
document.onreadystatechange = function() {
if (document.readyState == "complete") {
require('app').call(null);
}
};
</script>
</head>
<body>
<div id="target"></div>
<script>
$.getJSON('/data.json', function(data) {
require('component-400/app').call(null, data, '#target', function(err, selected) {
if (err) throw err;
console.log(selected);
});
})
</script>
</body>
</html>

54
src/app.coffee Normal file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env coffee
{ _ } = require 'lodash'
async = require 'async'
Rickshaw = require 'rickshaw'
graph = require './graph'
templates =
'body': require './body'
'label': require './label'
module.exports = ->
a = { number: 2, closed_at: '2013-05-09T09:04:53Z', size: 6 }
b = { number: 1, closed_at: '2013-05-20T10:04:53Z', size: 4 }
c = { number: 3, closed_at: '2013-06-15T09:04:53Z', size: 2 }
async.parallel [
_.partial(graph.actual, [ a, b, c ], 20)
_.partial(graph.ideal, '2013-05-09T09:04:53Z', '2013-08-29T09:04:53Z', 20)
], (err, [ actual, ideal ]) ->
throw err if err
document.querySelector('body').innerHTML = templates.body({})
graph = new Rickshaw.Graph
'element': document.querySelector('#graph')
'renderer': 'line'
'series': [
{ 'data': actual, 'color': '#73C03A', 'name': 'actual' }
{ 'data': ideal, 'color': 'rgba(0,0,0,0.2)', 'name': 'ideal' }
]
hoverDetail = new Rickshaw.Graph.HoverDetail
'graph': graph
'xFormatter': (timestamp) ->
new Date(timestamp * 1e3).toUTCString().substring(0, 11)
'formatter': (series, timestamp, points) ->
templates.label { 'class': series.name, points }
xAxis = new Rickshaw.Graph.Axis.Time 'graph': graph
yAxis = new Rickshaw.Graph.Axis.Y
'graph': graph
'orientation': 'left'
'tickFormat': Rickshaw.Fixtures.Number.formatKMBT
annotator = new Rickshaw.Graph.Annotate
'graph': graph
'element': document.querySelector('#timeline')
annotator.add +new Date / 1e3, 'Now'
graph.render()

View File

@ -1,9 +0,0 @@
#!/usr/bin/env coffee
{ _ } = require 'lodash'
module.exports =
# Map closed issues ready to be visualized.
# Assumes collection has been `filter`ed and is ordered.
'closed': (collection, total, cb) ->
cb null, _.map collection, ({ closed_at, size }) ->
{ x: +new Date(closed_at), y: total -= size }

View File

@ -3,12 +3,22 @@
"main": "app.js",
"version": "1.0.0-alpha",
"dependencies": {
"component/map": "*",
"segmentio/extend": "*",
"component/object": "*",
"manuelstofer/foreach": "*",
"component/dom": "*"
"bestiejs/lodash": "*",
"caolan/async": "*",
"cristiandouce/rickshaw": "*"
},
"scripts": [ ],
"styles": [ ]
"scripts": [
"app.coffee",
"modules/graph.coffee",
"modules/dates.coffee",
"modules/issues.coffee",
"modules/milestones.coffee",
"modules/regex.coffee",
"modules/request.coffee",
"templates/body.eco",
"templates/label.eco"
],
"styles": [
"styles/app.styl"
]
}

28
src/modules/graph.coffee Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env coffee
{ _ } = require 'lodash'
dates = require './dates'
module.exports =
# Map closed issues ready to be visualized by Rickshaw.
# Assumes collection has been `filter`ed and is ordered.
'actual': (collection, total, cb) ->
cb null, _.map collection, ({ closed_at, size }) ->
{ x: +new Date(closed_at) / 1e3, y: total -= size }
# Map ideal velocity for each day ready to be visualized by Rickshaw.
'ideal': (a, b, total, cb) ->
# Swap?
[ b, a ] = [ a, b ] if b < a
# Generate the days in between.
dates.range { a, b }, (err, data) ->
return cb err if err
# Daily velocity needed.
daily = total / data.length
# Map days to data points.
data = _.map data, (day) ->
{ x: +new Date(day) / 1e3, y: total -= daily }
cb null, data

View File

@ -4,7 +4,6 @@ async = require 'async'
req = require './request'
reg = require './regex'
dates = require './dates'
module.exports =
# Used on an initial fetch of issues for a repo.

5
src/styles/app.styl Normal file
View File

@ -0,0 +1,5 @@
body
padding: 100px
#graph
height: 200px

2
src/templates/body.eco Normal file
View File

@ -0,0 +1,2 @@
<div id="graph"></div>
<div id="timeline"></div>

10
src/templates/label.eco Normal file
View File

@ -0,0 +1,10 @@
<% points = Math.ceil @points %>
<% if points > 1: %>
<%- points %> points left
<% else: %>
<% if points is 1: %>
1 point left
<% else: %>
Done
<% end %>
<% end %>

View File

@ -4,7 +4,7 @@ path = require 'path'
{ _ } = require 'lodash'
moment = require 'moment'
dates = require path.resolve __dirname, '../src/dates.coffee'
dates = require path.resolve __dirname, '../src/modules/dates.coffee'
tests =
'range between two dates':

View File

@ -2,7 +2,7 @@
assert = require 'assert'
path = require 'path'
chart = require path.resolve __dirname, '../src/chart.coffee'
graph = require path.resolve __dirname, '../src/modules/graph.coffee'
module.exports =
'chartize closed issues': (done) ->
@ -10,11 +10,11 @@ module.exports =
b = { number: 1, closed_at: '2013-05-09T10:04:53Z', size: 4 }
c = { number: 3, closed_at: '2013-05-12T09:04:53Z', size: 2 }
chart.closed [ a, b, c ], 20, (err, data) ->
graph.actual [ a, b, c ], 20, (err, data) ->
assert.ifError err
assert.deepEqual data, [
{ x: 1368090293000, y: 14 }
{ x: 1368093893000, y: 10 }
{ x: 1368349493000, y: 8 }
{ x: 1368090293, y: 14 }
{ x: 1368093893, y: 10 }
{ x: 1368349493, y: 8 }
]
done.call null

View File

@ -5,7 +5,7 @@ proxy = require 'proxyquire'
req = {}
issues = proxy path.resolve(__dirname, '../src/issues.coffee'),
issues = proxy path.resolve(__dirname, '../src/modules/issues.coffee'),
'./request': req
module.exports =

View File

@ -5,7 +5,7 @@ proxy = require 'proxyquire'
req = {}
milestones = proxy path.resolve(__dirname, '../src/milestones.coffee'),
milestones = proxy path.resolve(__dirname, '../src/modules/milestones.coffee'),
'./request': req
module.exports =