Skip to content

Commit

Permalink
Merge branch 'dev' into wip/timeago
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Oct 28, 2015
2 parents 8947b29 + 5f682fb commit f322ff9
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 86 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "0.8.1",
"version": "0.8.2-beta2",
"dependencies": {
"jquery": "2.1.0",
"jQuery-Storage-API": "~1.7.2",
Expand Down
4 changes: 3 additions & 1 deletion lib/client/careportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var moment = require('moment-timezone');
var _ = require('lodash');
var parse_duration = require('parse-duration'); // https://www.npmjs.com/package/parse-duration
var times = require('../times');

function init (client, $) {
var careportal = { };
Expand Down Expand Up @@ -153,7 +155,7 @@ function init (client, $) {
, glucoseType: $('#treatment-form').find('input[name=glucoseType]:checked').val()
, carbs: $('#carbsGiven').val()
, insulin: $('#insulinGiven').val()
, duration: $('#duration').val()
, duration: times.msecs(parse_duration($('#duration').val())).mins < 1 ? $('#duration').val() : times.msecs(parse_duration($('#duration').val())).mins
, percent: $('#percent').val()
, absolute: $('#absolute').val()
, preBolus: parseInt($('#preBolus').val())
Expand Down
69 changes: 41 additions & 28 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,20 @@ function init (client, d3) {

// if already existing then transition each rect to its new position
treatRects.transition()
.attr('transform', function (d) {
.attr('transform', function (d) {
return 'translate(' + chart().xScale(new Date(d.mills)) + ',' + chart().yScale(utils.scaleMgdl(50)) + ')';
});

chart().focus.selectAll('.g-duration-rect').transition()
.attr('width', function (d) {
return chart().xScale(new Date(d.mills + times.mins(d.duration).msecs)) - chart().xScale(new Date(d.mills));
});

chart().focus.selectAll('.g-duration-text').transition()
.attr('transform', function (d) {
return 'translate(' + (chart().xScale(new Date(d.mills + times.mins(d.duration).msecs)) - chart().xScale(new Date(d.mills)))/2 + ',' + 10 + ')';
});

// if new rect then just display
var gs = treatRects.enter().append('g')
.attr('class','g-duration')
Expand All @@ -276,6 +286,7 @@ function init (client, d3) {
.on('mouseout', hideTooltip);

gs.append('rect')
.attr('class', 'g-duration-rect')
.attr('width', function (d) {
return chart().xScale(new Date(d.mills + times.mins(d.duration).msecs)) - chart().xScale(new Date(d.mills));
})
Expand All @@ -288,6 +299,7 @@ function init (client, d3) {
.attr('fill', fillColor);

gs.append('text')
.attr('class', 'g-duration-text')
.style('font-size', 15)
.attr('fill', 'white')
.attr('text-anchor', 'middle')
Expand Down Expand Up @@ -497,7 +509,6 @@ function init (client, d3) {

var date = from;
var lastbasal = 0;
var lastdate = from;

while (date <= to) {
var basalvalue = profile.getTempBasal(date, client.tempbasaltreatments);
Expand All @@ -513,25 +524,23 @@ function init (client, d3) {
}
}
lastbasal = basalvalue;
lastdate = date;
date += times.mins(1).msecs;
}
linedata.push( { d: to, b: profile.getTempBasal(to,client.tempbasaltreatments).tempbasal } );
notemplinedata.push( { d: to, b: profile.getTempBasal(to,client.tempbasaltreatments).basal } );
basalareadata.push( { d: to, b: profile.getTempBasal(to,client.tempbasaltreatments).basal } );
tempbasalareadata.push( { d: to, b: profile.getTempBasal(to,client.tempbasaltreatments).tempbasal } );

var toTempBasal = profile.getTempBasal(to, client.tempbasaltreatments);

linedata.push( { d: to, b: toTempBasal.tempbasal } );
notemplinedata.push( { d: to, b: toTempBasal.basal } );
basalareadata.push( { d: to, b: toTempBasal.basal } );
tempbasalareadata.push( { d: to, b: toTempBasal.tempbasal } );

chart().yScaleBasals.domain([0, d3.max(linedata, function(d) { return d.b; }) ]);
// update y axis domain
// chart().basals.select('.y')
// .call(chart().yAxisBasals);

chart().yScaleBasals.domain([d3.max(linedata, function(d) { return d.b; }), 0]);

chart().basals.selectAll('g').remove();
chart().basals.selectAll('.basalline').remove().data(linedata);
chart().basals.selectAll('.notempline').remove().data(notemplinedata);
chart().basals.selectAll('.basalarea').remove().data(basalareadata);
chart().basals.selectAll('.tempbasalarea').remove().data(tempbasalareadata);
// chart().basals.selectAll('.tempbasaltext').remove();

var valueline = d3.svg.line()
.interpolate('step-after')
Expand All @@ -549,7 +558,7 @@ function init (client, d3) {
g.append('path')
.attr('class', 'line basalline')
.attr('stroke', '#0099ff')
.attr('stroke-width', 2)
.attr('stroke-width', 1)
.attr('fill', 'none')
.attr('d', valueline(linedata))
.attr('clip-path', 'url(#clip)');
Expand All @@ -575,25 +584,29 @@ function init (client, d3) {
.attr('class', 'area tempbasalarea')
.datum(tempbasalareadata)
.attr('fill', '#0099ff')
.attr('fill-opacity', .6)
.attr('stroke-width', 2)
.attr('fill-opacity', .2)
.attr('stroke-width', 1)
.attr('d', area);
//console.log(tempbasals);

client.tempbasaltreatments.forEach(function (t) {
if (t.mills > to || t.mills + times.msecs(t.duration).msecs < from) {
return;
// only if basal and focus interval overlap and there is a chance to fit
if (t.mills < to && t.mills + times.mins(t.duration).msecs > from) {
var text = g.append('text')
.attr('class', 'tempbasaltext')
.style('font-size', 15)
.attr('fill', 'white')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('x', chart().xScaleBasals((Math.max(t.mills, from) + Math.min(t.mills + times.mins(t.duration).msecs, to))/2))
.attr('y', 10)
.text((t.percent ? (t.percent > 0 ? '+' : '') + t.percent + '%' : '') + (t.absolute ? t.absolute + 'U' : ''));
// better hide if not fit
if (text.node().getBBox().width > chart().xScaleBasals(t.mills + times.mins(t.duration).msecs) - chart().xScaleBasals(t.mills)) {
text.attr('display', 'none');
}
}
g.append('text')
.attr('class', 'tempbasaltext')
.style('font-size', 15)
.attr('fill', 'white')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('x', chart().xScaleBasals(t.mills + times.mins(t.duration).msecs/2))
.attr('y', 10)
.text((t.percent ? (t.percent > 0 ? '+' : '') + t.percent + '%' : '') + (t.absolute ? t.absolute + 'U' : ''));
});
});
};

return renderer;
Expand Down
Loading

0 comments on commit f322ff9

Please sign in to comment.