diff --git a/app/js/mdot.js b/app/js/mdot.js index b292512..4690004 100644 --- a/app/js/mdot.js +++ b/app/js/mdot.js @@ -273,9 +273,19 @@ var self = this; var chartData = []; + var temporal = {high:0, low:0}; + _(this.collection.models).each(function(i) { + var dt = i.get('dt'); + if (temporal.low === 0 || dt < temporal.low) { + temporal.low = dt; + } + if (temporal.high === 0 || dt > temporal.high) { + temporal.high = dt; + } + chartData.push({ - date: i.get('dt'), + date: dt, value: i.get(getMode) }); @@ -349,8 +359,8 @@ var self = this; // first trend line var trendLine = new AmCharts.TrendLine(); // note,when creating date objects 0 month is January, as months are zero based in JavaScript. - trendLine.initialDate = new Date(2016, 7, 8, 12); // 12 is hour - to start trend line in the middle of the day - trendLine.finalDate = new Date(2012, 7, 15, 12); + trendLine.initialDate = temporal.low; // 12 is hour - to start trend line in the middle of the day + trendLine.finalDate = temporal.high; trendLine.initialValue = 10; trendLine.finalValue = 19; trendLine.lineColor = "#CC0000"; @@ -358,8 +368,8 @@ var self = this; // second trend line trendLine = new AmCharts.TrendLine(); - trendLine.initialDate = new Date(2016, 7, 8, 12); // 12 is hour - to start trend line in the middle of the day - trendLine.finalDate = new Date(2012, 7, 15, 12); + trendLine.initialDate = temporal.low; // 12 is hour - to start trend line in the middle of the day + trendLine.finalDate = new temporal.high; trendLine.initialValue = 16; trendLine.finalValue = 10; trendLine.lineColor = "#CC0000";