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 23, 2015
2 parents eb128d1 + 1fe8494 commit 8947b29
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 151 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `ALARM_TIMEAGO_URGENT` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_URGENT_MINS` (`30`) - minutes since the last reading to trigger a urgent alarm
* `SHOW_PLUGINS` - enabled plugins that should have their visualizations shown, defaults to all enabled
* `LANGUAGE` (`en`) - language of Nighscout. If not available english is used
* `LANGUAGE` (`en`) - language of Nightscout. If not available english is used
* `SCALE_Y` (`log`) - The type of scaling used for the Y axis of the charts system wide.
* The default `log` (logarithmic) option will let you see more detail towards the lower range, while still showing the full CGM range.
* The `linear` option has equidistant tick marks, the range used is dynamic so that space at the top of chart isn't wasted.
* The `log-dynamic` is similar to the default `log` options, but uses the same dynamic range and the `linear` scale.

### Plugins

Expand Down Expand Up @@ -256,7 +260,8 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `MMCONNECT_INTERVAL` (`60000` *1 minute*) - Number of milliseconds to wait between requests to the CareLink server.
* `MMCONNECT_MAX_RETRY_DURATION` (`32`) - Maximum number of total seconds to spend retrying failed requests before giving up.
* `MMCONNECT_SGV_LIMIT` (`24`) - Maximum number of recent sensor glucose values to send to Nightscout on each request.
* `MMCONNECT_VERBOSE` - Set this to any truthy value to log CareLink request information to the console.
* `MMCONNECT_VERBOSE` - Set this to "true" to log CareLink request information to the console.
* `MMCONNECT_STORE_RAW_DATA` - Set this to "true" to store raw data returned from CareLink as `type: "carelink_raw"` database entries (useful for development).

Also see [Pushover](#pushover) and [IFTTT Maker](#ifttt-maker).

Expand Down
3 changes: 3 additions & 0 deletions lib/client/browser-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function init (client, plugins, serverSettings, $) {

langSelect.val(settings.language);

$('#scaleY').val(settings.scaleY);

if (settings.timeFormat === 24) {
$('#24-browser').prop('checked', true);
} else {
Expand Down Expand Up @@ -125,6 +127,7 @@ function init (client, plugins, serverSettings, $) {
theme: $('input:radio[name=theme-browser]:checked').val(),
timeFormat: parseInt($('input:radio[name=timeformat-browser]:checked').val()),
language: $('#language').val(),
scaleY: $('#scaleY').val(),
showPlugins: checkedPluginNames()
});

Expand Down
68 changes: 38 additions & 30 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,45 @@ function init (client, d3, $) {

var extent = client.dataExtent();

var yScaleType;
if (client.settings.scaleY === 'linear') {
yScaleType = d3.scale.linear;
} else {
yScaleType = d3.scale.log;
}

var focusYDomain = [utils.scaleMgdl(30), utils.scaleMgdl(510)];
var contextYDomain = [utils.scaleMgdl(36), utils.scaleMgdl(420)];

function dynamicDomain() {
var mult = 1.3
, targetTop = client.settings.thresholds.bgTargetTop
, mgdlMax = d3.max(client.data, function (d) { return d.mgdl; });

return [
utils.scaleMgdl(30)
, Math.max(utils.scaleMgdl(mgdlMax * mult), utils.scaleMgdl(targetTop * mult))
];
}

function dynamicDomainOrElse(defaultDomain) {
if (client.settings.scaleY === 'linear' || client.settings.scaleY === 'log-dynamic') {
return dynamicDomain();
} else {
return defaultDomain;
}
}

// define the parts of the axis that aren't dependent on width or height
var xScale = chart.xScale = d3.time.scale().domain(extent);

var yScale = chart.yScale = d3.scale.log()
.domain([utils.scaleMgdl(30), utils.scaleMgdl(510)]);
var yScale = chart.yScale = yScaleType()
.domain(dynamicDomainOrElse(focusYDomain));

var xScale2 = chart.xScale2 = d3.time.scale().domain(extent);

var yScale2 = chart.yScale2 = d3.scale.log()
.domain([utils.scaleMgdl(36), utils.scaleMgdl(420)]);
var yScale2 = chart.yScale2 = yScaleType()
.domain(dynamicDomainOrElse(contextYDomain));

chart.xScaleBasals = d3.time.scale().domain(extent);

Expand All @@ -59,30 +88,7 @@ function init (client, d3, $) {
['%Y', function() { return true; }]
]);

// Tick Values
var tickValues;
if (client.settings.units === 'mmol') {
tickValues = [
2.0
, Math.round(utils.scaleMgdl(client.settings.thresholds.bgLow))
, Math.round(utils.scaleMgdl(client.settings.thresholds.bgTargetBottom))
, 6.0
, Math.round(utils.scaleMgdl(client.settings.thresholds.bgTargetTop))
, Math.round(utils.scaleMgdl(client.settings.thresholds.bgHigh))
, 22.0
];
} else {
tickValues = [
40
, client.settings.thresholds.bgLow
, client.settings.thresholds.bgTargetBottom
, 120
, client.settings.thresholds.bgTargetTop
, client.settings.thresholds.bgHigh
, 400
];
}

var tickValues = client.ticks(client);

chart.xAxis = d3.svg.axis()
.scale(xScale)
Expand Down Expand Up @@ -323,7 +329,7 @@ function init (client, d3, $) {
chart.context.append('line')
.attr('class', 'open-top')
.attr('stroke', '#111')
.attr('stroke-width', 15);
.attr('stroke-width', 12);

// add a x-axis line that closes the the brush container on left side
chart.context.append('line')
Expand Down Expand Up @@ -498,6 +504,7 @@ function init (client, d3, $) {

chart.scroll = function scroll (nowDate) {
chart.xScale.domain(createAdjustedRange());
chart.yScale.domain(dynamicDomainOrElse(focusYDomain));
chart.xScaleBasals.domain(createAdjustedRange());

// remove all insulin/carb treatment bubbles so that they can be redrawn to correct location
Expand Down Expand Up @@ -538,8 +545,9 @@ function init (client, d3, $) {
.attr('x2', chart.xScale2(chart.brush.extent()[1]))
.attr('y2', chart.yScale2(utils.scaleMgdl(420)));

// update x axis
// update x,y axis
chart.focus.select('.x.axis').call(chart.xAxis);
chart.focus.select('.y.axis').call(chart.yAxis);

renderer.addFocusCircles();
renderer.addTreatmentCircles();
Expand Down
1 change: 1 addition & 0 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ client.init = function init(serverSettings, plugins) {
client.browserUtils = require('./browser-utils')($);
client.settings = require('./browser-settings')(client, plugins, serverSettings, $);
client.utils = require('../utils')(client.settings);
client.ticks = require('./ticks');

client.sbx = sandbox.clientInit(client.settings, client.now);
client.rawbg = plugins('rawbg');
Expand Down
81 changes: 81 additions & 0 deletions lib/client/ticks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

function prepare (client, opts) {
opts = checkOptions(client, opts);

if (opts.scaleY === 'linear') {
return prepareLinear(client, opts);
} else {
return prepareLog(client, opts);
}
}

function checkOptions (client, opts) {
opts = opts || {};
opts.scaleY = opts.scaleY || client.settings.scaleY;
//assume any values from opts are already scaled
//do any other scaling here
opts.high = opts.high || Math.round(client.utils.scaleMgdl(client.settings.thresholds.bgHigh));
opts.targetTop = opts.targetTop || Math.round(client.utils.scaleMgdl(client.settings.thresholds.bgTargetTop));
opts.targetBottom = opts.targetBottom || Math.round(client.utils.scaleMgdl(client.settings.thresholds.bgTargetBottom));
opts.low = opts.low || Math.round(client.utils.scaleMgdl(client.settings.thresholds.bgLow));

return opts;
}

function prepareLog (client, opts) {
if (client.settings.units === 'mmol') {
return [
2.0
, Math.round(client.utils.scaleMgdl(client.settings.thresholds.bgLow))
, opts.targetBottom
, 6.0
, opts.targetTop
, opts.high
, 22.0
];
} else {
return [
40
, opts.low
, opts.targetBottom
, 120
, opts.targetTop
, opts.high
, 400
];
}
}

function prepareLinear (client, opts) {
if (client.settings.units === 'mmol') {
return [
2.0
, 4.0
, 6.0
, 8.0
, 10.0
, 12.0
, 14.0
, 16.0
, 18.0
, 20.0
, 22.0
];
} else {
return [
40
, 80
, 120
, 160
, 200
, 240
, 280
, 320
, 360
, 400
];
}
}

module.exports = prepare;
10 changes: 5 additions & 5 deletions lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ function init() {
,fr: 'Ajouter à partir de la base de données'
,pt: 'Adicionar do banco de dados'
,ro: 'Adaugă din baza de date'
,bg: 'Добави към базата с данни'
,bg: 'Добави от базата с данни'
,hr: 'Dodaj iz baze podataka'
,sv: 'Lägg till från databas'
,it: 'Aggiungi dal database'
Expand Down Expand Up @@ -3733,7 +3733,7 @@ function init() {
,pt: 'Calculadora de bolus'
,sv: 'Boluskalkylator'
,ro: 'Calculator sugestie bolus'
,bg: 'Съветник при изчисление на болуса'
,bg: 'Болус съветник '
,hr: 'Bolus wizard'
,it: 'Bolo guidato'
,dk: 'Bolusberegner'
Expand Down Expand Up @@ -4268,12 +4268,12 @@ function init() {
,'Duration' : {
cs: 'Doba trvání'
,ro: 'Durata'
,bg: 'Продължителност'
,bg: 'Времетраене'
}
,'Duration in minutes' : {
cs: 'Doba trvání v minutách'
,ro: 'Durata în minute'
,bg: 'Продължителност в мин.'
,bg: 'Времетраене в мин.'
}
,'Temp Basal' : {
cs: 'Dočasný bazál'
Expand Down Expand Up @@ -4303,7 +4303,7 @@ function init() {
,'Basal value' : { // absolute value for temp basal
cs: 'Hodnota bazálu'
,ro: 'Valoare bazală'
,bg: 'Временна стойност на базала'
,bg: 'Временен базал'
}
,'Absolute basal value' : {
cs: 'Hodnota bazálu'
Expand Down
Loading

0 comments on commit 8947b29

Please sign in to comment.