diff --git a/lib/client/renderer.js b/lib/client/renderer.js index ab25f80819b..d92559926e8 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -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 { @@ -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 @@ -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') @@ -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; } @@ -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;