From 963e2728c20feb17af77613e8cf8cd50848735d1 Mon Sep 17 00:00:00 2001 From: Jasper Speicher Date: Wed, 14 Oct 2015 14:55:49 -0700 Subject: [PATCH] Remove logging from charts.js --- dist/components/omh-web-visualizations-charts.js | 3 --- dist/components/omh-web-visualizations-charts.min.js | 2 +- dist/omh-web-visualizations-all.js | 3 --- dist/omh-web-visualizations-all.min.js | 2 +- src/charts.js | 3 --- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/dist/components/omh-web-visualizations-charts.js b/dist/components/omh-web-visualizations-charts.js index 1df8dfb..390af52 100644 --- a/dist/components/omh-web-visualizations-charts.js +++ b/dist/components/omh-web-visualizations-charts.js @@ -320,9 +320,6 @@ //pull the datum value out based on the measure's keypath var valueKeyPath = getMeasureSettings( measure ).valueKeyPath; var yValue = resolveKeyPath( omhDatum, valueKeyPath ); - if (valueKeyPath == "body.minutes_moderate_activity.value" && yValue==undefined ){ - console.info('yValue ' + measure, omhDatum ); - } //create the datum that plottable will use parsedData[ measure ].push( { diff --git a/dist/components/omh-web-visualizations-charts.min.js b/dist/components/omh-web-visualizations-charts.min.js index 7bfc2f3..4f91368 100644 --- a/dist/components/omh-web-visualizations-charts.min.js +++ b/dist/components/omh-web-visualizations-charts.min.js @@ -1 +1 @@ -!function(e,t){var a="OMHWebVisualizations";e[a]=t(e,a),e[a].QUANTIZE_YEAR=6,e[a].QUANTIZE_MONTH=5,e[a].QUANTIZE_DAY=4,e[a].QUANTIZE_HOUR=3,e[a].QUANTIZE_MINUTE=2,e[a].QUANTIZE_SECOND=1,e[a].QUANTIZE_MILLISECOND=0,e[a].QUANTIZE_NONE=-1}(this,function(e,t){var a=e.hasOwnProperty(t)?e[t]:{};return a.Chart=function(e,t,a,n){var i=864e5,o=.5,r="1px",s="1px";t.jquery||(t=$(t)),n||(n={});var l=null;t.addClass("omh-chart-container");var u=null,m=a.split(/\s*,\s*/),c={},d={},h=null,p=null,v={userInterface:{toolbar:{enabled:!0},timespanButtons:{enabled:!0},zoomButtons:{enabled:!0},navigation:{enabled:!0},tooltips:{enabled:!0,timeFormat:"M/D/YY, h:mma"},panZoom:{enabled:!0,showHint:!0}},measures:{body_weight:{valueKeyPath:"body.body_weight.value",range:{min:0,max:100},units:"kg",thresholds:{max:57}},heart_rate:{valueKeyPath:"body.heart_rate.value",range:{min:30,max:150},units:"bpm"},step_count:{valueKeyPath:"body.step_count",range:{min:0,max:1500},units:"Steps",seriesName:"Steps",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",barColor:"#eeeeee",daysShownOnTimeline:{min:7,max:90}}},minutes_moderate_activity:{valueKeyPath:"body.minutes_moderate_activity.value",range:{min:0,max:300},units:"Minutes",seriesName:"Minutes of moderate activity",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",daysShownOnTimeline:{min:7,max:90}}},systolic_blood_pressure:{valueKeyPath:"body.systolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:120}},diastolic_blood_pressure:{valueKeyPath:"body.diastolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:80}}}},b={range:{min:0,max:100},units:"Units",seriesName:"Series",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_NONE,chart:{type:"line",pointSize:9,lineColor:"#dedede",pointFillColor:"#4a90e2",pointStrokeColor:"#0066d6",aboveThesholdPointFillColor:"#e8ac4e",aboveThesholdPointStrokeColor:"#745628",barColor:"#4a90e2",daysShownOnTimeline:{min:1,max:1e3}}};this.getComponents=function(){var e={};e[m[0]]=w;var t={};t[m[0]]=I;var a={};a[m[0]]=C;var n={};n[m[0]]=T;var i={};i[m[0]]=N;var o={};return o[m[0]]=F,$.each(W,function(n,i){e[i.measure]=i.scale,t[i.measure]=i.axis,a[i.measure]=i.label}),{xScales:n,yScales:e,colorScales:o,gridlines:null,legends:[R],xAxes:i,yAxes:t,plots:E,yLabels:a,table:h,tooltip:Se,toolbar:pe,panZoomInteractions:{plotGroup:ie,xAxis:oe}}},this.getD3Selection=function(){return l};var f=$.extend(!0,{},v,n);$.each(Object.keys(f.measures),function(e,t){f.measures[t]=$.extend(!0,{},b,f.measures[t])});var y=f.userInterface,g=function(e){return f.measures[e]},_={},x=function(e,t){if(void 0==e)return e;var a;"string"==typeof t?(_[t]||(_[t]=t.split(".")),a=_[t].slice()):a=t;try{if(t&&a.length>0)return x(e[a.shift()],a)}catch(n){}return e};this.getIntervalDisplayDate=function(e,t,a){var n,i=e.body.effective_time_frame.time_interval,o=i.start_date_time?new Date(i.start_date_time).getTime():null,r=i.end_date_time?new Date(i.end_date_time).getTime():null,s=i.start_date_time?t(i.start_date_time):null,l=i.end_date_time?t(i.end_date_time):null,u={ps:1e-9,ns:1e-6,us:.001,ms:1,sec:1e3,min:6e4,h:36e5,d:"d",wk:"w",Mo:"M",yr:"y"},m=i.duration.unit,c=i.duration.value,d=u[m];"string"!=typeof d?(n=c*d,o||(o=r-c),r||(r=o+c)):(o||(o=l.subtract(c,u[m]).valueOf()),r||(r=s.add(c,u[m]).valueOf()),n=r-o);var h=new Date(o),p=a<=OMHWebVisualizations.QUANTIZE_MONTH?h.getMonth():6,v=a<=OMHWebVisualizations.QUANTIZE_DAY?h.getDate():a===OMHWebVisualizations.QUANTIZE_MONTH?15:1,b=a<=OMHWebVisualizations.QUANTIZE_HOUR?h.getHours():a===OMHWebVisualizations.QUANTIZE_DAY?12:0,f=a<=OMHWebVisualizations.QUANTIZE_MINUTE?h.getMinutes():a===OMHWebVisualizations.QUANTIZE_HOUR?30:0,y=a<=OMHWebVisualizations.QUANTIZE_SECOND?h.getSeconds():a===OMHWebVisualizations.QUANTIZE_MINUTE?30:0,g=a<=OMHWebVisualizations.QUANTIZE_MILLISECOND?h.getMilliseconds():a===OMHWebVisualizations.QUANTIZE_SECOND?500:0,_=new Date(h.getFullYear(),p,v,b,f,y,g);return _},this.parseOmhData=function(e,t,a){var n={},i=this;return $.each(e,function(e,o){$.each(t,function(e,t){var r=g(t).valueKeyPath,s=x(o,r);if(void 0!==s&&"object"!=typeof s){o.groupName+="_"+t,n.hasOwnProperty(t)||(n[t]=[]);var l;if(o.body.effective_time_frame.date_time&&(l=new Date(o.body.effective_time_frame.date_time)),o.body.effective_time_frame.time_interval){var u=g(t).timeQuantizationLevel;l=i.getIntervalDisplayDate(o,a,u)}var m=g(t).valueKeyPath,c=x(o,m);"body.minutes_moderate_activity.value"==m&&void 0==c&&console.info("yValue "+t,o),n[t].push({y:c,x:l,provider:o.header.acquisition_provenance.source_name,omhDatum:o,hasTooltip:0==e,measure:t})}})}),n},u=this.parseOmhData(e,m,moment),this.consolidateData=function(e){e.sort(function(e,t){return e.x.getTime()-t.x.getTime()});for(var t=0;tt.max},U=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointFillColor:t.pointFillColor},z=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointStrokeColor:t.pointStrokeColor},H=function(e){return g(e.measure).chart.barColor},Q=(new Plottable.Plots.Scatter).x(function(e){return e.x},T).y(function(e){return e.y},w).size(function(e){return g(e.measure).chart.pointSize}).attr("fill",function(e){return U(e)}).attr("opacity",o).attr("stroke-width",s).attr("stroke",function(e){return z(e)}),k=[],L=0,W=[];$.each(u,function(e,t){"clustered_bar"===g(e).chart.type&&L++}),$.each(m,function(t,a){if(u.hasOwnProperty(a)){e=u[a];var n=new Plottable.Dataset(e),i=g(a);if(n.measure=a,"clustered_bar"===i.chart.type){var o=w;if(k.length>0){var s=i.range,l=i.units;o=(new Plottable.Scales.Linear).domainMin(s.min).domainMax(s.max);var m=new Plottable.Axes.Numeric(o,"right"),c=new Plottable.Components.AxisLabel(l,"0").padding(5).xAlignment("left").yAlignment("top");W.push({measure:a,axis:m,label:c,scale:o})}var d=(new Plottable.Plots.ClusteredBar).x(function(e){return e.x},T).y(function(e){return e.y},o).attr("fill",function(e){return H(e)});k.push(d);for(var h=0;L>h;h++)d.addDataset(h===k.length-1?n:new Plottable.Dataset([]));var p=N.axisConfigurations(),v=[];$.each(p,function(e,t){("day"===t[0].interval||"month"===t[0].interval||"year"===t[0].interval)&&v.push(t)}),N.axisConfigurations(v),E.push(d)}else{var b=(new Plottable.Plots.Line).x(function(e){return e.x},T).y(function(e){return e.y},w).attr("stroke",i.chart.lineColor).attr("stroke-width",r);b.addDataset(n),Q.addDataset(n),E.push(b)}}});var V=(new Plottable.Scales.Linear).domainMin(0).domainMax(1),B=(new Plottable.Plots.Line).x(function(e){return e.x},V).y(function(e){return e.y},w).attr("stroke","#dedede").attr("stroke-width",r);$.each(u,function(e,t){var a=g(e).thresholds;a&&B.addDataset(new Plottable.Dataset([{x:0,y:a.max},{x:1,y:a.max}]))}),E.push(B),E.push(Q);var F=null,R=null;if(L>0){F=new Plottable.Scales.Color,R=new Plottable.Components.Legend(F);var Y=[],K=[];$.each(u,function(e,t){var a=g(e),n=a.seriesName,i=a.chart.barColor;n&&i&&(Y.push(n),K.push(i))}),F.domain(Y),F.range(K),R.maxEntriesPerRow(2),R.symbol(Plottable.SymbolFactories.square),R.xAlignment("right"),R.yAlignment("top"),E.push(R)}if(y.panZoom.enabled&&y.panZoom.showHint){var G=new Plottable.Components.Label("( Drag chart to pan, pinch or scroll to zoom )",0).padding(10).yAlignment("bottom").xAlignment("right").addClass("zoom-hint-label"),j=((new Plottable.Interactions.Click).attachTo(G).onClick(function(e){j()}),function(){G.addClass("hidden")});E.push(G)}var q=new Plottable.Components.Group(E),X=new Plottable.Components.Group([I,C]),J=[X,q],ee=[null,N];$.each(W,function(e,t){J.push(new Plottable.Components.Group([t.axis,t.label])),ee.push(null)}),h=new Plottable.Components.Table([J,ee]),h.yAlignment("bottom"),A.attachTo(h);var te=D.chart.daysShownOnTimeline,ae=te.min,ne=te.max,ie=null,oe=null;if(y.panZoom.enabled&&(ie=new Plottable.Interactions.PanZoom,ie.addXScale(T),ie.attachTo(q),oe=new Plottable.Interactions.PanZoom,oe.addXScale(T),oe.attachTo(N),ae&&(ie.minDomainExtent(T,ae*i),oe.minDomainExtent(T,ae*i)),ne&&(ie.maxDomainExtent(T,ne*i),oe.maxDomainExtent(T,ne*i))),ne){var re=[];$.each(u,function(e,t){$.each(t,function(e,t){re.push(t.x)})});var se=T.extentOfValues(re),le=se[1].getTime()-se[0].getTime(),ue=ne*i;le>ue&&(se[1]=new Date(se[0].getTime()+ue)),T.domain(se)}var me=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max;a&&(e=Math.max(e,a)),n&&(e=Math.min(e,n));var o=T.domain(),r=[o[0],new Date(o[0].getTime()+e*i)];T.domain(r)},ce=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max,o=T.domain();timeInDays=(o[1].getTime()-o[0].getTime())/i,timeInDays*=(100-e)/100,a&&(timeInDays=Math.max(timeInDays,a)),n&&(timeInDays=Math.min(timeInDays,n));var r=[o[0],new Date(o[0].getTime()+timeInDays*i)];T.domain(r)},de=function(e){var t=T.domain();timeInDays=(t[1].getTime()-t[0].getTime())/i,timeInDays*=e/100;var a=[new Date(t[0].getTime()+timeInDays*i),new Date(t[1].getTime()+timeInDays*i)];T.domain(a)},he=function(){$(".time-button").removeClass("active")},pe=null;if(y.toolbar.enabled){if(pe=$("
"),pe.addClass("omh-chart-toolbar"),pe.attr("unselectable","on"),t.append(pe),y.timespanButtons.enabled){var ve={"1wk":7,"1m":30,"3m":90,"6m":180};pe.append($('Show: ')),$.each(ve,function(e,t){if(ne>=t&&t>=ae){var a=$(''+e+"");a.on("click",function(){he(),me(t),$(this).addClass("active")}),pe.append(a)}})}if(y.zoomButtons.enabled){var be={"−":-20,"+":20};pe.append($(' Zoom: ')),$.each(be,function(e,t){var a=$(''+e+"");a.on("click",function(){he(),ce(t)}),pe.append(a)})}if(y.navigation.enabled){var fe=$('< prev').click(function(){de(-100)});pe.prepend(fe);var ye=$('next >').click(function(){de(100)});pe.append(ye)}}var ge=Q.datasets(),_e=ge&&ge.length>0;if(y.tooltips.enabled&&_e){var xe=null,De=function(e){e.selection.style("opacity","1")},Te=function(e){e.selection.style("opacity",o)},we=function(e,t){$.each(d[e][t],function(e,t){De(t)})},Pe=function(e,t){$.each(d[e][t],function(e,t){Te(t)})},Ne=function(e){Se.show(e.datum,e.selection[0][0])},Ie=function(e){e&&l&&(e.selection[0][0].getBoundingClientRect().left>l[0][0].getBoundingClientRect().left&&e.selection[0][0].getBoundingClientRect().rightl[0][0].getBoundingClientRect().top+t?e:xe)}},Ae=function(e){null!==xe?e.datum.omhDatum.body!==xe.datum.omhDatum.body&&(Pe(xe.datum.omhDatum.groupName,xe.index),xe=e,we(xe.datum.omhDatum.groupName,e.index)):xe=e,null===e.datum},Me=new Plottable.Interactions.Pointer;Me.onPointerExit(function(e){Se.hide()}),Me.onPointerEnter(Ce.bind(this));var Oe=function(e){var t;try{t=Q.entityNearest(e)}catch(a){return}Ae(t),Ce()}.bind(this);Me.onPointerMove(Oe),Me.attachTo(Q);var Ee=function(e,t){var a,n="value";if(Z(e)&&(n+=" above-threshold"),"_systolic_blood_pressure_diastolic_blood_pressure"===e.omhDatum.groupName){var i=e.omhDatum.body.systolic_blood_pressure.value.toFixed(0),o=e.omhDatum.body.diastolic_blood_pressure.value.toFixed(0);a='
'+i+"/"+o+"
"}else a="_heart_rate"===e.omhDatum.groupName?'
'+e.y.toFixed(0)+"
":'
'+e.y.toFixed(1)+"
";var r=y.tooltips.timeFormat;return a+='
'+moment(e.x).format(r)+"
",a+='
'+e.provider+"
"},Se=d3.tip().attr("class","d3-tip").html(function(e){return'
'+Ee(e,a)+"
"})}this.destroy=function(){Me&&Me.offPointerMove(Oe),Me&&Me.detachFrom(Q),A.detachFrom(h),h.destroy(),Se&&Se.destroy(),p&&p.offWheel(O),Ce&&A.offDrag(Ce),pe&&pe.remove(),$.each(S,function(e,t){t()})},this.renderTo=function(e){l=d3.select(e),Se&&l.call(Se),p&&p.offWheel(O),p=new Plottable.Dispatchers.Mouse.getDispatcher(l[0][0]).onWheel(O),h.renderTo(l),c={},d={},$.each(Q.entities(),function(e,t){var a=t.datum.omhDatum.groupName;c[a]||(c[a]=[]),t.datum.hasTooltip&&(c[a][t.index]=t),d[a]||(d[a]=[]),d[a][t.index]||(d[a][t.index]=[]),d[a][t.index].push(t)})}},a}); \ No newline at end of file +!function(e,t){var a="OMHWebVisualizations";e[a]=t(e,a),e[a].QUANTIZE_YEAR=6,e[a].QUANTIZE_MONTH=5,e[a].QUANTIZE_DAY=4,e[a].QUANTIZE_HOUR=3,e[a].QUANTIZE_MINUTE=2,e[a].QUANTIZE_SECOND=1,e[a].QUANTIZE_MILLISECOND=0,e[a].QUANTIZE_NONE=-1}(this,function(e,t){var a=e.hasOwnProperty(t)?e[t]:{};return a.Chart=function(e,t,a,n){var i=864e5,o=.5,r="1px",s="1px";t.jquery||(t=$(t)),n||(n={});var l=null;t.addClass("omh-chart-container");var u=null,m=a.split(/\s*,\s*/),c={},d={},h=null,p=null,v={userInterface:{toolbar:{enabled:!0},timespanButtons:{enabled:!0},zoomButtons:{enabled:!0},navigation:{enabled:!0},tooltips:{enabled:!0,timeFormat:"M/D/YY, h:mma"},panZoom:{enabled:!0,showHint:!0}},measures:{body_weight:{valueKeyPath:"body.body_weight.value",range:{min:0,max:100},units:"kg",thresholds:{max:57}},heart_rate:{valueKeyPath:"body.heart_rate.value",range:{min:30,max:150},units:"bpm"},step_count:{valueKeyPath:"body.step_count",range:{min:0,max:1500},units:"Steps",seriesName:"Steps",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",barColor:"#eeeeee",daysShownOnTimeline:{min:7,max:90}}},minutes_moderate_activity:{valueKeyPath:"body.minutes_moderate_activity.value",range:{min:0,max:300},units:"Minutes",seriesName:"Minutes of moderate activity",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",daysShownOnTimeline:{min:7,max:90}}},systolic_blood_pressure:{valueKeyPath:"body.systolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:120}},diastolic_blood_pressure:{valueKeyPath:"body.diastolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:80}}}},b={range:{min:0,max:100},units:"Units",seriesName:"Series",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_NONE,chart:{type:"line",pointSize:9,lineColor:"#dedede",pointFillColor:"#4a90e2",pointStrokeColor:"#0066d6",aboveThesholdPointFillColor:"#e8ac4e",aboveThesholdPointStrokeColor:"#745628",barColor:"#4a90e2",daysShownOnTimeline:{min:1,max:1e3}}};this.getComponents=function(){var e={};e[m[0]]=w;var t={};t[m[0]]=I;var a={};a[m[0]]=C;var n={};n[m[0]]=T;var i={};i[m[0]]=N;var o={};return o[m[0]]=F,$.each(W,function(n,i){e[i.measure]=i.scale,t[i.measure]=i.axis,a[i.measure]=i.label}),{xScales:n,yScales:e,colorScales:o,gridlines:null,legends:[R],xAxes:i,yAxes:t,plots:E,yLabels:a,table:h,tooltip:Se,toolbar:pe,panZoomInteractions:{plotGroup:ie,xAxis:oe}}},this.getD3Selection=function(){return l};var f=$.extend(!0,{},v,n);$.each(Object.keys(f.measures),function(e,t){f.measures[t]=$.extend(!0,{},b,f.measures[t])});var y=f.userInterface,g=function(e){return f.measures[e]},_={},x=function(e,t){if(void 0==e)return e;var a;"string"==typeof t?(_[t]||(_[t]=t.split(".")),a=_[t].slice()):a=t;try{if(t&&a.length>0)return x(e[a.shift()],a)}catch(n){}return e};this.getIntervalDisplayDate=function(e,t,a){var n,i=e.body.effective_time_frame.time_interval,o=i.start_date_time?new Date(i.start_date_time).getTime():null,r=i.end_date_time?new Date(i.end_date_time).getTime():null,s=i.start_date_time?t(i.start_date_time):null,l=i.end_date_time?t(i.end_date_time):null,u={ps:1e-9,ns:1e-6,us:.001,ms:1,sec:1e3,min:6e4,h:36e5,d:"d",wk:"w",Mo:"M",yr:"y"},m=i.duration.unit,c=i.duration.value,d=u[m];"string"!=typeof d?(n=c*d,o||(o=r-c),r||(r=o+c)):(o||(o=l.subtract(c,u[m]).valueOf()),r||(r=s.add(c,u[m]).valueOf()),n=r-o);var h=new Date(o),p=a<=OMHWebVisualizations.QUANTIZE_MONTH?h.getMonth():6,v=a<=OMHWebVisualizations.QUANTIZE_DAY?h.getDate():a===OMHWebVisualizations.QUANTIZE_MONTH?15:1,b=a<=OMHWebVisualizations.QUANTIZE_HOUR?h.getHours():a===OMHWebVisualizations.QUANTIZE_DAY?12:0,f=a<=OMHWebVisualizations.QUANTIZE_MINUTE?h.getMinutes():a===OMHWebVisualizations.QUANTIZE_HOUR?30:0,y=a<=OMHWebVisualizations.QUANTIZE_SECOND?h.getSeconds():a===OMHWebVisualizations.QUANTIZE_MINUTE?30:0,g=a<=OMHWebVisualizations.QUANTIZE_MILLISECOND?h.getMilliseconds():a===OMHWebVisualizations.QUANTIZE_SECOND?500:0,_=new Date(h.getFullYear(),p,v,b,f,y,g);return _},this.parseOmhData=function(e,t,a){var n={},i=this;return $.each(e,function(e,o){$.each(t,function(e,t){var r=g(t).valueKeyPath,s=x(o,r);if(void 0!==s&&"object"!=typeof s){o.groupName+="_"+t,n.hasOwnProperty(t)||(n[t]=[]);var l;if(o.body.effective_time_frame.date_time&&(l=new Date(o.body.effective_time_frame.date_time)),o.body.effective_time_frame.time_interval){var u=g(t).timeQuantizationLevel;l=i.getIntervalDisplayDate(o,a,u)}var m=g(t).valueKeyPath,c=x(o,m);n[t].push({y:c,x:l,provider:o.header.acquisition_provenance.source_name,omhDatum:o,hasTooltip:0==e,measure:t})}})}),n},u=this.parseOmhData(e,m,moment),this.consolidateData=function(e){e.sort(function(e,t){return e.x.getTime()-t.x.getTime()});for(var t=0;tt.max},U=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointFillColor:t.pointFillColor},z=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointStrokeColor:t.pointStrokeColor},H=function(e){return g(e.measure).chart.barColor},Q=(new Plottable.Plots.Scatter).x(function(e){return e.x},T).y(function(e){return e.y},w).size(function(e){return g(e.measure).chart.pointSize}).attr("fill",function(e){return U(e)}).attr("opacity",o).attr("stroke-width",s).attr("stroke",function(e){return z(e)}),k=[],L=0,W=[];$.each(u,function(e,t){"clustered_bar"===g(e).chart.type&&L++}),$.each(m,function(t,a){if(u.hasOwnProperty(a)){e=u[a];var n=new Plottable.Dataset(e),i=g(a);if(n.measure=a,"clustered_bar"===i.chart.type){var o=w;if(k.length>0){var s=i.range,l=i.units;o=(new Plottable.Scales.Linear).domainMin(s.min).domainMax(s.max);var m=new Plottable.Axes.Numeric(o,"right"),c=new Plottable.Components.AxisLabel(l,"0").padding(5).xAlignment("left").yAlignment("top");W.push({measure:a,axis:m,label:c,scale:o})}var d=(new Plottable.Plots.ClusteredBar).x(function(e){return e.x},T).y(function(e){return e.y},o).attr("fill",function(e){return H(e)});k.push(d);for(var h=0;L>h;h++)d.addDataset(h===k.length-1?n:new Plottable.Dataset([]));var p=N.axisConfigurations(),v=[];$.each(p,function(e,t){("day"===t[0].interval||"month"===t[0].interval||"year"===t[0].interval)&&v.push(t)}),N.axisConfigurations(v),E.push(d)}else{var b=(new Plottable.Plots.Line).x(function(e){return e.x},T).y(function(e){return e.y},w).attr("stroke",i.chart.lineColor).attr("stroke-width",r);b.addDataset(n),Q.addDataset(n),E.push(b)}}});var V=(new Plottable.Scales.Linear).domainMin(0).domainMax(1),B=(new Plottable.Plots.Line).x(function(e){return e.x},V).y(function(e){return e.y},w).attr("stroke","#dedede").attr("stroke-width",r);$.each(u,function(e,t){var a=g(e).thresholds;a&&B.addDataset(new Plottable.Dataset([{x:0,y:a.max},{x:1,y:a.max}]))}),E.push(B),E.push(Q);var F=null,R=null;if(L>0){F=new Plottable.Scales.Color,R=new Plottable.Components.Legend(F);var Y=[],K=[];$.each(u,function(e,t){var a=g(e),n=a.seriesName,i=a.chart.barColor;n&&i&&(Y.push(n),K.push(i))}),F.domain(Y),F.range(K),R.maxEntriesPerRow(2),R.symbol(Plottable.SymbolFactories.square),R.xAlignment("right"),R.yAlignment("top"),E.push(R)}if(y.panZoom.enabled&&y.panZoom.showHint){var G=new Plottable.Components.Label("( Drag chart to pan, pinch or scroll to zoom )",0).padding(10).yAlignment("bottom").xAlignment("right").addClass("zoom-hint-label"),j=((new Plottable.Interactions.Click).attachTo(G).onClick(function(e){j()}),function(){G.addClass("hidden")});E.push(G)}var q=new Plottable.Components.Group(E),X=new Plottable.Components.Group([I,C]),J=[X,q],ee=[null,N];$.each(W,function(e,t){J.push(new Plottable.Components.Group([t.axis,t.label])),ee.push(null)}),h=new Plottable.Components.Table([J,ee]),h.yAlignment("bottom"),A.attachTo(h);var te=D.chart.daysShownOnTimeline,ae=te.min,ne=te.max,ie=null,oe=null;if(y.panZoom.enabled&&(ie=new Plottable.Interactions.PanZoom,ie.addXScale(T),ie.attachTo(q),oe=new Plottable.Interactions.PanZoom,oe.addXScale(T),oe.attachTo(N),ae&&(ie.minDomainExtent(T,ae*i),oe.minDomainExtent(T,ae*i)),ne&&(ie.maxDomainExtent(T,ne*i),oe.maxDomainExtent(T,ne*i))),ne){var re=[];$.each(u,function(e,t){$.each(t,function(e,t){re.push(t.x)})});var se=T.extentOfValues(re),le=se[1].getTime()-se[0].getTime(),ue=ne*i;le>ue&&(se[1]=new Date(se[0].getTime()+ue)),T.domain(se)}var me=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max;a&&(e=Math.max(e,a)),n&&(e=Math.min(e,n));var o=T.domain(),r=[o[0],new Date(o[0].getTime()+e*i)];T.domain(r)},ce=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max,o=T.domain();timeInDays=(o[1].getTime()-o[0].getTime())/i,timeInDays*=(100-e)/100,a&&(timeInDays=Math.max(timeInDays,a)),n&&(timeInDays=Math.min(timeInDays,n));var r=[o[0],new Date(o[0].getTime()+timeInDays*i)];T.domain(r)},de=function(e){var t=T.domain();timeInDays=(t[1].getTime()-t[0].getTime())/i,timeInDays*=e/100;var a=[new Date(t[0].getTime()+timeInDays*i),new Date(t[1].getTime()+timeInDays*i)];T.domain(a)},he=function(){$(".time-button").removeClass("active")},pe=null;if(y.toolbar.enabled){if(pe=$("
"),pe.addClass("omh-chart-toolbar"),pe.attr("unselectable","on"),t.append(pe),y.timespanButtons.enabled){var ve={"1wk":7,"1m":30,"3m":90,"6m":180};pe.append($('Show: ')),$.each(ve,function(e,t){if(ne>=t&&t>=ae){var a=$(''+e+"");a.on("click",function(){he(),me(t),$(this).addClass("active")}),pe.append(a)}})}if(y.zoomButtons.enabled){var be={"−":-20,"+":20};pe.append($(' Zoom: ')),$.each(be,function(e,t){var a=$(''+e+"");a.on("click",function(){he(),ce(t)}),pe.append(a)})}if(y.navigation.enabled){var fe=$('< prev').click(function(){de(-100)});pe.prepend(fe);var ye=$('next >').click(function(){de(100)});pe.append(ye)}}var ge=Q.datasets(),_e=ge&&ge.length>0;if(y.tooltips.enabled&&_e){var xe=null,De=function(e){e.selection.style("opacity","1")},Te=function(e){e.selection.style("opacity",o)},we=function(e,t){$.each(d[e][t],function(e,t){De(t)})},Pe=function(e,t){$.each(d[e][t],function(e,t){Te(t)})},Ne=function(e){Se.show(e.datum,e.selection[0][0])},Ie=function(e){e&&l&&(e.selection[0][0].getBoundingClientRect().left>l[0][0].getBoundingClientRect().left&&e.selection[0][0].getBoundingClientRect().rightl[0][0].getBoundingClientRect().top+t?e:xe)}},Ae=function(e){null!==xe?e.datum.omhDatum.body!==xe.datum.omhDatum.body&&(Pe(xe.datum.omhDatum.groupName,xe.index),xe=e,we(xe.datum.omhDatum.groupName,e.index)):xe=e,null===e.datum},Me=new Plottable.Interactions.Pointer;Me.onPointerExit(function(e){Se.hide()}),Me.onPointerEnter(Ce.bind(this));var Oe=function(e){var t;try{t=Q.entityNearest(e)}catch(a){return}Ae(t),Ce()}.bind(this);Me.onPointerMove(Oe),Me.attachTo(Q);var Ee=function(e,t){var a,n="value";if(Z(e)&&(n+=" above-threshold"),"_systolic_blood_pressure_diastolic_blood_pressure"===e.omhDatum.groupName){var i=e.omhDatum.body.systolic_blood_pressure.value.toFixed(0),o=e.omhDatum.body.diastolic_blood_pressure.value.toFixed(0);a='
'+i+"/"+o+"
"}else a="_heart_rate"===e.omhDatum.groupName?'
'+e.y.toFixed(0)+"
":'
'+e.y.toFixed(1)+"
";var r=y.tooltips.timeFormat;return a+='
'+moment(e.x).format(r)+"
",a+='
'+e.provider+"
"},Se=d3.tip().attr("class","d3-tip").html(function(e){return'
'+Ee(e,a)+"
"})}this.destroy=function(){Me&&Me.offPointerMove(Oe),Me&&Me.detachFrom(Q),A.detachFrom(h),h.destroy(),Se&&Se.destroy(),p&&p.offWheel(O),Ce&&A.offDrag(Ce),pe&&pe.remove(),$.each(S,function(e,t){t()})},this.renderTo=function(e){l=d3.select(e),Se&&l.call(Se),p&&p.offWheel(O),p=new Plottable.Dispatchers.Mouse.getDispatcher(l[0][0]).onWheel(O),h.renderTo(l),c={},d={},$.each(Q.entities(),function(e,t){var a=t.datum.omhDatum.groupName;c[a]||(c[a]=[]),t.datum.hasTooltip&&(c[a][t.index]=t),d[a]||(d[a]=[]),d[a][t.index]||(d[a][t.index]=[]),d[a][t.index].push(t)})}},a}); \ No newline at end of file diff --git a/dist/omh-web-visualizations-all.js b/dist/omh-web-visualizations-all.js index 1df8dfb..390af52 100644 --- a/dist/omh-web-visualizations-all.js +++ b/dist/omh-web-visualizations-all.js @@ -320,9 +320,6 @@ //pull the datum value out based on the measure's keypath var valueKeyPath = getMeasureSettings( measure ).valueKeyPath; var yValue = resolveKeyPath( omhDatum, valueKeyPath ); - if (valueKeyPath == "body.minutes_moderate_activity.value" && yValue==undefined ){ - console.info('yValue ' + measure, omhDatum ); - } //create the datum that plottable will use parsedData[ measure ].push( { diff --git a/dist/omh-web-visualizations-all.min.js b/dist/omh-web-visualizations-all.min.js index 7bfc2f3..4f91368 100644 --- a/dist/omh-web-visualizations-all.min.js +++ b/dist/omh-web-visualizations-all.min.js @@ -1 +1 @@ -!function(e,t){var a="OMHWebVisualizations";e[a]=t(e,a),e[a].QUANTIZE_YEAR=6,e[a].QUANTIZE_MONTH=5,e[a].QUANTIZE_DAY=4,e[a].QUANTIZE_HOUR=3,e[a].QUANTIZE_MINUTE=2,e[a].QUANTIZE_SECOND=1,e[a].QUANTIZE_MILLISECOND=0,e[a].QUANTIZE_NONE=-1}(this,function(e,t){var a=e.hasOwnProperty(t)?e[t]:{};return a.Chart=function(e,t,a,n){var i=864e5,o=.5,r="1px",s="1px";t.jquery||(t=$(t)),n||(n={});var l=null;t.addClass("omh-chart-container");var u=null,m=a.split(/\s*,\s*/),c={},d={},h=null,p=null,v={userInterface:{toolbar:{enabled:!0},timespanButtons:{enabled:!0},zoomButtons:{enabled:!0},navigation:{enabled:!0},tooltips:{enabled:!0,timeFormat:"M/D/YY, h:mma"},panZoom:{enabled:!0,showHint:!0}},measures:{body_weight:{valueKeyPath:"body.body_weight.value",range:{min:0,max:100},units:"kg",thresholds:{max:57}},heart_rate:{valueKeyPath:"body.heart_rate.value",range:{min:30,max:150},units:"bpm"},step_count:{valueKeyPath:"body.step_count",range:{min:0,max:1500},units:"Steps",seriesName:"Steps",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",barColor:"#eeeeee",daysShownOnTimeline:{min:7,max:90}}},minutes_moderate_activity:{valueKeyPath:"body.minutes_moderate_activity.value",range:{min:0,max:300},units:"Minutes",seriesName:"Minutes of moderate activity",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",daysShownOnTimeline:{min:7,max:90}}},systolic_blood_pressure:{valueKeyPath:"body.systolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:120}},diastolic_blood_pressure:{valueKeyPath:"body.diastolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:80}}}},b={range:{min:0,max:100},units:"Units",seriesName:"Series",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_NONE,chart:{type:"line",pointSize:9,lineColor:"#dedede",pointFillColor:"#4a90e2",pointStrokeColor:"#0066d6",aboveThesholdPointFillColor:"#e8ac4e",aboveThesholdPointStrokeColor:"#745628",barColor:"#4a90e2",daysShownOnTimeline:{min:1,max:1e3}}};this.getComponents=function(){var e={};e[m[0]]=w;var t={};t[m[0]]=I;var a={};a[m[0]]=C;var n={};n[m[0]]=T;var i={};i[m[0]]=N;var o={};return o[m[0]]=F,$.each(W,function(n,i){e[i.measure]=i.scale,t[i.measure]=i.axis,a[i.measure]=i.label}),{xScales:n,yScales:e,colorScales:o,gridlines:null,legends:[R],xAxes:i,yAxes:t,plots:E,yLabels:a,table:h,tooltip:Se,toolbar:pe,panZoomInteractions:{plotGroup:ie,xAxis:oe}}},this.getD3Selection=function(){return l};var f=$.extend(!0,{},v,n);$.each(Object.keys(f.measures),function(e,t){f.measures[t]=$.extend(!0,{},b,f.measures[t])});var y=f.userInterface,g=function(e){return f.measures[e]},_={},x=function(e,t){if(void 0==e)return e;var a;"string"==typeof t?(_[t]||(_[t]=t.split(".")),a=_[t].slice()):a=t;try{if(t&&a.length>0)return x(e[a.shift()],a)}catch(n){}return e};this.getIntervalDisplayDate=function(e,t,a){var n,i=e.body.effective_time_frame.time_interval,o=i.start_date_time?new Date(i.start_date_time).getTime():null,r=i.end_date_time?new Date(i.end_date_time).getTime():null,s=i.start_date_time?t(i.start_date_time):null,l=i.end_date_time?t(i.end_date_time):null,u={ps:1e-9,ns:1e-6,us:.001,ms:1,sec:1e3,min:6e4,h:36e5,d:"d",wk:"w",Mo:"M",yr:"y"},m=i.duration.unit,c=i.duration.value,d=u[m];"string"!=typeof d?(n=c*d,o||(o=r-c),r||(r=o+c)):(o||(o=l.subtract(c,u[m]).valueOf()),r||(r=s.add(c,u[m]).valueOf()),n=r-o);var h=new Date(o),p=a<=OMHWebVisualizations.QUANTIZE_MONTH?h.getMonth():6,v=a<=OMHWebVisualizations.QUANTIZE_DAY?h.getDate():a===OMHWebVisualizations.QUANTIZE_MONTH?15:1,b=a<=OMHWebVisualizations.QUANTIZE_HOUR?h.getHours():a===OMHWebVisualizations.QUANTIZE_DAY?12:0,f=a<=OMHWebVisualizations.QUANTIZE_MINUTE?h.getMinutes():a===OMHWebVisualizations.QUANTIZE_HOUR?30:0,y=a<=OMHWebVisualizations.QUANTIZE_SECOND?h.getSeconds():a===OMHWebVisualizations.QUANTIZE_MINUTE?30:0,g=a<=OMHWebVisualizations.QUANTIZE_MILLISECOND?h.getMilliseconds():a===OMHWebVisualizations.QUANTIZE_SECOND?500:0,_=new Date(h.getFullYear(),p,v,b,f,y,g);return _},this.parseOmhData=function(e,t,a){var n={},i=this;return $.each(e,function(e,o){$.each(t,function(e,t){var r=g(t).valueKeyPath,s=x(o,r);if(void 0!==s&&"object"!=typeof s){o.groupName+="_"+t,n.hasOwnProperty(t)||(n[t]=[]);var l;if(o.body.effective_time_frame.date_time&&(l=new Date(o.body.effective_time_frame.date_time)),o.body.effective_time_frame.time_interval){var u=g(t).timeQuantizationLevel;l=i.getIntervalDisplayDate(o,a,u)}var m=g(t).valueKeyPath,c=x(o,m);"body.minutes_moderate_activity.value"==m&&void 0==c&&console.info("yValue "+t,o),n[t].push({y:c,x:l,provider:o.header.acquisition_provenance.source_name,omhDatum:o,hasTooltip:0==e,measure:t})}})}),n},u=this.parseOmhData(e,m,moment),this.consolidateData=function(e){e.sort(function(e,t){return e.x.getTime()-t.x.getTime()});for(var t=0;tt.max},U=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointFillColor:t.pointFillColor},z=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointStrokeColor:t.pointStrokeColor},H=function(e){return g(e.measure).chart.barColor},Q=(new Plottable.Plots.Scatter).x(function(e){return e.x},T).y(function(e){return e.y},w).size(function(e){return g(e.measure).chart.pointSize}).attr("fill",function(e){return U(e)}).attr("opacity",o).attr("stroke-width",s).attr("stroke",function(e){return z(e)}),k=[],L=0,W=[];$.each(u,function(e,t){"clustered_bar"===g(e).chart.type&&L++}),$.each(m,function(t,a){if(u.hasOwnProperty(a)){e=u[a];var n=new Plottable.Dataset(e),i=g(a);if(n.measure=a,"clustered_bar"===i.chart.type){var o=w;if(k.length>0){var s=i.range,l=i.units;o=(new Plottable.Scales.Linear).domainMin(s.min).domainMax(s.max);var m=new Plottable.Axes.Numeric(o,"right"),c=new Plottable.Components.AxisLabel(l,"0").padding(5).xAlignment("left").yAlignment("top");W.push({measure:a,axis:m,label:c,scale:o})}var d=(new Plottable.Plots.ClusteredBar).x(function(e){return e.x},T).y(function(e){return e.y},o).attr("fill",function(e){return H(e)});k.push(d);for(var h=0;L>h;h++)d.addDataset(h===k.length-1?n:new Plottable.Dataset([]));var p=N.axisConfigurations(),v=[];$.each(p,function(e,t){("day"===t[0].interval||"month"===t[0].interval||"year"===t[0].interval)&&v.push(t)}),N.axisConfigurations(v),E.push(d)}else{var b=(new Plottable.Plots.Line).x(function(e){return e.x},T).y(function(e){return e.y},w).attr("stroke",i.chart.lineColor).attr("stroke-width",r);b.addDataset(n),Q.addDataset(n),E.push(b)}}});var V=(new Plottable.Scales.Linear).domainMin(0).domainMax(1),B=(new Plottable.Plots.Line).x(function(e){return e.x},V).y(function(e){return e.y},w).attr("stroke","#dedede").attr("stroke-width",r);$.each(u,function(e,t){var a=g(e).thresholds;a&&B.addDataset(new Plottable.Dataset([{x:0,y:a.max},{x:1,y:a.max}]))}),E.push(B),E.push(Q);var F=null,R=null;if(L>0){F=new Plottable.Scales.Color,R=new Plottable.Components.Legend(F);var Y=[],K=[];$.each(u,function(e,t){var a=g(e),n=a.seriesName,i=a.chart.barColor;n&&i&&(Y.push(n),K.push(i))}),F.domain(Y),F.range(K),R.maxEntriesPerRow(2),R.symbol(Plottable.SymbolFactories.square),R.xAlignment("right"),R.yAlignment("top"),E.push(R)}if(y.panZoom.enabled&&y.panZoom.showHint){var G=new Plottable.Components.Label("( Drag chart to pan, pinch or scroll to zoom )",0).padding(10).yAlignment("bottom").xAlignment("right").addClass("zoom-hint-label"),j=((new Plottable.Interactions.Click).attachTo(G).onClick(function(e){j()}),function(){G.addClass("hidden")});E.push(G)}var q=new Plottable.Components.Group(E),X=new Plottable.Components.Group([I,C]),J=[X,q],ee=[null,N];$.each(W,function(e,t){J.push(new Plottable.Components.Group([t.axis,t.label])),ee.push(null)}),h=new Plottable.Components.Table([J,ee]),h.yAlignment("bottom"),A.attachTo(h);var te=D.chart.daysShownOnTimeline,ae=te.min,ne=te.max,ie=null,oe=null;if(y.panZoom.enabled&&(ie=new Plottable.Interactions.PanZoom,ie.addXScale(T),ie.attachTo(q),oe=new Plottable.Interactions.PanZoom,oe.addXScale(T),oe.attachTo(N),ae&&(ie.minDomainExtent(T,ae*i),oe.minDomainExtent(T,ae*i)),ne&&(ie.maxDomainExtent(T,ne*i),oe.maxDomainExtent(T,ne*i))),ne){var re=[];$.each(u,function(e,t){$.each(t,function(e,t){re.push(t.x)})});var se=T.extentOfValues(re),le=se[1].getTime()-se[0].getTime(),ue=ne*i;le>ue&&(se[1]=new Date(se[0].getTime()+ue)),T.domain(se)}var me=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max;a&&(e=Math.max(e,a)),n&&(e=Math.min(e,n));var o=T.domain(),r=[o[0],new Date(o[0].getTime()+e*i)];T.domain(r)},ce=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max,o=T.domain();timeInDays=(o[1].getTime()-o[0].getTime())/i,timeInDays*=(100-e)/100,a&&(timeInDays=Math.max(timeInDays,a)),n&&(timeInDays=Math.min(timeInDays,n));var r=[o[0],new Date(o[0].getTime()+timeInDays*i)];T.domain(r)},de=function(e){var t=T.domain();timeInDays=(t[1].getTime()-t[0].getTime())/i,timeInDays*=e/100;var a=[new Date(t[0].getTime()+timeInDays*i),new Date(t[1].getTime()+timeInDays*i)];T.domain(a)},he=function(){$(".time-button").removeClass("active")},pe=null;if(y.toolbar.enabled){if(pe=$("
"),pe.addClass("omh-chart-toolbar"),pe.attr("unselectable","on"),t.append(pe),y.timespanButtons.enabled){var ve={"1wk":7,"1m":30,"3m":90,"6m":180};pe.append($('Show: ')),$.each(ve,function(e,t){if(ne>=t&&t>=ae){var a=$(''+e+"");a.on("click",function(){he(),me(t),$(this).addClass("active")}),pe.append(a)}})}if(y.zoomButtons.enabled){var be={"−":-20,"+":20};pe.append($(' Zoom: ')),$.each(be,function(e,t){var a=$(''+e+"");a.on("click",function(){he(),ce(t)}),pe.append(a)})}if(y.navigation.enabled){var fe=$('< prev').click(function(){de(-100)});pe.prepend(fe);var ye=$('next >').click(function(){de(100)});pe.append(ye)}}var ge=Q.datasets(),_e=ge&&ge.length>0;if(y.tooltips.enabled&&_e){var xe=null,De=function(e){e.selection.style("opacity","1")},Te=function(e){e.selection.style("opacity",o)},we=function(e,t){$.each(d[e][t],function(e,t){De(t)})},Pe=function(e,t){$.each(d[e][t],function(e,t){Te(t)})},Ne=function(e){Se.show(e.datum,e.selection[0][0])},Ie=function(e){e&&l&&(e.selection[0][0].getBoundingClientRect().left>l[0][0].getBoundingClientRect().left&&e.selection[0][0].getBoundingClientRect().rightl[0][0].getBoundingClientRect().top+t?e:xe)}},Ae=function(e){null!==xe?e.datum.omhDatum.body!==xe.datum.omhDatum.body&&(Pe(xe.datum.omhDatum.groupName,xe.index),xe=e,we(xe.datum.omhDatum.groupName,e.index)):xe=e,null===e.datum},Me=new Plottable.Interactions.Pointer;Me.onPointerExit(function(e){Se.hide()}),Me.onPointerEnter(Ce.bind(this));var Oe=function(e){var t;try{t=Q.entityNearest(e)}catch(a){return}Ae(t),Ce()}.bind(this);Me.onPointerMove(Oe),Me.attachTo(Q);var Ee=function(e,t){var a,n="value";if(Z(e)&&(n+=" above-threshold"),"_systolic_blood_pressure_diastolic_blood_pressure"===e.omhDatum.groupName){var i=e.omhDatum.body.systolic_blood_pressure.value.toFixed(0),o=e.omhDatum.body.diastolic_blood_pressure.value.toFixed(0);a='
'+i+"/"+o+"
"}else a="_heart_rate"===e.omhDatum.groupName?'
'+e.y.toFixed(0)+"
":'
'+e.y.toFixed(1)+"
";var r=y.tooltips.timeFormat;return a+='
'+moment(e.x).format(r)+"
",a+='
'+e.provider+"
"},Se=d3.tip().attr("class","d3-tip").html(function(e){return'
'+Ee(e,a)+"
"})}this.destroy=function(){Me&&Me.offPointerMove(Oe),Me&&Me.detachFrom(Q),A.detachFrom(h),h.destroy(),Se&&Se.destroy(),p&&p.offWheel(O),Ce&&A.offDrag(Ce),pe&&pe.remove(),$.each(S,function(e,t){t()})},this.renderTo=function(e){l=d3.select(e),Se&&l.call(Se),p&&p.offWheel(O),p=new Plottable.Dispatchers.Mouse.getDispatcher(l[0][0]).onWheel(O),h.renderTo(l),c={},d={},$.each(Q.entities(),function(e,t){var a=t.datum.omhDatum.groupName;c[a]||(c[a]=[]),t.datum.hasTooltip&&(c[a][t.index]=t),d[a]||(d[a]=[]),d[a][t.index]||(d[a][t.index]=[]),d[a][t.index].push(t)})}},a}); \ No newline at end of file +!function(e,t){var a="OMHWebVisualizations";e[a]=t(e,a),e[a].QUANTIZE_YEAR=6,e[a].QUANTIZE_MONTH=5,e[a].QUANTIZE_DAY=4,e[a].QUANTIZE_HOUR=3,e[a].QUANTIZE_MINUTE=2,e[a].QUANTIZE_SECOND=1,e[a].QUANTIZE_MILLISECOND=0,e[a].QUANTIZE_NONE=-1}(this,function(e,t){var a=e.hasOwnProperty(t)?e[t]:{};return a.Chart=function(e,t,a,n){var i=864e5,o=.5,r="1px",s="1px";t.jquery||(t=$(t)),n||(n={});var l=null;t.addClass("omh-chart-container");var u=null,m=a.split(/\s*,\s*/),c={},d={},h=null,p=null,v={userInterface:{toolbar:{enabled:!0},timespanButtons:{enabled:!0},zoomButtons:{enabled:!0},navigation:{enabled:!0},tooltips:{enabled:!0,timeFormat:"M/D/YY, h:mma"},panZoom:{enabled:!0,showHint:!0}},measures:{body_weight:{valueKeyPath:"body.body_weight.value",range:{min:0,max:100},units:"kg",thresholds:{max:57}},heart_rate:{valueKeyPath:"body.heart_rate.value",range:{min:30,max:150},units:"bpm"},step_count:{valueKeyPath:"body.step_count",range:{min:0,max:1500},units:"Steps",seriesName:"Steps",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",barColor:"#eeeeee",daysShownOnTimeline:{min:7,max:90}}},minutes_moderate_activity:{valueKeyPath:"body.minutes_moderate_activity.value",range:{min:0,max:300},units:"Minutes",seriesName:"Minutes of moderate activity",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_DAY,chart:{type:"clustered_bar",daysShownOnTimeline:{min:7,max:90}}},systolic_blood_pressure:{valueKeyPath:"body.systolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:120}},diastolic_blood_pressure:{valueKeyPath:"body.diastolic_blood_pressure.value",range:{min:30,max:200},units:"mmHg",thresholds:{max:80}}}},b={range:{min:0,max:100},units:"Units",seriesName:"Series",timeQuantizationLevel:OMHWebVisualizations.QUANTIZE_NONE,chart:{type:"line",pointSize:9,lineColor:"#dedede",pointFillColor:"#4a90e2",pointStrokeColor:"#0066d6",aboveThesholdPointFillColor:"#e8ac4e",aboveThesholdPointStrokeColor:"#745628",barColor:"#4a90e2",daysShownOnTimeline:{min:1,max:1e3}}};this.getComponents=function(){var e={};e[m[0]]=w;var t={};t[m[0]]=I;var a={};a[m[0]]=C;var n={};n[m[0]]=T;var i={};i[m[0]]=N;var o={};return o[m[0]]=F,$.each(W,function(n,i){e[i.measure]=i.scale,t[i.measure]=i.axis,a[i.measure]=i.label}),{xScales:n,yScales:e,colorScales:o,gridlines:null,legends:[R],xAxes:i,yAxes:t,plots:E,yLabels:a,table:h,tooltip:Se,toolbar:pe,panZoomInteractions:{plotGroup:ie,xAxis:oe}}},this.getD3Selection=function(){return l};var f=$.extend(!0,{},v,n);$.each(Object.keys(f.measures),function(e,t){f.measures[t]=$.extend(!0,{},b,f.measures[t])});var y=f.userInterface,g=function(e){return f.measures[e]},_={},x=function(e,t){if(void 0==e)return e;var a;"string"==typeof t?(_[t]||(_[t]=t.split(".")),a=_[t].slice()):a=t;try{if(t&&a.length>0)return x(e[a.shift()],a)}catch(n){}return e};this.getIntervalDisplayDate=function(e,t,a){var n,i=e.body.effective_time_frame.time_interval,o=i.start_date_time?new Date(i.start_date_time).getTime():null,r=i.end_date_time?new Date(i.end_date_time).getTime():null,s=i.start_date_time?t(i.start_date_time):null,l=i.end_date_time?t(i.end_date_time):null,u={ps:1e-9,ns:1e-6,us:.001,ms:1,sec:1e3,min:6e4,h:36e5,d:"d",wk:"w",Mo:"M",yr:"y"},m=i.duration.unit,c=i.duration.value,d=u[m];"string"!=typeof d?(n=c*d,o||(o=r-c),r||(r=o+c)):(o||(o=l.subtract(c,u[m]).valueOf()),r||(r=s.add(c,u[m]).valueOf()),n=r-o);var h=new Date(o),p=a<=OMHWebVisualizations.QUANTIZE_MONTH?h.getMonth():6,v=a<=OMHWebVisualizations.QUANTIZE_DAY?h.getDate():a===OMHWebVisualizations.QUANTIZE_MONTH?15:1,b=a<=OMHWebVisualizations.QUANTIZE_HOUR?h.getHours():a===OMHWebVisualizations.QUANTIZE_DAY?12:0,f=a<=OMHWebVisualizations.QUANTIZE_MINUTE?h.getMinutes():a===OMHWebVisualizations.QUANTIZE_HOUR?30:0,y=a<=OMHWebVisualizations.QUANTIZE_SECOND?h.getSeconds():a===OMHWebVisualizations.QUANTIZE_MINUTE?30:0,g=a<=OMHWebVisualizations.QUANTIZE_MILLISECOND?h.getMilliseconds():a===OMHWebVisualizations.QUANTIZE_SECOND?500:0,_=new Date(h.getFullYear(),p,v,b,f,y,g);return _},this.parseOmhData=function(e,t,a){var n={},i=this;return $.each(e,function(e,o){$.each(t,function(e,t){var r=g(t).valueKeyPath,s=x(o,r);if(void 0!==s&&"object"!=typeof s){o.groupName+="_"+t,n.hasOwnProperty(t)||(n[t]=[]);var l;if(o.body.effective_time_frame.date_time&&(l=new Date(o.body.effective_time_frame.date_time)),o.body.effective_time_frame.time_interval){var u=g(t).timeQuantizationLevel;l=i.getIntervalDisplayDate(o,a,u)}var m=g(t).valueKeyPath,c=x(o,m);n[t].push({y:c,x:l,provider:o.header.acquisition_provenance.source_name,omhDatum:o,hasTooltip:0==e,measure:t})}})}),n},u=this.parseOmhData(e,m,moment),this.consolidateData=function(e){e.sort(function(e,t){return e.x.getTime()-t.x.getTime()});for(var t=0;tt.max},U=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointFillColor:t.pointFillColor},z=function(e){var t=g(e.measure).chart;return Z(e)?t.aboveThesholdPointStrokeColor:t.pointStrokeColor},H=function(e){return g(e.measure).chart.barColor},Q=(new Plottable.Plots.Scatter).x(function(e){return e.x},T).y(function(e){return e.y},w).size(function(e){return g(e.measure).chart.pointSize}).attr("fill",function(e){return U(e)}).attr("opacity",o).attr("stroke-width",s).attr("stroke",function(e){return z(e)}),k=[],L=0,W=[];$.each(u,function(e,t){"clustered_bar"===g(e).chart.type&&L++}),$.each(m,function(t,a){if(u.hasOwnProperty(a)){e=u[a];var n=new Plottable.Dataset(e),i=g(a);if(n.measure=a,"clustered_bar"===i.chart.type){var o=w;if(k.length>0){var s=i.range,l=i.units;o=(new Plottable.Scales.Linear).domainMin(s.min).domainMax(s.max);var m=new Plottable.Axes.Numeric(o,"right"),c=new Plottable.Components.AxisLabel(l,"0").padding(5).xAlignment("left").yAlignment("top");W.push({measure:a,axis:m,label:c,scale:o})}var d=(new Plottable.Plots.ClusteredBar).x(function(e){return e.x},T).y(function(e){return e.y},o).attr("fill",function(e){return H(e)});k.push(d);for(var h=0;L>h;h++)d.addDataset(h===k.length-1?n:new Plottable.Dataset([]));var p=N.axisConfigurations(),v=[];$.each(p,function(e,t){("day"===t[0].interval||"month"===t[0].interval||"year"===t[0].interval)&&v.push(t)}),N.axisConfigurations(v),E.push(d)}else{var b=(new Plottable.Plots.Line).x(function(e){return e.x},T).y(function(e){return e.y},w).attr("stroke",i.chart.lineColor).attr("stroke-width",r);b.addDataset(n),Q.addDataset(n),E.push(b)}}});var V=(new Plottable.Scales.Linear).domainMin(0).domainMax(1),B=(new Plottable.Plots.Line).x(function(e){return e.x},V).y(function(e){return e.y},w).attr("stroke","#dedede").attr("stroke-width",r);$.each(u,function(e,t){var a=g(e).thresholds;a&&B.addDataset(new Plottable.Dataset([{x:0,y:a.max},{x:1,y:a.max}]))}),E.push(B),E.push(Q);var F=null,R=null;if(L>0){F=new Plottable.Scales.Color,R=new Plottable.Components.Legend(F);var Y=[],K=[];$.each(u,function(e,t){var a=g(e),n=a.seriesName,i=a.chart.barColor;n&&i&&(Y.push(n),K.push(i))}),F.domain(Y),F.range(K),R.maxEntriesPerRow(2),R.symbol(Plottable.SymbolFactories.square),R.xAlignment("right"),R.yAlignment("top"),E.push(R)}if(y.panZoom.enabled&&y.panZoom.showHint){var G=new Plottable.Components.Label("( Drag chart to pan, pinch or scroll to zoom )",0).padding(10).yAlignment("bottom").xAlignment("right").addClass("zoom-hint-label"),j=((new Plottable.Interactions.Click).attachTo(G).onClick(function(e){j()}),function(){G.addClass("hidden")});E.push(G)}var q=new Plottable.Components.Group(E),X=new Plottable.Components.Group([I,C]),J=[X,q],ee=[null,N];$.each(W,function(e,t){J.push(new Plottable.Components.Group([t.axis,t.label])),ee.push(null)}),h=new Plottable.Components.Table([J,ee]),h.yAlignment("bottom"),A.attachTo(h);var te=D.chart.daysShownOnTimeline,ae=te.min,ne=te.max,ie=null,oe=null;if(y.panZoom.enabled&&(ie=new Plottable.Interactions.PanZoom,ie.addXScale(T),ie.attachTo(q),oe=new Plottable.Interactions.PanZoom,oe.addXScale(T),oe.attachTo(N),ae&&(ie.minDomainExtent(T,ae*i),oe.minDomainExtent(T,ae*i)),ne&&(ie.maxDomainExtent(T,ne*i),oe.maxDomainExtent(T,ne*i))),ne){var re=[];$.each(u,function(e,t){$.each(t,function(e,t){re.push(t.x)})});var se=T.extentOfValues(re),le=se[1].getTime()-se[0].getTime(),ue=ne*i;le>ue&&(se[1]=new Date(se[0].getTime()+ue)),T.domain(se)}var me=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max;a&&(e=Math.max(e,a)),n&&(e=Math.min(e,n));var o=T.domain(),r=[o[0],new Date(o[0].getTime()+e*i)];T.domain(r)},ce=function(e){var t=D.chart.daysShownOnTimeline,a=t.min,n=t.max,o=T.domain();timeInDays=(o[1].getTime()-o[0].getTime())/i,timeInDays*=(100-e)/100,a&&(timeInDays=Math.max(timeInDays,a)),n&&(timeInDays=Math.min(timeInDays,n));var r=[o[0],new Date(o[0].getTime()+timeInDays*i)];T.domain(r)},de=function(e){var t=T.domain();timeInDays=(t[1].getTime()-t[0].getTime())/i,timeInDays*=e/100;var a=[new Date(t[0].getTime()+timeInDays*i),new Date(t[1].getTime()+timeInDays*i)];T.domain(a)},he=function(){$(".time-button").removeClass("active")},pe=null;if(y.toolbar.enabled){if(pe=$("
"),pe.addClass("omh-chart-toolbar"),pe.attr("unselectable","on"),t.append(pe),y.timespanButtons.enabled){var ve={"1wk":7,"1m":30,"3m":90,"6m":180};pe.append($('Show: ')),$.each(ve,function(e,t){if(ne>=t&&t>=ae){var a=$(''+e+"");a.on("click",function(){he(),me(t),$(this).addClass("active")}),pe.append(a)}})}if(y.zoomButtons.enabled){var be={"−":-20,"+":20};pe.append($(' Zoom: ')),$.each(be,function(e,t){var a=$(''+e+"");a.on("click",function(){he(),ce(t)}),pe.append(a)})}if(y.navigation.enabled){var fe=$('< prev').click(function(){de(-100)});pe.prepend(fe);var ye=$('next >').click(function(){de(100)});pe.append(ye)}}var ge=Q.datasets(),_e=ge&&ge.length>0;if(y.tooltips.enabled&&_e){var xe=null,De=function(e){e.selection.style("opacity","1")},Te=function(e){e.selection.style("opacity",o)},we=function(e,t){$.each(d[e][t],function(e,t){De(t)})},Pe=function(e,t){$.each(d[e][t],function(e,t){Te(t)})},Ne=function(e){Se.show(e.datum,e.selection[0][0])},Ie=function(e){e&&l&&(e.selection[0][0].getBoundingClientRect().left>l[0][0].getBoundingClientRect().left&&e.selection[0][0].getBoundingClientRect().rightl[0][0].getBoundingClientRect().top+t?e:xe)}},Ae=function(e){null!==xe?e.datum.omhDatum.body!==xe.datum.omhDatum.body&&(Pe(xe.datum.omhDatum.groupName,xe.index),xe=e,we(xe.datum.omhDatum.groupName,e.index)):xe=e,null===e.datum},Me=new Plottable.Interactions.Pointer;Me.onPointerExit(function(e){Se.hide()}),Me.onPointerEnter(Ce.bind(this));var Oe=function(e){var t;try{t=Q.entityNearest(e)}catch(a){return}Ae(t),Ce()}.bind(this);Me.onPointerMove(Oe),Me.attachTo(Q);var Ee=function(e,t){var a,n="value";if(Z(e)&&(n+=" above-threshold"),"_systolic_blood_pressure_diastolic_blood_pressure"===e.omhDatum.groupName){var i=e.omhDatum.body.systolic_blood_pressure.value.toFixed(0),o=e.omhDatum.body.diastolic_blood_pressure.value.toFixed(0);a='
'+i+"/"+o+"
"}else a="_heart_rate"===e.omhDatum.groupName?'
'+e.y.toFixed(0)+"
":'
'+e.y.toFixed(1)+"
";var r=y.tooltips.timeFormat;return a+='
'+moment(e.x).format(r)+"
",a+='
'+e.provider+"
"},Se=d3.tip().attr("class","d3-tip").html(function(e){return'
'+Ee(e,a)+"
"})}this.destroy=function(){Me&&Me.offPointerMove(Oe),Me&&Me.detachFrom(Q),A.detachFrom(h),h.destroy(),Se&&Se.destroy(),p&&p.offWheel(O),Ce&&A.offDrag(Ce),pe&&pe.remove(),$.each(S,function(e,t){t()})},this.renderTo=function(e){l=d3.select(e),Se&&l.call(Se),p&&p.offWheel(O),p=new Plottable.Dispatchers.Mouse.getDispatcher(l[0][0]).onWheel(O),h.renderTo(l),c={},d={},$.each(Q.entities(),function(e,t){var a=t.datum.omhDatum.groupName;c[a]||(c[a]=[]),t.datum.hasTooltip&&(c[a][t.index]=t),d[a]||(d[a]=[]),d[a][t.index]||(d[a][t.index]=[]),d[a][t.index].push(t)})}},a}); \ No newline at end of file diff --git a/src/charts.js b/src/charts.js index 1df8dfb..390af52 100644 --- a/src/charts.js +++ b/src/charts.js @@ -320,9 +320,6 @@ //pull the datum value out based on the measure's keypath var valueKeyPath = getMeasureSettings( measure ).valueKeyPath; var yValue = resolveKeyPath( omhDatum, valueKeyPath ); - if (valueKeyPath == "body.minutes_moderate_activity.value" && yValue==undefined ){ - console.info('yValue ' + measure, omhDatum ); - } //create the datum that plottable will use parsedData[ measure ].push( {