// Licensed to Cloudera, Inc. under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. Cloudera, Inc. licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /* * jHue Blueprint plugin * it's a layer of abstraction on top of other chart/drawing/mapping plugins */ jQuery.cachedScripts = {}; jQuery.cacheScript = function (url, callback) { if (jQuery.cachedScripts != null && jQuery.cachedScripts[url] != null) { callback(jQuery.cachedScripts[url]); } else { var options = $.extend({}, { dataType: "script", cache: true, url: url, async: false, complete: function (script) { jQuery.cachedScripts[url] = script; callback(script); } }); return jQuery.ajax(options); } }; var FLOT_LOADED, FLOT_PIE_LOADED = false; (function ($, window, document, undefined) { var pluginName = "jHueBlueprint", COLORS = { ORANGE: "#FB950D", GREEN: "#419E08", BLUE: "#338BB8" }, TYPES = { LINECHART: "lines", BARCHART: "bars", POINTCHART: "points", PIECHART: "pie", MAP: "map" }, defaults = { data: [], type: TYPES.LINECHART, fill: false, width: "100%", height: 200, borderWidth: 0, tooltips: true, enableSelection: false, onSelect: function () { }, onItemClick: function () { } }; function Plugin(element, options) { this.element = element; this.options = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.init(); } Plugin.prototype.init = function () { var _this = this; $.cacheScript("/static/ext/js/jquery/plugins/jquery.flot.min.js", function (script, textStatus) { FLOT_LOADED = true; if (_this.options.type == TYPES.PIECHART) { $.cacheScript("/static/ext/js/jquery/plugins/jquery.flot.pie.min.js", function (script, textStatus) { FLOT_PIE_LOADED = true; flot_pie(_this); }); } else { if (_this.options.enableSelection) { $.cacheScript("/static/ext/js/jquery/plugins/jquery.flot.selection.min.js", function (script, textStatus) { flot(_this); }); } else { flot(_this); } } }); }; Plugin.prototype.setOptions = function (options) { this.options = $.extend({}, defaults, options); }; function addSerie(element, serie) { if (!FLOT_LOADED) { window.setTimeout(function () { addSerie(element, serie); }, 500) } else { var _series = $(element).data("plotSeries"); if (_series == null) { if (typeof console != "undefined") { console.warn("$(elem).jHueBlueprint('add', options) requires an existing data serie to work. Use $(elem).jHueBlueprint(options) instead."); } } else { _series.push(getSerie(serie)); var _plot = $.plot(element, _series, { grid: { borderWidth: element.data('plugin_' + pluginName).options.borderWidth } }); $(element).data("plotObj", _plot); $(element).data("plotSeries", _series); } } }; function showTooltip(x, y, contents) { $("