From 7aaad2ed8a67985f133d7bf1026f22f8b2d3d0d4 Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Thu, 15 Aug 2013 18:12:12 +0100 Subject: [PATCH] an example rendering and apps building --- .gitignore | 4 +- public/config.json | 481 ---------------------------- public/index.html | 20 +- src/app.coffee | 54 ++++ src/chart.coffee | 9 - src/component.json | 24 +- src/{ => modules}/dates.coffee | 0 src/modules/graph.coffee | 28 ++ src/{ => modules}/issues.coffee | 1 - src/{ => modules}/milestones.coffee | 0 src/{ => modules}/regex.coffee | 0 src/{ => modules}/request.coffee | 0 src/styles/app.styl | 5 + src/templates/body.eco | 2 + src/templates/label.eco | 10 + test/dates.coffee | 2 +- test/{chart.coffee => graph.coffee} | 10 +- test/issues.coffee | 2 +- test/milestones.coffee | 2 +- 19 files changed, 135 insertions(+), 519 deletions(-) delete mode 100644 public/config.json create mode 100644 src/app.coffee delete mode 100644 src/chart.coffee rename src/{ => modules}/dates.coffee (100%) create mode 100644 src/modules/graph.coffee rename src/{ => modules}/issues.coffee (98%) rename src/{ => modules}/milestones.coffee (100%) rename src/{ => modules}/regex.coffee (100%) rename src/{ => modules}/request.coffee (100%) create mode 100644 src/styles/app.styl create mode 100644 src/templates/body.eco create mode 100644 src/templates/label.eco rename test/{chart.coffee => graph.coffee} (60%) diff --git a/.gitignore b/.gitignore index 01aa474..92e1fd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules/ .idea/ -*.log \ No newline at end of file +*.log +src/components/ +build/ \ No newline at end of file diff --git a/public/config.json b/public/config.json deleted file mode 100644 index c6bb0fd..0000000 --- a/public/config.json +++ /dev/null @@ -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" - } -} \ No newline at end of file diff --git a/public/index.html b/public/index.html index 518f98d..17de2cd 100644 --- a/public/index.html +++ b/public/index.html @@ -2,22 +2,18 @@ - component-400 + GitHub Burndown Chart - - + -
- \ No newline at end of file diff --git a/src/app.coffee b/src/app.coffee new file mode 100644 index 0000000..64f5c37 --- /dev/null +++ b/src/app.coffee @@ -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() \ No newline at end of file diff --git a/src/chart.coffee b/src/chart.coffee deleted file mode 100644 index 0b31067..0000000 --- a/src/chart.coffee +++ /dev/null @@ -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 } \ No newline at end of file diff --git a/src/component.json b/src/component.json index 9607163..1f15c1b 100644 --- a/src/component.json +++ b/src/component.json @@ -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" + ] } \ No newline at end of file diff --git a/src/dates.coffee b/src/modules/dates.coffee similarity index 100% rename from src/dates.coffee rename to src/modules/dates.coffee diff --git a/src/modules/graph.coffee b/src/modules/graph.coffee new file mode 100644 index 0000000..a3ef01b --- /dev/null +++ b/src/modules/graph.coffee @@ -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 \ No newline at end of file diff --git a/src/issues.coffee b/src/modules/issues.coffee similarity index 98% rename from src/issues.coffee rename to src/modules/issues.coffee index b342677..017c116 100644 --- a/src/issues.coffee +++ b/src/modules/issues.coffee @@ -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. diff --git a/src/milestones.coffee b/src/modules/milestones.coffee similarity index 100% rename from src/milestones.coffee rename to src/modules/milestones.coffee diff --git a/src/regex.coffee b/src/modules/regex.coffee similarity index 100% rename from src/regex.coffee rename to src/modules/regex.coffee diff --git a/src/request.coffee b/src/modules/request.coffee similarity index 100% rename from src/request.coffee rename to src/modules/request.coffee diff --git a/src/styles/app.styl b/src/styles/app.styl new file mode 100644 index 0000000..5d8a802 --- /dev/null +++ b/src/styles/app.styl @@ -0,0 +1,5 @@ +body + padding: 100px + +#graph + height: 200px \ No newline at end of file diff --git a/src/templates/body.eco b/src/templates/body.eco new file mode 100644 index 0000000..e44b614 --- /dev/null +++ b/src/templates/body.eco @@ -0,0 +1,2 @@ +
+
\ No newline at end of file diff --git a/src/templates/label.eco b/src/templates/label.eco new file mode 100644 index 0000000..f2f2a33 --- /dev/null +++ b/src/templates/label.eco @@ -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 %> \ No newline at end of file diff --git a/test/dates.coffee b/test/dates.coffee index 5afd48e..ac4cb4a 100644 --- a/test/dates.coffee +++ b/test/dates.coffee @@ -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': diff --git a/test/chart.coffee b/test/graph.coffee similarity index 60% rename from test/chart.coffee rename to test/graph.coffee index 22d9324..d373f1a 100644 --- a/test/chart.coffee +++ b/test/graph.coffee @@ -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 \ No newline at end of file diff --git a/test/issues.coffee b/test/issues.coffee index b8da0c5..a1ec35c 100644 --- a/test/issues.coffee +++ b/test/issues.coffee @@ -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 = diff --git a/test/milestones.coffee b/test/milestones.coffee index 81505b0..a487991 100644 --- a/test/milestones.coffee +++ b/test/milestones.coffee @@ -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 =