{I" class:ETI"ProcessedAsset;FI"logical_path;TI"prosperity/graph.js;FI" pathname;TI"c/Users/simon/Documents/rainforest/prosperity/app/assets/javascripts/prosperity/graph.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+¬[vSI" length;TiqI" digest;TI"%b9a17205ffa8192b322068d18f9c8874;FI" source;TI"q(function() { var Graph, SubGraph, updateMetricOptions, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; SubGraph = (function() { function SubGraph(options) { this.url = options.url; } SubGraph.prototype.render = function() { var chartEl, el, getSeries; el = $('
', { "class": 'sub-graph' }); el.append("
Loading...
"); chartEl = $('
', { "class": 'sub-graph-chart' }); el.append(chartEl); getSeries = (function(_this) { return function(url) { return $.get(url, function(json) { var chart, chartOptions, data, i, point, redraw, start_time, time, _i, _len, _ref; el.find('.title').html(json.label); chartOptions = { element: chartEl, series: [], xkey: "x", ykeys: [], labels: [], smooth: false }; if (json.key === 'change') { chartOptions.postUnits = '%'; } chart = new Morris.Line(chartOptions); data = []; start_time = Date.parse(json.start_time); _ref = json.data; for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { point = _ref[i]; time = start_time + i * json.period_milliseconds; data[i] || (data[i] = { x: time }); data[i][json.key] = point; } chart.options.ykeys.push(json.key); chart.options.labels.push(json.key); return chart.setData(data.slice(), redraw = true); }); }; })(this); getSeries(this.url); return el; }; return SubGraph; })(); Graph = (function() { function Graph(options) { this.render = __bind(this.render, this); this.url = options.url; this.el = options.el; this.$el = $(options.el); } Graph.prototype.render = function() { $.getJSON(this.url, (function(_this) { return function(json) { var el, extractor, index, subgraph, _i, _len, _ref, _results; _ref = json.extractors; _results = []; for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) { extractor = _ref[index]; subgraph = new SubGraph({ url: extractor.url }); el = subgraph.render(); _results.push(_this.$el.append(el)); } return _results; }; })(this)); return this; }; return Graph; })(); this.Prosperity || (this.Prosperity = {}); this.Prosperity.Graph = Graph; updateMetricOptions = function(el) { var $el, $form, $optionSelect, option, options, possibleOptions, selectedOption, _i, _len, _results; $el = $(el); if ($el.length === 0) { return; } $form = $el.parents('form'); options = $form.data('metric-options'); possibleOptions = options[$el.val()] || []; $optionSelect = $el.parents(".graph-line").find(".metric-option-select select"); selectedOption = $form.find("input[type=\"hidden\"][name=\"" + ($optionSelect.attr('name')) + "\"]").val(); $optionSelect.html(''); _results = []; for (_i = 0, _len = possibleOptions.length; _i < _len; _i++) { option = possibleOptions[_i]; _results.push($optionSelect.append($('