o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1379639354.493023: @value"®e{I" class:EFI"BundledAsset;FI"logical_path;FI"heart/heart.js;TI" pathname;FI"T/Users/cwabbott/work/innovationtime/heart/app/assets/javascripts/heart/heart.js;FI"content_type;FI"application/javascript;FI" mtime;FI"2013-09-07T16:02:09+09:00;FI" length;FiŪcI" digest;F"%e39d60084732adc25fe3f3ce4937b559I" source;FI"Ūc//[JTGP == "Javascript the Good Parts"] //[JTGP page25 "Global Abatement"] var HEART = function(){ /* - JSON responses are cached in the the private cache property - heart_this refers to the global scope - Whenever an element is turned into a flot canvas, the flot object is cached in graphs. That way, subsequent calls to modify the flot on that element will get the same object returned. */ var cache = {indices : [], values : []}, heart_this = this, graphs = {indices : [], instances : []}; var graph_options = {points : false, bars : false, lines : true, zoom : false, stack : null, pie : false, fill : true}; //[JTGP page37 "Closure"] return { // //metric data json caching // cacheRead : function(index){ return cache.values[cache.indices.findIndex(index)]; }, cacheWrite : function(index,value){ var current_index = cache.indices.findIndex(index); if(current_index){ //[JTGP page139 "Using JSON Securely"] cache.values[current_index] = eval("("+value+")"); }else{ cache.indices.push(index); cache.values.push(eval("("+value+")")); } }, cacheInspect : function(){ return cache; }, //cache_index is the serialized value of all the form checkboxes (options) in the dashboard form cacheIndex : function(){ return $('#heartform input').serialize().toString(); }, graphRead : function(dom){ return graphs.instances[graphs.indices.findIndex(dom)]; }, graphWrite : function(index,value){ var current_index = graphs.indices.findIndex(index); if(current_index){ graphs.instances[current_index] = value; }else{ graphs.indices.push(index); graphs.instances.push(value); } }, annotate : function() { $.ajax({ type : "POST", cache : false, url : HEARTENGINE.annotatePath(), dataType: 'script', data : { 'fulldate': $('#annotation_fulldate').val(), 'note': $('#annotation_note').val(), 'date_from': $('#date_from').val(), 'date_to': $('#date_to').val(), 'user_id': $('#annotation_user_id').val() }, success : function(res){ $("#clickdatalabel").text('Annotated!'); $('#clickdata').fadeOut(1200); }, headers: { 'X-Transaction': 'POST Example', 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }, }); }, description : function(bool_remove){ var remove = bool_remove || false; if(!remove){ $.ajax({ type : "POST", cache : false, url : HEARTENGINE.annotateDescriptionPath(), dataType: 'script', data : { 'fulldate': '2999-12-31', 'note': $('#custom_description').val(), 'date_from': '2999-12-31', 'date_to': '2999-12-31' }, success : function(res){ if(typeof(chart_description) != 'undefined' && chart_description != ""){ $('#description_div').html(chart_description); $('#description_div').show(); $('#description_div_form').hide(); } HEART.link(); }, headers: { 'X-Transaction': 'POST Example', 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }, }); }else{ $('#custom_description').val(""); $('#description_div').html(""); $('#description').val(""); $('#description').attr("checked", false); } }, link : function(){ var date_from = "", date_to = "", yearly_stacked = "", description = ""; var flotit_date_from = $('#date_from').val(); var flotit_date_to = $('#date_to').val(); if($('#yearly_stacked').attr("checked")){ yearly_stacked = "&yearly_stacked=1"; } if(flotit_date_from != "#{@metrics.first.fulldate.to_s}"){ date_from = "&date_from="+flotit_date_from; } if(flotit_date_to != "#{@metrics.last.fulldate.to_s}"){ date_to = "&date_to="+flotit_date_to; } if($('#description').attr("checked")){ description = "&description=" + $("#description").val(); } $('#linkto').val(HEARTENGINE.baseUrl()+HEARTENGINE.defaultPath()+"?review=1&" + $('#heartform input:checkbox').serialize().toString() + date_from + date_to + description + yearly_stacked); $('#linkto').effect("highlight", {color: "#72B9EB"}, 2000); }, image : function(){ HEART.flotGraph( { flotoptions: { legend: { noColumns: 3, show: true, showOnCanvas: true, position: 'nw'} } } ).draw(); dashboard_id = $('#dashboard_id').val(); result = $.ajax({ type : "POST", cache : true, url : HEARTENGINE.imagesPath(), dataType : 'text', data : { 'dashboard_id': dashboard_id, 'dataurl': $('#flot .flot-base')[0].toDataURL(), 'purpose': 'export' }, async : true, success : function(res){ var image = jQuery.parseJSON(res); window.open(HEARTENGINE.imagesPath() + '/' + image.id + '.png'); }, headers : { 'X-Transaction': 'POST Example', 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }, }); HEART.flotGraph().draw(); }, tsv : function(){ $('#tsv_export').attr("checked", true); HEART.flotGraph().draw(); }, table : function(){ $('#heart_data_table').toggle(); var cache_index = HEART.cacheIndex(); var exportdata = [], exportlabels = []; var movingaverage = '0'; $.each($('input:checkbox:checked.movingaverages'),function(){ movingaverage = $(this).val(); $.each($('input:checkbox:checked.measurements'),function(){ var flotDataHash = $.trim("flotData" + "_" + movingaverage); if($(this).attr("checked")){ exportdata.push(HEART.cacheRead(cache_index)[flotDataHash][$(this).val()].data); exportlabels.push(HEART.cacheRead(cache_index)[flotDataHash][$(this).val()].label); } }) }); var data_table = $('#heart_data_table'); var headers = ''; data_table.empty(); $.each(exportlabels, function(){ headers += ''+this+''; }); data_table.append('Date'+headers+''); var rows = {}; var total_rows = exportdata.length; for(var i=0; i'; for(var i=0; i'; } data_table.append(''+td+''); }); }, get_points : function(){ return graph_options.points; }, set_points : function(){ $('.heart_points').toggleClass('heart_off'); graph_options.points = (graph_options.points) ? false : true; HEART.flotGraph().draw(); }, get_bars : function(){ return graph_options.bars; }, set_bars : function(){ if(graph_options.lines){ $('.heart_lines').toggleClass('heart_off'); graph_options.lines = false; //mutually exclusive } if(graph_options.pie){ $('.heart_pie').toggleClass('heart_off'); graph_options.pie = false; } $('.heart_bars').toggleClass('heart_off'); graph_options.bars = (graph_options.bars) ? false : true; HEART.flotGraph().draw(); }, get_lines : function(){ return graph_options.lines; }, set_lines : function(){ if(graph_options.bars){ $('.heart_bars').toggleClass('heart_off'); graph_options.bars = false; //mutually exclusive } if(graph_options.pie){ $('.heart_pie').toggleClass('heart_off'); graph_options.pie = false; } $('.heart_lines').toggleClass('heart_off'); graph_options.lines = (graph_options.lines) ? false : true; HEART.flotGraph().draw(); }, get_pie : function(){ return graph_options.pie; }, set_pie : function(){ if(graph_options.lines){ $('.heart_lines').toggleClass('heart_off'); graph_options.lines = false; //mutually exclusive } if(graph_options.bars){ $('.heart_bars').toggleClass('heart_off'); graph_options.bars = false; } $('.heart_pie').toggleClass('heart_off'); graph_options.pie = (graph_options.pie) ? false : true; HEART.flotGraph().draw(); }, get_zoom : function(){ return graph_options.zoom; }, set_zoom : function(){ $('.heart_zoom').toggleClass('heart_off'); graph_options.zoom = (graph_options.zoom) ? false : true; HEART.flotGraph().draw(); }, get_stack : function(){ return graph_options.stack; }, set_stack : function(){ $('.heart_stack').toggleClass('heart_off'); graph_options.stack = (graph_options.stack) ? null : true; if(graph_options.stack){ $(".annotations").attr("checked", false); } HEART.flotGraph().draw(); }, get_fill : function(){ return graph_options.fill; }, set_fill : function(){ $('.heart_fill').toggleClass('heart_off'); graph_options.fill = (graph_options.fill) ? null : true; HEART.flotGraph().draw(); }, // //different type of graphs // flotGraph : function(spec){ var spec = spec || {}; var flotoptions = { colors: ["#FF8300", "#06799F", "#FF2800", "#9440ed","#C3F500"], xaxis: { mode: "time", reserveSpace: null}, xaxes: [{ }, { show: false, tickFormatter: function(v, xaxis){return "";},}, { show: false, tickFormatter: function(v, xaxis){return "";},}, { show: false, tickFormatter: function(v, xaxis){return "";},}, { show: false, tickFormatter: function(v, xaxis){return "";},},], yaxis: { min: 0 }, grid: { backgroundColor: { colors: ["#fff", "#fff"] }, hoverable: true, clickable: true }, legend: { noColumns: 3, container: $('#flotlegend, .legend'), labelBoxBorderColor: null, show: true, labelFormatter: function(label, series) { return "" + label + ""; } }, series: { stack: HEART.get_stack(), pie: { show: HEART.get_pie(), radius: 1, label: { show: true, radius: 3/4, background: { opacity: 0.5, color: '#000' } } } }, zoom: { interactive: HEART.get_zoom() }, pan: { interactive: true }, bars : { show : HEART.get_bars(), fill : HEART.get_fill(), barWidth : 24 * 60 * 60 * 1000 }, lines : { show : HEART.get_lines(), fill : HEART.get_fill() }, points : { show : HEART.get_points() }, }; jQuery.extend(flotoptions, spec.flotoptions); spec.flotoptions = flotoptions; var that = this.graph(spec); //privileged methods added for this instance that.get_options = function(){ return flotoptions; }; that.hover(); that.click(); return that; }, miniGraph : function(spec){ var spec = spec || {}; spec.flotoptions = { colors: ["#FF8300", "#06799F", "#FF2800", "#9440ed","#C3F500"], xaxis: { mode: "time", tickLength: 0, show: false, reserveSpace: true }, grid: { backgroundColor: { colors: ["#fff", "#fff"] }, hoverable: false, clickable: false }, legend: { show: false, noColumns: 0}, lines : { show : true, fill : true }, points : { show : true }, }; var that = this.graph(spec); return that; }, //[JTGP page52 "Functional (Inheritance)"] // //following functions are all methods of the "graph" object that is returned by lineGraph, miniGraph, etc // graph : function(spec){ var that = {}; var spec = spec || {}; //private properties var target = spec.target || "#flot"; var metrics = ""; var flotoptions = spec.flotoptions || {xaxis: { mode: "time", tickLength: 0 }}; //was reflot var draw = function(options){ options = options || {}; if(typeof(options.serialized) != 'undefined'){ var pairs, tmp = ""; $('input:checkbox:checked').attr('checked', false); $('#description_div').html(""); $('#description').val(' '); $('#description').attr('checked', false); pairs = options.serialized.split('&'); for (var i = 0;i= dateObject.valueOf() + 86400000) { dateObject.setTime(dateObject.valueOf() + 86400000); new_timeseries_obj_data[stacked_index].push([dateObject.valueOf(),0]); } } flots.reverse(); }else{ flots[count] = HEART.cacheRead(cache_index)[flotDataHash][$(this).val()]; count++; } if($('#tsv_export').attr("checked")){ exportdata.push(HEART.cacheRead(cache_index)[flotDataHash][$(this).val()].data); exportlabels.push(HEART.cacheRead(cache_index)[flotDataHash][$(this).val()].label); } } }); }); if($('#tsv_export').attr("checked")){ $('#tsv_export').attr("checked", false); window.DownloadJSON2CSV(exportdata, exportlabels); } var count_annotations = 0; $.each($('input:checkbox:checked.annotations'),function(){ if($(this).attr("checked")){ flots[count] = HEART.cacheRead(cache_index)["flotDataAnnotationsHash" + $(this).val()]["note"]; count++; count_annotations++; } }); if(count_annotations == 0){ options["grid"]["markings"] = ""; }else{ options["grid"]["markings"] = HEART.cacheRead(cache_index)["markings"]; } if(typeof(HEART.cacheRead(cache_index)["chart_description"]) != 'undefined'){ if(HEART.cacheRead(cache_index)["chart_description"] != ""){ $('#description_div').html(HEART.cacheRead(cache_index)["chart_description"]); }else{ $('#description_div').html(""); } } return $.plot($(target), flots, options); } var get_options = function(){ return flotoptions; }; var get_target = function(){ return target; }; var previousPoint = null; var hover = function(){ var dom = $(target); $(dom).bind("plothover", function (event, pos, item) { if(!HEART.get_pie()){ $("#x").text(pos.x.toFixed(2)); $("#y").text(pos.y.toFixed(2)); if (item) { if (previousPoint != item.datapoint) { previousPoint = item.datapoint; $("#tooltip").remove(); var x = item.datapoint[0], y = item.datapoint[1], z = item.series.data[item.dataIndex][2]; dateString = new Date(x); if(y == 0 && z != "" || y == 1 && z != ""){ y = z;//annotations } window.showTooltip(item.pageX + 10, item.pageY, item.series.label + " = " + y + "
" + dateString.toDateString()); } }else{ $("#tooltip").remove(); } } }); } var click = function(){ var dom = $(target); $(dom).bind("plotclick", function (event, pos, item) { if (item) { var note = ""; dateString = new Date(item.datapoint[0]); $("#clickdata").show(); $('#annotation_fulldate').val(item.datapoint[0]); var fdah_array = []; if(HEART.cacheRead(HEART.cacheIndex())["flotDataAnnotationsHash" + item.datapoint[1]]){ fdah_array = HEART.cacheRead(HEART.cacheIndex())["flotDataAnnotationsHash" + item.datapoint[1]]["note"]["data"]; $("#annotation_user_id").val(HEART.cacheRead(HEART.cacheIndex())["flotDataAnnotationsHash" + item.datapoint[1]]["user_id"]); $('#annotation_user_id').attr('disabled', true); }else{ $('#annotation_user_id').attr('disabled', false); } for (var i = 0;i/gi, '\n')); $("#annotation_legend").text(dateString.toDateString()); $("#clickdatalabel").text("Annotate " + dateString.toDateString()); $("#annotation_fetch").val(item.series.att_name); } }); } //[JTGP page53 "Functional (Inheritance 'two steps')"] that.draw = draw; that.refresh_metrics = refresh_metrics; that.flotit = flotit; that.get_options = get_options; that.hover = hover; that.click = click; return that; },//end graph object };//end of return }(); ;FI"required_assets_digest;F"%c45fe801f16f50a758df08e8c52b2980I" _version;F"%ffd318ca8b794f42f5029101c2cf5d91