From 956e8cc84695e462e6ddbc69c7f9f45c7c092986 Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Mon, 13 Oct 2014 19:55:25 -0700 Subject: [PATCH] trying to split charting a bit --- public/js/app.bundle.js | 296 ++++++++++++++------------- public/js/app.js | 296 ++++++++++++++------------- src/modules/chart/axes.coffee | 18 ++ src/modules/{ => chart}/lines.coffee | 2 +- src/views/chart.coffee | 19 +- 5 files changed, 335 insertions(+), 296 deletions(-) create mode 100644 src/modules/chart/axes.coffee rename src/modules/{ => chart}/lines.coffee (98%) diff --git a/public/js/app.bundle.js b/public/js/app.bundle.js index 5f29e9e..f62d7d2 100644 --- a/public/js/app.bundle.js +++ b/public/js/app.bundle.js @@ -39259,6 +39259,156 @@ Router.prototype.mount = function(routes, path) { }); + // axes.coffee + root.require.register('burnchart/src/modules/chart/axes.js', function(exports, require, module) { + + module.exports = { + horizontal: function(height) { + return d3.svg.axis().scale(x).orient("bottom").tickSize(-height).tickFormat(function(d) { + return d.getDate(); + }).tickPadding(10); + }, + vertical: function(width, y) { + return d3.svg.axis().scale(y).orient("left").tickSize(-width).ticks(5).tickPadding(10); + } + }; + + }); + + // lines.coffee + root.require.register('burnchart/src/modules/chart/lines.js', function(exports, require, module) { + + var config, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + config = require('../../models/config'); + + module.exports = { + actual: function(issues, created_at, total) { + var head, max, min, range, rest; + head = [ + { + 'date': new Date(created_at), + 'points': total + } + ]; + min = +Infinity; + max = -Infinity; + rest = _.map(issues, function(issue) { + var closed_at, size; + size = issue.size, closed_at = issue.closed_at; + if (size < min) { + min = size; + } + if (size > max) { + max = size; + } + issue.date = new Date(closed_at); + issue.points = total -= size; + return issue; + }); + range = d3.scale.linear().domain([min, max]).range([5, 8]); + rest = _.map(rest, function(issue) { + issue.radius = range(issue.size); + return issue; + }); + return [].concat(head, rest); + }, + ideal: function(a, b, total) { + var cutoff, d, days, length, m, now, once, velocity, y, _ref, _ref1; + if (b < a) { + _ref = [a, b], b = _ref[0], a = _ref[1]; + } + _ref1 = _.map(a.match(config.data.chart.datetime)[1].split('-'), function(v) { + return parseInt(v); + }), y = _ref1[0], m = _ref1[1], d = _ref1[2]; + cutoff = new Date(b); + days = []; + length = 0; + (once = function(inc) { + var day, day_of; + day = new Date(y, m - 1, d + inc); + if (!(day_of = day.getDay())) { + day_of = 7; + } + if (__indexOf.call(config.data.chart.off_days, day_of) >= 0) { + days.push({ + date: day, + off_day: true + }); + } else { + length += 1; + days.push({ + date: day + }); + } + if (!(day > cutoff)) { + return once(inc + 1); + } + })(0); + velocity = total / (length - 1); + days = _.map(days, function(day, i) { + day.points = total; + if (days[i] && !days[i].off_day) { + total -= velocity; + } + return day; + }); + if ((now = new Date()) > cutoff) { + days.push({ + date: now, + points: 0 + }); + } + return days; + }, + trend: function(actual, created_at, due_on) { + var a, b, b1, c1, e, fn, intercept, l, last, slope, start, values; + if (!actual.length) { + return []; + } + start = +actual[0].date; + values = _.map(actual, function(_arg) { + var date, points; + date = _arg.date, points = _arg.points; + return [+date - start, points]; + }); + last = actual[actual.length - 1]; + values.push([+new Date() - start, last.points]); + b1 = 0; + e = 0; + c1 = 0; + a = (l = values.length) * _.reduce(values, function(sum, _arg) { + var a, b; + a = _arg[0], b = _arg[1]; + b1 += a; + e += b; + c1 += Math.pow(a, 2); + return sum + (a * b); + }, 0); + slope = (a - (b1 * e)) / ((l * c1) - (Math.pow(b1, 2))); + intercept = (e - (slope * b1)) / l; + fn = function(x) { + return slope * x + intercept; + }; + created_at = new Date(created_at); + due_on = due_on ? new Date(due_on) : new Date(); + a = created_at - start; + b = due_on - start; + return [ + { + date: created_at, + points: fn(a) + }, { + date: due_on, + points: fn(b) + } + ]; + } + }; + + }); + // issues.coffee root.require.register('burnchart/src/modules/github/issues.js', function(exports, require, module) { @@ -39601,140 +39751,6 @@ Router.prototype.mount = function(routes, path) { }); - // lines.coffee - root.require.register('burnchart/src/modules/lines.js', function(exports, require, module) { - - var config, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - config = require('../models/config'); - - module.exports = { - actual: function(issues, created_at, total) { - var head, max, min, range, rest; - head = [ - { - 'date': new Date(created_at), - 'points': total - } - ]; - min = +Infinity; - max = -Infinity; - rest = _.map(issues, function(issue) { - var closed_at, size; - size = issue.size, closed_at = issue.closed_at; - if (size < min) { - min = size; - } - if (size > max) { - max = size; - } - issue.date = new Date(closed_at); - issue.points = total -= size; - return issue; - }); - range = d3.scale.linear().domain([min, max]).range([5, 8]); - rest = _.map(rest, function(issue) { - issue.radius = range(issue.size); - return issue; - }); - return [].concat(head, rest); - }, - ideal: function(a, b, total) { - var cutoff, d, days, length, m, now, once, velocity, y, _ref, _ref1; - if (b < a) { - _ref = [a, b], b = _ref[0], a = _ref[1]; - } - _ref1 = _.map(a.match(config.data.chart.datetime)[1].split('-'), function(v) { - return parseInt(v); - }), y = _ref1[0], m = _ref1[1], d = _ref1[2]; - cutoff = new Date(b); - days = []; - length = 0; - (once = function(inc) { - var day, day_of; - day = new Date(y, m - 1, d + inc); - if (!(day_of = day.getDay())) { - day_of = 7; - } - if (__indexOf.call(config.data.chart.off_days, day_of) >= 0) { - days.push({ - date: day, - off_day: true - }); - } else { - length += 1; - days.push({ - date: day - }); - } - if (!(day > cutoff)) { - return once(inc + 1); - } - })(0); - velocity = total / (length - 1); - days = _.map(days, function(day, i) { - day.points = total; - if (days[i] && !days[i].off_day) { - total -= velocity; - } - return day; - }); - if ((now = new Date()) > cutoff) { - days.push({ - date: now, - points: 0 - }); - } - return days; - }, - trend: function(actual, created_at, due_on) { - var a, b, b1, c1, e, fn, intercept, l, last, slope, start, values; - if (!actual.length) { - return []; - } - start = +actual[0].date; - values = _.map(actual, function(_arg) { - var date, points; - date = _arg.date, points = _arg.points; - return [+date - start, points]; - }); - last = actual[actual.length - 1]; - values.push([+new Date() - start, last.points]); - b1 = 0; - e = 0; - c1 = 0; - a = (l = values.length) * _.reduce(values, function(sum, _arg) { - var a, b; - a = _arg[0], b = _arg[1]; - b1 += a; - e += b; - c1 += Math.pow(a, 2); - return sum + (a * b); - }, 0); - slope = (a - (b1 * e)) / ((l * c1) - (Math.pow(b1, 2))); - intercept = (e - (slope * b1)) / l; - fn = function(x) { - return slope * x + intercept; - }; - created_at = new Date(created_at); - due_on = due_on ? new Date(due_on) : new Date(); - a = created_at - start; - b = due_on - start; - return [ - { - date: created_at, - points: fn(a) - }, { - date: due_on, - points: fn(b) - } - ]; - } - }; - - }); - // mediator.coffee root.require.register('burnchart/src/modules/mediator.js', function(exports, require, module) { @@ -40014,9 +40030,11 @@ Router.prototype.mount = function(routes, path) { // chart.coffee root.require.register('burnchart/src/views/chart.js', function(exports, require, module) { - var lines; + var axes, lines; - lines = require('../modules/lines'); + lines = require('../modules/chart/lines'); + + axes = require('../modules/chart/axes'); module.exports = Ractive.extend({ 'name': 'views/chart', @@ -40040,10 +40058,8 @@ Router.prototype.mount = function(routes, path) { height -= margin.top + margin.bottom; x = d3.time.scale().range([0, width]); y = d3.scale.linear().range([height, 0]); - xAxis = d3.svg.axis().scale(x).orient("bottom").tickSize(-height).tickFormat(function(d) { - return d.getDate(); - }).tickPadding(10); - yAxis = d3.svg.axis().scale(y).orient("left").tickSize(-width).ticks(5).tickPadding(10); + xAxis = axes.horizontal(height); + yAxis = axes.vertical(width, y); line = d3.svg.line().interpolate("linear").x(function(d) { return x(d.date); }).y(function(d) { diff --git a/public/js/app.js b/public/js/app.js index c02e935..85a7f65 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -211,6 +211,156 @@ }); + // axes.coffee + root.require.register('burnchart/src/modules/chart/axes.js', function(exports, require, module) { + + module.exports = { + horizontal: function(height) { + return d3.svg.axis().scale(x).orient("bottom").tickSize(-height).tickFormat(function(d) { + return d.getDate(); + }).tickPadding(10); + }, + vertical: function(width, y) { + return d3.svg.axis().scale(y).orient("left").tickSize(-width).ticks(5).tickPadding(10); + } + }; + + }); + + // lines.coffee + root.require.register('burnchart/src/modules/chart/lines.js', function(exports, require, module) { + + var config, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + config = require('../../models/config'); + + module.exports = { + actual: function(issues, created_at, total) { + var head, max, min, range, rest; + head = [ + { + 'date': new Date(created_at), + 'points': total + } + ]; + min = +Infinity; + max = -Infinity; + rest = _.map(issues, function(issue) { + var closed_at, size; + size = issue.size, closed_at = issue.closed_at; + if (size < min) { + min = size; + } + if (size > max) { + max = size; + } + issue.date = new Date(closed_at); + issue.points = total -= size; + return issue; + }); + range = d3.scale.linear().domain([min, max]).range([5, 8]); + rest = _.map(rest, function(issue) { + issue.radius = range(issue.size); + return issue; + }); + return [].concat(head, rest); + }, + ideal: function(a, b, total) { + var cutoff, d, days, length, m, now, once, velocity, y, _ref, _ref1; + if (b < a) { + _ref = [a, b], b = _ref[0], a = _ref[1]; + } + _ref1 = _.map(a.match(config.data.chart.datetime)[1].split('-'), function(v) { + return parseInt(v); + }), y = _ref1[0], m = _ref1[1], d = _ref1[2]; + cutoff = new Date(b); + days = []; + length = 0; + (once = function(inc) { + var day, day_of; + day = new Date(y, m - 1, d + inc); + if (!(day_of = day.getDay())) { + day_of = 7; + } + if (__indexOf.call(config.data.chart.off_days, day_of) >= 0) { + days.push({ + date: day, + off_day: true + }); + } else { + length += 1; + days.push({ + date: day + }); + } + if (!(day > cutoff)) { + return once(inc + 1); + } + })(0); + velocity = total / (length - 1); + days = _.map(days, function(day, i) { + day.points = total; + if (days[i] && !days[i].off_day) { + total -= velocity; + } + return day; + }); + if ((now = new Date()) > cutoff) { + days.push({ + date: now, + points: 0 + }); + } + return days; + }, + trend: function(actual, created_at, due_on) { + var a, b, b1, c1, e, fn, intercept, l, last, slope, start, values; + if (!actual.length) { + return []; + } + start = +actual[0].date; + values = _.map(actual, function(_arg) { + var date, points; + date = _arg.date, points = _arg.points; + return [+date - start, points]; + }); + last = actual[actual.length - 1]; + values.push([+new Date() - start, last.points]); + b1 = 0; + e = 0; + c1 = 0; + a = (l = values.length) * _.reduce(values, function(sum, _arg) { + var a, b; + a = _arg[0], b = _arg[1]; + b1 += a; + e += b; + c1 += Math.pow(a, 2); + return sum + (a * b); + }, 0); + slope = (a - (b1 * e)) / ((l * c1) - (Math.pow(b1, 2))); + intercept = (e - (slope * b1)) / l; + fn = function(x) { + return slope * x + intercept; + }; + created_at = new Date(created_at); + due_on = due_on ? new Date(due_on) : new Date(); + a = created_at - start; + b = due_on - start; + return [ + { + date: created_at, + points: fn(a) + }, { + date: due_on, + points: fn(b) + } + ]; + } + }; + + }); + // issues.coffee root.require.register('burnchart/src/modules/github/issues.js', function(exports, require, module) { @@ -553,140 +703,6 @@ }); - // lines.coffee - root.require.register('burnchart/src/modules/lines.js', function(exports, require, module) { - - var config, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - - config = require('../models/config'); - - module.exports = { - actual: function(issues, created_at, total) { - var head, max, min, range, rest; - head = [ - { - 'date': new Date(created_at), - 'points': total - } - ]; - min = +Infinity; - max = -Infinity; - rest = _.map(issues, function(issue) { - var closed_at, size; - size = issue.size, closed_at = issue.closed_at; - if (size < min) { - min = size; - } - if (size > max) { - max = size; - } - issue.date = new Date(closed_at); - issue.points = total -= size; - return issue; - }); - range = d3.scale.linear().domain([min, max]).range([5, 8]); - rest = _.map(rest, function(issue) { - issue.radius = range(issue.size); - return issue; - }); - return [].concat(head, rest); - }, - ideal: function(a, b, total) { - var cutoff, d, days, length, m, now, once, velocity, y, _ref, _ref1; - if (b < a) { - _ref = [a, b], b = _ref[0], a = _ref[1]; - } - _ref1 = _.map(a.match(config.data.chart.datetime)[1].split('-'), function(v) { - return parseInt(v); - }), y = _ref1[0], m = _ref1[1], d = _ref1[2]; - cutoff = new Date(b); - days = []; - length = 0; - (once = function(inc) { - var day, day_of; - day = new Date(y, m - 1, d + inc); - if (!(day_of = day.getDay())) { - day_of = 7; - } - if (__indexOf.call(config.data.chart.off_days, day_of) >= 0) { - days.push({ - date: day, - off_day: true - }); - } else { - length += 1; - days.push({ - date: day - }); - } - if (!(day > cutoff)) { - return once(inc + 1); - } - })(0); - velocity = total / (length - 1); - days = _.map(days, function(day, i) { - day.points = total; - if (days[i] && !days[i].off_day) { - total -= velocity; - } - return day; - }); - if ((now = new Date()) > cutoff) { - days.push({ - date: now, - points: 0 - }); - } - return days; - }, - trend: function(actual, created_at, due_on) { - var a, b, b1, c1, e, fn, intercept, l, last, slope, start, values; - if (!actual.length) { - return []; - } - start = +actual[0].date; - values = _.map(actual, function(_arg) { - var date, points; - date = _arg.date, points = _arg.points; - return [+date - start, points]; - }); - last = actual[actual.length - 1]; - values.push([+new Date() - start, last.points]); - b1 = 0; - e = 0; - c1 = 0; - a = (l = values.length) * _.reduce(values, function(sum, _arg) { - var a, b; - a = _arg[0], b = _arg[1]; - b1 += a; - e += b; - c1 += Math.pow(a, 2); - return sum + (a * b); - }, 0); - slope = (a - (b1 * e)) / ((l * c1) - (Math.pow(b1, 2))); - intercept = (e - (slope * b1)) / l; - fn = function(x) { - return slope * x + intercept; - }; - created_at = new Date(created_at); - due_on = due_on ? new Date(due_on) : new Date(); - a = created_at - start; - b = due_on - start; - return [ - { - date: created_at, - points: fn(a) - }, { - date: due_on, - points: fn(b) - } - ]; - } - }; - - }); - // mediator.coffee root.require.register('burnchart/src/modules/mediator.js', function(exports, require, module) { @@ -966,9 +982,11 @@ // chart.coffee root.require.register('burnchart/src/views/chart.js', function(exports, require, module) { - var lines; + var axes, lines; - lines = require('../modules/lines'); + lines = require('../modules/chart/lines'); + + axes = require('../modules/chart/axes'); module.exports = Ractive.extend({ 'name': 'views/chart', @@ -992,10 +1010,8 @@ height -= margin.top + margin.bottom; x = d3.time.scale().range([0, width]); y = d3.scale.linear().range([height, 0]); - xAxis = d3.svg.axis().scale(x).orient("bottom").tickSize(-height).tickFormat(function(d) { - return d.getDate(); - }).tickPadding(10); - yAxis = d3.svg.axis().scale(y).orient("left").tickSize(-width).ticks(5).tickPadding(10); + xAxis = axes.horizontal(height); + yAxis = axes.vertical(width, y); line = d3.svg.line().interpolate("linear").x(function(d) { return x(d.date); }).y(function(d) { diff --git a/src/modules/chart/axes.coffee b/src/modules/chart/axes.coffee new file mode 100644 index 0000000..ea975d4 --- /dev/null +++ b/src/modules/chart/axes.coffee @@ -0,0 +1,18 @@ +module.exports = + + horizontal: (height) -> + d3.svg.axis().scale(x) + .orient("bottom") + # Show vertical lines... + .tickSize(-height) + # ...with day of the month... + .tickFormat( (d) -> d.getDate() ) + # ...and give us a spacer. + .tickPadding(10) + + vertical: (width, y) -> + d3.svg.axis().scale(y) + .orient("left") + .tickSize(-width) + .ticks(5) + .tickPadding(10) \ No newline at end of file diff --git a/src/modules/lines.coffee b/src/modules/chart/lines.coffee similarity index 98% rename from src/modules/lines.coffee rename to src/modules/chart/lines.coffee index 0b1d4ee..7eaaaa8 100644 --- a/src/modules/lines.coffee +++ b/src/modules/chart/lines.coffee @@ -1,4 +1,4 @@ -config = require '../models/config' +config = require '../../models/config' module.exports = diff --git a/src/views/chart.coffee b/src/views/chart.coffee index 99acf26..38068ab 100644 --- a/src/views/chart.coffee +++ b/src/views/chart.coffee @@ -1,4 +1,5 @@ -lines = require '../modules/lines' +lines = require '../modules/chart/lines' +axes = require '../modules/chart/axes' module.exports = Ractive.extend @@ -29,20 +30,8 @@ module.exports = Ractive.extend y = d3.scale.linear().range([ height, 0 ]) # Axes. - xAxis = d3.svg.axis().scale(x) - .orient("bottom") - # Show vertical lines... - .tickSize(-height) - # ...with day of the month... - .tickFormat( (d) -> d.getDate() ) - # ...and give us a spacer. - .tickPadding(10) - - yAxis = d3.svg.axis().scale(y) - .orient("left") - .tickSize(-width) - .ticks(5) - .tickPadding(10) + xAxis = axes.horizontal height + yAxis = axes.vertical width, y # Line generator. line = d3.svg.line()