Skip to content

Commit

Permalink
allow treatment bubbles to scale up past 1U/20g size
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleibrand committed Oct 18, 2017
1 parent fb4e74e commit 33f16f4
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,23 @@ function init (client, d3) {
contextCircles.exit().remove();
};

function calcTreatmentRadius(treatment, opts) {
var CR = treatment.CR || 20;
function calcTreatmentRadius(treatment, opts, carbratio) {
var CR = treatment.CR || carbratio || 20;
var carbs = treatment.carbs || CR;
var insulin = treatment.insulin || 1;
var carbsOrInsulin = CR;
if ( treatment.carbs ) {
carbsOrInsulin = treatment.carbs;
} else if ( treatment.insulin ) {
carbsOrInsulin = treatment.insulin * CR;
}

var R1 = Math.sqrt(Math.min(carbs, insulin * CR)) / opts.scale
, R2 = Math.sqrt(Math.max(carbs, insulin * CR)) / opts.scale
, R3 = R2 + 8 / opts.scale
// R4 determines how far from the treatment dot the labels are placed
, R4 = R2 + 25 / opts.scale
// R1 determines the size of the treatment dot
var R1 = Math.sqrt(2*carbsOrInsulin) / opts.scale
, R2 = R1
// R3/R4 determine how far from the treatment dot the labels are placed
, R3 = R1 + 8 / opts.scale
, R4 = R1 + 25 / opts.scale
;

return {
Expand All @@ -414,8 +421,10 @@ function init (client, d3) {

function prepareArc(treatment, radius) {
var arc_data = [
// white carb half-circle on top
{ 'element': '', 'color': 'white', 'start': -1.5708, 'end': 1.5708, 'inner': 0, 'outer': radius.R1 },
{ 'element': '', 'color': 'transparent', 'start': -1.5708, 'end': 1.5708, 'inner': radius.R2, 'outer': radius.R3 },
// blue insulin half-circle on bottom
{ 'element': '', 'color': '#0099ff', 'start': 1.5708, 'end': 4.7124, 'inner': 0, 'outer': radius.R1 },
// these form a very short transparent arc along the bottom of an insulin treatment to position the label
// these used to be semicircles from 1.5708 to 4.7124, but that made the tooltip target too big
Expand Down Expand Up @@ -845,7 +854,7 @@ function init (client, d3) {

label.append('text')
// reduce the treatment label font size to make it readable with SMB
.style('font-size', 35 / opts.scale)
.style('font-size', 30 / opts.scale)
.style('text-shadow', '0px 0px 10px rgba(0, 0, 0, 1)')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
Expand All @@ -866,11 +875,11 @@ function init (client, d3) {
renderer.drawTreatment(d, {
scale: renderer.bubbleScale()
, showLabels: true
});
}, client.sbx.data.profile.getCarbRatio(new Date()));
});
};

renderer.drawTreatment = function drawTreatment(treatment, opts) {
renderer.drawTreatment = function drawTreatment(treatment, opts, carbratio) {
if (!treatment.carbs && !treatment.insulin) {
return;
}
Expand All @@ -882,7 +891,7 @@ function init (client, d3) {
return;
}

var radius = calcTreatmentRadius(treatment, opts);
var radius = calcTreatmentRadius(treatment, opts, carbratio);
if (radius.isNaN) {
console.warn('Bad Data: Found isNaN value in treatment', treatment);
return;
Expand Down

0 comments on commit 33f16f4

Please sign in to comment.