{I" class:ETI"ProcessedAsset;FI"logical_path;TI"prosperity/graph.js;FI" pathname;TI"]/Users/simon/Documents/code/prosperity/app/assets/javascripts/prosperity/graph.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+fŪSI" length;TiI" digest;TI"%c6e0a35bf02a086675ea9a07413b55b2;FI" source;TI"(function() { var Graph, SubGraph, updateMetricOptions, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; SubGraph = (function() { function SubGraph(options) { var chartEl, graphType, hoverCallback; if (options == null) { options = {}; } this["class"] = __bind(this["class"], this); this.el = $('
', { "class": 'sub-graph' }); graphType = this.graphType = options.graphType; if (options.showTitle) { this.el.append("
Loading...
"); } this.el.find('.title').html(options.label); chartEl = $('
', { "class": 'sub-graph-chart' }); this.el.append(chartEl); hoverCallback = function(index, options, content, data) { var key, sum, t, value; if (graphType === 'area') { data = options.data[index]; sum = 0; for (key in data) { value = data[key]; if (key !== 'x') { sum += value; } } t = "Total: " + sum; content += t; } return content; }; this.data = []; this.chartOptions = { element: chartEl, series: [], xkey: "x", ykeys: [], labels: [], smooth: false, data: this.data, hideHover: true, hoverCallback: hoverCallback, events: [new Date().toISOString()] }; if (options.key === 'change') { this.chartOptions.postUnits = '%'; } } SubGraph.prototype.addSeries = function(json) { var data, i, point, start_time, time, _i, _len, _ref; data = this.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.uid] = point; } this.chartOptions.ykeys.push(json.uid); this.chartOptions.labels.push(json.uid); return this.el; }; SubGraph.prototype["class"] = function() { if (this.graphType === 'area') { return Morris.Area; } else { return Morris.Line; } }; SubGraph.prototype.draw = function() { return this.chart = new this["class"]()(this.chartOptions); }; return SubGraph; })(); Graph = (function() { function Graph(options) { this.getSubgraph = __bind(this.getSubgraph, this); this.render = __bind(this.render, this); this.url = options.url; this.el = options.el; this.$el = $(options.el); } Graph.prototype.render = function() { $.ajax({ url: this.url, dataType: 'json', success: (function(_this) { return function(json) { var extractor, index, _i, _len, _ref, _results; _ref = json.extractors; _results = []; for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) { extractor = _ref[index]; _results.push($.ajax({ url: extractor.url, dataType: 'json', success: function(line_json) { var subgraph; subgraph = _this.getSubgraph({ label: line_json.label, key: line_json.key, graphType: json.graph_type }); subgraph.addSeries(line_json); if (_this.$el.hasClass('dashboard')) { if (subgraph.chartOptions.ykeys.length === json.extractors.length) { return subgraph.draw(); } } else { return subgraph.draw(); } }, error: function(xhr) { return _this.displayError(xhr); } })); } return _results; }; })(this), error: (function(_this) { return function(xhr) { return _this.displayError(xhr); }; })(this) }); return this; }; Graph.prototype.displayError = function(xhr) { var errorMessage, t; errorMessage = null; if (xhr.status >= 400 && xhr.status < 500) { errorMessage = JSON.parse(xhr.responseText).error; } errorMessage || (errorMessage = "An unknown server error has occured."); t = $('
', { "class": 'alert alert-danger', text: errorMessage }); return this.$el.find('.errors').append(t); }; Graph.prototype.getSubgraph = function(options) { var create; create = (function(_this) { return function(options) { var subgraph; subgraph = new SubGraph(options); _this.$el.find('.loading').remove(); _this.$el.append(subgraph.el); return subgraph; }; })(this); if (this.$el.hasClass('dashboard')) { return this.subGraph || (this.subGraph = create(options)); } else { return create($.extend(options, { showTitle: true })); } }; 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()] || []; possibleOptions = possibleOptions.sort(); $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($('