galaxy-commits
Threads by month
- ----- 2026 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- 15302 discussions
2 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/a15c52999493/
Changeset: a15c52999493
Branch: stable
User: guerler
Date: 2014-06-24 19:38:13
Summary: Charts plugin update
Affected #: 164 files
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/app.css
--- a/config/plugins/visualizations/charts/static/app.css
+++ b/config/plugins/visualizations/charts/static/app.css
@@ -1,3 +1,20 @@
+.charts-tooltip {
+ position: absolute;
+ text-align: center;
+ padding: 3px 5px 3px 5px;
+ font: 12px sans-serif;
+ background: white;
+ border: 1px solid gray;
+ border-radius: 4px;
+ pointer-events: none;
+}
+
+.charts-tooltip-first {
+ font-weight: bold;
+ text-align: left;
+ padding-right: 5px;
+}
+
.charts-grid .item {
padding: 5px;
margin: 5px;
@@ -17,6 +34,7 @@
.charts-grid .image {
padding: 10px;
width: 100px;
+ height: 86px;
}
.charts-grid .title {
@@ -47,6 +65,7 @@
margin-left: 5px;
top: -1px;
font-size: 1.0em;
+ display: inline;
}
.charts-viewport .icon {
@@ -63,5 +82,6 @@
.charts-viewport .charts-viewport-canvas {
display: block;
width:100%;
+ min-height: 100px;
height: inherit;
}
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/app.js
--- a/config/plugins/visualizations/charts/static/app.js
+++ b/config/plugins/visualizations/charts/static/app.js
@@ -86,6 +86,22 @@
}
},
+ // get root path
+ chartPath: function(chart_type) {
+ // create path from id
+ var path = chart_type.split(/_(.+)/);
+
+ // check path
+ if (path.length >= 2) {
+ // return path
+ return path[0] + '/' + path[1];
+ } else {
+ // log status
+ console.debug('FAILED App:chartPath() - Invalid format: ' + chart_type);
+ }
+ return undefined;
+ },
+
// execute command
execute: function(options) {
},
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/build-app.js
--- a/config/plugins/visualizations/charts/static/build-app.js
+++ b/config/plugins/visualizations/charts/static/build-app.js
@@ -3,4 +3,4 @@
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
-define("mvc/ui/ui-modal",[],function(){var e=Backbone.View.extend({elMain:"body",optionsDefault:{title:"ui-modal",body:"",backdrop:!0,height:null,width:null,closing_events:!1,closing_callback:null},buttonList:{},initialize:function(e){e&&this._create(e)},show:function(e){this.initialize(e),this.options.height?(this.$body.css("height",this.options.height),this.$body.css("overflow","hidden")):this.$body.css("max-height",$(window).height()/2),this.options.width&&this.$dialog.css("width",this.options.width),this.visible?this.$el.show():this.$el.fadeIn("fast"),this.visible=!0},hide:function(){this.visible=!1,this.$el.fadeOut("fast"),this.options.closing_callback&&this.options.closing_callback()},enableButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).prop("disabled",!1)},disableButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).prop("disabled",!0)},showButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).show()},hideButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).hide()},getButton:function(e){var t=this.buttonList[e];return this.$buttons.find("#"+t)},scrollTop:function(){return this.$body.scrollTop()},_create:function(e){var t=this;this.options=_.defaults(e,this.optionsDefault),this.options.body=="progress"&&(this.options.body=$('<div class="progress progress-striped active"><div class="progress-bar progress-bar-info" style="width:100%"></div></div>')),this.$el&&(this.$el.remove(),$(document).off("keyup.ui-modal")),this.setElement(this._template(this.options.title)),this.$dialog=this.$el.find(".modal-dialog"),this.$body=this.$el.find(".modal-body"),this.$footer=this.$el.find(".modal-footer"),this.$buttons=this.$el.find(".buttons"),this.$backdrop=this.$el.find(".modal-backdrop"),this.$body.html(this.options.body),this.options.backdrop||this.$backdrop.removeClass("in");if(this.options.buttons){this.buttonList={};var n=0;$.each(this.options.buttons,function(e,r){var i="button-"+n++;t.$buttons.append($('<button id="'+i+'"></button>').text(e).click(r)).append(" "),t.buttonList[e]=i})}else this.$footer.hide();$(this.elMain).append($(this.el)),this.options.closing_events&&($(document).on("keyup.ui-modal",function(e){e.keyCode==27&&t.hide()}),this.$el.find(".modal-backdrop").on("click",function(){t.hide()}))},_template:function(e){return'<div class="modal"><div class="modal-backdrop fade in" style="z-index: -1;"></div><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" style="display: none;">×</button><h4 class="title">'+e+"</h4>"+"</div>"+'<div class="modal-body" style="position: static;"></div>'+'<div class="modal-footer">'+'<div class="buttons" style="float: right;"></div>'+"</div>"+"</div"+"</div>"+"</div>"}});return{View:e}}),function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=i.toString,l=i.hasOwnProperty,c=r.forEach,h=r.map,p=r.reduce,d=r.reduceRight,v=r.filter,m=r.every,g=r.some,y=r.indexOf,b=r.lastIndexOf,w=Array.isArray,E=Object.keys,S=s.bind,x=function(e){if(e instanceof x)return e;if(!(this instanceof x))return new x(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=x),exports._=x):e._=x,x.VERSION="1.4.4";var T=x.each=x.forEach=function(e,t,r){if(e==null)return;if(c&&e.forEach===c)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(x.has(e,o)&&t.call(r,e[o],o,e)===n)return};x.map=x.collect=function(e,t,n){var r=[];return e==null?r:h&&e.map===h?e.map(t,n):(T(e,function(e,i,s){r.push(t.call(n,e,i,s))}),r)};var N="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(p&&e.reduce===p)return r&&(t=x.bind(t,r)),i?e.reduce(t,n):e.reduce(t);T(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError(N);return n},x.reduceRight=x.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(d&&e.reduceRight===d)return r&&(t=x.bind(t,r)),i?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=x.keys(e);s=o.length}T(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError(N);return n},x.find=x.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},x.filter=x.select=function(e,t,n){var r=[];return e==null?r:v&&e.filter===v?e.filter(t,n):(T(e,function(e,i,s){t.call(n,e,i,s)&&r.push(e)}),r)},x.reject=function(e,t,n){return x.filter(e,function(e,r,i){return!t.call(n,e,r,i)},n)},x.every=x.all=function(e,t,r){t||(t=x.identity);var i=!0;return e==null?i:m&&e.every===m?e.every(t,r):(T(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=x.some=x.any=function(e,t,r){t||(t=x.identity);var i=!1;return e==null?i:g&&e.some===g?e.some(t,r):(T(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};x.contains=x.include=function(e,t){return e==null?!1:y&&e.indexOf===y?e.indexOf(t)!=-1:C(e,function(e){return e===t})},x.invoke=function(e,t){var n=u.call(arguments,2),r=x.isFunction(t);return x.map(e,function(e){return(r?t:e[t]).apply(e,n)})},x.pluck=function(e,t){return x.map(e,function(e){return e[t]})},x.where=function(e,t,n){return x.isEmpty(t)?n?void 0:[]:x[n?"find":"filter"](e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},x.findWhere=function(e,t){return x.where(e,t,!0)},x.max=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&x.isEmpty(e))return-Infinity;var r={computed:-Infinity,value:-Infinity};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},x.min=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&x.isEmpty(e))return Infinity;var r={computed:Infinity,value:Infinity};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},x.shuffle=function(e){var t,n=0,r=[];return T(e,function(e){t=x.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return x.isFunction(e)?e:function(t){return t[e]}};x.sortBy=function(e,t,n){var r=k(t);return x.pluck(x.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t==null?x.identity:t);return T(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};x.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(x.has(e,t)?e[t]:e[t]=[]).push(n)})},x.countBy=function(e,t,n){return L(e,t,n,function(e,t){x.has(e,t)||(e[t]=0),e[t]++})},x.sortedIndex=function(e,t,n,r){n=n==null?x.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},x.toArray=function(e){return e?x.isArray(e)?u.call(e):e.length===+e.length?x.map(e,x.identity):x.values(e):[]},x.size=function(e){return e==null?0:e.length===+e.length?e.length:x.keys(e).length},x.first=x.head=x.take=function(e,t,n){return e==null?void 0:t!=null&&!n?u.call(e,0,t):e[0]},x.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},x.last=function(e,t,n){return e==null?void 0:t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},x.rest=x.tail=x.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},x.compact=function(e){return x.filter(e,x.identity)};var A=function(e,t,n){return T(e,function(e){x.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};x.flatten=function(e,t){return A(e,t,[])},x.without=function(e){return x.difference(e,u.call(arguments,1))},x.uniq=x.unique=function(e,t,n,r){x.isFunction(t)&&(r=n,n=t,t=!1);var i=n?x.map(e,n,r):e,s=[],o=[];return T(i,function(n,r){if(t?!r||o[o.length-1]!==n:!x.contains(o,n))o.push(n),s.push(e[r])}),s},x.union=function(){return x.uniq(a.apply(r,arguments))},x.intersection=function(e){var t=u.call(arguments,1);return x.filter(x.uniq(e),function(e){return x.every(t,function(t){return x.indexOf(t,e)>=0})})},x.difference=function(e){var t=a.apply(r,u.call(arguments,1));return x.filter(e,function(e){return!x.contains(t,e)})},x.zip=function(){var e=u.call(arguments),t=x.max(x.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=x.pluck(e,""+r);return n},x.unzip=function(e){var t=[];return x.each(e,function(e,n){x.each(e,function(e,r){t.length<=r&&(t[r]=[]),t[r][n]=e})}),t},x.object=function(e,t){if(e==null)return{};var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},x.indexOf=function(e,t,n){if(e==null)return-1;var r=0,i=e.length;if(n){if(typeof n!="number")return r=x.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(y&&e.indexOf===y)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},x.lastIndexOf=function(e,t,n){if(e==null)return-1;var r=n!=null;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},x.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};x.bind=function(e,t){var n,r;if(e.bind===S&&S)return S.apply(e,u.call(arguments,1));if(!x.isFunction(e))throw new TypeError;return n=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=e.prototype;var i=new O;O.prototype=null;var s=e.apply(i,n.concat(u.call(arguments)));return Object(s)===s?s:i}return e.apply(t,n.concat(u.call(arguments)))}},x.partial=function(e){var t=u.call(arguments,1);return function(){return e.apply(this,t.concat(u.call(arguments)))}},x.bindAll=function(e){var t=u.call(arguments,1);if(t.length===0)throw new Error("bindAll must be passed function names");return T(t,function(t){e[t]=x.bind(e[t],e)}),e},x.memoize=function(e,t){var n={};return t||(t=x.identity),function(){var r=t.apply(this,arguments);return x.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},x.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},x.defer=function(e){return x.delay.apply(x,[e,1].concat(u.call(arguments,1)))},x.throttle=function(e,t,n){var r,i,s,o,u=0,a=function(){u=new Date,s=null,o=e.apply(r,i)};return function(){var f=new Date;!u&&n===!1&&(u=f);var l=t-(f-u);return r=this,i=arguments,l<=0?(clearTimeout(s),s=null,u=f,o=e.apply(r,i)):s||(s=setTimeout(a,l)),o}},x.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},x.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},x.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},x.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},x.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},x.keys=E||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)x.has(e,n)&&t.push(n);return t},x.values=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push(e[n]);return t},x.pairs=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push([n,e[n]]);return t},x.invert=function(e){var t={};for(var n in e)x.has(e,n)&&(t[e[n]]=n);return t},x.functions=x.methods=function(e){var t=[];for(var n in e)x.isFunction(e[n])&&t.push(n);return t.sort()},x.extend=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]=t[n]}),e},x.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return T(n,function(n){n in e&&(t[n]=e[n])}),t},x.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)x.contains(n,i)||(t[i]=e[i]);return t},x.defaults=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]===void 0&&(e[n]=t[n])}),e},x.clone=function(e){return x.isObject(e)?x.isArray(e)?e.slice():x.extend({},e):e},x.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof x&&(e=e._wrapped),t instanceof x&&(t=t._wrapped);var i=f.call(e);if(i!=f.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,l=t.constructor;if(a!==l&&!(x.isFunction(a)&&a instanceof a&&x.isFunction(l)&&l instanceof l))return!1;for(var c in e)if(x.has(e,c)){o++;if(!(u=x.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(x.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};x.isEqual=function(e,t){return M(e,t,[],[])},x.isEmpty=function(e){if(e==null)return!0;if(x.isArray(e)||x.isString(e))return e.length===0;for(var t in e)if(x.has(e,t))return!1;return!0},x.isElement=function(e){return!!e&&e.nodeType===1},x.isArray=w||function(e){return f.call(e)=="[object Array]"},x.isObject=function(e){return e===Object(e)},T(["Arguments","Function","String","Number","Date","RegExp"],function(e){x["is"+e]=function(t){return f.call(t)=="[object "+e+"]"}}),x.isArguments(arguments)||(x.isArguments=function(e){return!!e&&!!x.has(e,"callee")}),typeof /./!="function"&&(x.isFunction=function(e){return typeof e=="function"}),x.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},x.isNaN=function(e){return x.isNumber(e)&&e!=+e},x.isBoolean=function(e){return e===!0||e===!1||f.call(e)=="[object Boolean]"},x.isNull=function(e){return e===null},x.isUndefined=function(e){return e===void 0},x.has=function(e,t){return l.call(e,t)},x.noConflict=function(){return e._=t,this},x.identity=function(e){return e},x.times=function(e,t,n){var r=Array(e);for(var i=0;i<e;i++)r[i]=t.call(n,i);return r},x.random=function(e,t){return t==null&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))};var _={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};_.unescape=x.invert(_.escape);var D={escape:new RegExp("["+x.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+x.keys(_.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(e){x[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),x.result=function(e,t){if(e==null)return void 0;var n=e[t];return x.isFunction(n)?n.call(e):n},x.mixin=function(e){T(x.functions(e),function(t){var n=x[t]=e[t];x.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(x,e))}})};var P=0;x.uniqueId=function(e){var t=++P+"";return e?e+t:t},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(e,t,n){var r;n=x.defaults({},n,x.templateSettings);var i=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),s=0,o="__p+='";e.replace(i,function(t,n,r,i,u){return o+=e.slice(s,u).replace(j,function(e){return"\\"+B[e]}),n&&(o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(o+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(o+="';\n"+i+"\n__p+='"),s=u+t.length,t}),o+="';\n",n.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{r=new Function(n.variable||"obj","_",o)}catch(u){throw u.source=o,u}if(t)return r(t,x);var a=function(e){return r.call(this,e,x)};return a.source="function("+(n.variable||"obj")+"){\n"+o+"}",a},x.chain=function(e){return x(e).chain()};var F=function(e){return this._chain?x(e).chain():e};x.mixin(x),T(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];x.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),T(["concat","join","slice"],function(e){var t=r[e];x.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),define("libs/underscore",function(e){return function(){var t,n;return t||e._}}(this)),define("utils/utils",["libs/underscore"],function(e){function t(e,t,r){n("GET",e,{},t,r)}function n(e,t,n,r,i){if(e=="GET"||e=="DELETE")t.indexOf("?")==-1?t+="?":t+="&",t+=$.param(n);var s=new XMLHttpRequest;s.open(e,t,!0),s.setRequestHeader("Accept","application/json"),s.setRequestHeader("Cache-Control","no-cache"),s.setRequestHeader("X-Requested-With","XMLHttpRequest"),s.setRequestHeader("Content-Type","application/json"),s.onloadend=function(){var e=s.status;try{response=jQuery.parseJSON(s.responseText)}catch(t){response=s.responseText}e==200?r&&r(response):i&&i(response)},e=="GET"||e=="DELETE"?s.send():s.send(JSON.stringify(n))}function r(e,t){var n=$('<div class="'+e+'"></div>');n.appendTo(":eq(0)");var r=n.css(t);return n.remove(),r}function i(e){$('link[href^="'+e+'"]').length||$('<link href="'+galaxy_config.root+e+'" rel="stylesheet">').appendTo("head")}function s(t,n){return t?e.defaults(t,n):n}function o(e,t){var n="";if(e>=1e11)e/=1e11,n="TB";else if(e>=1e8)e/=1e8,n="GB";else if(e>=1e5)e/=1e5,n="MB";else if(e>=100)e/=100,n="KB";else{if(!(e>0))return"<strong>-</strong>";e*=10,n="b"}var r=Math.round(e)/10;return t?r+" "+n:"<strong>"+r+"</strong> "+n}function u(){return(new Date).getTime().toString(36)}function a(e){var t=$("<p></p>");return t.append(e),t}function f(){var e=new Date,t=(e.getHours()<10?"0":"")+e.getHours(),n=(e.getMinutes()<10?"0":"")+e.getMinutes(),r=e.getDate()+"/"+(e.getMonth()+1)+"/"+e.getFullYear()+", "+t+":"+n;return r}return{cssLoadFile:i,cssGetAttribute:r,get:t,merge:s,bytesToString:o,uuid:u,time:f,wrap:a,request:n}}),define("mvc/ui/ui-portlet",["utils/utils"],function(e){var t=Backbone.View.extend({visible:!1,optionsDefault:{title:"",icon:"",buttons:null,body:null,height:null,operations:null,placement:"bottom",overflow:"auto"},$title:null,$content:null,$buttons:null,$operations:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.$content=this.$el.find("#content"),this.$title=this.$el.find("#title-text"),this.options.height&&(this.$el.find("#body").css("height",this.options.height),this.$el.find("#content").css("overflow",this.options.overflow)),this.$buttons=$(this.el).find("#buttons");if(this.options.buttons){var n=this;$.each(this.options.buttons,function(e,t){t.$el.prop("id",e),n.$buttons.append(t.$el)})}else this.$buttons.remove();this.$operations=$(this.el).find("#operations");if(this.options.operations){var n=this;$.each(this.options.operations,function(e,t){t.$el.prop("id",e),n.$operations.append(t.$el)})}this.options.body&&this.append(this.options.body)},append:function(t){this.$content.append(e.wrap(t))},content:function(){return this.$content},show:function(){this.$el.fadeIn("fast"),this.visible=!0},hide:function(){this.$el.fadeOut("fast"),this.visible=!1},enableButton:function(e){this.$buttons.find("#"+e).prop("disabled",!1)},disableButton:function(e){this.$buttons.find("#"+e).prop("disabled",!0)},hideOperation:function(e){this.$operations.find("#"+e).hide()},showOperation:function(e){this.$operations.find("#"+e).show()},setOperation:function(e,t){var n=this.$operations.find("#"+e);n.off("click"),n.on("click",t)},title:function(e){var t=this.$title;return e&&t.html(e),t.html()},_template:function(e){var t='<div class="toolForm portlet-view no-highlight">';if(e.title||e.icon)t+='<div id="title" class="toolFormTitle portlet-title"><div id="operations" class="portlet-operations"/><div style="overflow: hidden;">',e.icon&&(t+='<div class="portlet-title-icon fa '+e.icon+'"> </div>'),t+='<div id="title-text" class="portlet-title-text">'+e.title+"</div>",t+="</div></div>";return t+='<div id="body" class="toolFormBody portlet-body">',e.placement=="top"&&(t+='<div id="buttons" class="portlet-buttons"/>'),t+='<div id="content" class="portlet-content"/>',e.placement=="bottom"&&(t+='<div id="buttons" class="portlet-buttons"/>'),t+="</div></div>",t}});return{View:t}}),define("plugin/library/ui-select",["utils/utils"],function(e){var t=Backbone.View.extend({optionsDefault:{id:"",cls:"",empty:"No data available",visible:!0,wait:!1},selected:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.$select=this.$el.find("#select"),this.$icon=this.$el.find("#icon"),this.selected=this.options.value;var n=this;this.options.onchange&&this.$select.on("change",function(){n.value(n.$select.val())}),this._refresh(),this.options.visible||this.hide(),this.options.wait?this.wait():this.show()},value:function(e){var t=this.selected;e!==undefined&&(this.selected=e,this.$select.val(e));var n=this.selected;return n&&n!=t&&this.options.onchange&&this.options.onchange(n),n},text:function(){return this.$select.find("option:selected").text()},show:function(){this.$icon.removeClass(),this.$icon.addClass("fa fa-caret-down"),this.$select.show(),this.$el.show()},hide:function(){this.$el.hide()},wait:function(){this.$icon.removeClass(),this.$icon.addClass("fa fa-spinner fa-spin"),this.$select.hide()},disabled:function(){return this.$select.is(":disabled")},enable:function(){this.$select.prop("disabled",!1)},disable:function(){this.$select.prop("disabled",!0)},add:function(e){this.$select.append(this._templateOption(e)),this._refresh()},del:function(e){this.$select.find("option[value="+e+"]").remove(),this.$select.trigger("change"),this._refresh()},update:function(e){this.$select.find("option").remove();for(var t in e)this.$select.append(this._templateOption(e[t]));!this.selected&&e.length>0&&this.value(e[0].value),this._refresh()},_refresh:function(){this.$select.find("option[value=null]").remove();var e=this.$select.find("option").length;e==0?(this.$select.append(this._templateOption({value:"null",label:this.options.empty})),this.disable()):(this.enable(),this.selected&&this.$select.val(this.selected))},_exists:function(e){return 0!=this.$select.find("option[value="+e+"]").length},_templateOption:function(e){return'<option value="'+e.value+'">'+e.label+"</option>"},_template:function(e){var t='<div id="'+e.id+'" class="styled-select">'+'<div class="button">'+'<i id="icon"/>'+"</div>"+'<select id="select" class="select '+e.cls+" "+e.id+'">';for(key in e.data){var n=e.data[key],r="";if(n.value==e.value||n.value=="")r="selected";t+='<option value="'+n.value+'" '+r+">"+n.label+"</option>"}return t+="</select></div>",t}});return{View:t}}),define("plugin/library/ui",["utils/utils","plugin/library/ui-select"],function(e,t){var n=Backbone.View.extend({optionsDefault:{url:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options))},_template:function(e){return'<img src="'+e.url+'"/>'}}),r=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options))},title:function(e){this.$el.find("b").html(e)},_template:function(e){return'<label class="'+e.cls+'"><b>'+e.title+"</b></label>"},value:function(){return options.title}}),i=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options))},title:function(e){this.$el.html(e)},_template:function(e){return'<div class="'+e.cls+'">'+e.title+"</div>"},value:function(){return options.title}}),s=Backbone.View.extend({optionsDefault:{id:null,title:"","float":"right",cls:"btn-default",icon:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){var t='<button id="'+e.id+'" type="submit" style="margin-right: 5px; float: '+e.float+';" type="button" class="btn '+e.cls+'">';return e.icon&&(t+='<i class="icon fa '+e.icon+'"></i> '),t+=e.title+"</button>",t}}),o=Backbone.View.extend({optionsDefault:{title:"",id:null,"float":"right",cls:"icon-btn",icon:"",tooltip:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){var t="";e.title&&(t="width: auto;");var n='<div id="'+e.id+'" style="margin-right: 5px; float: '+e.float+"; "+t+'" class="'+e.cls+'">';return e.title?n+='<div style="margin-right: 5px; margin-left: 5px;"><i class="icon fa '+e.icon+'"/> '+'<span style="position: relative; font-size: 0.8em; font-weight: normal; top: -1px;">'+e.title+"</span>"+"</div>":n+='<i class="icon fa '+e.icon+'"/>',n+="</div>",n}}),u=Backbone.View.extend({optionsDefault:{"float":"right",icon:"",tooltip:"",placement:"bottom",title:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){return'<div><span class="fa '+e.icon+'" style="font-size: 1.2em;"/> '+e.title+"</div>"}}),a=Backbone.View.extend({optionsDefault:{title:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick)},_template:function(e){return'<div><a href="javascript:void(0)">'+e.title+"</a></div>"}}),f=Backbone.View.extend({optionsDefault:{message:"",status:"info",persistent:!1},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement("<div></div>")},update:function(t){this.options=e.merge(t,this.optionsDefault);if(t.message!=""){this.$el.html(this._template(this.options)),this.$el.fadeIn();if(!t.persistent){var n=this;window.setTimeout(function(){n.$el.is(":visible")?n.$el.fadeOut():n.$el.hide()},3e3)}}else this.$el.fadeOut()},_template:function(e){return'<div class="alert alert-'+e.status+'" style="padding: 2px 2px 2px 10px;">'+e.message+"</div>"}}),l=Backbone.View.extend({optionsDefault:{onclick:null,searchword:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options));var n=this;this.options.onclick&&this.$el.on("submit",function(e){var t=n.$el.find("#search");n.options.onclick(t.val())})},_template:function(e){return'<div class="search"><form onsubmit="return false;"><input id="search" class="form-control input-sm" type="text" name="search" placeholder="Search..." value="'+e.searchword+'">'+'<button type="submit" class="btn search-btn">'+'<i class="fa fa-search"></i>'+"</button>"+"</form>"+"</div>"}}),c=Backbone.View.extend({optionsDefault:{title:"Unlabeled",body:null},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.options.body&&this.$el.find(".body").append(this.options.body)},_template:function(e){return'<div id="title" class="title">'+e.title+":"+"</div>"}}),h=Backbone.View.extend({optionsDefault:{id:"",title:"",target:"",href:"",onunload:null,onclick:null,visible:!0,icon:null,tag:""},$menu:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement($(this._template(this.options)));var n=$(this.el).find(".root"),r=this;n.on("click",function(e){e.preventDefault(),r.options.onclick&&r.options.onclick()}),this.options.visible||this.hide()},show:function(){$(this.el).show()},hide:function(){$(this.el).hide()},addMenu:function(t){var n={title:"",target:"",href:"",onclick:null,divider:!1,icon:null};n=e.merge(t,n),this.$menu||($(this.el).append(this._templateMenu()),this.$menu=$(this.el).find(".menu"));var r=$(this._templateMenuItem(n));r.on("click",function(e){e.preventDefault(),n.onclick&&n.onclick()}),this.$menu.append(r),n.divider&&this.$menu.append($(this._templateDivider()))},_templateMenuItem:function(e){var t='<li><a href="'+e.href+'" target="'+e.target+'">';return e.icon&&(t+='<i class="fa '+e.icon+'"></i>'),t+=" "+e.title+"</a>"+"</li>",t},_templateMenu:function(){return'<ul class="menu dropdown-menu pull-right" role="menu"></ul>'},_templateDivider:function(){return'<li class="divider"></li>'},_template:function(e){var t='<div id="'+e.id+'" class="button-menu btn-group">'+'<button type="button" class="root btn btn-default dropdown-toggle" data-toggle="dropdown">';return e.icon&&(t+='<i class="fa '+e.icon+'"></i>'),"</button></div>",t}}),p=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:!1,visible:!0},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.options.disabled&&this.$el.prop("disabled",!0),this.options.visible||this.$el.hide();var n=this;this.options.onchange&&this.$el.on("input",function(){n.options.onchange()})},value:function(e){return e!==undefined&&this.$el.val(e),this.$el.val()},_template:function(e){return'<input id="'+e.id+'" type="'+e.type+'" value="'+e.value+'" placeholder="'+e.placeholder+'" class="form-control">'}});return{Label:r,Image:n,Button:s,Icon:u,ButtonIcon:o,Input:p,Anchor:a,Message:f,Searchbox:l,Title:c,Text:i,Select:t,ButtonMenu:h}}),define("plugin/library/jobs",["utils/utils"],function(e){return Backbone.Model.extend({initialize:function(t,n){this.app=t,this.options=e.merge(n,this.optionsDefault)},request:function(e,t,n,r,i){var s=this;e.state("wait","Requesting job results...");var o=e.get("dataset_id_job");o!=""?s._wait(e,r,i):s._submit(e,t,n,r,i)},cleanup:function(t){var n=this,r=t.get("dataset_id_job");r!=""&&(e.request("PUT",config.root+"api/histories/none/contents/"+r,{deleted:!0},function(){n._refreshHdas()}),t.set("dataset_id_job",""))},_submit:function(t,n,r,i,s){var o=this,u=t.id,a=t.get("type"),f=this.app.types.get(a);data={tool_id:"charts",inputs:{input:{id:t.get("dataset_id"),src:"hda"},module:f.execute,columns:r,settings:n}},t.state("wait","Sending job request..."),e.request("POST",config.root+"api/tools",data,function(e){if(!e.outputs||e.outputs.length==0)t.state("failed","Job submission failed. No response."),s&&s();else{o._refreshHdas();var n=e.outputs[0];t.state("wait","Your job has been queued. You may close the browser window. The job will run in the background."),t.set("dataset_id_job",n.id),this.app.storage.save(),o._wait(t,i,s)}},function(e){var n="";e&&e.message&&e.message.data&&e.message.data.input&&(n=e.message.data.input+"."),t.state("failed","This visualization requires the 'charts' tool. Please make sure it is installed. "+n),s&&s()})},_wait:function(t,n,r){var i=this;e.request("GET",config.root+"api/datasets/"+t.get("dataset_id_job"),{},function(e){var s=!1;switch(e.state){case"ok":t.state("wait","Job completed successfully..."),n&&n(e),s=!0;break;case"error":t.state("failed","Job has failed. Please check the history for details."),r&&r(e),s=!0;break;case"running":t.state("wait","Your job is running. You may close the browser window. The job will continue in the background.")}s||setTimeout(function(){i._wait(t,n,r)},i.app.config.get("query_timeout"))})},_refreshHdas:function(){Galaxy&&Galaxy.currHistoryPanel&&Galaxy.currHistoryPanel.refreshContents()}})}),define("plugin/library/datasets",["utils/utils"],function(e){return Backbone.Collection.extend({list:{},cache:{},initialize:function(t,n){this.app=t,this.options=e.merge(n,this.optionsDefault)},request:function(t,n,r){var i=this;if(t.groups)this._get(t,n);else{var s=this.list[t.id];if(s){n(s);return}e.request("GET",config.root+"api/datasets/"+t.id,{},function(e){switch(e.state){case"error":r&&r(e);break;default:i.list[t.id]=e,n(e)}})}},_block_id:function(e,t){return e.id+"_"+e.start+"_"+e.end+"_"+t},_get:function(e,t){e.start||(e.start=0),e.end||(e.end=this.app.config.get("query_limit"));var n=[],r={},i=0;for(var s in e.groups){var o=e.groups[s];for(var u in o.columns){var a=o.columns[u].index,f=this._block_id(e,a);if(this.cache[f])continue;!r[a]&&a!==undefined&&(r[a]=i,n.push(a),i++)}}if(n.length==0){this._fill_from_cache(e),t(e);return}var l={dataset_id:e.id,start:e.start,end:e.end,columns:n},c=this;this._fetch(l,function(r){for(var i in r){var s=n[i],o=c._block_id(e,s);c.cache[o]=r[i]}c._fill_from_cache(e),t(e)})},_fill_from_cache:function(e){console.debug("Datasets::_fill_from_cache() - Filling request from cache.");for(var t in e.groups){var n=e.groups[t];n.values=[];for(var r in n.columns){var i=n.columns[r],s=this._block_id(e,i.index),o=this.cache[s];for(k in o){var u=n.values[k];u===undefined&&(u={x:parseInt(k)+e.start},n.values[k]=u);var a=o[k];isNaN(a)&&!i.is_label&&(a=0),u[r]=a}}}},_fetch:function(t,n){var r=t.start?t.start:0,i=Math.abs(t.end-t.start),s=this.app.config.get("query_limit");if(!i||i>s)i=s;var o=0;t.columns&&(o=t.columns.length,console.debug("Datasets::_fetch() - Fetching "+o+" column(s)")),o==0&&console.debug("Datasets::_fetch() - No columns requested");var u="";for(var a in t.columns)u+=t.columns[a]+",";u=u.substring(0,u.length-1);var f=this;e.request("GET",config.root+"api/datasets/"+t.dataset_id,{data_type:"raw_data",provider:"dataset-column",limit:i,offset:r,indeces:u},function(e){var t=new Array(o);for(var r=0;r<o;r++)t[r]=[];for(var r in e.data){var i=e.data[r];for(var s in i){var u=i[s];u!==undefined&&u!=2147483647&&t[s].push(u)}}console.debug("Datasets::_fetch() - Fetching complete."),n(t)})}})}),define("plugin/models/group",[],function(){return Backbone.Model.extend({defaults:{key:"Data label",date:""},reset:function(){this.clear({silent:!0}).set(this.defaults),this.trigger("reset",this)}})}),define("plugin/models/groups",["plugin/models/group"],function(e){return Backbone.Collection.extend({model:e})}),define("plugin/library/deferred",["utils/utils"],function(e){return Backbone.Model.extend({queue:[],process:{},counter:0,initialize:function(){this.on("refresh",function(){if(this.counter==0)for(var e in this.queue){var t=this.queue[e];this.queue.splice(e,1),t()}})},execute:function(e){this.queue.push(e),this.trigger("refresh")},register:function(){var t=e.uuid();return this.process[t]=!0,this.counter++,console.debug("Deferred:register() - Registering "+t),t},done:function(e){this.process[e]&&(delete this.process[e],this.counter--,console.debug("Deferred:done() - Unregistering "+e),this.trigger("refresh"))},ready:function(){return this.counter==0}})});var Visualization=Backbone.Model.extend({defaults:{config:{}},urlRoot:function(){var e="/api/visualizations";return window.galaxy_config&&galaxy_config.root?galaxy_config.root+e:e},initialize:function(e){_.isObject(e.config)&&_.isObject(this.defaults.config)&&_.defaults(e.config,this.defaults.config),this._setUpListeners()},_setUpListeners:function(){},set:function(e,t){if(e==="config"){var n=this.get("config");_.isObject(n)&&(t=_.extend(_.clone(n),t))}return Backbone.Model.prototype.set.call(this,e,t),this},toString:function(){var e=this.get("id")||"";return this.get("title")&&(e+=":"+this.get("title")),"Visualization("+e+")"}}),VisualizationCollection=Backbone.Collection.extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(e,t){t=t||{}},set:function(e,t){var n=this;e=_.map(e,function(e){var t=n.get(e.id);if(!t)return e;var r=t.toJSON();return _.extend(r,e),r}),Backbone.Collection.prototype.set.call(this,e,t)},toString:function(){return["VisualizationCollection(",[this.historyId,this.length].join(),")"].join("")}});define("mvc/visualization/visualization-model",function(){}),define("plugin/models/chart",["plugin/models/groups","plugin/library/deferred","mvc/visualization/visualization-model"],function(e,t){return Backbone.Model.extend({defaults:{id:null,title:"",type:"",date:null,state:"",state_info:"",modified:!1,dataset_id:"",dataset_id_job:""},initialize:function(n){this.groups=new e,this.settings=new Backbone.Model,this.deferred=new t},reset:function(){this.clear({silent:!0}).set(this.defaults),this.groups.reset(),this.settings.clear(),this.trigger("reset",this)},copy:function(e){var t=this;t.clear({silent:!0}).set(this.defaults),t.set(e.attributes),t.settings=e.settings.clone(),t.groups.reset(),e.groups.each(function(e){t.groups.add(e.clone())}),t.trigger("change",t)},state:function(e,t){this.set("state",e),this.set("state_info",t),this.trigger("set:state"),console.debug("Chart:state() - "+t+" ("+e+")")}})}),define("plugin/library/storage",["utils/utils","plugin/models/chart","plugin/models/group"],function(e,t,n){return Backbone.Model.extend({vis:null,initialize:function(e){this.app=e,this.chart=this.app.chart,this.options=this.app.options,this.id=this.options.id,this.vis=new Visualization({type:"charts",config:{dataset_id:this.options.config.dataset_id,chart_dict:{}}}),this.id&&(this.vis.id=this.id);var t=this.options.config.chart_dict;t&&(this.vis.get("config").chart_dict=t)},save:function(){var e=this.app.chart;this.vis.get("config").chart_dict={};var t=e.get("title");t!=""&&this.vis.set("title",t);var n={attributes:e.attributes,settings:e.settings.attributes,groups:[]};e.groups.each(function(e){n.groups.push(e.attributes)}),this.vis.get("config").chart_dict=n;var r=this;this.vis.save().fail(function(e,t,n){console.error(e,t,n)}).then(function(e){e&&e.id&&(r.id=e.id)})},load:function(){var e=this.vis.get("config").chart_dict;if(!e.attributes)return!1;this.chart.set(e.attributes),this.chart.state("ok","Loading saved visualization..."),this.chart.settings.set(e.settings);for(var t in e.groups)this.chart.groups.add(new n(e.groups[t]));return this.chart.set("modified",!1),!0}})}),define("plugin/views/viewport",["mvc/ui/ui-portlet","plugin/library/ui","utils/utils"],function(e,t,n){return Backbone.View.extend({container_list:[],canvas_list:[],initialize:function(e,t){this.app=e,this.chart=this.app.chart,this.options=n.merge(t,this.optionsDefault),this.setElement($(this._template())),this._fullscreen(this.$el,80),this._createContainer("div");var r=this;this.chart.on("redraw",function(){r._draw(r.chart)}),this.chart.on("set:state",function(){var e=r.$el.find("#info"),t=r.$el.find("container"),n=e.find("#icon");n.removeClass(),e.show(),e.find("#text").html(r.chart.get("state_info")),t.hide();var i=r.chart.get("state");switch(i){case"ok":e.hide(),t.show();break;case"failed":n.addClass("icon fa fa-warning");break;default:n.addClass("icon fa fa-spinner fa-spin")}})},show:function(){this.$el.show()},hide:function(){this.$el.hide()},_fullscreen:function(e,t){e.css("height",$(window).height()-t),$(window).resize(function(){e.css("height",$(window).height()-t)})},_createContainer:function(e,t){t=t||1;for(var n in this.container_list)this.container_list[n].remove();this.container_list=[],this.canvas_list=[];for(var n=0;n<t;n++){var r=$(this._templateContainer(e,parseInt(100/t)));this.$el.append(r),this.container_list[n]=r,e=="svg"?this.canvas_list[n]=d3.select(r.find("#canvas")[0]):this.canvas_list[n]=r.find("#canvas")}},_draw:function(e){var t=this,n=e.deferred.register(),r=e.get("type");this.chart_settings=this.app.types.get(r);var i=this.chart_settings.use_panels,s=1;i&&(s=e.groups.length),this._createContainer(this.chart_settings.tag,s),e.state("wait","Please wait...");if(!this.chart_settings.execute||this.chart_settings.execute&&e.get("modified"))this.app.jobs.cleanup(e),e.set("modified",!1);var t=this;require(["plugin/charts/"+r+"/wrapper"],function(r){var i=new r(t.app,{canvas:t.canvas_list});t.chart_settings.execute?t.app.jobs.request(e,t._defaultSettingsString(e),t._defaultRequestString(e),function(){i.draw(n,e,t._defaultRequestDictionary(e))},function(){e.deferred.done(n)}):i.draw(n,e,t._defaultRequestDictionary(e))})},_defaultRequestString:function(e){var t="",n=0,r=this;return e.groups.each(function(e){n++;for(var i in r.chart_settings.columns)t+=i+"_"+n+":"+(parseInt(e.get(i))+1)+", "}),t.substring(0,t.length-2)},_defaultSettingsString:function(e){var t="";for(key in e.settings.attributes)t+=key+":"+e.settings.get(key)+", ";return t.substring(0,t.length-2)},_defaultRequestDictionary:function(e){var t={groups:[]};this.chart_settings.execute?t.id=e.get("dataset_id_job"):t.id=e.get("dataset_id");var n=0,r=this;return e.groups.each(function(e){var i={};for(var s in r.chart_settings.columns){var o=r.chart_settings.columns[s];i[s]={index:e.get(s),is_label:o.is_label}}t.groups.push({key:++n+":"+e.get("key"),columns:i})}),t},_template:function(){return'<div class="charts-viewport"><div id="info" class="info"><span id="icon" class="icon" /><span id="text" class="text" /></div></div>'},_templateContainer:function(e,t){return'<div class="charts-viewport-container" style="width:'+t+'%;">'+'<div id="menu"/>'+"<"+e+' id="canvas" class="charts-viewport-canvas">'+"</div>"}})}),define("plugin/views/viewer",["utils/utils","plugin/library/ui","mvc/ui/ui-portlet","plugin/models/group","plugin/views/viewport"],function(e,t,n,r,i){return Backbone.View.extend({initialize:function(e,r){this.app=e,this.chart=this.app.chart,this.viewport_view=new i(e);var s=this;this.portlet=new n.View({icon:"fa-bar-chart-o",title:"Viewport",operations:{edit_button:new t.ButtonIcon({icon:"fa-edit",tooltip:"Customize this chart",title:"Editor",onclick:function(){s._wait(s.chart,function(){s.app.go("editor")})}})}}),this.portlet.append(this.viewport_view.$el),this.setElement(this.portlet.$el);var s=this;this.chart.on("change:title",function(){s._refreshTitle()})},show:function(){this.$el.show(),$(window).trigger("resize")},hide:function(){this.$el.hide()},_refreshTitle:function(){var e=this.chart.get("title");this.portlet.title(e)},_screenshot:function(){var e=new XMLSerializer,t=e.serializeToString(this.viewport_view.svg.node()),n="data:image/svg+xml;base64,"+btoa(t);window.location.href="data:application/x-download/;charset=utf-8,"+encodeURIComponent(t)},_wait:function(e,t){if(e.deferred.ready())t();else{var n=this;this.app.modal.show({title:"Please wait!",body:"Your chart is currently being processed. Please wait and try again.",buttons:{Close:function(){n.app.modal.hide()},Retry:function(){n.app.modal.hide(),setTimeout(function(){n._wait(e,t)},n.app.config.get("query_timeout"))}}})}}})}),define("mvc/ui/ui-tabs",["utils/utils"],function(e){var t=Backbone.View.extend({visible:!1,list:{},$nav:null,$content:null,first_tab:null,optionsDefault:{title_new:"",operations:null,onnew:null},initialize:function(t){this.options=e.merge(t,this.optionsDefault);var n=$(this._template(this.options));this.$nav=n.find(".tab-navigation"),this.$content=n.find(".tab-content"),this.setElement(n),this.list={};var r=this;this.options.operations&&$.each(this.options.operations,function(e,t){t.$el.prop("id",e),r.$nav.find(".operations").append(t.$el)});if(this.options.onnew){var i=$(this._template_tab_new(this.options));this.$nav.append(i),i.tooltip({title:"Add a new tab",placement:"bottom",container:r.$el}),i.on("click",function(e){i.tooltip("hide"),r.options.onnew()})}},add:function(e){var t=e.id,n={$title:$(this._template_tab(e)),$content:$(this._template_tab_content(e)),removable:e.ondel?!0:!1};this.list[t]=n,this.options.onnew?this.$nav.find("#new-tab").before(n.$title):this.$nav.append(n.$title),n.$content.append(e.$el),this.$content.append(n.$content),_.size(this.list)==1&&(n.$title.addClass("active"),n.$content.addClass("active"),this.first_tab=t);if(e.ondel){var r=this,i=n.$title.find("#delete");i.tooltip({title:"Delete this tab",placement:"bottom",container:r.$el}),i.on("click",function(){return i.tooltip("destroy"),r.$el.find(".tooltip").remove(),e.ondel(),!1})}e.onclick&&n.$title.on("click",function(){e.onclick()})},del:function(e){var t=this.list[e];t.$title.remove(),t.$content.remove(),delete t,this.first_tab==e&&(this.first_tab=null),this.first_tab!=null&&this.show(this.first_tab)},delRemovable:function(){for(var e in this.list){var t=this.list[e];t.removable&&this.del(e)}},show:function(e){this.$el.fadeIn("fast"),this.visible=!0,e&&this.list[e].$title.find("a").tab("show")},hide:function(){this.$el.fadeOut("fast"),this.visible=!1},hideOperation:function(e){this.$nav.find("#"+e).hide()},showOperation:function(e){this.$nav.find("#"+e).show()},setOperation:function(e,t){var n=this.$nav.find("#"+e);n.off("click"),n.on("click",t)},title:function(e,t){var n=this.list[e].$title.find("#text");return t&&n.html(t),n.html()},_template:function(e){return'<div class="tabbable tabs-left"><ul class="tab-navigation nav nav-tabs"><div class="operations" style="float: right; margin-bottom: 4px;"></div></ul><div class="tab-content"/></div>'},_template_tab_new:function(e){return'<li id="new-tab"><a href="javascript:void(0);"><i style="font-size: 0.8em; margin-right: 5px;" class="fa fa-plus-circle"/>'+e.title_new+"</a>"+"</li>"},_template_tab:function(e){var t='<li id="title-'+e.id+'">'+'<a title="" href="#tab-'+e.id+'" data-toggle="tab" data-original-title="">'+'<span id="text">'+e.title+"</span>";return e.ondel&&(t+='<i id="delete" style="font-size: 0.8em; margin-left: 5px; cursor: pointer;" class="fa fa-minus-circle"/>'),t+="</a></li>",t},_template_tab_content:function(e){return'<div id="tab-'+e.id+'" class="tab-pane"/>'}});return{View:t}}),define("plugin/library/ui-table",["utils/utils"],function(e){var t=Backbone.View.extend({row:null,row_count:0,optionsDefault:{content:"No content available.",onchange:null,ondblclick:null,onconfirm:null},events:{click:"_onclick",dblclick:"_ondblclick"},first:!0,initialize:function(t){this.options=e.merge(t,this.optionsDefault);var n=$(this._template(t));this.$thead=n.find("thead"),this.$tbody=n.find("tbody"),this.$tmessage=n.find("tmessage"),this.setElement(n),this.row=$("<tr></tr>")},addHeader:function(e){var t=$("<th></th>");t.append(e),this.row.append(t)},appendHeader:function(){this.$thead.append(this.row),this.row=$("<tr></tr>")},add:function(e,t,n){var r=$("<td></td>");t&&r.css("width",t),n&&r.css("text-align",n),r.append(e),this.row.append(r)},append:function(e){this._commit(e)},prepend:function(e){this._commit(e,!0)},remove:function(e){var t=this.$tbody.find("#"+e);t.length>0&&(t.remove(),this.row_count--,this._refresh())},removeAll:function(){this.$tbody.html(""),this.row_count=0,this._refresh()},value:function(e){this.before=this.$tbody.find(".current").attr("id"),e!==undefined&&(this.$tbody.find("tr").removeClass("current"),e&&this.$tbody.find("#"+e).addClass("current"));var t=this.$tbody.find(".current").attr("id");return t===undefined?null:(t!=this.before&&this.options.onchange&&this.options.onchange(e),t)},size:function(){return this.$tbody.find("tr").length},_commit:function(e,t){this.remove(e),this.row.attr("id",e),t?this.$tbody.prepend(this.row):this.$tbody.append(this.row),this.row=$("<tr></tr>"),this.row_count++,this._refresh()},_onclick:function(e){var t=this.value(),n=$(e.target).closest("tr").attr("id");n!=""&&n&&t!=n&&(this.options.onconfirm?this.options.onconfirm(n):this.value(n))},_ondblclick:function(e){var t=this.value();t&&this.options.ondblclick&&this.options.ondblclick(t)},_refresh:function(){this.row_count==0?this.$tmessage.show():this.$tmessage.hide()},_template:function(e){return'<div><table class="grid"><thead></thead><tbody style="cursor: pointer;"></tbody></table><tmessage>'+e.content+"</tmessage>"+"<div>"}});return{View:t}}),define("plugin/views/group",["plugin/library/ui-table","plugin/library/ui","utils/utils"],function(e,t,n){return Backbone.View.extend({initialize:function(r,i){this.app=r;var s=this;this.chart=this.app.chart,this.group=i.group,this.group_key=new t.Input({placeholder:"Data label",onchange:function(){s.group.set("key",s.group_key.value())}}),this.table=new e.View({content:"No data column."});var o=$("<div/>");o.append(n.wrap((new t.Label({title:"Provide a label:"})).$el)),o.append(n.wrap(this.group_key.$el)),o.append(n.wrap((new t.Label({title:"Select columns:"})).$el)),o.append(n.wrap(this.table.$el)),this.setElement(o);var s=this;this.chart.on("change:dataset_id",function(){s._refreshTable()}),this.chart.on("change:type",function(){s._refreshTable()}),this.group.on("change:key",function(){s._refreshGroupKey()}),this.group.on("change",function(){s._refreshGroup()}),this._refreshTable(),this._refreshGroupKey(),this._refreshGroup()},_refreshTable:function(){var e=this.chart.get("dataset_id"),n=this.chart.get("type");if(!e||!n)return;var r=this,i=this.app.types.get(n);this.table.removeAll();var s={};for(var o in i.columns){var u=this.group.get(o);u||this.group.set(o,0);var a=i.columns[o],f=new t.Select.View({id:"select_"+o,gid:o,onchange:function(e){r.group.set(this.gid,e),r.chart.set("modified",!0)},value:u,wait:!0});this.table.add(a.title,"25%"),this.table.add(f.$el),this.table.append(o),s[o]=f}this.chart.state("wait","Loading metadata...");var l=this.chart.deferred.register();this.app.datasets.request({id:e},function(e){for(var t in s){var n=i.columns[t].is_label,o=[],u=e.metadata_column_types;for(var a in u)(!n&&(u[a]=="int"||u[a]=="float")||n)&&o.push({label:"Column: "+(parseInt(a)+1)+" ["+u[a]+"]",value:a});s[t].update(o),s[t].show()}r.chart.state("ok","Metadata initialized..."),r.chart.deferred.done(l)})},_refreshGroup:function(){this.group.set("date",n.time())},_refreshGroupKey:function(){var e=this.group.get("key");e===undefined&&(e=""),this.group_key.value(e)}})}),define("plugin/library/ui-table-form",["plugin/library/ui-table","plugin/library/ui","utils/utils"],function(e,t,n){var r=Backbone.View.extend({list:[],initialize:function(r){this.table_title=new t.Label({title:r.title}),this.table=new e.View({content:r.content});var i=$("<div/>");i.append(n.wrap(this.table_title.$el)),i.append(n.wrap(this.table.$el)),this.setElement(i)},title:function(e){this.table_title.title(e)},update:function(e,t){this.table.removeAll(),this.list=[];for(var n in e)this._add(n,e[n],t);for(var n in this.list){var r=this.list[n].options.onchange;r&&r()}},_add:function(e,n,r){var i=this,s=null,o=n.type;switch(o){case"text":s=new t.Input({id:e,placeholder:n.placeholder,onchange:function(){r.set(e,s.value())}});break;case"select":s=new t.Select.View({id:e,data:n.data,onchange:function(){var t=s.value();r.set(e,t);var o=_.findWhere(n.data,{value:t});o&&(o.show&&i.$el.find("#"+o.show).fadeIn("fast"),o.hide&&i.$el.find("#"+o.hide).fadeOut("fast"))}});break;case"separator":s=$("<div/>");break;default:console.log("ui-table-form:_add","Unknown setting type ("+n.type+")");return}if(o!="separator"){r.get(e)||r.set(e,n.init),s.value(r.get(e)),this.list[e]=s;var u=$("<div/>");u.append(s.$el),u.append('<div class="toolParamHelp" style="font-size: 0.9em;">'+n.info+"</div>"),this.table.add('<span style="white-space: nowrap;">'+n.title+"</span>","25%"),this.table.add(u)}else this.table.add('<h6 style="white-space: nowrap;">'+n.title+":<h6/>"),this.table.add($("<div/>"));this.table.append(e)}});return{View:r}}),define("plugin/views/settings",["plugin/library/ui","plugin/library/ui-table-form","utils/utils"],function(e,t,n){return Backbone.View.extend({initialize:function(e,n){this.app=e;var r=this;this.chart=this.app.chart,this.form=new t.View({title:"Chart options:",content:"This chart type does not provide any options."}),this.setElement(this.form.$el);var r=this;this.chart.on("change",function(){r._refreshTable()})},_refreshTable:function(){var e=this.chart.get("type");if(!e)return;var t=this.app.types.get(e);this.form.title(t.category+" - "+t.title+":"),this.form.update(t.settings,this.chart.settings)}})}),define("plugin/views/types",["utils/utils","plugin/library/ui"],function(e,t){return Backbone.View.extend({optionsDefault:{onchange:null,ondblclick:null},events:{click:"_onclick",dblclick:"_ondblclick"},initialize:function(t,n){this.app=t,this.options=e.merge(n,this.optionsDefault);var r=$('<div class="charts-grid"/>');this.setElement(r);var i={},s=t.types.attributes;for(var o in s){var u=s[o],a=u.category;i[a]||(i[a]={}),i[a][o]=u}for(var a in i){var r=$('<div style="clear: both;"/>');r.append(e.wrap(this._template_header({title:a})));for(var o in i[a]){var u=i[a][o];r.append(e.wrap(this._template_item({id:o,title:u.title,url:config.app_root+"charts/"+o+"/logo.png"})))}this.$el.append(e.wrap(r))}},value:function(e){var t=this.$el.find(".current").attr("id");e!==undefined&&(this.$el.find(".current").removeClass("current"),this.$el.find("#"+e).addClass("current"));var n=this.$el.find(".current").attr("id");return n===undefined?null:(n!=t&&this.options.onchange&&this.options.onchange(e),n)},_onclick:function(e){var t=this.value(),n=$(e.target).closest(".item").attr("id");n!=""&&n&&t!=n&&this.value(n)},_ondblclick:function(e){var t=this.value();t&&this.options.ondblclick&&this.options.ondblclick(t)},_template_header:function(e){return'<div class="header">• '+e.title+"<div>"},_template_item:function(e){return'<div id="'+e.id+'" class="item">'+'<img class="image" src="'+e.url+'">'+'<div class="title">'+e.title+"</div>"+"<div>"}})}),define("plugin/views/editor",["mvc/ui/ui-tabs","plugin/library/ui","mvc/ui/ui-portlet","utils/utils","plugin/models/chart","plugin/models/group","plugin/views/group","plugin/views/settings","plugin/views/types"],function(e,t,n,r,i,s,o,u,a){return Backbone.View.extend({optionsDefault:{header:!0,content:"No content available."},initialize:function(i,s){var o=this;this.app=i,this.chart=this.app.chart,this.options=r.merge(s,this.optionsDefault),this.portlet=new n.View({icon:"fa-bar-chart-o",title:"Editor",operations:{save:new t.ButtonIcon({icon:"fa-save",tooltip:"Draw Chart",title:"Draw",onclick:function(){o.app.go("viewer"),o._saveChart()}}),back:new t.ButtonIcon({icon:"fa-caret-left",tooltip:"Return to Viewer",title:"Return",onclick:function(){o.app.go("viewer"),o.app.storage.load()}})}}),this.types=new a(i,{onchange:function(e){o.chart.settings.clear(),o.chart.set({type:e}),o.chart.set("modified",!0)},ondblclick:function(e){o.app.go("viewer"),o._saveChart()}}),this.tabs=new e.View({title_new:"Add Data",onnew:function(){var e=o._addGroupModel();o.tabs.show(e.id)}}),this.title=new t.Input({placeholder:"Chart title",onchange:function(){o.chart.set("title",o.title.value())}});var f=$("<div/>");f.append(r.wrap((new t.Label({title:"Provide a chart title:"})).$el)),f.append(r.wrap(this.title.$el)),f.append(r.wrap((new t.Label({title:"Select a chart type:"})).$el)),f.append(r.wrap(this.types.$el)),this.tabs.add({id:"main",title:"Start",$el:f}),this.settings=new u(this.app),this.tabs.add({id:"settings",title:"Configuration",$el:this.settings.$el}),this.portlet.append(this.tabs.$el),this.setElement(this.portlet.$el),this.tabs.hideOperation("back");var o=this;this.chart.on("change:title",function(e){o._refreshTitle()}),this.chart.on("change:type",function(e){o.types.value(e.get("type"))}),this.chart.on("reset",function(e){o._resetChart()}),this.app.chart.on("redraw",function(e){o.portlet.showOperation("back")}),this.app.chart.groups.on("add",function(e){o._addGroup(e)}),this.app.chart.groups.on("remove",function(e){o._removeGroup(e)}),this.app.chart.groups.on("reset",function(e){o._removeAllGroups()}),this.app.chart.groups.on("change:key",function(e){o._refreshGroupKey()}),this._resetChart()},show:function(){this.$el.show()},hide:function(){this.$el.hide()},_refreshTitle:function(){var e=this.chart.get("title");this.portlet.title(e),this.title.value(e)},_refreshGroupKey:function(){var e=this,t=0;this.chart.groups.each(function(n){var r=n.get("key","");r==""&&(r="Chart data"),e.tabs.title(n.id,++t+": "+r)})},_addGroupModel:function(){var e=new s({id:r.uuid()});return this.chart.groups.add(e),e},_addGroup:function(e){var t=this,n=new o(this.app,{group:e}),r=t.chart.groups.length;this.tabs.add({id:e.id,$el:n.$el,ondel:function(){t.chart.groups.remove(e.id)}}),this._refreshGroupKey()},_removeGroup:function(e){this.tabs.del(e.id),this._refreshGroupKey(),this.chart.set("modified",!0)},_removeAllGroups:function(e){this.tabs.delRemovable()},_resetChart:function(){this.chart.set("id",r.uuid()),this.chart.set("type","nvd3_bar"),this.chart.set("dataset_id",this.app.options.config.dataset_id),this.chart.set("title","New Chart"),this.portlet.hideOperation("back")},_saveChart:function(){this.chart.set({type:this.types.value(),title:this.title.value(),date:r.time()}),this.chart.groups.length==0&&this._addGroupModel();var e=this;this.chart.deferred.execute(function(){e.app.storage.save(),e.chart.trigger("redraw")})}})}),define("plugin/models/config",[],function(){return Backbone.Model.extend({defaults:{query_limit:5e3,query_timeout:500}})}),define("plugin/charts/nvd3/config",[],function(){return{title:"",category:"",library:"nvd3.js",tag:"svg",columns:{y:{title:"Values for y-axis"}},settings:{separator_label:{title:"X axis",type:"separator"},x_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"X-axis",placeholder:"Axis label"},x_axis_type:{title:"Axis value type",info:"Select the value type of the axis.",type:"select",init:"auto",data:[{label:"-- Do not show values --",value:"hide",hide:"x_axis_tick"},{label:"Auto",value:"auto",hide:"x_axis_tick"},{label:"Float",value:"f",show:"x_axis_tick"},{label:"Exponent",value:"e",show:"x_axis_tick"},{label:"Integer",value:"d",hide:"x_axis_tick"},{label:"Percentage",value:"p",show:"x_axis_tick"},{label:"Rounded",value:"r",show:"x_axis_tick"},{label:"SI-prefix",value:"s",show:"x_axis_tick"}]},x_axis_tick:{title:"Axis tick format",info:"Select the tick format for the axis.",type:"select",init:".1",data:[{label:"0.00001",value:".5"},{label:"0.0001",value:".4"},{label:"0.001",value:".3"},{label:"0.01",value:".2"},{label:"0.1",value:".1"},{label:"1",value:"1"}]},separator_tick:{title:"Y axis",type:"separator"},y_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"Y-axis",placeholder:"Axis label"},y_axis_type:{title:"Axis value type",info:"Select the value type of the axis.",type:"select",init:"auto",data:[{label:"-- Do not show values --",value:"hide",hide:"y_axis_tick"},{label:"Auto",value:"auto",hide:"y_axis_tick"},{label:"Float",value:"f",show:"y_axis_tick"},{label:"Exponent",value:"e",show:"y_axis_tick"},{label:"Integer",value:"d",hide:"y_axis_tick"},{label:"Percentage",value:"p",show:"y_axis_tick"},{label:"Rounded",value:"r",show:"y_axis_tick"},{label:"SI-prefix",value:"s",show:"y_axis_tick"}]},y_axis_tick:{title:"Axis tick format",info:"Select the tick format for the axis.",type:"select",init:".1",data:[{label:"0.00001",value:".5"},{label:"0.0001",value:".4"},{label:"0.001",value:".3"},{label:"0.01",value:".2"},{label:"0.1",value:".1"},{label:"1",value:"1"}]},separator_legend:{title:"Others",type:"separator"},show_legend:{title:"Show legend",info:"Would you like to add a legend?",type:"select",init:"true",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]}}}}),define("plugin/charts/nvd3_bar/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Regular",category:"Bar diagrams"})}),define("plugin/charts/nvd3_bar_stacked/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Stacked",category:"Bar diagrams"})}),define("plugin/charts/nvd3_bar_horizontal/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Horizontal",category:"Bar diagrams",settings:{x_axis_type:{init:"hide"}}})}),define("plugin/charts/nvd3_bar_horizontal_stacked/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Stacked horizontal",category:"Bar diagrams",settings:{x_axis_type:{init:"hide"}}})}),define("plugin/charts/nvd3_histogram/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Histogram",category:"Data processing (requires 'charts' tool from Toolshed)",execute:"histogram",columns:{y:{title:"Observations"}},settings:{x_axis_label:{init:"Breaks"},y_axis_label:{init:"Density"},y_axis_type:{init:"f"},y_axis_tick:{init:".2"}}})}),define("plugin/charts/nvd3_histogram_discrete/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Histogram (discrete)",category:"Data processing (requires 'charts' tool from Toolshed)",execute:"histogramdiscrete",columns:{y:{title:"Observations",is_label:!0}},settings:{x_axis_label:{init:"Breaks"},y_axis_label:{init:"Density"},y_axis_type:{init:"f"},y_axis_tick:{init:".2"}}})}),define("plugin/charts/nvd3_line/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Line chart",category:"Others"})}),define("plugin/charts/nvd3_line_focus/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Line with focus",category:"Others"})}),define("plugin/charts/nvd3_pie/config",[],function(){return{title:"Pie chart",library:"nvd3.js",category:"Area charts",tag:"svg",use_panels:!0,columns:{label:{title:"Labels",is_label:!0},y:{title:"Values"}},settings:{show_legend:{title:"Show legend",info:"Would you like to add a legend?",type:"select",init:"false",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]},donut_ratio:{title:"Donut ratio",info:"Determine how large the donut hole will be.",type:"select",init:"0.5",data:[{label:"50%",value:"0.5"},{label:"25%",value:"0.25"},{label:"10%",value:"0.10"},{label:"0%",value:"0"}]},label_separator:{type:"separator",title:"Label settings"},label_type:{title:"Donut label",info:"What would you like to show for each slice?",type:"select",init:"percent",data:[{label:"-- Nothing --",value:"hide",hide:"label_outside"},{label:"Label column",value:"key",show:"label_outside"},{label:"Value column",value:"value",show:"label_outside"},{label:"Percentage",value:"percent",show:"label_outside"}]},label_outside:{title:"Show outside",info:"Would you like to show labels outside the donut?",type:"select",init:"false",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]}}}}),define("plugin/charts/nvd3_scatter/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Scatter plot",category:"Others",columns:{x:{title:"Values for x-axis"}}})}),define("plugin/charts/nvd3_stackedarea/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Regular",category:"Area charts"})}),define("plugin/charts/nvd3_stackedarea_full/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Expanded",category:"Area charts"})}),define("plugin/charts/nvd3_stackedarea_stream/config",["plugin/charts/nvd3/config"],function(e){return $.extend(!0,{},e,{title:"Stream",category:"Area charts"})}),define("plugin/charts/highcharts_boxplot/config",[],function(){return{title:"Box plot",category:"Data processing (requires 'charts' tool from Toolshed)",library:"highcharts.js",tag:"div",execute:"boxplot",columns:{y:{title:"Observations"}},settings:{separator_label:{title:"X axis",type:"separator"},x_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"X-axis",placeholder:"Axis label"},separator_tick:{title:"Y axis",type:"separator"},y_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"Y-axis",placeholder:"Axis label"}}}}),define("plugin/charts/heatmap/config",[],function(){return{title:"Heatmap",category:"Data processing (requires 'charts' tool from Toolshed)",library:"",tag:"div",use_panels:!0,execute:"heatmap",columns:{row_label:{title:"Row labels",is_label:!0},col_label:{title:"Column labels",is_label:!0},value:{title:"Observations"}},settings:{color_set:{title:"Color scheme",info:"Select a color scheme for your heatmap",type:"select",init:"ocean",data:[{label:"Cold-to-Hot",value:"hot"},{label:"Cool",value:"cool"},{label:"Copper",value:"copper"},{label:"Gebco",value:"gebco"},{label:"Globe",value:"globe"},{label:"Gray scale",value:"gray"},{label:"Haxby",value:"haxby"},{label:"Jet",value:"jet"},{label:"No-Green",value:"no_green"},{label:"Ocean",value:"ocean"},{label:"Polar",value:"polar"},{label:"Rainbow",value:"rainbow"},{label:"Red-to-Green",value:"redgreen"},{label:"Red-to-green (saturated)",value:"red2green"},{label:"Relief",value:"relief"},{label:"Seismograph",value:"seis"},{label:"Sealand",value:"sealand"},{label:"Split",value:"split"},{label:"Topo",value:"topo"},{label:"Wysiwyg",value:"wysiwyg"}]},sorting:{title:"Sorting",info:"How should the columns be clustered?",type:"select",init:"hclust",data:[{label:"Read from dataset",value:"hclust"},{label:"Sort column and row labels",value:"byboth"},{label:"Sort column labels",value:"bycolumns"},{label:"Sort by rows",value:"byrow"}]}},menu:function(){return{color_set:this.settings.color_set}}}}),define("plugin/charts/types",["plugin/charts/nvd3_bar/config","plugin/charts/nvd3_bar_stacked/config","plugin/charts/nvd3_bar_horizontal/config","plugin/charts/nvd3_bar_horizontal_stacked/config","plugin/charts/nvd3_histogram/config","plugin/charts/nvd3_histogram_discrete/config","plugin/charts/nvd3_line/config","plugin/charts/nvd3_line_focus/config","plugin/charts/nvd3_pie/config","plugin/charts/nvd3_scatter/config","plugin/charts/nvd3_stackedarea/config","plugin/charts/nvd3_stackedarea_full/config","plugin/charts/nvd3_stackedarea_stream/config","plugin/charts/highcharts_boxplot/config","plugin/charts/heatmap/config"],function(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d){return Backbone.Model.extend({defaults:{nvd3_bar:e,nvd3_bar_stacked:t,nvd3_bar_horizontal:n,nvd3_bar_horizontal_stacked:r,nvd3_stackedarea:l,nvd3_stackedarea_full:c,nvd3_stackedarea_stream:h,nvd3_line:o,nvd3_line_focus:u,nvd3_scatter:f,nvd3_pie:a,nvd3_histogram:i,highcharts_boxplot:p,heatmap:d}})}),define("plugin/app",["mvc/ui/ui-modal","mvc/ui/ui-portlet","plugin/library/ui","utils/utils","plugin/library/jobs","plugin/library/datasets","plugin/library/storage","plugin/views/viewer","plugin/views/editor","plugin/models/config","plugin/models/chart","plugin/charts/types"],function(e,t,n,r,i,s,o,u,a,f,l,c){return Backbone.View.extend({initialize:function(t){this.options=t,Galaxy&&Galaxy.modal?this.modal=Galaxy.modal:this.modal=new e.View,this.config=new f,this.types=new c,this.chart=new l,this.jobs=new i(this),this.datasets=new s(this),this.storage=new o(this),this.viewer_view=new u(this),this.editor_view=new a(this),this.$el.append(this.viewer_view.$el),this.$el.append(this.editor_view.$el);if(!this.storage.load())this.go("editor");else{this.go("viewer");var n=this;this.chart.deferred.execute(function(){n.chart.trigger("redraw")})}},go:function(e){$(".tooltip").hide();switch(e){case"editor":this.editor_view.show(),this.viewer_view.hide();break;case"viewer":this.editor_view.hide(),this.viewer_view.show()}},execute:function(e){},onunload:function(){},log:function(e,t){console.log(e+" "+t)}})});
\ No newline at end of file
+define("mvc/ui/ui-modal",[],function(){var e=Backbone.View.extend({elMain:"body",optionsDefault:{title:"ui-modal",body:"",backdrop:!0,height:null,width:null,closing_events:!1,closing_callback:null},buttonList:{},initialize:function(e){e&&this._create(e)},show:function(e){this.initialize(e),this.options.height?(this.$body.css("height",this.options.height),this.$body.css("overflow","hidden")):this.$body.css("max-height",$(window).height()/2),this.options.width&&this.$dialog.css("width",this.options.width),this.visible?this.$el.show():this.$el.fadeIn("fast"),this.visible=!0},hide:function(){this.visible=!1,this.$el.fadeOut("fast"),this.options.closing_callback&&this.options.closing_callback()},enableButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).prop("disabled",!1)},disableButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).prop("disabled",!0)},showButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).show()},hideButton:function(e){var t=this.buttonList[e];this.$buttons.find("#"+t).hide()},getButton:function(e){var t=this.buttonList[e];return this.$buttons.find("#"+t)},scrollTop:function(){return this.$body.scrollTop()},_create:function(e){var t=this;this.options=_.defaults(e,this.optionsDefault),this.options.body=="progress"&&(this.options.body=$('<div class="progress progress-striped active"><div class="progress-bar progress-bar-info" style="width:100%"></div></div>')),this.$el&&(this.$el.remove(),$(document).off("keyup.ui-modal")),this.setElement(this._template(this.options.title)),this.$dialog=this.$el.find(".modal-dialog"),this.$body=this.$el.find(".modal-body"),this.$footer=this.$el.find(".modal-footer"),this.$buttons=this.$el.find(".buttons"),this.$backdrop=this.$el.find(".modal-backdrop"),this.$body.html(this.options.body),this.options.backdrop||this.$backdrop.removeClass("in");if(this.options.buttons){this.buttonList={};var n=0;$.each(this.options.buttons,function(e,r){var i="button-"+n++;t.$buttons.append($('<button id="'+i+'"></button>').text(e).click(r)).append(" "),t.buttonList[e]=i})}else this.$footer.hide();$(this.elMain).append($(this.el)),this.options.closing_events&&($(document).on("keyup.ui-modal",function(e){e.keyCode==27&&t.hide()}),this.$el.find(".modal-backdrop").on("click",function(){t.hide()}))},_template:function(e){return'<div class="ui-modal modal"><div class="modal-backdrop fade in" style="z-index: -1;"></div><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" style="display: none;">×</button><h4 class="title">'+e+"</h4>"+"</div>"+'<div class="modal-body" style="position: static;"></div>'+'<div class="modal-footer">'+'<div class="buttons" style="float: right;"></div>'+"</div>"+"</div"+"</div>"+"</div>"}});return{View:e}}),function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=i.toString,l=i.hasOwnProperty,c=r.forEach,h=r.map,p=r.reduce,d=r.reduceRight,v=r.filter,m=r.every,g=r.some,y=r.indexOf,b=r.lastIndexOf,w=Array.isArray,E=Object.keys,S=s.bind,x=function(e){if(e instanceof x)return e;if(!(this instanceof x))return new x(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=x),exports._=x):e._=x,x.VERSION="1.4.4";var T=x.each=x.forEach=function(e,t,r){if(e==null)return;if(c&&e.forEach===c)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(x.has(e,o)&&t.call(r,e[o],o,e)===n)return};x.map=x.collect=function(e,t,n){var r=[];return e==null?r:h&&e.map===h?e.map(t,n):(T(e,function(e,i,s){r.push(t.call(n,e,i,s))}),r)};var N="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(p&&e.reduce===p)return r&&(t=x.bind(t,r)),i?e.reduce(t,n):e.reduce(t);T(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError(N);return n},x.reduceRight=x.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(d&&e.reduceRight===d)return r&&(t=x.bind(t,r)),i?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=x.keys(e);s=o.length}T(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError(N);return n},x.find=x.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},x.filter=x.select=function(e,t,n){var r=[];return e==null?r:v&&e.filter===v?e.filter(t,n):(T(e,function(e,i,s){t.call(n,e,i,s)&&r.push(e)}),r)},x.reject=function(e,t,n){return x.filter(e,function(e,r,i){return!t.call(n,e,r,i)},n)},x.every=x.all=function(e,t,r){t||(t=x.identity);var i=!0;return e==null?i:m&&e.every===m?e.every(t,r):(T(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=x.some=x.any=function(e,t,r){t||(t=x.identity);var i=!1;return e==null?i:g&&e.some===g?e.some(t,r):(T(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};x.contains=x.include=function(e,t){return e==null?!1:y&&e.indexOf===y?e.indexOf(t)!=-1:C(e,function(e){return e===t})},x.invoke=function(e,t){var n=u.call(arguments,2),r=x.isFunction(t);return x.map(e,function(e){return(r?t:e[t]).apply(e,n)})},x.pluck=function(e,t){return x.map(e,function(e){return e[t]})},x.where=function(e,t,n){return x.isEmpty(t)?n?void 0:[]:x[n?"find":"filter"](e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},x.findWhere=function(e,t){return x.where(e,t,!0)},x.max=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&x.isEmpty(e))return-Infinity;var r={computed:-Infinity,value:-Infinity};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},x.min=function(e,t,n){if(!t&&x.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&x.isEmpty(e))return Infinity;var r={computed:Infinity,value:Infinity};return T(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},x.shuffle=function(e){var t,n=0,r=[];return T(e,function(e){t=x.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return x.isFunction(e)?e:function(t){return t[e]}};x.sortBy=function(e,t,n){var r=k(t);return x.pluck(x.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t==null?x.identity:t);return T(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};x.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(x.has(e,t)?e[t]:e[t]=[]).push(n)})},x.countBy=function(e,t,n){return L(e,t,n,function(e,t){x.has(e,t)||(e[t]=0),e[t]++})},x.sortedIndex=function(e,t,n,r){n=n==null?x.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},x.toArray=function(e){return e?x.isArray(e)?u.call(e):e.length===+e.length?x.map(e,x.identity):x.values(e):[]},x.size=function(e){return e==null?0:e.length===+e.length?e.length:x.keys(e).length},x.first=x.head=x.take=function(e,t,n){return e==null?void 0:t!=null&&!n?u.call(e,0,t):e[0]},x.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},x.last=function(e,t,n){return e==null?void 0:t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},x.rest=x.tail=x.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},x.compact=function(e){return x.filter(e,x.identity)};var A=function(e,t,n){return T(e,function(e){x.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};x.flatten=function(e,t){return A(e,t,[])},x.without=function(e){return x.difference(e,u.call(arguments,1))},x.uniq=x.unique=function(e,t,n,r){x.isFunction(t)&&(r=n,n=t,t=!1);var i=n?x.map(e,n,r):e,s=[],o=[];return T(i,function(n,r){if(t?!r||o[o.length-1]!==n:!x.contains(o,n))o.push(n),s.push(e[r])}),s},x.union=function(){return x.uniq(a.apply(r,arguments))},x.intersection=function(e){var t=u.call(arguments,1);return x.filter(x.uniq(e),function(e){return x.every(t,function(t){return x.indexOf(t,e)>=0})})},x.difference=function(e){var t=a.apply(r,u.call(arguments,1));return x.filter(e,function(e){return!x.contains(t,e)})},x.zip=function(){var e=u.call(arguments),t=x.max(x.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=x.pluck(e,""+r);return n},x.unzip=function(e){var t=[];return x.each(e,function(e,n){x.each(e,function(e,r){t.length<=r&&(t[r]=[]),t[r][n]=e})}),t},x.object=function(e,t){if(e==null)return{};var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},x.indexOf=function(e,t,n){if(e==null)return-1;var r=0,i=e.length;if(n){if(typeof n!="number")return r=x.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(y&&e.indexOf===y)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},x.lastIndexOf=function(e,t,n){if(e==null)return-1;var r=n!=null;if(b&&e.lastIndexOf===b)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},x.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};x.bind=function(e,t){var n,r;if(e.bind===S&&S)return S.apply(e,u.call(arguments,1));if(!x.isFunction(e))throw new TypeError;return n=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=e.prototype;var i=new O;O.prototype=null;var s=e.apply(i,n.concat(u.call(arguments)));return Object(s)===s?s:i}return e.apply(t,n.concat(u.call(arguments)))}},x.partial=function(e){var t=u.call(arguments,1);return function(){return e.apply(this,t.concat(u.call(arguments)))}},x.bindAll=function(e){var t=u.call(arguments,1);if(t.length===0)throw new Error("bindAll must be passed function names");return T(t,function(t){e[t]=x.bind(e[t],e)}),e},x.memoize=function(e,t){var n={};return t||(t=x.identity),function(){var r=t.apply(this,arguments);return x.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},x.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},x.defer=function(e){return x.delay.apply(x,[e,1].concat(u.call(arguments,1)))},x.throttle=function(e,t,n){var r,i,s,o,u=0,a=function(){u=new Date,s=null,o=e.apply(r,i)};return function(){var f=new Date;!u&&n===!1&&(u=f);var l=t-(f-u);return r=this,i=arguments,l<=0?(clearTimeout(s),s=null,u=f,o=e.apply(r,i)):s||(s=setTimeout(a,l)),o}},x.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},x.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},x.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},x.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},x.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},x.keys=E||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)x.has(e,n)&&t.push(n);return t},x.values=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push(e[n]);return t},x.pairs=function(e){var t=[];for(var n in e)x.has(e,n)&&t.push([n,e[n]]);return t},x.invert=function(e){var t={};for(var n in e)x.has(e,n)&&(t[e[n]]=n);return t},x.functions=x.methods=function(e){var t=[];for(var n in e)x.isFunction(e[n])&&t.push(n);return t.sort()},x.extend=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]=t[n]}),e},x.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return T(n,function(n){n in e&&(t[n]=e[n])}),t},x.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)x.contains(n,i)||(t[i]=e[i]);return t},x.defaults=function(e){return T(u.call(arguments,1),function(t){if(t)for(var n in t)e[n]===void 0&&(e[n]=t[n])}),e},x.clone=function(e){return x.isObject(e)?x.isArray(e)?e.slice():x.extend({},e):e},x.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof x&&(e=e._wrapped),t instanceof x&&(t=t._wrapped);var i=f.call(e);if(i!=f.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,l=t.constructor;if(a!==l&&!(x.isFunction(a)&&a instanceof a&&x.isFunction(l)&&l instanceof l))return!1;for(var c in e)if(x.has(e,c)){o++;if(!(u=x.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(x.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};x.isEqual=function(e,t){return M(e,t,[],[])},x.isEmpty=function(e){if(e==null)return!0;if(x.isArray(e)||x.isString(e))return e.length===0;for(var t in e)if(x.has(e,t))return!1;return!0},x.isElement=function(e){return!!e&&e.nodeType===1},x.isArray=w||function(e){return f.call(e)=="[object Array]"},x.isObject=function(e){return e===Object(e)},T(["Arguments","Function","String","Number","Date","RegExp"],function(e){x["is"+e]=function(t){return f.call(t)=="[object "+e+"]"}}),x.isArguments(arguments)||(x.isArguments=function(e){return!!e&&!!x.has(e,"callee")}),typeof /./!="function"&&(x.isFunction=function(e){return typeof e=="function"}),x.isFinite=function(e){return isFinite(e)&&!isNaN(parseFloat(e))},x.isNaN=function(e){return x.isNumber(e)&&e!=+e},x.isBoolean=function(e){return e===!0||e===!1||f.call(e)=="[object Boolean]"},x.isNull=function(e){return e===null},x.isUndefined=function(e){return e===void 0},x.has=function(e,t){return l.call(e,t)},x.noConflict=function(){return e._=t,this},x.identity=function(e){return e},x.times=function(e,t,n){var r=Array(e);for(var i=0;i<e;i++)r[i]=t.call(n,i);return r},x.random=function(e,t){return t==null&&(t=e,e=0),e+Math.floor(Math.random()*(t-e+1))};var _={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};_.unescape=x.invert(_.escape);var D={escape:new RegExp("["+x.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+x.keys(_.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(e){x[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),x.result=function(e,t){if(e==null)return void 0;var n=e[t];return x.isFunction(n)?n.call(e):n},x.mixin=function(e){T(x.functions(e),function(t){var n=x[t]=e[t];x.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(x,e))}})};var P=0;x.uniqueId=function(e){var t=++P+"";return e?e+t:t},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(e,t,n){var r;n=x.defaults({},n,x.templateSettings);var i=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),s=0,o="__p+='";e.replace(i,function(t,n,r,i,u){return o+=e.slice(s,u).replace(j,function(e){return"\\"+B[e]}),n&&(o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(o+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(o+="';\n"+i+"\n__p+='"),s=u+t.length,t}),o+="';\n",n.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{r=new Function(n.variable||"obj","_",o)}catch(u){throw u.source=o,u}if(t)return r(t,x);var a=function(e){return r.call(this,e,x)};return a.source="function("+(n.variable||"obj")+"){\n"+o+"}",a},x.chain=function(e){return x(e).chain()};var F=function(e){return this._chain?x(e).chain():e};x.mixin(x),T(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];x.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),T(["concat","join","slice"],function(e){var t=r[e];x.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),define("libs/underscore",function(e){return function(){var t,n;return t||e._}}(this)),define("utils/utils",["libs/underscore"],function(e){function t(e,t,r){n("GET",e,{},t,r)}function n(e,t,n,r,i){if(e=="GET"||e=="DELETE")t.indexOf("?")==-1?t+="?":t+="&",t+=$.param(n);var s=new XMLHttpRequest;s.open(e,t,!0),s.setRequestHeader("Accept","application/json"),s.setRequestHeader("Cache-Control","no-cache"),s.setRequestHeader("X-Requested-With","XMLHttpRequest"),s.setRequestHeader("Content-Type","application/json"),s.onloadend=function(){var e=s.status;try{response=jQuery.parseJSON(s.responseText)}catch(t){response=s.responseText}e==200?r&&r(response):i&&i(response)},e=="GET"||e=="DELETE"?s.send():s.send(JSON.stringify(n))}function r(e,t){var n=$('<div class="'+e+'"></div>');n.appendTo(":eq(0)");var r=n.css(t);return n.remove(),r}function i(e){$('link[href^="'+e+'"]').length||$('<link href="'+galaxy_config.root+e+'" rel="stylesheet">').appendTo("head")}function s(t,n){return t?e.defaults(t,n):n}function o(e,t){var n="";if(e>=1e11)e/=1e11,n="TB";else if(e>=1e8)e/=1e8,n="GB";else if(e>=1e5)e/=1e5,n="MB";else if(e>=100)e/=100,n="KB";else{if(!(e>0))return"<strong>-</strong>";e*=10,n="b"}var r=Math.round(e)/10;return t?r+" "+n:"<strong>"+r+"</strong> "+n}function u(){return"x"+Math.random().toString(36).substring(2,9)}function a(e){var t=$("<p></p>");return t.append(e),t}function f(){var e=new Date,t=(e.getHours()<10?"0":"")+e.getHours(),n=(e.getMinutes()<10?"0":"")+e.getMinutes(),r=e.getDate()+"/"+(e.getMonth()+1)+"/"+e.getFullYear()+", "+t+":"+n;return r}return{cssLoadFile:i,cssGetAttribute:r,get:t,merge:s,bytesToString:o,uuid:u,time:f,wrap:a,request:n}}),define("mvc/ui/ui-portlet",["utils/utils"],function(e){var t=Backbone.View.extend({visible:!1,optionsDefault:{title:"",icon:"",buttons:null,body:null,scrollable:!0,nopadding:!1,operations:null,placement:"bottom"},$title:null,$content:null,$buttons:null,$operations:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.$content=this.$el.find("#content"),this.$title=this.$el.find("#portlet-header-text");var n=this.$el.find("#portlet-content");this.options.scrollable?n.addClass("scroll"):this.options.title?n.addClass("no-scroll"):n.addClass("no-scroll-no-title"),this.options.nopadding&&(n.css("padding","0px"),this.$content.css("padding","0px")),this.$buttons=$(this.el).find("#buttons");if(this.options.buttons){var r=this;$.each(this.options.buttons,function(e,t){t.$el.prop("id",e),r.$buttons.append(t.$el)})}else this.$buttons.remove();this.$operations=$(this.el).find("#operations");if(this.options.operations){var r=this;$.each(this.options.operations,function(e,t){t.$el.prop("id",e),r.$operations.append(t.$el)})}this.options.body&&this.append(this.options.body)},append:function(t){this.$content.append(e.wrap(t))},content:function(){return this.$content},show:function(){this.$el.fadeIn("fast"),this.visible=!0},hide:function(){this.$el.fadeOut("fast"),this.visible=!1},enableButton:function(e){this.$buttons.find("#"+e).prop("disabled",!1)},disableButton:function(e){this.$buttons.find("#"+e).prop("disabled",!0)},hideOperation:function(e){this.$operations.find("#"+e).hide()},showOperation:function(e){this.$operations.find("#"+e).show()},setOperation:function(e,t){var n=this.$operations.find("#"+e);n.off("click"),n.on("click",t)},title:function(e){var t=this.$title;return e&&t.html(e),t.html()},_template:function(e){var t='<div class="ui-portlet">';return e.title&&(t+='<div id="portlet-header" class="portlet-header"><div id="operations" style="float: right;"></div><h3>',e.icon&&(t+='<i class="icon fa '+e.icon+'"> </i>'),t+='<span id="portlet-header-text">'+e.title+"</span>"+"</h3>"+"</div>"),t+='<div id="portlet-content" class="portlet-content">',e.placement=="top"&&(t+='<div id="buttons" class="buttons"></div>'),t+='<div id="content" class="content"></div>',e.placement=="bottom"&&(t+='<div id="buttons" class="buttons"></div>'),t+="</div></div>",t}});return{View:t}}),define("plugin/library/ui-select",["utils/utils"],function(e){var t=Backbone.View.extend({optionsDefault:{id:"",cls:"",empty:"No data available",visible:!0,wait:!1},selected:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.selected=this.options.value,this.setElement(this._template(this.options)),this.$select=this.$el.find("#select"),this.$icon=this.$el.find("#icon");var n=this;this.$select.on("change",function(){n.value(n.$select.val())}),this.on("change",function(){n.options.onchange&&n.options.onchange(n.value())}),this._refresh(),this.options.visible||this.hide(),this.options.wait?this.wait():this.show()},value:function(e){var t=this.selected;e!==undefined&&(this.selected=e,this.$select.val(e));var n=this.selected;return n&&n!=t&&this.options.onchange&&this.options.onchange(n),n},first:function(){var e=this.$select.find("option");return e.length>0?e.val():undefined},text:function(){return this.$select.find("option:selected").text()},show:function(){this.$icon.removeClass(),this.$icon.addClass("fa fa-caret-down"),this.$select.show(),this.$el.show()},hide:function(){this.$el.hide()},wait:function(){this.$icon.removeClass(),this.$icon.addClass("fa fa-spinner fa-spin"),this.$select.hide()},disabled:function(){return this.$select.is(":disabled")},enable:function(){this.$select.prop("disabled",!1)},disable:function(){this.$select.prop("disabled",!0)},add:function(e){this.$select.append(this._templateOption(e)),this._refresh()},del:function(e){this.$select.find("option[value="+e+"]").remove(),this.$select.trigger("change"),this._refresh()},update:function(e){this.$select.find("option").remove();for(var t in e)this.$select.append(this._templateOption(e[t]));this._refresh()},setOnChange:function(e){this.options.onchange=e},exists:function(e){return this.$select.find("option[value="+e+"]").length>0},_refresh:function(){this.$select.find("option[value=null]").remove();var e=this.$select.find("option").length;e==0?(this.disable(),this.$select.append(this._templateOption({value:"null",label:this.options.empty}))):this.enable(),this.selected&&this.$select.val(this.selected)},_templateOption:function(e){return'<option value="'+e.value+'">'+e.label+"</option>"},_template:function(e){var t='<div id="'+e.id+'" class="ui-select">'+'<div class="button">'+'<i id="icon"/>'+"</div>"+'<select id="select" class="select '+e.cls+" "+e.id+'">';for(key in e.data){var n=e.data[key],r="";if(n.value==e.value||n.value=="")r="selected";t+='<option value="'+n.value+'" '+r+">"+n.label+"</option>"}return t+="</select></div>",t}});return{View:t}}),define("plugin/library/ui-button-menu",["utils/utils"],function(e){return Backbone.View.extend({optionsDefault:{id:"",title:"","float":"right",icon:null,onclick:null,cls:"icon-btn",tooltip:"",target:"",href:"",onunload:null,visible:!0,tag:""},$menu:null,initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement($(this._template(this.options)));var n=$(this.el).find(".root"),r=this;n.on("click",function(e){$(".tooltip").hide(),e.preventDefault(),r.options.onclick&&r.options.onclick()}),this.options.visible||this.hide(),n.tooltip({title:t.tooltip,placement:"bottom"})},show:function(){$(this.el).show()},hide:function(){$(this.el).hide()},addMenu:function(t){var n={title:"",target:"",href:"",onclick:null,divider:!1,icon:null,cls:"button-menu btn-group"};n=e.merge(t,n),this.$menu||($(this.el).append(this._templateMenu()),this.$menu=$(this.el).find(".menu"));var r=$(this._templateMenuItem(n));r.on("click",function(e){e.preventDefault(),n.onclick&&n.onclick()}),this.$menu.append(r),n.divider&&this.$menu.append($(this._templateDivider()))},_templateMenuItem:function(e){var t='<li><a href="'+e.href+'" target="'+e.target+'">';return e.icon&&(t+='<i class="fa '+e.icon+'"></i>'),t+=" "+e.title+"</a>"+"</li>",t},_templateMenu:function(){return'<ul class="menu dropdown-menu pull-right" role="menu"></ul>'},_templateDivider:function(){return'<li class="divider"></li>'},_template:function(e){var t="";e.title&&(t="width: auto;");var n='<div id="'+e.id+'" style="float: '+e.float+"; "+t+'" class="ui-button-icon dropdown '+e.cls+'">';return e.title?n+='<div class="root button dropdown-toggle" data-toggle="dropdown"><i class="icon fa '+e.icon+'"/> '+'<span class="title">'+e.title+"</span>"+"</div>":n+='<i class="icon fa '+e.icon+'"/>',n+="</div>",n}})}),define("plugin/library/ui",["utils/utils","plugin/library/ui-select","plugin/library/ui-button-menu","mvc/ui/ui-modal"],function(e,t,n,r){var i=Backbone.View.extend({optionsDefault:{url:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options))},_template:function(e){return'<img class="ui-image '+e.cls+'" src="'+e.url+'"/>'}}),s=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options))},title:function(e){this.$el.html(e)},_template:function(e){return'<label class="ui-label '+e.cls+'">'+e.title+"</label>"},value:function(){return options.title}}),o=Backbone.View.extend({optionsDefault:{"float":"right",icon:"",tooltip:"",placement:"bottom",title:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){return'<div><span class="fa '+e.icon+'" class="ui-icon"/> '+e.title+"</div>"}}),u=Backbone.View.extend({optionsDefault:{id:null,title:"","float":"right",cls:"btn btn-default",icon:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){var t='<button id="'+e.id+'" type="submit" style="float: '+e.float+';" type="button" class="ui-button '+e.cls+'">';return e.icon&&(t+='<i class="icon fa '+e.icon+'"></i> '),t+=e.title+"</button>",t}}),a=Backbone.View.extend({optionsDefault:{id:null,title:"","float":"right",cls:"icon-btn",icon:"",tooltip:"",onclick:null},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick),$(this.el).tooltip({title:t.tooltip,placement:"bottom"})},_template:function(e){var t="";e.title&&(t="width: auto;");var n='<div id="'+e.id+'" style="float: '+e.float+"; "+t+'" class="ui-button-icon '+e.cls+'">';return e.title?n+='<div class="button"><i class="icon fa '+e.icon+'"/> '+'<span class="title">'+e.title+"</span>"+"</div>":n+='<i class="icon fa '+e.icon+'"/>',n+="</div>",n}}),f=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),$(this.el).on("click",t.onclick)},_template:function(e){return'<div><a href="javascript:void(0)" class="ui-anchor '+e.cls+'">'+e.title+"</a></div>"}}),l=Backbone.View.extend({optionsDefault:{message:"",status:"info",persistent:!1},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement("<div></div>")},update:function(t){this.options=e.merge(t,this.optionsDefault);if(t.message!=""){this.$el.html(this._template(this.options)),this.$el.find(".alert").append(t.message),this.$el.fadeIn();if(!t.persistent){var n=this;window.setTimeout(function(){n.$el.is(":visible")?n.$el.fadeOut():n.$el.hide()},3e3)}}else this.$el.fadeOut()},_template:function(e){return'<div class="ui-message alert alert-'+e.status+'"/>'}}),c=Backbone.View.extend({optionsDefault:{onclick:null,searchword:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options));var n=this;this.options.onclick&&this.$el.on("submit",function(e){var t=n.$el.find("#search");n.options.onclick(t.val())})},_template:function(e){return'<div class="ui-search"><form onsubmit="return false;"><input id="search" class="form-control input-sm" type="text" name="search" placeholder="Search..." value="'+e.searchword+'">'+'<button type="submit" class="btn search-btn">'+'<i class="fa fa-search"></i>'+"</button>"+"</form>"+"</div>"}}),h=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:!1,visible:!0,cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.options.disabled&&this.$el.prop("disabled",!0),this.options.visible||this.$el.hide();var n=this;this.$el.on("input",function(){n.options.onchange&&n.options.onchange(n.$el.val())})},value:function(e){return e!==undefined&&this.$el.val(e),this.$el.val()},_template:function(e){return'<input id="'+e.id+'" type="'+e.type+'" value="'+e.value+'" placeholder="'+e.placeholder+'" class="ui-input '+e.cls+'">'}}),p=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:!1,visible:!0,cls:""},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.options.disabled&&this.$el.prop("disabled",!0),this.options.visible||this.$el.hide();var n=this;this.$el.on("input",function(){n.options.onchange&&n.options.onchange(n.$el.val())})},value:function(e){return e!==undefined&&this.$el.val(e),this.$el.val()},_template:function(e){return'<textarea id="'+e.id+'" class="ui-textarea '+e.cls+'" rows="5"></textarea>'}}),d=Backbone.View.extend({optionsDefault:{value:"",visible:!0,cls:"",data:[],id:e.uuid()},initialize:function(t){this.options=e.merge(t,this.optionsDefault),this.setElement(this._template(this.options)),this.options.visible||this.$el.hide(),this.options.value&&this.value(this.options.value),this.current=this.options.value;var n=this;this.$el.find("input").on("change",function(){n.value(n._getValue())})},value:function(e){var t=this.current;e!==undefined&&(this.$el.find("label").removeClass("active"),this.$el.find('[value="'+e+'"]').closest("label").addClass("active"),this.current=e);var n=this.current;return n!=t&&this.options.onchange&&this.options.onchange(this.current),this.current},_getValue:function(){var e=this.$el.find(":checked"),t=null;return e.length>0&&(t=e.val()),t},_template:function(e){var t='<div class="btn-group ui-radiobutton" data-toggle="buttons">';for(key in e.data){var n=e.data[key];t+='<label class="btn btn-default"><input type="radio" name="'+e.id+'" value="'+n.value+'" selected>'+n.label+"</label>"}return t+="</div>",t}});return{Label:s,Button:u,Icon:o,ButtonIcon:a,Input:h,Anchor:f,Message:l,Searchbox:c,Select:t,ButtonMenu:n,Modal:r,Textarea:p,Image:i,RadioButton:d}}),define("plugin/library/jobs",["utils/utils"],function(e){return Backbone.Model.extend({initialize:function(t,n){this.app=t,this.options=e.merge(n,this.optionsDefault)},request:function(e,t,n,r,i){var s=this;e.state("wait","Requesting job results...");var o=e.get("dataset_id_job");o!=""?s._wait(e,r,i):s._submit(e,t,n,r,i)},cleanup:function(t){var n=this,r=t.get("dataset_id_job");r!=""&&(e.request("PUT",config.root+"api/histories/none/contents/"+r,{deleted:!0},function(){n._refreshHdas()}),t.set("dataset_id_job",""))},_submit:function(t,n,r,i,s){var o=this,u=t.id,a=t.get("type"),f=t.definition;data={tool_id:"charts",inputs:{input:{id:t.get("dataset_id"),src:"hda"},module:f.execute,columns:r,settings:n}},t.state("wait","Sending job request..."),e.request("POST",config.root+"api/tools",data,function(e){if(!e.outputs||e.outputs.length==0)t.state("failed","Job submission failed. No response."),s&&s();else{o._refreshHdas();var n=e.outputs[0];t.state("wait","Your job has been queued. You may close the browser window. The job will run in the background."),t.set("dataset_id_job",n.id),this.app.storage.save(),o._wait(t,i,s)}},function(e){var n="";e&&e.message&&e.message.data&&e.message.data.input&&(n=e.message.data.input+"."),t.state("failed","This visualization requires the 'charts' tool. Please make sure it is installed. "+n),s&&s()})},_wait:function(t,n,r){var i=this;e.request("GET",config.root+"api/datasets/"+t.get("dataset_id_job"),{},function(e){var s=!1;switch(e.state){case"ok":t.state("wait","Job completed successfully..."),n&&n(e),s=!0;break;case"error":t.state("failed","Job has failed. Please check the history for details."),r&&r(e),s=!0;break;case"running":t.state("wait","Your job is running. You may close the browser window. The job will continue in the background.")}s||setTimeout(function(){i._wait(t,n,r)},i.app.config.get("query_timeout"))})},_refreshHdas:function(){Galaxy&&Galaxy.currHistoryPanel&&Galaxy.currHistoryPanel.refreshContents()}})}),define("plugin/library/datasets",["utils/utils"],function(e){return Backbone.Collection.extend({list:{},cache:{},initialize:function(t,n){this.app=t,this.options=e.merge(n,this.optionsDefault)},request:function(e){e.groups?this._get_blocks(e):this._get_dataset(e.id,e.success,e.error)},_get_blocks:function(e){function h(i){c._get(i,function(){var s=!1;for(var o in e.groups){destination_group=e.groups[o],source_group=i.groups[o],destination_group.values||(destination_group.values=[]),destination_group.values=destination_group.values.concat(source_group.values);if(source_group.values.length==0){s=!0;break}}if(++l<a&&!s){n&&n(parseInt(l/a*100));var u=i.start+r;i=$.extend(!0,f,{start:u}),h(i)}else t()})}var t=e.success,n=e.progress,r=this.app.config.get("query_limit"),i=this.app.config.get("query_timeout"),s=e.start||0,o=s+e.query_limit||s+this.app.config.get("query_limit"),u=Math.abs(o-s);if(u<=0){console.debug("FAILED - Datasets::request() - Invalid query range.");return}var a=Math.ceil(u/r)||1,f=$.extend(!0,{},e),l=0,c=this,p=$.extend(!0,f,{start:s});this._get_dataset(e.id,function(){h(p)})},_get_dataset:function(t,n,r){var i=this.list[t];if(i){n(i);return}var s=this;e.request("GET",config.root+"api/datasets/"+t,{},function(e){switch(e.state){case"error":r&&r(e);break;default:s.list[t]=e,n(e)}})},_block_id:function(e,t){return e.id+"_"+e.start+"_"+e.start+this.app.config.get("query_limit")+"_"+t},_get:function(e,t){e.start=e.start||0;var n=[],r={},i=0;for(var s in e.groups){var o=e.groups[s];for(var u in o.columns){var a=o.columns[u].index,f=this._block_id(e,a);if(this.cache[f]||a==="auto"||a==="zero")continue;!r[a]&&a!==undefined&&(r[a]=i,n.push(a),i++)}}if(n.length==0){this._fill_from_cache(e),t(e);return}var l={dataset_id:e.id,start:e.start,columns:n},c=this;this._fetch(l,function(r){for(var i in r){var s=n[i],o=c._block_id(e,s);c.cache[o]=r[i]}c._fill_from_cache(e),t(e)})},_fill_from_cache:function(e){var t=e.start;console.debug("Datasets::_fill_from_cache() - Filling request from cache at "+t+".");var n=0;for(var r in e.groups){var i=e.groups[r];for(var s in i.columns){var o=i.columns[s],u=this._block_id(e,o.index),a=this.cache[u];a&&(n=Math.max(n,a.length))}}n==0&&console.debug("Datasets::_fill_from_cache() - Reached data range limit.");for(var r in e.groups){var i=e.groups[r];i.values=[];for(var f=0;f<n;f++)i.values[f]={x:parseInt(f)+t}}for(var r in e.groups){var i=e.groups[r];for(var s in i.columns){var o=i.columns[s];switch(o.index){case"auto":for(var f=0;f<n;f++){var l=i.values[f];l[s]=parseInt(f)+t}break;case"zero":for(var f=0;f<n;f++){var l=i.values[f];l[s]=0}break;default:var u=this._block_id(e,o.index),a=this.cache[u];for(var f=0;f<n;f++){var l=i.values[f],c=a[f];isNaN(c)&&!o.is_label&&(c=0),l[s]=c}}}}},_fetch:function(t,n){var r=t.start?t.start:0,i=this.app.config.get("query_limit"),s=0;t.columns&&(s=t.columns.length,console.debug("Datasets::_fetch() - Fetching "+s+" column(s) at "+r+".")),s==0&&console.debug("Datasets::_fetch() - No columns requested");var o="";for(var u in t.columns)o+=t.columns[u]+",";o=o.substring(0,o.length-1);var a=this;e.request("GET",config.root+"api/datasets/"+t.dataset_id,{data_type:"raw_data",provider:"dataset-column",limit:i,offset:r,indeces:o},function(e){var t=new Array(s);for(var r=0;r<s;r++)t[r]=[];for(var r in e.data){var i=e.data[r];for(var o in i){var u=i[o];u!==undefined&&u!=2147483647&&t[o].push(u)}}console.debug("Datasets::_fetch() - Fetching complete."),n(t)})}})}),define("plugin/models/group",[],function(){return Backbone.Model.extend({defaults:{key:"Data label",date:""},reset:function(){this.clear({silent:!0}).set(this.defaults),this.trigger("reset",this)}})}),define("plugin/models/groups",["plugin/models/group"],function(e){return Backbone.Collection.extend({model:e})}),define("plugin/library/deferred",["utils/utils"],function(e){return Backbone.Model.extend({queue:[],process:{},counter:0,initialize:function(){this.on("refresh",function(){for(var e in this.queue)if(this.counter==0){var t=this.queue[e];this.queue.splice(e,1),t()}})},execute:function(e){this.queue.push(e),this.trigger("refresh")},register:function(){var t=e.uuid();return this.process[t]=!0,this.counter++,console.debug("Deferred:register() - Registering "+t),t},done:function(e){this.process[e]&&(delete this.process[e],this.counter--,console.debug("Deferred:done() - Unregistering "+e),this.trigger("refresh"))},ready:function(){return this.counter==0}})});var Visualization=Backbone.Model.extend({defaults:{config:{}},urlRoot:function(){var e="/api/visualizations";return window.galaxy_config&&galaxy_config.root?galaxy_config.root+e:e},initialize:function(e){_.isObject(e.config)&&_.isObject(this.defaults.config)&&_.defaults(e.config,this.defaults.config),this._setUpListeners()},_setUpListeners:function(){},set:function(e,t){if(e==="config"){var n=this.get("config");_.isObject(n)&&(t=_.extend(_.clone(n),t))}return Backbone.Model.prototype.set.call(this,e,t),this},toString:function(){var e=this.get("id")||"";return this.get("title")&&(e+=":"+this.get("title")),"Visualization("+e+")"}}),VisualizationCollection=Backbone.Collection.extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(e,t){t=t||{}},set:function(e,t){var n=this;e=_.map(e,function(e){var t=n.get(e.id);if(!t)return e;var r=t.toJSON();return _.extend(r,e),r}),Backbone.Collection.prototype.set.call(this,e,t)},toString:function(){return["VisualizationCollection(",[this.historyId,this.length].join(),")"].join("")}});define("mvc/visualization/visualization-model",function(){}),define("plugin/models/chart",["plugin/models/groups","plugin/library/deferred","mvc/visualization/visualization-model"],function(e,t){return Backbone.Model.extend({defaults:{id:null,title:"",type:"",date:null,state:"",state_info:"",modified:!1,dataset_id:"",dataset_id_job:""},initialize:function(n){this.groups=new e,this.settings=new Backbone.Model,this.deferred=new t},reset:function(){this.clear({silent:!0}).set(this.defaults),this.groups.reset(),this.settings.clear(),this.trigger("reset",this)},copy:function(e){var t=this;t.clear({silent:!0}).set(this.defaults),t.set(e.attributes),t.settings=e.settings.clone(),t.groups.reset(),e.groups.each(function(e){t.groups.add(e.clone())}),t.trigger("change",t)},state:function(e,t){this.set("state",e),this.set("state_info",t),this.trigger("set:state"),console.debug("Chart:state() - "+t+" ("+e+")")}})}),define("plugin/library/storage",["utils/utils","plugin/models/chart","plugin/models/group"],function(e,t,n){return Backbone.Model.extend({vis:null,initialize:function(e){this.app=e,this.chart=this.app.chart,this.options=this.app.options,this.id=this.options.id,this.vis=new Visualization({type:"charts",config:{dataset_id:this.options.config.dataset_id,chart_dict:{}}}),this.id&&(this.vis.id=this.id);var t=this.options.config.chart_dict;t&&(this.vis.get("config").chart_dict=t)},save:function(){var e=this.app.chart;this.vis.get("config").chart_dict={};var t=e.get("title");t!=""&&this.vis.set("title",t);var n={attributes:e.attributes,settings:e.settings.attributes,groups:[]};e.groups.each(function(e){n.groups.push(e.attributes)}),this.vis.get("config").chart_dict=n;var r=this;this.vis.save().fail(function(e,t,n){console.error(e,t,n)}).then(function(e){e&&e.id&&(r.id=e.id)})},load:function(){var e=this.vis.get("config").chart_dict;if(!e.attributes)return!1;var t=e.attributes.type;if(!t)return console.debug("Storage::load() - Chart type not provided. Invalid format."),!1;var r=this.app.types.get(t);if(!r)return console.debug("Storage::load() - Chart type not supported. Please re-configure the chart. Resetting chart."),!1;console.debug("Storage::load() - Loading chart type "+t+"."),this.chart.definition=r,this.chart.set(e.attributes),this.chart.state("ok","Loading saved visualization..."),this.chart.settings.set(e.settings);for(var i in e.groups)this.chart.groups.add(new n(e.groups[i]));return this.chart.set("modified",!1),!0}})}),define("plugin/views/viewport",["mvc/ui/ui-portlet","plugin/library/ui","utils/utils"],function(e,t,n){return Backbone.View.extend({container_list:[],canvas_list:[],initialize:function(e,t){this.app=e,this.chart=this.app.chart,this.options=n.merge(t,this.optionsDefault),this.setElement($(this._template())),this._fullscreen(this.$el,100),this._createContainer("div");var r=this;this.chart.on("redraw",function(){r._draw(r.chart)}),this.chart.on("set:state",function(){var e=r.$el.find("#info"),t=r.$el.find(".charts-viewport-container"),n=e.find("#icon");n.removeClass(),e.show(),e.find("#text").html(r.chart.get("state_info"));var i=r.chart.get("state");switch(i){case"ok":e.hide(),t.show();break;case"failed":n.addClass("icon fa fa-warning"),t.hide();break;default:n.addClass("icon fa fa-spinner fa-spin"),t.show()}})},show:function(){this.$el.show()},hide:function(){this.$el.hide()},_fullscreen:function(e,t){e.css("height",$(window).height()-t),$(window).resize(function(){e.css("height",$(window).height()-t)})},_createContainer:function(e,t){t=t||1;for(var n in this.container_list)this.container_list[n].remove();this.container_list=[],this.canvas_list=[];for(var n=0;n<t;n++){var r=$(this._templateContainer(e,parseInt(100/t)));this.$el.append(r),this.container_list[n]=r,this.canvas_list[n]=r.find(".charts-viewport-canvas").attr("id")}},_draw:function(e){var t=this,n=e.deferred.register(),r=e.get("type");this.chart_definition=e.definition;var i=1;e.settings.get("use_panels")==="true"&&(i=e.groups.length),this._createContainer(this.chart_definition.tag,i),e.state("wait","Please wait...");if(!this.chart_definition.execute||this.chart_definition.execute&&e.get("modified"))this.app.jobs.cleanup(e),e.set("modified",!1);var t=this;require(["plugin/charts/"+this.app.chartPath(r)+"/wrapper"],function(r){if(t.chart_definition.execute)t.app.jobs.request(e,t._defaultSettingsString(e),t._defaultRequestString(e),function(){var i=new r(t.app,{process_id:n,chart:e,request_dictionary:t._defaultRequestDictionary(e),canvas_list:t.canvas_list})},function(){e.deferred.done(n)});else var i=new r(t.app,{process_id:n,chart:e,request_dictionary:t._defaultRequestDictionary(e),canvas_list:t.canvas_list})})},_defaultRequestString:function(e){var t="",n=0,r=this;return e.groups.each(function(e){n++;for(var i in r.chart_definition.columns)t+=i+"_"+n+":"+(parseInt(e.get(i))+1)+", "}),t.substring(0,t.length-2)},_defaultSettingsString:function(e){var t="";for(key in e.settings.attributes)t+=key+":"+e.settings.get(key)+", ";return t.substring(0,t.length-2)},_defaultRequestDictionary:function(e){var t={groups:[]};this.chart_definition.execute?t.id=e.get("dataset_id_job"):t.id=e.get("dataset_id");var r=0,i=this;return e.groups.each(function(e){var s={};for(var o in i.chart_definition.columns){var u=i.chart_definition.columns[o];s[o]=n.merge({index:e.get(o)},u)}t.groups.push({key:++r+":"+e.get("key"),columns:s})}),t},_template:function(){return'<div class="charts-viewport"><div id="info" class="info"><span id="icon" class="icon"/><span id="text" class="text" /></div></div>'},_templateContainer:function(e,t){return'<div class="charts-viewport-container" style="width:'+t+'%;">'+'<div id="menu"/>'+"<"+e+' id="'+n.uuid()+'" class="charts-viewport-canvas">'+"</div>"}})}),define("plugin/library/screenshot",["libs/underscore"],function(e){function t(e){e.$el.find("svg").length>0?r(e):n(e)}function n(e){try{var t=e.$el.find(".jqplot-target"),n=t.jqplotToImageStr({});n&&(window.location.href=n.replace("image/png","image/octet-stream"))}catch(r){console.debug("FAILED - Screenshot::_fromCanvas() - "+r),e.error&&e.error("Please reduce your chart to a single panel and try again.")}}function r(e){var t=e.$el,n=e.url,r=e.name,s=new XMLSerializer,o=document.createElement("canvas"),u=$(o),a=t.find("svg").length,f=t.find("svg").first(),l=parseInt(f.css("height")),c=parseInt(f.css("width"));u.attr("width",c*a),u.attr("height",l),(!o.getContext||!o.getContext("2d"))&&alert("Your browser doesn't support this feature, please use a modern browser");var h=o.getContext("2d"),p=0;t.find("svg").each(function(){var e=$(this);e.attr({version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:c,height:l});var t=s.serializeToString(this);h.drawSvg(t,p,0,c,l),p+=c}),window.location.href=i(o,o.getContext("2d"),"white").replace("image/png","image/octet-stream")}function i(e,t,n){var r=e.width,i=e.height,s;if(n){s=t.getImageData(0,0,r,i);var o=t.globalCompositeOperation;t.globalCompositeOperation="destination-over",t.fillStyle=n,t.fillRect(0,0,r,i)}var u=e.toDataURL("image/png");return n&&(t.clearRect(0,0,r,i),t.putImageData(s,0,0),t.globalCompositeOperation=o),u}function s(e){window.location.href="data:none/none;base64,"+btoa(a(e).string)}function o(e){for(var t in document.styleSheets){var n=document.styleSheets[t],r=n.cssRules;if(r)for(var i=0,s=r.length;i<s;i++)try{e.find(r[i].selectorText).each(function(e,t){t.style.cssText+=r[i].style.cssText})}catch(o){}}}function u(e){var t=a(e),n={filename:name||"chart",type:"application/pdf",height:t.height,width:t.width,scale:2,svg:t.string},r=$("body"),i=r.find("#viewport-form");i.length===0&&(i=$("<form>",{id:"viewport-form",method:"post",action:"http://export.highcharts.com/",display:"none"}),r.append(i)),i.empty();for(name in n){var s=$("<input/>",{type:"hidden",name:name,value:n[name]});i.append(s)}try{i.submit()}catch(o){console.log(o)}}function a(e){if(e.$el.find("svg").length==0&&e.error){e.error("No SVG found. This chart type does not support SVG/PDF export.");return}var t=e.$el,n=t.find("svg").length,r=parseInt(t.find("svg").first().css("height")),i=parseInt(t.find("svg").first().css("width")),s=new XMLSerializer,u=$("<svg/>");u.attr({version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:i*n,height:r});var a="",f=0;return t.find("svg").each(function(){var e=$(this).clone();o(e);var t=$('<g transform="translate('+f+', 0)">');t.append(e.find("g").first()),u.append(t),f+=i}),{string:s.serializeToString(u[0]),height:r,width:i}}return{createPNG:t,createSVG:s,createPDF:u}}),define("plugin/views/viewer",["utils/utils","plugin/library/ui","mvc/ui/ui-portlet","plugin/models/group","plugin/views/viewport","plugin/library/screenshot"],function(e,t,n,r,i,s){return Backbone.View.extend({initialize:function(e,r){this.app=e,this.chart=this.app.chart,this.viewport_view=new i(e);var o=this;this.message=new t.Message;var u=new t.ButtonMenu({icon:"fa-camera",title:"Screenshot",tooltip:"Download as PNG, SVG or PDF file"});u.addMenu({id:"button-png",title:"Save as PNG",icon:"fa-file",onclick:function(){o._wait(o.chart,function(){s.createPNG({$el:o.viewport_view.$el,title:o.chart.get("title"),error:function(e){o.message.update({message:e,status:"danger"})}})})}}),u.addMenu({id:"button-svg",title:"Save as SVG",icon:"fa-file-text-o",onclick:function(){o._wait(o.chart,function(){s.createSVG({$el:o.viewport_view.$el,title:o.chart.get("title"),error:function(e){o.message.update({message:e,status:"danger"})}})})}}),u.addMenu({id:"button-png",title:"Save as PDF",icon:"fa-file-o",onclick:function(){o.app.modal.show({title:"Send chart data for PDF creation",body:"Galaxy does not provide integrated PDF export scripts. You may click 'Continue' to create the PDF by using a 3rd party service (https://export.highcharts.com)",buttons:{Cancel:function(){o.app.modal.hide()},Continue:function(){o.app.modal.hide(),o._wait(o.chart,function(){s.createPDF({$el:o.viewport_view.$el,title:o.chart.get("title"),error:function(e){o.message.update({message:e,status:"danger"})}})})}}})}}),this.portlet=new n.View({icon:"fa-bar-chart-o",title:"Viewport",scrollable:!1,operations:{edit_button:new t.ButtonIcon({icon:"fa-edit",tooltip:"Customize this chart",title:"Editor",onclick:function(){o._wait(o.chart,function(){o.app.go("editor")})}}),picture_button_menu:u}}),this.portlet.append(this.message.$el),this.portlet.append(this.viewport_view.$el),this.setElement(this.portlet.$el);var o=this;this.chart.on("change:title",function(){o._refreshTitle()})},show:function(){this.$el.show(),$(window).trigger("resize")},hide:function(){this.$el.hide()},_refreshTitle:function(){var e=this.chart.get("title");this.portlet.title(e)},_wait:function(e,t){e.deferred.ready()?t():this.message.update({message:"Your chart is currently being processed. Please wait and try again."})}})}),define("mvc/ui/ui-tabs",["utils/utils"],function(e){var t=Backbone.View.extend({optionsDefault:{title_new:"",operations:null,onnew:null},initialize:function(t){this.visible=!1,this.$nav=null,this.$content=null,this.first_tab=null,this.options=e.merge(t,this.optionsDefault);var n=$(this._template(this.options));this.$nav=n.find(".tab-navigation"),this.$content=n.find(".tab-content"),this.setElement(n),this.list={};var r=this;this.options.operations&&$.each(this.options.operations,function(e,t){t.$el.prop("id",e),r.$nav.find(".operations").append(t.$el)});if(this.options.onnew){var i=$(this._template_tab_new(this.options));this.$nav.append(i),i.tooltip({title:"Add a new tab",placement:"bottom",container:r.$el}),i.on("click",function(e){i.tooltip("hide"),r.options.onnew()})}},add:function(e){var t=this,n=e.id,r=$(this._template_tab(e)),i=$(this._template_tab_content(e));this.list[n]=e.ondel?!0:!1,this.options.onnew?this.$nav.find("#new-tab").before(r):this.$nav.append(r),i.append(e.$el),this.$content.append(i),_.size(this.list)==1&&(r.addClass("active"),i.addClass("active"),this.first_tab=n);if(e.ondel){var s=r.find("#delete");s.tooltip({title:"Delete this tab",placement:"bottom",container:t.$el}),s.on("click",function(){return s.tooltip("destroy"),t.$el.find(".tooltip").remove(),e.ondel(),!1})}r.on("click",function(r){r.preventDefault(),e.onclick?e.onclick():t.show(n)})},del:function(e){this.$el.find("#tab-"+e).remove(),this.$el.find("#tab-content-"+e).remove(),this.first_tab==e&&(this.first_tab=null),this.first_tab!=null&&this.show(this.first_tab)},delRemovable:function(){for(var e in this.list)this.list[e]&&this.del(e)},show:function(e){this.$el.fadeIn("fast"),this.visible=!0,e&&(this.$el.find(".tab-element").removeClass("active"),this.$el.find(".tab-pane").removeClass("active"),this.$el.find("#tab-"+e).addClass("active"),this.$el.find("#tab-content-"+e).addClass("active"))},hide:function(){this.$el.fadeOut("fast"),this.visible=!1},hideOperation:function(e){this.$nav.find("#"+e).hide()},showOperation:function(e){this.$nav.find("#"+e).show()},setOperation:function(e,t){var n=this.$nav.find("#"+e);n.off("click"),n.on("click",t)},title:function(e,t){var n=this.$el.find("#tab-title-text-"+e);return t&&n.html(t),n.html()},_template:function(e){return'<div class="ui-tabs tabbable tabs-left"><ul id="tab-navigation" class="tab-navigation nav nav-tabs"><div class="operations" style="float: right; margin-bottom: 4px;"></div></ul><div id="tab-content" class="tab-content"/></div>'},_template_tab_new:function(e){return'<li id="new-tab"><a href="javascript:void(0);"><i class="ui-tabs-add fa fa-plus-circle"/>'+e.title_new+"</a>"+"</li>"},_template_tab:function(e){var t='<li id="tab-'+e.id+'" class="tab-element">'+'<a id="tab-title-link-'+e.id+'" title="" href="#tab-content-'+e.id+'" data-original-title="">'+'<span id="tab-title-text-'+e.id+'">'+e.title+"</span>";return e.ondel&&(t+='<i id="delete" class="ui-tabs-delete fa fa-minus-circle"/>'),t+="</a></li>",t},_template_tab_content:function(e){return'<div id="tab-content-'+e.id+'" class="tab-pane"/>'}});return{View:t}}),define("plugin/library/ui-table",["utils/utils"],function(e){var t=Backbone.View.extend({row:null,row_count:0,optionsDefault:{content:"No content available.",onchange:null,ondblclick:null,onconfirm:null,cls:""},events:{click:"_onclick",dblclick:"_ondblclick"},initialize:function(t){this.options=e.merge(t,this.optionsDefault);var n=$(this._template(t));this.$thead=n.find("thead"),this.$tbody=n.find("tbody"),this.$tmessage=n.find("tmessage"),this.setElement(n),this.row=$("<tr></tr>")},addHeader:function(e){var t=$("<th></th>");t.append(e),this.row.append(t)},appendHeader:function(){this.$thead.append(this.row),this.row=$("<tr></tr>")},add:function(e,t,n){var r=$("<td></td>");t&&r.css("width",t),n&&r.css("text-align",n),r.append(e),this.row.append(r)},append:function(e){this._commit(e)},prepend:function(e){this._commit(e,!0)},get:function(e){return this.$el.find("#"+e)},del:function(e){var t=this.$tbody.find("#"+e);t.length>0&&(t.remove(),this.row_count--,this._refresh())},delAll:function(){this.$tbody.empty(),this.row_count=0,this._refresh()},value:function(e){this.before=this.$tbody.find(".current").attr("id"),e!==undefined&&(this.$tbody.find("tr").removeClass("current"),e&&this.$tbody.find("#"+e).addClass("current"));var t=this.$tbody.find(".current").attr("id");return t===undefined?null:(t!=this.before&&this.options.onchange&&this.options.onchange(e),t)},size:function(){return this.$tbody.find("tr").length},_commit:function(e,t){this.del(e),this.row.attr("id",e),t?this.$tbody.prepend(this.row):this.$tbody.append(this.row),this.row=$("<tr></tr>"),this.row_count++,this._refresh()},_onclick:function(e){var t=this.value(),n=$(e.target).closest("tr").attr("id");n!=""&&n&&t!=n&&(this.options.onconfirm?this.options.onconfirm(n):this.value(n))},_ondblclick:function(e){var t=this.value();t&&this.options.ondblclick&&this.options.ondblclick(t)},_refresh:function(){this.row_count==0?this.$tmessage.show():this.$tmessage.hide()},_template:function(e){return'<div><table class="ui-table '+e.cls+'">'+"<thead></thead>"+'<tbody style="cursor: pointer;"></tbody>'+"</table>"+"<tmessage>"+e.content+"</tmessage>"+"<div>"}});return{View:t}}),define("plugin/views/group",["plugin/library/ui-table","plugin/library/ui","utils/utils"],function(e,t,n){return Backbone.View.extend({initialize:function(r,i){this.app=r;var s=this;this.chart=this.app.chart,this.group=i.group,this.group_key=new t.Input({placeholder:"Data label",onchange:function(e){s.group.set("key",e)}}),this.table=new e.View({content:"No data column."});var o=$("<div/>");o.append(n.wrap((new t.Label({title:"Provide a label:"})).$el)),o.append(n.wrap(this.group_key.$el)),o.append(n.wrap((new t.Label({title:"Select columns:"})).$el)),o.append(n.wrap(this.table.$el)),this.setElement(o);var s=this;this.chart.on("change:dataset_id",function(){s._refreshTable()}),this.chart.on("change:type",function(){s._refreshTable()}),this.group.on("change:key",function(){s._refreshGroupKey()}),this.group.on("change",function(){s._refreshGroup()}),this._refreshTable(),this._refreshGroupKey(),this._refreshGroup()},_refreshTable:function(){var e=this.chart.get("dataset_id"),n=this.chart.get("type");if(!e||!n)return;var r=this,i=this.chart.definition;this.table.delAll();var s={};for(var o in i.columns){var u=i.columns[o];if(!u){console.debug("Group::_refreshTable() - Skipping column definition.");continue}var a=new t.Select.View({id:"select_"+o,wait:!0}),f=u.title;u.is_unique&&(f+=" (all data labels)"),this.table.add(f,"25%"),this.table.add(a.$el),this.table.append(o),s[o]=a}this.chart.state("wait","Loading metadata...");var l=this.chart.deferred.register(),c={id:e,success:function(e){for(var t in s)r._addRow(t,e,s,i.columns[t]);r.chart.state("ok","Metadata initialized..."),r.chart.deferred.done(l)}};this.app.datasets.request(c)},_addRow:function(e,t,n,r){var i=this,s=r.is_label,o=r.is_auto,u=r.is_numeric,a=r.is_unique,f=r.is_zero,l=[],c=n[e];o&&l.push({label:"Column: Row Number",value:"auto"}),f&&l.push({label:"Column: None",value:"zero"});var h=t.metadata_column_types;for(var p in h){var d=!1;h[p]=="int"||h[p]=="float"?d=u:d=s,d&&l.push({label:"Column: "+(parseInt(p)+1)+" ["+h[p]+"]",value:p})}c.update(l),a&&this.chart.groups.first()&&this.group.set(e,this.chart.groups.first().get(e));if(!c.exists(this.group.get(e))){var v=c.first();console.debug('Group()::_addRow() - Switching model value from "'+this.group.get(e)+'" to "'+v+'".'),this.group.set(e,v)}c.value(this.group.get(e)),this.group.off("change:"+e),this.group.on("change:"+e,function(){c.value(i.group.get(e))}),c.setOnChange(function(t){a?i.chart.groups.each(function(n){n.set(e,t)}):i.group.set(e,t),i.chart.set("modified",!0)}),c.show()},_refreshGroup:function(){this.group.set("date",n.time())},_refreshGroupKey:function(){var e=this.group.get("key");e===undefined&&(e=""),this.group_key.value(e)}})}),define("plugin/library/ui-table-form",["plugin/library/ui-table","plugin/library/ui","utils/utils"],function(e,t,n){var r=Backbone.View.extend({optionsDefault:{title:"",content:"",mode:""},list:[],initialize:function(r,i){this.app=r,this.options=n.merge(i,this.optionsDefault),this.table_title=new t.Label({title:this.options.title}),this.table=new e.View({content:this.options.content});var s=$('<div class="ui-table-form"/>');this.options.title&&s.append(n.wrap(this.table_title.$el)),s.append(n.wrap(this.table.$el)),this.setElement(s)},title:function(e){this.table_title.title(e)},update:function(e,t){this.table.delAll(),this.list=[];for(var n in e)this._add(e[n].id||n,e[n],t);for(var n in this.list)this.list[n].trigger("change")},_add:function(e,n,r){var i=this,s=null,o=n.type;switch(o){case"text":s=new t.Input({id:"field-"+e,placeholder:n.placeholder,value:r.get(e),onchange:function(t){r.set(e,t)}});break;case"radiobutton":s=new t.RadioButton({id:"field-"+e,data:n.data,value:r.get(e),onchange:function(t){r.set(e,t);var s=_.findWhere(n.data,{value:t});if(s&&s.operations){var o=s.operations;for(var u in o.show){var a=o.show[u];i.table.get(a).show()}for(var u in o.hide){var a=o.hide[u];i.table.get(a).hide()}}}});break;case"select":s=new t.Select.View({id:"field-"+e,data:n.data,value:r.get(e),onchange:function(t){r.set(e,t);var s=_.findWhere(n.data,{value:t});if(s&&s.operations){var o=s.operations;for(var u in o.show){var a=o.show[u];i.table.get(a).show()}for(var u in o.hide){var a=o.hide[u];i.table.get(a).hide()}}}});break;case"dataset":s=new t.Select.View({id:"field-"+e,onchange:function(t){r.set(e,t)}}),i.app.datasets.on("all",function(){var t=[];i.app.datasets.each(function(e){e.get("datatype_id")==n.data&&t.push({value:e.get("id"),label:e.get("name")})}),s.update(t),r.get(e)||r.set(e,s.first()),s.value(r.get(e))}),i.app.datasets.trigger("all.datasets");break;case"textarea":s=new t.Textarea({id:"field-"+e,onchange:function(){r.set(e,s.value())}});break;case"separator":s=$("<div/>");break;default:s=new t.Input({id:"field-"+e,placeholder:n.placeholder,type:n.type,onchange:function(){r.set(e,s.value())}})}if(o!="separator"){r.get(e)||r.set(e,n.init),s.value(r.get(e)),this.list[e]=s;var u=$("<div/>");u.append(s.$el),n.info&&u.append('<div class="ui-table-form-info">'+n.info+"</div>"),this.options.style=="bold"?(this.table.add((new t.Label({title:n.title,cls:"form-label"})).$el),this.table.add(u)):(this.table.add('<span class="ui-table-form-title">'+n.title+"</span>","25%"),this.table.add(u))}else this.table.add('<div class="ui-table-form-separator">'+n.title+":<div/>"),this.table.add($("<div/>"));this.table.append(e),n.hide&&this.table.get(e).hide()}});return{View:r}}),define("plugin/views/settings",["plugin/library/ui","plugin/library/ui-table-form","utils/utils"],function(e,t,n){return Backbone.View.extend({initialize:function(e,n){this.app=e;var r=this;this.chart=this.app.chart,this.form=new t.View(e,{content:"This chart type does not provide any options."}),this.setElement(this.form.$el);var r=this;this.chart.on("change",function(){r._refresh()})},_refresh:function(){var e=this.chart.definition;if(!e)return;this.form.title(e.category+" - "+e.title+":"),this.form.update(e.settings,this.chart.settings)}})}),define("plugin/views/types",["utils/utils","plugin/library/ui"],function(e,t){return Backbone.View.extend({optionsDefault:{onchange:null,ondblclick:null},events:{click:"_onclick",dblclick:"_ondblclick"},initialize:function(n,r){var i=this;this.app=n,this.options=e.merge(r,this.optionsDefault);var s=$('<div class="charts-grid"/>');s.append(e.wrap((new t.Label({title:"How many data points would you like to analyze?"})).$el)),this.library=new t.RadioButton({data:[{label:"Few (<500)",value:"small"},{label:"Some (<10k)",value:"medium"},{label:"Many (>10k)",value:"large"}],onchange:function(e){i._filter(e)}}),s.append(e.wrap(this.library.$el)),this.setElement(s),this._render(),this.library.value("small")},value:function(e){var t=this.$el.find(".current").attr("id");e!==undefined&&(this.$el.find(".current").removeClass("current"),this.$el.find("#"+e).addClass("current"));var n=this.$el.find(".current").attr("id");return n===undefined?null:(n!=t&&this.options.onchange&&this.options.onchange(e),n)},_filter:function(e){this.$el.find(".header").hide();var t=this.app.types.attributes;for(var n in t){var r=t[n],i=this.$el.find("#"+n),s=this.$el.find("#types-header-"+this.categories_index[r.category]),o=r.keywords||"";o.indexOf(e)>=0?(i.show(),s.show()):i.hide()}},_render:function(){this.categories={},this.categories_index={};var t=0,n=this.app.types.attributes;for(var r in n){var i=n[r],s=i.category;this.categories[s]||(this.categories[s]={},this.categories_index[s]=t++),this.categories[s][r]=i}for(var s in this.categories){var o=$('<div style="clear: both;"/>');o.append(e.wrap(this._template_header({id:"types-header-"+this.categories_index[s],title:s})));for(var r in this.categories[s]){var i=this.categories[s][r],u=i.title+" ("+i.library+")";i.zoomable&&(u='<span class="fa fa-search-plus"/>'+u),o.append(e.wrap(this._template_item({id:r,title:u,url:config.app_root+"charts/"+this.app.chartPath(r)+"/logo.png"})))}this.$el.append(e.wrap(o))}},_onclick:function(e){var t=this.value(),n=$(e.target).closest(".item").attr("id");n!=""&&n&&t!=n&&this.value(n)},_ondblclick:function(e){var t=this.value();t&&this.options.ondblclick&&this.options.ondblclick(t)},_template_header:function(e){return'<div id="'+e.id+'" class="header">'+"• "+e.title+"<div>"},_template_item:function(e){return'<div id="'+e.id+'" class="item">'+'<img class="image" src="'+e.url+'">'+'<div class="title">'+e.title+"</div>"+"<div>"}})}),define("plugin/views/editor",["mvc/ui/ui-tabs","plugin/library/ui","mvc/ui/ui-portlet","utils/utils","plugin/models/chart","plugin/models/group","plugin/views/group","plugin/views/settings","plugin/views/types"],function(e,t,n,r,i,s,o,u,a){return Backbone.View.extend({optionsDefault:{header:!0,content:"No content available."},initialize:function(i,s){var o=this;this.app=i,this.chart=this.app.chart,this.options=r.merge(s,this.optionsDefault),this.message=new t.Message,this.portlet=new n.View({icon:"fa-bar-chart-o",title:"Editor",operations:{save:new t.ButtonIcon({icon:"fa-save",tooltip:"Draw Chart",title:"Draw",onclick:function(){o._saveChart()}}),back:new t.ButtonIcon({icon:"fa-caret-left",tooltip:"Return to Viewer",title:"Cancel",onclick:function(){o.app.go("viewer"),o.app.storage.load()}})}}),this.types=new a(i,{onchange:function(e){var t=o.app.types.get(e);t||console.debug("FAILED - Editor::onchange() - Chart type not supported."),o.chart.definition=t,o.chart.settings.clear(),o.chart.set({type:e}),o.chart.set("modified",!0),console.debug("Editor::onchange() - Switched chart type.")},ondblclick:function(e){o._saveChart()}}),this.tabs=new e.View({title_new:"Add Data",onnew:function(){var e=o._addGroupModel();o.tabs.show(e.id)}}),this.title=new t.Input({placeholder:"Chart title",onchange:function(){o.chart.set("title",o.title.value())}});var f=$("<div/>");f.append(r.wrap((new t.Label({title:"Provide a chart title:"})).$el)),f.append(r.wrap(this.title.$el)),f.append(r.wrap(this.types.$el)),this.tabs.add({id:"main",title:"Start",$el:f}),this.settings=new u(this.app),this.tabs.add({id:"settings",title:"Configuration",$el:this.settings.$el}),this.portlet.append(this.message.$el),this.portlet.append(this.tabs.$el),this.setElement(this.portlet.$el),this.tabs.hideOperation("back");var o=this;this.chart.on("change:title",function(e){o._refreshTitle()}),this.chart.on("change:type",function(e){o.types.value(e.get("type"))}),this.chart.on("reset",function(e){o._resetChart()}),this.app.chart.on("redraw",function(e){o.portlet.showOperation("back")}),this.app.chart.groups.on("add",function(e){o._addGroup(e)}),this.app.chart.groups.on("remove",function(e){o._removeGroup(e)}),this.app.chart.groups.on("reset",function(e){o._removeAllGroups()}),this.app.chart.groups.on("change:key",function(e){o._refreshGroupKey()}),this._resetChart()},show:function(){this.$el.show()},hide:function(){this.$el.hide()},_refreshTitle:function(){var e=this.chart.get("title");this.portlet.title(e),this.title.value(e)},_refreshGroupKey:function(){var e=this,t=0;this.chart.groups.each(function(n){var r=n.get("key","");r==""&&(r="Data label"),e.tabs.title(n.id,++t+": "+r)})},_addGroupModel:function(){var e=new s({id:r.uuid()});return this.chart.groups.add(e),e},_addGroup:function(e){var t=this,n=new o(this.app,{group:e});this.tabs.add({id:e.id,$el:n.$el,ondel:function(){t.chart.groups.remove(e.id)}}),this._refreshGroupKey(),this.chart.set("modified",!0)},_removeGroup:function(e){this.tabs.del(e.id),this._refreshGroupKey(),this.chart.set("modified",!0)},_removeAllGroups:function(e){this.tabs.delRemovable()},_resetChart:function(){this.chart.set("id",r.uuid()),this.chart.set("type","nvd3_bar"),this.chart.set("dataset_id",this.app.options.config.dataset_id),this.chart.set("title","New Chart"),this.portlet.hideOperation("back")},_saveChart:function(){this.chart.set({type:this.types.value(),title:this.title.value(),date:r.time()});if(this.chart.groups.length==0){this.message.update({message:"Please select data columns before drawing the chart."});var e=this._addGroupModel();this.tabs.show(e.id);return}var t=this,n=!0,i=this.chart.definition;this.chart.groups.each(function(e){if(!n)return;for(var r in i.columns)if(e.attributes[r]=="null"){t.message.update({status:"danger",message:"This chart type requires column types not found in your tabular file."}),t.tabs.show(e.id),n=!1;return}});if(!n)return;this.app.go("viewer");var t=this;this.chart.deferred.execute(function(){t.app.storage.save(),t.chart.trigger("redraw")})}})}),define("plugin/models/config",[],function(){return Backbone.Model.extend({defaults:{query_limit:500,query_timeout:100}})}),define("plugin/charts/forms/default",[],function(){return{title:"",category:"",library:"",tag:"",keywords:"",query_limit:0,settings:{separator_x:{title:"X axis",type:"separator"},x_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"X-axis",placeholder:"Axis label"},x_axis_type:{title:"Axis value type",info:"Select the value type of the axis.",type:"select",init:"auto",data:[{label:"-- Do not show values --",value:"hide",operations:{hide:["x_axis_precision"]}},{label:"Auto",value:"auto",operations:{hide:["x_axis_precision"]}},{label:"Float",value:"f",operations:{show:["x_axis_precision"]}},{label:"Exponent",value:"e",operations:{show:["x_axis_precision"]}},{label:"Integer",value:"d",operations:{hide:["x_axis_precision"]}},{label:"Percentage",value:"p",operations:{show:["x_axis_precision"]}},{label:"SI-prefix",value:"s",operations:{hide:["x_axis_precision"]}}]},x_axis_precision:{title:"Axis tick format",info:"Select the tick format for the axis.",type:"select",init:"1",data:[{label:"0.00001",value:"5"},{label:"0.0001",value:"4"},{label:"0.001",value:"3"},{label:"0.01",value:"2"},{label:"0.1",value:"1"},{label:"1",value:"0"}]},separator_y:{title:"Y axis",type:"separator"},y_axis_label:{title:"Axis label",info:"Provide a label for the axis.",type:"text",init:"Y-axis",placeholder:"Axis label"},y_axis_type:{title:"Axis value type",info:"Select the value type of the axis.",type:"select",init:"auto",data:[{label:"-- Do not show values --",value:"hide",operations:{hide:["y_axis_precision"]}},{label:"Auto",value:"auto",operations:{hide:["y_axis_precision"]}},{label:"Float",value:"f",operations:{show:["y_axis_precision"]}},{label:"Exponent",value:"e",operations:{show:["y_axis_precision"]}},{label:"Integer",value:"d",operations:{hide:["y_axis_precision"]}},{label:"Percentage",value:"p",operations:{show:["y_axis_precision"]}},{label:"SI-prefix",value:"s",operations:{hide:["y_axis_precision"]}}]},y_axis_precision:{title:"Axis tick format",info:"Select the tick format for the axis.",type:"select",init:"1",data:[{label:"0.00001",value:"5"},{label:"0.0001",value:"4"},{label:"0.001",value:"3"},{label:"0.01",value:"2"},{label:"0.1",value:"1"},{label:"1",value:"0"}]},separator_legend:{title:"Others",type:"separator"},show_legend:{title:"Show legend",info:"Would you like to add a legend?",type:"radiobutton",init:"true",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]},use_panels:{title:"Use multi-panels",info:"Would you like to separate your data into individual panels?",type:"radiobutton",init:"false",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]}}}}),function(){function t(e,t){return(new Date(t,e+1,0)).getDate()}function n(e,t,n){return function(r,i,s){var o=e(r),u=[];o<r&&t(o);if(s>1)while(o<i){var a=new Date(+o);n(a)%s===0&&u.push(a),t(o)}else while(o<i)u.push(new Date(+o)),t(o);return u}}var e=window.nv||{};e.version="1.1.15b",e.dev=!0,window.nv=e,e.tooltip=e.tooltip||{},e.utils=e.utils||{},e.models=e.models||{},e.charts={},e.graphs=[],e.logs={},e.dispatch=d3.dispatch("render_start","render_end"),e.dev&&(e.dispatch.on("render_start",function(t){e.logs.startTime=+(new Date)}),e.dispatch.on("render_end",function(t){e.logs.endTime=+(new Date),e.logs.totalTime=e.logs.endTime-e.logs.startTime,e.log("total",e.logs.totalTime)})),e.log=function(){if(e.dev&&console.log&&console.log.apply)console.log.apply(console,arguments);else if(e.dev&&typeof console.log=="function"&&Function.prototype.bind){var t=Function.prototype.bind.call(console.log,console);t.apply(console,arguments)}return arguments[arguments.length-1]},e.render=function(n){n=n||1,e.render.active=!0,e.dispatch.render_start(),setTimeout(function(){var t,r;for(var i=0;i<n&&(r=e.render.queue[i]);i++)t=r.generate(),typeof r.callback==typeof Function&&r.callback(t),e.graphs.push(t);e.render.queue.splice(0,i),e.render.queue.length?setTimeout(arguments.callee,0):(e.dispatch.render_end(),e.render.active=!1)},0)},e.render.active=!1,e.render.queue=[],e.addGraph=function(t){typeof arguments[0]==typeof Function&&(t={generate:arguments[0],callback:arguments[1]}),e.render.queue.push(t),e.render.active||e.render()},e.identity=function(e){return e},e.strip=function(e){return e.replace(/(\s|&)/g,"")},d3.time.monthEnd=function(e){return new Date(e.getFullYear(),e.getMonth(),0)},d3.time.monthEnds=n(d3.time.monthEnd,function(e){e.setUTCDate(e.getUTCDate()+1),e.setDate(t(e.getMonth()+1,e.getFullYear()))},function(e){return e.getMonth()}),e.interactiveGuideline=function(){function c(o){o.each(function(o){function g(){var e=d3.mouse(this),n=e[0],r=e[1],o=!0,a=!1;l&&(n=d3.event.offsetX,r=d3.event.offsetY,d3.event.target.tagName!=="svg"&&(o=!1),d3.event.target.className.baseVal.match("nv-legend")&&(a=!0)),o&&(n-=i.left,r-=i.top);if(n<0||r<0||n>p||r>d||d3.event.relatedTarget&&d3.event.relatedTarget.ownerSVGElement===undefined||a){if(l&&d3.event.relatedTarget&&d3.event.relatedTarget.ownerSVGElement===undefined&&d3.event.relatedTarget.className.match(t.nvPointerEventsClass))return;u.elementMouseout({mouseX:n,mouseY:r}),c.renderGuideLine(null);return}var f=s.invert(n);u.elementMousemove({mouseX:n,mouseY:r,pointXValue:f}),d3.event.type==="dblclick"&&u.elementDblclick({mouseX:n,mouseY:r,pointXValue:f})}var h=d3.select(this),p=n||960,d=r||400,v=h.selectAll("g.nv-wrap.nv-interactiveLineLayer").data([o]),m=v.enter().append("g").attr("class"," nv-wrap nv-interactiveLineLayer");m.append("g").attr("class","nv-interactiveGuideLine");if(!f)return;f.on("mousemove",g,!0).on("mouseout",g,!0).on("dblclick",g),c.renderGuideLine=function(t){if(!a)return;var n=v.select(".nv-interactiveGuideLine").selectAll("line").data(t!=null?[e.utils.NaNtoZero(t)]:[],String);n.enter().append("line").attr("class","nv-guideline").attr("x1",function(e){return e}).attr("x2",function(e){return e}).attr("y1",d).attr("y2",0),n.exit().remove()}})}var t=e.models.tooltip(),n=null,r=null,i={left:0,top:0},s=d3.scale.linear(),o=d3.scale.linear(),u=d3.dispatch("elementMousemove","elementMouseout","elementDblclick"),a=!0,f=null,l=navigator.userAgent.indexOf("MSIE")!==-1;return c.dispatch=u,c.tooltip=t,c.margin=function(e){return arguments.length?(i.top=typeof e.top!="undefined"?e.top:i.top,i.left=typeof e.left!="undefined"?e.left:i.left,c):i},c.width=function(e){return arguments.length?(n=e,c):n},c.height=function(e){return arguments.length?(r=e,c):r},c.xScale=function(e){return arguments.length?(s=e,c):s},c.showGuideLine=function(e){return arguments.length?(a=e,c):a},c.svgContainer=function(e){return arguments.length?(f=e,c):f},c},e.interactiveBisect=function(e,t,n){if(!e instanceof Array)return null;typeof n!="function"&&(n=function(e,t){return e.x});var r=d3.bisector(n).left,i=d3.max([0,r(e,t)-1]),s=n(e[i],i);typeof s=="undefined"&&(s=i);if(s===t)return i;var o=d3.min([i+1,e.length-1]),u=n(e[o],o);return typeof u=="undefined"&&(u=o),Math.abs(u-t)>=Math.abs(s-t)?i:o},e.nearestValueIndex=function(e,t,n){var r=Infinity,i=null;return e.forEach(function(e,s){var o=Math.abs(t-e);o<=r&&o<n&&(r=o,i=s)}),i},function(){window.nv.tooltip={},window.nv.models.tooltip=function(){function y(){if(a){var e=d3.select(a);e.node().tagName!=="svg"&&(e=e.select("svg"));var t=e.node()?e.attr("viewBox"):null;if(t){t=t.split(" ");var n=parseInt(e.style("width"))/t[2];l.left=l.left*n,l.top=l.top*n}}}function b(e){var t;a?t=d3.select(a):t=d3.select("body");var n=t.select(".nvtooltip");return n.node()===null&&(n=t.append("div").attr("class","nvtooltip "+(u?u:"xy-tooltip")).attr("id",h)),n.node().innerHTML=e,n.style("top",0).style("left",0).style("opacity",0),n.selectAll("div, table, td, tr").classed(p,!0),n.classed(p,!0),n.node()}function w(){if(!c)return;if(!g(n))return;y();var t=l.left,u=o!=null?o:l.top,h=b(m(n));f=h;if(a){var p=a.getElementsByTagName("svg")[0],d=p?p.getBoundingClientRect():a.getBoundingClientRect(),v={left:0,top:0};if(p){var E=p.getBoundingClientRect(),S=a.getBoundingClientRect(),x=E.top;if(x<0){var T=a.getBoundingClientRect();x=Math.abs(x)>T.height?0:x}v.top=Math.abs(x-S.top),v.left=Math.abs(E.left-S.left)}t+=a.offsetLeft+v.left-2*a.scrollLeft,u+=a.offsetTop+v.top-2*a.scrollTop}return s&&s>0&&(u=Math.floor(u/s)*s),e.tooltip.calcTooltipPosition([t,u],r,i,h),w}var t=null,n=null,r="w",i=50,s=25,o=null,u=null,a=null,f=null,l={left:null,top:null},c=!0,h="nvtooltip-"+Math.floor(Math.random()*1e5),p="nv-pointer-events-none",d=function(e,t){return e},v=function(e){return e},m=function(e){if(t!=null)return t;if(e==null)return"";var n=d3.select(document.createElement("table")),r=n.selectAll("thead").data([e]).enter().append("thead");r.append("tr").append("td").attr("colspan",3).append("strong").classed("x-value",!0).html(v(e.value));var i=n.selectAll("tbody").data([e]).enter().append("tbody"),s=i.selectAll("tr").data(function(e){return e.series}).enter().append("tr").classed("highlight",function(e){return e.highlight});s.append("td").classed("legend-color-guide",!0).append("div").style("background-color",function(e){return e.color}),s.append("td").classed("key",!0).html(function(e){return e.key}),s.append("td").classed("value",!0).html(function(e,t){return d(e.value,t)}),s.selectAll("td").each(function(e){if(e.highlight){var t=d3.scale.linear().domain([0,1]).range(["#fff",e.color]),n=.6;d3.select(this).style("border-bottom-color",t(n)).style("border-top-color",t(n))}});var o=n.node().outerHTML;return e.footer!==undefined&&(o+="<div class='footer'>"+e.footer+"</div>"),o},g=function(e){return e&&e.series&&e.series.length>0?!0:!1};return w.nvPointerEventsClass=p,w.content=function(e){return arguments.length?(t=e,w):t},w.tooltipElem=function(){return f},w.contentGenerator=function(e){return arguments.length?(typeof e=="function"&&(m=e),w):m},w.data=function(e){return arguments.length?(n=e,w):n},w.gravity=function(e){return arguments.length?(r=e,w):r},w.distance=function(e){return arguments.length?(i=e,w):i},w.snapDistance=function(e){return arguments.length?(s=e,w):s},w.classes=function(e){return arguments.length?(u=e,w):u},w.chartContainer=function(e){return arguments.length?(a=e,w):a},w.position=function(e){return arguments.length?(l.left=typeof e.left!="undefined"?e.left:l.left,l.top=typeof e.top!="undefined"?e.top:l.top,w):l},w.fixedTop=function(e){return arguments.length?(o=e,w):o},w.enabled=function(e){return arguments.length?(c=e,w):c},w.valueFormatter=function(e){return arguments.length?(typeof e=="function"&&(d=e),w):d},w.headerFormatter=function(e){return arguments.length?(typeof e=="function"&&(v=e),w):v},w.id=function(){return h},w},e.tooltip.show=function(t,n,r,i,s,o){var u=document.createElement("div");u.className="nvtooltip "+(o?o:"xy-tooltip");var a=s;if(!s||s.tagName.match(/g|svg/i))a=document.getElementsByTagName("body")[0];u.style.left=0,u.style.top=0,u.style.opacity=0,u.innerHTML=n,a.appendChild(u),s&&(t[0]=t[0]-s.scrollLeft,t[1]=t[1]-s.scrollTop),e.tooltip.calcTooltipPosition(t,r,i,u)},e.tooltip.findFirstNonSVGParent=function(e){while(e.tagName.match(/^g|svg$/i)!==null)e=e.parentNode;return e},e.tooltip.findTotalOffsetTop=function(e,t){var n=t;do isNaN(e.offsetTop)||(n+=e.offsetTop);while(e=e.offsetParent);return n},e.tooltip.findTotalOffsetLeft=function(e,t){var n=t;do isNaN(e.offsetLeft)||(n+=e.offsetLeft);while(e=e.offsetParent);return n},e.tooltip.calcTooltipPosition=function(t,n,r,i){var s=parseInt(i.offsetHeight),o=parseInt(i.offsetWidth),u=e.utils.windowSize().width,a=e.utils.windowSize().height,f=window.pageYOffset,l=window.pageXOffset,c,h;a=window.innerWidth>=document.body.scrollWidth?a:a-16,u=window.innerHeight>=document.body.scrollHeight?u:u-16,n=n||"s",r=r||20;var p=function(t){return e.tooltip.findTotalOffsetTop(t,h)},d=function(t){return e.tooltip.findTotalOffsetLeft(t,c)};switch(n){case"e":c=t[0]-o-r,h=t[1]-s/2;var v=d(i),m=p(i);v<l&&(c=t[0]+r>l?t[0]+r:l-v+c),m<f&&(h=f-m+h),m+s>f+a&&(h=f+a-m+h-s);break;case"w":c=t[0]+r,h=t[1]-s/2;var v=d(i),m=p(i);v+o>u&&(c=t[0]-o-r),m<f&&(h=f+5),m+s>f+a&&(h=f+a-m+h-s);break;case"n":c=t[0]-o/2-5,h=t[1]+r;var v=d(i),m=p(i);v<l&&(c=l+5),v+o>u&&(c=c-o/2+5),m+s>f+a&&(h=f+a-m+h-s);break;case"s":c=t[0]-o/2,h=t[1]-s-r;var v=d(i),m=p(i);v<l&&(c=l+5),v+o>u&&(c=c-o/2+5),f>m&&(h=f);break;case"none":c=t[0],h=t[1]-r;var v=d(i),m=p(i)}return i.style.left=c+"px",i.style.top=h+"px",i.style.opacity=1,i.style.position="absolute",i},e.tooltip.cleanup=function(){var e=document.getElementsByClassName("nvtooltip"),t=[];while(e.length)t.push(e[0]),e[0].style.transitionDelay="0 !important",e[0].style.opacity=0,e[0].className="nvtooltip-pending-removal";setTimeout(function(){while(t.length){var e=t.pop();e.parentNode.removeChild(e)}},500)}}(),e.utils.windowSize=function(){var e={width:640,height:480};return document.body&&document.body.offsetWidth&&(e.width=document.body.offsetWidth,e.height=document.body.offsetHeight),document.compatMode=="CSS1Compat"&&document.documentElement&&document.documentElement.offsetWidth&&(e.width=document.documentElement.offsetWidth,e.height=document.documentElement.offsetHeight),window.innerWidth&&window.innerHeight&&(e.width=window.innerWidth,e.height=window.innerHeight),e},e.utils.windowResize=function(e){if(e===undefined)return;var t=window.onresize;window.onresize=function(n){typeof t=="function"&&t(n),e(n)}},e.utils.getColor=function(t){return arguments.length?Object.prototype.toString.call(t)==="[object Array]"?function(e,n){return e.color||t[n%t.length]}:t:e.utils.defaultColor()},e.utils.defaultColor=function(){var e=d3.scale.category20().range();return function(t,n){return t.color||e[n%e.length]}},e.utils.customTheme=function(e,t,n){t=t||function(e){return e.key},n=n||d3.scale.category20().range();var r=n.length;return function(i,s){var o=t(i);return r||(r=n.length),typeof e[o]!="undefined"?typeof e[o]=="function"?e[o]():e[o]:n[--r]}},e.utils.pjax=function(t,n){function r(r){d3.html(r,function(r){var i=d3.select(n).node();i.parentNode.replaceChild(d3.select(r).select(n).node(),i),e.utils.pjax(t,n)})}d3.selectAll(t).on("click",function(){history.pushState(this.href,this.textContent,this.href),r(this.href),d3.event.preventDefault()}),d3.select(window).on("popstate",function(){d3.event.state&&r(d3.event.state)})},e.utils.calcApproxTextWidth=function(e){if(typeof e.style=="function"&&typeof e.text=="function"){var t=parseInt(e.style("font-size").replace("px","")),n=e.text().length;return n*t*.5}return 0},e.utils.NaNtoZero=function(e){return typeof e!="number"||isNaN(e)||e===null||e===Infinity?0:e},e.utils.optionsFunc=function(e){return e&&d3.map(e).forEach(function(e,t){typeof this[e]=="function"&&this[e](t)}.bind(this)),this},e.models.axis=function(){function m(e){return e.each(function(e){var i=d3.select(this),m=i.selectAll("g.nv-wrap.nv-axis").data([e]),g=m.enter().append("g").attr("class","nvd3 nv-wrap nv-axis"),y=g.append("g"),b=m.select("g");p!==null?t.ticks(p):(t.orient()=="top"||t.orient()=="bottom")&&t.ticks(Math.abs(s.range()[1]-s.range()[0])/100),b.call(t),v=v||t.scale();var w=t.tickFormat();w==null&&(w=v.tickFormat());var E=b.selectAll("text.nv-axislabel").data([o||null]);E.exit().remove();switch(t.orient()){case"top":E.enter().append("text").attr("class","nv-axislabel");var S=s.range().length==2?s.range()[1]:s.range()[s.range().length-1]+(s.range()[1]-s.range()[0]);E.attr("text-anchor","middle").attr("y",0).attr("x",S/2);if(u){var x=m.selectAll("g.nv-axisMaxMin").data(s.domain());x.enter().append("g").attr("class","nv-axisMaxMin").append("text"),x.exit().remove(),x.attr("transform",function(e,t){return"translate("+s(e)+",0)"}).select("text").attr("dy","-0.5em").attr("y",-t.tickPadding()).attr("text-anchor","middle").text(function(e,t){var n=w(e);return(""+n).match("NaN")?"":n}),x.attr("transform",function(e,t){return"translate("+s.range()[t]+",0)"})}break;case"bottom":var T=36,N=30,C=b.selectAll("g").select("text");if(f%360){C.each(function(e,t){var n=this.getBBox().width;n>N&&(N=n)});var k=Math.abs(Math.sin(f*Math.PI/180)),T=(k?k*N:N)+30;C.attr("transform",function(e,t,n){return"rotate("+f+" 0,0)"}).style("text-anchor",f%360>0?"start":"end")}E.enter().append("text").attr("class","nv-axislabel");var S=s.range().length==2?s.range()[1]:s.range()[s.range().length-1]+(s.range()[1]-s.range()[0]);E.attr("text-anchor","middle").attr("y",T).attr("x",S/2);if(u){var x=m.selectAll("g.nv-axisMaxMin").data([s.domain()[0],s.domain()[s.domain().length-1]]);x.enter().append("g").attr("class","nv-axisMaxMin").append("text"),x.exit().remove(),x.attr("transform",function(e,t){return"translate("+(s(e)+(h?s.rangeBand()/2:0))+",0)"}).select("text").attr("dy",".71em").attr("y",t.tickPadding()).attr("transform",function(e,t,n){return"rotate("+f+" 0,0)"}).style("text-anchor",f?f%360>0?"start":"end":"middle").text(function(e,t){var n=w(e);return(""+n).match("NaN")?"":n}),x.attr("transform",function(e,t){return"translate("+(s(e)+(h?s.rangeBand()/2:0))+",0)"})}c&&C.attr("transform",function(e,t){return"translate(0,"+(t%2==0?"0":"12")+")"});break;case"right":E.enter().append("text").attr("class","nv-axislabel"),E.style("text-anchor",l?"middle":"begin").attr("transform",l?"rotate(90)":"").attr("y",l?-Math.max(n.right,r)+12:-10).attr("x",l?s.range()[0]/2:t.tickPadding());if(u){var x=m.selectAll("g.nv-axisMaxMin").data(s.domain());x.enter().append("g").attr("class","nv-axisMaxMin").append("text").style("opacity",0),x.exit().remove(),x.attr("transform",function(e,t){return"translate(0,"+s(e)+")"}).select("text").attr("dy",".32em").attr("y",0).attr("x",t.tickPadding()).style("text-anchor","start").text(function(e,t){var n=w(e);return(""+n).match("NaN")?"":n}),x.attr("transform",function(e,t){return"translate(0,"+s.range()[t]+")"}).select("text").style("opacity",1)}break;case"left":E.enter().append("text").attr("class","nv-axislabel"),E.style("text-anchor",l?"middle":"end").attr("transform",l?"rotate(-90)":"").attr("y",l?-Math.max(n.left,r)+d:-10).attr("x",l?-s.range()[0]/2:-t.tickPadding());if(u){var x=m.selectAll("g.nv-axisMaxMin").data(s.domain());x.enter().append("g").attr("class","nv-axisMaxMin").append("text").style("opacity",0),x.exit().remove(),x.attr("transform",function(e,t){return"translate(0,"+v(e)+")"}).select("text").attr("dy",".32em").attr("y",0).attr("x",-t.tickPadding()).attr("text-anchor","end").text(function(e,t){var n=w(e);return(""+n).match("NaN")?"":n}),x.attr("transform",function(e,t){return"translate(0,"+s.range()[t]+")"}).select("text").style("opacity",1)}}E.text(function(e){return e}),u&&(t.orient()==="left"||t.orient()==="right")&&(b.selectAll("g").each(function(e,t){d3.select(this).select("text").attr("opacity",1);if(s(e)<s.range()[1]+10||s(e)>s.range()[0]-10)(e>1e-10||e<-1e-10)&&d3.select(this).attr("opacity",0),d3.select(this).select("text").attr("opacity",0)}),s.domain()[0]==s.domain()[1]&&s.domain()[0]==0&&m.selectAll("g.nv-axisMaxMin").style("opacity",function(e,t){return t?0:1}));if(u&&(t.orient()==="top"||t.orient()==="bottom")){var L=[];m.selectAll("g.nv-axisMaxMin").each(function(e,t){try{t?L.push(s(e)-this.getBBox().width-4):L.push(s(e)+this.getBBox().width+4)}catch(n){t?L.push(s(e)-4):L.push(s(e)+4)}}),b.selectAll("g").each(function(e,t){if(s(e)<L[0]||s(e)>L[1])e>1e-10||e<-1e-10?d3.select(this).remove():d3.select(this).select("text").remove()})}a&&b.selectAll(".tick").filter(function(e){return!parseFloat(Math.round(e.__data__*1e5)/1e6)&&e.__data__!==undefined}).classed("zero",!0),v=s.copy()}),m}var t=d3.svg.axis(),n={top:0,right:0,bottom:0,left:0},r=75,i=60,s=d3.scale.linear(),o=null,u=!0,a=!0,f=0,l=!0,c=!1,h=!1,p=null,d=12;t.scale(s).orient("bottom").tickFormat(function(e){return e});var v;return m.axis=t,d3.rebind(m,t,"orient","tickValues","tickSubdivide","tickSize","tickPadding","tickFormat"),d3.rebind(m,s,"domain","range","rangeBand","rangeBands"),m.options=e.utils.optionsFunc.bind(m),m.margin=function(e){return arguments.length?(n.top=typeof e.top!="undefined"?e.top:n.top,n.right=typeof e.right!="undefined"?e.right:n.right,n.bottom=typeof e.bottom!="undefined"?e.bottom:n.bottom,n.left=typeof e.left!="undefined"?e.left:n.left,m):n},m.width=function(e){return arguments.length?(r=e,m):r},m.ticks=function(e){return arguments.length?(p=e,m):p},m.height=function(e){return arguments.length?(i=e,m):i},m.axisLabel=function(e){return arguments.length?(o=e,m):o},m.showMaxMin=function(e){return arguments.length?(u=e,m):u},m.highlightZero=function(e){return arguments.length?(a=e,m):a},m.scale=function(e){return arguments.length?(s=e,t.scale(s),h=typeof s.rangeBands=="function",d3.rebind(m,s,"domain","range","rangeBand","rangeBands"),m):s},m.rotateYLabel=function(e){return arguments.length?(l=e,m):l},m.rotateLabels=function(e){return arguments.length?(f=e,m):f},m.staggerLabels=function(e){return arguments.length?(c=e,m):c},m.axisLabelDistance=function(e){return arguments.length?(d=e,m):d},m},e.models.historicalBar=function(){function w(E){return E.each(function(w){var E=n-t.left-t.right,S=r-t.top-t.bottom,T=d3.select(this);s.domain(d||d3.extent(w[0].values.map(u).concat(f))),c?s.range(m||[E*.5/w[0].values.length,E*(w[0].values.length-.5)/w[0].values.length]):s.range(m||[0,E]),o.domain(v||d3.extent(w[0].values.map(a).concat(l))).range(g||[S,0]),s.domain()[0]===s.domain()[1]&&(s.domain()[0]?s.domain([s.domain()[0]-s.domain()[0]*.01,s.domain()[1]+s.domain()[1]*.01]):s.domain([-1,1])),o.domain()[0]===o.domain()[1]&&(o.domain()[0]?o.domain([o.domain()[0]+o.domain()[0]*.01,o.domain()[1]-o.domain()[1]*.01]):o.domain([-1,1]));var N=T.selectAll("g.nv-wrap.nv-historicalBar-"+i).data([w[0].values]),C=N.enter().append("g").attr("class","nvd3 nv-wrap nv-historicalBar-"+i),k=C.append("defs"),L=C.append("g"),A=N.select("g");L.append("g").attr("class","nv-bars"),N.attr("transform","translate("+t.left+","+t.top+")"),T.on("click",function(e,t){y.chartClick({data:e,index:t,pos:d3.event,id:i})}),k.append("clipPath").attr("id","nv-chart-clip-path-"+i).append("rect"),N.select("#nv-chart-clip-path-"+i+" rect").attr("width",E).attr("height",S),A.attr("clip-path",h?"url(#nv-chart-clip-path-"+i+")":"");var O=N.select(".nv-bars").selectAll(".nv-bar").data(function(e){return e},function(e,t){return u(e,t)});O.exit().remove();var M=O.enter().append("rect").attr("x",0).attr("y",function(t,n){return e.utils.NaNtoZero(o(Math.max(0,a(t,n))))}).attr("height",function(t,n){return e.utils.NaNtoZero(Math.abs(o(a(t,n))-o(0)))}).attr("transform",function(e,t){return"translate("+(s(u(e,t))-E/w[0].values.length*.45)+",0)"}).on("mouseover",function(e,t){if(!b)return;d3.select(this).classed("hover",!0),y.elementMouseover({point:e,series:w[0],pos:[s(u(e,t)),o(a(e,t))],pointIndex:t,seriesIndex:0,e:d3.event})}).on("mouseout",function(e,t){if(!b)return;d3.select(this).classed("hover",!1),y.elementMouseout({point:e,series:w[0],pointIndex:t,seriesIndex:0,e:d3.event})}).on("click",function(e,t){if(!b)return;y.elementClick({value:a(e,t),data:e,index:t,pos:[s(u(e,t)),o(a(e,t))],e:d3.event,id:i}),d3.event.stopPropagation()}).on("dblclick",function(e,t){if(!b)return;y.elementDblClick({value:a(e,t),data:e,index:t,pos:[s(u(e,t)),o(a(e,t))],e:d3.event,id:i}),d3.event.stopPropagation()});O.attr("fill",function(e,t){return p(e,t)}).attr("class",function(e,t,n){return(a(e,t)<0?"nv-bar negative":"nv-bar positive")+" nv-bar-"+n+"-"+t}).attr("transform",function(e,t){return"translate("+(s(u(e,t))-E/w[0].values.length*.45)+",0)"}).attr("width",E/w[0].values.length*.9),O.attr("y",function(t,n){var r=a(t,n)<0?o(0):o(0)-o(a(t,n))<1?o(0)-1:o(a(t,n));return e.utils.NaNtoZero(r)}).attr("height",function(t,n){return e.utils.NaNtoZero(Math.max(Math.abs(o(a(t,n))-o(0)),1))})}),w}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=Math.floor(Math.random()*1e4),s=d3.scale.linear(),o=d3.scale.linear(),u=function(e){return e.x},a=function(e){return e.y},f=[],l=[0],c=!1,h=!0,p=e.utils.defaultColor(),d,v,m,g,y=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),b=!0;return w.highlightPoint=function(e,t){d3.select(".nv-historicalBar-"+i).select(".nv-bars .nv-bar-0-"+e).classed("hover",t)},w.clearHighlights=function(){d3.select(".nv-historicalBar-"+i).select(".nv-bars .nv-bar.hover").classed("hover",!1)},w.dispatch=y,w.options=e.utils.optionsFunc.bind(w),w.x=function(e){return arguments.length?(u=e,w):u},w.y=function(e){return arguments.length?(a=e,w):a},w.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,w):t},w.width=function(e){return arguments.length?(n=e,w):n},w.height=function(e){return arguments.length?(r=e,w):r},w.xScale=function(e){return arguments.length?(s=e,w):s},w.yScale=function(e){return arguments.length?(o=e,w):o},w.xDomain=function(e){return arguments.length?(d=e,w):d},w.yDomain=function(e){return arguments.length?(v=e,w):v},w.xRange=function(e){return arguments.length?(m=e,w):m},w.yRange=function(e){return arguments.length?(g=e,w):g},w.forceX=function(e){return arguments.length?(f=e,w):f},w.forceY=function(e){return arguments.length?(l=e,w):l},w.padData=function(e){return arguments.length?(c=e,w):c},w.clipEdge=function(e){return arguments.length?(h=e,w):h},w.color=function(t){return arguments.length?(p=e.utils.getColor(t),w):p},w.id=function(e){return arguments.length?(i=e,w):i},w.interactive=function(e){return arguments.length?(b=!1,w):b},w},e.models.bullet=function(){function m(e){return e.each(function(e,n){var p=c-t.left-t.right,m=h-t.top-t.bottom,g=d3.select(this),y=i.call(this,e,n).slice().sort(d3.descending),b=s.call(this,e,n).slice().sort(d3.descending),w=o.call(this,e,n).slice().sort(d3.descending),E=u.call(this,e,n).slice(),S=a.call(this,e,n).slice(),x=f.call(this,e,n).slice(),T=d3.scale.linear().domain(d3.extent(d3.merge([l,y]))).range(r?[p,0]:[0,p]),N=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(T.range());this.__chart__=T;var C=d3.min(y),k=d3.max(y),L=y[1],A=g.selectAll("g.nv-wrap.nv-bullet").data([e]),O=A.enter().append("g").attr("class","nvd3 nv-wrap nv-bullet"),M=O.append("g"),_=A.select("g");M.append("rect").attr("class","nv-range nv-rangeMax"),M.append("rect").attr("class","nv-range nv-rangeAvg"),M.append("rect").attr("class","nv-range nv-rangeMin"),M.append("rect").attr("class","nv-measure"),M.append("path").attr("class","nv-markerTriangle"),A.attr("transform","translate("+t.left+","+t.top+")");var D=function(e){return Math.abs(N(e)-N(0))},P=function(e){return Math.abs(T(e)-T(0))},H=function(e){return e<0?N(e):N(0)},B=function(e){return e<0?T(e):T(0)};_.select("rect.nv-rangeMax").attr("height",m).attr("width",P(k>0?k:C)).attr("x",B(k>0?k:C)).datum(k>0?k:C),_.select("rect.nv-rangeAvg").attr("height",m).attr("width",P(L)).attr("x",B(L)).datum(L),_.select("rect.nv-rangeMin").attr("height",m).attr("width",P(k)).attr("x",B(k)).attr("width",P(k>0?C:k)).attr("x",B(k>0?C:k)).datum(k>0?C:k),_.select("rect.nv-measure").style("fill",d).attr("height",m/3).attr("y",m/3).attr("width",w<0?T(0)-T(w[0]):T(w[0])-T(0)).attr("x",B(w)).on("mouseover",function(){v.elementMouseover({value:w[0],label:x[0]||"Current",pos:[T(w[0]),m/2]})}).on("mouseout",function(){v.elementMouseout({value:w[0],label:x[0]||"Current"})});var j=m/6;b[0]?_.selectAll("path.nv-markerTriangle").attr("transform",function(e){return"translate("+T(b[0])+","+m/2+")"}).attr("d","M0,"+j+"L"+j+","+ -j+" "+ -j+","+ -j+"Z").on("mouseover",function(){v.elementMouseover({value:b[0],label:S[0]||"Previous",pos:[T(b[0]),m/2]})}).on("mouseout",function(){v.elementMouseout({value:b[0],label:S[0]||"Previous"})}):_.selectAll("path.nv-markerTriangle").remove(),A.selectAll(".nv-range").on("mouseover",function(e,t){var n=E[t]||(t?t==1?"Mean":"Minimum":"Maximum");v.elementMouseover({value:e,label:n,pos:[T(e),m/2]})}).on("mouseout",function(e,t){var n=E[t]||(t?t==1?"Mean":"Minimum":"Maximum");v.elementMouseout({value:e,label:n})})}),m}var t={top:0,right:0,bottom:0,left:0},n="left",r=!1,i=function(e){return e.ranges},s=function(e){return e.markers},o=function(e){return e.measures},u=function(e){return e.rangeLabels?e.rangeLabels:[]},a=function(e){return e.markerLabels?e.markerLabels:[]},f=function(e){return e.measureLabels?e.measureLabels:[]},l=[0],c=380,h=30,p=null,d=e.utils.getColor(["#1f77b4"]),v=d3.dispatch("elementMouseover","elementMouseout");return m.dispatch=v,m.options=e.utils.optionsFunc.bind(m),m.orient=function(e){return arguments.length?(n=e,r=n=="right"||n=="bottom",m):n},m.ranges=function(e){return arguments.length?(i=e,m):i},m.markers=function(e){return arguments.length?(s=e,m):s},m.measures=function(e){return arguments.length?(o=e,m):o},m.forceX=function(e){return arguments.length?(l=e,m):l},m.width=function(e){return arguments.length?(c=e,m):c},m.height=function(e){return arguments.length?(h=e,m):h},m.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,m):t},m.tickFormat=function(e){return arguments.length?(p=e,m):p},m.color=function(t){return arguments.length?(d=e.utils.getColor(t),m):d},m},e.models.bulletChart=function(){function m(e){return e.each(function(n,h){var g=d3.select(this),y=(a||parseInt(g.style("width"))||960)-i.left-i.right,b=f-i.top-i.bottom,w=this;m.update=function(){m(e)},m.container=this;if(!n||!s.call(this,n,h)){var E=g.selectAll(".nv-noData").data([p]);return E.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),E.attr("x",i.left+y/2).attr("y",18+i.top+b/2).text(function(e){return e}),m}g.selectAll(".nv-noData").remove();var S=s.call(this,n,h).slice().sort(d3.descending),x=o.call(this,n,h).slice().sort(d3.descending),T=u.call(this,n,h).slice().sort(d3.descending),N=g.selectAll("g.nv-wrap.nv-bulletChart").data([n]),C=N.enter().append("g").attr("class","nvd3 nv-wrap nv-bulletChart"),k=C.append("g"),L=N.select("g");k.append("g").attr("class","nv-bulletWrap"),k.append("g").attr("class","nv-titles"),N.attr("transform","translate("+i.left+","+i.top+")");var A=d3.scale.linear().domain([0,Math.max(S[0],x[0],T[0])]).range(r?[y,0]:[0,y]),O=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(A.range());this.__chart__=A;var M=function(e){return Math.abs(O(e)-O(0))},_=function(e){return Math.abs(A(e)-A(0))},D=k.select(".nv-titles").append("g").attr("text-anchor","end").attr("transform","translate(-6,"+(f-i.top-i.bottom)/2+")");D.append("text").attr("class","nv-title").text(function(e){return e.title}),D.append("text").attr("class","nv-subtitle").attr("dy","1em").text(function(e){return e.subtitle}),t.width(y).height(b);var P=L.select(".nv-bulletWrap");d3.transition(P).call(t);var H=l||A.tickFormat(y/100),B=L.selectAll("g.nv-tick").data(A.ticks(y/50),function(e){return this.textContent||H(e)}),j=B.enter().append("g").attr("class","nv-tick").attr("transform",function(e){return"translate("+O(e)+",0)"}).style("opacity",1e-6);j.append("line").attr("y1",b).attr("y2",b*7/6),j.append("text").attr("text-anchor","middle").attr("dy","1em").attr("y",b*7/6).text(H);var F=d3.transition(B).attr("transform",function(e){return"translate("+A(e)+",0)"}).style("opacity",1);F.select("line").attr("y1",b).attr("y2",b*7/6),F.select("text").attr("y",b*7/6),d3.transition(B.exit()).attr("transform",function(e){return"translate("+A(e)+",0)"}).style("opacity",1e-6).remove(),d.on("tooltipShow",function(e){e.key=n.title,c&&v(e,w.parentNode)})}),d3.timer.flush(),m}var t=e.models.bullet(),n="left",r=!1,i={top:5,right:40,bottom:20,left:120},s=function(e){return e.ranges},o=function(e){return e.markers},u=function(e){return e.measures},a=null,f=55,l=null,c=!0,h=function(e,t,n,r,i){return"<h3>"+t+"</h3>"+"<p>"+n+"</p>"},p="No Data Available.",d=d3.dispatch("tooltipShow","tooltipHide"),v=function(t,n){var r=t.pos[0]+(n.offsetLeft||0)+i.left,s=t.pos[1]+(n.offsetTop||0)+i.top,o=h(t.key,t.label,t.value,t,m);e.tooltip.show([r,s],o,t.value<0?"e":"w",null,n)};return t.dispatch.on("elementMouseover.tooltip",function(e){d.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){d.tooltipHide(e)}),d.on("tooltipHide",function(){c&&e.tooltip.cleanup()}),m.dispatch=d,m.bullet=t,d3.rebind(m,t,"color"),m.options=e.utils.optionsFunc.bind(m),m.orient=function(e){return arguments.length?(n=e,r=n=="right"||n=="bottom",m):n},m.ranges=function(e){return arguments.length?(s=e,m):s},m.markers=function(e){return arguments.length?(o=e,m):o},m.measures=function(e){return arguments.length?(u=e,m):u},m.width=function(e){return arguments.length?(a=e,m):a},m.height=function(e){return arguments.length?(f=e,m):f},m.margin=function(e){return arguments.length?(i.top=typeof e.top!="undefined"?e.top:i.top,i.right=typeof e.right!="undefined"?e.right:i.right,i.bottom=typeof e.bottom!="undefined"?e.bottom:i.bottom,i.left=typeof e.left!="undefined"?e.left:i.left,m):i},m.tickFormat=function(e){return arguments.length?(l=e,m):l},m.tooltips=function(e){return arguments.length?(c=e,m):c},m.tooltipContent=function(e){return arguments.length?(h=e,m):h},m.noData=function(e){return arguments.length?(p=e,m):p},m},e.models.cumulativeLineChart=function(){function D(b){return b.each(function(b){function I(e,t){d3.select(D.container).style("cursor","ew-resize")}function q(e,t){M.x=d3.event.x,M.i=Math.round(O.invert(M.x)),nt()}function R(e,t){d3.select(D.container).style("cursor","auto"),x.index=M.i,k.stateChange(x)}function nt(){tt.data([M]);var e=D.transitionDuration();D.transitionDuration(0),D.update(),D.transitionDuration(e)}var L=d3.select(this).classed("nv-chart-"+S,!0),A=this,H=(f||parseInt(L.style("width"))||960)-u.left-u.right,B=(l||parseInt(L.style("height"))||400)-u.top-u.bottom;D.update=function(){L.call(D)},D.container=this,x.disabled=b.map(function(e){return!!e.disabled});if(!T){var j;T={};for(j in x)x[j]instanceof Array?T[j]=x[j].slice(0):T[j]=x[j]}var F=d3.behavior.drag().on("dragstart",I).on("drag",q).on("dragend",R);if(!b||!b.length||!b.filter(function(e){return e.values.length}).length){var U=L.selectAll(".nv-noData").data([N]);return U.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),U.attr("x",u.left+H/2).attr("y",u.top+B/2).text(function(e){return e}),D}L.selectAll(".nv-noData").remove(),w=t.xScale(),E=t.yScale();if(!y){var z=b.filter(function(e){return!e.disabled}).map(function(e,n){var r=d3.extent(e.values,t.y());return r[0]<-0.95&&(r[0]=-0.95),[(r[0]-r[1])/(1+r[1]),(r[1]-r[0])/(1+r[0])]}),W=[d3.min(z,function(e){return e[0]}),d3.max(z,function(e){return e[1]})];t.yDomain(W)}else t.yDomain(null);O.domain([0,b[0].values.length-1]).range([0,H]).clamp(!0);var b=P(M.i,b),X=g?"none":"all",V=L.selectAll("g.nv-wrap.nv-cumulativeLine").data([b]),$=V.enter().append("g").attr("class","nvd3 nv-wrap nv-cumulativeLine").append("g"),J=V.select("g");$.append("g").attr("class","nv-interactive"),$.append("g").attr("class","nv-x nv-axis").style("pointer-events","none"),$.append("g").attr("class","nv-y nv-axis"),$.append("g").attr("class","nv-background"),$.append("g").attr("class","nv-linesWrap").style("pointer-events",X),$.append("g").attr("class","nv-avgLinesWrap").style("pointer-events","none"),$.append("g").attr("class","nv-legendWrap"),$.append("g").attr("class","nv-controlsWrap"),c&&(i.width(H),J.select(".nv-legendWrap").datum(b).call(i),u.top!=i.height()&&(u.top=i.height(),B=(l||parseInt(L.style("height"))||400)-u.top-u.bottom),J.select(".nv-legendWrap").attr("transform","translate(0,"+ -u.top+")"));if(m){var K=[{key:"Re-scale y-axis",disabled:!y}];s.width(140).color(["#444","#444","#444"]).rightAlign(!1).margin({top:5,right:0,bottom:5,left:20}),J.select(".nv-controlsWrap").datum(K).attr("transform","translate(0,"+ -u.top+")").call(s)}V.attr("transform","translate("+u.left+","+u.top+")"),d&&J.select(".nv-y.nv-axis").attr("transform","translate("+H+",0)");var Q=b.filter(function(e){return e.tempDisabled});V.select(".tempDisabled").remove(),Q.length&&V.append("text").attr("class","tempDisabled").attr("x",H/2).attr("y","-.71em").style("text-anchor","end").text(Q.map(function(e){return e.key}).join(", ")+" values cannot be calculated for this time period."),g&&(o.width(H).height(B).margin({left:u.left,top:u.top}).svgContainer(L).xScale(w),V.select(".nv-interactive").call(o)),$.select(".nv-background").append("rect"),J.select(".nv-background rect").attr("width",H).attr("height",B),t.y(function(e){return e.display.y}).width(H).height(B).color(b.map(function(e,t){return e.color||a(e,t)}).filter(function(e,t){return!b[t].disabled&&!b[t].tempDisabled}));var G=J.select(".nv-linesWrap").datum(b.filter(function(e){return!e.disabled&&!e.tempDisabled}));G.call(t),b.forEach(function(e,t){e.seriesIndex=t});var Y=b.filter(function(e){return!e.disabled&&!!C(e)}),Z=J.select(".nv-avgLinesWrap").selectAll("line").data(Y,function(e){return e.key}),et=function(e){var t=E(C(e));return t<0?0:t>B?B:t};Z.enter().append("line").style("stroke-width",2).style("stroke-dasharray","10,10").style("stroke",function(e,n){return t.color()(e,e.seriesIndex)}).attr("x1",0).attr("x2",H).attr("y1",et).attr("y2",et),Z.style("stroke-opacity",function(e){var t=E(C(e));return t<0||t>B?0:1}).attr("x1",0).attr("x2",H).attr("y1",et).attr("y2",et),Z.exit().remove();var tt=G.selectAll(".nv-indexLine").data([M]);tt.enter().append("rect").attr("class","nv-indexLine").attr("width",3).attr("x",-2).attr("fill","red").attr("fill-opacity",.5).style("pointer-events","all").call(F),tt.attr("transform",function(e){return"translate("+O(e.i)+",0)"}).attr("height",B),h&&(n.scale(w).ticks(Math.min(b[0].values.length,H/70)).tickSize(-B,0),J.select(".nv-x.nv-axis").attr("transform","translate(0,"+E.range()[0]+")"),d3.transition(J.select(".nv-x.nv-axis")).call(n)),p&&(r.scale(E).ticks(B/36).tickSize(-H,0),d3.transition(J.select(".nv-y.nv-axis")).call(r)),J.select(".nv-background rect").on("click",function(){M.x=d3.mouse(this)[0],M.i=Math.round(O.invert(M.x)),x.index=M.i,k.stateChange(x),nt()}),t.dispatch.on("elementClick",function(e){M.i=e.pointIndex,M.x=O(M.i),x.index=M.i,k.stateChange(x),nt()}),s.dispatch.on("legendClick",function(e,t){e.disabled=!e.disabled,y=!e.disabled,x.rescaleY=y,k.stateChange(x),D.update()}),i.dispatch.on("stateChange",function(e){x.disabled=e.disabled,k.stateChange(x),D.update()}),o.dispatch.on("elementMousemove",function(i){t.clearHighlights();var s,f,l,c=[];b.filter(function(e,t){return e.seriesIndex=t,!e.disabled}).forEach(function(n,r){f=e.interactiveBisect(n.values,i.pointXValue,D.x()),t.highlightPoint(r,f,!0);var o=n.values[f];if(typeof o=="undefined")return;typeof s=="undefined"&&(s=o),typeof l=="undefined"&&(l=D.xScale()(D.x()(o,f))),c.push({key:n.key,value:D.y()(o,f),color:a(n,n.seriesIndex)})});if(c.length>2){var h=D.yScale().invert(i.mouseY),p=Math.abs(D.yScale().domain()[0]-D.yScale().domain()[1]),d=.03*p,m=e.nearestValueIndex(c.map(function(e){return e.value}),h,d);m!==null&&(c[m].highlight=!0)}var g=n.tickFormat()(D.x()(s,f),f);o.tooltip.position({left:l+u.left,top:i.mouseY+u.top}).chartContainer(A.parentNode).enabled(v).valueFormatter(function(e,t){return r.tickFormat()(e)}).data({value:g,series:c})(),o.renderGuideLine(l)}),o.dispatch.on("elementMouseout",function(e){k.tooltipHide(),t.clearHighlights()}),k.on("tooltipShow",function(e){v&&_(e,A.parentNode)}),k.on("changeState",function(e){typeof e.disabled!="undefined"&&(b.forEach(function(t,n){t.disabled=e.disabled[n]}),x.disabled=e.disabled),typeof e.index!="undefined"&&(M.i=e.index,M.x=O(M.i),x.index=e.index,tt.data([M])),typeof e.rescaleY!="undefined"&&(y=e.rescaleY),D.update()})}),D}function P(e,n){return n.map(function(n,r){if(!n.values)return n;var i=n.values[e];if(i==null)return n;var s=t.y()(i,e);return s<-0.95&&!A?(n.tempDisabled=!0,n):(n.tempDisabled=!1,n.values=n.values.map(function(e,n){return e.display={y:(t.y()(e,n)-s)/(1+s)},e}),n)})}var t=e.models.line(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.models.legend(),o=e.interactiveGuideline(),u={top:30,right:30,bottom:50,left:60},a=e.utils.defaultColor(),f=null,l=null,c=!0,h=!0,p=!0,d=!1,v=!0,m=!0,g=!1,y=!0,b=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},w,E,S=t.id(),x={index:0,rescaleY:y},T=null,N="No Data Available.",C=function(e){return e.average},k=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),L=0,A=!1;n.orient("bottom").tickPadding(7),r.orient(d?"right":"left"),s.updateState(!1);var O=d3.scale.linear(),M={i:0,x:0},_=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=b(i.series.key,a,f,i,D);e.tooltip.show([o,u],l,null,null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+u.left,e.pos[1]+u.top],k.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){k.tooltipHide(e)}),k.on("tooltipHide",function(){v&&e.tooltip.cleanup()}),D.dispatch=k,D.lines=t,D.legend=i,D.xAxis=n,D.yAxis=r,D.interactiveLayer=o,d3.rebind(D,t,"defined","isArea","x","y","xScale","yScale","size","xDomain","yDomain","xRange","yRange","forceX","forceY","interactive","clipEdge","clipVoronoi","useVoronoi","id"),D.options=e.utils.optionsFunc.bind(D),D.margin=function(e){return arguments.length?(u.top=typeof e.top!="undefined"?e.top:u.top,u.right=typeof e.right!="undefined"?e.right:u.right,u.bottom=typeof e.bottom!="undefined"?e.bottom:u.bottom,u.left=typeof e.left!="undefined"?e.left:u.left,D):u},D.width=function(e){return arguments.length?(f=e,D):f},D.height=function(e){return arguments.length?(l=e,D):l},D.color=function(t){return arguments.length?(a=e.utils.getColor(t),i.color(a),D):a},D.rescaleY=function(e){return arguments.length?(y=e,D):y},D.showControls=function(e){return arguments.length?(m=e,D):m},D.useInteractiveGuideline=function(e){return arguments.length?(g=e,e===!0&&(D.interactive(!1),D.useVoronoi(!1)),D):g},D.showLegend=function(e){return arguments.length?(c=e,D):c},D.showXAxis=function(e){return arguments.length?(h=e,D):h},D.showYAxis=function(e){return arguments.length?(p=e,D):p},D.rightAlignYAxis=function(e){return arguments.length?(d=e,r.orient(e?"right":"left"),D):d},D.tooltips=function(e){return arguments.length?(v=e,D):v},D.tooltipContent=function(e){return arguments.length?(b=e,D):b},D.state=function(e){return arguments.length?(x=e,D):x},D.defaultState=function(e){return arguments.length?(T=e,D):T},D.noData=function(e){return arguments.length?(N=e,D):N},D.average=function(e){return arguments.length?(C=e,D):C},D.transitionDuration=function(e){return arguments.length?(L=e,D):L},D.noErrorCheck=function(e){return arguments.length?(A=e,D):A},D},e.models.discreteBar=function(){function E(e){return e.each(function(e){var i=n-t.left-t.right,E=r-t.top-t.bottom,S=d3.select(this);e.forEach(function(e,t){e.values.forEach(function(e){e.series=t})});var T=p&&d?[]:e.map(function(e){return e.values.map(function(e,t){return{x:u(e,t),y:a(e,t),y0:e.y0}})});s.domain(p||d3.merge(T).map(function(e){return e.x})).rangeBands(v||[0,i],.1),o.domain(d||d3.extent(d3.merge(T).map(function(e){return e.y}).concat(f))),c?o.range(m||[E-(o.domain()[0]<0?12:0),o.domain()[1]>0?12:0]):o.range(m||[E,0]),b=b||s,w=w||o.copy().range([o(0),o(0)]);var N=S.selectAll("g.nv-wrap.nv-discretebar").data([e]),C=N.enter().append("g").attr("class","nvd3 nv-wrap nv-discretebar"),k=C.append("g"),L=N.select("g");k.append("g").attr("class","nv-groups"),N.attr("transform","translate("+t.left+","+t.top+")");var A=N.select(".nv-groups").selectAll(".nv-group").data(function(e){return e},function(e){return e.key});A.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),A.exit().style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),A.attr("class",function(e,t){return"nv-group nv-series-"+t}).classed("hover",function(e){return e.hover}),A.style("stroke-opacity",1).style("fill-opacity",.75);var O=A.selectAll("g.nv-bar").data(function(e){return e.values});O.exit().remove();var M=O.enter().append("g").attr("transform",function(e,t,n){return"translate("+(s(u(e,t))+s.rangeBand()*.05)+", "+o(0)+")"}).on("mouseover",function(t,n){d3.select(this).classed("hover",!0),g.elementMouseover({value:a(t,n),point:t,series:e[t.series],pos:[s(u(t,n))+s.rangeBand()*(t.series+.5)/e.length,o(a(t,n))],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("mouseout",function(t,n){d3.select(this).classed("hover",!1),g.elementMouseout({value:a(t,n),point:t,series:e[t.series],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("click",function(t,n){g.elementClick({value:a(t,n),point:t,series:e[t.series],pos:[s(u(t,n))+s.rangeBand()*(t.series+.5)/e.length,o(a(t,n))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(t,n){g.elementDblClick({value:a(t,n),point:t,series:e[t.series],pos:[s(u(t,n))+s.rangeBand()*(t.series+.5)/e.length,o(a(t,n))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()});M.append("rect").attr("height",0).attr("width",s.rangeBand()*.9/e.length),c?(M.append("text").attr("text-anchor","middle"),O.select("text").text(function(e,t){return h(a(e,t))}).attr("x",s.rangeBand()*.9/2).attr("y",function(e,t){return a(e,t)<0?o(a(e,t))-o(0)+12:-4})):O.selectAll("text").remove(),O.attr("class",function(e,t){return a(e,t)<0?"nv-bar negative":"nv-bar positive"}).style("fill",function(e,t){return e.color||l(e,t)}).style("stroke",function(e,t){return e.color||l(e,t)}).select("rect").attr("class",y).attr("width",s.rangeBand()*.9/e.length),O.attr("transform",function(e,t){var n=s(u(e,t))+s.rangeBand()*.05,r=a(e,t)<0?o(0):o(0)-o(a(e,t))<1?o(0)-1:o(a(e,t));return"translate("+n+", "+r+")"}).select("rect").attr("height",function(e,t){return Math.max(Math.abs(o(a(e,t))-o(d&&d[0]||0))||1)}),b=s.copy(),w=o.copy()}),E}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=Math.floor(Math.random()*1e4),s=d3.scale.ordinal(),o=d3.scale.linear(),u=function(e){return e.x},a=function(e){return e.y},f=[0],l=e.utils.defaultColor(),c=!1,h=d3.format(",.2f"),p,d,v,m,g=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),y="discreteBar",b,w;return E.dispatch=g,E.options=e.utils.optionsFunc.bind(E),E.x=function(e){return arguments.length?(u=e,E):u},E.y=function(e){return arguments.length?(a=e,E):a},E.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,E):t},E.width=function(e){return arguments.length?(n=e,E):n},E.height=function(e){return arguments.length?(r=e,E):r},E.xScale=function(e){return arguments.length?(s=e,E):s},E.yScale=function(e){return arguments.length?(o=e,E):o},E.xDomain=function(e){return arguments.length?(p=e,E):p},E.yDomain=function(e){return arguments.length?(d=e,E):d},E.xRange=function(e){return arguments.length?(v=e,E):v},E.yRange=function(e){return arguments.length?(m=e,E):m},E.forceY=function(e){return arguments.length?(f=e,E):f},E.color=function(t){return arguments.length?(l=e.utils.getColor(t),E):l},E.id=function(e){return arguments.length?(i=e,E):i},E.showValues=function(e){return arguments.length?(c=e,E):c},E.valueFormat=function(e){return arguments.length?(h=e,E):h},E.rectClass=function(e){return arguments.length?(y=e,E):y},E},e.models.discreteBarChart=function(){function w(e){return e.each(function(e){var u=d3.select(this),p=this,y=(s||parseInt(u.style("width"))||960)-i.left-i.right,E=(o||parseInt(u.style("height"))||400)-i.top-i.bottom;w.update=function(){g.beforeUpdate(),u.call(w)},w.container=this;if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var S=u.selectAll(".nv-noData").data([m]);return S.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),S.attr("x",i.left+y/2).attr("y",i.top+E/2).text(function(e){return e}),w}u.selectAll(".nv-noData").remove(),d=t.xScale(),v=t.yScale().clamp(!0);var T=u.selectAll("g.nv-wrap.nv-discreteBarWithAxes").data([e]),N=T.enter().append("g").attr("class","nvd3 nv-wrap nv-discreteBarWithAxes").append("g"),C=N.append("defs"),k=T.select("g");N.append("g").attr("class","nv-x nv-axis"),N.append("g").attr("class","nv-y nv-axis").append("g").attr("class","nv-zeroLine").append("line"),N.append("g").attr("class","nv-barsWrap"),k.attr("transform","translate("+i.left+","+i.top+")"),l&&k.select(".nv-y.nv-axis").attr("transform","translate("+y+",0)"),t.width(y).height(E);var L=k.select(".nv-barsWrap").datum(e.filter(function(e){return!e.disabled}));L.call(t),C.append("clipPath").attr("id","nv-x-label-clip-"+t.id()).append("rect"),k.select("#nv-x-label-clip-"+t.id()+" rect").attr("width",d.rangeBand()*(c?2:1)).attr("height",16).attr("x",-d.rangeBand()/(c?1:2));if(a){n.scale(d).ticks(y/100).tickSize(-E,0),k.select(".nv-x.nv-axis").attr("transform","translate(0,"+(v.range()[0]+(t.showValues()&&v.domain()[0]<0?16:0))+")"),k.select(".nv-x.nv-axis").call(n);var A=k.select(".nv-x.nv-axis").selectAll("g");c&&A.selectAll("text").attr("transform",function(e,t,n){return"translate(0,"+(n%2==0?"5":"17")+")"})}f&&(r.scale(v).ticks(E/36).tickSize(-y,0),k.select(".nv-y.nv-axis").call(r)),k.select(".nv-zeroLine line").attr("x1",0).attr("x2",y).attr("y1",v(0)).attr("y2",v(0)),g.on("tooltipShow",function(e){h&&b(e,p.parentNode)})}),w}var t=e.models.discreteBar(),n=e.models.axis(),r=e.models.axis(),i={top:15,right:10,bottom:50,left:60},s=null,o=null,u=e.utils.getColor(),a=!0,f=!0,l=!1,c=!1,h=!0,p=function(e,t,n,r,i){return"<h3>"+t+"</h3>"+"<p>"+n+"</p>"},d,v,m="No Data Available.",g=d3.dispatch("tooltipShow","tooltipHide","beforeUpdate"),y=0;n.orient("bottom").highlightZero(!1).showMaxMin(!1).tickFormat(function(e){return e}),r.orient(l?"right":"left").tickFormat(d3.format(",.1f"));var b=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=p(i.series.key,a,f,i,w);e.tooltip.show([o,u],l,i.value<0?"n":"s",null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+i.left,e.pos[1]+i.top],g.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){g.tooltipHide(e)}),g.on("tooltipHide",function(){h&&e.tooltip.cleanup()}),w.dispatch=g,w.discretebar=t,w.xAxis=n,w.yAxis=r,d3.rebind(w,t,"x","y","xDomain","yDomain","xRange","yRange","forceX","forceY","id","showValues","valueFormat"),w.options=e.utils.optionsFunc.bind(w),w.margin=function(e){return arguments.length?(i.top=typeof e.top!="undefined"?e.top:i.top,i.right=typeof e.right!="undefined"?e.right:i.right,i.bottom=typeof e.bottom!="undefined"?e.bottom:i.bottom,i.left=typeof e.left!="undefined"?e.left:i.left,w):i},w.width=function(e){return arguments.length?(s=e,w):s},w.height=function(e){return arguments.length?(o=e,w):o},w.color=function(n){return arguments.length?(u=e.utils.getColor(n),t.color(u),w):u},w.showXAxis=function(e){return arguments.length?(a=e,w):a},w.showYAxis=function(e){return arguments.length?(f=e,w):f},w.rightAlignYAxis=function(e){return arguments.length?(l=e,r.orient(e?"right":"left"),w):l},w.staggerLabels=function(e){return arguments.length?(c=e,w):c},w.tooltips=function(e){return arguments.length?(h=e,w):h},w.tooltipContent=function(e){return arguments.length?(p=e,w):p},w.noData=function(e){return arguments.length?(m=e,w):m},w.transitionDuration=function(e){return arguments.length?(y=e,w):y},w},e.models.distribution=function(){function l(e){return e.each(function(e){var a=n-(i==="x"?t.left+t.right:t.top+t.bottom),l=i=="x"?"y":"x",c=d3.select(this);f=f||u;var h=c.selectAll("g.nv-distribution").data([e]),p=h.enter().append("g").attr("class","nvd3 nv-distribution"),d=p.append("g"),v=h.select("g");h.attr("transform","translate("+t.left+","+t.top+")");var m=v.selectAll("g.nv-dist").data(function(e){return e},function(e){return e.key});m.enter().append("g"),m.attr("class",function(e,t){return"nv-dist nv-series-"+t}).style("stroke",function(e,t){return o(e,t)});var g=m.selectAll("line.nv-dist"+i).data(function(e){return e.values});g.enter().append("line").attr(i+"1",function(e,t){return f(s(e,t))}).attr(i+"2",function(e,t){return f(s(e,t))}),m.exit().selectAll("line.nv-dist"+i).attr(i+"1",function(e,t){return u(s(e,t))}).attr(i+"2",function(e,t){return u(s(e,t))}).style("stroke-opacity",0).remove(),g.attr("class",function(e,t){return"nv-dist"+i+" nv-dist"+i+"-"+t}).attr(l+"1",0).attr(l+"2",r),g.attr(i+"1",function(e,t){return u(s(e,t))}).attr(i+"2",function(e,t){return u(s(e,t))}),f=u.copy()}),l}var t={top:0,right:0,bottom:0,left:0},n=400,r=8,i="x",s=function(e){return e[i]},o=e.utils.defaultColor(),u=d3.scale.linear(),a,f;return l.options=e.utils.optionsFunc.bind(l),l.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,l):t},l.width=function(e){return arguments.length?(n=e,l):n},l.axis=function(e){return arguments.length?(i=e,l):i},l.size=function(e){return arguments.length?(r=e,l):r},l.getData=function(e){return arguments.length?(s=d3.functor(e),l):s},l.scale=function(e){return arguments.length?(u=e,l):u},l.color=function(t){return arguments.length?(o=e.utils.getColor(t),l):o},l},e.models.historicalBarChart=function(){function x(e){return e.each(function(d){var E=d3.select(this),T=this,N=(u||parseInt(E.style("width"))||960)-s.left-s.right,C=(a||parseInt(E.style("height"))||400)-s.top-s.bottom;x.update=function(){E.call(x)},x.container=this,g.disabled=d.map(function(e){return!!e.disabled});if(!y){var k;y={};for(k in g)g[k]instanceof Array?y[k]=g[k].slice(0):y[k]=g[k]}if(!d||!d.length||!d.filter(function(e){return e.values.length}).length){var L=E.selectAll(".nv-noData").data([b]);return L.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),L.attr("x",s.left+N/2).attr("y",s.top+C/2).text(function(e){return e}),x}E.selectAll(".nv-noData").remove(),v=t.xScale(),m=t.yScale();var A=E.selectAll("g.nv-wrap.nv-historicalBarChart").data([d]),O=A.enter().append("g").attr("class","nvd3 nv-wrap nv-historicalBarChart").append("g"),M=A.select("g");O.append("g").attr("class","nv-x nv-axis"),O.append("g").attr("class","nv-y nv-axis"),O.append("g").attr("class","nv-barsWrap"),O.append("g").attr("class","nv-legendWrap"),f&&(i.width(N),M.select(".nv-legendWrap").datum(d).call(i),s.top!=i.height()&&(s.top=i.height(),C=(a||parseInt(E.style("height"))||400)-s.top-s.bottom),A.select(".nv-legendWrap").attr("transform","translate(0,"+ -s.top+")")),A.attr("transform","translate("+s.left+","+s.top+")"),h&&M.select(".nv-y.nv-axis").attr("transform","translate("+N+",0)"),t.width(N).height(C).color(d.map(function(e,t){return e.color||o(e,t)}).filter(function(e,t){return!d[t].disabled}));var _=M.select(".nv-barsWrap").datum(d.filter(function(e){return!e.disabled}));_.call(t),l&&(n.scale(v).tickSize(-C,0),M.select(".nv-x.nv-axis").attr("transform","translate(0,"+m.range()[0]+")"),M.select(".nv-x.nv-axis").call(n)),c&&(r.scale(m).ticks(C/36).tickSize(-N,0),M.select(".nv-y.nv-axis").call(r)),i.dispatch.on("legendClick",function(t,n){t.disabled=!t.disabled,d.filter(function(e){return!e.disabled}).length||d.map(function(e){return e.disabled=!1,A.selectAll(".nv-series").classed("disabled",!1),e}),g.disabled=d.map(function(e){return!!e.disabled}),w.stateChange(g),e.call(x)}),i.dispatch.on("legendDblclick",function(e){d.forEach(function(e){e.disabled=!0}),e.disabled=!1,g.disabled=d.map(function(e){return!!e.disabled}),w.stateChange(g),x.update()}),w.on("tooltipShow",function(e){p&&S(e,T.parentNode)}),w.on("changeState",function(e){typeof e.disabled!="undefined"&&(d.forEach(function(t,n){t.disabled=e.disabled[n]}),g.disabled=e.disabled),x.update()})}),x}var t=e.models.historicalBar(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s={top:30,right:90,bottom:50,left:90},o=e.utils.defaultColor(),u=null,a=null,f=!1,l=!0,c=!0,h=!1,p=!0,d=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},v,m,g={},y=null,b="No Data Available.",w=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),E=0;n.orient("bottom").tickPadding(7),r.orient(h?"right":"left");var S=function(i,s){if(s){var o=d3.select(s).select("svg"),u=o.node()?o.attr("viewBox"):null;if(u){u=u.split(" ");var a=parseInt(o.style("width"))/u[2];i.pos[0]=i.pos[0]*a,i.pos[1]=i.pos[1]*a}}var f=i.pos[0]+(s.offsetLeft||0),l=i.pos[1]+(s.offsetTop||0),c=n.tickFormat()(t.x()(i.point,i.pointIndex)),h=r.tickFormat()(t.y()(i.point,i.pointIndex)),p=d(i.series.key,c,h,i,x);e.tooltip.show([f,l],p,null,null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+s.left,e.pos[1]+s.top],w.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){w.tooltipHide(e)}),w.on("tooltipHide",function(){p&&e.tooltip.cleanup()}),x.dispatch=w,x.bars=t,x.legend=i,x.xAxis=n,x.yAxis=r,d3.rebind(x,t,"defined","isArea","x","y","size","xScale","yScale","xDomain","yDomain","xRange","yRange","forceX","forceY","interactive","clipEdge","clipVoronoi","id","interpolate","highlightPoint","clearHighlights","interactive"),x.options=e.utils.optionsFunc.bind(x),x.margin=function(e){return arguments.length?(s.top=typeof e.top!="undefined"?e.top:s.top,s.right=typeof e.right!="undefined"?e.right:s.right,s.bottom=typeof e.bottom!="undefined"?e.bottom:s.bottom,s.left=typeof e.left!="undefined"?e.left:s.left,x):s},x.width=function(e){return arguments.length?(u=e,x):u},x.height=function(e){return arguments.length?(a=e,x):a},x.color=function(t){return arguments.length?(o=e.utils.getColor(t),i.color(o),x):o},x.showLegend=function(e){return arguments.length?(f=e,x):f},x.showXAxis=function(e){return arguments.length?(l=e,x):l},x.showYAxis=function(e){return arguments.length?(c=e,x):c},x.rightAlignYAxis=function(e){return arguments.length?(h=e,r.orient(e?"right":"left"),x):h},x.tooltips=function(e){return arguments.length?(p=e,x):p},x.tooltipContent=function(e){return arguments.length?(d=e,x):d},x.state=function(e){return arguments.length?(g=e,x):g},x.defaultState=function(e){return arguments.length?(y=e,x):y},x.noData=function(e){return arguments.length?(b=e,x):b},x.transitionDuration=function(e){return arguments.length?(E=e,x):E},x},e.models.indentedTree=function(){function g(e){return e.each(function(e){function k(e,t,n){d3.event.stopPropagation();if(d3.event.shiftKey&&!n)return d3.event.shiftKey=!1,e.values&&e.values.forEach(function(e){(e.values||e._values)&&k(e,0,!0)}),!0;if(!O(e))return!0;e.values?(e._values=e.values,e.values=null):(e.values=e._values,e._values=null),g.update()}function L(e){return e._values&&e._values.length?h:e.values&&e.values.length?p:""}function A(e){return e._values&&e._values.length}function O(e){var t=e.values||e._values;return t&&t.length}var t=1,n=d3.select(this),i=d3.layout.tree().children(function(e){return e.values}).size([r,f]);g.update=function(){n.call(g)},e[0]||(e[0]={key:a});var s=i.nodes(e[0]),y=d3.select(this).selectAll("div").data([[s]]),b=y.enter().append("div").attr("class","nvd3 nv-wrap nv-indentedtree"),w=b.append("table"),E=y.select("table").attr("width","100%").attr("class",c);if(o){var S=w.append("thead"),x=S.append("tr");l.forEach(function(e){x.append("th").attr("width",e.width?e.width:"10%").style("text-align",e.type=="numeric"?"right":"left").append("span").text(e.label)})}var T=E.selectAll("tbody").data(function(e){return e});T.enter().append("tbody"),t=d3.max(s,function(e){return e.depth}),i.size([r,t*f]);var N=T.selectAll("tr").data(function(e){return e.filter(function(e){return u&&!e.children?u(e):!0})},function(e,t){return e.id||e.id||++m});N.exit().remove(),N.select("img.nv-treeicon").attr("src",L).classed("folded",A);var C=N.enter().append("tr");l.forEach(function(e,t){var n=C.append("td").style("padding-left",function(e){return(t?0:e.depth*f+12+(L(e)?0:16))+"px"},"important").style("text-align",e.type=="numeric"?"right":"left");t==0&&n.append("img").classed("nv-treeicon",!0).classed("nv-folded",A).attr("src",L).style("width","14px").style("height","14px").style("padding","0 1px").style("display",function(e){return L(e)?"inline-block":"none"}).on("click",k),n.each(function(n){!t&&v(n)?d3.select(this).append("a").attr("href",v).attr("class",d3.functor(e.classes)).append("span"):d3.select(this).append("span"),d3.select(this).select("span").attr("class",d3.functor(e.classes)).text(function(t){return e.format?t[e.key]?e.format(t[e.key]):"-":t[e.key]||"-"})}),e.showCount&&(n.append("span").attr("class","nv-childrenCount"),N.selectAll("span.nv-childrenCount").text(function(e){return e.values&&e.values.length||e._values&&e._values.length?"("+(e.values&&e.values.filter(function(e){return u?u(e):!0}).length||e._values&&e._values.filter(function(e){return u?u(e):!0}).length||0)+")":""}))}),N.order().on("click",function(e){d.elementClick({row:this,data:e,pos:[e.x,e.y]})}).on("dblclick",function(e){d.elementDblclick({row:this,data:e,pos:[e.x,e.y]})}).on("mouseover",function(e){d.elementMouseover({row:this,data:e,pos:[e.x,e.y]})}).on("mouseout",function(e){d.elementMouseout({row:this,data:e,pos:[e.x,e.y]})})}),g}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=e.utils.defaultColor(),s=Math.floor(Math.random()*1e4),o=!0,u=!1,a="No Data Available.",f=20,l=[{key:"key",label:"Name",type:"text"}],c=null,h="images/grey-plus.png",p="images/grey-minus.png",d=d3.dispatch("elementClick","elementDblclick","elementMouseover","elementMouseout"),v=function(e){return e.url},m=0;return g.options=e.utils.optionsFunc.bind(g),g.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,g):t},g.width=function(e){return arguments.length?(n=e,g):n},g.height=function(e){return arguments.length?(r=e,g):r},g.color=function(t){return arguments.length?(i=e.utils.getColor(t),scatter.color(i),g):i},g.id=function(e){return arguments.length?(s=e,g):s},g.header=function(e){return arguments.length?(o=e,g):o},g.noData=function(e){return arguments.length?(a=e,g):a},g.filterZero=function(e){return arguments.length?(u=e,g):u},g.columns=function(e){return arguments.length?(l=e,g):l},g.tableClass=function(e){return arguments.length?(c=e,g):c},g.iconOpen=function(e){return arguments.length?(h=e,g):h},g.iconClose=function(e){return arguments.length?(p=e,g):p},g.getUrl=function(e){return arguments.length?(v=e,g):v},g},e.models.legend=function(){function c(h){return h.each(function(c){var h=n-t.left-t.right,p=d3.select(this),d=p.selectAll("g.nv-legend").data([c]),v=d.enter().append("g").attr("class","nvd3 nv-legend").append("g"),m=d.select("g");d.attr("transform","translate("+t.left+","+t.top+")");var g=m.selectAll(".nv-series").data(function(e){return e}),y=g.enter().append("g").attr("class","nv-series").on("mouseover",function(e,t){l.legendMouseover(e,t)}).on("mouseout",function(e,t){l.legendMouseout(e,t)}).on("click",function(e,t){l.legendClick(e,t),a&&(f?(c.forEach(function(e){e.disabled=!0}),e.disabled=!1):(e.disabled=!e.disabled,c.every(function(e){return e.disabled})&&c.forEach(function(e){e.disabled=!1})),l.stateChange({disabled:c.map(function(e){return!!e.disabled})}))}).on("dblclick",function(e,t){l.legendDblclick(e,t),a&&(c.forEach(function(e){e.disabled=!0}),e.disabled=!1,l.stateChange({disabled:c.map(function(e){return!!e.disabled})}))});y.append("circle").style("stroke-width",2).attr("class","nv-legend-symbol").attr("r",5),y.append("text").attr("text-anchor","start").attr("class","nv-legend-text").attr("dy",".32em").attr("dx","8"),g.classed("disabled",function(e){return e.disabled}),g.exit().remove(),g.select("circle").style("fill",function(e,t){return e.color||s(e,t)}).style("stroke",function(e,t){return e.color||s(e,t)}),g.select("text").text(i);if(o){var b=[];g.each(function(t,n){var r=d3.select(this).select("text"),i;try{i=r.getComputedTextLength();if(i<=0)throw Error()}catch(s){i=e.utils.calcApproxTextWidth(r)}b.push(i+28)});var w=0,E=0,S=[];while(E<h&&w<b.length)S[w]=b[w],E+=b[w++];w===0&&(w=1);while(E>h&&w>1){S=[],w--;for(var x=0;x<b.length;x++)b[x]>(S[x%w]||0)&&(S[x%w]=b[x]);E=S.reduce(function(e,t,n,r){return e+t})}var T=[];for(var N=0,C=0;N<w;N++)T[N]=C,C+=S[N];g.attr("transform",function(e,t){return"translate("+T[t%w]+","+(5+Math.floor(t/w)*20)+")"}),u?m.attr("transform","translate("+(n-t.right-E)+","+t.top+")"):m.attr("transform","translate(0,"+t.top+")"),r=t.top+t.bottom+Math.ceil(b.length/w)*20}else{var k=5,L=5,A=0,O;g.attr("transform",function(e,r){var i=d3.select(this).select("text").node().getComputedTextLength()+28;return O=L,n<t.left+t.right+O+i&&(L=O=5,k+=20),L+=i,L>A&&(A=L),"translate("+O+","+k+")"}),m.attr("transform","translate("+(n-t.right-A)+","+t.top+")"),r=t.top+t.bottom+k+15}}),c}var t={top:5,right:0,bottom:5,left:0},n=400,r=20,i=function(e){return e.key},s=e.utils.defaultColor(),o=!0,u=!0,a=!0,f=!1,l=d3.dispatch("legendClick","legendDblclick","legendMouseover","legendMouseout","stateChange");return c.dispatch=l,c.options=e.utils.optionsFunc.bind(c),c.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,c):t},c.width=function(e){return arguments.length?(n=e,c):n},c.height=function(e){return arguments.length?(r=e,c):r},c.key=function(e){return arguments.length?(i=e,c):i},c.color=function(t){return arguments.length?(s=e.utils.getColor(t),c):s},c.align=function(e){return arguments.length?(o=e,c):o},c.rightAlign=function(e){return arguments.length?(u=e,c):u},c.updateState=function(e){return arguments.length?(a=e,c):a},c.radioButtonMode=function(e){return arguments.length?(f=e,c):f},c},e.models.line=function(){function m(g){return g.each(function(m){var g=r-n.left-n.right,b=i-n.top-n.bottom,w=d3.select(this);c=t.xScale(),h=t.yScale(),d=d||c,v=v||h;var E=w.selectAll("g.nv-wrap.nv-line").data([m]),S=E.enter().append("g").attr("class","nvd3 nv-wrap nv-line"),T=S.append("defs"),N=S.append("g"),C=E.select("g");N.append("g").attr("class","nv-groups"),N.append("g").attr("class","nv-scatterWrap"),E.attr("transform","translate("+n.left+","+n.top+")"),t.width(g).height(b);var k=E.select(".nv-scatterWrap");k.call(t),T.append("clipPath").attr("id","nv-edge-clip-"+t.id()).append("rect"),E.select("#nv-edge-clip-"+t.id()+" rect").attr("width",g).attr("height",b>0?b:0),C.attr("clip-path",l?"url(#nv-edge-clip-"+t.id()+")":""),k.attr("clip-path",l?"url(#nv-edge-clip-"+t.id()+")":"");var L=E.select(".nv-groups").selectAll(".nv-group").data(function(e){return e},function(e){return e.key});L.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),L.exit().remove(),L.attr("class",function(e,t){return"nv-group nv-series-"+t}).classed("hover",function(e){return e.hover}).style("fill",function(e,t){return s(e,t)}).style("stroke",function(e,t){return s(e,t)}),L.style("stroke-opacity",1).style("fill-opacity",.5);var A=L.selectAll("path.nv-area").data(function(e){return f(e)?[e]:[]});A.enter().append("path").attr("class","nv-area").attr("d",function(t){return d3.svg.area().interpolate(p).defined(a).x(function(t,n){return e.utils.NaNtoZero(d(o(t,n)))}).y0(function(t,n){return e.utils.NaNtoZero(v(u(t,n)))}).y1(function(e,t){return v(h.domain()[0]<=0?h.domain()[1]>=0?0:h.domain()[1]:h.domain()[0])}).apply(this,[t.values])}),L.exit().selectAll("path.nv-area").remove(),A.attr("d",function(t){return d3.svg.area().interpolate(p).defined(a).x(function(t,n){return e.utils.NaNtoZero(c(o(t,n)))}).y0(function(t,n){return e.utils.NaNtoZero(h(u(t,n)))}).y1(function(e,t){return h(h.domain()[0]<=0?h.domain()[1]>=0?0:h.domain()[1]:h.domain()[0])}).apply(this,[t.values])});var O=L.selectAll("path.nv-line").data(function(e){return[e.values]});O.enter().append("path").attr("class","nv-line").attr("d",d3.svg.line().interpolate(p).defined(a).x(function(t,n){return e.utils.NaNtoZero(d(o(t,n)))}).y(function(t,n){return e.utils.NaNtoZero(v(u(t,n)))})),O.attr("d",d3.svg.line().interpolate(p).defined(a).x(function(t,n){return e.utils.NaNtoZero(c(o(t,n)))}).y(function(t,n){return e.utils.NaNtoZero(h(u(t,n)))})),d=c.copy(),v=h.copy()}),m}var t=e.models.scatter(),n={top:0,right:0,bottom:0,left:0},r=960,i=500,s=e.utils.defaultColor(),o=function(e){return e.x},u=function(e){return e.y},a=function(e,t){return!isNaN(u(e,t))&&u(e,t)!==null},f=function(e){return e.area},l=!1,c,h,p="linear";t.size(16).sizeDomain([16,256]);var d,v;return m.dispatch=t.dispatch,m.scatter=t,d3.rebind(m,t,"id","interactive","size","xScale","yScale","zScale","xDomain","yDomain","xRange","yRange","sizeDomain","forceX","forceY","forceSize","clipVoronoi","useVoronoi","clipRadius","padData","highlightPoint","clearHighlights"),m.options=e.utils.optionsFunc.bind(m),m.margin=function(e){return arguments.length?(n.top=typeof e.top!="undefined"?e.top:n.top,n.right=typeof e.right!="undefined"?e.right:n.right,n.bottom=typeof e.bottom!="undefined"?e.bottom:n.bottom,n.left=typeof e.left!="undefined"?e.left:n.left,m):n},m.width=function(e){return arguments.length?(r=e,m):r},m.height=function(e){return arguments.length?(i=e,m):i},m.x=function(e){return arguments.length?(o=e,t.x(e),m):o},m.y=function(e){return arguments.length?(u=e,t.y(e),m):u},m.clipEdge=function(e){return arguments.length?(l=e,m):l},m.color=function(n){return arguments.length?(s=e.utils.getColor(n),t.color(s),m):s},m.interpolate=function(e){return arguments.length?(p=e,m):p},m.defined=function(e){return arguments.length?(a=e,m):a},m.isArea=function(e){return arguments.length?(f=d3.functor(e),m):f},m},e.models.lineChart=function(){function N(m){return m.each(function(m){var x=d3.select(this),C=this,k=(a||parseInt(x.style("width"))||960)-o.left-o.right,L=(f||parseInt(x.style("height"))||400)-o.top-o.bottom;N.update=function(){x.call(N)},N.container=this,b.disabled=m.map(function(e){return!!e.disabled});if(!w){var A;w={};for(A in b)b[A]instanceof Array?w[A]=b[A].slice(0):w[A]=b[A]}if(!m||!m.length||!m.filter(function(e){return e.values.length}).length){var O=x.selectAll(".nv-noData").data([E]);return O.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),O.attr("x",o.left+k/2).attr("y",o.top+L/2).text(function(e){return e}),N}x.selectAll(".nv-noData").remove(),g=t.xScale(),y=t.yScale();var M=x.selectAll("g.nv-wrap.nv-lineChart").data([m]),_=M.enter().append("g").attr("class","nvd3 nv-wrap nv-lineChart").append("g"),D=M.select("g");_.append("rect").style("opacity",0),_.append("g").attr("class","nv-x nv-axis"),_.append("g").attr("class","nv-y nv-axis"),_.append("g").attr("class","nv-linesWrap"),_.append("g").attr("class","nv-legendWrap"),_.append("g").attr("class","nv-interactive"),D.select("rect").attr("width",k).attr("height",L>0?L:0),l&&(i.width(k),D.select(".nv-legendWrap").datum(m).call(i),o.top!=i.height()&&(o.top=i.height(),L=(f||parseInt(x.style("height"))||400)-o.top-o.bottom),M.select(".nv-legendWrap").attr("transform","translate(0,"+ -o.top+")")),M.attr("transform","translate("+o.left+","+o.top+")"),p&&D.select(".nv-y.nv-axis").attr("transform","translate("+k+",0)"),d&&(s.width(k).height(L).margin({left:o.left,top:o.top}).svgContainer(x).xScale(g),M.select(".nv-interactive").call(s)),t.width(k).height(L).color(m.map(function(e,t){return e.color||u(e,t)}).filter(function(e,t){return!m[t].disabled}));var P=D.select(".nv-linesWrap").datum(m.filter(function(e){return!e.disabled}));P.call(t),c&&(n.scale(g).ticks(k/100).tickSize(-L,0),D.select(".nv-x.nv-axis").attr("transform","translate(0,"+y.range()[0]+")"),D.select(".nv-x.nv-axis").call(n)),h&&(r.scale(y).ticks(L/36).tickSize(-k,0),D.select(".nv-y.nv-axis").call(r)),i.dispatch.on("stateChange",function(e){b=e,S.stateChange(b),N.update()}),s.dispatch.on("elementMousemove",function(i){t.clearHighlights();var a,f,l,c=[];m.filter(function(e,t){return e.seriesIndex=t,!e.disabled}).forEach(function(n,r){f=e.interactiveBisect(n.values,i.pointXValue,N.x()),t.highlightPoint(r,f,!0);var s=n.values[f];if(typeof s=="undefined")return;typeof a=="undefined"&&(a=s),typeof l=="undefined"&&(l=N.xScale()(N.x()(s,f))),c.push({key:n.key,value:N.y()(s,f),color:u(n,n.seriesIndex)})});if(c.length>2){var h=N.yScale().invert(i.mouseY),p=Math.abs(N.yScale().domain()[0]-N.yScale().domain()[1]),d=.03*p,g=e.nearestValueIndex(c.map(function(e){return e.value}),h,d);g!==null&&(c[g].highlight=!0)}var y=n.tickFormat()(N.x()(a,f));s.tooltip.position({left:l+o.left,top:i.mouseY+o.top}).chartContainer(C.parentNode).enabled(v).valueFormatter(function(e,t){return r.tickFormat()(e)}).data({value:y,series:c})(),s.renderGuideLine(l)}),s.dispatch.on("elementMouseout",function(e){S.tooltipHide(),t.clearHighlights()}),S.on("tooltipShow",function(e){v&&T(e,C.parentNode)}),S.on("changeState",function(e){typeof e.disabled!="undefined"&&m.length===e.disabled.length&&(m.forEach(function(t,n){t.disabled=e.disabled[n]}),b.disabled=e.disabled),N.update()})}),N}var t=e.models.line(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.interactiveGuideline(),o={top:30,right:20,bottom:50,left:60},u=e.utils.defaultColor(),a=null,f=null,l=!0,c=!0,h=!0,p=!1,d=!1,v=!0,m=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},g,y,b={},w=null,E="No Data Available.",S=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),x=0;n.orient("bottom").tickPadding(7),r.orient(p?"right":"left");var T=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=m(i.series.key,a,f,i,N);e.tooltip.show([o,u],l,null,null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+o.left,e.pos[1]+o.top],S.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){S.tooltipHide(e)}),S.on("tooltipHide",function(){v&&e.tooltip.cleanup()}),N.dispatch=S,N.lines=t,N.legend=i,N.xAxis=n,N.yAxis=r,N.interactiveLayer=s,d3.rebind(N,t,"defined","isArea","x","y","size","xScale","yScale","xDomain","yDomain","xRange","yRange","forceX","forceY","interactive","clipEdge","clipVoronoi","useVoronoi","id","interpolate"),N.options=e.utils.optionsFunc.bind(N),N.margin=function(e){return arguments.length?(o.top=typeof e.top!="undefined"?e.top:o.top,o.right=typeof e.right!="undefined"?e.right:o.right,o.bottom=typeof e.bottom!="undefined"?e.bottom:o.bottom,o.left=typeof e.left!="undefined"?e.left:o.left,N):o},N.width=function(e){return arguments.length?(a=e,N):a},N.height=function(e){return arguments.length?(f=e,N):f},N.color=function(t){return arguments.length?(u=e.utils.getColor(t),i.color(u),N):u},N.showLegend=function(e){return arguments.length?(l=e,N):l},N.showXAxis=function(e){return arguments.length?(c=e,N):c},N.showYAxis=function(e){return arguments.length?(h=e,N):h},N.rightAlignYAxis=function(e){return arguments.length?(p=e,r.orient(e?"right":"left"),N):p},N.useInteractiveGuideline=function(e){return arguments.length?(d=e,e===!0&&(N.interactive(!1),N.useVoronoi(!1)),N):d},N.tooltips=function(e){return arguments.length?(v=e,N):v},N.tooltipContent=function(e){return arguments.length?(m=e,N):m},N.state=function(e){return arguments.length?(b=e,N):b},N.defaultState=function(e){return arguments.length?(w=e,N):w},N.noData=function(e){return arguments.length?(E=e,N):E},N.transitionDuration=function(e){return arguments.length?(x=e,N):x},N},e.models.linePlusBarChart=function(){function T(e){return e.each(function(e){var l=d3.select(this),c=this,v=(a||parseInt(l.style("width"))||960)-u.left-u.right,N=(f||parseInt(l.style("height"))||400)-u.top-u.bottom;T.update=function(){l.call(T)},b.disabled=e.map(function(e){return!!e.disabled});if(!w){var C;w={};for(C in b)b[C]instanceof Array?w[C]=b[C].slice(0):w[C]=b[C]}if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var k=l.selectAll(".nv-noData").data([E]);return k.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),k.attr("x",u.left+v/2).attr("y",u.top+N/2).text(function(e){return e}),T}l.selectAll(".nv-noData").remove();var L=e.filter(function(e){return!e.disabled&&e.bar}),A=e.filter(function(e){return!e.bar});m=A.filter(function(e){return!e.disabled}).length&&A.filter(function(e){return!e.disabled})[0].values.length?t.xScale():n.xScale(),g=n.yScale(),y=t.yScale();var O=d3.select(this).selectAll("g.nv-wrap.nv-linePlusBar").data([e]),M=O.enter().append("g").attr("class","nvd3 nv-wrap nv-linePlusBar").append("g"),_=O.select("g");M.append("g").attr("class","nv-x nv-axis"),M.append("g").attr("class","nv-y1 nv-axis"),M.append("g").attr("class","nv-y2 nv-axis"),M.append("g").attr("class","nv-barsWrap"),M.append("g").attr("class","nv-linesWrap"),M.append("g").attr("class","nv-legendWrap"),p&&(o.width(v/2),_.select(".nv-legendWrap").datum(e.map(function(e){return e.originalKey=e.originalKey===undefined?e.key:e.originalKey,e.key=e.originalKey+(e.bar?" (left axis)":" (right axis)"),e})).call(o),u.top!=o.height()&&(u.top=o.height(),N=(f||parseInt(l.style("height"))||400)-u.top-u.bottom),_.select(".nv-legendWrap").attr("transform","translate("+v/2+","+ -u.top+")")),O.attr("transform","translate("+u.left+","+u.top+")"),t.width(v).height(N).color(e.map(function(e,t){return e.color||h(e,t)}).filter(function(t,n){return!e[n].disabled&&!e[n].bar})),n.width(v).height(N).color(e.map(function(e,t){return e.color||h(e,t)}).filter(function(t,n){return!e[n].disabled&&e[n].bar}));var D=_.select(".nv-barsWrap").datum(L.length?L:[{values:[]}]),P=_.select(".nv-linesWrap").datum(A[0]&&!A[0].disabled?A:[{values:[]}]);d3.transition(D).call(n),d3.transition(P).call(t),r.scale(m).ticks(v/100).tickSize(-N,0),_.select(".nv-x.nv-axis").attr("transform","translate(0,"+g.range()[0]+")"),d3.transition(_.select(".nv-x.nv-axis")).call(r),i.scale(g).ticks(N/36).tickSize(-v,0),d3.transition(_.select(".nv-y1.nv-axis")).style("opacity",L.length?1:0).call(i),s.scale(y).ticks(N/36).tickSize(L.length?0:-v,0),_.select(".nv-y2.nv-axis").style("opacity",A.length?1:0).attr("transform","translate("+v+",0)"),d3.transition(_.select(".nv-y2.nv-axis")).call(s),o.dispatch.on("stateChange",function(e){b=e,S.stateChange(b),T.update()}),S.on("tooltipShow",function(e){d&&x(e,c.parentNode)}),S.on("changeState",function(t){typeof t.disabled!="undefined"&&(e.forEach(function(e,n){e.disabled=t.disabled[n]}),b.disabled=t.disabled),T.update()})}),T}var t=e.models.line(),n=e.models.historicalBar(),r=e.models.axis(),i=e.models.axis(),s=e.models.axis(),o=e.models.legend(),u={top:30,right:60,bottom:50,left:60},a=null,f=null,l=function(e){return e.x},c=function(e){return e.y},h=e.utils.defaultColor(),p=!0,d=!0,v=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},m,g,y,b={},w=null,E="No Data Available.",S=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");n.padData(!0),t.clipEdge(!1).padData(!0),r.orient("bottom").tickPadding(7).highlightZero(!1),i.orient("left"),s.orient("right");var x=function(n,o){var u=n.pos[0]+(o.offsetLeft||0),a=n.pos[1]+(o.offsetTop||0),f=r.tickFormat()(t.x()(n.point,n.pointIndex)),l=(n.series.bar?i:s).tickFormat()(t.y()(n.point,n.pointIndex)),c=v(n.series.key,f,l,n,T);e.tooltip.show([u,a],c,n.value<0?"n":"s",null,o)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+u.left,e.pos[1]+u.top],S.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){S.tooltipHide(e)}),n.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+u.left,e.pos[1]+u.top],S.tooltipShow(e)}),n.dispatch.on("elementMouseout.tooltip",function(e){S.tooltipHide(e)}),S.on("tooltipHide",function(){d&&e.tooltip.cleanup()}),T.dispatch=S,T.legend=o,T.lines=t,T.bars=n,T.xAxis=r,T.y1Axis=i,T.y2Axis=s,d3.rebind(T,t,"defined","size","clipVoronoi","interpolate"),T.options=e.utils.optionsFunc.bind(T),T.x=function(e){return arguments.length?(l=e,t.x(e),n.x(e),T):l},T.y=function(e){return arguments.length?(c=e,t.y(e),n.y(e),T):c},T.margin=function(e){return arguments.length?(u.top=typeof e.top!="undefined"?e.top:u.top,u.right=typeof e.right!="undefined"?e.right:u.right,u.bottom=typeof e.bottom!="undefined"?e.bottom:u.bottom,u.left=typeof e.left!="undefined"?e.left:u.left,T):u},T.width=function(e){return arguments.length?(a=e,T):a},T.height=function(e){return arguments.length?(f=e,T):f},T.color=function(t){return arguments.length?(h=e.utils.getColor(t),o.color(h),T):h},T.showLegend=function(e){return arguments.length?(p=e,T):p},T.tooltips=function(e){return arguments.length?(d=e,T):d},T.tooltipContent=function(e){return arguments.length?(v=e,T):v},T.state=function(e){return arguments.length?(b=e,T):b},T.defaultState=function(e){return arguments.length?(w=e,T):w},T.noData=function(e){return arguments.length?(E=e,T):E},T},e.models.lineWithFocusChart=function(){function k(e){return e.each(function(e){function R(e){var t=+(e=="e"),n=t?1:-1,r=O/3;return"M"+.5*n+","+r+"A6,6 0 0 "+t+" "+6.5*n+","+(r+6)+"V"+(2*r-6)+"A6,6 0 0 "+t+" "+.5*n+","+2*r+"Z"+"M"+2.5*n+","+(r+8)+"V"+(2*r-8)+"M"+4.5*n+","+(r+8)+"V"+(2*r-8)}function U(){a.empty()||a.extent(w),F.data([a.empty()?g.domain():w]).each(function(e,t){var n=g(e[0])-v.range()[0],r=v.range()[1]-g(e[1]);d3.select(this).select(".left").attr("width",n<0?0:n),d3.select(this).select(".right").attr("x",g(e[1])).attr("width",r<0?0:r)})}function z(){w=a.empty()?null:a.extent();var n=a.empty()?g.domain():a.extent();if(Math.abs(n[0]-n[1])<=1)return;T.brush({extent:n,brush:a}),U();var s=P.select(".nv-focus .nv-linesWrap").datum(e.filter(function(e){return!e.disabled}).map(function(e,r){return{key:e.key,values:e.values.filter(function(e,r){return t.x()(e,r)>=n[0]&&t.x()(e,r)<=n[1]})}}));s.call(t),P.select(".nv-focus .nv-x.nv-axis").call(r),P.select(".nv-focus .nv-y.nv-axis").call(i)}var S=d3.select(this),N=this,L=(h||parseInt(S.style("width"))||960)-f.left-f.right,A=(p||parseInt(S.style("height"))||400)-f.top-f.bottom-d,O=d-l.top-l.bottom;k.update=function(){S.call(k)},k.container=this;if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var M=S.selectAll(".nv-noData").data([x]);return M.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),M.attr("x",f.left+L/2).attr("y",f.top+A/2).text(function(e){return e}),k}S.selectAll(".nv-noData").remove(),v=t.xScale(),m=t.yScale(),g=n.xScale(),y=n.yScale();var _=S.selectAll("g.nv-wrap.nv-lineWithFocusChart").data([e]),D=_.enter().append("g").attr("class","nvd3 nv-wrap nv-lineWithFocusChart").append("g"),P=_.select("g");D.append("g").attr("class","nv-legendWrap");var H=D.append("g").attr("class","nv-focus");H.append("g").attr("class","nv-x nv-axis"),H.append("g").attr("class","nv-y nv-axis"),H.append("g").attr("class","nv-linesWrap");var B=D.append("g").attr("class","nv-context");B.append("g").attr("class","nv-x nv-axis"),B.append("g").attr("class","nv-y nv-axis"),B.append("g").attr("class","nv-linesWrap"),B.append("g").attr("class","nv-brushBackground"),B.append("g").attr("class","nv-x nv-brush"),b&&(u.width(L),P.select(".nv-legendWrap").datum(e).call(u),f.top!=u.height()&&(f.top=u.height(),A=(p||parseInt(S.style("height"))||400)-f.top-f.bottom-d),P.select(".nv-legendWrap").attr("transform","translate(0,"+ -f.top+")")),_.attr("transform","translate("+f.left+","+f.top+")"),t.width(L).height(A).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),n.defined(t.defined()).width(L).height(O).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),P.select(".nv-context").attr("transform","translate(0,"+(A+f.bottom+l.top)+")");var j=P.select(".nv-context .nv-linesWrap").datum(e.filter(function(e){return!e.disabled}));d3.transition(j).call(n),r.scale(v).ticks(L/100).tickSize(-A,0),i.scale(m).ticks(A/36).tickSize(-L,0),P.select(".nv-focus .nv-x.nv-axis").attr("transform","translate(0,"+A+")"),a.x(g).on("brush",function(){var e=k.transitionDuration();k.transitionDuration(0),z(),k.transitionDuration(e)}),w&&a.extent(w);var F=P.select(".nv-brushBackground").selectAll("g").data([w||a.extent()]),I=F.enter().append("g");I.append("rect").attr("class","left").attr("x",0).attr("y",0).attr("height",O),I.append("rect").attr("class","right").attr("x",0).attr("y",0).attr("height",O);var q=P.select(".nv-x.nv-brush").call(a);q.selectAll("rect").attr("height",O),q.selectAll(".resize").append("path").attr("d",R),z(),s.scale(g).ticks(L/100).tickSize(-O,0),P.select(".nv-context .nv-x.nv-axis").attr("transform","translate(0,"+y.range()[0]+")"),d3.transition(P.select(".nv-context .nv-x.nv-axis")).call(s),o.scale(y).ticks(O/36).tickSize(-L,0),d3.transition(P.select(".nv-context .nv-y.nv-axis")).call(o),P.select(".nv-context .nv-x.nv-axis").attr("transform","translate(0,"+y.range()[0]+")"),u.dispatch.on("stateChange",function(e){k.update()}),T.on("tooltipShow",function(e){E&&C(e,N.parentNode)})}),k}var t=e.models.line(),n=e.models.line(),r=e.models.axis(),i=e.models.axis(),s=e.models.axis(),o=e.models.axis(),u=e.models.legend(),a=d3.svg.brush(),f={top:30,right:30,bottom:30,left:60},l={top:0,right:30,bottom:20,left:60},c=e.utils.defaultColor(),h=null,p=null,d=100,v,m,g,y,b=!0,w=null,E=!0,S=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},x="No Data Available.",T=d3.dispatch("tooltipShow","tooltipHide","brush"),N=0;t.clipEdge(!0),n.interactive(!1),r.orient("bottom").tickPadding(5),i.orient("left"),s.orient("bottom").tickPadding(5),o.orient("left");var C=function(n,s){var o=n.pos[0]+(s.offsetLeft||0),u=n.pos[1]+(s.offsetTop||0),a=r.tickFormat()(t.x()(n.point,n.pointIndex)),f=i.tickFormat()(t.y()(n.point,n.pointIndex)),l=S(n.series.key,a,f,n,k);e.tooltip.show([o,u],l,null,null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+f.left,e.pos[1]+f.top],T.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),T.on("tooltipHide",function(){E&&e.tooltip.cleanup()}),k.dispatch=T,k.legend=u,k.lines=t,k.lines2=n,k.xAxis=r,k.yAxis=i,k.x2Axis=s,k.y2Axis=o,d3.rebind(k,t,"defined","isArea","size","xDomain","yDomain","xRange","yRange","forceX","forceY","interactive","clipEdge","clipVoronoi","id"),k.options=e.utils.optionsFunc.bind(k),k.x=function(e){return arguments.length?(t.x(e),n.x(e),k):t.x},k.y=function(e){return arguments.length?(t.y(e),n.y(e),k):t.y},k.margin=function(e){return arguments.length?(f.top=typeof e.top!="undefined"?e.top:f.top,f.right=typeof e.right!="undefined"?e.right:f.right,f.bottom=typeof e.bottom!="undefined"?e.bottom:f.bottom,f.left=typeof e.left!="undefined"?e.left:f.left,k):f},k.margin2=function(e){return arguments.length?(l=e,k):l},k.width=function(e){return arguments.length?(h=e,k):h},k.height=function(e){return arguments.length?(p=e,k):p},k.height2=function(e){return arguments.length?(d=e,k):d},k.color=function(t){return arguments.length?(c=e.utils.getColor(t),u.color(c),k):c},k.showLegend=function(e){return arguments.length?(b=e,k):b},k.tooltips=function(e){return arguments.length?(E=e,k):E},k.tooltipContent=function(e){return arguments.length?(S=e,k):S},k.interpolate=function(e){return arguments.length?(t.interpolate(e),n.interpolate(e),k):t.interpolate()},k.noData=function(e){return arguments.length?(x=e,k):x},k.xTickFormat=function(e){return arguments.length?(r.tickFormat(e),s.tickFormat(e),k):r.tickFormat()},k.yTickFormat=function(e){return arguments.length?(i.tickFormat(e),o.tickFormat(e),k):i.tickFormat()},k.brushExtent=function(e){return arguments.length?(w=e,k):w},k.transitionDuration=function(e){return arguments.length?(N=e,k):N},k},e.models.linePlusBarWithFocusChart=function(){function B(e){return e.each(function(e){function tt(e){var t=+(e=="e"),n=t?1:-1,r=I/3;return"M"+.5*n+","+r+"A6,6 0 0 "+t+" "+6.5*n+","+(r+6)+"V"+(2*r-6)+"A6,6 0 0 "+t+" "+.5*n+","+2*r+"Z"+"M"+2.5*n+","+(r+8)+"V"+(2*r-8)+"M"+4.5*n+","+(r+8)+"V"+(2*r-8)}function nt(){h.empty()||h.extent(x),Y.data([h.empty()?k.domain():x]).each(function(e,t){var n=k(e[0])-k.range()[0],r=k.range()[1]-k(e[1]);d3.select(this).select(".left").attr("width",n<0?0:n),d3.select(this).select(".right").attr("x",k(e[1])).attr("width",r<0?0:r)})}function rt(){x=h.empty()?null:h.extent(),S=h.empty()?k.domain():h.extent(),D.brush({extent:S,brush:h}),nt(),r.width(j).height(F).color(e.map(function(e,t){return e.color||w(e,t)}).filter(function(t,n){return!e[n].disabled&&e[n].bar})),t.width(j).height(F).color(e.map(function(e,t){return e.color||w(e,t)}).filter(function(t,n){return!e[n].disabled&&!e[n].bar}));var n=$.select(".nv-focus .nv-barsWrap").datum(R.length?R.map(function(e,t){return{key:e.key,values:e.values.filter(function(e,t){return r.x()(e,t)>=S[0]&&r.x()(e,t)<=S[1]})}}):[{values:[]}]),i=$.select(".nv-focus .nv-linesWrap").datum(U[0].disabled?[{values:[]}]:U.map(function(e,n){return{key:e.key,values:e.values.filter(function(e,n){return t.x()(e,n)>=S[0]&&t.x()(e,n)<=S[1]})}}));R.length?C=r.xScale():C=t.xScale(),s.scale(C).ticks(j/100).tickSize(-F,0),s.domain([Math.ceil(S[0]),Math.floor(S[1])]),$.select(".nv-x.nv-axis").call(s),n.call(r),i.call(t),$.select(".nv-focus .nv-x.nv-axis").attr("transform","translate(0,"+L.range()[0]+")"),u.scale(L).ticks(F/36).tickSize(-j,0),$.select(".nv-focus .nv-y1.nv-axis").style("opacity",R.length?1:0),a.scale(A).ticks(F/36).tickSize(R.length?0:-j,0),$.select(".nv-focus .nv-y2.nv-axis").style("opacity",U.length?1:0).attr("transform","translate("+C.range()[1]+",0)"),$.select(".nv-focus .nv-y1.nv-axis").call(u),$.select(".nv-focus .nv-y2.nv-axis").call(a)}var N=d3.select(this),P=this,j=(v||parseInt(N.style("width"))||960)-p.left-p.right,F=(m||parseInt(N.style("height"))||400)-p.top-p.bottom-g,I=g-d.top-d.bottom;B.update=function(){N.call(B)},B.container=this;if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var q=N.selectAll(".nv-noData").data([_]);return q.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),q.attr("x",p.left+j/2).attr("y",p.top+F/2).text(function(e){return e}),B}N.selectAll(".nv-noData").remove();var R=e.filter(function(e){return!e.disabled&&e.bar}),U=e.filter(function(e){return!e.bar});C=r.xScale(),k=o.scale(),L=r.yScale(),A=t.yScale(),O=i.yScale(),M=n.yScale();var z=e.filter(function(e){return!e.disabled&&e.bar}).map(function(e){return e.values.map(function(e,t){return{x:y(e,t),y:b(e,t)}})}),W=e.filter(function(e){return!e.disabled&&!e.bar}).map(function(e){return e.values.map(function(e,t){return{x:y(e,t),y:b(e,t)}})});C.range([0,j]),k.domain(d3.extent(d3.merge(z.concat(W)),function(e){return e.x})).range([0,j]);var X=N.selectAll("g.nv-wrap.nv-linePlusBar").data([e]),V=X.enter().append("g").attr("class","nvd3 nv-wrap nv-linePlusBar").append("g"),$=X.select("g");V.append("g").attr("class","nv-legendWrap");var J=V.append("g").attr("class","nv-focus");J.append("g").attr("class","nv-x nv-axis"),J.append("g").attr("class","nv-y1 nv-axis"),J.append("g").attr("class","nv-y2 nv-axis"),J.append("g").attr("class","nv-barsWrap"),J.append("g").attr("class","nv-linesWrap");var K=V.append("g").attr("class","nv-context");K.append("g").attr("class","nv-x nv-axis"),K.append("g").attr("class","nv-y1 nv-axis"),K.append("g").attr("class","nv-y2 nv-axis"),K.append("g").attr("class","nv-barsWrap"),K.append("g").attr("class","nv-linesWrap"),K.append("g").attr("class","nv-brushBackground"),K.append("g").attr("class","nv-x nv-brush"),E&&(c.width(j/2),$.select(".nv-legendWrap").datum(e.map(function(e){return e.originalKey=e.originalKey===undefined?e.key:e.originalKey,e.key=e.originalKey+(e.bar?" (left axis)":" (right axis)"),e})).call(c),p.top!=c.height()&&(p.top=c.height(),F=(m||parseInt(N.style("height"))||400)-p.top-p.bottom-g),$.select(".nv-legendWrap").attr("transform","translate("+j/2+","+ -p.top+")")),X.attr("transform","translate("+p.left+","+p.top+")"),i.width(j).height(I).color(e.map(function(e,t){return e.color||w(e,t)}).filter(function(t,n){return!e[n].disabled&&e[n].bar})),n.width(j).height(I).color(e.map(function(e,t){return e.color||w(e,t)}).filter(function(t,n){return!e[n].disabled&&!e[n].bar}));var Q=$.select(".nv-context .nv-barsWrap").datum(R.length?R:[{values:[]}]),G=$.select(".nv-context .nv-linesWrap").datum(U[0].disabled?[{values:[]}]:U);$.select(".nv-context").attr("transform","translate(0,"+(F+p.bottom+d.top)+")"),Q.call(i),G.call(n),h.x(k).on("brush",rt),x&&h.extent(x);var Y=$.select(".nv-brushBackground").selectAll("g").data([x||h.extent()]),Z=Y.enter().append("g");Z.append("rect").attr("class","left").attr("x",0).attr("y",0).attr("height",I),Z.append("rect").attr("class","right").attr("x",0).attr("y",0).attr("height",I);var et=$.select(".nv-x.nv-brush").call(h);et.selectAll("rect").attr("height",I),et.selectAll(".resize").append("path").attr("d",tt),o.ticks(j/100).tickSize(-I,0),$.select(".nv-context .nv-x.nv-axis").attr("transform","translate(0,"+O.range()[0]+")"),$.select(".nv-context .nv-x.nv-axis").call(o),f.scale(O).ticks(I/36).tickSize(-j,0),$.select(".nv-context .nv-y1.nv-axis").style("opacity",R.length?1:0).attr("transform","translate(0,"+k.range()[0]+")"),$.select(".nv-context .nv-y1.nv-axis").call(f),l.scale(M).ticks(I/36).tickSize(R.length?0:-j,0),$.select(".nv-context .nv-y2.nv-axis").style("opacity",U.length?1:0).attr("transform","translate("+k.range()[1]+",0)"),$.select(".nv-context .nv-y2.nv-axis").call(l),c.dispatch.on("stateChange",function(e){B.update()}),D.on("tooltipShow",function(e){T&&H(e,P.parentNode)}),rt()}),B}var t=e.models.line(),n=e.models.line(),r=e.models.historicalBar(),i=e.models.historicalBar(),s=e.models.axis(),o=e.models.axis(),u=e.models.axis(),a=e.models.axis(),f=e.models.axis(),l=e.models.axis(),c=e.models.legend(),h=d3.svg.brush(),p={top:30,right:30,bottom:30,left:60},d={top:0,right:30,bottom:20,left:60},v=null,m=null,g=100,y=function(e){return e.x},b=function(e){return e.y},w=e.utils.defaultColor(),E=!0,S,x=null,T=!0,N=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},C,k,L,A,O,M,_="No Data Available.",D=d3.dispatch("tooltipShow","tooltipHide","brush"),P=0;t.clipEdge(!0),n.interactive(!1),s.orient("bottom").tickPadding(5),u.orient("left"),a.orient("right"),o.orient("bottom").tickPadding(5),f.orient("left"),l.orient("right");var H=function(n,r){S&&(n.pointIndex+=Math.ceil(S[0]));var i=n.pos[0]+(r.offsetLeft||0),o=n.pos[1]+(r.offsetTop||0),f=s.tickFormat()(t.x()(n.point,n.pointIndex)),l=(n.series.bar?u:a).tickFormat()(t.y()(n.point,n.pointIndex)),c=N(n.series.key,f,l,n,B);e.tooltip.show([i,o],c,n.value<0?"n":"s",null,r)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+p.left,e.pos[1]+p.top],D.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){D.tooltipHide(e)}),r.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+p.left,e.pos[1]+p.top],D.tooltipShow(e)}),r.dispatch.on("elementMouseout.tooltip",function(e){D.tooltipHide(e)}),D.on("tooltipHide",function(){T&&e.tooltip.cleanup()}),B.dispatch=D,B.legend=c,B.lines=t,B.lines2=n,B.bars=r,B.bars2=i,B.xAxis=s,B.x2Axis=o,B.y1Axis=u,B.y2Axis=a,B.y3Axis=f,B.y4Axis=l,d3.rebind(B,t,"defined","size","clipVoronoi","interpolate"),B.options=e.utils.optionsFunc.bind(B),B.x=function(e){return arguments.length?(y=e,t.x(e),r.x(e),B):y},B.y=function(e){return arguments.length?(b=e,t.y(e),r.y(e),B):b},B.margin=function(e){return arguments.length?(p.top=typeof e.top!="undefined"?e.top:p.top,p.right=typeof e.right!="undefined"?e.right:p.right,p.bottom=typeof e.bottom!="undefined"?e.bottom:p.bottom,p.left=typeof e.left!="undefined"?e.left:p.left,B):p},B.width=function(e){return arguments.length?(v=e,B):v},B.height=function(e){return arguments.length?(m=e,B):m},B.color=function(t){return arguments.length?(w=e.utils.getColor(t),c.color(w),B):w},B.showLegend=function(e){return arguments.length?(E=e,B):E},B.tooltips=function(e){return arguments.length?(T=e,B):T},B.tooltipContent=function(e){return arguments.length?(N=e,B):N},B.noData=function(e){return arguments.length?(_=e,B):_},B.brushExtent=function(e){return arguments.length?(x=e,B):x},B},e.models.multiBar=function(){function C(e){return e.each(function(e){var g=n-t.left-t.right,C=r-t.top-t.bottom,k=d3.select(this);d&&e.length&&(d=[{values:e[0].values.map(function(e){return{x:e.x,y:0,series:e.series,size:.01}})}]),c&&(e=d3.layout.stack().offset(h).values(function(e){return e.values}).y(a)(!e.length&&d?d:e)),e.forEach(function(e,t){e.values.forEach(function(e){e.series=t})}),c&&e[0].values.map(function(t,n){var r=0,i=0;e.map(function(e){var t=e.values[n];t.size=Math.abs(t.y),t.y<0?(t.y1=i,i-=t.size):(t.y1=t.size+r,r+=t.size)})});var L=y&&b?[]:e.map(function(e){return e.values.map(function(e,t){return{x:u(e,t),y:a(e,t),y0:e.y0,y1:e.y1}})});i.domain(y||d3.merge(L).map(function(e){return e.x})).rangeBands(w||[0,g],S),s.domain(b||d3.extent(d3.merge(L).map(function(e){return c?e.y>0?e.y1:e.y1+e.y:e.y}).concat(f))).range(E||[C,0]),i.domain()[0]===i.domain()[1]&&(i.domain()[0]?i.domain([i.domain()[0]-i.domain()[0]*.01,i.domain()[1]+i.domain()[1]*.01]):i.domain([-1,1])),s.domain()[0]===s.domain()[1]&&(s.domain()[0]?s.domain([s.domain()[0]+s.domain()[0]*.01,s.domain()[1]-s.domain()[1]*.01]):s.domain([-1,1])),T=T||i,N=N||s;var A=k.selectAll("g.nv-wrap.nv-multibar").data([e]),O=A.enter().append("g").attr("class","nvd3 nv-wrap nv-multibar"),M=O.append("defs"),_=O.append("g"),D=A.select("g");_.append("g").attr("class","nv-groups"),A.attr("transform","translate("+t.left+","+t.top+")"),M.append("clipPath").attr("id","nv-edge-clip-"+o).append("rect"),A.select("#nv-edge-clip-"+o+" rect").attr("width",g).attr("height",C),D.attr("clip-path",l?"url(#nv-edge-clip-"+o+")":"");var P=A.select(".nv-groups").selectAll(".nv-group").data(function(e){return e},function(e,t){return t});P.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),P.exit().selectAll("rect.nv-bar").attr("y",function(e){return c?N(e.y0):N(0)}).attr("height",0).remove(),P.attr("class",function(e,t){return"nv-group nv-series-"+t}).classed("hover",function(e){return e.hover}).style("fill",function(e,t){return p(e,t)}).style("stroke",function(e,t){return p(e,t)}),P.style("stroke-opacity",1).style("fill-opacity",.75);var H=P.selectAll("rect.nv-bar").data(function(t){return d&&!e.length?d.values:t.values});H.exit().remove();var B=H.enter().append("rect").attr("class",function(e,t){return a(e,t)<0?"nv-bar negative":"nv-bar positive"}).attr("x",function(t,n,r){return c?0:r*i.rangeBand()/e.length}).attr("y",function(e){return N(c?e.y0:0)}).attr("height",0).attr("width",i.rangeBand()/(c?1:e.length)).attr("transform",function(e,t){return"translate("+i(u(e,t))+",0)"});H.style("fill",function(e,t,n){return p(e,n,t)}).style("stroke",function(e,t,n){return p(e,n,t)}).on("mouseover",function(t,n){d3.select(this).classed("hover",!0),x.elementMouseover({value:a(t,n),point:t,series:e[t.series],pos:[i(u(t,n))+i.rangeBand()*(c?e.length/2:t.series+.5)/e.length,s(a(t,n)+(c?t.y0:0))],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("mouseout",function(t,n){d3.select(this).classed("hover",!1),x.elementMouseout({value:a(t,n),point:t,series:e[t.series],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("click",function(t,n){x.elementClick({value:a(t,n),point:t,series:e[t.series],pos:[i(u(t,n))+i.rangeBand()*(c?e.length/2:t.series+.5)/e.length,s(a(t,n)+(c?t.y0:0))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(t,n){x.elementDblClick({value:a(t,n),point:t,series:e[t.series],pos:[i(u(t,n))+i.rangeBand()*(c?e.length/2:t.series+.5)/e.length,s(a(t,n)+(c?t.y0:0))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()}),H.attr("class",function(e,t){return a(e,t)<0?"nv-bar negative":"nv-bar positive"}).attr("transform",function(e,t){return"translate("+i(u(e,t))+",0)"}),v&&(m||(m=e.map(function(){return!0})),H.style("fill",function(e,t,n){return d3.rgb(v(e,t)).darker(m.map(function(e,t){return t}).filter(function(e,t){return!m[t]})[n]).toString()}).style("stroke",function(e,t,n){return d3.rgb(v(e,t)).darker(m.map(function(e,t){return t}).filter(function(e,t){return!m[t]})[n]).toString()})),c?H.attr("y",function(e,t){return s(c?e.y1:0)}).attr("height",function(e,t){return Math.max(Math.abs(s(e.y+(c?e.y0:0))-s(c?e.y0:0)),1)}).attr("x",function(t,n){return c?0:t.series*i.rangeBand()/e.length}).attr("width",i.rangeBand()/(c?1:e.length)):H.attr("x",function(t,n){return t.series*i.rangeBand()/e.length}).attr("width",i.rangeBand()/e.length).attr("y",function(e,t){return a(e,t)<0?s(0):s(0)-s(a(e,t))<1?s(0)-1:s(a(e,t))||0}).attr("height",function(e,t){return Math.max(Math.abs(s(a(e,t))-s(0)),1)||0}),T=i.copy(),N=s.copy()}),C}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=d3.scale.ordinal(),s=d3.scale.linear(),o=Math.floor(Math.random()*1e4),u=function(e){return e.x},a=function(e){return e.y},f=[0],l=!0,c=!1,h="zero",p=e.utils.defaultColor(),d=!1,v=null,m,g=1200,y,b,w,E,S=.1,x=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),T,N;return C.dispatch=x,C.options=e.utils.optionsFunc.bind(C),C.x=function(e){return arguments.length?(u=e,C):u},C.y=function(e){return arguments.length?(a=e,C):a},C.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,C):t},C.width=function(e){return arguments.length?(n=e,C):n},C.height=function(e){return arguments.length?(r=e,C):r},C.xScale=function(e){return arguments.length?(i=e,C):i},C.yScale=function(e){return arguments.length?(s=e,C):s},C.xDomain=function(e){return arguments.length?(y=e,C):y},C.yDomain=function(e){return arguments.length?(b=e,C):b},C.xRange=function(e){return arguments.length?(w=e,C):w},C.yRange=function(e){return arguments.length?(E=e,C):E},C.forceY=function(e){return arguments.length?(f=e,C):f},C.stacked=function(e){return arguments.length?(c=e,C):c},C.stackOffset=function(e){return arguments.length?(h=e,C):h},C.clipEdge=function(e){return arguments.length?(l=e,C):l},C.color=function(t){return arguments.length?(p=e.utils.getColor(t),C):p},C.barColor=function(t){return arguments.length?(v=e.utils.getColor(t),C):v},C.disabled=function(e){return arguments.length?(m=e,C):m},C.id=function(e){return arguments.length?(o=e,C):o},C.hideable=function(e){return arguments.length?(d=e,C):d},C.delay=function(e){return arguments.length?(g=e,C):g},C.groupSpacing=function(e){return arguments.length?(S=e,C):S},C},e.models.multiBarChart=function(){function A(e){return e.each(function(e){var b=d3.select(this),k=this,O=(u||parseInt(b.style("width"))||960)-o.left-o.right,M=(a||parseInt(b.style("height"))||400)-o.top-o.bottom;A.update=function(){b.call(A)},A.container=this,S.disabled=e.map(function(e){return!!e.disabled});if(!x){var _;x={};for(_ in S)S[_]instanceof Array?x[_]=S[_].slice(0):x[_]=S[_]}if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var D=b.selectAll(".nv-noData").data([T]);return D.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),D.attr("x",o.left+O/2).attr("y",o.top+M/2).text(function(e){return e}),A}b.selectAll(".nv-noData").remove(),w=t.xScale(),E=t.yScale();var P=b.selectAll("g.nv-wrap.nv-multiBarWithLegend").data([e]),H=P.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarWithLegend").append("g"),B=P.select("g");H.append("g").attr("class","nv-x nv-axis"),H.append("g").attr("class","nv-y nv-axis"),H.append("g").attr("class","nv-barsWrap"),H.append("g").attr("class","nv-legendWrap"),H.append("g").attr("class","nv-controlsWrap"),c&&(i.width(O-C()),t.barColor()&&e.forEach(function(e,t){e.color=d3.rgb("#ccc").darker(t*1.5).toString()}),B.select(".nv-legendWrap").datum(e).call(i),o.top!=i.height()&&(o.top=i.height(),M=(a||parseInt(b.style("height"))||400)-o.top-o.bottom),B.select(".nv-legendWrap").attr("transform","translate("+C()+","+ -o.top+")"));if(l){var j=[{key:"Grouped",disabled:t.stacked()},{key:"Stacked",disabled:!t.stacked()}];s.width(C()).color(["#444","#444","#444"]),B.select(".nv-controlsWrap").datum(j).attr("transform","translate(0,"+ -o.top+")").call(s)}P.attr("transform","translate("+o.left+","+o.top+")"),d&&B.select(".nv-y.nv-axis").attr("transform","translate("+O+",0)"),t.disabled(e.map(function(e){return e.disabled})).width(O).height(M).color(e.map(function(e,t){return e.color||f(e,t)}).filter(function(t,n){return!e[n].disabled}));var F=B.select(".nv-barsWrap").datum(e.filter(function(e){return!e.disabled}));F.call(t);if(h){n.scale(w).ticks(O/100).tickSize(-M,0),B.select(".nv-x.nv-axis").attr("transform","translate(0,"+E.range()[0]+")"),B.select(".nv-x.nv-axis").call(n);var I=B.select(".nv-x.nv-axis > g").selectAll("g");I.selectAll("line, text").style("opacity",1);if(m){var q=function(e,t){return"translate("+e+","+t+")"},R=5,U=17;I.selectAll("text").attr("transform",function(e,t,n){return q(0,n%2==0?R:U)});var z=d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length;B.selectAll(".nv-x.nv-axis .nv-axisMaxMin text").attr("transform",function(e,t){return q(0,t===0||z%2!==0?U:R)})}v&&I.filter(function(t,n){return n%Math.ceil(e[0].values.length/(O/100))!==0}).selectAll("text, line").style("opacity",0),g&&I.selectAll(".tick text").attr("transform","rotate("+g+" 0,0)").style("text-anchor",g>0?"start":"end"),B.select(".nv-x.nv-axis").selectAll("g.nv-axisMaxMin text").style("opacity",1)}p&&(r.scale(E).ticks(M/36).tickSize(-O,0),B.select(".nv-y.nv-axis").call(r)),i.dispatch.on("stateChange",function(e){S=e,N.stateChange(S),A.update()}),s.dispatch.on("legendClick",function(e,n){if(!e.disabled)return;j=j.map(function(e){return e.disabled=!0,e}),e.disabled=!1;switch(e.key){case"Grouped":t.stacked(!1);break;case"Stacked":t.stacked(!0)}S.stacked=t.stacked(),N.stateChange(S),A.update()}),N.on("tooltipShow",function(e){y&&L(e,k.parentNode)}),N.on("changeState",function(n){typeof n.disabled!="undefined"&&(e.forEach(function(e,t){e.disabled=n.disabled[t]}),S.disabled=n.disabled),typeof n.stacked!="undefined"&&(t.stacked(n.stacked),S.stacked=n.stacked),A.update()})}),A}var t=e.models.multiBar(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.models.legend(),o={top:30,right:20,bottom:50,left:60},u=null,a=null,f=e.utils.defaultColor(),l=!0,c=!0,h=!0,p=!0,d=!1,v=!0,m=!1,g=0,y=!0,b=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" on "+t+"</p>"},w,E,S={stacked:!1},x=null,T="No Data Available.",N=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),C=function(){return l?180:0},k=0;t.stacked(!1),n.orient("bottom").tickPadding(7).highlightZero(!0).showMaxMin(!1).tickFormat(function(e){return e}),r.orient(d?"right":"left").tickFormat(d3.format(",.1f")),s.updateState(!1);var L=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=b(i.series.key,a,f,i,A);e.tooltip.show([o,u],l,i.value<0?"n":"s",null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+o.left,e.pos[1]+o.top],N.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){N.tooltipHide(e)}),N.on("tooltipHide",function(){y&&e.tooltip.cleanup()}),A.dispatch=N,A.multibar=t,A.legend=i,A.xAxis=n,A.yAxis=r,d3.rebind(A,t,"x","y","xDomain","yDomain","xRange","yRange","forceX","forceY","clipEdge","id","stacked","stackOffset","delay","barColor","groupSpacing"),A.options=e.utils.optionsFunc.bind(A),A.margin=function(e){return arguments.length?(o.top=typeof e.top!="undefined"?e.top:o.top,o.right=typeof e.right!="undefined"?e.right:o.right,o.bottom=typeof e.bottom!="undefined"?e.bottom:o.bottom,o.left=typeof e.left!="undefined"?e.left:o.left,A):o},A.width=function(e){return arguments.length?(u=e,A):u},A.height=function(e){return arguments.length?(a=e,A):a},A.color=function(t){return arguments.length?(f=e.utils.getColor(t),i.color(f),A):f},A.showControls=function(e){return arguments.length?(l=e,A):l},A.showLegend=function(e){return arguments.length?(c=e,A):c},A.showXAxis=function(e){return arguments.length?(h=e,A):h},A.showYAxis=function(e){return arguments.length?(p=e,A):p},A.rightAlignYAxis=function(e){return arguments.length?(d=e,r.orient(e?"right":"left"),A):d},A.reduceXTicks=function(e){return arguments.length?(v=e,A):v},A.rotateLabels=function(e){return arguments.length?(g=e,A):g},A.staggerLabels=function(e){return arguments.length?(m=e,A):m},A.tooltip=function(e){return arguments.length?(b=e,A):b},A.tooltips=function(e){return arguments.length?(y=e,A):y},A.tooltipContent=function(e){return arguments.length?(b=e,A):b},A.state=function(e){return arguments.length?(S=e,A):S},A.defaultState=function(e){return arguments.length?(x=e,A):x},A.noData=function(e){return arguments.length?(T=e,A):T},A.transitionDuration=function(e){return arguments.length?(k=e,A):k},A},e.models.multiBarHorizontal=function(){function C(e){return e.each(function(e){var i=n-t.left-t.right,y=r-t.top-t.bottom,C=d3.select(this);p&&(e=d3.layout.stack().offset("zero").values(function(e){return e.values}).y(a)(e)),e.forEach(function(e,t){e.values.forEach(function(e){e.series=t})}),p&&e[0].values.map(function(t,n){var r=0,i=0;e.map(function(e){var t=e.values[n];t.size=Math.abs(t.y),t.y<0?(t.y1=i-t.size,i-=t.size):(t.y1=r,r+=t.size)})});var k=b&&w?[]:e.map(function(e){return e.values.map(function(e,t){return{x:u(e,t),y:a(e,t),y0:e.y0,y1:e.y1}})});s.domain(b||d3.merge(k).map(function(e){return e.x})).rangeBands(E||[0,y],.1),o.domain(w||d3.extent(d3.merge(k).map(function(e){return p?e.y>0?e.y1+e.y:e.y1:e.y}).concat(f))),d&&!p?o.range(S||[o.domain()[0]<0?m:0,i-(o.domain()[1]>0?m:0)]):o.range(S||[0,i]),T=T||s,N=N||d3.scale.linear().domain(o.domain()).range([o(0),o(0)]);var L=d3.select(this).selectAll("g.nv-wrap.nv-multibarHorizontal").data([e]),A=L.enter().append("g").attr("class","nvd3 nv-wrap nv-multibarHorizontal"),O=A.append("defs"),M=A.append("g"),_=L.select("g");M.append("g").attr("class","nv-groups"),L.attr("transform","translate("+t.left+","+t.top+")");var D=L.select(".nv-groups").selectAll(".nv-group").data(function(e){return e},function(e,t){return t});D.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),D.exit().style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),D.attr("class",function(e,t){return"nv-group nv-series-"+t}).classed("hover",function(e){return e.hover}).style("fill",function(e,t){return l(e,t)}).style("stroke",function(e,t){return l(e,t)}),D.style("stroke-opacity",1).style("fill-opacity",.75);var P=D.selectAll("g.nv-bar").data(function(e){return e.values});P.exit().remove();var H=P.enter().append("g").attr("transform",function(t,n,r){return"translate("+N(p?t.y0:0)+","+(p?0:r*s.rangeBand()/e.length+s(u(t,n)))+")"});H.append("rect").attr("width",0).attr("height",s.rangeBand()/(p?1:e.length)),P.on("mouseover",function(t,n){d3.select(this).classed("hover",!0),x.elementMouseover({value:a(t,n),point:t,series:e[t.series],pos:[o(a(t,n)+(p?t.y0:0)),s(u(t,n))+s.rangeBand()*(p?e.length/2:t.series+.5)/e.length],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("mouseout",function(t,n){d3.select(this).classed("hover",!1),x.elementMouseout({value:a(t,n),point:t,series:e[t.series],pointIndex:n,seriesIndex:t.series,e:d3.event})}).on("click",function(t,n){x.elementClick({value:a(t,n),point:t,series:e[t.series],pos:[s(u(t,n))+s.rangeBand()*(p?e.length/2:t.series+.5)/e.length,o(a(t,n)+(p?t.y0:0))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(t,n){x.elementDblClick({value:a(t,n),point:t,series:e[t.series],pos:[s(u(t,n))+s.rangeBand()*(p?e.length/2:t.series+.5)/e.length,o(a(t,n)+(p?t.y0:0))],pointIndex:n,seriesIndex:t.series,e:d3.event}),d3.event.stopPropagation()}),H.append("text"),d&&!p?(P.select("text").attr("text-anchor",function(e,t){return a(e,t)<0?"end":"start"}).attr("y",s.rangeBand()/(e.length*2)).attr("dy",".32em").text(function(e,t){return g(a(e,t))}),P.select("text").attr("x",function(e,t){return a(e,t)<0?-4:o(a(e,t))-o(0)+4})):P.selectAll("text").text(""),v&&!p?(H.append("text").classed("nv-bar-label",!0),P.select("text.nv-bar-label").attr("text-anchor",function(e,t){return a(e,t)<0?"start":"end"}).attr("y",s.rangeBand()/(e.length*2)).attr("dy",".32em").text(function(e,t){return u(e,t)}),P.select("text.nv-bar-label").attr("x",function(e,t){return a(e,t)<0?o(0)-o(a(e,t))+4:-4})):P.selectAll("text.nv-bar-label").text(""),P.attr("class",function(e,t){return a(e,t)<0?"nv-bar negative":"nv-bar positive"}),c&&(h||(h=e.map(function(){return!0})),P.style("fill",function(e,t,n){return d3.rgb(c(e,t)).darker(h.map(function(e,t){return t}).filter(function(e,t){return!h[t]})[n]).toString()}).style("stroke",function(e,t,n){return d3.rgb(c(e,t)).darker(h.map(function(e,t){return t}).filter(function(e,t){return!h[t]})[n]).toString()})),p?P.attr("transform",function(e,t){return"translate("+o(e.y1)+","+s(u(e,t))+")"}).select("rect").attr("width",function(e,t){return Math.abs(o(a(e,t)+e.y0)-o(e.y0))}).attr("height",s.rangeBand()):P.attr("transform",function(t,n){return"translate("+(a(t,n)<0?o(a(t,n)):o(0))+","+(t.series*s.rangeBand()/e.length+s(u(t,n)))+")"}).select("rect").attr("height",s.rangeBand()/e.length).attr("width",function(e,t){return Math.max(Math.abs(o(a(e,t))-o(0)),1)}),T=s.copy(),N=o.copy()}),C}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=Math.floor(Math.random()*1e4),s=d3.scale.ordinal(),o=d3.scale.linear(),u=function(e){return e.x},a=function(e){return e.y},f=[0],l=e.utils.defaultColor(),c=null,h,p=!1,d=!1,v=!1,m=60,g=d3.format(",.2f"),y=1200,b,w,E,S,x=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),T,N;return C.dispatch=x,C.options=e.utils.optionsFunc.bind(C),C.x=function(e){return arguments.length?(u=e,C):u},C.y=function(e){return arguments.length?(a=e,C):a},C.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,C):t},C.width=function(e){return arguments.length?(n=e,C):n},C.height=function(e){return arguments.length?(r=e,C):r},C.xScale=function(e){return arguments.length?(s=e,C):s},C.yScale=function(e){return arguments.length?(o=e,C):o},C.xDomain=function(e){return arguments.length?(b=e,C):b},C.yDomain=function(e){return arguments.length?(w=e,C):w},C.xRange=function(e){return arguments.length?(E=e,C):E},C.yRange=function(e){return arguments.length?(S=e,C):S},C.forceY=function(e){return arguments.length?(f=e,C):f},C.stacked=function(e){return arguments.length?(p=e,C):p},C.color=function(t){return arguments.length?(l=e.utils.getColor(t),C):l},C.barColor=function(t){return arguments.length?(c=e.utils.getColor(t),C):c},C.disabled=function(e){return arguments.length?(h=e,C):h},C.id=function(e){return arguments.length?(i=e,C):i},C.delay=function(e){return arguments.length?(y=e,C):y},C.showValues=function(e){return arguments.length?(d=e,C):d},C.showBarLabels=function(e){return arguments.length?(v=e,C):v},C.valueFormat=function(e){return arguments.length?(g=e,C):g},C.valuePadding=function(e){return arguments.length?(m=e,C):m},C},e.models.multiBarHorizontalChart=function(){function C(e){return e.each(function(e){var d=d3.select(this),m=this,T=(u||parseInt(d.style("width"))||960)-o.left-o.right,k=(a||parseInt(d.style("height"))||400)-o.top-o.bottom;C.update=function(){d.call(C)},C.container=this,b.disabled=e.map(function(e){return!!e.disabled});if(!w){var L;w={};for(L in b)b[L]instanceof Array?w[L]=b[L].slice(0):w[L]=b[L]}if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var A=d.selectAll(".nv-noData").data([E]);return A.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),A.attr("x",o.left+T/2).attr("y",o.top+k/2).text(function(e){return e}),C}d.selectAll(".nv-noData").remove(),g=t.xScale(),y=t.yScale();var O=d.selectAll("g.nv-wrap.nv-multiBarHorizontalChart").data([e]),M=O.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarHorizontalChart").append("g"),_=O.select("g");M.append("g").attr("class","nv-x nv-axis"),M.append("g").attr("class","nv-y nv-axis").append("g").attr("class","nv-zeroLine").append("line"),M.append("g").attr("class","nv-barsWrap"),M.append("g").attr("class","nv-legendWrap"),M.append("g").attr("class","nv-controlsWrap"),c&&(i.width(T-x()),t.barColor()&&e.forEach(function(e,t){e.color=d3.rgb("#ccc").darker(t*1.5).toString()}),_.select(".nv-legendWrap").datum(e).call(i),o.top!=i.height()&&(o.top=i.height(),k=(a||parseInt(d.style("height"))||400)-o.top-o.bottom),_.select(".nv-legendWrap").attr("transform","translate("+x()+","+ -o.top+")"));if(l){var D=[{key:"Grouped",disabled:t.stacked()},{key:"Stacked",disabled:!t.stacked()}];s.width(x()).color(["#444","#444","#444"]),_.select(".nv-controlsWrap").datum(D).attr("transform","translate(0,"+ -o.top+")").call(s)}O.attr("transform","translate("+o.left+","+o.top+")"),t.disabled(e.map(function(e){return e.disabled})).width(T).height(k).color(e.map(function(e,t){return e.color||f(e,t)}).filter(function(t,n){return!e[n].disabled}));var P=_.select(".nv-barsWrap").datum(e.filter(function(e){return!e.disabled}));P.call(t);if(h){n.scale(g).ticks(k/24).tickSize(-T,0),_.select(".nv-x.nv-axis").call(n);var H=_.select(".nv-x.nv-axis").selectAll("g");H.selectAll("line, text")}p&&(r.scale(y).ticks(T/100).tickSize(-k,0),_.select(".nv-y.nv-axis").attr("transform","translate(0,"+k+")"),_.select(".nv-y.nv-axis").call(r)),_.select(".nv-zeroLine line").attr("x1",y(0)).attr("x2",y(0)).attr("y1",0).attr("y2",-k),i.dispatch.on("stateChange",function(e){b=e,S.stateChange(b),C.update()}),s.dispatch.on("legendClick",function(e,n){if(!e.disabled)return;D=D.map(function(e){return e.disabled=!0,e}),e.disabled=!1;switch(e.key){case"Grouped":t.stacked(!1);break;case"Stacked":t.stacked(!0)}b.stacked=t.stacked(),S.stateChange(b),C.update()}),S.on("tooltipShow",function(e){v&&N(e,m.parentNode)}),S.on("changeState",function(n){typeof n.disabled!="undefined"&&(e.forEach(function(e,t){e.disabled=n.disabled[t]}),b.disabled=n.disabled),typeof n.stacked!="undefined"&&(t.stacked(n.stacked),b.stacked=n.stacked),C.update()})}),C}var t=e.models.multiBarHorizontal(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend().height(30),s=e.models.legend().height(30),o={top:30,right:20,bottom:50,left:60},u=null,a=null,f=e.utils.defaultColor(),l=!0,c=!0,h=!0,p=!0,d=!1,v=!0,m=function(e,t,n,r,i){return"<h3>"+e+" - "+t+"</h3>"+"<p>"+n+"</p>"},g,y,b={stacked:d},w=null,E="No Data Available.",S=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),x=function(){return l?180:0},T=0;t.stacked(d),n.orient("left").tickPadding(5).highlightZero(!1).showMaxMin(!1).tickFormat(function(e){return e}),r.orient("bottom").tickFormat(d3.format(",.1f")),s.updateState(!1);var N=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=m(i.series.key,a,f,i,C);e.tooltip.show([o,u],l,i.value<0?"e":"w",null,s)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+o.left,e.pos[1]+o.top],S.tooltipShow(e)}),t.dispatch.on("elementMouseout.tooltip",function(e){S.tooltipHide(e)}),S.on("tooltipHide",function(){v&&e.tooltip.cleanup()}),C.dispatch=S,C.multibar=t,C.legend=i,C.xAxis=n,C.yAxis=r,d3.rebind(C,t,"x","y","xDomain","yDomain","xRange","yRange","forceX","forceY","clipEdge","id","delay","showValues","showBarLabels","valueFormat","stacked","barColor"),C.options=e.utils.optionsFunc.bind(C),C.margin=function(e){return arguments.length?(o.top=typeof e.top!="undefined"?e.top:o.top,o.right=typeof e.right!="undefined"?e.right:o.right,o.bottom=typeof e.bottom!="undefined"?e.bottom:o.bottom,o.left=typeof e.left!="undefined"?e.left:o.left,C):o},C.width=function(e){return arguments.length?(u=e,C):u},C.height=function(e){return arguments.length?(a=e,C):a},C.color=function(t){return arguments.length?(f=e.utils.getColor(t),i.color(f),C):f},C.showControls=function(e){return arguments.length?(l=e,C):l},C.showLegend=function(e){return arguments.length?(c=e,C):c},C.showXAxis=function(e){return arguments.length?(h=e,C):h},C.showYAxis=function(e){return arguments.length?(p=e,C):p},C.tooltip=function(e){return arguments.length?(m=e,C):m},C.tooltips=function(e){return arguments.length?(v=e,C):v},C.tooltipContent=function(e){return arguments.length?(m=e,C):m},C.state=function(e){return arguments.length?(b=e,C):b},C.defaultState=function(e){return arguments.length?(w=e,C):w},C.noData=function(e){return arguments.length?(E=e,C):E},C.transitionDuration=function(e){return arguments.length?(T=e,C):T},C},e.models.multiChart=function(){function C(e){return e.each(function(e){var u=d3.select(this),f=this;C.update=function(){u.call(C)},C.container=this;var k=(r||parseInt(u.style("width"))||960)-t.left-t.right,L=(i||parseInt(u.style("height"))||400)-t.top-t.bottom,A=e.filter(function(e){return!e.disabled&&e.type=="line"&&e.yAxis==1}),O=e.filter(function(e){return!e.disabled&&e.type=="line"&&e.yAxis==2}),M=e.filter(function(e){return!e.disabled&&e.type=="bar"&&e.yAxis==1}),_=e.filter(function(e){return!e.disabled&&e.type=="bar"&&e.yAxis==2}),D=e.filter(function(e){return!e.disabled&&e.type=="area"&&e.yAxis==1}),P=e.filter(function(e){return!e.disabled&&e.type=="area"&&e.yAxis==2}),H=e.filter(function(e){return!e.disabled&&e.yAxis==1}).map(function(e){return e.values.map(function(e,t){return{x:e.x,y:e.y}})}),B=e.filter(function(e){return!e.disabled&&e.yAxis==2}).map(function(e){return e.values.map(function(e,t){return{x:e.x,y:e.y}})});a.domain(d3.extent(d3.merge(H.concat(B)),function(e){return e.x})).range([0,k]);var j=u.selectAll("g.wrap.multiChart").data([e]),F=j.enter().append("g").attr("class","wrap nvd3 multiChart").append("g");F.append("g").attr("class","x axis"),F.append("g").attr("class","y1 axis"),F.append("g").attr("class","y2 axis"),F.append("g").attr("class","lines1Wrap"),F.append("g").attr("class","lines2Wrap"),F.append("g").attr("class","bars1Wrap"),F.append("g").attr("class","bars2Wrap"),F.append("g").attr("class","stack1Wrap"),F.append("g").attr("class","stack2Wrap"),F.append("g").attr("class","legendWrap");var I=j.select("g");s&&(x.width(k/2),I.select(".legendWrap").datum(e.map(function(e){return e.originalKey=e.originalKey===undefined?e.key:e.originalKey,e.key=e.originalKey+(e.yAxis==1?"":" (right axis)"),e})).call(x),t.top!=x.height()&&(t.top=x.height(),L=(i||parseInt(u.style("height"))||400)-t.top-t.bottom),I.select(".legendWrap").attr("transform","translate("+k/2+","+ -t.top+")")),d.width(k).height(L).interpolate("monotone").color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==1&&e[n].type=="line"})),v.width(k).height(L).interpolate("monotone").color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==2&&e[n].type=="line"})),m.width(k).height(L).color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==1&&e[n].type=="bar"})),g.width(k).height(L).color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==2&&e[n].type=="bar"})),y.width(k).height(L).color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==1&&e[n].type=="area"})),b.width(k).height(L).color(e.map(function(e,t){return e.color||n[t%n.length]}).filter(function(t,n){return!e[n].disabled&&e[n].yAxis==2&&e[n].type=="area"})),I.attr("transform","translate("+t.left+","+t.top+")");var q=I.select(".lines1Wrap").datum(A),R=I.select(".bars1Wrap").datum(M),U=I.select(".stack1Wrap").datum(D),z=I.select(".lines2Wrap").datum(O),W=I.select(".bars2Wrap").datum(_),X=I.select(".stack2Wrap").datum(P),V=D.length?D.map(function(e){return e.values}).reduce(function(e,t){return e.map(function(e,n){return{x:e.x,y:e.y+t[n].y}})}).concat([{x:0,y:0}]):[],$=P.length?P.map(function(e){return e.values}).reduce(function(e,t){return e.map(function(e,n){return{x:e.x,y:e.y+t[n].y}})}).concat([{x:0,y:0}]):[];h.domain(l||d3.extent(d3.merge(H).concat(V),function(e){return e.y})).range([0,L]),p.domain(c||d3.extent(d3.merge(B).concat($),function(e){return e.y})).range([0,L]),d.yDomain(h.domain()),m.yDomain(h.domain()),y.yDomain(h.domain()),v.yDomain(p.domain()),g.yDomain(p.domain()),b.yDomain(p.domain()),D.length&&d3.transition(U).call(y),P.length&&d3.transition(X).call(b),M.length&&d3.transition(R).call(m),_.length&&d3.transition(W).call(g),A.length&&d3.transition(q).call(d),O.length&&d3.transition(z).call(v),w.ticks(k/100).tickSize(-L,0),I.select(".x.axis").attr("transform","translate(0,"+L+")"),d3.transition(I.select(".x.axis")).call(w),E.ticks(L/36).tickSize(-k,0),d3.transition(I.select(".y1.axis")).call(E),S.ticks(L/36).tickSize(-k,0),d3.transition(I.select(".y2.axis")).call(S),I.select(".y2.axis").style("opacity",B.length?1:0).attr("transform","translate("+a.range()[1]+",0)"),x.dispatch.on("stateChange",function(e){C.update()}),T.on("tooltipShow",function(e){o&&N(e,f.parentNode)})}),C}var t={top:30,right:20,bottom:50,left:60},n=d3.scale.category20().range(),r=null,i=null,s=!0,o=!0,u=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" at "+t+"</p>"},a,f,l,c,a=d3.scale.linear(),h=d3.scale.linear(),p=d3.scale.linear(),d=e.models.line().yScale(h),v=e.models.line().yScale(p),m=e.models.multiBar().stacked(!1).yScale(h),g=e.models.multiBar().stacked(!1).yScale(p),y=e.models.stackedArea().yScale(h),b=e.models.stackedArea().yScale(p),w=e.models.axis().scale(a).orient("bottom").tickPadding(5),E=e.models.axis().scale(h).orient("left"),S=e.models.axis().scale(p).orient("right"),x=e.models.legend().height(30),T=d3.dispatch("tooltipShow","tooltipHide"),N=function(t,n){var r=t.pos[0]+(n.offsetLeft||0),i=t.pos[1]+(n.offsetTop||0),s=w.tickFormat()(d.x()(t.point,t.pointIndex)),o=(t.series.yAxis==2?S:E).tickFormat()(d.y()(t.point,t.pointIndex)),a=u(t.series.key,s,o,t,C);e.tooltip.show([r,i],a,undefined,undefined,n.offsetParent)};return d.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),d.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),v.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),v.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),m.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),m.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),g.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),g.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),y.dispatch.on("tooltipShow",function(e){if(!Math.round(y.y()(e.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),y.dispatch.on("tooltipHide",function(e){T.tooltipHide(e)}),b.dispatch.on("tooltipShow",function(e){if(!Math.round(b.y()(e.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),b.dispatch.on("tooltipHide",function(e){T.tooltipHide(e)}),d.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),d.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),v.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],T.tooltipShow(e)}),v.dispatch.on("elementMouseout.tooltip",function(e){T.tooltipHide(e)}),T.on("tooltipHide",function(){o&&e.tooltip.cleanup()}),C.dispatch=T,C.lines1=d,C.lines2=v,C.bars1=m,C.bars2=g,C.stack1=y,C.stack2=b,C.xAxis=w,C.yAxis1=E,C.yAxis2=S,C.options=e.utils.optionsFunc.bind(C),C.x=function(e){return arguments.length?(getX=e,d.x(e),m.x(e),C):getX},C.y=function(e){return arguments.length?(getY=e,d.y(e),m.y(e),C):getY},C.yDomain1=function(e){return arguments.length?(l=e,C):l},C.yDomain2=function(e){return arguments.length?(c=e,C):c},C.margin=function(e){return arguments.length?(t=e,C):t},C.width=function(e){return arguments.length?(r=e,C):r},C.height=function(e){return arguments.length?(i=e,C):i},C.color=function(e){return arguments.length?(n=e,x.color(e),C):n},C.showLegend=function(e){return arguments.length?(s=e,C):s},C.tooltips=function(e){return arguments.length?(o=e,C):o},C.tooltipContent=function(e){return arguments.length?(u=e,C):u},C},e.models.ohlcBar=function(){function x(e){return e.each(function(e){var g=n-t.left-t.right,x=r-t.top-t.bottom,T=d3.select(this);s.domain(y||d3.extent(e[0].values.map(u).concat(p))),v?s.range(w||[g*.5/e[0].values.length,g*(e[0].values.length-.5)/e[0].values.length]):s.range(w||[0,g]),o.domain(b||[d3.min(e[0].values.map(h).concat(d)),d3.max(e[0].values.map(c).concat(d))]).range(E||[x,0]),s.domain()[0]===s.domain()[1]&&(s.domain()[0]?s.domain([s.domain()[0]-s.domain()[0]*.01,s.domain()[1]+s.domain()[1]*.01]):s.domain([-1,1])),o.domain()[0]===o.domain()[1]&&(o.domain()[0]?o.domain([o.domain()[0]+o.domain()[0]*.01,o.domain()[1]-o.domain()[1]*.01]):o.domain([-1,1]));var N=d3.select(this).selectAll("g.nv-wrap.nv-ohlcBar").data([e[0].values]),C=N.enter().append("g").attr("class","nvd3 nv-wrap nv-ohlcBar"),k=C.append("defs"),L=C.append("g"),A=N.select("g");L.append("g").attr("class","nv-ticks"),N.attr("transform","translate("+t.left+","+t.top+")"),T.on("click",function(e,t){S.chartClick({data:e,index:t,pos:d3.event,id:i})}),k.append("clipPath").attr("id","nv-chart-clip-path-"+i).append("rect"),N.select("#nv-chart-clip-path-"+i+" rect").attr("width",g).attr("height",x),A.attr("clip-path",m?"url(#nv-chart-clip-path-"+i+")":"");var O=N.select(".nv-ticks").selectAll(".nv-tick").data(function(e){return e});O.exit().remove();var M=O.enter().append("path").attr("class",function(e,t,n){return(f(e,t)>l(e,t)?"nv-tick negative":"nv-tick positive")+" nv-tick-"+n+"-"+t}).attr("d",function(t,n){var r=g/e[0].values.length*.9;return"m0,0l0,"+(o(f(t,n))-o(c(t,n)))+"l"+ -r/2+",0l"+r/2+",0l0,"+(o(h(t,n))-o(f(t,n)))+"l0,"+(o(l(t,n))-o(h(t,n)))+"l"+r/2+",0l"+ -r/2+",0z"}).attr("transform",function(e,t){return"translate("+s(u(e,t))+","+o(c(e,t))+")"}).on("mouseover",function(t,n){d3.select(this).classed("hover",!0),S.elementMouseover({point:t,series:e[0],pos:[s(u(t,n)),o(a(t,n))],pointIndex:n,seriesIndex:0,e:d3.event})}).on("mouseout",function(t,n){d3.select(this).classed("hover",!1),S.elementMouseout({point:t,series:e[0],pointIndex:n,seriesIndex:0,e:d3.event})}).on("click",function(e,t){S.elementClick({value:a(e,t),data:e,index:t,pos:[s(u(e,t)),o(a(e,t))],e:d3.event,id:i}),d3.event.stopPropagation()}).on("dblclick",function(e,t){S.elementDblClick({value:a(e,t),data:e,index:t,pos:[s(u(e,t)),o(a(e,t))],e:d3.event,id:i}),d3.event.stopPropagation()});O.attr("class",function(e,t,n){return(f(e,t)>l(e,t)?"nv-tick negative":"nv-tick positive")+" nv-tick-"+n+"-"+t}),d3.transition(O).attr("transform",function(e,t){return"translate("+s(u(e,t))+","+o(c(e,t))+")"}).attr("d",function(t,n){var r=g/e[0].values.length*.9;return"m0,0l0,"+(o(f(t,n))-o(c(t,n)))+"l"+ -r/2+",0l"+r/2+",0l0,"+(o(h(t,n))-o(f(t,n)))+"l0,"+(o(l(t,n))-o(h(t,n)))+"l"+r/2+",0l"+ -r/2+",0z"})}),x}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=Math.floor(Math.random()*1e4),s=d3.scale.linear(),o=d3.scale.linear(),u=function(e){return e.x},a=function(e){return e.y},f=function(e){return e.open},l=function(e){return e.close},c=function(e){return e.high},h=function(e){return e.low},p=[],d=[],v=!1,m=!0,g=e.utils.defaultColor(),y,b,w,E,S=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");return x.dispatch=S,x.options=e.utils.optionsFunc.bind(x),x.x=function(e){return arguments.length?(u=e,x):u},x.y=function(e){return arguments.length?(a=e,x):a},x.open=function(e){return arguments.length?(f=e,x):f},x.close=function(e){return arguments.length?(l=e,x):l},x.high=function(e){return arguments.length?(c=e,x):c},x.low=function(e){return arguments.length?(h=e,x):h},x.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,x):t},x.width=function(e){return arguments.length?(n=e,x):n},x.height=function(e){return arguments.length?(r=e,x):r},x.xScale=function(e){return arguments.length?(s=e,x):s},x.yScale=function(e){return arguments.length?(o=e,x):o},x.xDomain=function(e){return arguments.length?(y=e,x):y},x.yDomain=function(e){return arguments.length?(b=e,x):b},x.xRange=function(e){return arguments.length?(w=e,x):w},x.yRange=function(e){return arguments.length?(E=e,x):E},x.forceX=function(e){return arguments.length?(p=e,x):p},x.forceY=function(e){return arguments.length?(d=e,x):d},x.padData=function(e){return arguments.length?(v=e,x):v},x.clipEdge=function(e){return arguments.length?(m=e,x):m},x.color=function(t){return arguments.length?(g=e.utils.getColor(t),x):g},x.id=function(e){return arguments.length?(i=e,x):i},x},e.models.pie=function(){function S(e){return e.each(function(e){function q(e){var t=(e.startAngle+e.endAngle)*90/Math.PI-90;return t>90?t-180:t}function R(e){e.endAngle=isNaN(e.endAngle)?0:e.endAngle,e.startAngle=isNaN(e.startAngle)?0:e.startAngle,m||(e.innerRadius=0);var t=d3.interpolate(this._current,e);return this._current=t(0),function(e){return A(t(e))}}function U(e){e.innerRadius=0;var t=d3.interpolate({startAngle:0,endAngle:0},e);return function(e){return A(t(e))}}var o=n-t.left-t.right,f=r-t.top-t.bottom,S=Math.min(o,f)/2,x=S-S/5,T=d3.select(this),N=T.selectAll(".nv-wrap.nv-pie").data(e),C=N.enter().append("g").attr("class","nvd3 nv-wrap nv-pie nv-chart-"+u),k=C.append("g"),L=N.select("g");k.append("g").attr("class","nv-pie"),k.append("g").attr("class","nv-pieLabels"),N.attr("transform","translate("+t.left+","+t.top+")"),L.select(".nv-pie").attr("transform","translate("+o/2+","+f/2+")"),L.select(".nv-pieLabels").attr("transform","translate("+o/2+","+f/2+")"),T.on("click",function(e,t){E.chartClick({data:e,index:t,pos:d3.event,id:u})});var A=d3.svg.arc().outerRadius(x);y&&A.startAngle(y),b&&A.endAngle(b),m&&A.innerRadius(S*w);var O=d3.layout.pie().sort(null).value(function(e){return e.disabled?0:s(e)}),M=N.select(".nv-pie").selectAll(".nv-slice").data(O),_=N.select(".nv-pieLabels").selectAll(".nv-label").data(O);M.exit().remove(),_.exit().remove();var D=M.enter().append("g").attr("class","nv-slice").on("mouseover",function(e,t){d3.select(this).classed("hover",!0),E.elementMouseover({label:i(e.data),value:s(e.data),point:e.data,pointIndex:t,pos:[d3.event.pageX,d3.event.pageY],id:u})}).on("mouseout",function(e,t){d3.select(this).classed("hover",!1),E.elementMouseout({label:i(e.data),value:s(e.data),point:e.data,index:t,id:u})}).on("click",function(e,t){E.elementClick({label:i(e.data),value:s(e.data),point:e.data,index:t,pos:d3.event,id:u}),d3.event.stopPropagation()}).on("dblclick",function(e,t){E.elementDblClick({label:i(e.data),value:s(e.data),point:e.data,index:t,pos:d3.event,id:u}),d3.event.stopPropagation()});M.attr("fill",function(e,t){return a(e,t)}).attr("stroke",function(e,t){return a(e,t)});var P=D.append("path").each(function(e){this._current=e});M.select("path").attr("d",A);if(l){var H=d3.svg.arc().innerRadius(0);c&&(H=A),h&&(H=d3.svg.arc().outerRadius(A.outerRadius())),_.enter().append("g").classed("nv-label",!0).each(function(e,t){var n=d3.select(this);n.attr("transform",function(e){if(g){e.outerRadius=x+10,e.innerRadius=x+15;var t=(e.startAngle+e.endAngle)/2*(180/Math.PI);return(e.startAngle+e.endAngle)/2<Math.PI?t-=90:t+=90,"translate("+H.centroid(e)+") rotate("+t+")"}return e.outerRadius=S+10,e.innerRadius=S+15,"translate("+H.centroid(e)+")"}),n.append("rect").style("stroke","#fff").style("fill","#fff").attr("rx",3).attr("ry",3),n.append("text").style("text-anchor",g?(e.startAngle+e.endAngle)/2<Math.PI?"start":"end":"middle").style("fill","#000")});var B={},j=14,F=140,I=function(e){return Math.floor(e[0]/F)*F+","+Math.floor(e[1]/j)*j};_.attr("transform",function(e){if(g){e.outerRadius=x+10,e.innerRadius=x+15;var t=(e.startAngle+e.endAngle)/2*(180/Math.PI);return(e.startAngle+e.endAngle)/2<Math.PI?t-=90:t+=90,"translate("+H.centroid(e)+") rotate("+t+")"}e.outerRadius=S+10,e.innerRadius=S+15;var n=H.centroid(e),r=I(n);return B[r]&&(n[1]-=j),B[I(n)]=!0,"translate("+n+")"}),_.select(".nv-label text").style("text-anchor",g?(d.startAngle+d.endAngle)/2<Math.PI?"start":"end":"middle").text(function(e,t){var n=(e.endAngle-e.startAngle)/(2*Math.PI),r={key:i(e.data),value:s(e.data),percent:d3.format("%")(n)};return e.value&&n>v?r[p]:""})}}),S}var t={top:0,right:0,bottom:0,left:0},n=500,r=500,i=function(e){return e.x},s=function(e){return e.y},o=function(e){return e.description},u=Math.floor(Math.random()*1e4),a=e.utils.defaultColor(),f=d3.format(",.2f"),l=!0,c=!0,h=!1,p="key",v=.02,m=!1,g=!1,y=!1,b=!1,w=.5,E=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");return S.dispatch=E,S.options=e.utils.optionsFunc.bind(S),S.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,S):t},S.width=function(e){return arguments.length?(n=e,S):n},S.height=function(e){return arguments.length?(r=e,S):r},S.values=function(t){return e.log("pie.values() is no longer supported."),S},S.x=function(e){return arguments.length?(i=e,S):i},S.y=function(e){return arguments.length?(s=d3.functor(e),S):s},S.description=function(e){return arguments.length?(o=e,S):o},S.showLabels=function(e){return arguments.length?(l=e,S):l},S.labelSunbeamLayout=function(e){return arguments.length?(g=e,S):g},S.donutLabelsOutside=function(e){return arguments.length?(h=e,S):h},S.pieLabelsOutside=function(e){return arguments.length?(c=e,S):c},S.labelType=function(e){return arguments.length?(p=e,p=p||"key",S):p},S.donut=function(e){return arguments.length?(m=e,S):m},S.donutRatio=function(e){return arguments.length?(w=e,S):w},S.startAngle=function(e){return arguments.length?(y=e,S):y},S.endAngle=function(e){return arguments.length?(b=e,S):b},S.id=function(e){return arguments.length?(u=e,S):u},S.color=function(t){return arguments.length?(a=e.utils.getColor(t),S):a},S.valueFormat=function(e){return arguments.length?(f=e,S):f},S.labelThreshold=function(e){return arguments.length?(v=e,S):v},S},e.models.pieChart=function(){function v(e){return e.each(function(e){var u=d3.select(this),a=this,f=(i||parseInt(u.style("width"))||960)-r.left-r.right,d=(s||parseInt(u.style("height"))||400)-r.top-r.bottom;v.update=function(){u.call(v)},v.container=this,l.disabled=e.map(function(e){return!!e.disabled});if(!c){var m;c={};for(m in l)l[m]instanceof Array?c[m]=l[m].slice(0):c[m]=l[m]}if(!e||!e.length){var g=u.selectAll(".nv-noData").data([h]);return g.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),g.attr("x",r.left+f/2).attr("y",r.top+d/2).text(function(e){return e}),v}u.selectAll(".nv-noData").remove();var y=u.selectAll("g.nv-wrap.nv-pieChart").data([e]),b=y.enter().append("g").attr("class","nvd3 nv-wrap nv-pieChart").append("g"),w=y.select("g");b.append("g").attr("class","nv-pieWrap"),b.append("g").attr("class","nv-legendWrap"),o&&(n.width(f).key(t.x()),y.select(".nv-legendWrap").datum(e).call(n),r.top!=n.height()&&(r.top=n.height(),d=(s||parseInt(u.style("height"))||400)-r.top-r.bottom),y.select(".nv-legendWrap").attr("transform","translate(0,"+ -r.top+")")),y.attr("transform","translate("+r.left+","+r.top+")"),t.width(f).height(d);var E=w.select(".nv-pieWrap").datum([e]);d3.transition(E).call(t),n.dispatch.on("stateChange",function(e){l=e,p.stateChange(l),v.update()}),t.dispatch.on("elementMouseout.tooltip",function(e){p.tooltipHide(e)}),p.on("changeState",function(t){typeof t.disabled!="undefined"&&(e.forEach(function(e,n){e.disabled=t.disabled[n]}),l.disabled=t.disabled),v.update()})}),v}var t=e.models.pie(),n=e.models.legend(),r={top:30,right:20,bottom:20,left:20},i=null,s=null,o=!0,u=e.utils.defaultColor(),a=!0,f=function(e,t,n,r){return"<h3>"+e+"</h3>"+"<p>"+t+"</p>"},l={},c=null,h="No Data Available.",p=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),d=function(n,r){var i=t.description()(n.point)||t.x()(n.point),s=n.pos[0]+(r&&r.offsetLeft||0),o=n.pos[1]+(r&&r.offsetTop||0),u=t.valueFormat()(t.y()(n.point)),a=f(i,u,n,v);e.tooltip.show([s,o],a,n.value<0?"n":"s",null,r)};return t.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+r.left,e.pos[1]+r.top],p.tooltipShow(e)}),p.on("tooltipShow",function(e){a&&d(e)}),p.on("tooltipHide",function(){a&&e.tooltip.cleanup()}),v.legend=n,v.dispatch=p,v.pie=t,d3.rebind(v,t,"valueFormat","values","x","y","description","id","showLabels","donutLabelsOutside","pieLabelsOutside","labelType","donut","donutRatio","labelThreshold"),v.options=e.utils.optionsFunc.bind(v),v.margin=function(e){return arguments.length?(r.top=typeof e.top!="undefined"?e.top:r.top,r.right=typeof e.right!="undefined"?e.right:r.right,r.bottom=typeof e.bottom!="undefined"?e.bottom:r.bottom,r.left=typeof e.left!="undefined"?e.left:r.left,v):r},v.width=function(e){return arguments.length?(i=e,v):i},v.height=function(e){return arguments.length?(s=e,v):s},v.color=function(r){return arguments.length?(u=e.utils.getColor(r),n.color(u),t.color(u),v):u},v.showLegend=function(e){return arguments.length?(o=e,v):o},v.tooltips=function(e){return arguments.length?(a=e,v):a},v.tooltipContent=function(e){return arguments.length?(f=e,v):f},v.state=function(e){return arguments.length?(l=e,v):l},v.defaultState=function(e){return arguments.length?(c=e,v):c},v.noData=function(e){return arguments.length?(h=e,v):h},v},e.models.scatter=function(){function I(q){return q.each(function(I){function Q(){if(!g)return!1;var e,i=d3.merge(I.map(function(e,t){return e.values.map(function(e,n){var r=f(e,n),i=l(e,n);return[o(r),u(i),t,n,e]}).filter(function(e,t){return b(e[4],t)})}));if(D===!0){if(x){var a=X.select("defs").selectAll(".nv-point-clips").data([s]).enter();a.append("clipPath").attr("class","nv-point-clips").attr("id","nv-points-clip-"+s);var c=X.select("#nv-points-clip-"+s).selectAll("circle").data(i);c.enter().append("circle").attr("r",T),c.exit().remove(),c.attr("cx",function(e){return e[0]}).attr("cy",function(e){return e[1]}),X.select(".nv-point-paths").attr("clip-path","url(#nv-points-clip-"+s+")")}i.length&&(i.push([o.range()[0]-20,u.range()[0]-20,null,null]),i.push([o.range()[1]+20,u.range()[1]+20,null,null]),i.push([o.range()[0]-20,u.range()[0]+20,null,null]),i.push([o.range()[1]+20,u.range()[1]-20,null,null]));var h=d3.geom.polygon([[-10,-10],[-10,r+10],[n+10,r+10],[n+10,-10]]),p=1e-6;i=i.sort(function(e,t){return e[0]-t[0]||e[1]-t[1]});for(var d=0;d<i.length-1;)Math.abs(i[d][0]-i[d+1][0])<p&&Math.abs(i[d][1]-i[d+1][1])<p?i.splice(d+1,1):d++;var v=d3.geom.voronoi(i).map(function(e,t){return{data:h.clip(e),series:i[t][2],point:i[t][3]}}),m=X.select(".nv-point-paths").selectAll("path").data(v);m.enter().append("path").attr("class",function(e,t){return"nv-path-"+t}),m.exit().remove(),m.attr("d",function(e){return!e||!e.data||e.data.length===0?"M 0 0":"M"+e.data.join("L")+"Z"});var y=function(e,n){if(F)return 0;var r=I[e.series];if(typeof r=="undefined")return;var i=r.values[e.point];n({point:i,series:r,pos:[o(f(i,e.point))+t.left,u(l(i,e.point))+t.top],seriesIndex:e.series,pointIndex:e.point})};m.on("click",function(e){y(e,_.elementClick)}).on("mouseover",function(e){y(e,_.elementMouseover)}).on("mouseout",function(e,t){y(e,_.elementMouseout)})}else X.select(".nv-groups").selectAll(".nv-group").selectAll(".nv-point").on("click",function(e,n){if(F||!I[e.series])return 0;var r=I[e.series],i=r.values[n];_.elementClick({point:i,series:r,pos:[o(f(i,n))+t.left,u(l(i,n))+t.top],seriesIndex:e.series,pointIndex:n})}).on("mouseover",function(e,n){if(F||!I[e.series])return 0;var r=I[e.series],i=r.values[n];_.elementMouseover({point:i,series:r,pos:[o(f(i,n))+t.left,u(l(i,n))+t.top],seriesIndex:e.series,pointIndex:n})}).on("mouseout",function(e,t){if(F||!I[e.series])return 0;var n=I[e.series],r=n.values[t];_.elementMouseout({point:r,series:n,seriesIndex:e.series,pointIndex:t})});F=!1}var q=n-t.left-t.right,R=r-t.top-t.bottom,U=d3.select(this);I.forEach(function(e,t){e.values.forEach(function(e){e.series=t})});var W=N&&C&&A?[]:d3.merge(I.map(function(e){return e.values.map(function(e,t){return{x:f(e,t),y:l(e,t),size:c(e,t)}})}));o.domain(N||d3.extent(W.map(function(e){return e.x}).concat(d))),w&&I[0]?o.range(k||[(q*E+q)/(2*I[0].values.length),q-q*(1+E)/(2*I[0].values.length)]):o.range(k||[0,q]),u.domain(C||d3.extent(W.map(function(e){return e.y}).concat(v))).range(L||[R,0]),a.domain(A||d3.extent(W.map(function(e){return e.size}).concat(m))).range(O||[16,256]);if(o.domain()[0]===o.domain()[1]||u.domain()[0]===u.domain()[1])M=!0;o.domain()[0]===o.domain()[1]&&(o.domain()[0]?o.domain([o.domain()[0]-o.domain()[0]*.01,o.domain()[1]+o.domain()[1]*.01]):o.domain([-1,1])),u.domain()[0]===u.domain()[1]&&(u.domain()[0]?u.domain([u.domain()[0]-u.domain()[0]*.01,u.domain()[1]+u.domain()[1]*.01]):u.domain([-1,1])),isNaN(o.domain()[0])&&o.domain([-1,1]),isNaN(u.domain()[0])&&u.domain([-1,1]),P=P||o,H=H||u,B=B||a;var X=U.selectAll("g.nv-wrap.nv-scatter").data([I]),V=X.enter().append("g").attr("class","nvd3 nv-wrap nv-scatter nv-chart-"+s+(M?" nv-single-point":"")),$=V.append("defs"),J=V.append("g"),K=X.select("g");J.append("g").attr("class","nv-groups"),J.append("g").attr("class","nv-point-paths"),X.attr("transform","translate("+t.left+","+t.top+")"),$.append("clipPath").attr("id","nv-edge-clip-"+s).append("rect"),X.select("#nv-edge-clip-"+s+" rect").attr("width",q).attr("height",R>0?R:0),K.attr("clip-path",S?"url(#nv-edge-clip-"+s+")":""),F=!0;var G=X.select(".nv-groups").selectAll(".nv-group").data(function(e){return e},function(e){return e.key});G.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),G.exit().remove(),G.attr("class",function(e,t){return"nv-group nv-series-"+t}).classed("hover",function(e){return e.hover}),G.style("fill",function(e,t){return i(e,t)}).style("stroke",function(e,t){return i(e,t)}).style("stroke-opacity",1).style("fill-opacity",.5);if(p){var Y=G.selectAll("circle.nv-point").data(function(e){return e.values},y);Y.enter().append("circle").style("fill",function(e,t){return e.color}).style("stroke",function(e,t){return e.color}).attr("cx",function(t,n){return e.utils.NaNtoZero(P(f(t,n)))}).attr("cy",function(t,n){return e.utils.NaNtoZero(H(l(t,n)))}).attr("r",function(e,t){return Math.sqrt(a(c(e,t))/Math.PI)}),Y.exit().remove(),G.exit().selectAll("path.nv-point").attr("cx",function(t,n){return e.utils.NaNtoZero(o(f(t,n)))}).attr("cy",function(t,n){return e.utils.NaNtoZero(u(l(t,n)))}).remove(),Y.each(function(e,t){d3.select(this).classed("nv-point",!0).classed("nv-point-"+t,!0).classed("hover",!1)}),Y.attr("cx",function(t,n){return e.utils.NaNtoZero(o(f(t,n)))}).attr("cy",function(t,n){return e.utils.NaNtoZero(u(l(t,n)))}).attr("r",function(e,t){return Math.sqrt(a(c(e,t))/Math.PI)})}else{var Y=G.selectAll("path.nv-point").data(function(e){return e.values});Y.enter().append("path").style("fill",function(e,t){return e.color}).style("stroke",function(e,t){return e.color}).attr("transform",function(e,t){return"translate("+P(f(e,t))+","+H(l(e,t))+")"}).attr("d",d3.svg.symbol().type(h).size(function(e,t){return a(c(e,t))})),Y.exit().remove(),G.exit().selectAll("path.nv-point").attr("transform",function(e,t){return"translate("+o(f(e,t))+","+u(l(e,t))+")"}).remove(),Y.each(function(e,t){d3.select(this).classed("nv-point",!0).classed("nv-point-"+t,!0).classed("hover",!1)}),Y.attr("transform",function(e,t){return"translate("+o(f(e,t))+","+u(l(e,t))+")"}).attr("d",d3.svg.symbol().type(h).size(function(e,t){return a(c(e,t))}))}clearTimeout(j),j=setTimeout(Q,300),P=o.copy(),H=u.copy(),B=a.copy()}),I}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=e.utils.defaultColor(),s=Math.floor(Math.random()*1e5),o=d3.scale.linear(),u=d3.scale.linear(),a=d3.scale.linear(),f=function(e){return e.x},l=function(e){return e.y},c=function(e){return e.size||1},h=function(e){return e.shape||"circle"},p=!0,d=[],v=[],m=[],g=!0,y=null,b=function(e){return!e.notActive},w=!1,E=.1,S=!1,x=!0,T=function(){return 25},N=null,C=null,k=null,L=null,A=null,O=null,M=!1,_=d3.dispatch("elementClick","elementMouseover","elementMouseout"),D=!0,P,H,B,j,F=!1;return I.clearHighlights=function(){d3.selectAll(".nv-chart-"+s+" .nv-point.hover").classed("hover",!1)},I.highlightPoint=function(e,t,n){d3.select(".nv-chart-"+s+" .nv-series-"+e+" .nv-point-"+t).classed("hover",n)},_.on("elementMouseover.point",function(e){g&&I.highlightPoint(e.seriesIndex,e.pointIndex,!0)}),_.on("elementMouseout.point",function(e){g&&I.highlightPoint(e.seriesIndex,e.pointIndex,!1)}),I.dispatch=_,I.options=e.utils.optionsFunc.bind(I),I.x=function(e){return arguments.length?(f=d3.functor(e),I):f},I.y=function(e){return arguments.length?(l=d3.functor(e),I):l},I.size=function(e){return arguments.length?(c=d3.functor(e),I):c},I.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,I):t},I.width=function(e){return arguments.length?(n=e,I):n},I.height=function(e){return arguments.length?(r=e,I):r},I.xScale=function(e){return arguments.length?(o=e,I):o},I.yScale=function(e){return arguments.length?(u=e,I):u},I.zScale=function(e){return arguments.length?(a=e,I):a},I.xDomain=function(e){return arguments.length?(N=e,I):N},I.yDomain=function(e){return arguments.length?(C=e,I):C},I.sizeDomain=function(e){return arguments.length?(A=e,I):A},I.xRange=function(e){return arguments.length?(k=e,I):k},I.yRange=function(e){return arguments.length?(L=e,I):L},I.sizeRange=function(e){return arguments.length?(O=e,I):O},I.forceX=function(e){return arguments.length?(d=e,I):d},I.forceY=function(e){return arguments.length?(v=e,I):v},I.forceSize=function(e){return arguments.length?(m=e,I):m},I.interactive=function(e){return arguments.length?(g=e,I):g},I.pointKey=function(e){return arguments.length?(y=e,I):y},I.pointActive=function(e){return arguments.length?(b=e,I):b},I.padData=function(e){return arguments.length?(w=e,I):w},I.padDataOuter=function(e){return arguments.length?(E=e,I):E},I.clipEdge=function(e){return arguments.length?(S=e,I):S},I.clipVoronoi=function(e){return arguments.length?(x=e,I):x},I.useVoronoi=function(e){return arguments.length?(D=e,D===!1&&(x=!1),I):D},I.clipRadius=function(e){return arguments.length?(T=e,I):T},I.color=function(t){return arguments.length?(i=e.utils.getColor(t),I):i},I.shape=function(e){return arguments.length?(h=e,I):h},I.onlyCircles=function(e){return arguments.length?(p=e,I):p},I.id=function(e){return arguments.length?(s=e,I):s},I.singlePoint=function(e){return arguments.length?(M=e,I):M},I},e.models.scatterChart=function(){function F(e){return e.each(function(e){function J(){if(T)return W.select(".nv-point-paths").style("pointer-events","all"),!1;W.select(".nv-point-paths").style("pointer-events","none");var i=d3.mouse(this);h.distortion(x).focus(i[0]),p.distortion(x).focus(i[1]),W.select(".nv-scatterWrap").call(t),b&&W.select(".nv-x.nv-axis").call(n),w&&W.select(".nv-y.nv-axis").call(r),W.select(".nv-distributionX").datum(e.filter(function(e){return!e.disabled})).call(o),W.select(".nv-distributionY").datum(e.filter(function(e){return!e.disabled})).call(u)}var C=d3.select(this),k=this,L=(f||parseInt(C.style("width"))||960)-a.left-a.right,D=(l||parseInt(C.style("height"))||400)-a.top-a.bottom;F.update=function(){C.call(F)},F.container=this,A.disabled=e.map(function(e){return!!e.disabled});if(!O){var I;O={};for(I in A)A[I]instanceof Array?O[I]=A[I].slice(0):O[I]=A[I]}if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var q=C.selectAll(".nv-noData").data([_]);return q.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),q.attr("x",a.left+L/2).attr("y",a.top+D/2).text(function(e){return e}),F}C.selectAll(".nv-noData").remove(),P=P||h,H=H||p;var R=C.selectAll("g.nv-wrap.nv-scatterChart").data([e]),U=R.enter().append("g").attr("class","nvd3 nv-wrap nv-scatterChart nv-chart-"+t.id()),z=U.append("g"),W=R.select("g");z.append("rect").attr("class","nvd3 nv-background"),z.append("g").attr("class","nv-x nv-axis"),z.append("g").attr("class","nv-y nv-axis"),z.append("g").attr("class","nv-scatterWrap"),z.append("g").attr("class","nv-distWrap"),z.append("g").attr("class","nv-legendWrap"),z.append("g").attr("class","nv-controlsWrap");if(y){var X=S?L/2:L;i.width(X),R.select(".nv-legendWrap").datum(e).call(i),a.top!=i.height()&&(a.top=i.height(),D=(l||parseInt(C.style("height"))||400)-a.top-a.bottom),R.select(".nv-legendWrap").attr("transform","translate("+(L-X)+","+ -a.top+")")}S&&(s.width(180).color(["#444"]),W.select(".nv-controlsWrap").datum(j).attr("transform","translate(0,"+ -a.top+")").call(s)),R.attr("transform","translate("+a.left+","+a.top+")"),E&&W.select(".nv-y.nv-axis").attr("transform","translate("+L+",0)"),t.width(L).height(D).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),d!==0&&t.xDomain(null),v!==0&&t.yDomain(null),R.select(".nv-scatterWrap").datum(e.filter(function(e){return!e.disabled})).call(t);if(d!==0){var V=h.domain()[1]-h.domain()[0];t.xDomain([h.domain()[0]-d*V,h.domain()[1]+d*V])}if(v!==0){var $=p.domain()[1]-p.domain()[0];t.yDomain([p.domain()[0]-v*$,p.domain()[1]+v*$])}(v!==0||d!==0)&&R.select(".nv-scatterWrap").datum(e.filter(function(e){return!e.disabled})).call(t),b&&(n.scale(h).ticks(n.ticks()&&n.ticks().length?n.ticks():L/100).tickSize(-D,0),W.select(".nv-x.nv-axis").attr("transform","translate(0,"+p.range()[0]+")").call(n)),w&&(r.scale(p).ticks(r.ticks()&&r.ticks().length?r.ticks():D/36).tickSize(-L,0),W.select(".nv-y.nv-axis").call(r)),m&&(o.getData(t.x()).scale(h).width(L).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),z.select(".nv-distWrap").append("g").attr("class","nv-distributionX"),W.select(".nv-distributionX").attr("transform","translate(0,"+p.range()[0]+")").datum(e.filter(function(e){return!e.disabled})).call(o)),g&&(u.getData(t.y()).scale(p).width(D).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),z.select(".nv-distWrap").append("g").attr("class","nv-distributionY"),W.select(".nv-distributionY").attr("transform","translate("+(E?L:-u.size())+",0)").datum(e.filter(function(e){return!e.disabled})).call(u)),d3.fisheye&&(W.select(".nv-background").attr("width",L).attr("height",D),W.select(".nv-background").on("mousemove",J),W.select(".nv-background").on("click",function(){T=!T}),t.dispatch.on("elementClick.freezeFisheye",function(){T=!T})),s.dispatch.on("legendClick",function(e,i){e.disabled=!e.disabled,x=e.disabled?0:2.5,W.select(".nv-background").style("pointer-events",e.disabled?"none":"all"),W.select(".nv-point-paths").style("pointer-events",e.disabled?"all":"none"),e.disabled?(h.distortion(x).focus(0),p.distortion(x).focus(0),W.select(".nv-scatterWrap").call(t),W.select(".nv-x.nv-axis").call(n),W.select(".nv-y.nv-axis").call(r)):T=!1,F.update()}),i.dispatch.on("stateChange",function(e){A.disabled=e.disabled,M.stateChange(A),F.update()}),t.dispatch.on("elementMouseover.tooltip",function(e){d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-distx-"+e.pointIndex).attr("y1",function(t,n){return e.pos[1]-D}),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-disty-"+e.pointIndex).attr("x2",e.pos[0]+o.size()),e.pos=[e.pos[0]+a.left,e.pos[1]+a.top],M.tooltipShow(e)}),M.on("tooltipShow",function(e){N&&B(e,k.parentNode)}),M.on("changeState",function(t){typeof t.disabled!="undefined"&&(e.forEach(function(e,n){e.disabled=t.disabled[n]}),A.disabled=t.disabled),F.update()}),P=h.copy(),H=p.copy()}),F}var t=e.models.scatter(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.models.legend(),o=e.models.distribution(),u=e.models.distribution(),a={top:30,right:20,bottom:50,left:75},f=null,l=null,c=e.utils.defaultColor(),h=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):t.xScale(),p=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):t.yScale(),d=0,v=0,m=!1,g=!1,y=!0,b=!0,w=!0,E=!1,S=!!d3.fisheye,x=0,T=!1,N=!0,C=function(e,t,n){return"<strong>"+t+"</strong>"},k=function(e,t,n){return"<strong>"+n+"</strong>"},L=null,A={},O=null,M=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),_="No Data Available.",D=0;t.xScale(h).yScale(p),n.orient("bottom").tickPadding(10),r.orient(E?"right":"left").tickPadding(10),o.axis("x"),u.axis("y"),s.updateState(!1);var P,H,B=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),f=i.pos[0]+(s.offsetLeft||0),l=p.range()[0]+a.top+(s.offsetTop||0),c=h.range()[0]+a.left+(s.offsetLeft||0),d=i.pos[1]+(s.offsetTop||0),v=n.tickFormat()(t.x()(i.point,i.pointIndex)),m=r.tickFormat()(t.y()(i.point,i.pointIndex));C!=null&&e.tooltip.show([f,l],C(i.series.key,v,m,i,F),"n",1,s,"x-nvtooltip"),k!=null&&e.tooltip.show([c,d],k(i.series.key,v,m,i,F),"e",1,s,"y-nvtooltip"),L!=null&&e.tooltip.show([o,u],L(i.series.key,v,m,i,F),i.value<0?"n":"s",null,s)},j=[{key:"Magnify",disabled:!0}];return t.dispatch.on("elementMouseout.tooltip",function(e){M.tooltipHide(e),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-distx-"+e.pointIndex).attr("y1",0),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-disty-"+e.pointIndex).attr("x2",u.size())}),M.on("tooltipHide",function(){N&&e.tooltip.cleanup()}),F.dispatch=M,F.scatter=t,F.legend=i,F.controls=s,F.xAxis=n,F.yAxis=r,F.distX=o,F.distY=u,d3.rebind(F,t,"id","interactive","pointActive","x","y","shape","size","xScale","yScale","zScale","xDomain","yDomain","xRange","yRange","sizeDomain","sizeRange","forceX","forceY","forceSize","clipVoronoi","clipRadius","useVoronoi"),F.options=e.utils.optionsFunc.bind(F),F.margin=function(e){return arguments.length?(a.top=typeof e.top!="undefined"?e.top:a.top,a.right=typeof e.right!="undefined"?e.right:a.right,a.bottom=typeof e.bottom!="undefined"?e.bottom:a.bottom,a.left=typeof e.left!="undefined"?e.left:a.left,F):a},F.width=function(e){return arguments.length?(f=e,F):f},F.height=function(e){return arguments.length?(l=e,F):l},F.color=function(t){return arguments.length?(c=e.utils.getColor(t),i.color(c),o.color(c),u.color(c),F):c},F.showDistX=function(e){return arguments.length?(m=e,F):m},F.showDistY=function(e){return arguments.length?(g=e,F):g},F.showControls=function(e){return arguments.length?(S=e,F):S},F.showLegend=function(e){return arguments.length?(y=e,F):y},F.showXAxis=function(e){return arguments.length?(b=e,F):b},F.showYAxis=function(e){return arguments.length?(w=e,F):w},F.rightAlignYAxis=function(e){return arguments.length?(E=e,r.orient(e?"right":"left"),F):E},F.fisheye=function(e){return arguments.length?(x=e,F):x},F.xPadding=function(e){return arguments.length?(d=e,F):d},F.yPadding=function(e){return arguments.length?(v=e,F):v},F.tooltips=function(e){return arguments.length?(N=e,F):N},F.tooltipContent=function(e){return arguments.length?(L=e,F):L},F.tooltipXContent=function(e){return arguments.length?(C=e,F):C},F.tooltipYContent=function(e){return arguments.length?(k=e,F):k},F.state=function(e){return arguments.length?(A=e,F):A},F.defaultState=function(e){return arguments.length?(O=e,F):O},F.noData=function(e){return arguments.length?(_=e,F):_},F.transitionDuration=function(e){return arguments.length?(D=e,F):D},F},e.models.scatterPlusLineChart=function(){function B(e){return e.each(function(e){function V(){if(S)return U.select(".nv-point-paths").style("pointer-events","all"),!1;U.select(".nv-point-paths").style("pointer-events","none");var i=d3.mouse(this);h.distortion(E).focus(i[0]),p.distortion(E).focus(i[1]),U.select(".nv-scatterWrap").datum(e.filter(function(e){return!e.disabled})).call(t),g&&U.select(".nv-x.nv-axis").call(n),y&&U.select(".nv-y.nv-axis").call(r),U.select(".nv-distributionX").datum(e.filter(function(e){return!e.disabled})).call(o),U.select(".nv-distributionY").datum(e.filter(function(e){return!e.disabled})).call(u)}var T=d3.select(this),N=this,C=(f||parseInt(T.style("width"))||960)-a.left-a.right,M=(l||parseInt(T.style("height"))||400)-a.top-a.bottom;B.update=function(){T.call(B)},B.container=this,k.disabled=e.map(function(e){return!!e.disabled});if(!L){var j;L={};for(j in k)k[j]instanceof Array?L[j]=k[j].slice(0):L[j]=k[j]}if(!e||!e.length||!e.filter(function(e){return e.values.length}).length){var F=T.selectAll(".nv-noData").data([O]);return F.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),F.attr("x",a.left+C/2).attr("y",a.top+M/2).text(function(e){return e}),B}T.selectAll(".nv-noData").remove(),h=t.xScale(),p=t.yScale(),_=_||h,D=D||p;var I=T.selectAll("g.nv-wrap.nv-scatterChart").data([e]),q=I.enter().append("g").attr("class","nvd3 nv-wrap nv-scatterChart nv-chart-"+t.id()),R=q.append("g"),U=I.select("g");R.append("rect").attr("class","nvd3 nv-background").style("pointer-events","none"),R.append("g").attr("class","nv-x nv-axis"),R.append("g").attr("class","nv-y nv-axis"),R.append("g").attr("class","nv-scatterWrap"),R.append("g").attr("class","nv-regressionLinesWrap"),R.append("g").attr("class","nv-distWrap"),R.append("g").attr("class","nv-legendWrap"),R.append("g").attr("class","nv-controlsWrap"),I.attr("transform","translate("+a.left+","+a.top+")"),b&&U.select(".nv-y.nv-axis").attr("transform","translate("+C+",0)"),m&&(i.width(C/2),I.select(".nv-legendWrap").datum(e).call(i),a.top!=i.height()&&(a.top=i.height(),M=(l||parseInt(T.style("height"))||400)-a.top-a.bottom),I.select(".nv-legendWrap").attr("transform","translate("+C/2+","+ -a.top+")")),w&&(s.width(180).color(["#444"]),U.select(".nv-controlsWrap").datum(H).attr("transform","translate(0,"+ -a.top+")").call(s)),t.width(C).height(M).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),I.select(".nv-scatterWrap").datum(e.filter(function(e){return!e.disabled})).call(t),I.select(".nv-regressionLinesWrap").attr("clip-path","url(#nv-edge-clip-"+t.id()+")");var z=I.select(".nv-regressionLinesWrap").selectAll(".nv-regLines").data(function(e){return e});z.enter().append("g").attr("class","nv-regLines");var W=z.selectAll(".nv-regLine").data(function(e){return[e]}),X=W.enter().append("line").attr("class","nv-regLine").style("stroke-opacity",0);W.attr("x1",h.range()[0]).attr("x2",h.range()[1]).attr("y1",function(e,t){return p(h.domain()[0]*e.slope+e.intercept)}).attr("y2",function(e,t){return p(h.domain()[1]*e.slope+e.intercept)}).style("stroke",function(e,t,n){return c(e,n)}).style("stroke-opacity",function(e,t){return e.disabled||typeof e.slope=="undefined"||typeof e.intercept=="undefined"?0:1}),g&&(n.scale(h).ticks(n.ticks()?n.ticks():C/100).tickSize(-M,0),U.select(".nv-x.nv-axis").attr("transform","translate(0,"+p.range()[0]+")").call(n)),y&&(r.scale(p).ticks(r.ticks()?r.ticks():M/36).tickSize(-C,0),U.select(".nv-y.nv-axis").call(r)),d&&(o.getData(t.x()).scale(h).width(C).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),R.select(".nv-distWrap").append("g").attr("class","nv-distributionX"),U.select(".nv-distributionX").attr("transform","translate(0,"+p.range()[0]+")").datum(e.filter(function(e){return!e.disabled})).call(o)),v&&(u.getData(t.y()).scale(p).width(M).color(e.map(function(e,t){return e.color||c(e,t)}).filter(function(t,n){return!e[n].disabled})),R.select(".nv-distWrap").append("g").attr("class","nv-distributionY"),U.select(".nv-distributionY").attr("transform","translate("+(b?C:-u.size())+",0)").datum(e.filter(function(e){return!e.disabled})).call(u)),d3.fisheye&&(U.select(".nv-background").attr("width",C).attr("height",M),U.select(".nv-background").on("mousemove",V),U.select(".nv-background").on("click",function(){S=!S}),t.dispatch.on("elementClick.freezeFisheye",function(){S=!S})),s.dispatch.on("legendClick",function(e,i){e.disabled=!e.disabled,E=e.disabled?0:2.5,U.select(".nv-background").style("pointer-events",e.disabled?"none":"all"),U.select(".nv-point-paths").style("pointer-events",e.disabled?"all":"none"),e.disabled?(h.distortion(E).focus(0),p.distortion(E).focus(0),U.select(".nv-scatterWrap").call(t),U.select(".nv-x.nv-axis").call(n),U.select(".nv-y.nv-axis").call(r)):S=!1,B.update()}),i.dispatch.on("stateChange",function(e){k=e,A.stateChange(k),B.update()}),t.dispatch.on("elementMouseover.tooltip",function(e){d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-distx-"+e.pointIndex).attr("y1",e.pos[1]-M),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-disty-"+e.pointIndex).attr("x2",e.pos[0]+o.size()),e.pos=[e.pos[0]+a.left,e.pos[1]+a.top],A.tooltipShow(e)}),A.on("tooltipShow",function(e){x&&P(e,N.parentNode)}),A.on("changeState",function(t){typeof t.disabled!="undefined"&&(e.forEach(function(e,n){e.disabled=t.disabled[n]}),k.disabled=t.disabled),B.update()}),_=h.copy(),D=p.copy()}),B}var t=e.models.scatter(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.models.legend(),o=e.models.distribution(),u=e.models.distribution(),a={top:30,right:20,bottom:50,left:75},f=null,l=null,c=e.utils.defaultColor(),h=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):t.xScale(),p=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):t.yScale(),d=!1,v=!1,m=!0,g=!0,y=!0,b=!1,w=!!d3.fisheye,E=0,S=!1,x=!0,T=function(e,t,n){return"<strong>"+t+"</strong>"},N=function(e,t,n){return"<strong>"+n+"</strong>"},C=function(e,t,n,r){return"<h3>"+e+"</h3>"+"<p>"+r+"</p>"},k={},L=null,A=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),O="No Data Available.",M=0;t.xScale(h).yScale(p),n.orient("bottom").tickPadding(10),r.orient(b?"right":"left").tickPadding(10),o.axis("x"),u.axis("y"),s.updateState(!1);var _,D,P=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),f=i.pos[0]+(s.offsetLeft||0),l=p.range()[0]+a.top+(s.offsetTop||0),c=h.range()[0]+a.left+(s.offsetLeft||0),d=i.pos[1]+(s.offsetTop||0),v=n.tickFormat()(t.x()(i.point,i.pointIndex)),m=r.tickFormat()(t.y()(i.point,i.pointIndex));T!=null&&e.tooltip.show([f,l],T(i.series.key,v,m,i,B),"n",1,s,"x-nvtooltip"),N!=null&&e.tooltip.show([c,d],N(i.series.key,v,m,i,B),"e",1,s,"y-nvtooltip"),C!=null&&e.tooltip.show([o,u],C(i.series.key,v,m,i.point.tooltip,i,B),i.value<0?"n":"s",null,s)},H=[{key:"Magnify",disabled:!0}];return t.dispatch.on("elementMouseout.tooltip",function(e){A.tooltipHide(e),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-distx-"+e.pointIndex).attr("y1",0),d3.select(".nv-chart-"+t.id()+" .nv-series-"+e.seriesIndex+" .nv-disty-"+e.pointIndex).attr("x2",u.size())}),A.on("tooltipHide",function(){x&&e.tooltip.cleanup()}),B.dispatch=A,B.scatter=t,B.legend=i,B.controls=s,B.xAxis=n,B.yAxis=r,B.distX=o,B.distY=u,d3.rebind(B,t,"id","interactive","pointActive","x","y","shape","size","xScale","yScale","zScale","xDomain","yDomain","xRange","yRange","sizeDomain","sizeRange","forceX","forceY","forceSize","clipVoronoi","clipRadius","useVoronoi"),B.options=e.utils.optionsFunc.bind(B),B.margin=function(e){return arguments.length?(a.top=typeof e.top!="undefined"?e.top:a.top,a.right=typeof e.right!="undefined"?e.right:a.right,a.bottom=typeof e.bottom!="undefined"?e.bottom:a.bottom,a.left=typeof e.left!="undefined"?e.left:a.left,B):a},B.width=function(e){return arguments.length?(f=e,B):f},B.height=function(e){return arguments.length?(l=e,B):l},B.color=function(t){return arguments.length?(c=e.utils.getColor(t),i.color(c),o.color(c),u.color(c),B):c},B.showDistX=function(e){return arguments.length?(d=e,B):d},B.showDistY=function(e){return arguments.length?(v=e,B):v},B.showControls=function(e){return arguments.length?(w=e,B):w},B.showLegend=function(e){return arguments.length?(m=e,B):m},B.showXAxis=function(e){return arguments.length?(g=e,B):g},B.showYAxis=function(e){return arguments.length?(y=e,B):y},B.rightAlignYAxis=function(e){return arguments.length?(b=e,r.orient(e?"right":"left"),B):b},B.fisheye=function(e){return arguments.length?(E=e,B):E},B.tooltips=function(e){return arguments.length?(x=e,B):x},B.tooltipContent=function(e){return arguments.length?(C=e,B):C},B.tooltipXContent=function(e){return arguments.length?(T=e,B):T},B.tooltipYContent=function(e){return arguments.length?(N=e,B):N},B.state=function(e){return arguments.length?(k=e,B):k},B.defaultState=function(e){return arguments.length?(L=e,B):L},B.noData=function(e){return arguments.length?(O=e,B):O},B.transitionDuration=function(e){return arguments.length?(M=e,B):M},B},e.models.sparkline=function(){function d(e){return e.each(function(e){var i=n-t.left-t.right,d=r-t.top-t.bottom,v=d3.select(this);s.domain(l||d3.extent(e,u)).range(h||[0,i]),o.domain(c||d3.extent(e,a)).range(p||[d,0]);var m=v.selectAll("g.nv-wrap.nv-sparkline").data([e]),g=m.enter().append("g").attr("class","nvd3 nv-wrap nv-sparkline"),b=g.append("g"),w=m.select("g");m.attr("transform","translate("+t.left+","+t.top+")");var E=m.selectAll("path").data(function(e){return[e]});E.enter().append("path"),E.exit().remove(),E.style("stroke",function(e,t){return e.color||f(e,t)}).attr("d",d3.svg.line().x(function(e,t){return s(u(e,t))}).y(function(e,t){return o(a(e,t))}));var S=m.selectAll("circle.nv-point").data(function(e){function n(t){if(t!=-1){var n=e[t];return n.pointIndex=t,n}return null}var t=e.map(function(e,t){return a(e,t)}),r=n(t.lastIndexOf(o.domain()[1])),i=n(t.indexOf(o.domain()[0])),s=n(t.length-1);return[i,r,s].filter(function(e){return e!=null})});S.enter().append("circle"),S.exit().remove(),S.attr("cx",function(e,t){return s(u(e,e.pointIndex))}).attr("cy",function(e,t){return o(a(e,e.pointIndex))}).attr("r",2).attr("class",function(e,t){return u(e,e.pointIndex)==s.domain()[1]?"nv-point nv-currentValue":a(e,e.pointIndex)==o.domain()[0]?"nv-point nv-minValue":"nv-point nv-maxValue"})}),d}var t={top:2,right:0,bottom:2,left:0},n=400,r=32,i=!0,s=d3.scale.linear(),o=d3.scale.linear(),u=function(e){return e.x},a=function(e){return e.y},f=e.utils.getColor(["#000"]),l,c,h,p;return d.options=e.utils.optionsFunc.bind(d),d.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,d):t},d.width=function(e){return arguments.length?(n=e,d):n},d.height=function(e){return arguments.length?(r=e,d):r},d.x=function(e){return arguments.length?(u=d3.functor(e),d):u},d.y=function(e){return arguments.length?(a=d3.functor(e),d):a},d.xScale=function(e){return arguments.length?(s=e,d):s},d.yScale=function(e){return arguments.length?(o=e,d):o},d.xDomain=function(e){return arguments.length?(l=e,d):l},d.yDomain=function(e){return arguments.length?(c=e,d):c},d.xRange=function(e){return arguments.length?(h=e,d):h},d.yRange=function(e){return arguments.length?(p=e,d):p},d.animate=function(e){return arguments.length?(i=e,d):i},d.color=function(t){return arguments.length?(f=e.utils.getColor(t),d):f},d},e.models.sparklinePlus=function(){function v(e){return e.each(function(c){function O(){if(a)return;var e=C.selectAll(".nv-hoverValue").data(u),r=e.enter().append("g").attr("class","nv-hoverValue").style("stroke-opacity",0).style("fill-opacity",0);e.exit().style("stroke-opacity",0).style("fill-opacity",0).remove(),e.attr("transform",function(e){return"translate("+s(t.x()(c[e],e))+",0)"}).style("stroke-opacity",1).style("fill-opacity",1);if(!u.length)return;r.append("line").attr("x1",0).attr("y1",-n.top).attr("x2",0).attr("y2",b),r.append("text").attr("class","nv-xValue").attr("x",-6).attr("y",-n.top).attr("text-anchor","end").attr("dy",".9em"),C.select(".nv-hoverValue .nv-xValue").text(f(t.x()(c[u[0]],u[0]))),r.append("text").attr("class","nv-yValue").attr("x",6).attr("y",-n.top).attr("text-anchor","start").attr("dy",".9em"),C.select(".nv-hoverValue .nv-yValue").text(l(t.y()(c[u[0]],u[0])))}function M(){function r(e,n){var r=Math.abs(t.x()(e[0],0)-n),i=0;for(var s=0;s<e.length;s++)Math.abs(t.x()(e[s],s)-n)<r&&(r=Math.abs(t.x()(e[s],s)-n),i=s);return i}if(a)return;var e=d3.mouse(this)[0]-n.left;u=[r(c,Math.round(s.invert(e)))],O()}var m=d3.select(this),g=(r||parseInt(m.style("width"))||960)-n.left-n.right,b=(i||parseInt(m.style("height"))||400)-n.top-n.bottom;v.update=function(){v(e)},v.container=this;if(!c||!c.length){var w=m.selectAll(".nv-noData").data([d]);return w.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),w.attr("x",n.left+g/2).attr("y",n.top+b/2).text(function(e){return e}),v}m.selectAll(".nv-noData").remove();var E=t.y()(c[c.length-1],c.length-1);s=t.xScale(),o=t.yScale();var S=m.selectAll("g.nv-wrap.nv-sparklineplus").data([c]),T=S.enter().append("g").attr("class","nvd3 nv-wrap nv-sparklineplus"),N=T.append("g"),C=S.select("g");N.append("g").attr("class","nv-sparklineWrap"),N.append("g").attr("class","nv-valueWrap"),N.append("g").attr("class","nv-hoverArea"),S.attr("transform","translate("+n.left+","+n.top+")");var k=C.select(".nv-sparklineWrap");t.width(g).height(b),k.call(t);var L=C.select(".nv-valueWrap"),A=L.selectAll(".nv-currentValue").data([E]);A.enter().append("text").attr("class","nv-currentValue").attr("dx",p?-8:8).attr("dy",".9em").style("text-anchor",p?"end":"start"),A.attr("x",g+(p?n.right:0)).attr("y",h?function(e){return o(e)}:0).style("fill",t.color()(c[c.length-1],c.length-1)).text(l(E)),N.select(".nv-hoverArea").append("rect").on("mousemove",M).on("click",function(){a=!a}).on("mouseout",function(){u=[],O()}),C.select(".nv-hoverArea rect").attr("transform",function(e){return"translate("+ -n.left+","+ -n.top+")"}).attr("width",g+n.left+n.right).attr("height",b+n.top)}),v}var t=e.models.sparkline(),n={top:15,right:100,bottom:10,left:50},r=null,i=null,s,o,u=[],a=!1,f=d3.format(",r"),l=d3.format(",.2f"),c=!0,h=!0,p=!1,d="No Data Available.";return v.sparkline=t,d3.rebind(v,t,"x","y","xScale","yScale","color"),v.options=e.utils.optionsFunc.bind(v),v.margin=function(e){return arguments.length?(n.top=typeof e.top!="undefined"?e.top:n.top,n.right=typeof e.right!="undefined"?e.right:n.right,n.bottom=typeof e.bottom!="undefined"?e.bottom:n.bottom,n.left=typeof e.left!="undefined"?e.left:n.left,v):n},v.width=function(e){return arguments.length?(r=e,v):r},v.height=function(e){return arguments.length?(i=e,v):i},v.xTickFormat=function(e){return arguments.length?(f=e,v):f},v.yTickFormat=function(e){return arguments.length?(l=e,v):l},v.showValue=function(e){return arguments.length?(c=e,v):c},v.alignValue=function(e){return arguments.length?(h=e,v):h},v.rightAlignValue=function(e){return arguments.length?(p=e,v):p},v.noData=function(e){return arguments.length?(d=e,v):d},v},e.models.stackedArea=function(){function g(e){return e.each(function(e){var a=n-t.left-t.right,b=r-t.top-t.bottom,w=d3.select(this);p=v.xScale(),d=v.yScale();var E=e;e.forEach(function(e,t){e.seriesIndex=t,e.values=e.values.map(function(e,n){return e.index=n,e.seriesIndex=t,e})});var S=e.filter(function(e){return!e.disabled});e=d3.layout.stack().order(l).offset(f).values(function(e){return e.values}).x(o).y(u).out(function(e,t,n){var r=u(e)===0?0:n;e.display={y:r,y0:t}})(S);var T=w.selectAll("g.nv-wrap.nv-stackedarea").data([e]),N=T.enter().append("g").attr("class","nvd3 nv-wrap nv-stackedarea"),C=N.append("defs"),k=N.append("g"),L=T.select("g");k.append("g").attr("class","nv-areaWrap"),k.append("g").attr("class","nv-scatterWrap"),T.attr("transform","translate("+t.left+","+t.top+")"),v.width(a).height(b).x(o).y(function(e){return e.display.y+e.display.y0}).forceY([0]).color(e.map(function(e,t){return e.color||i(e,e.seriesIndex)}));var A=L.select(".nv-scatterWrap").datum(e);A.call(v),C.append("clipPath").attr("id","nv-edge-clip-"+s).append("rect"),T.select("#nv-edge-clip-"+s+" rect").attr("width",a).attr("height",b),L.attr("clip-path",h?"url(#nv-edge-clip-"+s+")":"");var O=d3.svg.area().x(function(e,t){return p(o(e,t))}).y0(function(e){return d(e.display.y0)}).y1(function(e){return d(e.display.y+e.display.y0)}).interpolate(c),M=d3.svg.area().x(function(e,t){return p(o(e,t))}).y0(function(e){return d(e.display.y0)}).y1(function(e){return d(e.display.y0)}),_=L.select(".nv-areaWrap").selectAll("path.nv-area").data(function(e){return e});_.enter().append("path").attr("class",function(e,t){return"nv-area nv-area-"+t}).attr("d",function(e,t){return M(e.values,e.seriesIndex)}).on("mouseover",function(e,t){d3.select(this).classed("hover",!0),m.areaMouseover({point:e,series:e.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:e.seriesIndex})}).on("mouseout",function(e,t){d3.select(this).classed("hover",!1),m.areaMouseout({point:e,series:e.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:e.seriesIndex})}).on("click",function(e,t){d3.select(this).classed("hover",!1),m.areaClick({point:e,series:e.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:e.seriesIndex})}),_.exit().remove(),_.style("fill",function(e,t){return e.color||i(e,e.seriesIndex)}).style("stroke",function(e,t){return e.color||i(e,e.seriesIndex)}),_.attr("d",function(e,t){return O(e.values,t)}),v.dispatch.on("elementMouseover.area",function(e){L.select(".nv-chart-"+s+" .nv-area-"+e.seriesIndex).classed("hover",!0)}),v.dispatch.on("elementMouseout.area",function(e){L.select(".nv-chart-"+s+" .nv-area-"+e.seriesIndex).classed("hover",!1)}),g.d3_stackedOffset_stackPercent=function(e){var t=e.length,n=e[0].length,r=1/t,i,s,o,a=[];for(s=0;s<n;++s){for(i=0,o=0;i<E.length;i++)o+=u(E[i].values[s]);if(o)for(i=0;i<t;i++)e[i][s][1]/=o;else for(i=0;i<t;i++)e[i][s][1]=r}for(s=0;s<n;++s)a[s]=0;return a}}),g}var t={top:0,right:0,bottom:0,left:0},n=960,r=500,i=e.utils.defaultColor(),s=Math.floor(Math.random()*1e5),o=function(e){return e.x},u=function(e){return e.y},a="stack",f="zero",l="default",c="linear",h=!1,p,d,v=e.models.scatter(),m=d3.dispatch("tooltipShow","tooltipHide","areaClick","areaMouseover","areaMouseout");return v.size(2.2).sizeDomain([2.2,2.2]),v.dispatch.on("elementClick.area",function(e){m.areaClick(e)}),v.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+t.left,e.pos[1]+t.top],m.tooltipShow(e)}),v.dispatch.on("elementMouseout.tooltip",function(e){m.tooltipHide(e)}),g.dispatch=m,g.scatter=v,d3.rebind(g,v,"interactive","size","xScale","yScale","zScale","xDomain","yDomain","xRange","yRange","sizeDomain","forceX","forceY","forceSize","clipVoronoi","useVoronoi","clipRadius","highlightPoint","clearHighlights"),g.options=e.utils.optionsFunc.bind(g),g.x=function(e){return arguments.length?(o=d3.functor(e),g):o},g.y=function(e){return arguments.length?(u=d3.functor(e),g):u},g.margin=function(e){return arguments.length?(t.top=typeof e.top!="undefined"?e.top:t.top,t.right=typeof e.right!="undefined"?e.right:t.right,t.bottom=typeof e.bottom!="undefined"?e.bottom:t.bottom,t.left=typeof e.left!="undefined"?e.left:t.left,g):t},g.width=function(e){return arguments.length?(n=e,g):n},g.height=function(e){return arguments.length?(r=e,g):r},g.clipEdge=function(e){return arguments.length?(h=e,g):h},g.color=function(t){return arguments.length?(i=e.utils.getColor(t),g):i},g.offset=function(e){return arguments.length?(f=e,g):f},g.order=function(e){return arguments.length?(l=e,g):l},g.style=function(e){if(!arguments.length)return a;a=e;switch(a){case"stack":g.offset("zero"),g.order("default");break;case"stream":g.offset("wiggle"),g.order("inside-out");break;case"stream-center":g.offset("silhouette"),g.order("inside-out");break;case"expand":g.offset("expand"),g.order("default");break;case"stack_percent":g.offset(g.d3_stackedOffset_stackPercent),g.order("default")}return g},g.interpolate=function(e){return arguments.length?(c=e,g):c},g},e.models.stackedAreaChart=function(){function M(y){return y.each(function(y){var A=d3.select(this),_=this,D=(a||parseInt(A.style("width"))||960)-u.left-u.right,P=(f||parseInt(A.style("height"))||400)-u.top-u.bottom;M.update=function(){A.call(M)},M.container=this,S.disabled=y.map(function(e){return!!e.disabled});if(!x){var H;x={};for(H in S)S[H]instanceof Array?x[H]=S[H].slice(0):x[H]=S[H]}if(!y||!y.length||!y.filter(function(e){return e.values.length}).length){var B=A.selectAll(".nv-noData").data([T]);return B.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),B.attr("x",u.left+D/2).attr("y",u.top+P/2).text(function(e){return e}),M}A.selectAll(".nv-noData").remove(),b=t.xScale(),w=t.yScale();var j=A.selectAll("g.nv-wrap.nv-stackedAreaChart").data([y]),F=j.enter().append("g").attr("class","nvd3 nv-wrap nv-stackedAreaChart").append("g"),I=j.select("g");F.append("rect").style("opacity",0),F.append("g").attr("class","nv-x nv-axis"),F.append("g").attr("class","nv-y nv-axis"),F.append("g").attr("class","nv-stackedWrap"),F.append("g").attr("class","nv-legendWrap"),F.append("g").attr("class","nv-controlsWrap"),F.append("g").attr("class","nv-interactive"),I.select("rect").attr("width",D).attr("height",P);if(h){var q=c?D-C:D;i.width(q),I.select(".nv-legendWrap").datum(y).call(i),u.top!=i.height()&&(u.top=i.height(),P=(f||parseInt(A.style("height"))||400)-u.top-u.bottom),I.select(".nv-legendWrap").attr("transform","translate("+(D-q)+","+ -u.top+")")}if(c){var R=[{key:L.stacked||"Stacked",metaKey:"Stacked",disabled:t.style()!="stack",style:"stack"},{key:L.stream||"Stream",metaKey:"Stream",disabled:t.style()!="stream",style:"stream"},{key:L.expanded||"Expanded",metaKey:"Expanded",disabled:t.style()!="expand",style:"expand"},{key:L.stack_percent||"Stack %",metaKey:"Stack_Percent",disabled:t.style()!="stack_percent",style:"stack_percent"}];C=k.length/3*260,R=R.filter(function(e){return k.indexOf(e.metaKey)!==-1}),s.width(C).color(["#444","#444","#444"]),I.select(".nv-controlsWrap").datum(R).call(s),u.top!=Math.max(s.height(),i.height())&&(u.top=Math.max(s.height(),i.height()),P=(f||parseInt(A.style("height"))||400)-u.top-u.bottom),I.select(".nv-controlsWrap").attr("transform","translate(0,"+ -u.top+")")}j.attr("transform","translate("+u.left+","+u.top+")"),v&&I.select(".nv-y.nv-axis").attr("transform","translate("+D+",0)"),m&&(o.width(D).height(P).margin({left:u.left,top:u.top}).svgContainer(A).xScale(b),j.select(".nv-interactive").call(o)),t.width(D).height(P);var U=I.select(".nv-stackedWrap").datum(y);U.call(t),p&&(n.scale(b).ticks(D/100).tickSize(-P,0),I.select(".nv-x.nv-axis").attr("transform","translate(0,"+P+")"),I.select(".nv-x.nv-axis").call(n)),d&&(r.scale(w).ticks(t.offset()=="wiggle"?0:P/36).tickSize(-D,0).setTickFormat(t.style()=="expand"||t.style()=="stack_percent"?d3.format("%"):E),I.select(".nv-y.nv-axis").call(r)),t.dispatch.on("areaClick.toggle",function(e){y.filter(function(e){return!e.disabled}).length===1?y.forEach(function(e){e.disabled=!1}):y.forEach(function(t,n){t.disabled=n!=e.seriesIndex}),S.disabled=y.map(function(e){return!!e.disabled}),N.stateChange(S),M.update()}),i.dispatch.on("stateChange",function(e){S.disabled=e.disabled,N.stateChange(S),M.update()}),s.dispatch.on("legendClick",function(e,n){if(!e.disabled)return;R=R.map(function(e){return e.disabled=!0,e}),e.disabled=!1,t.style(e.style),S.style=t.style(),N.stateChange(S),M.update()}),o.dispatch.on("elementMousemove",function(i){t.clearHighlights();var s,a,f,c=[];y.filter(function(e,t){return e.seriesIndex=t,!e.disabled}).forEach(function(n,r){a=e.interactiveBisect(n.values,i.pointXValue,M.x()),t.highlightPoint(r,a,!0);var o=n.values[a];if(typeof o=="undefined")return;typeof s=="undefined"&&(s=o),typeof f=="undefined"&&(f=M.xScale()(M.x()(o,a)));var u=t.style()=="expand"?o.display.y:M.y()(o,a);c.push({key:n.key,value:u,color:l(n,n.seriesIndex),stackedValue:o.display})}),c.reverse();if(c.length>2){var h=M.yScale().invert(i.mouseY),p=Infinity,d=null;c.forEach(function(e,t){h=Math.abs(h);var n=Math.abs(e.stackedValue.y0),r=Math.abs(e.stackedValue.y);if(h>=n&&h<=r+n){d=t;return}}),d!=null&&(c[d].highlight=!0)}var v=n.tickFormat()(M.x()(s,a)),m=t.style()=="expand"?function(e,t){return d3.format(".1%")(e)}:function(e,t){return r.tickFormat()(e)};o.tooltip.position({left:f+u.left,top:i.mouseY+u.top}).chartContainer(_.parentNode).enabled(g).valueFormatter(m).data({value:v,series:c})(),o.renderGuideLine(f)}),o.dispatch.on("elementMouseout",function(e){N.tooltipHide(),t.clearHighlights()}),N.on("tooltipShow",function(e){g&&O(e,_.parentNode)}),N.on("changeState",function(e){typeof e.disabled!="undefined"&&y.length===e.disabled.length&&(y.forEach(function(t,n){t.disabled=e.disabled[n]}),S.disabled=e.disabled),typeof e.style!="undefined"&&t.style(e.style),M.update()})}),M}var t=e.models.stackedArea(),n=e.models.axis(),r=e.models.axis(),i=e.models.legend(),s=e.models.legend(),o=e.interactiveGuideline(),u={top:30,right:25,bottom:50,left:60},a=null,f=null,l=e.utils.defaultColor(),c=!0,h=!0,p=!0,d=!0,v=!1,m=!1,g=!0,y=function(e,t,n,r,i){return"<h3>"+e+"</h3>"+"<p>"+n+" on "+t+"</p>"},b,w,E=d3.format(",.2f"),S={style:t.style()},x=null,T="No Data Available.",N=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),C=250,k=["Stacked","Stream","Expanded"],L={},A=0;n.orient("bottom").tickPadding(7),r.orient(v?"right":"left"),s.updateState(!1);var O=function(i,s){var o=i.pos[0]+(s.offsetLeft||0),u=i.pos[1]+(s.offsetTop||0),a=n.tickFormat()(t.x()(i.point,i.pointIndex)),f=r.tickFormat()(t.y()(i.point,i.pointIndex)),l=y(i.series.key,a,f,i,M);e.tooltip.show([o,u],l,i.value<0?"n":"s",null,s)};return t.dispatch.on("tooltipShow",function(e){e.pos=[e.pos[0]+u.left,e.pos[1]+u.top],N.tooltipShow(e)}),t.dispatch.on("tooltipHide",function(e){N.tooltipHide(e)}),N.on("tooltipHide",function(){g&&e.tooltip.cleanup()}),M.dispatch=N,M.stacked=t,M.legend=i,M.controls=s,M.xAxis=n,M.yAxis=r,M.interactiveLayer=o,d3.rebind(M,t,"x","y","size","xScale","yScale","xDomain","yDomain","xRange","yRange","sizeDomain","interactive","useVoronoi","offset","order","style","clipEdge","forceX","forceY","forceSize","interpolate"),M.options=e.utils.optionsFunc.bind(M),M.margin=function(e){return arguments.length?(u.top=typeof e.top!="undefined"?e.top:u.top,u.right=typeof e.right!="undefined"?e.right:u.right,u.bottom=typeof e.bottom!="undefined"?e.bottom:u.bottom,u.left=typeof e.left!="undefined"?e.left:u.left,M):u},M.width=function(e){return arguments.length?(a=e,M):a},M.height=function(e){return arguments.length?(f=e,M):f},M.color=function(n){return arguments.length?(l=e.utils.getColor(n),i.color(l),t.color(l),M):l},M.showControls=function(e){return arguments.length?(c=e,M):c},M.showLegend=function(e){return arguments.length?(h=e,M):h},M.showXAxis=function(e){return arguments.length?(p=e,M):p},M.showYAxis=function(e){return arguments.length?(d=e,M):d},M.rightAlignYAxis=function(e){return arguments.length?(v=e,r.orient(e?"right":"left"),M):v},M.useInteractiveGuideline=function(e){return arguments.length?(m=e,e===!0&&(M.interactive(!1),M.useVoronoi(!1)),M):m},M.tooltip=function(e){return arguments.length?(y=e,M):y},M.tooltips=function(e){return arguments.length?(g=e,M):g},M.tooltipContent=function(e){return arguments.length?(y=e,M):y},M.state=function(e){return arguments.length?(S=e,M):S},M.defaultState=function(e){return arguments.length?(x=e,M):x},M.noData=function(e){return arguments.length?(T=e,M):T},M.transitionDuration=function(e){return arguments.length?(A=e,M):A},M.controlsData=function(e){return arguments.length?(k=e,M):k},M.controlLabels=function(e){return arguments.length?typeof e!="object"?L:(L=e,M):L},r.setTickFormat=r.tickFormat,r.tickFormat=function(e){return arguments.length?(E=e,r):E},M}}(),define("plugin/plugins/nvd3/nv.d3",function(){}),define("plugin/charts/nvd3/common/config",["plugin/charts/forms/default","plugin/plugins/nvd3/nv.d3"],function(e){return $.extend(!0,{},e,{title:"",category:"",library:"NVD3",tag:"svg",keywords:"small",query_limit:500})}),define("plugin/charts/nvd3/bar/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Regular",category:"Bar diagrams",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/bar_stacked/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Stacked",category:"Bar diagrams",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/bar_horizontal/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Horizontal",category:"Bar diagrams",settings:{x_axis_type:{init:"hide"}},columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/bar_horizontal_stacked/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Stacked horizontal",category:"Bar diagrams",settings:{x_axis_type:{init:"hide"}},columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/line_focus/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Line with focus",category:"Others",zoomable:"native",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/pie/config",["plugin/plugins/nvd3/nv.d3"],function(){return $.extend(!0,{},{title:"Pie chart",category:"Area charts",library:"NVD3",tag:"svg",keywords:"small",columns:{label:{title:"Labels",is_label:!0,is_auto:!0},y:{title:"Values",is_numeric:!0}},settings:{main_separator:{type:"separator",title:"Pie chart settings"},donut_ratio:{title:"Donut ratio",info:"Determine how large the donut hole will be.",type:"select",init:"0.5",data:[{label:"50%",value:"0.5"},{label:"25%",value:"0.25"},{label:"10%",value:"0.10"},{label:"0%",value:"0"}]},show_legend:{title:"Show legend",info:"Would you like to add a legend?",type:"radiobutton",init:"false",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]},label_separator:{type:"separator",title:"Label settings"},label_type:{title:"Donut label",info:"What would you like to show for each slice?",type:"select",init:"percent",data:[{label:"-- Nothing --",value:"hide",hide:"label_outside"},{label:"Label column",value:"key",show:"label_outside"},{label:"Value column",value:"value",show:"label_outside"},{label:"Percentage",value:"percent",show:"label_outside"}]},label_outside:{title:"Show outside",info:"Would you like to show labels outside the donut?",type:"radiobutton",init:"false",data:[{label:"Yes",value:"true"},{label:"No",value:"false"}]},use_panels:{init:"true",hide:!0}}})}),define("plugin/charts/nvd3/stackedarea_full/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Expanded",zoomable:!0,category:"Area charts",keywords:"default small",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/stackedarea_stream/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Stream",category:"Area charts",zoomable:!0,keywords:"default small",showmaxmin:!0,columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/histogram/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Histogram",category:"Data processing (requires 'charts' tool from Toolshed)",execute:"histogram",keywords:"small medium large",columns:{y:{title:"Observations",is_numeric:!0}},settings:{x_axis_label:{init:"Values"},y_axis_label:{init:"Density"},y_axis_type:{init:"f"},y_axis_precision:{init:".2"}}})}),define("plugin/charts/nvd3/line/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Line chart",category:"Others",zoomable:!0,columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/scatter/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Scatter plot",category:"Others",zoomable:!0,columns:{x:{title:"Values for x-axis",is_numeric:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/nvd3/stackedarea/config",["plugin/charts/nvd3/common/config"],function(e){return $.extend(!0,{},e,{title:"Regular",zoomable:!0,category:"Area charts",keywords:"default small",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/jqplot/common/config",["plugin/charts/forms/default"],function(e){return $.extend(!0,{},e,{title:"",category:"",library:"jqPlot",tag:"div",zoomable:!0,keywords:"medium",query_limit:1e4,settings:{separator_grid:{title:"Grids",type:"separator"},x_axis_grid:{title:"Axis grid",info:"Would you like to show grid lines for the X axis?",type:"radiobutton",init:"false",data:[{label:"On",value:"true"},{label:"Off",value:"false"}]},y_axis_grid:{title:"Axis grid",info:"Would you like to show grid lines for the Y axis?",type:"radiobutton",init:"true",data:[{label:"On",value:"true"},{label:"Off",value:"false"}]}}})}),define("plugin/charts/jqplot/bar/config",["plugin/charts/jqplot/common/config"],function(e){return $.extend(!0,{},e,{title:"Regular",category:"Bar diagrams",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/jqplot/line/config",["plugin/charts/jqplot/common/config"],function(e){return $.extend(!0,{},e,{title:"Line chart",category:"Others",columns:{x:{title:"Values for x-axis",is_label:!0,is_auto:!0,is_unique:!0},y:{title:"Values for y-axis",is_numeric:!0}}})}),define("plugin/charts/jqplot/scatter/config",["plugin/charts/jqplot/common/config"],function(e){return $.extend(!0,{},e,{title:"Scatter plot",category:"Others",columns:{x:{title:"Values for x-axis",is_numeric:!0},y:{title:"Values for y-axis",is_numeric:!0}},settings:{x_axis_grid:{init:"true"}}})}),define("plugin/charts/jqplot/boxplot/config",["plugin/charts/jqplot/common/config"],function(e){return $.extend(!0,{},e,{title:"Box plot",category:"Data processing (requires 'charts' tool from Toolshed)",library:"jqPlot",tag:"div",execute:"boxplot",keywords:"small medium large",columns:{y:{title:"Observations",is_numeric:!0}},settings:{show_legend:{init:"false"}}})}),define("plugin/charts/jqplot/histogram_discrete/config",["plugin/charts/jqplot/common/config"],function(e){return $.extend(!0,{},e,{title:"Discrete Histogram",category:"Data processing (requires 'charts' tool from Toolshed)",execute:"histogramdiscrete",keywords:"small medium large",columns:{x:{title:"Observations",is_label:!0}},settings:{x_axis_label:{init:"Breaks"},y_axis_label:{init:"Density"}}})}),define("plugin/charts/others/heatmap/config",["plugin/charts/forms/default"],function(e){return $.extend(!0,{},e,{title:"Heatmap",category:"Others",query_limit:1e3,library:"Custom",tag:"svg",keywords:"small",zoomable:!0,columns:{x:{title:"Column labels",is_label:!0,is_numeric:!0,is_unique:!0},y:{title:"Row labels",is_label:!0,is_numeric:!0,is_unique:!0},z:{title:"Observation",is_numeric:!0}},settings:{use_panels:{init:"true",hide:!0},color_set:{title:"Color scheme",info:"Select a color scheme for your heatmap",type:"select",init:"jet",data:[{label:"Cold-to-Hot",value:"hot"},{label:"Cool",value:"cool"},{label:"Copper",value:"copper"},{label:"Gray scale",value:"gray"},{label:"Jet",value:"jet"},{label:"No-Green",value:"no_green"},{label:"Ocean",value:"ocean"},{label:"Polar",value:"polar"},{label:"Red-to-Green",value:"redgreen"},{label:"Red-to-green (saturated)",value:"red2green"},{label:"Relief",value:"relief"},{label:"Seismograph",value:"seis"},{label:"Sealand",value:"sealand"},{label:"Split",value:"split"},{label:"Wysiwyg",value:"wysiwyg"}]},url_template:{title:"Url template",info:"Enter a url to link the labels with external sources. Use __LABEL__ as placeholder.",type:"text",init:"",placeholder:"http://someurl.com?id=__LABEL__"}}})}),define("plugin/charts/others/heatmap_cluster/config",["plugin/charts/others/heatmap/config"],function(e){return $.extend(!0,{},e,{title:"Clustered Heatmap",category:"Data processing (requires 'charts' tool from Toolshed)",execute:"heatmap",keywords:"small medium large"})}),define("plugin/charts/types",["plugin/charts/nvd3/bar/config","plugin/charts/nvd3/bar_stacked/config","plugin/charts/nvd3/bar_horizontal/config","plugin/charts/nvd3/bar_horizontal_stacked/config","plugin/charts/nvd3/line_focus/config","plugin/charts/nvd3/pie/config","plugin/charts/nvd3/stackedarea_full/config","plugin/charts/nvd3/stackedarea_stream/config","plugin/charts/nvd3/histogram/config","plugin/charts/nvd3/line/config","plugin/charts/nvd3/scatter/config","plugin/charts/nvd3/stackedarea/config","plugin/charts/jqplot/bar/config","plugin/charts/jqplot/line/config","plugin/charts/jqplot/scatter/config","plugin/charts/jqplot/boxplot/config","plugin/charts/jqplot/histogram_discrete/config","plugin/charts/others/heatmap/config","plugin/charts/others/heatmap_cluster/config"],function(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y){return Backbone.Model.extend({defaults:{nvd3_bar:e,nvd3_bar_stacked:t,nvd3_bar_horizontal:n,nvd3_bar_horizontal_stacked:r,nvd3_line_focus:i,nvd3_stackedarea:c,nvd3_stackedarea_full:o,nvd3_stackedarea_stream:u,nvd3_pie:s,nvd3_line:f,nvd3_scatter:l,nvd3_histogram:a,jqplot_bar:h,jqplot_histogram_discrete:m,jqplot_line:p,jqplot_scatter:d,jqplot_boxplot:v,others_heatmap:g,others_heatmap_cluster:y}})}),define("plugin/app",["mvc/ui/ui-modal","mvc/ui/ui-portlet","plugin/library/ui","utils/utils","plugin/library/jobs","plugin/library/datasets","plugin/library/storage","plugin/views/viewer","plugin/views/editor","plugin/models/config","plugin/models/chart","plugin/charts/types"],function(e,t,n,r,i,s,o,u,a,f,l,c){return Backbone.View.extend({initialize:function(t){this.options=t,Galaxy&&Galaxy.modal?this.modal=Galaxy.modal:this.modal=new e.View,this.config=new f,this.types=new c,this.chart=new l,this.jobs=new i(this),this.datasets=new s(this),this.storage=new o(this),this.viewer_view=new u(this),this.editor_view=new a(this),this.$el.append(this.viewer_view.$el),this.$el.append(this.editor_view.$el);if(!this.storage.load())this.go("editor");else{this.go("viewer");var n=this;this.chart.deferred.execute(function(){n.chart.trigger("redraw")})}},go:function(e){$(".tooltip").hide();switch(e){case"editor":this.editor_view.show(),this.viewer_view.hide();break;case"viewer":this.editor_view.hide(),this.viewer_view.show()}},chartPath:function(e){var t=e.split(/_(.+)/);return t.length>=2?t[0]+"/"+t[1]:(console.debug("FAILED App:chartPath() - Invalid format: "+e),undefined)},execute:function(e){},onunload:function(){},log:function(e,t){console.log(e+" "+t)}})});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/forms/default.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/forms/default.js
@@ -0,0 +1,252 @@
+define([], function() {
+
+return {
+ title : '',
+ category : '',
+ library : '',
+ tag : '',
+ keywords : '',
+ query_limit : 0,
+ settings : {
+ separator_x : {
+ title : 'X axis',
+ type : 'separator'
+ },
+ x_axis_label : {
+ title : 'Axis label',
+ info : 'Provide a label for the axis.',
+ type : 'text',
+ init : 'X-axis',
+ placeholder : 'Axis label'
+ },
+ x_axis_type : {
+ title : 'Axis value type',
+ info : 'Select the value type of the axis.',
+ type : 'select',
+ init : 'auto',
+ data : [
+ {
+ label : '-- Do not show values --',
+ value : 'hide',
+ operations : {
+ hide : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'Auto',
+ value : 'auto',
+ operations : {
+ hide : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'Float',
+ value : 'f',
+ operations : {
+ show : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'Exponent',
+ value : 'e',
+ operations : {
+ show : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'Integer',
+ value : 'd',
+ operations : {
+ hide : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'Percentage',
+ value : 'p',
+ operations : {
+ show : ['x_axis_precision']
+ }
+ },
+ {
+ label : 'SI-prefix',
+ value : 's',
+ operations : {
+ hide : ['x_axis_precision']
+ }
+ }
+ ]
+ },
+ x_axis_precision : {
+ title : 'Axis tick format',
+ info : 'Select the tick format for the axis.',
+ type : 'select',
+ init : '1',
+ data : [
+ {
+ label : '0.00001',
+ value : '5'
+ },
+ {
+ label : '0.0001',
+ value : '4'
+ },
+ {
+ label : '0.001',
+ value : '3'
+ },
+ {
+ label : '0.01',
+ value : '2'
+ },
+ {
+ label : '0.1',
+ value : '1'
+ },
+ {
+ label : '1',
+ value : '0'
+ }
+ ]
+
+ },
+ separator_y : {
+ title : 'Y axis',
+ type : 'separator'
+ },
+ y_axis_label : {
+ title : 'Axis label',
+ info : 'Provide a label for the axis.',
+ type : 'text',
+ init : 'Y-axis',
+ placeholder : 'Axis label'
+ },
+ y_axis_type : {
+ title : 'Axis value type',
+ info : 'Select the value type of the axis.',
+ type : 'select',
+ init : 'auto',
+ data : [
+ {
+ label : '-- Do not show values --',
+ value : 'hide',
+ operations : {
+ hide : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'Auto',
+ value : 'auto',
+ operations : {
+ hide : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'Float',
+ value : 'f',
+ operations : {
+ show : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'Exponent',
+ value : 'e',
+ operations : {
+ show : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'Integer',
+ value : 'd',
+ operations : {
+ hide : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'Percentage',
+ value : 'p',
+ operations : {
+ show : ['y_axis_precision']
+ }
+ },
+ {
+ label : 'SI-prefix',
+ value : 's',
+ operations : {
+ hide : ['y_axis_precision']
+ }
+ }
+ ]
+ },
+ y_axis_precision : {
+ title : 'Axis tick format',
+ info : 'Select the tick format for the axis.',
+ type : 'select',
+ init : '1',
+ data : [
+ {
+ label : '0.00001',
+ value : '5'
+ },
+ {
+ label : '0.0001',
+ value : '4'
+ },
+ {
+ label : '0.001',
+ value : '3'
+ },
+ {
+ label : '0.01',
+ value : '2'
+ },
+ {
+ label : '0.1',
+ value : '1'
+ },
+ {
+ label : '1',
+ value : '0'
+ }
+ ]
+
+ },
+ separator_legend : {
+ title : 'Others',
+ type : 'separator'
+ },
+ show_legend : {
+ title : 'Show legend',
+ info : 'Would you like to add a legend?',
+ type : 'radiobutton',
+ init : 'true',
+ data : [
+ {
+ label : 'Yes',
+ value : 'true'
+ },
+ {
+ label : 'No',
+ value : 'false'
+ }
+ ]
+ },
+ use_panels : {
+ title : 'Use multi-panels',
+ info : 'Would you like to separate your data into individual panels?',
+ type : 'radiobutton',
+ init : 'false',
+ data : [
+ {
+ label : 'Yes',
+ value : 'true'
+ },
+ {
+ label : 'No',
+ value : 'false'
+ }
+ ]
+ }
+ }
+};
+
+});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/heatmap/config.js
--- a/config/plugins/visualizations/charts/static/charts/heatmap/config.js
+++ /dev/null
@@ -1,195 +0,0 @@
-define([], function() {
-
-return {
- title : 'Heatmap',
- category : 'Data processing (requires \'charts\' tool from Toolshed)',
- library : '',
- tag : 'div',
- use_panels : true,
- execute : 'heatmap',
-
- // columns
- columns : {
- row_label : {
- title : 'Row labels',
- is_label : true
- },
- col_label : {
- title : 'Column labels',
- is_label : true
- },
- value : {
- title : 'Observations'
- },
- },
-
- // settings
- settings: {
- /*limit : {
- title : 'Limit',
- info : 'Which to ranked clusters would you like to visualize',
- type : 'select',
- init : '20',
- data : [
- {
- label : '20',
- value : '20'
- },
- {
- label : '30',
- value : '30'
- },
- {
- label : '40',
- value : '40'
- },
- {
- label : '50',
- value : '50'
- },
- {
- label : '60',
- value : '60'
- },
- {
- label : '70',
- value : '70'
- },
- {
- label : '80',
- value : '80'
- },
- {
- label : '90',
- value : '90'
- },
- {
- label : '100',
- value : '100'
- }
- ]
- },*/
- color_set : {
- title : 'Color scheme',
- info : 'Select a color scheme for your heatmap',
- type : 'select',
- init : 'ocean',
- data : [
- {
- label : 'Cold-to-Hot',
- value : 'hot'
- },
- {
- label : 'Cool',
- value : 'cool'
- },
- {
- label : 'Copper',
- value : 'copper'
- },
- {
- label : 'Gebco',
- value : 'gebco'
- },
- {
- label : 'Globe',
- value : 'globe'
- },
- {
- label : 'Gray scale',
- value : 'gray'
- },
- {
- label : 'Haxby',
- value : 'haxby'
- },
- {
- label : 'Jet',
- value : 'jet'
- },
- {
- label : 'No-Green',
- value : 'no_green'
- },
- {
- label : 'Ocean',
- value : 'ocean'
- },
- {
- label : 'Polar',
- value : 'polar'
- },
- {
- label : 'Rainbow',
- value : 'rainbow'
- },
- {
- label : 'Red-to-Green',
- value : 'redgreen'
- },
- {
- label : 'Red-to-green (saturated)',
- value : 'red2green'
- },
- {
- label : 'Relief',
- value : 'relief'
- },
- {
- label : 'Seismograph',
- value : 'seis'
- },
- {
- label : 'Sealand',
- value : 'sealand'
- },
- {
- label : 'Split',
- value : 'split'
- },
- {
- label : 'Topo',
- value : 'topo'
- },
- {
- label : 'Wysiwyg',
- value : 'wysiwyg'
- }
- ]
- },
-
- sorting : {
- title : 'Sorting',
- info : 'How should the columns be clustered?',
- type : 'select',
- init : 'hclust',
- data : [
- {
- label : 'Read from dataset',
- value : 'hclust'
- },
- {
- label : 'Sort column and row labels',
- value : 'byboth'
- },
- {
- label : 'Sort column labels',
- value : 'bycolumns'
- },
- {
- label : 'Sort by rows',
- value : 'byrow'
- }
- ]
- }
- },
-
- // menu definition
- menu : function() {
- return {
- color_set : this.settings.color_set
- }
- }
-};
-
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/heatmap/heatmap-parameters.js
--- a/config/plugins/visualizations/charts/static/charts/heatmap/heatmap-parameters.js
+++ /dev/null
@@ -1,52 +0,0 @@
-// dependencies
-define(['utils/utils', 'plugin/charts/heatmap/heatmap-plugin'], function(Utils, HeatmapPlugin) {
-
-// color palettes
-var colorSets = {
- seis: ['#AA0000', '#D00000', '#F70000', '#FF1D00', '#FF4400', '#FF6A00', '#FF9000', '#FFB700', '#FFDD00', '#FFFF00', '#FFFF00', '#FFFF00', '#BDFF0C', '#73FF1A', '#3FFA36', '#16F45A', '#00D08B', '#0087CD', '#0048FA', '#0024E3'],
-
- sealand: ['#8C66FF', '#6A66FF', '#6684FF', '#66A7FF', '#66CAFF', '#66ECFF', '#66FFF0', '#66FFCE', '#66FFAB', '#66FF88', '#66FF66', '#88FF66', '#ABFF66', '#CEFF66', '#FFEEA6', '#FFD3A6', '#FFB8A6', '#FFAAB0', '#FFB5CB', '#FFC0E1'],
-
- redgreen: ['#005824', '#1A693B', '#347B53', '#4F8D6B', '#699F83', '#83B09B', '#9EC2B3', '#B8D4CB', '#D2E6E3', '#EDF8FB', '#FFFFFF', '#F1EEF6', '#E6D3E1','#DBB9CD', '#D19EB9', '#C684A4', '#BB6990', '#B14F7C', '#A63467', '#9B1A53', '#91003F'],
-
- ocean: ['#000000', '#000209', '#000413', '#00061E', '#000728', '#000932', '#002650', '#00426E', '#005E8C', '#007AAA', '#0096C8', '#22A9C2', '#45BCBB', '#67CFB5', '#8AE2AE', '#ACF6A8', '#BCF8B9', '#CBF9CA', '#DBFBDC', '#EBFDED'],
-
- cool: ['#00FFFF', '#0DF2FF', '#19E6FF', '#26D9FF', '#33CCFF', '#3FBFFF', '#4CB3FF', '#59A6FF', '#6699FF', '#738CFF', '#7F7FFF', '#8C73FF', '#9966FF', '#A659FF', '#B24DFF', '#BF3FFF', '#CC33FF', '#D926FF', '#E619FF', '#F20DFF'],
-
- copper: ['#000000', '#100906', '#1F130D', '#301E13', '#40281A', '#50321F', '#603C26', '#70462D', '#805033', '#905A3A', '#A06440', '#B06E46', '#C0784D', '#D08253', '#E08C5A', '#F09660', '#FFA066', '#FFAA6D', '#FFB473', '#FFBE7A'],
-
- gebco: ['#00F0FF', '#00F0FF', '#00F0FF', '#23FFFF', '#23FFFF', '#23FFFF', '#5AFFFF', '#5AFFFF', '#5AFFFF', '#8CFFE6', '#8CFFE6', '#8CFFE6', '#A5FFD7', '#A5FFD7', '#A5FFD7', '#C3FFD7', '#C3FFD7', '#C3FFD7', '#D2FFD7', '#E6FFF0'],
-
- globe: ['#9900FF', '#9900FF', '#7722FF', '#5544FF', '#3366FF', '#1188FF', '#1BA4FF', '#51BAFF', '#86D0FF', '#BCE6FF', '#336600', '#F3CA89', '#D9A627', '#A49019', '#9F7B0D', '#996600', '#B27676', '#C2B0B0', '#E5E5E5', '#FFFFFF'],
-
- gray: ['#000000', '#0D0D0D', '#191919', '#262626', '#333333', '#3F3F3F', '#4C4C4C', '#595959', '#666666', '#737373', '#7F7F7F', '#8C8C8C', '#999999', '#A6A6A6', '#B2B2B2', '#BFBFBF', '#CCCCCC', '#D9D9D9', '#E6E6E6', '#F2F2F2'],
-
- haxby: ['#090079', '#280096', '#0009C8', '#0019D4', '#1A66F0', '#19AFFF', '#32BEFF', '#61E1F0', '#6AECE1', '#8AECAE', '#CDFFA2', '#DFF68D', '#F8D768', '#FFBD57', '#F4754B', '#FF5A5A', '#FF7C7C', '#F6B3AE', '#FFC4C4', '#FFECEC'],
-
- hot: ['#000000', '#220000', '#440000', '#660000', '#880000', '#AA0000', '#CC0000', '#EE0000', '#FF1100', '#FF3300', '#FF5500', '#FF7700', '#FF9900', '#FFBB00', '#FFDD00', '#FFFF00', '#FFFF33', '#FFFF66', '#FFFF99', '#FFFFCC'],
-
- jet: ['#00007F', '#0000B2', '#0000E5', '#0019FF', '#004DFF', '#007FFF', '#00B2FF', '#00E5FF', '#FFFFF2', '#FFFFD9', '#FFFFBF', '#FFFFA5', '#FFFF8C', '#FFE500', '#FFB300', '#FF7F00', '#FF4C00', '#FF1900', '#E50000', '#B20000'],
-
- no_green: ['#1F60FF', '#1F60FF', '#1F9FFF', '#1FBFFF', '#00CFFF', '#2AFFFF', '#2AFFFF', '#55FFFF', '#7FFFFF', '#AAFFFF', '#FFFF54', '#FFFF54', '#FFF000', '#FFBF00', '#FFA800', '#FF8A00', '#FF8A00', '#FF7000', '#FF4D00', '#FF0000'],
-
- polar: ['#0000FF', '#1919FF', '#3333FF', '#4C4CFF', '#6666FF', '#7F7FFF', '#9999FF', '#B2B2FF', '#CCCCFF', '#E6E6FF', '#FFFFFF', '#FFE5E5', '#FFCCCC', '#FFB2B2', '#FF9999', '#FF7F7F', '#FF6666', '#FF4C4C', '#FF3333', '#FF1A1A'],
-
- rainbow: ['#FF00FF', '#BF00FF', '#7F00FF', '#3F00FF', '#0000FF', '#003FFF', '#007FFF', '#00BFFF', '#00FFFF', '#00FFBF', '#00FF7F', '#00FF3F', '#00FF00', '#3FFF00', '#7FFF00', '#BFFF00', '#FFFF00', '#FFBF00', '#FF7F00', '#FF3F00'],
-
- red2green: ['#FF0000', '#FF1919', '#FF3333', '#FF4C4C', '#FF6666', '#FF7F7F', '#FF9999', '#FFB2B2', '#FFCCCC', '#FFE6E6', '#FFFFFF', '#E5FFE5', '#CCFFCC', '#B2FFB2', '#99FF99', '#7FFF7F', '#66FF66', '#4CFF4C', '#33FF33', '#1AFF1A'],
-
- relief: ['#000000', '#000413', '#000728', '#002650', '#005E8C', '#0096C8', '#45BCBB', '#8AE2AE', '#BCF8B9', '#DBFBDC', '#467832', '#887438', '#B19D48', '#DBC758', '#FAE769', '#FAEB7E', '#FCED93', '#FCF1A7', '#FCF6C1', '#FDFAE0'],
-
- split: ['#7F7FFF', '#6666E6', '#4D4DCC', '#3333B3', '#1A1A99', '#00007F', '#000066', '#00004D', '#000033', '#00001A', '#000000', '#1A0000', '#330000', '#4D0000', '#660000', '#7F0000', '#991A1A', '#B33333', '#CC4D4D', '#E66666'],
-
- topo: ['#C977D9', '#A18AE6', '#8AA2E6', '#8BD1E7', '#8AF3CF', '#85F38E', '#BDF385', '#EDE485', '#F0B086', '#DE9F8B', '#74A3B3', '#99CC70', '#DCD68E', '#EDDFAD', '#F7E8CA', '#FFF9F3', '#FFF9F6', '#FFFBF9', '#FFFCFA', '#FFFEFD'],
-
- wysiwyg: ['#3F003F', '#3F003F', '#3F00BF', '#003FFF', '#00A0FF', '#3FBFFF', '#3FBFFF', '#40E0FF', '#3FFFBF', '#3FFF3F', '#7FFF3F', '#BFFF3F', '#BFFF3F', '#FFE040', '#FFE040', '#FF6040', '#FF1F40', '#FF60C0', '#FFA0FF', '#FFA0FF']
-}
-
-// return
-return {
- colorSets: colorSets
-}
-
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/heatmap/heatmap-plugin.js
--- a/config/plugins/visualizations/charts/static/charts/heatmap/heatmap-plugin.js
+++ /dev/null
@@ -1,739 +0,0 @@
-// dependencies
-define(['utils/utils'],
-function(Utils) {
-
-// widget
-return Backbone.View.extend(
-{
- // number of columns and rows
- colNumber: 0,
- rowNumber: 0,
-
- // indices
- rowIndex: [],
- colIndex: [],
-
- // labels
- rowLabel: [],
- colLabel: [],
-
- // cell size
- cellSize: 0,
-
- // font size
- fontSize: 0,
-
- // color buckets
- nColors: 0,
-
- // margins as cells
- margin : {
- top : 5,
- right : 5,
- bottom : 5,
- left : 5
- },
-
- // default settings
- optionsDefault: {
- title : '',
- pace : 1000,
- },
-
- // initialize
- initialize: function(options) {
- // link this
- var self = this;
-
- // load options
- this.options = Utils.merge(options, this.optionsDefault)
-
- // check requirements
- if (!this.options.data || !this.options.div || !this.options.colors) {
- console.debug('FAILED - HeatMapPlugin::initialize() - Parameters (container and/or data and/or colors) missing.');
- return;
- }
-
- // link data
- this.data = this.options.data;
-
- // set element
- this.setElement(this.options.div);
-
- //
- // data indexing
- //
-
- // labels (in alphabetical order)
- this.rowLabel = [];
- this.colLabel = [];
-
- // index (order from original dataset)
- this.rowIndex = [];
- this.colIndex = [];
-
- // unique keys (key indices are unique per label and indicate the labels rank in the alphabetical sorting)
- this.colRank = {};
- this.rowRank = {};
-
- //
- // identify and parse labels
- //
- for (var i in this.data) {
- var cell = this.data[i];
-
- // add label to index list
- var col_label = cell.col_label;
- if (this.colRank[col_label] === undefined) {
- this.colRank[col_label] = true;
- this.colLabel.push(col_label);
- this.colIndex.push(col_label);
- }
- var row_label = cell.row_label;
- if (this.rowRank[row_label] === undefined) {
- this.rowRank[row_label] = true;
- this.rowLabel.push(row_label);
- this.rowIndex.push(row_label);
- }
- }
-
- //
- // sort labels and update rank dictionary
- //
-
- // set sizes
- this.rowNumber = this.rowLabel.length
- this.colNumber = this.colLabel.length
-
- // sort labels alphabetical
- this.rowLabel.sort();
- this.colLabel.sort();
-
- // generate sorted key list for rows
- for (var i in this.rowLabel) {
- var row_label = this.rowLabel[i];
- var row = parseInt(i);
- this.rowRank[row_label] = row;
- }
-
- // generate sorted key list for columns
- for (var i in this.colLabel) {
- var col_label = this.colLabel[i];
- var col = parseInt(i);
- this.colRank[col_label] = col;
- }
-
- //
- // parse indexing from rank dictionary to cells
- //
-
- // min/max
- this.max = undefined;
- this.min = undefined
-
- // add indices to data
- for (var i in this.data) {
- // get cell data
- var cell = this.data[i];
-
- // add rank
- cell.col = this.colRank[cell.col_label];
- cell.row = this.rowRank[cell.row_label];
-
- // identify max/min values
- if (this.min == undefined || this.min > cell.value) {
- this.min = cell.value;
- }
- if (this.max == undefined || this.max < cell.value) {
- this.max = cell.value;
- }
- }
-
- //
- // translate original create cluster from order in original data
- //
-
- // generate sorted key list for columns
- for (var i in this.colIndex) {
- this.colIndex[i] = this.colRank[this.colIndex[i]];
- }
- // generate sorted key list for columns
- for (var i in this.rowIndex) {
- this.rowIndex[i] = this.rowRank[this.rowIndex[i]];
- }
-
- // middle
- this.mid = (this.max + this.min) / 2;
-
- //
- // set colors
- //
-
- // identify buckets
- this.nColors = this.options.colors.length;
-
- // color scale
- this.colorScale = d3.scale.quantile()
- .domain([this.min, this.mid, this.max])
- .range(this.options.colors);
-
- //
- // add ui elements
- //
- // create tooltip
- this.$tooltip = $(this._templateTooltip());
- this.$el.append(this.$tooltip);
-
- //
- // finally draw the heatmap
- //
- this._build();
-
- // catch window resize event
- $(window).resize(function () {
- self._build();
- });
- },
-
- _build: function() {
- // link this
- var self = this;
-
- // container (full draw area)
- this.widthContainer = this.$el.width();
- this.heightContainer = this.$el.height();
-
- // get grid dimensions
- this.width = this.widthContainer;
- this.height = this.heightContainer;
-
- // calculate cell size
- this.cellSize = Math.min(((this.height) / (this.rowNumber + this.margin.top + this.margin.bottom)),
- (this.width / (this.colNumber + this.margin.left + this.margin.right)));
-
- // set font size
- this.fontSize = Math.min(this.cellSize, 16);
-
- // set width/height for plugin
- this.width = this.cellSize * this.colNumber;
- this.height = this.cellSize * this.rowNumber;
-
- // get dimensions
- var margin = this.options.margin;
- var width = this.width;
- var height = this.height;
-
- // reset svg
- if (this.svg !== undefined) {
- this.$el.find('svg').remove();
- }
-
- // add main group and translate
- this.svg = d3.select(this.$el[0]).append('svg')
- .append('g')
- .attr('transform', 'translate(' + (this.widthContainer - width) / 2 + ',' +
- (this.heightContainer - height) / 2 + ')');
-
- // reset sorting
- this.rowSortOrder = false;
- this.colSortOrder = false;
-
- // build
- this.d3RowLabels = this._buildRowLabels();
- this.d3ColLabels = this._buildColLabels();
- this.d3HeatMap = this._buildHeatMap();
- this.d3Legend = this._buildLegend();
- this.d3Title = this._buildTitle();
- },
-
- // build title
- _buildTitle: function() {
- // link this
- var self = this;
-
- // gather data
- var height = this.height;
- var width = this.width;
- var cellSize = this.cellSize;
- var fontSize = this.fontSize;
- var title = this.options.title;
-
- // add title
- return this.svg.append('g')
- .append('text')
- .attr('x', width / 2)
- .attr('y', height + 3 * cellSize + fontSize + 3)
- .attr('text-anchor', 'middle')
- .text(title);
- },
-
- // build legend
- _buildLegend: function() {
- // link this
- var self = this;
-
- // gather data
- var cellSize = this.cellSize;
- var fontSize = this.fontSize;
- var height = this.height;
- var legendCellWidth = this.width / this.nColors;
-
- // create range labels
- var dataRange = [];
- for(var i = 0; i < this.nColors; i++) {
- dataRange.push('');
- }
-
- // prepare indices
- var dataRangeMin = 0;
- var dataRangeMid = parseInt((dataRange.length - 1) / 2);
- var dataRangeMax = dataRange.length - 1;
-
- // add labels
- dataRange[dataRangeMin] = this.min;
- dataRange[dataRangeMid] = this.mid;
- dataRange[dataRangeMax] = this.max;
-
- // create legend
- var legend = this.svg.selectAll('.legend')
- .data(dataRange)
- .enter().append('g')
- .attr('class', 'legend');
-
- // add boxes
- legend.append('rect')
- .attr('x', function(d, i) {
- return legendCellWidth * i;
- })
- .attr('y', height + cellSize)
- .attr('width', legendCellWidth)
- .attr('height', cellSize)
- .style('fill', function(d, i) {
- return self.options.colors[i];
- });
-
- // add text
- legend.append('text')
- .attr('class', 'mono')
- .text(function(d) {
- return d;
- })
- .attr('width', legendCellWidth)
- .attr('x', function(d, i) {
- return legendCellWidth * i;
- })
- .attr('y', height + cellSize - 3)
- .style('font-size', fontSize + 'px');
-
- // return
- return legend;
- },
-
- // build column labels
- _buildColLabels: function() {
- // link this
- var self = this;
-
- // gather data
- var cellSize = this.cellSize;
- var fontSize = this.fontSize;
- var colIndex = this.colIndex;
- var colLabel = this.colLabel;
-
- // column labels
- var colLabels = this.svg.append('g')
- .selectAll('.colLabelg')
- .data(colLabel)
- .enter()
- .append('text')
- .text(function (d) {
- return d;
- })
- .attr('x', 0)
- .attr('y', function (d, i) {
- return colIndex.indexOf(i) * cellSize;
- })
- .style('font-size', fontSize + 'px')
- .style('text-anchor', 'left')
- .attr('transform', 'translate(' + cellSize / 2 + ', -17) rotate (-90)')
- .attr('class', function (d, i) {
- return 'colLabel mono c' + i;
- })
- .on('mouseover', function(d) {
- d3.select(this).classed('text-hover',true);
- })
- .on('mouseout' , function(d) {
- d3.select(this).classed('text-hover',false);
- })
- .on('click', function(d, i) {
- self.colSortOrder=!self.colSortOrder;
- self._sortByLabel('c', 'row', self.rowNumber, i, self.colSortOrder);
- d3.select('#order').property('selectedIndex', 4).node().focus();
- });
-
- // return
- return colLabels;
- },
-
- // build row labels
- _buildRowLabels: function() {
- // link this
- var self = this;
-
- // gather data
- var cellSize = this.cellSize;
- var fontSize = this.fontSize;
- var rowIndex = this.rowIndex;
- var rowLabel = this.rowLabel;
-
- // draw labels
- var rowLabels = this.svg.append('g')
- .selectAll('.rowLabelg')
- .data(rowLabel)
- .enter()
- .append('text')
- .text(function (d) {
- return d;
- })
- .attr('x', 0)
- .attr('y', function (d, i) {
- return rowIndex.indexOf(i) * cellSize;
- })
- .style('font-size', fontSize + 'px')
- .style('text-anchor', 'end')
- .attr('transform', 'translate(-10,' + cellSize / 1.5 + ')')
- .attr('class', function (d, i) {
- return 'rowLabel mono r' + i;
- } )
- .on('mouseover', function(d) {
- d3.select(this).classed('text-hover',true);
- })
- .on('mouseout' , function(d) {
- d3.select(this).classed('text-hover',false);
- })
- .on('click', function(d, i) {
- self.rowSortOrder=!self.rowSortOrder;
- self._sortByLabel('r', 'col', self.colNumber, i, self.rowSortOrder);
- d3.select('#order').property('selectedIndex', 4).node().focus();
- });
-
- // return
- return rowLabels;
- },
-
- // build heat map
- _buildHeatMap: function() {
- // link this
- var self = this;
-
- // gather data
- var cellSize = this.cellSize;
- var rowIndex = this.rowIndex;
- var rowLabel = this.rowLabel;
- var colIndex = this.colIndex;
- var colLabel = this.colLabel;
-
- // heat map
- var heatmap = this.svg.append('g').attr('class','g3')
- .selectAll('.cellg')
- .data(self.data, function(d) {
- return d.row + ':' + d.col;
- })
- .enter()
- .append('rect')
- .attr('x', function(d) {
- return colIndex.indexOf(d.col) * cellSize;
- })
- .attr('y', function(d) {
- return rowIndex.indexOf(d.row) * cellSize;
- })
- .attr('class', function(d){
- return 'cell cell-border cr' + d.row + ' cc' + d.col;
- })
- .attr('width', cellSize)
- .attr('height', cellSize)
- .style('fill', function(d) {
- return self.colorScale(d.value);
- })
- .on('mouseover', function(d){
- // highlight text
- d3.select(this).classed('cell-hover',true);
- d3.selectAll('.rowLabel').classed('text-highlight',function(r,ri){ return ri==(d.row);});
- d3.selectAll('.colLabel').classed('text-highlight',function(c,ci){ return ci==(d.col);});
-
- // update the tooltip position and value
- d3.select('#heatmap-tooltip')
- .style('left', (d3.event.pageX+10) + 'px')
- .style('top', (d3.event.pageY-10) + 'px')
- .select('#value')
- .text('Label: ' + rowLabel[d.row] + ' | ' + colLabel[d.col] + ', Value: ' + d.value);
- // show the tooltip
- d3.select('#heatmap-tooltip').classed('hidden', false);
- })
- .on('mouseout', function(){
- d3.select(this).classed('cell-hover',false);
- d3.selectAll('.rowLabel').classed('text-highlight',false);
- d3.selectAll('.colLabel').classed('text-highlight',false);
- d3.select('#heatmap-tooltip').classed('hidden', true);
- });
-
- // return
- return heatmap;
- },
-
- // change ordering of cells
- _sortByLabel: function(rORc, rowORcol, n, index, sortOrder) {
- // get cell size
- var cellSize = this.cellSize;
-
- // define transition / prepare element
- var t = this.svg.transition().duration(this.options.pace);
-
- // create cells
- var cells=[];
- for (var i = 0; i < n; i++) {
- cells[i] = {
- value: this.min - 1
- }
- cells[i][rowORcol] = i;
- }
-
- // collect cells
- t.selectAll('.c' + rORc + index).filter(function(ce) {
- cells[ce[rowORcol]].value = ce.value;
- });
-
- // sort cells
- cells.sort(function(a, b) {
- if (sortOrder) {
- return b.value - a.value;
- } else {
- return a.value - b.value;
- }
- });
-
- // get sorted key list
- var sorted = [];
- for (var i in cells) {
- sorted.push(cells[i][rowORcol]);
- }
-
- // rows or columns
- if(rORc == 'r') {
- // sort cells
- t.selectAll('.cell')
- .attr('x', function(d) {
- return sorted.indexOf(d.col) * cellSize;
- });
-
- // sort labels
- t.selectAll('.colLabel')
- .attr('y', function (d, i) {
- return sorted.indexOf(i) * cellSize;
- });
- } else {
- // sort cells
- t.selectAll('.cell')
- .attr('y', function(d) {
- return sorted.indexOf(d.row) * cellSize;
- });
-
- // sort labels
- t.selectAll('.rowLabel')
- .attr('y', function (d, i) {
- return sorted.indexOf(i) * cellSize;
- });
- }
- },
-
- // sort function
- _sortByOrder: function (value) {
- // link this
- var self = this;
-
- // gather data
- var cellSize = this.cellSize;
- var rowIndex = this.rowIndex;
- var rowLabel = this.rowLabel;
- var colIndex = this.colIndex;
- var colLabel = this.colLabel;
-
- // set duration / select element
- var t = this.svg.transition().duration(this.options.pace);
- if(value=='hclust'){
- t.selectAll('.cell')
- .attr('x', function(d) {
- return colIndex.indexOf(d.col) * cellSize;
- })
- .attr('y', function(d) {
- return rowIndex.indexOf(d.row) * cellSize;
- });
-
- t.selectAll('.rowLabel')
- .attr('y', function(d, i) {
- return rowIndex.indexOf(i) * cellSize;
- });
-
- t.selectAll('.colLabel')
- .attr('y', function(d, i) {
- return colIndex.indexOf(i) * cellSize;
- });
-
- } else if (value=='byboth') {
- t.selectAll('.cell')
- .attr('x', function(d) {
- return d.col * cellSize;
- })
- .attr('y', function(d) {
- return d.row * cellSize;
- });
-
- t.selectAll('.rowLabel')
- .attr('y', function (d, i) {
- return i * cellSize;
- });
-
- t.selectAll('.colLabel')
- .attr('y', function (d, i) {
- return i * cellSize;
- });
- } else if (value=='byrow') {
- t.selectAll('.cell')
- .attr('y', function(d) {
- return d.row * cellSize;
- });
-
- t.selectAll('.rowLabel')
- .attr('y', function (d, i) {
- return i * cellSize;
- });
- } else if (value=='bycol'){
- t.selectAll('.cell')
- .attr('x', function(d) {
- return d.col * cellSize;
- });
- t.selectAll('.colLabel')
- .attr('y', function (d, i) {
- return i * cellSize;
- });
- }
- },
-
- // selection of cells
- _addSelectionTool: function() {
- //
- // selection
- //
- var sa=d3.select('.g3')
- .on('mousedown', function() {
- if( !d3.event.altKey) {
- d3.selectAll('.cell-selected').classed('cell-selected', false);
- d3.selectAll('.rowLabel').classed('text-selected', false);
- d3.selectAll('.colLabel').classed('text-selected', false);
- }
- var p = d3.mouse(this);
- sa.append('rect')
- .attr({
- rx : 0,
- ry : 0,
- class : 'selection',
- x : p[0],
- y : p[1],
- width : 1,
- height : 1
- })
- })
- .on('mousemove', function() {
- var s = sa.select('rect.selection');
-
- if(!s.empty()) {
- var p = d3.mouse(this),
- d = {
- x : parseInt(s.attr('x'), 10),
- y : parseInt(s.attr('y'), 10),
- width : parseInt(s.attr('width'), 10),
- height : parseInt(s.attr('height'), 10)
- },
- move = {
- x : p[0] - d.x,
- y : p[1] - d.y
- };
-
- if(move.x < 1 || (move.x*2<d.width)) {
- d.x = p[0];
- d.width -= move.x;
- } else {
- d.width = move.x;
- }
-
- if(move.y < 1 || (move.y*2<d.height)) {
- d.y = p[1];
- d.height -= move.y;
- } else {
- d.height = move.y;
- }
- s.attr(d);
-
- // deselect all temporary selected state objects
- d3.selectAll('.cell-selection.cell-selected').classed('cell-selected', false);
- d3.selectAll('.text-selection.text-selected').classed('text-selected',false);
- d3.selectAll('.cell').filter(function(cell_d, i) {
- if(!d3.select(this).classed('cell-selected') &&
- // inner circle inside selection frame
- (this.x.baseVal.value)+cellSize >= d.x && (this.x.baseVal.value)<=d.x+d.width &&
- (this.y.baseVal.value)+cellSize >= d.y && (this.y.baseVal.value)<=d.y+d.height)
- {
- d3.select(this)
- .classed('cell-selection', true)
- .classed('cell-selected', true);
-
- d3.select('.r' + cell_d.row)
- .classed('text-selection',true)
- .classed('text-selected',true);
-
- d3.select('.c' + cell_d.col)
- .classed('text-selection',true)
- .classed('text-selected',true);
- }
- });
- }
- })
- .on('mouseup', function() {
- // remove selection frame
- sa.selectAll('rect.selection').remove();
-
- // remove temporary selection marker class
- d3.selectAll('.cell-selection').classed('cell-selection', false);
- d3.selectAll('.text-selection').classed('text-selection', false);
- })
- .on('mouseout', function() {
- if(d3.event.relatedTarget.tagName=='html') {
- // remove selection frame
- sa.selectAll('rect.selection').remove();
-
- // remove temporary selection marker class
- d3.selectAll('.cell-selection').classed('cell-selection', false);
- d3.selectAll('.rowLabel').classed('text-selected',false);
- d3.selectAll('.colLabel').classed('text-selected',false);
- }
- });
- },
-
- // template
- _templateSelect: function() {
- return '<select id="order">' +
- '<option value="hclust">Cluster</option>' +
- '<option value="byboth">Sort by row and column</option>' +
- '<option value="byrow">Sort by row label</option>' +
- '<option value="bycol">Sort by column label</option>' +
- '</select>';
- },
-
- // template
- _templateTooltip: function() {
- return '<div id="heatmap-tooltip" class="hidden">' +
- '<p><span id="value"></p>'
- '</div>';
- }
-});
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/heatmap/logo.png
Binary file config/plugins/visualizations/charts/static/charts/heatmap/logo.png has changed
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/heatmap/wrapper.js
--- a/config/plugins/visualizations/charts/static/charts/heatmap/wrapper.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// dependencies
-define(['utils/utils', 'plugin/charts/heatmap/heatmap-plugin', 'plugin/charts/heatmap/heatmap-parameters'],
-function(Utils, HeatmapPlugin, HeatmapParameters) {
-
-// widget
-return Backbone.View.extend(
-{
- // initialize
- initialize: function(app, options) {
- this.app = app;
- this.options = options;
- },
-
- // render
- draw : function(process_id, chart, request_dictionary)
- {
- // link this
- var self = this;
-
- // loop through data groups
- var index = 0;
- for (var group_index in request_dictionary.groups) {
-
- // configure request
- var tmp_dict = {
- id : request_dictionary.id,
- groups : [{
- key : request_dictionary.groups[group_index].key,
- columns : {
- row_label: {
- index : index++,
- is_label : true
- },
- col_label: {
- index : index++,
- is_label : true
- },
- value: {
- index : index++
- }
- }
- }]
- };
-
- // target div
- var group_div = self.options.canvas[group_index];
-
- // draw group
- this._draw_group(group_index, group_div, chart, tmp_dict, function(group_index) {
- if (group_index == request_dictionary.groups.length - 1) {
- // set chart state
- chart.state('ok', 'Heat map drawn.');
-
- // unregister process
- chart.deferred.done(process_id);
- }
- });
- }
- },
-
- // draw group
- _draw_group: function(group_index, div, chart, request_dictionary, callback) {
- // link this
- var self = this;
-
- // request data
- this.app.datasets.request(request_dictionary, function() {
-
- // get group
- var group = request_dictionary.groups[0];
-
- // draw plot
- var heatmap = new HeatmapPlugin({
- 'title' : group.key,
- 'colors' : HeatmapParameters.colorSets[chart.settings.get('color_set')],
- 'data' : group.values,
- 'div' : div
- });
-
- // callback on completion
- callback (group_index);
- });
- }
-});
-
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/highcharts_boxplot/config.js
--- a/config/plugins/visualizations/charts/static/charts/highcharts_boxplot/config.js
+++ /dev/null
@@ -1,40 +0,0 @@
-define([], function() {
-
-return {
- title : 'Box plot',
- category : 'Data processing (requires \'charts\' tool from Toolshed)',
- library : 'highcharts.js',
- tag : 'div',
- execute : 'boxplot',
- columns : {
- y : {
- title : 'Observations'
- }
- },
- settings : {
- separator_label : {
- title : 'X axis',
- type : 'separator'
- },
- x_axis_label : {
- title : 'Axis label',
- info : 'Provide a label for the axis.',
- type : 'text',
- init : 'X-axis',
- placeholder : 'Axis label'
- },
- separator_tick : {
- title : 'Y axis',
- type : 'separator'
- },
- y_axis_label : {
- title : 'Axis label',
- info : 'Provide a label for the axis.',
- type : 'text',
- init : 'Y-axis',
- placeholder : 'Axis label'
- }
- }
-};
-
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/highcharts_boxplot/logo.png
Binary file config/plugins/visualizations/charts/static/charts/highcharts_boxplot/logo.png has changed
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/highcharts_boxplot/wrapper.js
--- a/config/plugins/visualizations/charts/static/charts/highcharts_boxplot/wrapper.js
+++ /dev/null
@@ -1,122 +0,0 @@
-// dependencies
-define(['utils/utils'], function(Utils) {
-
-// widget
-return Backbone.View.extend(
-{
- // highcharts configuration
- hc_config : {
- chart: {
- type: 'boxplot'
- },
-
- title: {
- text: ''
- },
-
- legend: {
- enabled: false
- },
-
- credits: {
- enabled: false
- },
-
- plotOptions: {
- series: {
- animation: false
- }
- },
-
- xAxis: {
- categories: [],
- title: {
- text: ''
- }
- },
-
- yAxis: {
- title: {
- text: ''
- }
- },
-
- series: [{
- name: 'Details:',
- data: [],
- tooltip: {
- headerFormat: '<em>{point.key}</em><br/>'
- }
- }]
- },
-
- // initialize
- initialize: function(app, options) {
- this.app = app;
- this.options = options;
- },
-
- // render
- draw : function(process_id, chart, request_dictionary)
- {
- // configure request
- var index = 0;
- for (var i in request_dictionary.groups) {
- var group = request_dictionary.groups[i];
- group.columns = null;
- group.columns = {
- x: {
- index: index++
- }
- }
- }
-
- // set axis labels
- this.hc_config.xAxis.title.text = chart.settings.get('x_axis_label');
- this.hc_config.yAxis.title.text = chart.settings.get('y_axis_label');
-
- // request data
- var self = this;
- this.app.datasets.request(request_dictionary, function() {
-
- // reset data/categories
- var data = [];
- var categories = [];
-
- // loop through data groups
- for (var key in request_dictionary.groups) {
- // get group
- var group = request_dictionary.groups[key];
-
- // add category
- categories.push(group.key);
-
- // format chart data
- var point = [];
- for (var key in group.values) {
- point.push(group.values[key].x);
- }
-
- // add to data
- data.push (point);
- }
-
- // categories
- self.hc_config.xAxis.categories = categories;
-
- // update data
- self.hc_config.series[0].data = data;
-
- // draw plot
- self.options.canvas[0].highcharts(self.hc_config);
-
- // set chart state
- chart.state('ok', 'Box plot drawn.');
-
- // unregister process
- chart.deferred.done(process_id);
- });
- }
-});
-
-});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/bar/config.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/jqplot/bar/config.js
@@ -0,0 +1,20 @@
+define(['plugin/charts/jqplot/common/config'], function(plot_config) {
+
+return $.extend(true, {}, plot_config, {
+ title : 'Regular',
+ category : 'Bar diagrams',
+ columns : {
+ x : {
+ title : 'Values for x-axis',
+ is_label : true,
+ is_auto : true,
+ is_unique : true
+ },
+ y : {
+ title : 'Values for y-axis',
+ is_numeric : true
+ }
+ }
+});
+
+});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/bar/logo.png
Binary file config/plugins/visualizations/charts/static/charts/jqplot/bar/logo.png has changed
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/bar/wrapper.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/jqplot/bar/wrapper.js
@@ -0,0 +1,26 @@
+// dependencies
+define(['plugin/charts/jqplot/common/wrapper'], function(Plot) {
+
+// widget
+return Backbone.Model.extend({
+ initialize: function(app, options) {
+ options.makeConfig = function(groups, plot_config){
+ $.extend(true, plot_config, {
+ seriesDefaults: {
+ renderer : $.jqplot.BarRenderer
+ },
+ axes: {
+ xaxis: {
+ min : -1
+ },
+ yaxis: {
+ pad : 1.2
+ }
+ }
+ });
+ };
+ new Plot(app, options);
+ }
+});
+
+});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/boxplot/config.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/jqplot/boxplot/config.js
@@ -0,0 +1,23 @@
+define(['plugin/charts/jqplot/common/config'], function(plot_config) {
+
+return $.extend(true, {}, plot_config, {
+ title : 'Box plot',
+ category : 'Data processing (requires \'charts\' tool from Toolshed)',
+ library : 'jqPlot',
+ tag : 'div',
+ execute : 'boxplot',
+ keywords : 'small medium large',
+ columns : {
+ y : {
+ title : 'Observations',
+ is_numeric : true
+ }
+ },
+ settings : {
+ show_legend : {
+ init : 'false'
+ }
+ }
+});
+
+});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/boxplot/logo.png
Binary file config/plugins/visualizations/charts/static/charts/jqplot/boxplot/logo.png has changed
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/boxplot/wrapper.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/jqplot/boxplot/wrapper.js
@@ -0,0 +1,127 @@
+// dependencies
+define(['plugin/charts/jqplot/common/wrapper', 'plugin/charts/tools'], function(Plot, Tools) {
+
+// widget
+return Backbone.View.extend(
+{
+ // initialize
+ initialize: function(app, options) {
+ // get request dictionary
+ var request_dictionary = options.request_dictionary;
+ var chart = options.chart;
+
+ // modify request
+ var index = 0;
+ for (var i in request_dictionary.groups) {
+ var group = request_dictionary.groups[i];
+ group.columns = null;
+ group.columns = {
+ x: {
+ index: index++
+ }
+ }
+ }
+
+ // create plot
+ var plot = new Plot(app, {
+ process_id : options.process_id,
+ chart : options.chart,
+ request_dictionary : options.request_dictionary,
+ canvas_list : options.canvas_list,
+ makeConfig : function(groups, plot_config){
+ var boundary = Tools.getDomains(groups, 'x');
+ $.extend(true, plot_config, {
+ seriesDefaults: {
+ renderer: $.jqplot.OHLCRenderer,
+ rendererOptions : {
+ candleStick : true,
+ fillUpBody : true,
+ fillDownBody : true
+ }
+ },
+ axes : {
+ xaxis: {
+ min: -1,
+ max: groups.length + 0.01
+ },
+ yaxis: {
+ min: boundary.x.min,
+ max: boundary.x.max
+ }
+ }
+ });
+ },
+ makeCategories: function(groups) {
+ // define custom category labels
+ var x_labels = [];
+ for (var group_index in groups) {
+ x_labels.push(groups[group_index].key);
+ }
+
+ // use default mapping
+ Tools.mapCategories (groups, x_labels);
+
+ // return labels array for x axis
+ return {
+ array: {
+ x : x_labels
+ }
+ }
+ },
+ makeSeriesLabels : function (groups, plot_config) {
+ return [{
+ label: 'Boxplot values'
+ }];
+ },
+ makeSeries: function (groups) {
+ /*/ example data
+ var catOHLC = [
+ [0, 138.7, 139.68, 135.18, 135.4],
+ [1, 143.46, 144.66, 139.79, 140.02],
+ [2, 140.67, 143.56, 132.88, 142.44],
+ [3, 136.01, 139.5, 134.53, 139.48]
+ ];
+ return [catOHLC];*/
+
+ // plot data
+ var plot_data = [];
+
+ // check group length
+ if (groups.length == 0 || groups[0].values.length < 5) {
+ chart.state('failed', 'Boxplot data could not be found.');
+ return [plot_data];
+ }
+
+ // loop through data groups
+ var indeces = [2, 4, 0, 1];
+ for (var group_index in groups) {
+ // get group
+ var group = groups[group_index];
+
+ // format chart data
+ var point = [];
+ point.push(parseInt(group_index));
+ for (var key in indeces) {
+ point.push(group.values[indeces[key]].x);
+ }
+
+ // add to data
+ plot_data.push (point);
+ }
+
+ // HACK: the boxplot renderer has an issue with single elements
+ var point = [];
+ point[0] = plot_data.length;
+ for (var key in indeces) {
+ point.push(0);
+ }
+ plot_data.push (point);
+
+ // return
+ return [plot_data];
+ }
+ });
+ }
+});
+
+});
\ No newline at end of file
diff -r 803567ccb30e01477a96d47cd39f6354337c5c5d -r a15c52999493cd723c114899d4224912b2c28ffc config/plugins/visualizations/charts/static/charts/jqplot/common/config.js
--- /dev/null
+++ b/config/plugins/visualizations/charts/static/charts/jqplot/common/config.js
@@ -0,0 +1,51 @@
+define(['plugin/charts/forms/default'], function(config_default) {
+
+return $.extend(true, {}, config_default, {
+ title : '',
+ category : '',
+ library : 'jqPlot',
+ tag : 'div',
+ zoomable : true,
+ keywords : 'medium',
+ query_limit : 10000,
+ settings : {
+ separator_grid : {
+ title : 'Grids',
+ type : 'separator'
+ },
+ x_axis_grid : {
+ title : 'Axis grid',
+ info : 'Would you like to show grid lines for the X axis?',
+ type : 'radiobutton',
+ init : 'false',
+ data : [
+ {
+ label : 'On',
+ value : 'true'
+ },
+ {
+ label : 'Off',
+ value : 'false'
+ }
+ ]
+ },
+ y_axis_grid : {
+ title : 'Axis grid',
+ info : 'Would you like to show grid lines for the Y axis?',
+ type : 'radiobutton',
+ init : 'true',
+ data : [
+ {
+ label : 'On',
+ value : 'true'
+ },
+ {
+ label : 'Off',
+ value : 'false'
+ }
+ ]
+ }
+ }
+});
+
+});
\ No newline at end of file
This diff is so big that we needed to truncate the remainder.
https://bitbucket.org/galaxy/galaxy-central/commits/8bf883f2638e/
Changeset: 8bf883f2638e
Branch: stable
User: guerler
Date: 2014-06-24 19:50:03
Summary: Charts style update
Affected #: 2 files
diff -r a15c52999493cd723c114899d4224912b2c28ffc -r 8bf883f2638e1bae7a1761a0fab98a981d6fa315 static/style/blue/base.css
--- a/static/style/blue/base.css
+++ b/static/style/blue/base.css
@@ -148,7 +148,7 @@
.form-control::-moz-placeholder{color:#999}
.form-control:-ms-input-placeholder{color:#999}
.form-control::-webkit-input-placeholder{color:#999}
-.form-control{display:block;width:100%;height:27px;padding:4px 10px;font-size:12px;line-height:1.428571429;color:#555;vertical-align:middle;background-color:#fff;border:1px solid #aaa;border-radius:3px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6)}
+.form-control,.ui-input{display:block;width:100%;height:27px;padding:4px 10px;font-size:12px;line-height:1.428571429;color:#555;vertical-align:middle;background-color:#fff;border:1px solid #aaa;border-radius:3px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6)}
.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control{cursor:not-allowed;background-color:#eee}
textarea.form-control{height:auto}
.form-group{margin-bottom:15px}
@@ -1278,17 +1278,25 @@
.upload-ftp .upload-ftp-help{margin-bottom:10px}
.upload-ftp .upload-ftp-warning{text-align:center;margin-top:20px}
.upload-settings .upload-settings-cover{position:absolute;width:100%;height:100%;top:0px;left:0px;background:#fff;opacity:0.4;cursor:no-drop}
+.ui-radiobutton label{height:23px;line-height:1em}
+.ui-table-form-separator{font-weight:bold;font-size:0.9em}
+.ui-label{font-weight:bold}
+.ui-message{padding:2px 2px 2px 10px}
+.ui-icon{font-size:1.2em}
+.ui-button-icon{margin-right:5px}.ui-button-icon ul i{font-size:1.2em;margin-right:5px;position:relative;top:1px}
+.ui-button-icon .button{margin-right:5px;margin-left:5px}
+.ui-button-icon .title{position:relative;font-size:0.8em;font-weight:normal;top:-1px}
+.ui-tabs .ui-tabs-add{font-size:0.8em;margin-right:5px}
+.ui-tabs .ui-tabs-delete{font-size:0.8em;margin-left:5px;cursor:pointer}
.no-highlight{-webkit-user-select:none;-moz-user-select:none;-khtml-user-select:none;-ms-user-select:none;}
-.portlet-view{min-width:300px}.portlet-view .portlet-title-icon{float:left;font-size:1.2em;padding-top:4px}
-.portlet-view .portlet-title{overflow:hidden;padding:2px 5px 2px 10px}
-.portlet-view .portlet-title-text{float:left;padding-top:2px}
-.portlet-view .portlet-operations{float:right;cursor:pointer}
-.portlet-view .portlet-buttons{height:50px;padding:10px}
-.portlet-view .portlet-content{height:inherit;padding:10px}
-.popover-view{max-width:700px;display:none}.popover-view .popover-close{position:absolute;right:10px;top:7px;font-size:1.2em;cursor:pointer}
-.popover-view .popover-title{padding:4px 10px}
-.styled-select{position:relative;height:27px;overflow:hidden;border:1px solid #bfbfbf;-moz-border-radius:3px;border-radius:3px}.styled-select .button{position:relative;width:25px;height:100%;float:right;border-left:1px solid #bfbfbf;padding-left:9px;padding-top:4px;background:#f2f2f2}
-.styled-select select{position:absolute;top:0px;height:100%;width:100%;padding-left:5px;cursor:pointer;background:transparent;border:0;border-radius:0;-webkit-appearance:none}
+.ui-portlet{border:solid #d6b161 1px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;position:relative;clear:both;width:auto;height:100%}.ui-portlet .portlet-header{padding:5px 10px;background:#ebd9b2;border-bottom:solid #d6b161 1px;padding:2px 8px;overflow:visible;float:right;width:100%}.ui-portlet .portlet-header h1,.ui-portlet .portlet-header h2,.ui-portlet .portlet-header h3,.ui-portlet .portlet-header h4,.ui-portlet .portlet-header h5,.ui-portlet .portlet-header h6{float:left;font-weight:normal;display:inline-block;vertical-align:middle;font-size:1em;margin:3px}.ui-portlet .portlet-header h1 .icon,.ui-portlet .portlet-header h2 .icon,.ui-portlet .portlet-header h3 .icon,.ui-portlet .portlet-header h4 .icon,.ui-portlet .portlet-header h5 .icon,.ui-portlet .portlet-header h6 .icon{font-size:1.2em}
+.ui-portlet .portlet-buttons{height:50px;padding:10px}
+.ui-portlet .portlet-content{height:inherit;padding:10px;clear:both}.ui-portlet .portlet-content .content{padding:10px;height:100%;width:100%}.ui-portlet .portlet-content .content .buttons{height:50px;padding:10px}
+.ui-portlet .no-scroll{height:calc(100% - 80px)}
+.ui-popover{max-width:700px;display:none}.ui-popover .popover-close{position:absolute;right:10px;top:7px;font-size:1.2em;cursor:pointer}
+.ui-popover .popover-title{padding:4px 10px}
+.ui-select{position:relative;height:27px;overflow:hidden;border:1px solid #bfbfbf;-moz-border-radius:3px;border-radius:3px}.ui-select .button{position:relative;width:25px;height:100%;float:right;border-left:1px solid #bfbfbf;padding-left:9px;padding-top:4px;background:#f2f2f2}
+.ui-select select{position:absolute;top:0px;height:100%;width:100%;padding-left:5px;cursor:pointer;background:transparent;border:0;border-radius:0;-webkit-appearance:none}
.libraryRow{background-color:#ebd9b2}
.datasetHighlighted{background-color:#f9f9f9}
.libraryItemDeleted-True{font-style:italic}
@@ -1453,7 +1461,7 @@
div.form-row-input{width:90%;float:left}
div.form-row-input label{font-weight:normal;display:inline}
div.form-row-error-message{width:300px;float:left;color:red;font-weight:bold;padding:3px 0}
-.form-row .help,.toolParamHelp{color:#666}.form-row .help a,.toolParamHelp a{color:#666}
+.form-row .help,.toolParamHelp,.ui-table-form-info{color:#666}.form-row .help a,.toolParamHelp a{color:#666}
.form-row.form-actions{background:whiteSmoke;border-top:solid #ddd 1px;padding-top:10px;padding-bottom:10px;margin-top:5px}
select{padding:2px;font-size:12px;line-height:1.428571429}
select,input,textarea{font:inherit}
@@ -1519,13 +1527,13 @@
.grid-header{padding-bottom:1em}
.grid-header h2{margin:0;margin-bottom:0.5em}
.grid-header .title{font-weight:bold}
-.grid{padding-top:1em;border-collapse:collapse;width:100%}
-.grid tbody td{line-height:1.428571429;border-top:solid #DDDDDD 1px;border-bottom:solid #DDDDDD 1px;padding:5px}
+.grid,.ui-table{padding-top:1em;border-collapse:collapse;width:100%}
+.grid tbody td,.ui-table tbody td{line-height:1.428571429;border-top:solid #DDDDDD 1px;border-bottom:solid #DDDDDD 1px;padding:5px}
.grid tbody td:empty{padding:0}
.grid thead tr{height:2em}
.grid thead th{line-height:1.428571429;background:#ebd9b2;color:#000;border-top:solid #d6b161 1px;border-bottom:solid #d6b161 1px;padding:5px;text-align:left;white-space:nowrap}
.grid tfoot td{background-color:#F8F8F8;border-top:solid #DDDDDD 1px;border-bottom:solid #DDDDDD 1px;padding:5px}
-.grid .current{background-color:#EEEEFF}
+.grid .current,.ui-table .current{background-color:#EEEEFF}
.count-box{min-width:1.1em;padding:5px;border-width:1px;border-style:solid;text-align:center;display:inline-block}
.text-filter-val{border:solid 1px #AAAAAA;padding:1px 2px 1px 3px;margin-right:5px;-moz-border-radius:.5em;-webkit-border-radius:.5em;font-style:italic}
.page-link a,.inactive-link{padding:0px 7px 0px 7px;color:#555}
diff -r a15c52999493cd723c114899d4224912b2c28ffc -r 8bf883f2638e1bae7a1761a0fab98a981d6fa315 static/style/src/less/ui.less
--- a/static/style/src/less/ui.less
+++ b/static/style/src/less/ui.less
@@ -1,3 +1,80 @@
+.ui-radiobutton {
+ label {
+ height: 23px;
+ line-height: 1em;
+ }
+}
+
+.ui-table {
+ &:extend(.grid);
+
+ tbody td {
+ &:extend(.grid tbody td);
+ }
+ .current {
+ &:extend(.grid .current);
+ }
+}
+
+.ui-table-form-info {
+ &:extend(.toolParamHelp);
+}
+
+.ui-table-form-separator {
+ font-weight: bold;
+ font-size: 0.9em;
+}
+
+.ui-label {
+ font-weight: bold;
+}
+
+.ui-message {
+ padding: 2px 2px 2px 10px;
+}
+
+.ui-icon {
+ font-size: 1.2em;
+}
+
+.ui-button-icon {
+ margin-right: 5px;
+ ul {
+ i {
+ font-size: 1.2em; margin-right: 5px; position: relative; top: 1px;
+ }
+ }
+}
+
+.ui-button-icon .button {
+ margin-right: 5px;
+ margin-left: 5px;
+}
+
+.ui-button-icon .title {
+ position: relative;
+ font-size: 0.8em;
+ font-weight: normal;
+ top: -1px;
+}
+
+.ui-input {
+ &:extend(.form-control);
+}
+
+.ui-tabs {
+ .ui-tabs-add {
+ font-size : 0.8em;
+ margin-right : 5px;
+ }
+
+ .ui-tabs-delete {
+ font-size : 0.8em;
+ margin-left : 5px;
+ cursor : pointer;
+ }
+}
+
.no-highlight {
-webkit-user-select: none; /* webkit (safari, chrome) browsers */
-moz-user-select: none; /* mozilla browsers */
@@ -5,30 +82,38 @@
-ms-user-select: none; /* IE10+ */
}
-.portlet-view {
- min-width: 300px;
+.ui-portlet {
+ border: solid @form-border 1px;
+ .border-radius(@panel-border-radius);
- .portlet-title-icon {
- float: left;
- font-size: 1.2em;
- padding-top: 4px;
- }
-
- .portlet-title {
- overflow: hidden;
- padding: 2px 5px 2px 10px;
+ position: relative;
+ clear: both;
+ width: auto;
+ height: 100%;
+
+ .portlet-header {
+ padding: 5px 10px;
+ background: @form-heading-bg;
+ border-bottom: solid @form-border 1px;
+ padding: 2px 8px;
+ overflow: visible;
+ float: right;
+ width:100%;
+
+ h1, h2, h3, h4, h5, h6 {
+ float: left;
+ font-weight: normal;
+ display: inline-block;
+ vertical-align: middle;
+ font-size: 1em;
+ margin: 3px;
+
+ .icon {
+ font-size: 1.2em;
+ }
+ }
}
- .portlet-title-text {
- float: left;
- padding-top: 2px;
- }
-
- .portlet-operations {
- float: right;
- cursor: pointer;
- }
-
.portlet-buttons {
height: 50px;
padding: 10px;
@@ -37,10 +122,26 @@
.portlet-content {
height: inherit;
padding: 10px;
+ clear: both;
+
+ .content {
+ padding : 10px;
+ height : 100%;
+ width : 100%;
+
+ .buttons {
+ height: 50px;
+ padding: 10px;
+ }
+ }
+ }
+
+ .no-scroll {
+ height: ~'calc(100% - 80px)';
}
}
-.popover-view {
+.ui-popover {
max-width: 700px;
display: none;
@@ -57,7 +158,7 @@
}
}
-.styled-select {
+.ui-select {
position: relative;
height: 27px;
overflow: hidden;
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: greg: Handle exporting and importing repository capsules with new ExportRepositoryManager and ImportRepositoryMnager classes respectively.
by commits-noreply@bitbucket.org 24 Jun '14
by commits-noreply@bitbucket.org 24 Jun '14
24 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/fdaad2cad392/
Changeset: fdaad2cad392
User: greg
Date: 2014-06-24 19:11:24
Summary: Handle exporting and importing repository capsules with new ExportRepositoryManager and ImportRepositoryMnager classes respectively.
Affected #: 10 files
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/galaxy/webapps/tool_shed/api/repositories.py
--- a/lib/galaxy/webapps/tool_shed/api/repositories.py
+++ b/lib/galaxy/webapps/tool_shed/api/repositories.py
@@ -10,14 +10,14 @@
from galaxy.web.base.controller import BaseAPIController
from galaxy.web.base.controller import HTTPBadRequest
from galaxy.web.framework.helpers import time_ago
+from tool_shed.capsule import capsule_manager
import tool_shed.repository_types.util as rt_util
-import tool_shed.util.shed_util_common as suc
from tool_shed.util import basic_util
from tool_shed.util import encoding_util
from tool_shed.util import hg_util
-from tool_shed.util import import_util
from tool_shed.util import metadata_util
from tool_shed.util import repository_maintenance_util
+from tool_shed.util import shed_util_common as suc
from tool_shed.util import tool_util
log = logging.getLogger( __name__ )
@@ -248,10 +248,14 @@
except tarfile.ReadError, e:
log.debug( 'Error opening capsule file %s: %s' % ( str( capsule_file_name ), str( e ) ) )
return {}
+ irm = capsule_manager.ImportRepositoryManager( trans.app,
+ trans.request.host,
+ trans.user,
+ trans.user_is_admin() )
capsule_dict[ 'tar_archive' ] = tar_archive
capsule_dict[ 'capsule_file_name' ] = capsule_file_name
- capsule_dict = import_util.extract_capsule_files( **capsule_dict )
- capsule_dict = import_util.validate_capsule( **capsule_dict )
+ capsule_dict = irm.extract_capsule_files( **capsule_dict )
+ capsule_dict = irm.validate_capsule( **capsule_dict )
status = capsule_dict.get( 'status', 'error' )
if status == 'error':
log.debug( 'The capsule contents are invalid and cannot be imported:<br/>%s' % \
@@ -263,15 +267,12 @@
return {}
file_path = encoding_util.tool_shed_decode( encoded_file_path )
export_info_file_path = os.path.join( file_path, 'export_info.xml' )
- export_info_dict = import_util.get_export_info_dict( export_info_file_path )
+ export_info_dict = irm.get_export_info_dict( export_info_file_path )
manifest_file_path = os.path.join( file_path, 'manifest.xml' )
# The manifest.xml file has already been validated, so no error_message should be returned here.
- repository_info_dicts, error_message = import_util.get_repository_info_from_manifest( manifest_file_path )
+ repository_info_dicts, error_message = irm.get_repository_info_from_manifest( manifest_file_path )
# Determine the status for each exported repository archive contained within the capsule.
- repository_status_info_dicts = import_util.get_repository_status_from_tool_shed( trans.app,
- trans.user,
- trans.user_is_admin(),
- repository_info_dicts )
+ repository_status_info_dicts = irm.get_repository_status_from_tool_shed( repository_info_dicts )
# Generate a list of repository name / import results message tuples for display after the capsule is imported.
import_results_tups = []
# Only create repositories that do not yet exist and that the current user is authorized to create. The
@@ -280,12 +281,9 @@
# Add the capsule_file_name and encoded_file_path to the repository_status_info_dict.
repository_status_info_dict[ 'capsule_file_name' ] = capsule_file_name
repository_status_info_dict[ 'encoded_file_path' ] = encoded_file_path
- import_results_tups = import_util.create_repository_and_import_archive( trans.app,
- trans.request.host,
- trans.user,
- repository_status_info_dict,
- import_results_tups )
- import_util.check_status_and_reset_downloadable( trans.app, import_results_tups )
+ import_results_tups = irm.create_repository_and_import_archive( repository_status_info_dict,
+ import_results_tups )
+ irm.check_status_and_reset_downloadable( import_results_tups )
basic_util.remove_dir( file_path )
# NOTE: the order of installation is defined in import_results_tups, but order will be lost
# when transferred to return_dict.
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/galaxy/webapps/tool_shed/api/repository_revisions.py
--- a/lib/galaxy/webapps/tool_shed/api/repository_revisions.py
+++ b/lib/galaxy/webapps/tool_shed/api/repository_revisions.py
@@ -5,7 +5,7 @@
from galaxy import util
from galaxy.model.orm import and_, not_, select
from galaxy.web.base.controller import BaseAPIController, HTTPBadRequest
-from tool_shed.util import export_util
+from tool_shed.capsule import capsule_manager
from tool_shed.util import hg_util
import tool_shed.util.shed_util_common as suc
@@ -53,15 +53,14 @@
log.debug( error_message )
return None, error_message
repository_id = trans.security.encode_id( repository.id )
- return export_util.export_repository( trans.app,
- trans.user,
- tool_shed_url,
- repository_id,
- str( repository.name ),
- changeset_revision,
- file_type,
- export_repository_dependencies,
- api=True )
+ erm = capsule_manager.ExportRepositoryManager( app=trans.app,
+ user=trans.user,
+ tool_shed_url=tool_shed_url,
+ repository=repository,
+ changeset_revision=changeset_revision,
+ export_repository_dependencies=export_repository_dependencies,
+ using_api=True )
+ return erm.export_repository()
def __get_value_mapper( self, trans ):
value_mapper = { 'id' : trans.security.encode_id,
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -14,20 +14,19 @@
from galaxy.web.framework.helpers import grids
from galaxy.util import json
from galaxy.model.orm import and_
-import tool_shed.util.shed_util_common as suc
+from tool_shed.capsule import capsule_manager
from tool_shed.util import basic_util
from tool_shed.util import common_util
from tool_shed.util import container_util
from tool_shed.util import encoding_util
-from tool_shed.util import export_util
from tool_shed.util import hg_util
-from tool_shed.util import import_util
from tool_shed.util import metadata_util
from tool_shed.util import readme_util
from tool_shed.util import repository_dependency_util
from tool_shed.util import repository_maintenance_util
from tool_shed.util import review_util
from tool_shed.util import search_util
+from tool_shed.util import shed_util_common as suc
from tool_shed.util import tool_dependency_util
from tool_shed.util import tool_util
from tool_shed.util import workflow_util
@@ -1149,7 +1148,7 @@
# server account's .hgrc file to include the following setting:
# [web]
# allow_archive = bz2, gz, zip
- file_type_str = export_util.get_file_type_str( changeset_revision, file_type )
+ file_type_str = basic_util.get_file_type_str( changeset_revision, file_type )
repository.times_downloaded += 1
trans.sa_session.add( repository )
trans.sa_session.flush()
@@ -1172,15 +1171,14 @@
file_type = 'gz'
export_repository_dependencies = CheckboxField.is_checked( export_repository_dependencies )
tool_shed_url = web.url_for( '/', qualified=True )
- repositories_archive, error_message = export_util.export_repository( trans.app,
- trans.user,
- tool_shed_url,
- repository_id,
- str( repository.name ),
- changeset_revision,
- file_type,
- export_repository_dependencies,
- api=False )
+ erm = capsule_manager.ExportRepositoryManager( app=trans.app,
+ user=trans.user,
+ tool_shed_url=tool_shed_url,
+ repository=repository,
+ changeset_revision=changeset_revision,
+ export_repository_dependencies=export_repository_dependencies,
+ using_api=False )
+ repositories_archive, error_message = erm.export_repository()
repositories_archive_filename = os.path.basename( repositories_archive.name )
if error_message:
message = error_message
@@ -1969,15 +1967,16 @@
encoded_file_path = kwd.get( 'encoded_file_path', None )
file_path = encoding_util.tool_shed_decode( encoded_file_path )
export_info_file_path = os.path.join( file_path, 'export_info.xml' )
- export_info_dict = import_util.get_export_info_dict( export_info_file_path )
+ irm = capsule_manager.ImportRepositoryManager( trans.app,
+ trans.request.host,
+ trans.user,
+ trans.user_is_admin() )
+ export_info_dict = irm.get_export_info_dict( export_info_file_path )
manifest_file_path = os.path.join( file_path, 'manifest.xml' )
# The manifest.xml file has already been validated, so no error_message should be returned here.
- repository_info_dicts, error_message = import_util.get_repository_info_from_manifest( manifest_file_path )
+ repository_info_dicts, error_message = irm.get_repository_info_from_manifest( manifest_file_path )
# Determine the status for each exported repository archive contained within the capsule.
- repository_status_info_dicts = import_util.get_repository_status_from_tool_shed( trans.app,
- trans.user,
- trans.user_is_admin(),
- repository_info_dicts )
+ repository_status_info_dicts = irm.get_repository_status_from_tool_shed( repository_info_dicts )
if 'import_capsule_button' in kwd:
# Generate a list of repository name / import results message tuples for display after the capsule is imported.
import_results_tups = []
@@ -1987,12 +1986,9 @@
# Add the capsule_file_name and encoded_file_path to the repository_status_info_dict.
repository_status_info_dict[ 'capsule_file_name' ] = capsule_file_name
repository_status_info_dict[ 'encoded_file_path' ] = encoded_file_path
- import_results_tups = import_util.create_repository_and_import_archive( trans.app,
- trans.request.host,
- trans.user,
- repository_status_info_dict,
- import_results_tups )
- import_util.check_status_and_reset_downloadable( trans.app, import_results_tups )
+ import_results_tups = irm.create_repository_and_import_archive( repository_status_info_dict,
+ import_results_tups )
+ irm.check_status_and_reset_downloadable( import_results_tups )
basic_util.remove_dir( file_path )
return trans.fill_template( '/webapps/tool_shed/repository/import_capsule_results.mako',
export_info_dict=export_info_dict,
@@ -3081,13 +3077,17 @@
status = kwd.get( 'status', 'done' )
url = kwd.get( 'url', '' )
if 'upload_capsule_button' in kwd:
- capsule_dict = import_util.upload_capsule( **kwd )
+ irm = capsule_manager.ImportRepositoryManager( trans.app,
+ trans.request.host,
+ trans.user,
+ trans.user_is_admin() )
+ capsule_dict = irm.upload_capsule( **kwd )
status = capsule_dict.get( 'status', 'error' )
if status == 'error':
message = capsule_dict.get( 'error_message', '' )
else:
- capsule_dict = import_util.extract_capsule_files( **capsule_dict )
- capsule_dict = import_util.validate_capsule( **capsule_dict )
+ capsule_dict = irm.extract_capsule_files( **capsule_dict )
+ capsule_dict = irm.validate_capsule( **capsule_dict )
status = capsule_dict.get( 'status', 'error' )
if status == 'ok':
return trans.response.send_redirect( web.url_for( controller='repository',
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/tool_shed/capsule/capsule_manager.py
--- /dev/null
+++ b/lib/tool_shed/capsule/capsule_manager.py
@@ -0,0 +1,867 @@
+import logging
+import os
+import shutil
+import tarfile
+import tempfile
+import threading
+import urllib
+from time import gmtime
+from time import strftime
+import tool_shed.repository_types.util as rt_util
+from galaxy import web
+from galaxy.util import asbool
+from galaxy.util import CHUNK_SIZE
+from galaxy.util.odict import odict
+from tool_shed.dependencies import dependency_manager
+from tool_shed.util import basic_util
+from tool_shed.util import commit_util
+from tool_shed.util import common_util
+from tool_shed.util import encoding_util
+from tool_shed.util import hg_util
+from tool_shed.util import metadata_util
+from tool_shed.util import repository_dependency_util
+from tool_shed.util import repository_maintenance_util
+from tool_shed.util import shed_util_common as suc
+from tool_shed.util import xml_util
+from tool_shed.galaxy_install.repository_dependencies.repository_dependency_manager import RepositoryDependencyManager
+
+log = logging.getLogger( __name__ )
+
+
+class ExportedRepositoryRegistry( object ):
+
+ def __init__( self ):
+ self.exported_repository_elems = []
+
+class ExportRepositoryManager( object ):
+
+ def __init__( self, app, user, tool_shed_url, repository, changeset_revision, export_repository_dependencies, using_api ):
+ self.app = app
+ self.capsule_filename = 'capsule'
+ self.capsule_with_dependencies_filename = 'capsule_with_dependencies'
+ self.changeset_revision = changeset_revision
+ self.export_repository_dependencies = asbool( export_repository_dependencies )
+ self.file_type = 'gz'
+ self.repository = repository
+ self.repository_id = self.app.security.encode_id( repository.id )
+ self.tool_shed_url = tool_shed_url
+ self.user = user
+ self.using_api = using_api
+
+ def export_repository( self ):
+ repositories_archive_filename = self.generate_repository_archive_filename( use_tmp_archive_dir=True )
+ if self.export_repository_dependencies:
+ repo_info_dicts = self.get_repo_info_dicts()
+ repository_ids = self.get_repository_ids( repo_info_dicts )
+ ordered_repository_ids, ordered_repositories, ordered_changeset_revisions = \
+ self.order_components_for_import( repository_ids, repo_info_dicts )
+ else:
+ ordered_repository_ids = []
+ ordered_repositories = []
+ ordered_changeset_revisions = []
+ if self.repository:
+ repository_metadata = \
+ suc.get_current_repository_metadata_for_changeset_revision( self.app,
+ self.repository,
+ self.changeset_revision )
+ if repository_metadata:
+ ordered_repository_ids = [ self.repository_id ]
+ ordered_repositories = [ self.repository ]
+ ordered_changeset_revisions = [ repository_metadata.changeset_revision ]
+ repositories_archive = None
+ error_messages = ''
+ lock = threading.Lock()
+ lock.acquire( True )
+ try:
+ repositories_archive = tarfile.open( repositories_archive_filename, "w:%s" % self.file_type )
+ exported_repository_registry = ExportedRepositoryRegistry()
+ for index, repository_id in enumerate( ordered_repository_ids ):
+ work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-export-er" )
+ ordered_repository = ordered_repositories[ index ]
+ ordered_changeset_revision = ordered_changeset_revisions[ index ]
+ repository_archive, error_message = self.generate_repository_archive( ordered_repository,
+ ordered_changeset_revision,
+ work_dir )
+ if error_message:
+ error_messages = '%s %s' % ( error_messages, error_message )
+ else:
+ archive_name = str( os.path.basename( repository_archive.name ) )
+ repositories_archive.add( repository_archive.name, arcname=archive_name )
+ attributes, sub_elements = self.get_repository_attributes_and_sub_elements( ordered_repository,
+ archive_name )
+ elem = xml_util.create_element( 'repository', attributes=attributes, sub_elements=sub_elements )
+ exported_repository_registry.exported_repository_elems.append( elem )
+ basic_util.remove_dir( work_dir )
+ # Keep information about the export in a file named export_info.xml in the archive.
+ sub_elements = self.generate_export_elem()
+ export_elem = xml_util.create_element( 'export_info', attributes=None, sub_elements=sub_elements )
+ tmp_export_info = xml_util.create_and_write_tmp_file( export_elem, use_indent=True )
+ repositories_archive.add( tmp_export_info, arcname='export_info.xml' )
+ # Write the manifest, which must preserve the order in which the repositories should be imported.
+ exported_repository_root = xml_util.create_element( 'repositories' )
+ for exported_repository_elem in exported_repository_registry.exported_repository_elems:
+ exported_repository_root.append( exported_repository_elem )
+ tmp_manifest = xml_util.create_and_write_tmp_file( exported_repository_root, use_indent=True )
+ repositories_archive.add( tmp_manifest, arcname='manifest.xml' )
+ except Exception, e:
+ log.exception( str( e ) )
+ finally:
+ lock.release()
+ if repositories_archive is not None:
+ repositories_archive.close()
+ if self.using_api:
+ encoded_repositories_archive_name = encoding_util.tool_shed_encode( repositories_archive_filename )
+ params = '?encoded_repositories_archive_name=%s' % encoded_repositories_archive_name
+ download_url = common_util.url_join( web.url_for( '/', qualified=True ),
+ 'repository/export_via_api%s' % params )
+ return dict( download_url=download_url, error_messages=error_messages )
+ return repositories_archive, error_messages
+
+ def generate_export_elem( self ):
+ sub_elements = odict()
+ sub_elements[ 'export_time' ] = strftime( '%a, %d %b %Y %H:%M:%S +0000', gmtime() )
+ sub_elements[ 'tool_shed' ] = str( self.tool_shed_url.rstrip( '/' ) )
+ sub_elements[ 'repository_name' ] = str( self.repository.name )
+ sub_elements[ 'repository_owner' ] = str( self.repository.user.username )
+ sub_elements[ 'changeset_revision' ] = str( self.changeset_revision )
+ sub_elements[ 'export_repository_dependencies' ] = str( self.export_repository_dependencies )
+ sub_elements[ 'exported_via_api' ] = str( self.using_api )
+ return sub_elements
+
+ def generate_repository_archive( self, repository, changeset_revision, work_dir ):
+ rdah = dependency_manager.RepositoryDependencyAttributeHandler( self.app, unpopulate=True )
+ tdah = dependency_manager.ToolDependencyAttributeHandler( self.app, unpopulate=True )
+ file_type_str = basic_util.get_file_type_str( changeset_revision, self.file_type )
+ file_name = '%s-%s' % ( repository.name, file_type_str )
+ return_code, error_message = hg_util.archive_repository_revision( self.app,
+ repository,
+ work_dir,
+ changeset_revision )
+ if return_code:
+ return None, error_message
+ repository_archive_name = os.path.join( work_dir, file_name )
+ # Create a compressed tar archive that will contain only valid files and possibly altered dependency definition files.
+ repository_archive = tarfile.open( repository_archive_name, "w:%s" % self.file_type )
+ for root, dirs, files in os.walk( work_dir ):
+ if root.find( '.hg' ) < 0 and root.find( 'hgrc' ) < 0:
+ for dir in dirs:
+ if dir in commit_util.UNDESIRABLE_DIRS:
+ dirs.remove( dir )
+ for name in files:
+ name = str( name )
+ if str( name ) in commit_util.UNDESIRABLE_FILES:
+ continue
+ full_path = os.path.join( root, name )
+ relative_path = full_path.replace( work_dir, '' ).lstrip( '/' )
+ # See if we have a repository dependencies defined.
+ if name == rt_util.REPOSITORY_DEPENDENCY_DEFINITION_FILENAME:
+ # Eliminate the toolshed, and changeset_revision attributes from all <repository> tags.
+ altered, root_elem, error_message = rdah.handle_tag_attributes( full_path )
+ if error_message:
+ return None, error_message
+ if altered:
+ tmp_filename = xml_util.create_and_write_tmp_file( root_elem, use_indent=True )
+ shutil.move( tmp_filename, full_path )
+ elif name == rt_util.TOOL_DEPENDENCY_DEFINITION_FILENAME:
+ # Eliminate the toolshed, and changeset_revision attributes from all <repository> tags.
+ altered, root_elem, error_message = tdah.handle_tag_attributes( full_path )
+ if error_message:
+ return None, error_message
+ if altered:
+ tmp_filename = xml_util.create_and_write_tmp_file( root_elem, use_indent=True )
+ shutil.move( tmp_filename, full_path )
+ repository_archive.add( full_path, arcname=relative_path )
+ repository_archive.close()
+ return repository_archive, error_message
+
+ def generate_repository_archive_filename( self, use_tmp_archive_dir=False ):
+ tool_shed = self.remove_protocol_from_tool_shed_url()
+ file_type_str = basic_util.get_file_type_str( self.changeset_revision, self.file_type )
+ if self.export_repository_dependencies:
+ repositories_archive_filename = '%s_%s_%s_%s_%s' % ( self.capsule_with_dependencies_filename,
+ tool_shed,
+ str( self.repository.name ),
+ str( self.repository.user.username ),
+ file_type_str )
+ else:
+ repositories_archive_filename = '%s_%s_%s_%s_%s' % ( self.capsule_filename,
+ tool_shed,
+ str( self.repository.name ),
+ str( self.repository.user.username ),
+ file_type_str )
+ if use_tmp_archive_dir:
+ tmp_archive_dir = tempfile.mkdtemp( prefix="tmp-toolshed-arcdir" )
+ repositories_archive_filename = os.path.join( tmp_archive_dir, repositories_archive_filename )
+ return repositories_archive_filename
+
+ def get_components_from_repo_info_dict( self, repo_info_dict ):
+ """
+ Return the repository and the associated latest installable changeset_revision (including
+ # updates) for the repository defined by the received repo_info_dict.
+ """
+ for repository_name, repo_info_tup in repo_info_dict.items():
+ # There should only be one entry in the received repo_info_dict.
+ description, \
+ repository_clone_url, \
+ changeset_revision, \
+ ctx_rev, \
+ repository_owner, \
+ repository_dependencies, \
+ tool_dependencies = \
+ suc.get_repo_info_tuple_contents( repo_info_tup )
+ repository = suc.get_repository_by_name_and_owner( self.app, repository_name, repository_owner )
+ repository_metadata = suc.get_current_repository_metadata_for_changeset_revision( self.app,
+ repository,
+ changeset_revision )
+ if repository_metadata:
+ return repository, repository_metadata.changeset_revision
+ return None, None
+
+ def get_repo_info_dict_for_import( self, encoded_repository_id, encoded_repository_ids, repo_info_dicts ):
+ """
+ The received encoded_repository_ids and repo_info_dicts are lists that contain associated
+ elements at each location in the list. This method will return the element from repo_info_dicts
+ associated with the received encoded_repository_id by determining its location in the received
+ encoded_repository_ids list.
+ """
+ for index, repository_id in enumerate( encoded_repository_ids ):
+ if repository_id == encoded_repository_id:
+ repo_info_dict = repo_info_dicts[ index ]
+ return repo_info_dict
+ return None
+
+ def get_repo_info_dicts( self ):
+ """
+ Return a list of dictionaries defining repositories that are required by the repository
+ associated with self.repository_id.
+ """
+ rdm = RepositoryDependencyManager( self.app )
+ repository = suc.get_repository_in_tool_shed( self.app, self.repository_id )
+ repository_metadata = suc.get_repository_metadata_by_changeset_revision( self.app,
+ self.repository_id,
+ self.changeset_revision )
+ # Get a dictionary of all repositories upon which the contents of the current repository_metadata record depend.
+ toolshed_base_url = str( web.url_for( '/', qualified=True ) ).rstrip( '/' )
+ repository_dependencies = \
+ repository_dependency_util.get_repository_dependencies_for_changeset_revision( app=self.app,
+ repository=self.repository,
+ repository_metadata=repository_metadata,
+ toolshed_base_url=toolshed_base_url,
+ key_rd_dicts_to_be_processed=None,
+ all_repository_dependencies=None,
+ handled_key_rd_dicts=None )
+ repo = hg_util.get_repo_for_repository( self.app,
+ repository=self.repository,
+ repo_path=None,
+ create=False )
+ ctx = hg_util.get_changectx_for_changeset( repo, self.changeset_revision )
+ repo_info_dict = {}
+ # Cast unicode to string.
+ repo_info_dict[ str( repository.name ) ] = ( str( self.repository.description ),
+ common_util.generate_clone_url_for_repository_in_tool_shed( self.user,
+ self.repository ),
+ str( self.changeset_revision ),
+ str( ctx.rev() ),
+ str( self.repository.user.username ),
+ repository_dependencies,
+ None )
+ all_required_repo_info_dict = rdm.get_required_repo_info_dicts( self.tool_shed_url, [ repo_info_dict ] )
+ all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] )
+ return all_repo_info_dicts
+
+ def get_repository_attributes_and_sub_elements( self, repository, archive_name ):
+ """
+ Get the information about a repository to create and populate an XML tag set. The
+ generated attributes will be contained within the <repository> tag, while the sub_elements
+ will be tag sets contained within the <repository> tag set.
+ """
+ attributes = odict()
+ sub_elements = odict()
+ attributes[ 'name' ] = str( repository.name )
+ attributes[ 'type' ] = str( repository.type )
+ # We have to associate the public username since the user_id will be different between tool sheds.
+ attributes[ 'username' ] = str( repository.user.username )
+ # Don't coerce description or long description from unicode to string because the fields are free text.
+ sub_elements[ 'description' ] = repository.description
+ sub_elements[ 'long_description' ] = repository.long_description
+ sub_elements[ 'archive' ] = archive_name
+ # Keep track of Category associations.
+ categories = []
+ for rca in repository.categories:
+ category = rca.category
+ categories.append( ( 'category', str( category.name ) ) )
+ sub_elements[ 'categories' ] = categories
+ return attributes, sub_elements
+
+ def get_repository_ids( self, repo_info_dicts ):
+ """Return a list of repository ids associated with each dictionary in the received repo_info_dicts."""
+ repository_ids = []
+ for repo_info_dict in repo_info_dicts:
+ for repository_name, repo_info_tup in repo_info_dict.items():
+ description, \
+ repository_clone_url, \
+ changeset_revision, \
+ ctx_rev, \
+ repository_owner, \
+ repository_dependencies, \
+ tool_dependencies = \
+ suc.get_repo_info_tuple_contents( repo_info_tup )
+ repository = suc.get_repository_by_name_and_owner( self.app, repository_name, repository_owner )
+ repository_ids.append( self.app.security.encode_id( repository.id ) )
+ return repository_ids
+
+ def order_components_for_import( self, repository_ids, repo_info_dicts ):
+ """
+ Some repositories may have repository dependencies that must be imported and have metadata set on
+ them before the dependent repository is imported. This method will inspect the list of repositories
+ about to be exported and make sure to order them appropriately for proper import. For each repository
+ about to be exported, if required repositories are not contained in the list of repositories about to
+ be exported, then they are not considered. Repository dependency definitions that contain circular
+ dependencies should not result in an infinite loop, but obviously ordering the list will not be handled
+ for one or more of the repositories that require prior import.
+ """
+ # The received list of repository_ids are the ids of all of the primary exported repository's
+ # repository dependencies. The primary repository will always be last in the returned lists.
+ ordered_repository_ids = []
+ ordered_repositories = []
+ ordered_changeset_revisions = []
+ # Create a dictionary whose keys are the received repository_ids and whose values are a list of
+ # repository_ids, each of which is contained in the received list of repository_ids and whose associated
+ # repository must be imported prior to the repository associated with the repository_id key.
+ prior_import_required_dict = suc.get_prior_import_or_install_required_dict( self.app,
+ repository_ids,
+ repo_info_dicts )
+ processed_repository_ids = []
+ # Process the list of repository dependencies defined for the primary exported repository.
+ while len( processed_repository_ids ) != len( prior_import_required_dict.keys() ):
+ repository_id = suc.get_next_prior_import_or_install_required_dict_entry( prior_import_required_dict,
+ processed_repository_ids )
+ if repository_id == self.repository_id:
+ # Append self.repository_id without processing it since it must be returned last in the order.
+ # It will be processed below after all dependencies are processed.
+ processed_repository_ids.append( self.repository_id )
+ continue
+ processed_repository_ids.append( repository_id )
+ if repository_id not in ordered_repository_ids:
+ prior_import_required_ids = prior_import_required_dict[ repository_id ]
+ for prior_import_required_id in prior_import_required_ids:
+ if prior_import_required_id not in ordered_repository_ids:
+ # Import the associated repository dependency first.
+ prior_repo_info_dict = \
+ self.get_repo_info_dict_for_import( prior_import_required_id,
+ repository_ids,
+ repo_info_dicts )
+ prior_repository, prior_import_changeset_revision = \
+ self.get_components_from_repo_info_dict( prior_repo_info_dict )
+ if prior_repository and prior_import_changeset_revision:
+ ordered_repository_ids.append( prior_import_required_id )
+ ordered_repositories.append( prior_repository )
+ ordered_changeset_revisions.append( prior_import_changeset_revision )
+ repo_info_dict = self.get_repo_info_dict_for_import( repository_id, repository_ids, repo_info_dicts )
+ repository, changeset_revision = self.get_components_from_repo_info_dict( repo_info_dict )
+ if repository and changeset_revision:
+ ordered_repository_ids.append( repository_id )
+ ordered_repositories.append( repository )
+ ordered_changeset_revisions.append( changeset_revision )
+ # Process the repository associated with self.repository_id last.
+ repo_info_dict = self.get_repo_info_dict_for_import( self.repository_id, repository_ids, repo_info_dicts )
+ repository, changeset_revision = self.get_components_from_repo_info_dict( repo_info_dict )
+ if repository and changeset_revision:
+ ordered_repository_ids.append( repository_id )
+ ordered_repositories.append( repository )
+ ordered_changeset_revisions.append( changeset_revision )
+ return ordered_repository_ids, ordered_repositories, ordered_changeset_revisions
+
+ def remove_protocol_from_tool_shed_url( self ):
+ protocol, base = self.tool_shed_url.split( '://' )
+ base = base.replace( ':', '_colon_' )
+ base = base.rstrip( '/' )
+ return base
+
+
+class ImportRepositoryManager( object ):
+
+ def __init__( self, app, host, user, user_is_admin ):
+ self.app = app
+ self.host = host
+ self.user = user
+ self.user_is_admin = user_is_admin
+
+ def check_status_and_reset_downloadable( self, import_results_tups ):
+ """Check the status of each imported repository and set downloadable to False if errors."""
+ sa_session = self.app.model.context.current
+ flush = False
+ for import_results_tup in import_results_tups:
+ ok, name_owner, message = import_results_tup
+ name, owner = name_owner
+ if not ok:
+ repository = suc.get_repository_by_name_and_owner( self.app, name, owner )
+ if repository is not None:
+ # Do not allow the repository to be automatically installed if population resulted in errors.
+ tip_changeset_revision = repository.tip( self.app )
+ repository_metadata = suc.get_repository_metadata_by_changeset_revision( self.app,
+ self.app.security.encode_id( repository.id ),
+ tip_changeset_revision )
+ if repository_metadata:
+ if repository_metadata.downloadable:
+ repository_metadata.downloadable = False
+ sa_session.add( repository_metadata )
+ if not flush:
+ flush = True
+ # Do not allow dependent repository revisions to be automatically installed if population
+ # resulted in errors.
+ dependent_downloadable_revisions = suc.get_dependent_downloadable_revisions( self.app, repository_metadata )
+ for dependent_downloadable_revision in dependent_downloadable_revisions:
+ if dependent_downloadable_revision.downloadable:
+ dependent_downloadable_revision.downloadable = False
+ sa_session.add( dependent_downloadable_revision )
+ if not flush:
+ flush = True
+ if flush:
+ sa_session.flush()
+
+ def create_repository_and_import_archive( self, repository_archive_dict, import_results_tups ):
+ """
+ Create a new repository in the tool shed and populate it with the contents of a gzip compressed
+ tar archive that was exported as part or all of the contents of a capsule.
+ """
+ results_message = ''
+ name = repository_archive_dict.get( 'name', None )
+ username = repository_archive_dict.get( 'owner', None )
+ if name is None or username is None:
+ ok = False
+ results_message += 'Import failed: required repository name <b>%s</b> or owner <b>%s</b> is missing.' % \
+ ( str( name ), str( username ))
+ import_results_tups.append( ( ok, ( str( name ), str( username ) ), results_message ) )
+ else:
+ status = repository_archive_dict.get( 'status', None )
+ if status is None:
+ # The repository does not yet exist in this Tool Shed and the current user is authorized to import
+ # the current archive file.
+ type = repository_archive_dict.get( 'type', 'unrestricted' )
+ description = repository_archive_dict.get( 'description', '' )
+ long_description = repository_archive_dict.get( 'long_description', '' )
+ # The owner entry in the repository_archive_dict is the public username of the user associated with
+ # the exported repository archive.
+ user = suc.get_user_by_username( self.app, username )
+ if user is None:
+ ok = False
+ results_message += 'Import failed: repository owner <b>%s</b> does not have an account in this Tool Shed.' % \
+ str( username )
+ import_results_tups.append( ( ok, ( str( name ), str( username ) ), results_message ) )
+ else:
+ user_id = user.id
+ # The categories entry in the repository_archive_dict is a list of category names. If a name does not
+ # exist in the current Tool Shed, the category will not be created, so it will not be associated with
+ # the repository.
+ category_ids = []
+ category_names = repository_archive_dict.get( 'category_names', [] )
+ for category_name in category_names:
+ category = suc.get_category_by_name( self.app, category_name )
+ if category is None:
+ results_message += 'This Tool Shed does not have the category <b>%s</b> so it ' % str( category_name )
+ results_message += 'will not be associated with this repository.'
+ else:
+ category_ids.append( self.app.security.encode_id( category.id ) )
+ # Create the repository record in the database.
+ repository, create_message = repository_maintenance_util.create_repository( self.app,
+ name,
+ type,
+ description,
+ long_description,
+ user_id=user_id,
+ category_ids=category_ids )
+ if create_message:
+ results_message += create_message
+ # Populate the new repository with the contents of exported repository archive.
+ results_dict = self.import_repository_archive( repository, repository_archive_dict )
+ ok = results_dict.get( 'ok', False )
+ error_message = results_dict.get( 'error_message', '' )
+ if error_message:
+ results_message += error_message
+ import_results_tups.append( ( ok, ( str( name ), str( username ) ), results_message ) )
+ else:
+ # The repository either already exists in this Tool Shed or the current user is not authorized to create it.
+ ok = True
+ results_message += 'Import not necessary: repository status for this Tool Shed is: %s.' % str( status )
+ import_results_tups.append( ( ok, ( str( name ), str( username ) ), results_message ) )
+ return import_results_tups
+
+ def extract_capsule_files( self, **kwd ):
+ """
+ Extract the uploaded capsule archive into a temporary location for inspection, validation
+ and potential import.
+ """
+ return_dict = {}
+ tar_archive = kwd.get( 'tar_archive', None )
+ capsule_file_name = kwd.get( 'capsule_file_name', None )
+ if tar_archive is not None and capsule_file_name is not None:
+ return_dict.update( kwd )
+ extract_directory_path = tempfile.mkdtemp( prefix="tmp-capsule-ecf" )
+ if capsule_file_name.endswith( '.tar.gz' ):
+ extract_directory_name = capsule_file_name.replace( '.tar.gz', '' )
+ elif capsule_file_name.endswith( '.tar' ):
+ extract_directory_name = capsule_file_name.replace( '.tar', '' )
+ else:
+ extract_directory_name = capsule_file_name
+ file_path = os.path.join( extract_directory_path, extract_directory_name )
+ return_dict[ 'encoded_file_path' ] = encoding_util.tool_shed_encode( file_path )
+ tar_archive.extractall( path=file_path )
+ try:
+ tar_archive.close()
+ except Exception, e:
+ log.exception( "Cannot close tar_archive: %s" % str( e ) )
+ del return_dict[ 'tar_archive' ]
+ return return_dict
+
+ def get_archives_from_manifest( self, manifest_file_path ):
+ """
+ Return the list of archive names defined in the capsule manifest. This method will validate
+ the manifest by ensuring all <repository> tag sets contain a valid <archive> sub-element.
+ """
+ archives = []
+ error_message = ''
+ manifest_tree, error_message = xml_util.parse_xml( manifest_file_path )
+ if error_message:
+ return archives, error_message
+ manifest_root = manifest_tree.getroot()
+ for elem in manifest_root:
+ # <repository name="package_lapack_3_4" type="tool_dependency_definition" username="test">
+ if elem.tag != 'repository':
+ error_message = 'All level one sub-elements in the manifest.xml file must be <repository> tag sets. '
+ error_message += 'The tag <b><%s></b> is invalid.' % str( elem.tag )
+ return [], error_message
+ archive_file_name = None
+ for repository_elem in elem:
+ if repository_elem.tag == 'archive':
+ # <archive>package_lapack_3_4-9e7a45ad3522.tar.gz</archive>
+ archive_file_name = repository_elem.text
+ break
+ if archive_file_name is None:
+ error_message = 'The %s tag set is missing a required <archive> sub-element.' % str( elem.tag )
+ return [], error_message
+ archives.append( archive_file_name )
+ return archives, error_message
+
+ def get_export_info_dict( self, export_info_file_path ):
+ """
+ Parse the export_info.xml file contained within the capsule and return a dictionary
+ containing its entries.
+ """
+ export_info_tree, error_message = xml_util.parse_xml( export_info_file_path )
+ export_info_root = export_info_tree.getroot()
+ export_info_dict = {}
+ for elem in export_info_root:
+ if elem.tag == 'export_time':
+ export_info_dict[ 'export_time' ] = elem.text
+ elif elem.tag == 'tool_shed':
+ export_info_dict[ 'tool_shed' ] = elem.text
+ elif elem.tag == 'repository_name':
+ export_info_dict[ 'repository_name' ] = elem.text
+ elif elem.tag == 'repository_owner':
+ export_info_dict[ 'repository_owner' ] = elem.text
+ elif elem.tag == 'changeset_revision':
+ export_info_dict[ 'changeset_revision' ] = elem.text
+ elif elem.tag == 'export_repository_dependencies':
+ if asbool( elem.text ):
+ export_info_dict[ 'export_repository_dependencies' ] = 'Yes'
+ else:
+ export_info_dict[ 'export_repository_dependencies' ] = 'No'
+ return export_info_dict
+
+ def get_repository_info_from_manifest( self, manifest_file_path ):
+ """
+ Parse the capsule manifest and return a list of dictionaries containing information about
+ each exported repository archive contained within the capsule.
+ """
+ repository_info_dicts = []
+ manifest_tree, error_message = xml_util.parse_xml( manifest_file_path )
+ if error_message:
+ return repository_info_dicts, error_message
+ manifest_root = manifest_tree.getroot()
+ for elem in manifest_root:
+ # <repository name="package_lapack_3_4" type="tool_dependency_definition" username="test">
+ if elem.tag != 'repository':
+ error_message = 'All level one sub-elements in the manifest.xml file must be <repository> tag sets. '
+ error_message += 'The tag <b><%s></b> is invalid.' % str( elem.tag )
+ return [], error_message
+ name = elem.get( 'name', None )
+ owner = elem.get( 'username', None )
+ type = elem.get( 'type', None )
+ if name is None or owner is None or type is None:
+ error_message = 'Missing required name, type, owner attributes from the tag %s' % str( elem.tag )
+ return [], error_message
+ repository_info_dict = dict( name=name, owner=owner, type=type )
+ for repository_elem in elem:
+ if repository_elem.tag == 'archive':
+ # <archive>package_lapack_3_4-9e7a45ad3522.tar.gz</archive>
+ archive_file_name = repository_elem.text
+ repository_info_dict[ 'archive_file_name' ] = archive_file_name
+ items = archive_file_name.split( '-' )
+ changeset_revision = items[ 1 ].rstrip( '.tar.gz' )
+ repository_info_dict [ 'changeset_revision' ] = changeset_revision
+ elif repository_elem.tag == 'categories':
+ category_names = []
+ for category_elem in repository_elem:
+ if category_elem.tag == 'category':
+ category_names.append( category_elem.text )
+ repository_info_dict[ 'category_names' ] = category_names
+ elif repository_elem.tag == 'description':
+ repository_info_dict[ 'description' ] = repository_elem.text
+ elif repository_elem.tag == 'long_description':
+ repository_info_dict[ 'long_description' ] = repository_elem.text
+ repository_info_dicts.append( repository_info_dict )
+ return repository_info_dicts, error_message
+
+ def get_repository_status_from_tool_shed( self, repository_info_dicts ):
+ """
+ For each exported repository archive contained in the capsule, inspect the Tool Shed to
+ see if that repository already exists or if the current user is authorized to create the
+ repository and set a status appropriately. If repository dependencies are included in the
+ capsule, repositories may have various owners. We will keep repositories associated with
+ owners, so we need to restrict created repositories to those the current user can create.
+ If the current user is an admin or a member of the IUC, all repositories will be created
+ no matter the owner. Otherwise only repositories whose associated owner is the current
+ user will be created.
+ """
+ repository_status_info_dicts = []
+ for repository_info_dict in repository_info_dicts:
+ repository = suc.get_repository_by_name_and_owner( self.app,
+ repository_info_dict[ 'name' ],
+ repository_info_dict[ 'owner' ] )
+ if repository:
+ if repository.deleted:
+ repository_info_dict[ 'status' ] = 'Exists, deleted'
+ elif repository.deprecated:
+ repository_info_dict[ 'status' ] = 'Exists, deprecated'
+ else:
+ repository_info_dict[ 'status' ] = 'Exists'
+ else:
+ # No repository with the specified name and owner currently exists, so make sure
+ # the current user can create one.
+ if self.user_is_admin:
+ repository_info_dict[ 'status' ] = None
+ elif self.app.security_agent.user_can_import_repository_archive( self.user,
+ repository_info_dict[ 'owner' ] ):
+ repository_info_dict[ 'status' ] = None
+ else:
+ repository_info_dict[ 'status' ] = 'Not authorized to import'
+ repository_status_info_dicts.append( repository_info_dict )
+ return repository_status_info_dicts
+
+ def import_repository_archive( self, repository, repository_archive_dict ):
+ """Import a repository archive contained within a repository capsule."""
+ rdah = dependency_manager.RepositoryDependencyAttributeHandler( self.app, unpopulate=False )
+ tdah = dependency_manager.ToolDependencyAttributeHandler( self.app, unpopulate=False )
+ archive_file_name = repository_archive_dict.get( 'archive_file_name', None )
+ capsule_file_name = repository_archive_dict[ 'capsule_file_name' ]
+ encoded_file_path = repository_archive_dict[ 'encoded_file_path' ]
+ file_path = encoding_util.tool_shed_decode( encoded_file_path )
+ results_dict = dict( ok=True, error_message='' )
+ archive_file_path = os.path.join( file_path, archive_file_name )
+ archive = tarfile.open( archive_file_path, 'r:*' )
+ repo_dir = repository.repo_path( self.app )
+ repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_dir, create=False )
+ undesirable_dirs_removed = 0
+ undesirable_files_removed = 0
+ ok, error_message = commit_util.check_archive( repository, archive )
+ if ok:
+ full_path = os.path.abspath( repo_dir )
+ filenames_in_archive = []
+ for tarinfo_obj in archive.getmembers():
+ # Check files and directories in the archive.
+ ok = os.path.basename( tarinfo_obj.name ) not in commit_util.UNDESIRABLE_FILES
+ if ok:
+ for file_path_item in tarinfo_obj.name.split( '/' ):
+ if file_path_item in commit_util.UNDESIRABLE_DIRS:
+ undesirable_dirs_removed += 1
+ error_message = 'Import failed: invalid file path <b>%s</b> in archive <b>%s</b>' % \
+ ( str( file_path_item ), str( archive_file_name ) )
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ return results_dict
+ filenames_in_archive.append( tarinfo_obj.name )
+ else:
+ undesirable_files_removed += 1
+ # Extract the uploaded archive to the repository root.
+ archive.extractall( path=full_path )
+ archive.close()
+ for filename in filenames_in_archive:
+ uploaded_file_name = os.path.join( full_path, filename )
+ if os.path.split( uploaded_file_name )[ -1 ] == rt_util.REPOSITORY_DEPENDENCY_DEFINITION_FILENAME:
+ # Inspect the contents of the file to see if toolshed or changeset_revision attributes
+ # are missing and if so, set them appropriately.
+ altered, root_elem, error_message = rdah.handle_tag_attributes( uploaded_file_name )
+ if error_message:
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ if altered:
+ tmp_filename = xml_util.create_and_write_tmp_file( root_elem )
+ shutil.move( tmp_filename, uploaded_file_name )
+ elif os.path.split( uploaded_file_name )[ -1 ] == rt_util.TOOL_DEPENDENCY_DEFINITION_FILENAME:
+ # Inspect the contents of the file to see if toolshed or changeset_revision
+ # attributes are missing and if so, set them appropriately.
+ altered, root_elem, error_message = tdah.handle_tag_attributes( uploaded_file_name )
+ if error_message:
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ if altered:
+ tmp_filename = xml_util.create_and_write_tmp_file( root_elem )
+ shutil.move( tmp_filename, uploaded_file_name )
+ commit_message = 'Imported from capsule %s' % str( capsule_file_name )
+ # Send email notification to those that have registered to receive alerts for new repositories in this Tool Shed.
+ new_repo_alert = True
+ # Since the repository is new, the following must be False.
+ remove_repo_files_not_in_tar = False
+ ok, error_message, files_to_remove, content_alert_str, undesirable_dirs_removed, undesirable_files_removed = \
+ commit_util.handle_directory_changes( self.app,
+ self.host,
+ self.user.username,
+ repository,
+ full_path,
+ filenames_in_archive,
+ remove_repo_files_not_in_tar,
+ new_repo_alert,
+ commit_message,
+ undesirable_dirs_removed,
+ undesirable_files_removed )
+ if error_message:
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ try:
+ status, error_message = metadata_util.set_repository_metadata_due_to_new_tip( self.app,
+ self.host,
+ self.user,
+ repository,
+ content_alert_str=content_alert_str )
+ if error_message:
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ except Exception, e:
+ log.debug( "Error setting metadata on repository %s created from imported archive %s: %s" % \
+ ( str( repository.name ), str( archive_file_name ), str( e ) ) )
+ else:
+ archive.close()
+ results_dict[ 'ok' ] = False
+ results_dict[ 'error_message' ] += error_message
+ return results_dict
+
+ def upload_capsule( self, **kwd ):
+ """Upload and prepare an exported repository capsule for validation."""
+ file_data = kwd.get( 'file_data', '' )
+ url = kwd.get( 'url', '' )
+ uploaded_file = None
+ return_dict = dict( error_message='',
+ encoded_file_path=None,
+ status='ok',
+ tar_archive=None,
+ uploaded_file=None,
+ capsule_file_name=None )
+ if file_data == '' and url == '':
+ message = 'No files were entered on the import form.'
+ status = 'error'
+ elif url:
+ valid_url = True
+ try:
+ stream = urllib.urlopen( url )
+ except Exception, e:
+ valid_url = False
+ message = 'Error importing file via http: %s' % str( e )
+ status = 'error'
+ if valid_url:
+ fd, uploaded_file_name = tempfile.mkstemp()
+ uploaded_file = open( uploaded_file_name, 'wb' )
+ while 1:
+ chunk = stream.read( CHUNK_SIZE )
+ if not chunk:
+ break
+ uploaded_file.write( chunk )
+ uploaded_file.flush()
+ uploaded_file_filename = url.split( '/' )[ -1 ]
+ isempty = os.path.getsize( os.path.abspath( uploaded_file_name ) ) == 0
+ elif file_data not in ( '', None ):
+ uploaded_file = file_data.file
+ uploaded_file_name = uploaded_file.name
+ uploaded_file_filename = os.path.split( file_data.filename )[ -1 ]
+ isempty = os.path.getsize( os.path.abspath( uploaded_file_name ) ) == 0
+ if uploaded_file is not None:
+ if isempty:
+ uploaded_file.close()
+ return_dict[ 'error_message' ] = 'Your uploaded capsule file is empty.'
+ return_dict[ 'status' ] = 'error'
+ return return_dict
+ try:
+ # Open for reading with transparent compression.
+ tar_archive = tarfile.open( uploaded_file_name, 'r:*' )
+ except tarfile.ReadError, e:
+ error_message = 'Error opening file %s: %s' % ( str( uploaded_file_name ), str( e ) )
+ log.exception( error_message )
+ return_dict[ 'error_message' ] = error_message
+ return_dict[ 'status' ] = 'error'
+ uploaded_file.close()
+ return return_dict
+ return_dict[ 'tar_archive' ] = tar_archive
+ return_dict[ 'capsule_file_name' ] = uploaded_file_filename
+ uploaded_file.close()
+ else:
+ return_dict[ 'error_message' ] = 'No files were entered on the import form.'
+ return_dict[ 'status' ] = 'error'
+ return return_dict
+ return return_dict
+
+ def validate_capsule( self, **kwd ):
+ """
+ Inspect the uploaded capsule's manifest and its contained files to ensure it is a valid
+ repository capsule.
+ """
+ capsule_dict = {}
+ capsule_dict.update( kwd )
+ encoded_file_path = capsule_dict.get( 'encoded_file_path', '' )
+ file_path = encoding_util.tool_shed_decode( encoded_file_path )
+ # The capsule must contain a valid XML file named export_info.xml.
+ export_info_file_path = os.path.join( file_path, 'export_info.xml' )
+ export_info_tree, error_message = xml_util.parse_xml( export_info_file_path )
+ if error_message:
+ capsule_dict[ 'error_message' ] = error_message
+ capsule_dict[ 'status' ] = 'error'
+ return capsule_dict
+ # The capsule must contain a valid XML file named manifest.xml.
+ manifest_file_path = os.path.join( file_path, 'manifest.xml' )
+ # Validate the capsule manifest by inspecting name, owner, changeset_revision and type
+ # information contained within each <repository> tag set.
+ repository_info_dicts, error_message = self.get_repository_info_from_manifest( manifest_file_path )
+ if error_message:
+ capsule_dict[ 'error_message' ] = error_message
+ capsule_dict[ 'status' ] = 'error'
+ return capsule_dict
+ # Validate the capsule manifest by ensuring all <repository> tag sets contain a valid
+ # <archive> sub-element.
+ archives, error_message = self.get_archives_from_manifest( manifest_file_path )
+ if error_message:
+ capsule_dict[ 'error_message' ] = error_message
+ capsule_dict[ 'status' ] = 'error'
+ return capsule_dict
+ # Validate the capsule manifest by ensuring each defined archive file name exists within
+ # the capsule.
+ error_message = self.verify_archives_in_capsule( file_path, archives )
+ if error_message:
+ capsule_dict[ 'error_message' ] = error_message
+ capsule_dict[ 'status' ] = 'error'
+ return capsule_dict
+ capsule_dict[ 'status' ] = 'ok'
+ return capsule_dict
+
+ def verify_archives_in_capsule( self, file_path, archives ):
+ """
+ Inspect the files contained within the capsule and make sure each is defined correctly
+ in the capsule manifest.
+ """
+ error_message = ''
+ for archive_file_name in archives:
+ full_path = os.path.join( file_path, archive_file_name )
+ if not os.path.exists( full_path ):
+ error_message = 'The uploaded capsule is invalid because the contained manifest.xml '
+ error_message += 'file defines an archive file named <b>%s</b> which ' % str( archive_file_name )
+ error_message += 'is not contained within the capsule.'
+ break
+ return error_message
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/tool_shed/scripts/api/export.py
--- a/lib/tool_shed/scripts/api/export.py
+++ b/lib/tool_shed/scripts/api/export.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""
-Export a specified repository revision and optionally all of its defined repository dependencies from the tool shed into a compressed archive.
+Export a specified repository revision and optionally all of its defined repository
+dependencies from the tool shed into a compressed archive.
Here is a working example of how to use this script to export a repository from the tool shed.
./export.py --url http://testtoolshed.g2.bx.psu.edu --name chemicaltoolbox --owner bgruening --revision 4133dbf7ff4d --export_repository_dependencies True --download_dir /tmp
@@ -8,15 +9,45 @@
import os
import sys
+import tempfile
import argparse
import urllib2
sys.path.insert( 0, os.path.dirname( __file__ ) )
from common import display
from common import submit
-from tool_shed.util import export_util
+from tool_shed.util import basic_util
+CAPSULE_FILENAME = 'capsule'
+CAPSULE_WITH_DEPENDENCIES_FILENAME = 'capsule_with_dependencies'
CHUNK_SIZE = 2**20 # 1Mb
+def generate_repository_archive_filename( tool_shed_url, name, owner, changeset_revision, file_type,
+ export_repository_dependencies, use_tmp_archive_dir=False ):
+ tool_shed = remove_protocol_from_tool_shed_url( tool_shed_url )
+ file_type_str = basic_util.get_file_type_str( changeset_revision, file_type )
+ if self.export_repository_dependencies:
+ repositories_archive_filename = '%s_%s_%s_%s_%s' % ( CAPSULE_WITH_DEPENDENCIES_FILENAME,
+ tool_shed,
+ name,
+ owner,
+ file_type_str )
+ else:
+ repositories_archive_filename = '%s_%s_%s_%s_%s' % ( CAPSULE_FILENAME,
+ tool_shed,
+ name,
+ owner,
+ file_type_str )
+ if use_tmp_archive_dir:
+ tmp_archive_dir = tempfile.mkdtemp( prefix="tmp-toolshed-arcdir" )
+ repositories_archive_filename = os.path.join( tmp_archive_dir, repositories_archive_filename )
+ return repositories_archive_filename
+
+def remove_protocol_from_tool_shed_url( tool_shed_url ):
+ protocol, base = tool_shed_url.split( '://' )
+ base = base.replace( ':', '_colon_' )
+ base = base.rstrip( '/' )
+ return base
+
def string_as_bool( string ):
if str( string ).lower() in ( 'true', 'yes', 'on' ):
return True
@@ -50,14 +81,15 @@
if error_messages:
print "Error attempting to export revision ", options.changeset_revision, " of repository ", options.name, " owned by ", options.owner, ":\n", error_messages
else:
+ export_repository_dependencies = string_as_bool( options.export_repository_dependencies )
repositories_archive_filename = \
- export_util.generate_repository_archive_filename( base_tool_shed_url,
- options.name,
- options.owner,
- options.changeset_revision,
- file_type,
- export_repository_dependencies=string_as_bool( options.export_repository_dependencies ),
- use_tmp_archive_dir=False )
+ generate_repository_archive_filename( base_tool_shed_url,
+ options.name,
+ options.owner,
+ options.changeset_revision,
+ file_type,
+ export_repository_dependencies=export_repository_dependencies,
+ use_tmp_archive_dir=False )
download_url = export_dict[ 'download_url' ]
download_dir = os.path.abspath( options.download_dir )
file_path = os.path.join( download_dir, repositories_archive_filename )
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/tool_shed/util/basic_util.py
--- a/lib/tool_shed/util/basic_util.py
+++ b/lib/tool_shed/util/basic_util.py
@@ -45,6 +45,17 @@
env_var_dict[ '__is64bit__' ] = sys.maxsize > 2**32
return env_var_dict
+def get_file_type_str( changeset_revision, file_type ):
+ if file_type == 'zip':
+ file_type_str = '%s.zip' % changeset_revision
+ elif file_type == 'bz2':
+ file_type_str = '%s.tar.bz2' % changeset_revision
+ elif file_type == 'gz':
+ file_type_str = '%s.tar.gz' % changeset_revision
+ else:
+ file_type_str = ''
+ return file_type_str
+
def move_file( current_dir, source, destination, rename_to=None ):
source_path = os.path.abspath( os.path.join( current_dir, source ) )
source_file = os.path.basename( source_path )
diff -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 -r fdaad2cad3926f1266bb534d998cdf24a5969578 lib/tool_shed/util/export_util.py
--- a/lib/tool_shed/util/export_util.py
+++ /dev/null
@@ -1,355 +0,0 @@
-import logging
-import os
-import shutil
-import tarfile
-import tempfile
-import threading
-from time import gmtime
-from time import strftime
-import tool_shed.repository_types.util as rt_util
-from galaxy import web
-from galaxy.util.odict import odict
-from tool_shed.dependencies import dependency_manager
-from tool_shed.util import basic_util
-from tool_shed.util import commit_util
-from tool_shed.util import common_util
-from tool_shed.util import encoding_util
-from tool_shed.util import hg_util
-from tool_shed.util import repository_dependency_util
-from tool_shed.util import shed_util_common as suc
-from tool_shed.util import xml_util
-from tool_shed.galaxy_install.repository_dependencies.repository_dependency_manager import RepositoryDependencyManager
-
-log = logging.getLogger( __name__ )
-
-CAPSULE_FILENAME = 'capsule'
-CAPSULE_WITH_DEPENDENCIES_FILENAME = 'capsule_with_dependencies'
-
-class ExportedRepositoryRegistry( object ):
-
- def __init__( self ):
- self.exported_repository_elems = []
-
-def export_repository( app, user, tool_shed_url, repository_id, repository_name, changeset_revision, file_type,
- export_repository_dependencies, api=False ):
- repository = suc.get_repository_in_tool_shed( app, repository_id )
- repositories_archive_filename = generate_repository_archive_filename( tool_shed_url,
- str( repository.name ),
- str( repository.user.username ),
- changeset_revision,
- file_type,
- export_repository_dependencies=export_repository_dependencies,
- use_tmp_archive_dir=True )
- if export_repository_dependencies:
- repo_info_dicts = get_repo_info_dicts( app, user, tool_shed_url, repository_id, changeset_revision )
- repository_ids = get_repository_ids( app, repo_info_dicts )
- ordered_repository_ids, ordered_repositories, ordered_changeset_revisions = \
- order_components_for_import( app, repository_id, repository_ids, repo_info_dicts )
- else:
- ordered_repository_ids = []
- ordered_repositories = []
- ordered_changeset_revisions = []
- if repository:
- repository_metadata = suc.get_current_repository_metadata_for_changeset_revision( app,
- repository,
- changeset_revision )
- if repository_metadata:
- ordered_repository_ids = [ repository_id ]
- ordered_repositories = [ repository ]
- ordered_changeset_revisions = [ repository_metadata.changeset_revision ]
- repositories_archive = None
- error_messages = ''
- lock = threading.Lock()
- lock.acquire( True )
- try:
- repositories_archive = tarfile.open( repositories_archive_filename, "w:%s" % file_type )
- exported_repository_registry = ExportedRepositoryRegistry()
- for index, repository_id in enumerate( ordered_repository_ids ):
- work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-export-er" )
- ordered_repository = ordered_repositories[ index ]
- ordered_changeset_revision = ordered_changeset_revisions[ index ]
- repository_archive, error_message = generate_repository_archive( app,
- work_dir,
- tool_shed_url,
- ordered_repository,
- ordered_changeset_revision,
- file_type )
- if error_message:
- error_messages = '%s %s' % ( error_messages, error_message )
- else:
- archive_name = str( os.path.basename( repository_archive.name ) )
- repositories_archive.add( repository_archive.name, arcname=archive_name )
- attributes, sub_elements = get_repository_attributes_and_sub_elements( ordered_repository, archive_name )
- elem = xml_util.create_element( 'repository', attributes=attributes, sub_elements=sub_elements )
- exported_repository_registry.exported_repository_elems.append( elem )
- basic_util.remove_dir( work_dir )
- # Keep information about the export in a file name export_info.xml in the archive.
- sub_elements = generate_export_elem( tool_shed_url, repository, changeset_revision, export_repository_dependencies, api )
- export_elem = xml_util.create_element( 'export_info', attributes=None, sub_elements=sub_elements )
- tmp_export_info = xml_util.create_and_write_tmp_file( export_elem, use_indent=True )
- repositories_archive.add( tmp_export_info, arcname='export_info.xml' )
- # Write the manifest, which must preserve the order in which the repositories should be imported.
- exported_repository_root = xml_util.create_element( 'repositories' )
- for exported_repository_elem in exported_repository_registry.exported_repository_elems:
- exported_repository_root.append( exported_repository_elem )
- tmp_manifest = xml_util.create_and_write_tmp_file( exported_repository_root, use_indent=True )
- repositories_archive.add( tmp_manifest, arcname='manifest.xml' )
- except Exception, e:
- log.exception( str( e ) )
- finally:
- lock.release()
- repositories_archive.close()
- if api:
- encoded_repositories_archive_name = encoding_util.tool_shed_encode( repositories_archive_filename )
- params = '?encoded_repositories_archive_name=%s' % encoded_repositories_archive_name
- download_url = common_util.url_join( web.url_for( '/', qualified=True ),
- 'repository/export_via_api%s' % params )
- return dict( download_url=download_url, error_messages=error_messages )
- return repositories_archive, error_messages
-
-def generate_repository_archive( app, work_dir, tool_shed_url, repository, changeset_revision, file_type ):
- rdah = dependency_manager.RepositoryDependencyAttributeHandler( app, unpopulate=True )
- tdah = dependency_manager.ToolDependencyAttributeHandler( app, unpopulate=True )
- file_type_str = get_file_type_str( changeset_revision, file_type )
- file_name = '%s-%s' % ( repository.name, file_type_str )
- return_code, error_message = hg_util.archive_repository_revision( app,
- repository,
- work_dir,
- changeset_revision )
- if return_code:
- return None, error_message
- repository_archive_name = os.path.join( work_dir, file_name )
- # Create a compressed tar archive that will contain only valid files and possibly altered dependency definition files.
- repository_archive = tarfile.open( repository_archive_name, "w:%s" % file_type )
- for root, dirs, files in os.walk( work_dir ):
- if root.find( '.hg' ) < 0 and root.find( 'hgrc' ) < 0:
- for dir in dirs:
- if dir in commit_util.UNDESIRABLE_DIRS:
- dirs.remove( dir )
- for name in files:
- name = str( name )
- if str( name ) in commit_util.UNDESIRABLE_FILES:
- continue
- full_path = os.path.join( root, name )
- relative_path = full_path.replace( work_dir, '' ).lstrip( '/' )
- # See if we have a repository dependencies defined.
- if name == rt_util.REPOSITORY_DEPENDENCY_DEFINITION_FILENAME:
- # Eliminate the toolshed, and changeset_revision attributes from all <repository> tags.
- altered, root_elem, error_message = rdah.handle_tag_attributes( full_path )
- if error_message:
- return None, error_message
- if altered:
- tmp_filename = xml_util.create_and_write_tmp_file( root_elem, use_indent=True )
- shutil.move( tmp_filename, full_path )
- elif name == rt_util.TOOL_DEPENDENCY_DEFINITION_FILENAME:
- # Eliminate the toolshed, and changeset_revision attributes from all <repository> tags.
- altered, root_elem, error_message = tdah.handle_tag_attributes( full_path )
- if error_message:
- return None, error_message
- if altered:
- tmp_filename = xml_util.create_and_write_tmp_file( root_elem, use_indent=True )
- shutil.move( tmp_filename, full_path )
- repository_archive.add( full_path, arcname=relative_path )
- repository_archive.close()
- return repository_archive, error_message
-
-def generate_repository_archive_filename( tool_shed_url, name, owner, changeset_revision, file_type,
- export_repository_dependencies=False, use_tmp_archive_dir=False ):
- tool_shed = remove_protocol_from_tool_shed_url( tool_shed_url )
- file_type_str = get_file_type_str( changeset_revision, file_type )
- if export_repository_dependencies:
- repositories_archive_filename = '%s_%s_%s_%s_%s' % ( CAPSULE_WITH_DEPENDENCIES_FILENAME, tool_shed, name, owner, file_type_str )
- else:
- repositories_archive_filename = '%s_%s_%s_%s_%s' % ( CAPSULE_FILENAME, tool_shed, name, owner, file_type_str )
- if use_tmp_archive_dir:
- tmp_archive_dir = tempfile.mkdtemp( prefix="tmp-toolshed-arcdir" )
- repositories_archive_filename = os.path.join( tmp_archive_dir, repositories_archive_filename )
- return repositories_archive_filename
-
-def generate_export_elem( tool_shed_url, repository, changeset_revision, export_repository_dependencies, api ):
- sub_elements = odict()
- sub_elements[ 'export_time' ] = strftime( '%a, %d %b %Y %H:%M:%S +0000', gmtime() )
- sub_elements[ 'tool_shed' ] = str( tool_shed_url.rstrip( '/' ) )
- sub_elements[ 'repository_name' ] = str( repository.name )
- sub_elements[ 'repository_owner' ] = str( repository.user.username )
- sub_elements[ 'changeset_revision' ] = str( changeset_revision )
- sub_elements[ 'export_repository_dependencies' ] = str( export_repository_dependencies )
- sub_elements[ 'exported_via_api' ] = str( api )
- return sub_elements
-
-def get_components_from_repo_info_dict( app, repo_info_dict ):
- """
- Return the repository and the associated latest installable changeset_revision (including updates) for the
- repository defined by the received repo_info_dict.
- """
- for repository_name, repo_info_tup in repo_info_dict.items():
- # There should only be one entry in the received repo_info_dict.
- description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = \
- suc.get_repo_info_tuple_contents( repo_info_tup )
- repository = suc.get_repository_by_name_and_owner( app, repository_name, repository_owner )
- repository_metadata = suc.get_current_repository_metadata_for_changeset_revision( app,
- repository,
- changeset_revision )
- if repository_metadata:
- return repository, repository_metadata.changeset_revision
- return None, None
-
-def get_file_type_str( changeset_revision, file_type ):
- if file_type == 'zip':
- file_type_str = '%s.zip' % changeset_revision
- elif file_type == 'bz2':
- file_type_str = '%s.tar.bz2' % changeset_revision
- elif file_type == 'gz':
- file_type_str = '%s.tar.gz' % changeset_revision
- else:
- file_type_str = ''
- return file_type_str
-
-def get_repo_info_dict_for_import( encoded_repository_id, encoded_repository_ids, repo_info_dicts ):
- """
- The received encoded_repository_ids and repo_info_dicts are lists that contain associated elements at each
- location in the list. This method will return the element from repo_info_dicts associated with the received
- encoded_repository_id by determining its location in the received encoded_repository_ids list.
- """
- for index, repository_id in enumerate( encoded_repository_ids ):
- if repository_id == encoded_repository_id:
- repo_info_dict = repo_info_dicts[ index ]
- return repo_info_dict
- return None
-
-def get_repo_info_dicts( app, user, tool_shed_url, repository_id, changeset_revision ):
- """
- Return a list of dictionaries defining repositories that are required by the repository associated with the
- received repository_id.
- """
- rdm = RepositoryDependencyManager( app )
- repository = suc.get_repository_in_tool_shed( app, repository_id )
- repository_metadata = suc.get_repository_metadata_by_changeset_revision( app, repository_id, changeset_revision )
- # Get a dictionary of all repositories upon which the contents of the current repository_metadata record depend.
- toolshed_base_url = str( web.url_for( '/', qualified=True ) ).rstrip( '/' )
- repository_dependencies = \
- repository_dependency_util.get_repository_dependencies_for_changeset_revision( app=app,
- repository=repository,
- repository_metadata=repository_metadata,
- toolshed_base_url=toolshed_base_url,
- key_rd_dicts_to_be_processed=None,
- all_repository_dependencies=None,
- handled_key_rd_dicts=None )
- repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False )
- ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision )
- repo_info_dict = {}
- # Cast unicode to string.
- repo_info_dict[ str( repository.name ) ] = ( str( repository.description ),
- common_util.generate_clone_url_for_repository_in_tool_shed( user, repository ),
- str( changeset_revision ),
- str( ctx.rev() ),
- str( repository.user.username ),
- repository_dependencies,
- None )
- all_required_repo_info_dict = rdm.get_required_repo_info_dicts( tool_shed_url, [ repo_info_dict ] )
- all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] )
- return all_repo_info_dicts
-
-def get_repository_attributes_and_sub_elements( repository, archive_name ):
- """
- Get the information about a repository to create and populate an XML tag set. The generated attributes will
- be contained within the <repository> tag, while the sub_elements will be tag sets contained within the <repository>
- tag set.
- """
- attributes = odict()
- sub_elements = odict()
- attributes[ 'name' ] = str( repository.name )
- attributes[ 'type' ] = str( repository.type )
- # We have to associate the public username since the user_id will be different between tool sheds.
- attributes[ 'username' ] = str( repository.user.username )
- # Don't coerce description or long description from unicode to string because the fields are free text.
- sub_elements[ 'description' ] = repository.description
- sub_elements[ 'long_description' ] = repository.long_description
- sub_elements[ 'archive' ] = archive_name
- # Keep track of Category associations.
- categories = []
- for rca in repository.categories:
- category = rca.category
- categories.append( ( 'category', str( category.name ) ) )
- sub_elements[ 'categories' ] = categories
- return attributes, sub_elements
-
-def get_repository_ids( app, repo_info_dicts ):
- """Return a list of repository ids associated with each dictionary in the received repo_info_dicts."""
- repository_ids = []
- for repo_info_dict in repo_info_dicts:
- for repository_name, repo_info_tup in repo_info_dict.items():
- description, \
- repository_clone_url, \
- changeset_revision, \
- ctx_rev, \
- repository_owner, \
- repository_dependencies, \
- tool_dependencies = \
- suc.get_repo_info_tuple_contents( repo_info_tup )
- repository = suc.get_repository_by_name_and_owner( app, repository_name, repository_owner )
- repository_ids.append( app.security.encode_id( repository.id ) )
- return repository_ids
-
-def order_components_for_import( app, primary_repository_id, repository_ids, repo_info_dicts ):
- """
- Some repositories may have repository dependencies that must be imported and have metadata set on
- them before the dependent repository is imported. This method will inspect the list of repositories
- about to be exported and make sure to order them appropriately for proper import. For each repository
- about to be exported, if required repositories are not contained in the list of repositories about to
- be exported, then they are not considered. Repository dependency definitions that contain circular
- dependencies should not result in an infinite loop, but obviously ordering the list will not be handled
- for one or more of the repositories that require prior import.
- """
- # The received primary_repository_id is the id of the repository being exported, with the received list
- # of repository_ids being only the ids of all of its repository dependencies. The primary repository will
- # always be last in the returned lists.
- ordered_repository_ids = []
- ordered_repositories = []
- ordered_changeset_revisions = []
- # Create a dictionary whose keys are the received repository_ids and whose values are a list of
- # repository_ids, each of which is contained in the received list of repository_ids and whose associated
- # repository must be imported prior to the repository associated with the repository_id key.
- prior_import_required_dict = suc.get_prior_import_or_install_required_dict( app, repository_ids, repo_info_dicts )
- processed_repository_ids = []
- # Process the list of repository dependencies defined for the repository associated with the received
- # primary_repository_id.
- while len( processed_repository_ids ) != len( prior_import_required_dict.keys() ):
- repository_id = suc.get_next_prior_import_or_install_required_dict_entry( prior_import_required_dict, processed_repository_ids )
- if repository_id == primary_repository_id:
- # Append the primary_repository_id without processing it since it must be returned last in the order.
- # It will be processed below after all dependencies are processed.
- processed_repository_ids.append( primary_repository_id )
- continue
- processed_repository_ids.append( repository_id )
- if repository_id not in ordered_repository_ids:
- prior_import_required_ids = prior_import_required_dict[ repository_id ]
- for prior_import_required_id in prior_import_required_ids:
- if prior_import_required_id not in ordered_repository_ids:
- # Import the associated repository dependency first.
- prior_repo_info_dict = get_repo_info_dict_for_import( prior_import_required_id, repository_ids, repo_info_dicts )
- prior_repository, prior_import_changeset_revision = get_components_from_repo_info_dict( app, prior_repo_info_dict )
- if prior_repository and prior_import_changeset_revision:
- ordered_repository_ids.append( prior_import_required_id )
- ordered_repositories.append( prior_repository )
- ordered_changeset_revisions.append( prior_import_changeset_revision )
- repo_info_dict = get_repo_info_dict_for_import( repository_id, repository_ids, repo_info_dicts )
- repository, changeset_revision = get_components_from_repo_info_dict( app, repo_info_dict )
- if repository and changeset_revision:
- ordered_repository_ids.append( repository_id )
- ordered_repositories.append( repository )
- ordered_changeset_revisions.append( changeset_revision )
- # Process the repository associated with the received primary_repository_id last.
- repo_info_dict = get_repo_info_dict_for_import( primary_repository_id, repository_ids, repo_info_dicts )
- repository, changeset_revision = get_components_from_repo_info_dict( app, repo_info_dict )
- if repository and changeset_revision:
- ordered_repository_ids.append( repository_id )
- ordered_repositories.append( repository )
- ordered_changeset_revisions.append( changeset_revision )
- return ordered_repository_ids, ordered_repositories, ordered_changeset_revisions
-
-def remove_protocol_from_tool_shed_url( base_url ):
- protocol, base = base_url.split( '://' )
- base = base.replace( ':', '_colon_' )
- base = base.rstrip( '/' )
- return base
This diff is so big that we needed to truncate the remainder.
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: jmchilton: Make galaxy.util.in_directory slightly more generic to match Pulsar's variant.
by commits-noreply@bitbucket.org 24 Jun '14
by commits-noreply@bitbucket.org 24 Jun '14
24 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/fbf4b5ab17a9/
Changeset: fbf4b5ab17a9
User: jmchilton
Date: 2014-06-24 04:55:11
Summary: Make galaxy.util.in_directory slightly more generic to match Pulsar's variant.
Fixes failing unit test in just added code.
Affected #: 1 file
diff -r 566388d623749dad4259ea04cf44a5d858a56671 -r fbf4b5ab17a90ec7b0deac658ead6a99b9a6ca76 lib/galaxy/util/__init__.py
--- a/lib/galaxy/util/__init__.py
+++ b/lib/galaxy/util/__init__.py
@@ -417,17 +417,16 @@
return slug_base
-def in_directory( file, directory ):
+def in_directory( file, directory, local_path_module=os.path ):
"""
Return true, if the common prefix of both is equal to directory
e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
"""
# Make both absolute.
- directory = os.path.abspath( directory )
- file = os.path.abspath( file )
-
- return os.path.commonprefix( [ file, directory ] ) == directory
+ directory = local_path_module.abspath(directory)
+ file = local_path_module.abspath(file)
+ return local_path_module.commonprefix([file, directory]) == directory
def merge_sorted_iterables( operator, *iterables ):
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: jmchilton: Merged in jmchilton/galaxy-central-fork-1 (pull request #422)
by commits-noreply@bitbucket.org 24 Jun '14
by commits-noreply@bitbucket.org 24 Jun '14
24 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/566388d62374/
Changeset: 566388d62374
User: jmchilton
Date: 2014-06-24 04:27:51
Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #422)
Implement Pulsar job runners.
Affected #: 32 files
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 job_conf.xml.sample_advanced
--- a/job_conf.xml.sample_advanced
+++ b/job_conf.xml.sample_advanced
@@ -19,27 +19,30 @@
<!-- Override the $DRMAA_LIBRARY_PATH environment variable --><param id="drmaa_library_path">/sge/lib/libdrmaa.so</param></plugin>
- <plugin id="lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <!-- More information on LWR can be found at https://lwr.readthedocs.org -->
- <!-- Uncomment following line to use libcurl to perform HTTP calls (defaults to urllib) -->
+ <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
+ <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
+ <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <!-- Pulsar runners (see more at https://pulsar.readthedocs.org) -->
+ <plugin id="pulsar_rest" type="runner" load="galaxy.jobs.runners.pulsar:PulsarRESTJobRunner">
+ <!-- Allow optimized HTTP calls with libcurl (defaults to urllib) --><!-- <param id="transport">curl</param> -->
- <!-- *Experimental Caching*: Uncomment next parameters to enable
- caching and specify the number of caching threads to enable on Galaxy
- side. Likely will not work with newer features such as MQ support.
- If this is enabled be sure to specify a `file_cache_dir` in the remote
- LWR's main configuration file.
+
+ <!-- *Experimental Caching*: Next parameter enables caching.
+ Likely will not work with newer features such as MQ support.
+
+ If this is enabled be sure to specify a `file_cache_dir` in
+ the remote Pulsar's servers main configuration file.
--><!-- <param id="cache">True</param> -->
- <!-- <param id="transfer_threads">2</param> --></plugin>
- <plugin id="amqp_lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <param id="url">amqp://guest:guest@localhost:5672//</param>
- <!-- If using message queue driven LWR - the LWR will generally
- initiate file transfers so a the URL of this Galaxy instance
- must be configured. -->
+ <plugin id="pulsar_mq" type="runner" load="galaxy.jobs.runners.pulsar:PulsarMQJobRunner">
+ <!-- AMQP URL to connect to. -->
+ <param id="amqp_url">amqp://guest:guest@localhost:5672//</param>
+ <!-- URL remote Pulsar apps should transfer files to this Galaxy
+ instance to/from. --><param id="galaxy_url">http://localhost:8080</param>
- <!-- If multiple managers configured on the LWR, specify which one
- this plugin targets. -->
+ <!-- Pulsar job manager to communicate with (see Pulsar
+ docs for information on job managers). --><!-- <param id="manager">_default_</param> --><!-- The AMQP client can provide an SSL client certificate (e.g. for
validation), the following options configure that certificate
@@ -58,9 +61,17 @@
higher value (in seconds) (or `None` to use blocking connections). --><!-- <param id="amqp_consumer_timeout">None</param> --></plugin>
- <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
- <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
- <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <plugin id="pulsar_legacy" type="runner" load="galaxy.jobs.runners.pulsar:PulsarLegacyJobRunner">
+ <!-- Pulsar job runner with default parameters matching those
+ of old LWR job runner. If your Pulsar server is running on a
+ Windows machine for instance this runner should still be used.
+
+ These destinations still needs to target a Pulsar server,
+ older LWR plugins and destinations still work in Galaxy can
+ target LWR servers, but this support should be considered
+ deprecated and will disappear with a future release of Galaxy.
+ -->
+ </plugin></plugins><handlers default="handlers"><!-- Additional job handlers - the id should match the name of a
@@ -125,8 +136,8 @@
$galaxy_root:ro,$tool_directory:ro,$working_directory:rw,$default_file_path:ro
- If using the LWR, defaults will be even further restricted because the
- LWR will (by default) stage all needed inputs into the job's job_directory
+ If using the Pulsar, defaults will be even further restricted because the
+ Pulsar will (by default) stage all needed inputs into the job's job_directory
(so there is not need to allow the docker container to read all the
files - let alone write over them). Defaults in this case becomes:
@@ -135,7 +146,7 @@
Python string.Template is used to expand volumes and values $defaults,
$galaxy_root, $default_file_path, $tool_directory, $working_directory,
are available to all jobs and $job_directory is also available for
- LWR jobs.
+ Pulsar jobs.
--><!-- Control memory allocatable by docker container with following option:
-->
@@ -213,87 +224,71 @@
<!-- A destination that represents a method in the dynamic runner. --><param id="function">foo</param></destination>
- <destination id="secure_lwr" runner="lwr">
- <param id="url">https://windowshost.examle.com:8913/</param>
- <!-- If set, private_token must match token remote LWR server configured with. -->
+ <destination id="secure_pulsar_rest_dest" runner="pulsar_rest">
+ <param id="url">https://examle.com:8913/</param>
+ <!-- If set, private_token must match token in remote Pulsar's
+ configuration. --><param id="private_token">123456789changeme</param><!-- Uncomment the following statement to disable file staging (e.g.
- if there is a shared file system between Galaxy and the LWR
+ if there is a shared file system between Galaxy and the Pulsar
server). Alternatively action can be set to 'copy' - to replace
http transfers with file system copies, 'remote_transfer' to cause
- the lwr to initiate HTTP transfers instead of Galaxy, or
- 'remote_copy' to cause lwr to initiate file system copies.
+ the Pulsar to initiate HTTP transfers instead of Galaxy, or
+ 'remote_copy' to cause Pulsar to initiate file system copies.
If setting this to 'remote_transfer' be sure to specify a
'galaxy_url' attribute on the runner plugin above. --><!-- <param id="default_file_action">none</param> --><!-- The above option is just the default, the transfer behavior
none|copy|http can be configured on a per path basis via the
- following file. See lib/galaxy/jobs/runners/lwr_client/action_mapper.py
- for examples of how to configure this file. This is very beta
- and nature of file will likely change.
+ following file. See Pulsar documentation for more details and
+ examples.
-->
- <!-- <param id="file_action_config">file_actions.json</param> -->
- <!-- Uncomment following option to disable Galaxy tool dependency
- resolution and utilize remote LWR's configuraiton of tool
- dependency resolution instead (same options as Galaxy for
- dependency resolution are available in LWR). At a minimum
- the remote LWR server should define a tool_dependencies_dir in
- its `server.ini` configuration. The LWR will not attempt to
- stage dependencies - so ensure the the required galaxy or tool
- shed packages are available remotely (exact same tool shed
- installed changesets are required).
+ <!-- <param id="file_action_config">file_actions.yaml</param> -->
+ <!-- The non-legacy Pulsar runners will attempt to resolve Galaxy
+ dependencies remotely - to enable this set a tool_dependency_dir
+ in Pulsar's configuration (can work with all the same dependency
+ resolutions mechanisms as Galaxy - tool Shed installs, Galaxy
+ packages, etc...). To disable this behavior, set the follow parameter
+ to none. To generate the dependency resolution command locally
+ set the following parameter local.
-->
- <!-- <param id="dependency_resolution">remote</params> -->
- <!-- Traditionally, the LWR allow Galaxy to generate a command line
- as if it were going to run the command locally and then the
- LWR client rewrites it after the fact using regular
- expressions. Setting the following value to true causes the
- LWR runner to insert itself into the command line generation
- process and generate the correct command line from the get go.
- This will likely be the default someday - but requires a newer
- LWR version and is less well tested. -->
- <!-- <param id="rewrite_parameters">true</params> -->
+ <!-- <param id="dependency_resolution">none</params> --><!-- Uncomment following option to enable setting metadata on remote
- LWR server. The 'use_remote_datatypes' option is available for
+ Pulsar server. The 'use_remote_datatypes' option is available for
determining whether to use remotely configured datatypes or local
ones (both alternatives are a little brittle). --><!-- <param id="remote_metadata">true</param> --><!-- <param id="use_remote_datatypes">false</param> --><!-- <param id="remote_property_galaxy_home">/path/to/remote/galaxy-central</param> -->
- <!-- If remote LWR server is configured to run jobs as the real user,
+ <!-- If remote Pulsar server is configured to run jobs as the real user,
uncomment the following line to pass the current Galaxy user
along. --><!-- <param id="submit_user">$__user_name__</param> -->
- <!-- Various other submission parameters can be passed along to the LWR
- whose use will depend on the remote LWR's configured job manager.
+ <!-- Various other submission parameters can be passed along to the Pulsar
+ whose use will depend on the remote Pulsar's configured job manager.
For instance:
-->
- <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- Disable parameter rewriting and rewrite generated commands
+ instead. This may be required if remote host is Windows machine
+ but probably not otherwise.
+ -->
+ <!-- <param id="rewrite_parameters">false</params> --></destination>
- <destination id="amqp_lwr_dest" runner="amqp_lwr" >
- <!-- url and private_token are not valid when using MQ driven LWR. The plugin above
- determines which queue/manager to target and the underlying MQ server should be
- used to configure security.
- -->
- <!-- Traditionally, the LWR client sends request to LWR
- server to populate various system properties. This
+ <destination id="pulsar_mq_dest" runner="amqp_pulsar" >
+ <!-- The RESTful Pulsar client sends a request to Pulsar
+ to populate various system properties. This
extra step can be disabled and these calculated here
on client by uncommenting jobs_directory and
specifying any additional remote_property_ of
interest, this is not optional when using message
queues.
-->
- <param id="jobs_directory">/path/to/remote/lwr/lwr_staging/</param>
- <!-- Default the LWR send files to and pull files from Galaxy when
- using message queues (in the more traditional mode Galaxy sends
- files to and pull files from the LWR - this is obviously less
- appropriate when using a message queue).
-
- The default_file_action currently requires pycurl be available
- to Galaxy (presumably in its virtualenv). Making this dependency
- optional is an open task.
+ <param id="jobs_directory">/path/to/remote/pulsar/files/staging/</param>
+ <!-- Otherwise MQ and Legacy pulsar destinations can be supplied
+ all the same destination parameters as the RESTful client documented
+ above (though url and private_token are ignored when using a MQ).
-->
- <param id="default_file_action">remote_transfer</param></destination><destination id="ssh_torque" runner="cli"><param id="shell_plugin">SecureShell</param>
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/pulsar.py
--- /dev/null
+++ b/lib/galaxy/jobs/runners/pulsar.py
@@ -0,0 +1,707 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+
+import logging
+
+from galaxy import model
+from galaxy.jobs.runners import AsynchronousJobState, AsynchronousJobRunner
+from galaxy.jobs import ComputeEnvironment
+from galaxy.jobs import JobDestination
+from galaxy.jobs.command_factory import build_command
+from galaxy.tools.deps import dependencies
+from galaxy.util import string_as_bool_or_none
+from galaxy.util.bunch import Bunch
+from galaxy.util import specs
+
+import errno
+from time import sleep
+import os
+
+from pulsar.client import build_client_manager
+from pulsar.client import url_to_destination_params
+from pulsar.client import finish_job as pulsar_finish_job
+from pulsar.client import submit_job as pulsar_submit_job
+from pulsar.client import ClientJobDescription
+from pulsar.client import PulsarOutputs
+from pulsar.client import ClientOutputs
+from pulsar.client import PathMapper
+
+log = logging.getLogger( __name__ )
+
+__all__ = [ 'PulsarLegacyJobRunner', 'PulsarRESTJobRunner', 'PulsarMQJobRunner' ]
+
+NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE = "Pulsar misconfiguration - Pulsar client configured to set metadata remotely, but remote Pulsar isn't properly configured with a galaxy_home directory."
+NO_REMOTE_DATATYPES_CONFIG = "Pulsar client is configured to use remote datatypes configuration when setting metadata externally, but Pulsar is not configured with this information. Defaulting to datatypes_conf.xml."
+GENERIC_REMOTE_ERROR = "Failed to communicate with remote job server."
+
+# Is there a good way to infer some default for this? Can only use
+# url_for from web threads. https://gist.github.com/jmchilton/9098762
+DEFAULT_GALAXY_URL = "http://localhost:8080"
+
+PULSAR_PARAM_SPECS = dict(
+ transport=dict(
+ map=specs.to_str_or_none,
+ valid=specs.is_in("urllib", "curl", None),
+ default=None
+ ),
+ cache=dict(
+ map=specs.to_bool_or_none,
+ default=None,
+ ),
+ amqp_url=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ galaxy_url=dict(
+ map=specs.to_str_or_none,
+ default=DEFAULT_GALAXY_URL,
+ ),
+ manager=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_consumer_timeout=dict(
+ map=lambda val: None if val == "None" else float(val),
+ default=None,
+ ),
+ amqp_connect_ssl_ca_certs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_keyfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_certfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_cert_reqs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Producer.…
+ amqp_publish_retry=dict(
+ map=specs.to_bool,
+ default=False,
+ ),
+ amqp_publish_priority=dict(
+ map=int,
+ valid=lambda x: 0 <= x and x <= 9,
+ default=0,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Exchange.…
+ amqp_publish_delivery_mode=dict(
+ map=str,
+ valid=specs.is_in("transient", "persistent"),
+ default="persistent",
+ ),
+ amqp_publish_retry_max_retries=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_start=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_step=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_max=dict(
+ map=int,
+ default=None,
+ ),
+)
+
+
+PARAMETER_SPECIFICATION_REQUIRED = object()
+PARAMETER_SPECIFICATION_IGNORED = object()
+
+
+class PulsarJobRunner( AsynchronousJobRunner ):
+ """
+ Pulsar Job Runner
+ """
+ runner_name = "PulsarJobRunner"
+
+ def __init__( self, app, nworkers, **kwds ):
+ """Start the job runner """
+ super( PulsarJobRunner, self ).__init__( app, nworkers, runner_param_specs=PULSAR_PARAM_SPECS, **kwds )
+ self._init_worker_threads()
+ galaxy_url = self.runner_params.galaxy_url
+ if galaxy_url:
+ galaxy_url = galaxy_url.rstrip("/")
+ self.galaxy_url = galaxy_url
+ self.__init_client_manager()
+ self._monitor()
+
+ def _monitor( self ):
+ # Extension point allow MQ variant to setup callback instead
+ self._init_monitor_thread()
+
+ def __init_client_manager( self ):
+ client_manager_kwargs = {}
+ for kwd in 'manager', 'cache', 'transport':
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ for kwd in self.runner_params.keys():
+ if kwd.startswith( 'amqp_' ):
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ self.client_manager = build_client_manager(**client_manager_kwargs)
+
+ def url_to_destination( self, url ):
+ """Convert a legacy URL to a job destination"""
+ return JobDestination( runner="pulsar", params=url_to_destination_params( url ) )
+
+ def check_watched_item(self, job_state):
+ try:
+ client = self.get_client_from_state(job_state)
+ status = client.get_status()
+ except Exception:
+ # An orphaned job was put into the queue at app startup, so remote server went down
+ # either way we are done I guess.
+ self.mark_as_finished(job_state)
+ return None
+ job_state = self._update_job_state_for_status(job_state, status)
+ return job_state
+
+ def _update_job_state_for_status(self, job_state, pulsar_status):
+ if pulsar_status == "complete":
+ self.mark_as_finished(job_state)
+ return None
+ if pulsar_status == "failed":
+ self.fail_job(job_state)
+ return None
+ if pulsar_status == "running" and not job_state.running:
+ job_state.running = True
+ job_state.job_wrapper.change_state( model.Job.states.RUNNING )
+ return job_state
+
+ def queue_job(self, job_wrapper):
+ job_destination = job_wrapper.job_destination
+ self._populate_parameter_defaults( job_destination )
+
+ command_line, client, remote_job_config, compute_environment = self.__prepare_job( job_wrapper, job_destination )
+
+ if not command_line:
+ return
+
+ try:
+ dependencies_description = PulsarJobRunner.__dependencies_description( client, job_wrapper )
+ rewrite_paths = not PulsarJobRunner.__rewrite_parameters( client )
+ unstructured_path_rewrites = {}
+ if compute_environment:
+ unstructured_path_rewrites = compute_environment.unstructured_path_rewrites
+
+ client_job_description = ClientJobDescription(
+ command_line=command_line,
+ input_files=self.get_input_files(job_wrapper),
+ client_outputs=self.__client_outputs(client, job_wrapper),
+ working_directory=job_wrapper.working_directory,
+ tool=job_wrapper.tool,
+ config_files=job_wrapper.extra_filenames,
+ dependencies_description=dependencies_description,
+ env=client.env,
+ rewrite_paths=rewrite_paths,
+ arbitrary_files=unstructured_path_rewrites,
+ )
+ job_id = pulsar_submit_job(client, client_job_description, remote_job_config)
+ log.info("Pulsar job submitted with job_id %s" % job_id)
+ job_wrapper.set_job_destination( job_destination, job_id )
+ job_wrapper.change_state( model.Job.states.QUEUED )
+ except Exception:
+ job_wrapper.fail( "failure running job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+ return
+
+ pulsar_job_state = AsynchronousJobState()
+ pulsar_job_state.job_wrapper = job_wrapper
+ pulsar_job_state.job_id = job_id
+ pulsar_job_state.old_state = True
+ pulsar_job_state.running = False
+ pulsar_job_state.job_destination = job_destination
+ self.monitor_job(pulsar_job_state)
+
+ def __prepare_job(self, job_wrapper, job_destination):
+ """ Build command-line and Pulsar client for this job. """
+ command_line = None
+ client = None
+ remote_job_config = None
+ compute_environment = None
+ try:
+ client = self.get_client_from_wrapper(job_wrapper)
+ tool = job_wrapper.tool
+ remote_job_config = client.setup(tool.id, tool.version)
+ rewrite_parameters = PulsarJobRunner.__rewrite_parameters( client )
+ prepare_kwds = {}
+ if rewrite_parameters:
+ compute_environment = PulsarComputeEnvironment( client, job_wrapper, remote_job_config )
+ prepare_kwds[ 'compute_environment' ] = compute_environment
+ job_wrapper.prepare( **prepare_kwds )
+ self.__prepare_input_files_locally(job_wrapper)
+ remote_metadata = PulsarJobRunner.__remote_metadata( client )
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( client )
+ metadata_kwds = self.__build_metadata_configuration(client, job_wrapper, remote_metadata, remote_job_config)
+ remote_command_params = dict(
+ working_directory=remote_job_config['working_directory'],
+ metadata_kwds=metadata_kwds,
+ dependency_resolution=dependency_resolution,
+ )
+ remote_working_directory = remote_job_config['working_directory']
+ # TODO: Following defs work for Pulsar, always worked for Pulsar but should be
+ # calculated at some other level.
+ remote_job_directory = os.path.abspath(os.path.join(remote_working_directory, os.path.pardir))
+ remote_tool_directory = os.path.abspath(os.path.join(remote_job_directory, "tool_files"))
+ container = self._find_container(
+ job_wrapper,
+ compute_working_directory=remote_working_directory,
+ compute_tool_directory=remote_tool_directory,
+ compute_job_directory=remote_job_directory,
+ )
+ command_line = build_command(
+ self,
+ job_wrapper=job_wrapper,
+ container=container,
+ include_metadata=remote_metadata,
+ include_work_dir_outputs=False,
+ remote_command_params=remote_command_params,
+ )
+ except Exception:
+ job_wrapper.fail( "failure preparing job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+
+ # If we were able to get a command line, run the job
+ if not command_line:
+ job_wrapper.finish( '', '' )
+
+ return command_line, client, remote_job_config, compute_environment
+
+ def __prepare_input_files_locally(self, job_wrapper):
+ """Run task splitting commands locally."""
+ prepare_input_files_cmds = getattr(job_wrapper, 'prepare_input_files_cmds', None)
+ if prepare_input_files_cmds is not None:
+ for cmd in prepare_input_files_cmds: # run the commands to stage the input files
+ if 0 != os.system(cmd):
+ raise Exception('Error running file staging command: %s' % cmd)
+ job_wrapper.prepare_input_files_cmds = None # prevent them from being used in-line
+
+ def _populate_parameter_defaults( self, job_destination ):
+ updated = False
+ params = job_destination.params
+ for key, value in self.destination_defaults.iteritems():
+ if key in params:
+ if value is PARAMETER_SPECIFICATION_IGNORED:
+ log.warn( "Pulsar runner in selected configuration ignores parameter %s" % key )
+ continue
+ #if self.runner_params.get( key, None ):
+ # # Let plugin define defaults for some parameters -
+ # # for instance that way jobs_directory can be
+ # # configured next to AMQP url (where it belongs).
+ # params[ key ] = self.runner_params[ key ]
+ # continue
+
+ if not value:
+ continue
+
+ if value is PARAMETER_SPECIFICATION_REQUIRED:
+ raise Exception( "Pulsar destination does not define required parameter %s" % key )
+ elif value is not PARAMETER_SPECIFICATION_IGNORED:
+ params[ key ] = value
+ updated = True
+ return updated
+
+ def get_output_files(self, job_wrapper):
+ output_paths = job_wrapper.get_output_fnames()
+ return [ str( o ) for o in output_paths ] # Force job_path from DatasetPath objects.
+
+ def get_input_files(self, job_wrapper):
+ input_paths = job_wrapper.get_input_paths()
+ return [ str( i ) for i in input_paths ] # Force job_path from DatasetPath objects.
+
+ def get_client_from_wrapper(self, job_wrapper):
+ job_id = job_wrapper.job_id
+ if hasattr(job_wrapper, 'task_id'):
+ job_id = "%s_%s" % (job_id, job_wrapper.task_id)
+ params = job_wrapper.job_destination.params.copy()
+ for key, value in params.iteritems():
+ if value:
+ params[key] = model.User.expand_user_properties( job_wrapper.get_job().user, value )
+
+ env = getattr( job_wrapper.job_destination, "env", [] )
+ return self.get_client( params, job_id, env )
+
+ def get_client_from_state(self, job_state):
+ job_destination_params = job_state.job_destination.params
+ job_id = job_state.job_id
+ return self.get_client( job_destination_params, job_id )
+
+ def get_client( self, job_destination_params, job_id, env=[] ):
+ # Cannot use url_for outside of web thread.
+ #files_endpoint = url_for( controller="job_files", job_id=encoded_job_id )
+
+ encoded_job_id = self.app.security.encode_id(job_id)
+ job_key = self.app.security.encode_id( job_id, kind="jobs_files" )
+ files_endpoint = "%s/api/jobs/%s/files?job_key=%s" % (
+ self.galaxy_url,
+ encoded_job_id,
+ job_key
+ )
+ get_client_kwds = dict(
+ job_id=str( job_id ),
+ files_endpoint=files_endpoint,
+ env=env
+ )
+ return self.client_manager.get_client( job_destination_params, **get_client_kwds )
+
+ def finish_job( self, job_state ):
+ stderr = stdout = ''
+ job_wrapper = job_state.job_wrapper
+ try:
+ client = self.get_client_from_state(job_state)
+ run_results = client.full_status()
+ remote_working_directory = run_results.get("working_directory", None)
+ stdout = run_results.get('stdout', '')
+ stderr = run_results.get('stderr', '')
+ exit_code = run_results.get('returncode', None)
+ pulsar_outputs = PulsarOutputs.from_status_response(run_results)
+ # Use Pulsar client code to transfer/copy files back
+ # and cleanup job if needed.
+ completed_normally = \
+ job_wrapper.get_state() not in [ model.Job.states.ERROR, model.Job.states.DELETED ]
+ cleanup_job = self.app.config.cleanup_job
+ client_outputs = self.__client_outputs(client, job_wrapper)
+ finish_args = dict( client=client,
+ job_completed_normally=completed_normally,
+ cleanup_job=cleanup_job,
+ client_outputs=client_outputs,
+ pulsar_outputs=pulsar_outputs )
+ failed = pulsar_finish_job( **finish_args )
+ if failed:
+ job_wrapper.fail("Failed to find or download one or more job outputs from remote server.", exception=True)
+ except Exception:
+ message = GENERIC_REMOTE_ERROR
+ job_wrapper.fail( message, exception=True )
+ log.exception("failure finishing job %d" % job_wrapper.job_id)
+ return
+ if not PulsarJobRunner.__remote_metadata( client ):
+ self._handle_metadata_externally( job_wrapper, resolve_requirements=True )
+ # Finish the job
+ try:
+ job_wrapper.finish(
+ stdout,
+ stderr,
+ exit_code,
+ remote_working_directory=remote_working_directory
+ )
+ except Exception:
+ log.exception("Job wrapper finish method failed")
+ job_wrapper.fail("Unable to finish job", exception=True)
+
+ def fail_job( self, job_state ):
+ """
+ Seperated out so we can use the worker threads for it.
+ """
+ self.stop_job( self.sa_session.query( self.app.model.Job ).get( job_state.job_wrapper.job_id ) )
+ job_state.job_wrapper.fail( getattr( job_state, "fail_message", GENERIC_REMOTE_ERROR ) )
+
+ def check_pid( self, pid ):
+ try:
+ os.kill( pid, 0 )
+ return True
+ except OSError, e:
+ if e.errno == errno.ESRCH:
+ log.debug( "check_pid(): PID %d is dead" % pid )
+ else:
+ log.warning( "check_pid(): Got errno %s when attempting to check PID %d: %s" % ( errno.errorcode[e.errno], pid, e.strerror ) )
+ return False
+
+ def stop_job( self, job ):
+ #if our local job has JobExternalOutputMetadata associated, then our primary job has to have already finished
+ job_ext_output_metadata = job.get_external_output_metadata()
+ if job_ext_output_metadata:
+ pid = job_ext_output_metadata[0].job_runner_external_pid # every JobExternalOutputMetadata has a pid set, we just need to take from one of them
+ if pid in [ None, '' ]:
+ log.warning( "stop_job(): %s: no PID in database for job, unable to stop" % job.id )
+ return
+ pid = int( pid )
+ if not self.check_pid( pid ):
+ log.warning( "stop_job(): %s: PID %d was already dead or can't be signaled" % ( job.id, pid ) )
+ return
+ for sig in [ 15, 9 ]:
+ try:
+ os.killpg( pid, sig )
+ except OSError, e:
+ log.warning( "stop_job(): %s: Got errno %s when attempting to signal %d to PID %d: %s" % ( job.id, errno.errorcode[e.errno], sig, pid, e.strerror ) )
+ return # give up
+ sleep( 2 )
+ if not self.check_pid( pid ):
+ log.debug( "stop_job(): %s: PID %d successfully killed with signal %d" % ( job.id, pid, sig ) )
+ return
+ else:
+ log.warning( "stop_job(): %s: PID %d refuses to die after signaling TERM/KILL" % ( job.id, pid ) )
+ else:
+ # Remote kill
+ pulsar_url = job.job_runner_name
+ job_id = job.job_runner_external_id
+ log.debug("Attempt remote Pulsar kill of job with url %s and id %s" % (pulsar_url, job_id))
+ client = self.get_client(job.destination_params, job_id)
+ client.kill()
+
+ def recover( self, job, job_wrapper ):
+ """Recovers jobs stuck in the queued/running state when Galaxy started"""
+ job_state = self._job_state( job, job_wrapper )
+ job_wrapper.command_line = job.get_command_line()
+ state = job.get_state()
+ if state in [model.Job.states.RUNNING, model.Job.states.QUEUED]:
+ log.debug( "(Pulsar/%s) is still in running state, adding to the Pulsar queue" % ( job.get_id()) )
+ job_state.old_state = True
+ job_state.running = state == model.Job.states.RUNNING
+ self.monitor_queue.put( job_state )
+
+ def shutdown( self ):
+ super( PulsarJobRunner, self ).shutdown()
+ self.client_manager.shutdown()
+
+ def _job_state( self, job, job_wrapper ):
+ job_state = AsynchronousJobState()
+ # TODO: Determine why this is set when using normal message queue updates
+ # but not CLI submitted MQ updates...
+ raw_job_id = job.get_job_runner_external_id() or job_wrapper.job_id
+ job_state.job_id = str( raw_job_id )
+ job_state.runner_url = job_wrapper.get_job_runner_url()
+ job_state.job_destination = job_wrapper.job_destination
+ job_state.job_wrapper = job_wrapper
+ return job_state
+
+ def __client_outputs( self, client, job_wrapper ):
+ work_dir_outputs = self.get_work_dir_outputs( job_wrapper )
+ output_files = self.get_output_files( job_wrapper )
+ client_outputs = ClientOutputs(
+ working_directory=job_wrapper.working_directory,
+ work_dir_outputs=work_dir_outputs,
+ output_files=output_files,
+ version_file=job_wrapper.get_version_string_path(),
+ )
+ return client_outputs
+
+ @staticmethod
+ def __dependencies_description( pulsar_client, job_wrapper ):
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( pulsar_client )
+ remote_dependency_resolution = dependency_resolution == "remote"
+ if not remote_dependency_resolution:
+ return None
+ requirements = job_wrapper.tool.requirements or []
+ installed_tool_dependencies = job_wrapper.tool.installed_tool_dependencies or []
+ return dependencies.DependenciesDescription(
+ requirements=requirements,
+ installed_tool_dependencies=installed_tool_dependencies,
+ )
+
+ @staticmethod
+ def __dependency_resolution( pulsar_client ):
+ dependency_resolution = pulsar_client.destination_params.get( "dependency_resolution", "local" )
+ if dependency_resolution not in ["none", "local", "remote"]:
+ raise Exception("Unknown dependency_resolution value encountered %s" % dependency_resolution)
+ return dependency_resolution
+
+ @staticmethod
+ def __remote_metadata( pulsar_client ):
+ remote_metadata = string_as_bool_or_none( pulsar_client.destination_params.get( "remote_metadata", False ) )
+ return remote_metadata
+
+ @staticmethod
+ def __use_remote_datatypes_conf( pulsar_client ):
+ """ When setting remote metadata, use integrated datatypes from this
+ Galaxy instance or use the datatypes config configured via the remote
+ Pulsar.
+
+ Both options are broken in different ways for same reason - datatypes
+ may not match. One can push the local datatypes config to the remote
+ server - but there is no guarentee these datatypes will be defined
+ there. Alternatively, one can use the remote datatype config - but
+ there is no guarentee that it will contain all the datatypes available
+ to this Galaxy.
+ """
+ use_remote_datatypes = string_as_bool_or_none( pulsar_client.destination_params.get( "use_remote_datatypes", False ) )
+ return use_remote_datatypes
+
+ @staticmethod
+ def __rewrite_parameters( pulsar_client ):
+ return string_as_bool_or_none( pulsar_client.destination_params.get( "rewrite_parameters", False ) ) or False
+
+ def __build_metadata_configuration(self, client, job_wrapper, remote_metadata, remote_job_config):
+ metadata_kwds = {}
+ if remote_metadata:
+ remote_system_properties = remote_job_config.get("system_properties", {})
+ remote_galaxy_home = remote_system_properties.get("galaxy_home", None)
+ if not remote_galaxy_home:
+ raise Exception(NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE)
+ metadata_kwds['exec_dir'] = remote_galaxy_home
+ outputs_directory = remote_job_config['outputs_directory']
+ configs_directory = remote_job_config['configs_directory']
+ working_directory = remote_job_config['working_directory']
+ # For metadata calculation, we need to build a list of of output
+ # file objects with real path indicating location on Galaxy server
+ # and false path indicating location on compute server. Since the
+ # Pulsar disables from_work_dir copying as part of the job command
+ # line we need to take the list of output locations on the Pulsar
+ # server (produced by self.get_output_files(job_wrapper)) and for
+ # each work_dir output substitute the effective path on the Pulsar
+ # server relative to the remote working directory as the
+ # false_path to send the metadata command generation module.
+ work_dir_outputs = self.get_work_dir_outputs(job_wrapper, job_working_directory=working_directory)
+ outputs = [Bunch(false_path=os.path.join(outputs_directory, os.path.basename(path)), real_path=path) for path in self.get_output_files(job_wrapper)]
+ for output in outputs:
+ for pulsar_workdir_path, real_path in work_dir_outputs:
+ if real_path == output.real_path:
+ output.false_path = pulsar_workdir_path
+ metadata_kwds['output_fnames'] = outputs
+ metadata_kwds['compute_tmp_dir'] = working_directory
+ metadata_kwds['config_root'] = remote_galaxy_home
+ default_config_file = os.path.join(remote_galaxy_home, 'universe_wsgi.ini')
+ metadata_kwds['config_file'] = remote_system_properties.get('galaxy_config_file', default_config_file)
+ metadata_kwds['dataset_files_path'] = remote_system_properties.get('galaxy_dataset_files_path', None)
+ if PulsarJobRunner.__use_remote_datatypes_conf( client ):
+ remote_datatypes_config = remote_system_properties.get('galaxy_datatypes_config_file', None)
+ if not remote_datatypes_config:
+ log.warn(NO_REMOTE_DATATYPES_CONFIG)
+ remote_datatypes_config = os.path.join(remote_galaxy_home, 'datatypes_conf.xml')
+ metadata_kwds['datatypes_config'] = remote_datatypes_config
+ else:
+ integrates_datatypes_config = self.app.datatypes_registry.integrated_datatypes_configs
+ # Ensure this file gets pushed out to the remote config dir.
+ job_wrapper.extra_filenames.append(integrates_datatypes_config)
+
+ metadata_kwds['datatypes_config'] = os.path.join(configs_directory, os.path.basename(integrates_datatypes_config))
+ return metadata_kwds
+
+
+class PulsarLegacyJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ rewrite_parameters="false",
+ dependency_resolution="local",
+ )
+
+
+class PulsarMQJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="remote_transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ jobs_directory=PARAMETER_SPECIFICATION_REQUIRED,
+ url=PARAMETER_SPECIFICATION_IGNORED,
+ private_token=PARAMETER_SPECIFICATION_IGNORED
+ )
+
+ def _monitor( self ):
+ # This is a message queue driven runner, don't monitor
+ # just setup required callback.
+ self.client_manager.ensure_has_status_update_callback(self.__async_update)
+
+ def __async_update( self, full_status ):
+ job_id = None
+ try:
+ job_id = full_status[ "job_id" ]
+ job, job_wrapper = self.app.job_manager.job_handler.job_queue.job_pair_for_id( job_id )
+ job_state = self._job_state( job, job_wrapper )
+ self._update_job_state_for_status(job_state, full_status[ "status" ] )
+ except Exception:
+ log.exception( "Failed to update Pulsar job status for job_id %s" % job_id )
+ raise
+ # Nothing else to do? - Attempt to fail the job?
+
+
+class PulsarRESTJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ url=PARAMETER_SPECIFICATION_REQUIRED,
+ )
+
+
+class PulsarComputeEnvironment( ComputeEnvironment ):
+
+ def __init__( self, pulsar_client, job_wrapper, remote_job_config ):
+ self.pulsar_client = pulsar_client
+ self.job_wrapper = job_wrapper
+ self.local_path_config = job_wrapper.default_compute_environment()
+ self.unstructured_path_rewrites = {}
+ # job_wrapper.prepare is going to expunge the job backing the following
+ # computations, so precalculate these paths.
+ self._wrapper_input_paths = self.local_path_config.input_paths()
+ self._wrapper_output_paths = self.local_path_config.output_paths()
+ self.path_mapper = PathMapper(pulsar_client, remote_job_config, self.local_path_config.working_directory())
+ self._config_directory = remote_job_config[ "configs_directory" ]
+ self._working_directory = remote_job_config[ "working_directory" ]
+ self._sep = remote_job_config[ "system_properties" ][ "separator" ]
+ self._tool_dir = remote_job_config[ "tools_directory" ]
+ version_path = self.local_path_config.version_path()
+ new_version_path = self.path_mapper.remote_version_path_rewrite(version_path)
+ if new_version_path:
+ version_path = new_version_path
+ self._version_path = version_path
+
+ def output_paths( self ):
+ local_output_paths = self._wrapper_output_paths
+
+ results = []
+ for local_output_path in local_output_paths:
+ wrapper_path = str( local_output_path )
+ remote_path = self.path_mapper.remote_output_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_output_path, remote_path ) )
+ return results
+
+ def input_paths( self ):
+ local_input_paths = self._wrapper_input_paths
+
+ results = []
+ for local_input_path in local_input_paths:
+ wrapper_path = str( local_input_path )
+ # This will over-copy in some cases. For instance in the case of task
+ # splitting, this input will be copied even though only the work dir
+ # input will actually be used.
+ remote_path = self.path_mapper.remote_input_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_input_path, remote_path ) )
+ return results
+
+ def _dataset_path( self, local_dataset_path, remote_path ):
+ remote_extra_files_path = None
+ if remote_path:
+ remote_extra_files_path = "%s_files" % remote_path[ 0:-len( ".dat" ) ]
+ return local_dataset_path.with_path_for_job( remote_path, remote_extra_files_path )
+
+ def working_directory( self ):
+ return self._working_directory
+
+ def config_directory( self ):
+ return self._config_directory
+
+ def new_file_path( self ):
+ return self.working_directory() # Problems with doing this?
+
+ def sep( self ):
+ return self._sep
+
+ def version_path( self ):
+ return self._version_path
+
+ def rewriter( self, parameter_value ):
+ unstructured_path_rewrites = self.unstructured_path_rewrites
+ if parameter_value in unstructured_path_rewrites:
+ # Path previously mapped, use previous mapping.
+ return unstructured_path_rewrites[ parameter_value ]
+ if parameter_value in unstructured_path_rewrites.itervalues():
+ # Path is a rewritten remote path (this might never occur,
+ # consider dropping check...)
+ return parameter_value
+
+ rewrite, new_unstructured_path_rewrites = self.path_mapper.check_for_arbitrary_rewrite( parameter_value )
+ if rewrite:
+ unstructured_path_rewrites.update(new_unstructured_path_rewrites)
+ return rewrite
+ else:
+ # Did need to rewrite, use original path or value.
+ return parameter_value
+
+ def unstructured_path_rewriter( self ):
+ return self.rewriter
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/__init__.py
--- a/lib/galaxy/jobs/runners/util/__init__.py
+++ b/lib/galaxy/jobs/runners/util/__init__.py
@@ -1,7 +1,7 @@
"""
This module and its submodules contains utilities for running external
processes and interfacing with job managers. This module should contain
-functionality shared between Galaxy and the LWR.
+functionality shared between Galaxy and the Pulsar.
"""
from galaxy.util.bunch import Bunch
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/factory.py
--- a/lib/galaxy/jobs/runners/util/cli/factory.py
+++ b/lib/galaxy/jobs/runners/util/cli/factory.py
@@ -5,7 +5,7 @@
)
code_dir = 'lib'
except ImportError:
- from lwr.managers.util.cli import (
+ from pulsar.managers.util.cli import (
CliInterface,
split_params
)
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/job/slurm.py
--- a/lib/galaxy/jobs/runners/util/cli/job/slurm.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/slurm.py
@@ -5,7 +5,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/job/torque.py
--- a/lib/galaxy/jobs/runners/util/cli/job/torque.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/torque.py
@@ -7,7 +7,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/__init__.py
--- a/lib/galaxy/objectstore/__init__.py
+++ b/lib/galaxy/objectstore/__init__.py
@@ -623,9 +623,9 @@
elif store == 'irods':
from .rods import IRODSObjectStore
return IRODSObjectStore(config=config, config_xml=config_xml)
- elif store == 'lwr':
- from .lwr import LwrObjectStore
- return LwrObjectStore(config=config, config_xml=config_xml)
+ elif store == 'pulsar':
+ from .pulsar import PulsarObjectStore
+ return PulsarObjectStore(config=config, config_xml=config_xml)
else:
log.error("Unrecognized object store definition: {0}".format(store))
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/lwr.py
--- a/lib/galaxy/objectstore/lwr.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from __future__ import absolute_import # Need to import lwr_client absolutely.
-from ..objectstore import ObjectStore
-try:
- from galaxy.jobs.runners.lwr_client.manager import ObjectStoreClientManager
-except ImportError:
- from lwr.lwr_client.manager import ObjectStoreClientManager
-
-
-class LwrObjectStore(ObjectStore):
- """
- Object store implementation that delegates to a remote LWR server.
-
- This may be more aspirational than practical for now, it would be good to
- Galaxy to a point that a handler thread could be setup that doesn't attempt
- to access the disk files returned by a (this) object store - just passing
- them along to the LWR unmodified. That modification - along with this
- implementation and LWR job destinations would then allow Galaxy to fully
- manage jobs on remote servers with completely different mount points.
-
- This implementation should be considered beta and may be dropped from
- Galaxy at some future point or significantly modified.
- """
-
- def __init__(self, config, config_xml):
- self.lwr_client = self.__build_lwr_client(config_xml)
-
- def exists(self, obj, **kwds):
- return self.lwr_client.exists(**self.__build_kwds(obj, **kwds))
-
- def file_ready(self, obj, **kwds):
- return self.lwr_client.file_ready(**self.__build_kwds(obj, **kwds))
-
- def create(self, obj, **kwds):
- return self.lwr_client.create(**self.__build_kwds(obj, **kwds))
-
- def empty(self, obj, **kwds):
- return self.lwr_client.empty(**self.__build_kwds(obj, **kwds))
-
- def size(self, obj, **kwds):
- return self.lwr_client.size(**self.__build_kwds(obj, **kwds))
-
- def delete(self, obj, **kwds):
- return self.lwr_client.delete(**self.__build_kwds(obj, **kwds))
-
- # TODO: Optimize get_data.
- def get_data(self, obj, **kwds):
- return self.lwr_client.get_data(**self.__build_kwds(obj, **kwds))
-
- def get_filename(self, obj, **kwds):
- return self.lwr_client.get_filename(**self.__build_kwds(obj, **kwds))
-
- def update_from_file(self, obj, **kwds):
- return self.lwr_client.update_from_file(**self.__build_kwds(obj, **kwds))
-
- def get_store_usage_percent(self):
- return self.lwr_client.get_store_usage_percent()
-
- def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
- return None
-
- def __build_kwds(self, obj, **kwds):
- kwds['object_id'] = obj.id
- return kwds
- pass
-
- def __build_lwr_client(self, config_xml):
- url = config_xml.get("url")
- private_token = config_xml.get("private_token", None)
- transport = config_xml.get("transport", None)
- manager_options = dict(transport=transport)
- client_options = dict(url=url, private_token=private_token)
- lwr_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
- return lwr_client
-
- def shutdown(self):
- pass
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/pulsar.py
--- /dev/null
+++ b/lib/galaxy/objectstore/pulsar.py
@@ -0,0 +1,73 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+from ..objectstore import ObjectStore
+from pulsar.client.manager import ObjectStoreClientManager
+
+
+class PulsarObjectStore(ObjectStore):
+ """
+ Object store implementation that delegates to a remote Pulsar server.
+
+ This may be more aspirational than practical for now, it would be good to
+ Galaxy to a point that a handler thread could be setup that doesn't attempt
+ to access the disk files returned by a (this) object store - just passing
+ them along to the Pulsar unmodified. That modification - along with this
+ implementation and Pulsar job destinations would then allow Galaxy to fully
+ manage jobs on remote servers with completely different mount points.
+
+ This implementation should be considered beta and may be dropped from
+ Galaxy at some future point or significantly modified.
+ """
+
+ def __init__(self, config, config_xml):
+ self.pulsar_client = self.__build_pulsar_client(config_xml)
+
+ def exists(self, obj, **kwds):
+ return self.pulsar_client.exists(**self.__build_kwds(obj, **kwds))
+
+ def file_ready(self, obj, **kwds):
+ return self.pulsar_client.file_ready(**self.__build_kwds(obj, **kwds))
+
+ def create(self, obj, **kwds):
+ return self.pulsar_client.create(**self.__build_kwds(obj, **kwds))
+
+ def empty(self, obj, **kwds):
+ return self.pulsar_client.empty(**self.__build_kwds(obj, **kwds))
+
+ def size(self, obj, **kwds):
+ return self.pulsar_client.size(**self.__build_kwds(obj, **kwds))
+
+ def delete(self, obj, **kwds):
+ return self.pulsar_client.delete(**self.__build_kwds(obj, **kwds))
+
+ # TODO: Optimize get_data.
+ def get_data(self, obj, **kwds):
+ return self.pulsar_client.get_data(**self.__build_kwds(obj, **kwds))
+
+ def get_filename(self, obj, **kwds):
+ return self.pulsar_client.get_filename(**self.__build_kwds(obj, **kwds))
+
+ def update_from_file(self, obj, **kwds):
+ return self.pulsar_client.update_from_file(**self.__build_kwds(obj, **kwds))
+
+ def get_store_usage_percent(self):
+ return self.pulsar_client.get_store_usage_percent()
+
+ def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
+ return None
+
+ def __build_kwds(self, obj, **kwds):
+ kwds['object_id'] = obj.id
+ return kwds
+ pass
+
+ def __build_pulsar_client(self, config_xml):
+ url = config_xml.get("url")
+ private_token = config_xml.get("private_token", None)
+ transport = config_xml.get("transport", None)
+ manager_options = dict(transport=transport)
+ client_options = dict(url=url, private_token=private_token)
+ pulsar_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
+ return pulsar_client
+
+ def shutdown(self):
+ pass
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/tools/deps/dependencies.py
--- a/lib/galaxy/tools/deps/dependencies.py
+++ b/lib/galaxy/tools/deps/dependencies.py
@@ -8,7 +8,7 @@
related context required to resolve dependencies via the
ToolShedPackageDependencyResolver.
- This is meant to enable remote resolution of dependencies, by the LWR or
+ This is meant to enable remote resolution of dependencies, by the Pulsar or
other potential remote execution mechanisms.
"""
@@ -39,7 +39,7 @@
@staticmethod
def _toolshed_install_dependency_from_dict(as_dict):
- # Rather than requiring full models in LWR, just use simple objects
+ # Rather than requiring full models in Pulsar, just use simple objects
# containing only properties and associations used to resolve
# dependencies for tool execution.
repository_object = bunch.Bunch(
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/__init__.py
--- /dev/null
+++ b/lib/pulsar/client/__init__.py
@@ -0,0 +1,62 @@
+"""
+pulsar client
+======
+
+This module contains logic for interfacing with an external Pulsar server.
+
+------------------
+Configuring Galaxy
+------------------
+
+Galaxy job runners are configured in Galaxy's ``job_conf.xml`` file. See ``job_conf.xml.sample_advanced``
+in your Galaxy code base or on
+`Bitbucket <https://bitbucket.org/galaxy/galaxy-dist/src/tip/job_conf.xml.sample_advanc…>`_
+for information on how to configure Galaxy to interact with the Pulsar.
+
+Galaxy also supports an older, less rich configuration of job runners directly
+in its main ``universe_wsgi.ini`` file. The following section describes how to
+configure Galaxy to communicate with the Pulsar in this legacy mode.
+
+Legacy
+------
+
+A Galaxy tool can be configured to be executed remotely via Pulsar by
+adding a line to the ``universe_wsgi.ini`` file under the
+``galaxy:tool_runners`` section with the format::
+
+ <tool_id> = pulsar://http://<pulsar_host>:<pulsar_port>
+
+As an example, if a host named remotehost is running the Pulsar server
+application on port ``8913``, then the tool with id ``test_tool`` can
+be configured to run remotely on remotehost by adding the following
+line to ``universe.ini``::
+
+ test_tool = pulsar://http://remotehost:8913
+
+Remember this must be added after the ``[galaxy:tool_runners]`` header
+in the ``universe.ini`` file.
+
+
+"""
+
+from .staging.down import finish_job
+from .staging.up import submit_job
+from .staging import ClientJobDescription
+from .staging import PulsarOutputs
+from .staging import ClientOutputs
+from .client import OutputNotFoundException
+from .manager import build_client_manager
+from .destination import url_to_destination_params
+from .path_mapper import PathMapper
+
+__all__ = [
+ build_client_manager,
+ OutputNotFoundException,
+ url_to_destination_params,
+ finish_job,
+ submit_job,
+ ClientJobDescription,
+ PulsarOutputs,
+ ClientOutputs,
+ PathMapper,
+]
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/action_mapper.py
--- /dev/null
+++ b/lib/pulsar/client/action_mapper.py
@@ -0,0 +1,567 @@
+from json import load
+from os import makedirs
+from os.path import exists
+from os.path import abspath
+from os.path import dirname
+from os.path import join
+from os.path import basename
+from os.path import sep
+import fnmatch
+from re import compile
+from re import escape
+import galaxy.util
+from galaxy.util.bunch import Bunch
+from .config_util import read_file
+from .util import directory_files
+from .util import unique_path_prefix
+from .transport import get_file
+from .transport import post_file
+
+
+DEFAULT_MAPPED_ACTION = 'transfer' # Not really clear to me what this should be, exception?
+DEFAULT_PATH_MAPPER_TYPE = 'prefix'
+
+STAGING_ACTION_REMOTE = "remote"
+STAGING_ACTION_LOCAL = "local"
+STAGING_ACTION_NONE = None
+STAGING_ACTION_DEFAULT = "default"
+
+# Poor man's enum.
+path_type = Bunch(
+ # Galaxy input datasets and extra files.
+ INPUT="input",
+ # Galaxy config and param files.
+ CONFIG="config",
+ # Files from tool's tool_dir (for now just wrapper if available).
+ TOOL="tool",
+ # Input work dir files - e.g. metadata files, task-split input files, etc..
+ WORKDIR="workdir",
+ # Galaxy output datasets in their final home.
+ OUTPUT="output",
+ # Galaxy from_work_dir output paths and other files (e.g. galaxy.json)
+ OUTPUT_WORKDIR="output_workdir",
+ # Other fixed tool parameter paths (likely coming from tool data, but not
+ # nessecarily). Not sure this is the best name...
+ UNSTRUCTURED="unstructured",
+)
+
+
+ACTION_DEFAULT_PATH_TYPES = [
+ path_type.INPUT,
+ path_type.CONFIG,
+ path_type.TOOL,
+ path_type.WORKDIR,
+ path_type.OUTPUT,
+ path_type.OUTPUT_WORKDIR,
+]
+ALL_PATH_TYPES = ACTION_DEFAULT_PATH_TYPES + [path_type.UNSTRUCTURED]
+
+
+class FileActionMapper(object):
+ """
+ Objects of this class define how paths are mapped to actions.
+
+ >>> json_string = r'''{"paths": [ \
+ {"path": "/opt/galaxy", "action": "none"}, \
+ {"path": "/galaxy/data", "action": "transfer"}, \
+ {"path": "/cool/bamfiles/**/*.bam", "action": "copy", "match_type": "glob"}, \
+ {"path": ".*/dataset_\\\\d+.dat", "action": "copy", "match_type": "regex"} \
+ ]}'''
+ >>> from tempfile import NamedTemporaryFile
+ >>> from os import unlink
+ >>> def mapper_for(default_action, config_contents):
+ ... f = NamedTemporaryFile(delete=False)
+ ... f.write(config_contents.encode('UTF-8'))
+ ... f.close()
+ ... mock_client = Bunch(default_file_action=default_action, action_config_path=f.name, files_endpoint=None)
+ ... mapper = FileActionMapper(mock_client)
+ ... mapper = FileActionMapper(config=mapper.to_dict()) # Serialize and deserialize it to make sure still works
+ ... unlink(f.name)
+ ... return mapper
+ >>> mapper = mapper_for(default_action='none', config_contents=json_string)
+ >>> # Test first config line above, implicit path prefix mapper
+ >>> action = mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input')
+ >>> action.action_type == u'none'
+ True
+ >>> action.staging_needed
+ False
+ >>> # Test another (2nd) mapper, this one with a different action
+ >>> action = mapper.action('/galaxy/data/files/000/dataset_1.dat', 'input')
+ >>> action.action_type == u'transfer'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Always at least copy work_dir outputs.
+ >>> action = mapper.action('/opt/galaxy/database/working_directory/45.sh', 'workdir')
+ >>> action.action_type == u'copy'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Test glob mapper (matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam', 'input').action_type == u'copy'
+ True
+ >>> # Test glob mapper (non-matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam.bai', 'input').action_type == u'none'
+ True
+ >>> # Regex mapper test.
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'input').action_type == u'copy'
+ True
+ >>> # Doesn't map unstructured paths by default
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'none'
+ True
+ >>> input_only_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "input"} \
+ ] }''')
+ >>> input_only_mapper.action('/dataset_1.dat', 'input').action_type == u'transfer'
+ True
+ >>> input_only_mapper.action('/dataset_1.dat', 'output').action_type == u'none'
+ True
+ >>> unstructured_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "*any*"} \
+ ] }''')
+ >>> unstructured_mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'transfer'
+ True
+ """
+
+ def __init__(self, client=None, config=None):
+ if config is None and client is None:
+ message = "FileActionMapper must be constructed from either a client or a config dictionary."
+ raise Exception(message)
+ if config is None:
+ config = self.__client_to_config(client)
+ self.default_action = config.get("default_action", "transfer")
+ self.mappers = mappers_from_dicts(config.get("paths", []))
+ self.files_endpoint = config.get("files_endpoint", None)
+
+ def action(self, path, type, mapper=None):
+ mapper = self.__find_mapper(path, type, mapper)
+ action_class = self.__action_class(path, type, mapper)
+ file_lister = DEFAULT_FILE_LISTER
+ action_kwds = {}
+ if mapper:
+ file_lister = mapper.file_lister
+ action_kwds = mapper.action_kwds
+ action = action_class(path, file_lister=file_lister, **action_kwds)
+ self.__process_action(action, type)
+ return action
+
+ def unstructured_mappers(self):
+ """ Return mappers that will map 'unstructured' files (i.e. go beyond
+ mapping inputs, outputs, and config files).
+ """
+ return filter(lambda m: path_type.UNSTRUCTURED in m.path_types, self.mappers)
+
+ def to_dict(self):
+ return dict(
+ default_action=self.default_action,
+ files_endpoint=self.files_endpoint,
+ paths=map(lambda m: m.to_dict(), self.mappers)
+ )
+
+ def __client_to_config(self, client):
+ action_config_path = client.action_config_path
+ if action_config_path:
+ config = read_file(action_config_path)
+ else:
+ config = dict()
+ config["default_action"] = client.default_file_action
+ config["files_endpoint"] = client.files_endpoint
+ return config
+
+ def __load_action_config(self, path):
+ config = load(open(path, 'rb'))
+ self.mappers = mappers_from_dicts(config.get('paths', []))
+
+ def __find_mapper(self, path, type, mapper=None):
+ if not mapper:
+ normalized_path = abspath(path)
+ for query_mapper in self.mappers:
+ if query_mapper.matches(normalized_path, type):
+ mapper = query_mapper
+ break
+ return mapper
+
+ def __action_class(self, path, type, mapper):
+ action_type = self.default_action if type in ACTION_DEFAULT_PATH_TYPES else "none"
+ if mapper:
+ action_type = mapper.action_type
+ if type in ["workdir", "output_workdir"] and action_type == "none":
+ # We are changing the working_directory relative to what
+ # Galaxy would use, these need to be copied over.
+ action_type = "copy"
+ action_class = actions.get(action_type, None)
+ if action_class is None:
+ message_template = "Unknown action_type encountered %s while trying to map path %s"
+ message_args = (action_type, path)
+ raise Exception(message_template % message_args)
+ return action_class
+
+ def __process_action(self, action, file_type):
+ """ Extension point to populate extra action information after an
+ action has been created.
+ """
+ if action.action_type == "remote_transfer":
+ url_base = self.files_endpoint
+ if not url_base:
+ raise Exception("Attempted to use remote_transfer action with defining a files_endpoint")
+ if "?" not in url_base:
+ url_base = "%s?" % url_base
+ # TODO: URL encode path.
+ url = "%s&path=%s&file_type=%s" % (url_base, action.path, file_type)
+ action.url = url
+
+REQUIRED_ACTION_KWD = object()
+
+
+class BaseAction(object):
+ action_spec = {}
+
+ def __init__(self, path, file_lister=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+
+ def unstructured_map(self, path_helper):
+ unstructured_map = self.file_lister.unstructured_map(self.path)
+ if self.staging_needed:
+ # To ensure uniqueness, prepend unique prefix to each name
+ prefix = unique_path_prefix(self.path)
+ for path, name in unstructured_map.iteritems():
+ unstructured_map[path] = join(prefix, name)
+ else:
+ path_rewrites = {}
+ for path in unstructured_map:
+ rewrite = self.path_rewrite(path_helper, path)
+ if rewrite:
+ path_rewrites[path] = rewrite
+ unstructured_map = path_rewrites
+ return unstructured_map
+
+ @property
+ def staging_needed(self):
+ return self.staging != STAGING_ACTION_NONE
+
+ @property
+ def staging_action_local(self):
+ return self.staging == STAGING_ACTION_LOCAL
+
+
+class NoneAction(BaseAction):
+ """ This action indicates the corresponding path does not require any
+ additional action. This should indicate paths that are available both on
+ the Pulsar client (i.e. Galaxy server) and remote Pulsar server with the same
+ paths. """
+ action_type = "none"
+ staging = STAGING_ACTION_NONE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return NoneAction(path=action_dict["path"])
+
+ def path_rewrite(self, path_helper, path=None):
+ return None
+
+
+class RewriteAction(BaseAction):
+ """ This actin indicates the Pulsar server should simply rewrite the path
+ to the specified file.
+ """
+ action_spec = dict(
+ source_directory=REQUIRED_ACTION_KWD,
+ destination_directory=REQUIRED_ACTION_KWD
+ )
+ action_type = "rewrite"
+ staging = STAGING_ACTION_NONE
+
+ def __init__(self, path, file_lister=None, source_directory=None, destination_directory=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+ self.source_directory = source_directory
+ self.destination_directory = destination_directory
+
+ def to_dict(self):
+ return dict(
+ path=self.path,
+ action_type=self.action_type,
+ source_directory=self.source_directory,
+ destination_directory=self.destination_directory,
+ )
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RewriteAction(
+ path=action_dict["path"],
+ source_directory=action_dict["source_directory"],
+ destination_directory=action_dict["destination_directory"],
+ )
+
+ def path_rewrite(self, path_helper, path=None):
+ if not path:
+ path = self.path
+ new_path = path_helper.from_posix_with_new_base(self.path, self.source_directory, self.destination_directory)
+ return None if new_path == self.path else new_path
+
+
+class TransferAction(BaseAction):
+ """ This actions indicates that the Pulsar client should initiate an HTTP
+ transfer of the corresponding path to the remote Pulsar server before
+ launching the job. """
+ action_type = "transfer"
+ staging = STAGING_ACTION_LOCAL
+
+
+class CopyAction(BaseAction):
+ """ This action indicates that the Pulsar client should execute a file system
+ copy of the corresponding path to the Pulsar staging directory prior to
+ launching the corresponding job. """
+ action_type = "copy"
+ staging = STAGING_ACTION_LOCAL
+
+
+class RemoteCopyAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_copy"
+ staging = STAGING_ACTION_REMOTE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteCopyAction(path=action_dict["path"])
+
+ def write_to_path(self, path):
+ galaxy.util.copy_to_path(open(self.path, "rb"), path)
+
+ def write_from_path(self, pulsar_path):
+ destination = self.path
+ parent_directory = dirname(destination)
+ if not exists(parent_directory):
+ makedirs(parent_directory)
+ with open(pulsar_path, "rb") as f:
+ galaxy.util.copy_to_path(f, destination)
+
+
+class RemoteTransferAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_transfer"
+ staging = STAGING_ACTION_REMOTE
+
+ def __init__(self, path, file_lister=None, url=None):
+ super(RemoteTransferAction, self).__init__(path, file_lister=file_lister)
+ self.url = url
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type, url=self.url)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteTransferAction(path=action_dict["path"], url=action_dict["url"])
+
+ def write_to_path(self, path):
+ get_file(self.url, path)
+
+ def write_from_path(self, pulsar_path):
+ post_file(self.url, pulsar_path)
+
+
+class MessageAction(object):
+ """ Sort of pseudo action describing "files" store in memory and
+ transferred via message (HTTP, Python-call, MQ, etc...)
+ """
+ action_type = "message"
+ staging = STAGING_ACTION_DEFAULT
+
+ def __init__(self, contents, client=None):
+ self.contents = contents
+ self.client = client
+
+ @property
+ def staging_needed(self):
+ return True
+
+ @property
+ def staging_action_local(self):
+ # Ekkk, cannot be called if created through from_dict.
+ # Shouldn't be a problem the way it is used - but is an
+ # object design problem.
+ return self.client.prefer_local_staging
+
+ def to_dict(self):
+ return dict(contents=self.contents, action_type=MessageAction.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return MessageAction(contents=action_dict["contents"])
+
+ def write_to_path(self, path):
+ open(path, "w").write(self.contents)
+
+
+DICTIFIABLE_ACTION_CLASSES = [RemoteCopyAction, RemoteTransferAction, MessageAction]
+
+
+def from_dict(action_dict):
+ action_type = action_dict.get("action_type", None)
+ target_class = None
+ for action_class in DICTIFIABLE_ACTION_CLASSES:
+ if action_type == action_class.action_type:
+ target_class = action_class
+ if not target_class:
+ message = "Failed to recover action from dictionary - invalid action type specified %s." % action_type
+ raise Exception(message)
+ return target_class.from_dict(action_dict)
+
+
+class BasePathMapper(object):
+
+ def __init__(self, config):
+ action_type = config.get('action', DEFAULT_MAPPED_ACTION)
+ action_class = actions.get(action_type, None)
+ action_kwds = action_class.action_spec.copy()
+ for key, value in action_kwds.items():
+ if key in config:
+ action_kwds[key] = config[key]
+ elif value is REQUIRED_ACTION_KWD:
+ message_template = "action_type %s requires key word argument %s"
+ message = message_template % (action_type, key)
+ raise Exception(message)
+ self.action_type = action_type
+ self.action_kwds = action_kwds
+ path_types_str = config.get('path_types', "*defaults*")
+ path_types_str = path_types_str.replace("*defaults*", ",".join(ACTION_DEFAULT_PATH_TYPES))
+ path_types_str = path_types_str.replace("*any*", ",".join(ALL_PATH_TYPES))
+ self.path_types = path_types_str.split(",")
+ self.file_lister = FileLister(config)
+
+ def matches(self, path, path_type):
+ path_type_matches = path_type in self.path_types
+ return path_type_matches and self._path_matches(path)
+
+ def _extend_base_dict(self, **kwds):
+ base_dict = dict(
+ action=self.action_type,
+ path_types=",".join(self.path_types),
+ match_type=self.match_type
+ )
+ base_dict.update(self.file_lister.to_dict())
+ base_dict.update(self.action_kwds)
+ base_dict.update(**kwds)
+ return base_dict
+
+
+class PrefixPathMapper(BasePathMapper):
+ match_type = 'prefix'
+
+ def __init__(self, config):
+ super(PrefixPathMapper, self).__init__(config)
+ self.prefix_path = abspath(config['path'])
+
+ def _path_matches(self, path):
+ return path.startswith(self.prefix_path)
+
+ def to_pattern(self):
+ pattern_str = "(%s%s[^\s,\"\']+)" % (escape(self.prefix_path), escape(sep))
+ return compile(pattern_str)
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.prefix_path)
+
+
+class GlobPathMapper(BasePathMapper):
+ match_type = 'glob'
+
+ def __init__(self, config):
+ super(GlobPathMapper, self).__init__(config)
+ self.glob_path = config['path']
+
+ def _path_matches(self, path):
+ return fnmatch.fnmatch(path, self.glob_path)
+
+ def to_pattern(self):
+ return compile(fnmatch.translate(self.glob_path))
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.glob_path)
+
+
+class RegexPathMapper(BasePathMapper):
+ match_type = 'regex'
+
+ def __init__(self, config):
+ super(RegexPathMapper, self).__init__(config)
+ self.pattern_raw = config['path']
+ self.pattern = compile(self.pattern_raw)
+
+ def _path_matches(self, path):
+ return self.pattern.match(path) is not None
+
+ def to_pattern(self):
+ return self.pattern
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.pattern_raw)
+
+MAPPER_CLASSES = [PrefixPathMapper, GlobPathMapper, RegexPathMapper]
+MAPPER_CLASS_DICT = dict(map(lambda c: (c.match_type, c), MAPPER_CLASSES))
+
+
+def mappers_from_dicts(mapper_def_list):
+ return map(lambda m: __mappper_from_dict(m), mapper_def_list)
+
+
+def __mappper_from_dict(mapper_dict):
+ map_type = mapper_dict.get('match_type', DEFAULT_PATH_MAPPER_TYPE)
+ return MAPPER_CLASS_DICT[map_type](mapper_dict)
+
+
+class FileLister(object):
+
+ def __init__(self, config):
+ self.depth = int(config.get("depth", "0"))
+
+ def to_dict(self):
+ return dict(
+ depth=self.depth
+ )
+
+ def unstructured_map(self, path):
+ depth = self.depth
+ if self.depth == 0:
+ return {path: basename(path)}
+ else:
+ while depth > 0:
+ path = dirname(path)
+ depth -= 1
+ return dict([(join(path, f), f) for f in directory_files(path)])
+
+DEFAULT_FILE_LISTER = FileLister(dict(depth=0))
+
+ACTION_CLASSES = [
+ NoneAction,
+ RewriteAction,
+ TransferAction,
+ CopyAction,
+ RemoteCopyAction,
+ RemoteTransferAction,
+]
+actions = dict([(clazz.action_type, clazz) for clazz in ACTION_CLASSES])
+
+
+__all__ = [
+ FileActionMapper,
+ path_type,
+ from_dict,
+ MessageAction,
+ RemoteTransferAction, # For testing
+]
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/amqp_exchange.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange.py
@@ -0,0 +1,139 @@
+try:
+ import kombu
+ from kombu import pools
+except ImportError:
+ kombu = None
+
+import socket
+import logging
+import threading
+from time import sleep
+log = logging.getLogger(__name__)
+
+
+KOMBU_UNAVAILABLE = "Attempting to bind to AMQP message queue, but kombu dependency unavailable"
+
+DEFAULT_EXCHANGE_NAME = "pulsar"
+DEFAULT_EXCHANGE_TYPE = "direct"
+# Set timeout to periodically give up looking and check if polling should end.
+DEFAULT_TIMEOUT = 0.2
+DEFAULT_HEARTBEAT = 580
+
+DEFAULT_RECONNECT_CONSUMER_WAIT = 1
+DEFAULT_HEARTBEAT_WAIT = 1
+
+
+class PulsarExchange(object):
+ """ Utility for publishing and consuming structured Pulsar queues using kombu.
+ This is shared between the server and client - an exchange should be setup
+ for each manager (or in the case of the client, each manager one wished to
+ communicate with.)
+
+ Each Pulsar manager is defined solely by name in the scheme, so only one Pulsar
+ should target each AMQP endpoint or care should be taken that unique
+ manager names are used across Pulsar servers targetting same AMQP endpoint -
+ and in particular only one such Pulsar should define an default manager with
+ name _default_.
+ """
+
+ def __init__(
+ self,
+ url,
+ manager_name,
+ connect_ssl=None,
+ timeout=DEFAULT_TIMEOUT,
+ publish_kwds={},
+ ):
+ """
+ """
+ if not kombu:
+ raise Exception(KOMBU_UNAVAILABLE)
+ self.__url = url
+ self.__manager_name = manager_name
+ self.__connect_ssl = connect_ssl
+ self.__exchange = kombu.Exchange(DEFAULT_EXCHANGE_NAME, DEFAULT_EXCHANGE_TYPE)
+ self.__timeout = timeout
+ # Be sure to log message publishing failures.
+ if publish_kwds.get("retry", False):
+ if "retry_policy" not in publish_kwds:
+ publish_kwds["retry_policy"] = {}
+ if "errback" not in publish_kwds["retry_policy"]:
+ publish_kwds["retry_policy"]["errback"] = self.__publish_errback
+ self.__publish_kwds = publish_kwds
+
+ @property
+ def url(self):
+ return self.__url
+
+ def consume(self, queue_name, callback, check=True, connection_kwargs={}):
+ queue = self.__queue(queue_name)
+ log.debug("Consuming queue '%s'", queue)
+ while check:
+ heartbeat_thread = None
+ try:
+ with self.connection(self.__url, heartbeat=DEFAULT_HEARTBEAT, **connection_kwargs) as connection:
+ with kombu.Consumer(connection, queues=[queue], callbacks=[callback], accept=['json']):
+ heartbeat_thread = self.__start_heartbeat(queue_name, connection)
+ while check and connection.connected:
+ try:
+ connection.drain_events(timeout=self.__timeout)
+ except socket.timeout:
+ pass
+ except (IOError, socket.error), exc:
+ # In testing, errno is None
+ log.warning('Got %s, will retry: %s', exc.__class__.__name__, exc)
+ if heartbeat_thread:
+ heartbeat_thread.join()
+ sleep(DEFAULT_RECONNECT_CONSUMER_WAIT)
+
+ def heartbeat(self, connection):
+ log.debug('AMQP heartbeat thread alive')
+ while connection.connected:
+ connection.heartbeat_check()
+ sleep(DEFAULT_HEARTBEAT_WAIT)
+ log.debug('AMQP heartbeat thread exiting')
+
+ def publish(self, name, payload):
+ with self.connection(self.__url) as connection:
+ with pools.producers[connection].acquire() as producer:
+ key = self.__queue_name(name)
+ producer.publish(
+ payload,
+ serializer='json',
+ exchange=self.__exchange,
+ declare=[self.__exchange],
+ routing_key=key,
+ **self.__publish_kwds
+ )
+
+ def __publish_errback(self, exc, interval):
+ log.error("Connection error while publishing: %r", exc, exc_info=1)
+ log.info("Retrying in %s seconds", interval)
+
+ def connection(self, connection_string, **kwargs):
+ if "ssl" not in kwargs:
+ kwargs["ssl"] = self.__connect_ssl
+ return kombu.Connection(connection_string, **kwargs)
+
+ def __queue(self, name):
+ queue_name = self.__queue_name(name)
+ queue = kombu.Queue(queue_name, self.__exchange, routing_key=queue_name)
+ return queue
+
+ def __queue_name(self, name):
+ key_prefix = self.__key_prefix()
+ queue_name = '%s_%s' % (key_prefix, name)
+ return queue_name
+
+ def __key_prefix(self):
+ if self.__manager_name == "_default_":
+ key_prefix = "pulsar_"
+ else:
+ key_prefix = "pulsar_%s_" % self.__manager_name
+ return key_prefix
+
+ def __start_heartbeat(self, queue_name, connection):
+ thread_name = "consume-heartbeat-%s" % (self.__queue_name(queue_name))
+ thread = threading.Thread(name=thread_name, target=self.heartbeat, args=(connection,))
+ thread.start()
+ return thread
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/amqp_exchange_factory.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange_factory.py
@@ -0,0 +1,41 @@
+from .amqp_exchange import PulsarExchange
+from .util import filter_destination_params
+
+
+def get_exchange(url, manager_name, params):
+ connect_ssl = parse_amqp_connect_ssl_params(params)
+ exchange_kwds = dict(
+ manager_name=manager_name,
+ connect_ssl=connect_ssl,
+ publish_kwds=parse_amqp_publish_kwds(params)
+ )
+ timeout = params.get('amqp_consumer_timeout', False)
+ if timeout is not False:
+ exchange_kwds['timeout'] = timeout
+ exchange = PulsarExchange(url, **exchange_kwds)
+ return exchange
+
+
+def parse_amqp_connect_ssl_params(params):
+ ssl_params = filter_destination_params(params, "amqp_connect_ssl_")
+ if not ssl_params:
+ return
+
+ ssl = __import__('ssl')
+ if 'cert_reqs' in ssl_params:
+ value = ssl_params['cert_reqs']
+ ssl_params['cert_reqs'] = getattr(ssl, value.upper())
+ return ssl_params
+
+
+def parse_amqp_publish_kwds(params):
+ all_publish_params = filter_destination_params(params, "amqp_publish_")
+ retry_policy_params = {}
+ for key in all_publish_params.keys():
+ if key.startswith("retry_"):
+ value = all_publish_params[key]
+ retry_policy_params[key[len("retry_"):]] = value
+ del all_publish_params[key]
+ if retry_policy_params:
+ all_publish_params["retry_policy"] = retry_policy_params
+ return all_publish_params
This diff is so big that we needed to truncate the remainder.
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
2 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/8c569cffa967/
Changeset: 8c569cffa967
User: jmchilton
Date: 2014-06-20 07:28:36
Summary: Implement Pulsar job runners.
LWR runner and client remains in Galaxy as is and can continue to target old LWR server. But these should be considered deprecated and will likely be dropped at some point. The LWR documentaiton in job_conf.xml.sample_advanced has been replaced with Pulsar documentation to reflect this.
Pulsar runners will need to target a Pulsar server (now with a RESTful web interface - MQ option also available). Information on upgrading an LWR instance to pulsar can be found in the [Pulsar docs](http://pulsar.readthedocs.org/en/latest/#upgrading-from-the-lwr).
Three new job runners have been added to replace the LWR runner. The `PulsarLegacyJobRunner` more or less has all of the old defaults that the LWR runner had and this one should be easiest to get working for people who are porting over old LWR servers (and will likely be most compatible with remote Windows hosts).
The `PulsarRESTJobRunner` targets a remote Pulsar server over HTTP(S) but has newer standard configuration options such as rewriting parameters at tool stage by default, remote dependency evaluation by default, etc....
The `PulsarMQJobRunner` targets a remote Pulsar server via AMQP - and has the newer defaults of the RESTful runner as well as targetting the Galaxy job files API by default. The `url` runner parameter has been renamed `amqp_url` for clarity.
These newer runners improve parameter handling in other ways such as warning deployers when ignored parameters are supplied.
Affected #: 32 files
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 job_conf.xml.sample_advanced
--- a/job_conf.xml.sample_advanced
+++ b/job_conf.xml.sample_advanced
@@ -19,27 +19,30 @@
<!-- Override the $DRMAA_LIBRARY_PATH environment variable --><param id="drmaa_library_path">/sge/lib/libdrmaa.so</param></plugin>
- <plugin id="lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <!-- More information on LWR can be found at https://lwr.readthedocs.org -->
- <!-- Uncomment following line to use libcurl to perform HTTP calls (defaults to urllib) -->
+ <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
+ <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
+ <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <!-- Pulsar runners (see more at https://pulsar.readthedocs.org) -->
+ <plugin id="pulsar_rest" type="runner" load="galaxy.jobs.runners.pulsar:PulsarRESTJobRunner">
+ <!-- Allow optimized HTTP calls with libcurl (defaults to urllib) --><!-- <param id="transport">curl</param> -->
- <!-- *Experimental Caching*: Uncomment next parameters to enable
- caching and specify the number of caching threads to enable on Galaxy
- side. Likely will not work with newer features such as MQ support.
- If this is enabled be sure to specify a `file_cache_dir` in the remote
- LWR's main configuration file.
+
+ <!-- *Experimental Caching*: Next parameter enables caching.
+ Likely will not work with newer features such as MQ support.
+
+ If this is enabled be sure to specify a `file_cache_dir` in
+ the remote Pulsar's servers main configuration file.
--><!-- <param id="cache">True</param> -->
- <!-- <param id="transfer_threads">2</param> --></plugin>
- <plugin id="amqp_lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <param id="url">amqp://guest:guest@localhost:5672//</param>
- <!-- If using message queue driven LWR - the LWR will generally
- initiate file transfers so a the URL of this Galaxy instance
- must be configured. -->
+ <plugin id="pulsar_mq" type="runner" load="galaxy.jobs.runners.pulsar:PulsarMQJobRunner">
+ <!-- AMQP URL to connect to. -->
+ <param id="amqp_url">amqp://guest:guest@localhost:5672//</param>
+ <!-- URL remote Pulsar apps should transfer files to this Galaxy
+ instance to/from. --><param id="galaxy_url">http://localhost:8080</param>
- <!-- If multiple managers configured on the LWR, specify which one
- this plugin targets. -->
+ <!-- Pulsar job manager to communicate with (see Pulsar
+ docs for information on job managers). --><!-- <param id="manager">_default_</param> --><!-- The AMQP client can provide an SSL client certificate (e.g. for
validation), the following options configure that certificate
@@ -58,9 +61,17 @@
higher value (in seconds) (or `None` to use blocking connections). --><!-- <param id="amqp_consumer_timeout">None</param> --></plugin>
- <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
- <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
- <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <plugin id="pulsar_legacy" type="runner" load="galaxy.jobs.runners.pulsar:PulsarLegacyJobRunner">
+ <!-- Pulsar job runner with default parameters matching those
+ of old LWR job runner. If your Pulsar server is running on a
+ Windows machine for instance this runner should still be used.
+
+ These destinations still needs to target a Pulsar server,
+ older LWR plugins and destinations still work in Galaxy can
+ target LWR servers, but this support should be considered
+ deprecated and will disappear with a future release of Galaxy.
+ -->
+ </plugin></plugins><handlers default="handlers"><!-- Additional job handlers - the id should match the name of a
@@ -125,8 +136,8 @@
$galaxy_root:ro,$tool_directory:ro,$working_directory:rw,$default_file_path:ro
- If using the LWR, defaults will be even further restricted because the
- LWR will (by default) stage all needed inputs into the job's job_directory
+ If using the Pulsar, defaults will be even further restricted because the
+ Pulsar will (by default) stage all needed inputs into the job's job_directory
(so there is not need to allow the docker container to read all the
files - let alone write over them). Defaults in this case becomes:
@@ -135,7 +146,7 @@
Python string.Template is used to expand volumes and values $defaults,
$galaxy_root, $default_file_path, $tool_directory, $working_directory,
are available to all jobs and $job_directory is also available for
- LWR jobs.
+ Pulsar jobs.
--><!-- Control memory allocatable by docker container with following option:
-->
@@ -213,87 +224,71 @@
<!-- A destination that represents a method in the dynamic runner. --><param id="function">foo</param></destination>
- <destination id="secure_lwr" runner="lwr">
- <param id="url">https://windowshost.examle.com:8913/</param>
- <!-- If set, private_token must match token remote LWR server configured with. -->
+ <destination id="secure_pulsar_rest_dest" runner="pulsar_rest">
+ <param id="url">https://examle.com:8913/</param>
+ <!-- If set, private_token must match token in remote Pulsar's
+ configuration. --><param id="private_token">123456789changeme</param><!-- Uncomment the following statement to disable file staging (e.g.
- if there is a shared file system between Galaxy and the LWR
+ if there is a shared file system between Galaxy and the Pulsar
server). Alternatively action can be set to 'copy' - to replace
http transfers with file system copies, 'remote_transfer' to cause
- the lwr to initiate HTTP transfers instead of Galaxy, or
- 'remote_copy' to cause lwr to initiate file system copies.
+ the Pulsar to initiate HTTP transfers instead of Galaxy, or
+ 'remote_copy' to cause Pulsar to initiate file system copies.
If setting this to 'remote_transfer' be sure to specify a
'galaxy_url' attribute on the runner plugin above. --><!-- <param id="default_file_action">none</param> --><!-- The above option is just the default, the transfer behavior
none|copy|http can be configured on a per path basis via the
- following file. See lib/galaxy/jobs/runners/lwr_client/action_mapper.py
- for examples of how to configure this file. This is very beta
- and nature of file will likely change.
+ following file. See Pulsar documentation for more details and
+ examples.
-->
- <!-- <param id="file_action_config">file_actions.json</param> -->
- <!-- Uncomment following option to disable Galaxy tool dependency
- resolution and utilize remote LWR's configuraiton of tool
- dependency resolution instead (same options as Galaxy for
- dependency resolution are available in LWR). At a minimum
- the remote LWR server should define a tool_dependencies_dir in
- its `server.ini` configuration. The LWR will not attempt to
- stage dependencies - so ensure the the required galaxy or tool
- shed packages are available remotely (exact same tool shed
- installed changesets are required).
+ <!-- <param id="file_action_config">file_actions.yaml</param> -->
+ <!-- The non-legacy Pulsar runners will attempt to resolve Galaxy
+ dependencies remotely - to enable this set a tool_dependency_dir
+ in Pulsar's configuration (can work with all the same dependency
+ resolutions mechanisms as Galaxy - tool Shed installs, Galaxy
+ packages, etc...). To disable this behavior, set the follow parameter
+ to none. To generate the dependency resolution command locally
+ set the following parameter local.
-->
- <!-- <param id="dependency_resolution">remote</params> -->
- <!-- Traditionally, the LWR allow Galaxy to generate a command line
- as if it were going to run the command locally and then the
- LWR client rewrites it after the fact using regular
- expressions. Setting the following value to true causes the
- LWR runner to insert itself into the command line generation
- process and generate the correct command line from the get go.
- This will likely be the default someday - but requires a newer
- LWR version and is less well tested. -->
- <!-- <param id="rewrite_parameters">true</params> -->
+ <!-- <param id="dependency_resolution">none</params> --><!-- Uncomment following option to enable setting metadata on remote
- LWR server. The 'use_remote_datatypes' option is available for
+ Pulsar server. The 'use_remote_datatypes' option is available for
determining whether to use remotely configured datatypes or local
ones (both alternatives are a little brittle). --><!-- <param id="remote_metadata">true</param> --><!-- <param id="use_remote_datatypes">false</param> --><!-- <param id="remote_property_galaxy_home">/path/to/remote/galaxy-central</param> -->
- <!-- If remote LWR server is configured to run jobs as the real user,
+ <!-- If remote Pulsar server is configured to run jobs as the real user,
uncomment the following line to pass the current Galaxy user
along. --><!-- <param id="submit_user">$__user_name__</param> -->
- <!-- Various other submission parameters can be passed along to the LWR
- whose use will depend on the remote LWR's configured job manager.
+ <!-- Various other submission parameters can be passed along to the Pulsar
+ whose use will depend on the remote Pulsar's configured job manager.
For instance:
-->
- <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- Disable parameter rewriting and rewrite generated commands
+ instead. This may be required if remote host is Windows machine
+ but probably not otherwise.
+ -->
+ <!-- <param id="rewrite_parameters">false</params> --></destination>
- <destination id="amqp_lwr_dest" runner="amqp_lwr" >
- <!-- url and private_token are not valid when using MQ driven LWR. The plugin above
- determines which queue/manager to target and the underlying MQ server should be
- used to configure security.
- -->
- <!-- Traditionally, the LWR client sends request to LWR
- server to populate various system properties. This
+ <destination id="pulsar_mq_dest" runner="amqp_pulsar" >
+ <!-- The RESTful Pulsar client sends a request to Pulsar
+ to populate various system properties. This
extra step can be disabled and these calculated here
on client by uncommenting jobs_directory and
specifying any additional remote_property_ of
interest, this is not optional when using message
queues.
-->
- <param id="jobs_directory">/path/to/remote/lwr/lwr_staging/</param>
- <!-- Default the LWR send files to and pull files from Galaxy when
- using message queues (in the more traditional mode Galaxy sends
- files to and pull files from the LWR - this is obviously less
- appropriate when using a message queue).
-
- The default_file_action currently requires pycurl be available
- to Galaxy (presumably in its virtualenv). Making this dependency
- optional is an open task.
+ <param id="jobs_directory">/path/to/remote/pulsar/files/staging/</param>
+ <!-- Otherwise MQ and Legacy pulsar destinations can be supplied
+ all the same destination parameters as the RESTful client documented
+ above (though url and private_token are ignored when using a MQ).
-->
- <param id="default_file_action">remote_transfer</param></destination><destination id="ssh_torque" runner="cli"><param id="shell_plugin">SecureShell</param>
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/jobs/runners/pulsar.py
--- /dev/null
+++ b/lib/galaxy/jobs/runners/pulsar.py
@@ -0,0 +1,707 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+
+import logging
+
+from galaxy import model
+from galaxy.jobs.runners import AsynchronousJobState, AsynchronousJobRunner
+from galaxy.jobs import ComputeEnvironment
+from galaxy.jobs import JobDestination
+from galaxy.jobs.command_factory import build_command
+from galaxy.tools.deps import dependencies
+from galaxy.util import string_as_bool_or_none
+from galaxy.util.bunch import Bunch
+from galaxy.util import specs
+
+import errno
+from time import sleep
+import os
+
+from pulsar.client import build_client_manager
+from pulsar.client import url_to_destination_params
+from pulsar.client import finish_job as pulsar_finish_job
+from pulsar.client import submit_job as pulsar_submit_job
+from pulsar.client import ClientJobDescription
+from pulsar.client import PulsarOutputs
+from pulsar.client import ClientOutputs
+from pulsar.client import PathMapper
+
+log = logging.getLogger( __name__ )
+
+__all__ = [ 'PulsarLegacyJobRunner', 'PulsarRESTJobRunner', 'PulsarMQJobRunner' ]
+
+NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE = "Pulsar misconfiguration - Pulsar client configured to set metadata remotely, but remote Pulsar isn't properly configured with a galaxy_home directory."
+NO_REMOTE_DATATYPES_CONFIG = "Pulsar client is configured to use remote datatypes configuration when setting metadata externally, but Pulsar is not configured with this information. Defaulting to datatypes_conf.xml."
+GENERIC_REMOTE_ERROR = "Failed to communicate with remote job server."
+
+# Is there a good way to infer some default for this? Can only use
+# url_for from web threads. https://gist.github.com/jmchilton/9098762
+DEFAULT_GALAXY_URL = "http://localhost:8080"
+
+PULSAR_PARAM_SPECS = dict(
+ transport=dict(
+ map=specs.to_str_or_none,
+ valid=specs.is_in("urllib", "curl", None),
+ default=None
+ ),
+ cache=dict(
+ map=specs.to_bool_or_none,
+ default=None,
+ ),
+ amqp_url=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ galaxy_url=dict(
+ map=specs.to_str_or_none,
+ default=DEFAULT_GALAXY_URL,
+ ),
+ manager=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_consumer_timeout=dict(
+ map=lambda val: None if val == "None" else float(val),
+ default=None,
+ ),
+ amqp_connect_ssl_ca_certs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_keyfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_certfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_cert_reqs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Producer.…
+ amqp_publish_retry=dict(
+ map=specs.to_bool,
+ default=False,
+ ),
+ amqp_publish_priority=dict(
+ map=int,
+ valid=lambda x: 0 <= x and x <= 9,
+ default=0,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Exchange.…
+ amqp_publish_delivery_mode=dict(
+ map=str,
+ valid=specs.is_in("transient", "persistent"),
+ default="persistent",
+ ),
+ amqp_publish_retry_max_retries=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_start=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_step=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_max=dict(
+ map=int,
+ default=None,
+ ),
+)
+
+
+PARAMETER_SPECIFICATION_REQUIRED = object()
+PARAMETER_SPECIFICATION_IGNORED = object()
+
+
+class PulsarJobRunner( AsynchronousJobRunner ):
+ """
+ Pulsar Job Runner
+ """
+ runner_name = "PulsarJobRunner"
+
+ def __init__( self, app, nworkers, **kwds ):
+ """Start the job runner """
+ super( PulsarJobRunner, self ).__init__( app, nworkers, runner_param_specs=PULSAR_PARAM_SPECS, **kwds )
+ self._init_worker_threads()
+ galaxy_url = self.runner_params.galaxy_url
+ if galaxy_url:
+ galaxy_url = galaxy_url.rstrip("/")
+ self.galaxy_url = galaxy_url
+ self.__init_client_manager()
+ self._monitor()
+
+ def _monitor( self ):
+ # Extension point allow MQ variant to setup callback instead
+ self._init_monitor_thread()
+
+ def __init_client_manager( self ):
+ client_manager_kwargs = {}
+ for kwd in 'manager', 'cache', 'transport':
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ for kwd in self.runner_params.keys():
+ if kwd.startswith( 'amqp_' ):
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ self.client_manager = build_client_manager(**client_manager_kwargs)
+
+ def url_to_destination( self, url ):
+ """Convert a legacy URL to a job destination"""
+ return JobDestination( runner="pulsar", params=url_to_destination_params( url ) )
+
+ def check_watched_item(self, job_state):
+ try:
+ client = self.get_client_from_state(job_state)
+ status = client.get_status()
+ except Exception:
+ # An orphaned job was put into the queue at app startup, so remote server went down
+ # either way we are done I guess.
+ self.mark_as_finished(job_state)
+ return None
+ job_state = self._update_job_state_for_status(job_state, status)
+ return job_state
+
+ def _update_job_state_for_status(self, job_state, pulsar_status):
+ if pulsar_status == "complete":
+ self.mark_as_finished(job_state)
+ return None
+ if pulsar_status == "failed":
+ self.fail_job(job_state)
+ return None
+ if pulsar_status == "running" and not job_state.running:
+ job_state.running = True
+ job_state.job_wrapper.change_state( model.Job.states.RUNNING )
+ return job_state
+
+ def queue_job(self, job_wrapper):
+ job_destination = job_wrapper.job_destination
+ self._populate_parameter_defaults( job_destination )
+
+ command_line, client, remote_job_config, compute_environment = self.__prepare_job( job_wrapper, job_destination )
+
+ if not command_line:
+ return
+
+ try:
+ dependencies_description = PulsarJobRunner.__dependencies_description( client, job_wrapper )
+ rewrite_paths = not PulsarJobRunner.__rewrite_parameters( client )
+ unstructured_path_rewrites = {}
+ if compute_environment:
+ unstructured_path_rewrites = compute_environment.unstructured_path_rewrites
+
+ client_job_description = ClientJobDescription(
+ command_line=command_line,
+ input_files=self.get_input_files(job_wrapper),
+ client_outputs=self.__client_outputs(client, job_wrapper),
+ working_directory=job_wrapper.working_directory,
+ tool=job_wrapper.tool,
+ config_files=job_wrapper.extra_filenames,
+ dependencies_description=dependencies_description,
+ env=client.env,
+ rewrite_paths=rewrite_paths,
+ arbitrary_files=unstructured_path_rewrites,
+ )
+ job_id = pulsar_submit_job(client, client_job_description, remote_job_config)
+ log.info("Pulsar job submitted with job_id %s" % job_id)
+ job_wrapper.set_job_destination( job_destination, job_id )
+ job_wrapper.change_state( model.Job.states.QUEUED )
+ except Exception:
+ job_wrapper.fail( "failure running job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+ return
+
+ pulsar_job_state = AsynchronousJobState()
+ pulsar_job_state.job_wrapper = job_wrapper
+ pulsar_job_state.job_id = job_id
+ pulsar_job_state.old_state = True
+ pulsar_job_state.running = False
+ pulsar_job_state.job_destination = job_destination
+ self.monitor_job(pulsar_job_state)
+
+ def __prepare_job(self, job_wrapper, job_destination):
+ """ Build command-line and Pulsar client for this job. """
+ command_line = None
+ client = None
+ remote_job_config = None
+ compute_environment = None
+ try:
+ client = self.get_client_from_wrapper(job_wrapper)
+ tool = job_wrapper.tool
+ remote_job_config = client.setup(tool.id, tool.version)
+ rewrite_parameters = PulsarJobRunner.__rewrite_parameters( client )
+ prepare_kwds = {}
+ if rewrite_parameters:
+ compute_environment = PulsarComputeEnvironment( client, job_wrapper, remote_job_config )
+ prepare_kwds[ 'compute_environment' ] = compute_environment
+ job_wrapper.prepare( **prepare_kwds )
+ self.__prepare_input_files_locally(job_wrapper)
+ remote_metadata = PulsarJobRunner.__remote_metadata( client )
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( client )
+ metadata_kwds = self.__build_metadata_configuration(client, job_wrapper, remote_metadata, remote_job_config)
+ remote_command_params = dict(
+ working_directory=remote_job_config['working_directory'],
+ metadata_kwds=metadata_kwds,
+ dependency_resolution=dependency_resolution,
+ )
+ remote_working_directory = remote_job_config['working_directory']
+ # TODO: Following defs work for Pulsar, always worked for Pulsar but should be
+ # calculated at some other level.
+ remote_job_directory = os.path.abspath(os.path.join(remote_working_directory, os.path.pardir))
+ remote_tool_directory = os.path.abspath(os.path.join(remote_job_directory, "tool_files"))
+ container = self._find_container(
+ job_wrapper,
+ compute_working_directory=remote_working_directory,
+ compute_tool_directory=remote_tool_directory,
+ compute_job_directory=remote_job_directory,
+ )
+ command_line = build_command(
+ self,
+ job_wrapper=job_wrapper,
+ container=container,
+ include_metadata=remote_metadata,
+ include_work_dir_outputs=False,
+ remote_command_params=remote_command_params,
+ )
+ except Exception:
+ job_wrapper.fail( "failure preparing job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+
+ # If we were able to get a command line, run the job
+ if not command_line:
+ job_wrapper.finish( '', '' )
+
+ return command_line, client, remote_job_config, compute_environment
+
+ def __prepare_input_files_locally(self, job_wrapper):
+ """Run task splitting commands locally."""
+ prepare_input_files_cmds = getattr(job_wrapper, 'prepare_input_files_cmds', None)
+ if prepare_input_files_cmds is not None:
+ for cmd in prepare_input_files_cmds: # run the commands to stage the input files
+ if 0 != os.system(cmd):
+ raise Exception('Error running file staging command: %s' % cmd)
+ job_wrapper.prepare_input_files_cmds = None # prevent them from being used in-line
+
+ def _populate_parameter_defaults( self, job_destination ):
+ updated = False
+ params = job_destination.params
+ for key, value in self.destination_defaults.iteritems():
+ if key in params:
+ if value is PARAMETER_SPECIFICATION_IGNORED:
+ log.warn( "Pulsar runner in selected configuration ignores parameter %s" % key )
+ continue
+ #if self.runner_params.get( key, None ):
+ # # Let plugin define defaults for some parameters -
+ # # for instance that way jobs_directory can be
+ # # configured next to AMQP url (where it belongs).
+ # params[ key ] = self.runner_params[ key ]
+ # continue
+
+ if not value:
+ continue
+
+ if value is PARAMETER_SPECIFICATION_REQUIRED:
+ raise Exception( "Pulsar destination does not define required parameter %s" % key )
+ elif value is not PARAMETER_SPECIFICATION_IGNORED:
+ params[ key ] = value
+ updated = True
+ return updated
+
+ def get_output_files(self, job_wrapper):
+ output_paths = job_wrapper.get_output_fnames()
+ return [ str( o ) for o in output_paths ] # Force job_path from DatasetPath objects.
+
+ def get_input_files(self, job_wrapper):
+ input_paths = job_wrapper.get_input_paths()
+ return [ str( i ) for i in input_paths ] # Force job_path from DatasetPath objects.
+
+ def get_client_from_wrapper(self, job_wrapper):
+ job_id = job_wrapper.job_id
+ if hasattr(job_wrapper, 'task_id'):
+ job_id = "%s_%s" % (job_id, job_wrapper.task_id)
+ params = job_wrapper.job_destination.params.copy()
+ for key, value in params.iteritems():
+ if value:
+ params[key] = model.User.expand_user_properties( job_wrapper.get_job().user, value )
+
+ env = getattr( job_wrapper.job_destination, "env", [] )
+ return self.get_client( params, job_id, env )
+
+ def get_client_from_state(self, job_state):
+ job_destination_params = job_state.job_destination.params
+ job_id = job_state.job_id
+ return self.get_client( job_destination_params, job_id )
+
+ def get_client( self, job_destination_params, job_id, env=[] ):
+ # Cannot use url_for outside of web thread.
+ #files_endpoint = url_for( controller="job_files", job_id=encoded_job_id )
+
+ encoded_job_id = self.app.security.encode_id(job_id)
+ job_key = self.app.security.encode_id( job_id, kind="jobs_files" )
+ files_endpoint = "%s/api/jobs/%s/files?job_key=%s" % (
+ self.galaxy_url,
+ encoded_job_id,
+ job_key
+ )
+ get_client_kwds = dict(
+ job_id=str( job_id ),
+ files_endpoint=files_endpoint,
+ env=env
+ )
+ return self.client_manager.get_client( job_destination_params, **get_client_kwds )
+
+ def finish_job( self, job_state ):
+ stderr = stdout = ''
+ job_wrapper = job_state.job_wrapper
+ try:
+ client = self.get_client_from_state(job_state)
+ run_results = client.full_status()
+ remote_working_directory = run_results.get("working_directory", None)
+ stdout = run_results.get('stdout', '')
+ stderr = run_results.get('stderr', '')
+ exit_code = run_results.get('returncode', None)
+ pulsar_outputs = PulsarOutputs.from_status_response(run_results)
+ # Use Pulsar client code to transfer/copy files back
+ # and cleanup job if needed.
+ completed_normally = \
+ job_wrapper.get_state() not in [ model.Job.states.ERROR, model.Job.states.DELETED ]
+ cleanup_job = self.app.config.cleanup_job
+ client_outputs = self.__client_outputs(client, job_wrapper)
+ finish_args = dict( client=client,
+ job_completed_normally=completed_normally,
+ cleanup_job=cleanup_job,
+ client_outputs=client_outputs,
+ pulsar_outputs=pulsar_outputs )
+ failed = pulsar_finish_job( **finish_args )
+ if failed:
+ job_wrapper.fail("Failed to find or download one or more job outputs from remote server.", exception=True)
+ except Exception:
+ message = GENERIC_REMOTE_ERROR
+ job_wrapper.fail( message, exception=True )
+ log.exception("failure finishing job %d" % job_wrapper.job_id)
+ return
+ if not PulsarJobRunner.__remote_metadata( client ):
+ self._handle_metadata_externally( job_wrapper, resolve_requirements=True )
+ # Finish the job
+ try:
+ job_wrapper.finish(
+ stdout,
+ stderr,
+ exit_code,
+ remote_working_directory=remote_working_directory
+ )
+ except Exception:
+ log.exception("Job wrapper finish method failed")
+ job_wrapper.fail("Unable to finish job", exception=True)
+
+ def fail_job( self, job_state ):
+ """
+ Seperated out so we can use the worker threads for it.
+ """
+ self.stop_job( self.sa_session.query( self.app.model.Job ).get( job_state.job_wrapper.job_id ) )
+ job_state.job_wrapper.fail( getattr( job_state, "fail_message", GENERIC_REMOTE_ERROR ) )
+
+ def check_pid( self, pid ):
+ try:
+ os.kill( pid, 0 )
+ return True
+ except OSError, e:
+ if e.errno == errno.ESRCH:
+ log.debug( "check_pid(): PID %d is dead" % pid )
+ else:
+ log.warning( "check_pid(): Got errno %s when attempting to check PID %d: %s" % ( errno.errorcode[e.errno], pid, e.strerror ) )
+ return False
+
+ def stop_job( self, job ):
+ #if our local job has JobExternalOutputMetadata associated, then our primary job has to have already finished
+ job_ext_output_metadata = job.get_external_output_metadata()
+ if job_ext_output_metadata:
+ pid = job_ext_output_metadata[0].job_runner_external_pid # every JobExternalOutputMetadata has a pid set, we just need to take from one of them
+ if pid in [ None, '' ]:
+ log.warning( "stop_job(): %s: no PID in database for job, unable to stop" % job.id )
+ return
+ pid = int( pid )
+ if not self.check_pid( pid ):
+ log.warning( "stop_job(): %s: PID %d was already dead or can't be signaled" % ( job.id, pid ) )
+ return
+ for sig in [ 15, 9 ]:
+ try:
+ os.killpg( pid, sig )
+ except OSError, e:
+ log.warning( "stop_job(): %s: Got errno %s when attempting to signal %d to PID %d: %s" % ( job.id, errno.errorcode[e.errno], sig, pid, e.strerror ) )
+ return # give up
+ sleep( 2 )
+ if not self.check_pid( pid ):
+ log.debug( "stop_job(): %s: PID %d successfully killed with signal %d" % ( job.id, pid, sig ) )
+ return
+ else:
+ log.warning( "stop_job(): %s: PID %d refuses to die after signaling TERM/KILL" % ( job.id, pid ) )
+ else:
+ # Remote kill
+ pulsar_url = job.job_runner_name
+ job_id = job.job_runner_external_id
+ log.debug("Attempt remote Pulsar kill of job with url %s and id %s" % (pulsar_url, job_id))
+ client = self.get_client(job.destination_params, job_id)
+ client.kill()
+
+ def recover( self, job, job_wrapper ):
+ """Recovers jobs stuck in the queued/running state when Galaxy started"""
+ job_state = self._job_state( job, job_wrapper )
+ job_wrapper.command_line = job.get_command_line()
+ state = job.get_state()
+ if state in [model.Job.states.RUNNING, model.Job.states.QUEUED]:
+ log.debug( "(Pulsar/%s) is still in running state, adding to the Pulsar queue" % ( job.get_id()) )
+ job_state.old_state = True
+ job_state.running = state == model.Job.states.RUNNING
+ self.monitor_queue.put( job_state )
+
+ def shutdown( self ):
+ super( PulsarJobRunner, self ).shutdown()
+ self.client_manager.shutdown()
+
+ def _job_state( self, job, job_wrapper ):
+ job_state = AsynchronousJobState()
+ # TODO: Determine why this is set when using normal message queue updates
+ # but not CLI submitted MQ updates...
+ raw_job_id = job.get_job_runner_external_id() or job_wrapper.job_id
+ job_state.job_id = str( raw_job_id )
+ job_state.runner_url = job_wrapper.get_job_runner_url()
+ job_state.job_destination = job_wrapper.job_destination
+ job_state.job_wrapper = job_wrapper
+ return job_state
+
+ def __client_outputs( self, client, job_wrapper ):
+ work_dir_outputs = self.get_work_dir_outputs( job_wrapper )
+ output_files = self.get_output_files( job_wrapper )
+ client_outputs = ClientOutputs(
+ working_directory=job_wrapper.working_directory,
+ work_dir_outputs=work_dir_outputs,
+ output_files=output_files,
+ version_file=job_wrapper.get_version_string_path(),
+ )
+ return client_outputs
+
+ @staticmethod
+ def __dependencies_description( pulsar_client, job_wrapper ):
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( pulsar_client )
+ remote_dependency_resolution = dependency_resolution == "remote"
+ if not remote_dependency_resolution:
+ return None
+ requirements = job_wrapper.tool.requirements or []
+ installed_tool_dependencies = job_wrapper.tool.installed_tool_dependencies or []
+ return dependencies.DependenciesDescription(
+ requirements=requirements,
+ installed_tool_dependencies=installed_tool_dependencies,
+ )
+
+ @staticmethod
+ def __dependency_resolution( pulsar_client ):
+ dependency_resolution = pulsar_client.destination_params.get( "dependency_resolution", "local" )
+ if dependency_resolution not in ["none", "local", "remote"]:
+ raise Exception("Unknown dependency_resolution value encountered %s" % dependency_resolution)
+ return dependency_resolution
+
+ @staticmethod
+ def __remote_metadata( pulsar_client ):
+ remote_metadata = string_as_bool_or_none( pulsar_client.destination_params.get( "remote_metadata", False ) )
+ return remote_metadata
+
+ @staticmethod
+ def __use_remote_datatypes_conf( pulsar_client ):
+ """ When setting remote metadata, use integrated datatypes from this
+ Galaxy instance or use the datatypes config configured via the remote
+ Pulsar.
+
+ Both options are broken in different ways for same reason - datatypes
+ may not match. One can push the local datatypes config to the remote
+ server - but there is no guarentee these datatypes will be defined
+ there. Alternatively, one can use the remote datatype config - but
+ there is no guarentee that it will contain all the datatypes available
+ to this Galaxy.
+ """
+ use_remote_datatypes = string_as_bool_or_none( pulsar_client.destination_params.get( "use_remote_datatypes", False ) )
+ return use_remote_datatypes
+
+ @staticmethod
+ def __rewrite_parameters( pulsar_client ):
+ return string_as_bool_or_none( pulsar_client.destination_params.get( "rewrite_parameters", False ) ) or False
+
+ def __build_metadata_configuration(self, client, job_wrapper, remote_metadata, remote_job_config):
+ metadata_kwds = {}
+ if remote_metadata:
+ remote_system_properties = remote_job_config.get("system_properties", {})
+ remote_galaxy_home = remote_system_properties.get("galaxy_home", None)
+ if not remote_galaxy_home:
+ raise Exception(NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE)
+ metadata_kwds['exec_dir'] = remote_galaxy_home
+ outputs_directory = remote_job_config['outputs_directory']
+ configs_directory = remote_job_config['configs_directory']
+ working_directory = remote_job_config['working_directory']
+ # For metadata calculation, we need to build a list of of output
+ # file objects with real path indicating location on Galaxy server
+ # and false path indicating location on compute server. Since the
+ # Pulsar disables from_work_dir copying as part of the job command
+ # line we need to take the list of output locations on the Pulsar
+ # server (produced by self.get_output_files(job_wrapper)) and for
+ # each work_dir output substitute the effective path on the Pulsar
+ # server relative to the remote working directory as the
+ # false_path to send the metadata command generation module.
+ work_dir_outputs = self.get_work_dir_outputs(job_wrapper, job_working_directory=working_directory)
+ outputs = [Bunch(false_path=os.path.join(outputs_directory, os.path.basename(path)), real_path=path) for path in self.get_output_files(job_wrapper)]
+ for output in outputs:
+ for pulsar_workdir_path, real_path in work_dir_outputs:
+ if real_path == output.real_path:
+ output.false_path = pulsar_workdir_path
+ metadata_kwds['output_fnames'] = outputs
+ metadata_kwds['compute_tmp_dir'] = working_directory
+ metadata_kwds['config_root'] = remote_galaxy_home
+ default_config_file = os.path.join(remote_galaxy_home, 'universe_wsgi.ini')
+ metadata_kwds['config_file'] = remote_system_properties.get('galaxy_config_file', default_config_file)
+ metadata_kwds['dataset_files_path'] = remote_system_properties.get('galaxy_dataset_files_path', None)
+ if PulsarJobRunner.__use_remote_datatypes_conf( client ):
+ remote_datatypes_config = remote_system_properties.get('galaxy_datatypes_config_file', None)
+ if not remote_datatypes_config:
+ log.warn(NO_REMOTE_DATATYPES_CONFIG)
+ remote_datatypes_config = os.path.join(remote_galaxy_home, 'datatypes_conf.xml')
+ metadata_kwds['datatypes_config'] = remote_datatypes_config
+ else:
+ integrates_datatypes_config = self.app.datatypes_registry.integrated_datatypes_configs
+ # Ensure this file gets pushed out to the remote config dir.
+ job_wrapper.extra_filenames.append(integrates_datatypes_config)
+
+ metadata_kwds['datatypes_config'] = os.path.join(configs_directory, os.path.basename(integrates_datatypes_config))
+ return metadata_kwds
+
+
+class PulsarLegacyJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ rewrite_parameters="false",
+ dependency_resolution="local",
+ )
+
+
+class PulsarMQJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="remote_transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ jobs_directory=PARAMETER_SPECIFICATION_REQUIRED,
+ url=PARAMETER_SPECIFICATION_IGNORED,
+ private_token=PARAMETER_SPECIFICATION_IGNORED
+ )
+
+ def _monitor( self ):
+ # This is a message queue driven runner, don't monitor
+ # just setup required callback.
+ self.client_manager.ensure_has_status_update_callback(self.__async_update)
+
+ def __async_update( self, full_status ):
+ job_id = None
+ try:
+ job_id = full_status[ "job_id" ]
+ job, job_wrapper = self.app.job_manager.job_handler.job_queue.job_pair_for_id( job_id )
+ job_state = self._job_state( job, job_wrapper )
+ self._update_job_state_for_status(job_state, full_status[ "status" ] )
+ except Exception:
+ log.exception( "Failed to update Pulsar job status for job_id %s" % job_id )
+ raise
+ # Nothing else to do? - Attempt to fail the job?
+
+
+class PulsarRESTJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ url=PARAMETER_SPECIFICATION_REQUIRED,
+ )
+
+
+class PulsarComputeEnvironment( ComputeEnvironment ):
+
+ def __init__( self, pulsar_client, job_wrapper, remote_job_config ):
+ self.pulsar_client = pulsar_client
+ self.job_wrapper = job_wrapper
+ self.local_path_config = job_wrapper.default_compute_environment()
+ self.unstructured_path_rewrites = {}
+ # job_wrapper.prepare is going to expunge the job backing the following
+ # computations, so precalculate these paths.
+ self._wrapper_input_paths = self.local_path_config.input_paths()
+ self._wrapper_output_paths = self.local_path_config.output_paths()
+ self.path_mapper = PathMapper(pulsar_client, remote_job_config, self.local_path_config.working_directory())
+ self._config_directory = remote_job_config[ "configs_directory" ]
+ self._working_directory = remote_job_config[ "working_directory" ]
+ self._sep = remote_job_config[ "system_properties" ][ "separator" ]
+ self._tool_dir = remote_job_config[ "tools_directory" ]
+ version_path = self.local_path_config.version_path()
+ new_version_path = self.path_mapper.remote_version_path_rewrite(version_path)
+ if new_version_path:
+ version_path = new_version_path
+ self._version_path = version_path
+
+ def output_paths( self ):
+ local_output_paths = self._wrapper_output_paths
+
+ results = []
+ for local_output_path in local_output_paths:
+ wrapper_path = str( local_output_path )
+ remote_path = self.path_mapper.remote_output_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_output_path, remote_path ) )
+ return results
+
+ def input_paths( self ):
+ local_input_paths = self._wrapper_input_paths
+
+ results = []
+ for local_input_path in local_input_paths:
+ wrapper_path = str( local_input_path )
+ # This will over-copy in some cases. For instance in the case of task
+ # splitting, this input will be copied even though only the work dir
+ # input will actually be used.
+ remote_path = self.path_mapper.remote_input_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_input_path, remote_path ) )
+ return results
+
+ def _dataset_path( self, local_dataset_path, remote_path ):
+ remote_extra_files_path = None
+ if remote_path:
+ remote_extra_files_path = "%s_files" % remote_path[ 0:-len( ".dat" ) ]
+ return local_dataset_path.with_path_for_job( remote_path, remote_extra_files_path )
+
+ def working_directory( self ):
+ return self._working_directory
+
+ def config_directory( self ):
+ return self._config_directory
+
+ def new_file_path( self ):
+ return self.working_directory() # Problems with doing this?
+
+ def sep( self ):
+ return self._sep
+
+ def version_path( self ):
+ return self._version_path
+
+ def rewriter( self, parameter_value ):
+ unstructured_path_rewrites = self.unstructured_path_rewrites
+ if parameter_value in unstructured_path_rewrites:
+ # Path previously mapped, use previous mapping.
+ return unstructured_path_rewrites[ parameter_value ]
+ if parameter_value in unstructured_path_rewrites.itervalues():
+ # Path is a rewritten remote path (this might never occur,
+ # consider dropping check...)
+ return parameter_value
+
+ rewrite, new_unstructured_path_rewrites = self.path_mapper.check_for_arbitrary_rewrite( parameter_value )
+ if rewrite:
+ unstructured_path_rewrites.update(new_unstructured_path_rewrites)
+ return rewrite
+ else:
+ # Did need to rewrite, use original path or value.
+ return parameter_value
+
+ def unstructured_path_rewriter( self ):
+ return self.rewriter
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/jobs/runners/util/__init__.py
--- a/lib/galaxy/jobs/runners/util/__init__.py
+++ b/lib/galaxy/jobs/runners/util/__init__.py
@@ -1,7 +1,7 @@
"""
This module and its submodules contains utilities for running external
processes and interfacing with job managers. This module should contain
-functionality shared between Galaxy and the LWR.
+functionality shared between Galaxy and the Pulsar.
"""
from galaxy.util.bunch import Bunch
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/jobs/runners/util/cli/factory.py
--- a/lib/galaxy/jobs/runners/util/cli/factory.py
+++ b/lib/galaxy/jobs/runners/util/cli/factory.py
@@ -5,7 +5,7 @@
)
code_dir = 'lib'
except ImportError:
- from lwr.managers.util.cli import (
+ from pulsar.managers.util.cli import (
CliInterface,
split_params
)
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/jobs/runners/util/cli/job/slurm.py
--- a/lib/galaxy/jobs/runners/util/cli/job/slurm.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/slurm.py
@@ -5,7 +5,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/jobs/runners/util/cli/job/torque.py
--- a/lib/galaxy/jobs/runners/util/cli/job/torque.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/torque.py
@@ -7,7 +7,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/objectstore/__init__.py
--- a/lib/galaxy/objectstore/__init__.py
+++ b/lib/galaxy/objectstore/__init__.py
@@ -623,9 +623,9 @@
elif store == 'irods':
from .rods import IRODSObjectStore
return IRODSObjectStore(config=config, config_xml=config_xml)
- elif store == 'lwr':
- from .lwr import LwrObjectStore
- return LwrObjectStore(config=config, config_xml=config_xml)
+ elif store == 'pulsar':
+ from .pulsar import PulsarObjectStore
+ return PulsarObjectStore(config=config, config_xml=config_xml)
else:
log.error("Unrecognized object store definition: {0}".format(store))
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/objectstore/lwr.py
--- a/lib/galaxy/objectstore/lwr.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from __future__ import absolute_import # Need to import lwr_client absolutely.
-from ..objectstore import ObjectStore
-try:
- from galaxy.jobs.runners.lwr_client.manager import ObjectStoreClientManager
-except ImportError:
- from lwr.lwr_client.manager import ObjectStoreClientManager
-
-
-class LwrObjectStore(ObjectStore):
- """
- Object store implementation that delegates to a remote LWR server.
-
- This may be more aspirational than practical for now, it would be good to
- Galaxy to a point that a handler thread could be setup that doesn't attempt
- to access the disk files returned by a (this) object store - just passing
- them along to the LWR unmodified. That modification - along with this
- implementation and LWR job destinations would then allow Galaxy to fully
- manage jobs on remote servers with completely different mount points.
-
- This implementation should be considered beta and may be dropped from
- Galaxy at some future point or significantly modified.
- """
-
- def __init__(self, config, config_xml):
- self.lwr_client = self.__build_lwr_client(config_xml)
-
- def exists(self, obj, **kwds):
- return self.lwr_client.exists(**self.__build_kwds(obj, **kwds))
-
- def file_ready(self, obj, **kwds):
- return self.lwr_client.file_ready(**self.__build_kwds(obj, **kwds))
-
- def create(self, obj, **kwds):
- return self.lwr_client.create(**self.__build_kwds(obj, **kwds))
-
- def empty(self, obj, **kwds):
- return self.lwr_client.empty(**self.__build_kwds(obj, **kwds))
-
- def size(self, obj, **kwds):
- return self.lwr_client.size(**self.__build_kwds(obj, **kwds))
-
- def delete(self, obj, **kwds):
- return self.lwr_client.delete(**self.__build_kwds(obj, **kwds))
-
- # TODO: Optimize get_data.
- def get_data(self, obj, **kwds):
- return self.lwr_client.get_data(**self.__build_kwds(obj, **kwds))
-
- def get_filename(self, obj, **kwds):
- return self.lwr_client.get_filename(**self.__build_kwds(obj, **kwds))
-
- def update_from_file(self, obj, **kwds):
- return self.lwr_client.update_from_file(**self.__build_kwds(obj, **kwds))
-
- def get_store_usage_percent(self):
- return self.lwr_client.get_store_usage_percent()
-
- def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
- return None
-
- def __build_kwds(self, obj, **kwds):
- kwds['object_id'] = obj.id
- return kwds
- pass
-
- def __build_lwr_client(self, config_xml):
- url = config_xml.get("url")
- private_token = config_xml.get("private_token", None)
- transport = config_xml.get("transport", None)
- manager_options = dict(transport=transport)
- client_options = dict(url=url, private_token=private_token)
- lwr_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
- return lwr_client
-
- def shutdown(self):
- pass
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/objectstore/pulsar.py
--- /dev/null
+++ b/lib/galaxy/objectstore/pulsar.py
@@ -0,0 +1,73 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+from ..objectstore import ObjectStore
+from pulsar.client.manager import ObjectStoreClientManager
+
+
+class PulsarObjectStore(ObjectStore):
+ """
+ Object store implementation that delegates to a remote Pulsar server.
+
+ This may be more aspirational than practical for now, it would be good to
+ Galaxy to a point that a handler thread could be setup that doesn't attempt
+ to access the disk files returned by a (this) object store - just passing
+ them along to the Pulsar unmodified. That modification - along with this
+ implementation and Pulsar job destinations would then allow Galaxy to fully
+ manage jobs on remote servers with completely different mount points.
+
+ This implementation should be considered beta and may be dropped from
+ Galaxy at some future point or significantly modified.
+ """
+
+ def __init__(self, config, config_xml):
+ self.pulsar_client = self.__build_pulsar_client(config_xml)
+
+ def exists(self, obj, **kwds):
+ return self.pulsar_client.exists(**self.__build_kwds(obj, **kwds))
+
+ def file_ready(self, obj, **kwds):
+ return self.pulsar_client.file_ready(**self.__build_kwds(obj, **kwds))
+
+ def create(self, obj, **kwds):
+ return self.pulsar_client.create(**self.__build_kwds(obj, **kwds))
+
+ def empty(self, obj, **kwds):
+ return self.pulsar_client.empty(**self.__build_kwds(obj, **kwds))
+
+ def size(self, obj, **kwds):
+ return self.pulsar_client.size(**self.__build_kwds(obj, **kwds))
+
+ def delete(self, obj, **kwds):
+ return self.pulsar_client.delete(**self.__build_kwds(obj, **kwds))
+
+ # TODO: Optimize get_data.
+ def get_data(self, obj, **kwds):
+ return self.pulsar_client.get_data(**self.__build_kwds(obj, **kwds))
+
+ def get_filename(self, obj, **kwds):
+ return self.pulsar_client.get_filename(**self.__build_kwds(obj, **kwds))
+
+ def update_from_file(self, obj, **kwds):
+ return self.pulsar_client.update_from_file(**self.__build_kwds(obj, **kwds))
+
+ def get_store_usage_percent(self):
+ return self.pulsar_client.get_store_usage_percent()
+
+ def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
+ return None
+
+ def __build_kwds(self, obj, **kwds):
+ kwds['object_id'] = obj.id
+ return kwds
+ pass
+
+ def __build_pulsar_client(self, config_xml):
+ url = config_xml.get("url")
+ private_token = config_xml.get("private_token", None)
+ transport = config_xml.get("transport", None)
+ manager_options = dict(transport=transport)
+ client_options = dict(url=url, private_token=private_token)
+ pulsar_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
+ return pulsar_client
+
+ def shutdown(self):
+ pass
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/galaxy/tools/deps/dependencies.py
--- a/lib/galaxy/tools/deps/dependencies.py
+++ b/lib/galaxy/tools/deps/dependencies.py
@@ -8,7 +8,7 @@
related context required to resolve dependencies via the
ToolShedPackageDependencyResolver.
- This is meant to enable remote resolution of dependencies, by the LWR or
+ This is meant to enable remote resolution of dependencies, by the Pulsar or
other potential remote execution mechanisms.
"""
@@ -39,7 +39,7 @@
@staticmethod
def _toolshed_install_dependency_from_dict(as_dict):
- # Rather than requiring full models in LWR, just use simple objects
+ # Rather than requiring full models in Pulsar, just use simple objects
# containing only properties and associations used to resolve
# dependencies for tool execution.
repository_object = bunch.Bunch(
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/pulsar/client/__init__.py
--- /dev/null
+++ b/lib/pulsar/client/__init__.py
@@ -0,0 +1,62 @@
+"""
+pulsar client
+======
+
+This module contains logic for interfacing with an external Pulsar server.
+
+------------------
+Configuring Galaxy
+------------------
+
+Galaxy job runners are configured in Galaxy's ``job_conf.xml`` file. See ``job_conf.xml.sample_advanced``
+in your Galaxy code base or on
+`Bitbucket <https://bitbucket.org/galaxy/galaxy-dist/src/tip/job_conf.xml.sample_advanc…>`_
+for information on how to configure Galaxy to interact with the Pulsar.
+
+Galaxy also supports an older, less rich configuration of job runners directly
+in its main ``universe_wsgi.ini`` file. The following section describes how to
+configure Galaxy to communicate with the Pulsar in this legacy mode.
+
+Legacy
+------
+
+A Galaxy tool can be configured to be executed remotely via Pulsar by
+adding a line to the ``universe_wsgi.ini`` file under the
+``galaxy:tool_runners`` section with the format::
+
+ <tool_id> = pulsar://http://<pulsar_host>:<pulsar_port>
+
+As an example, if a host named remotehost is running the Pulsar server
+application on port ``8913``, then the tool with id ``test_tool`` can
+be configured to run remotely on remotehost by adding the following
+line to ``universe.ini``::
+
+ test_tool = pulsar://http://remotehost:8913
+
+Remember this must be added after the ``[galaxy:tool_runners]`` header
+in the ``universe.ini`` file.
+
+
+"""
+
+from .staging.down import finish_job
+from .staging.up import submit_job
+from .staging import ClientJobDescription
+from .staging import PulsarOutputs
+from .staging import ClientOutputs
+from .client import OutputNotFoundException
+from .manager import build_client_manager
+from .destination import url_to_destination_params
+from .path_mapper import PathMapper
+
+__all__ = [
+ build_client_manager,
+ OutputNotFoundException,
+ url_to_destination_params,
+ finish_job,
+ submit_job,
+ ClientJobDescription,
+ PulsarOutputs,
+ ClientOutputs,
+ PathMapper,
+]
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/pulsar/client/action_mapper.py
--- /dev/null
+++ b/lib/pulsar/client/action_mapper.py
@@ -0,0 +1,567 @@
+from json import load
+from os import makedirs
+from os.path import exists
+from os.path import abspath
+from os.path import dirname
+from os.path import join
+from os.path import basename
+from os.path import sep
+import fnmatch
+from re import compile
+from re import escape
+import galaxy.util
+from galaxy.util.bunch import Bunch
+from .config_util import read_file
+from .util import directory_files
+from .util import unique_path_prefix
+from .transport import get_file
+from .transport import post_file
+
+
+DEFAULT_MAPPED_ACTION = 'transfer' # Not really clear to me what this should be, exception?
+DEFAULT_PATH_MAPPER_TYPE = 'prefix'
+
+STAGING_ACTION_REMOTE = "remote"
+STAGING_ACTION_LOCAL = "local"
+STAGING_ACTION_NONE = None
+STAGING_ACTION_DEFAULT = "default"
+
+# Poor man's enum.
+path_type = Bunch(
+ # Galaxy input datasets and extra files.
+ INPUT="input",
+ # Galaxy config and param files.
+ CONFIG="config",
+ # Files from tool's tool_dir (for now just wrapper if available).
+ TOOL="tool",
+ # Input work dir files - e.g. metadata files, task-split input files, etc..
+ WORKDIR="workdir",
+ # Galaxy output datasets in their final home.
+ OUTPUT="output",
+ # Galaxy from_work_dir output paths and other files (e.g. galaxy.json)
+ OUTPUT_WORKDIR="output_workdir",
+ # Other fixed tool parameter paths (likely coming from tool data, but not
+ # nessecarily). Not sure this is the best name...
+ UNSTRUCTURED="unstructured",
+)
+
+
+ACTION_DEFAULT_PATH_TYPES = [
+ path_type.INPUT,
+ path_type.CONFIG,
+ path_type.TOOL,
+ path_type.WORKDIR,
+ path_type.OUTPUT,
+ path_type.OUTPUT_WORKDIR,
+]
+ALL_PATH_TYPES = ACTION_DEFAULT_PATH_TYPES + [path_type.UNSTRUCTURED]
+
+
+class FileActionMapper(object):
+ """
+ Objects of this class define how paths are mapped to actions.
+
+ >>> json_string = r'''{"paths": [ \
+ {"path": "/opt/galaxy", "action": "none"}, \
+ {"path": "/galaxy/data", "action": "transfer"}, \
+ {"path": "/cool/bamfiles/**/*.bam", "action": "copy", "match_type": "glob"}, \
+ {"path": ".*/dataset_\\\\d+.dat", "action": "copy", "match_type": "regex"} \
+ ]}'''
+ >>> from tempfile import NamedTemporaryFile
+ >>> from os import unlink
+ >>> def mapper_for(default_action, config_contents):
+ ... f = NamedTemporaryFile(delete=False)
+ ... f.write(config_contents.encode('UTF-8'))
+ ... f.close()
+ ... mock_client = Bunch(default_file_action=default_action, action_config_path=f.name, files_endpoint=None)
+ ... mapper = FileActionMapper(mock_client)
+ ... mapper = FileActionMapper(config=mapper.to_dict()) # Serialize and deserialize it to make sure still works
+ ... unlink(f.name)
+ ... return mapper
+ >>> mapper = mapper_for(default_action='none', config_contents=json_string)
+ >>> # Test first config line above, implicit path prefix mapper
+ >>> action = mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input')
+ >>> action.action_type == u'none'
+ True
+ >>> action.staging_needed
+ False
+ >>> # Test another (2nd) mapper, this one with a different action
+ >>> action = mapper.action('/galaxy/data/files/000/dataset_1.dat', 'input')
+ >>> action.action_type == u'transfer'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Always at least copy work_dir outputs.
+ >>> action = mapper.action('/opt/galaxy/database/working_directory/45.sh', 'workdir')
+ >>> action.action_type == u'copy'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Test glob mapper (matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam', 'input').action_type == u'copy'
+ True
+ >>> # Test glob mapper (non-matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam.bai', 'input').action_type == u'none'
+ True
+ >>> # Regex mapper test.
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'input').action_type == u'copy'
+ True
+ >>> # Doesn't map unstructured paths by default
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'none'
+ True
+ >>> input_only_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "input"} \
+ ] }''')
+ >>> input_only_mapper.action('/dataset_1.dat', 'input').action_type == u'transfer'
+ True
+ >>> input_only_mapper.action('/dataset_1.dat', 'output').action_type == u'none'
+ True
+ >>> unstructured_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "*any*"} \
+ ] }''')
+ >>> unstructured_mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'transfer'
+ True
+ """
+
+ def __init__(self, client=None, config=None):
+ if config is None and client is None:
+ message = "FileActionMapper must be constructed from either a client or a config dictionary."
+ raise Exception(message)
+ if config is None:
+ config = self.__client_to_config(client)
+ self.default_action = config.get("default_action", "transfer")
+ self.mappers = mappers_from_dicts(config.get("paths", []))
+ self.files_endpoint = config.get("files_endpoint", None)
+
+ def action(self, path, type, mapper=None):
+ mapper = self.__find_mapper(path, type, mapper)
+ action_class = self.__action_class(path, type, mapper)
+ file_lister = DEFAULT_FILE_LISTER
+ action_kwds = {}
+ if mapper:
+ file_lister = mapper.file_lister
+ action_kwds = mapper.action_kwds
+ action = action_class(path, file_lister=file_lister, **action_kwds)
+ self.__process_action(action, type)
+ return action
+
+ def unstructured_mappers(self):
+ """ Return mappers that will map 'unstructured' files (i.e. go beyond
+ mapping inputs, outputs, and config files).
+ """
+ return filter(lambda m: path_type.UNSTRUCTURED in m.path_types, self.mappers)
+
+ def to_dict(self):
+ return dict(
+ default_action=self.default_action,
+ files_endpoint=self.files_endpoint,
+ paths=map(lambda m: m.to_dict(), self.mappers)
+ )
+
+ def __client_to_config(self, client):
+ action_config_path = client.action_config_path
+ if action_config_path:
+ config = read_file(action_config_path)
+ else:
+ config = dict()
+ config["default_action"] = client.default_file_action
+ config["files_endpoint"] = client.files_endpoint
+ return config
+
+ def __load_action_config(self, path):
+ config = load(open(path, 'rb'))
+ self.mappers = mappers_from_dicts(config.get('paths', []))
+
+ def __find_mapper(self, path, type, mapper=None):
+ if not mapper:
+ normalized_path = abspath(path)
+ for query_mapper in self.mappers:
+ if query_mapper.matches(normalized_path, type):
+ mapper = query_mapper
+ break
+ return mapper
+
+ def __action_class(self, path, type, mapper):
+ action_type = self.default_action if type in ACTION_DEFAULT_PATH_TYPES else "none"
+ if mapper:
+ action_type = mapper.action_type
+ if type in ["workdir", "output_workdir"] and action_type == "none":
+ # We are changing the working_directory relative to what
+ # Galaxy would use, these need to be copied over.
+ action_type = "copy"
+ action_class = actions.get(action_type, None)
+ if action_class is None:
+ message_template = "Unknown action_type encountered %s while trying to map path %s"
+ message_args = (action_type, path)
+ raise Exception(message_template % message_args)
+ return action_class
+
+ def __process_action(self, action, file_type):
+ """ Extension point to populate extra action information after an
+ action has been created.
+ """
+ if action.action_type == "remote_transfer":
+ url_base = self.files_endpoint
+ if not url_base:
+ raise Exception("Attempted to use remote_transfer action with defining a files_endpoint")
+ if "?" not in url_base:
+ url_base = "%s?" % url_base
+ # TODO: URL encode path.
+ url = "%s&path=%s&file_type=%s" % (url_base, action.path, file_type)
+ action.url = url
+
+REQUIRED_ACTION_KWD = object()
+
+
+class BaseAction(object):
+ action_spec = {}
+
+ def __init__(self, path, file_lister=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+
+ def unstructured_map(self, path_helper):
+ unstructured_map = self.file_lister.unstructured_map(self.path)
+ if self.staging_needed:
+ # To ensure uniqueness, prepend unique prefix to each name
+ prefix = unique_path_prefix(self.path)
+ for path, name in unstructured_map.iteritems():
+ unstructured_map[path] = join(prefix, name)
+ else:
+ path_rewrites = {}
+ for path in unstructured_map:
+ rewrite = self.path_rewrite(path_helper, path)
+ if rewrite:
+ path_rewrites[path] = rewrite
+ unstructured_map = path_rewrites
+ return unstructured_map
+
+ @property
+ def staging_needed(self):
+ return self.staging != STAGING_ACTION_NONE
+
+ @property
+ def staging_action_local(self):
+ return self.staging == STAGING_ACTION_LOCAL
+
+
+class NoneAction(BaseAction):
+ """ This action indicates the corresponding path does not require any
+ additional action. This should indicate paths that are available both on
+ the Pulsar client (i.e. Galaxy server) and remote Pulsar server with the same
+ paths. """
+ action_type = "none"
+ staging = STAGING_ACTION_NONE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return NoneAction(path=action_dict["path"])
+
+ def path_rewrite(self, path_helper, path=None):
+ return None
+
+
+class RewriteAction(BaseAction):
+ """ This actin indicates the Pulsar server should simply rewrite the path
+ to the specified file.
+ """
+ action_spec = dict(
+ source_directory=REQUIRED_ACTION_KWD,
+ destination_directory=REQUIRED_ACTION_KWD
+ )
+ action_type = "rewrite"
+ staging = STAGING_ACTION_NONE
+
+ def __init__(self, path, file_lister=None, source_directory=None, destination_directory=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+ self.source_directory = source_directory
+ self.destination_directory = destination_directory
+
+ def to_dict(self):
+ return dict(
+ path=self.path,
+ action_type=self.action_type,
+ source_directory=self.source_directory,
+ destination_directory=self.destination_directory,
+ )
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RewriteAction(
+ path=action_dict["path"],
+ source_directory=action_dict["source_directory"],
+ destination_directory=action_dict["destination_directory"],
+ )
+
+ def path_rewrite(self, path_helper, path=None):
+ if not path:
+ path = self.path
+ new_path = path_helper.from_posix_with_new_base(self.path, self.source_directory, self.destination_directory)
+ return None if new_path == self.path else new_path
+
+
+class TransferAction(BaseAction):
+ """ This actions indicates that the Pulsar client should initiate an HTTP
+ transfer of the corresponding path to the remote Pulsar server before
+ launching the job. """
+ action_type = "transfer"
+ staging = STAGING_ACTION_LOCAL
+
+
+class CopyAction(BaseAction):
+ """ This action indicates that the Pulsar client should execute a file system
+ copy of the corresponding path to the Pulsar staging directory prior to
+ launching the corresponding job. """
+ action_type = "copy"
+ staging = STAGING_ACTION_LOCAL
+
+
+class RemoteCopyAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_copy"
+ staging = STAGING_ACTION_REMOTE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteCopyAction(path=action_dict["path"])
+
+ def write_to_path(self, path):
+ galaxy.util.copy_to_path(open(self.path, "rb"), path)
+
+ def write_from_path(self, pulsar_path):
+ destination = self.path
+ parent_directory = dirname(destination)
+ if not exists(parent_directory):
+ makedirs(parent_directory)
+ with open(pulsar_path, "rb") as f:
+ galaxy.util.copy_to_path(f, destination)
+
+
+class RemoteTransferAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_transfer"
+ staging = STAGING_ACTION_REMOTE
+
+ def __init__(self, path, file_lister=None, url=None):
+ super(RemoteTransferAction, self).__init__(path, file_lister=file_lister)
+ self.url = url
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type, url=self.url)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteTransferAction(path=action_dict["path"], url=action_dict["url"])
+
+ def write_to_path(self, path):
+ get_file(self.url, path)
+
+ def write_from_path(self, pulsar_path):
+ post_file(self.url, pulsar_path)
+
+
+class MessageAction(object):
+ """ Sort of pseudo action describing "files" store in memory and
+ transferred via message (HTTP, Python-call, MQ, etc...)
+ """
+ action_type = "message"
+ staging = STAGING_ACTION_DEFAULT
+
+ def __init__(self, contents, client=None):
+ self.contents = contents
+ self.client = client
+
+ @property
+ def staging_needed(self):
+ return True
+
+ @property
+ def staging_action_local(self):
+ # Ekkk, cannot be called if created through from_dict.
+ # Shouldn't be a problem the way it is used - but is an
+ # object design problem.
+ return self.client.prefer_local_staging
+
+ def to_dict(self):
+ return dict(contents=self.contents, action_type=MessageAction.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return MessageAction(contents=action_dict["contents"])
+
+ def write_to_path(self, path):
+ open(path, "w").write(self.contents)
+
+
+DICTIFIABLE_ACTION_CLASSES = [RemoteCopyAction, RemoteTransferAction, MessageAction]
+
+
+def from_dict(action_dict):
+ action_type = action_dict.get("action_type", None)
+ target_class = None
+ for action_class in DICTIFIABLE_ACTION_CLASSES:
+ if action_type == action_class.action_type:
+ target_class = action_class
+ if not target_class:
+ message = "Failed to recover action from dictionary - invalid action type specified %s." % action_type
+ raise Exception(message)
+ return target_class.from_dict(action_dict)
+
+
+class BasePathMapper(object):
+
+ def __init__(self, config):
+ action_type = config.get('action', DEFAULT_MAPPED_ACTION)
+ action_class = actions.get(action_type, None)
+ action_kwds = action_class.action_spec.copy()
+ for key, value in action_kwds.items():
+ if key in config:
+ action_kwds[key] = config[key]
+ elif value is REQUIRED_ACTION_KWD:
+ message_template = "action_type %s requires key word argument %s"
+ message = message_template % (action_type, key)
+ raise Exception(message)
+ self.action_type = action_type
+ self.action_kwds = action_kwds
+ path_types_str = config.get('path_types', "*defaults*")
+ path_types_str = path_types_str.replace("*defaults*", ",".join(ACTION_DEFAULT_PATH_TYPES))
+ path_types_str = path_types_str.replace("*any*", ",".join(ALL_PATH_TYPES))
+ self.path_types = path_types_str.split(",")
+ self.file_lister = FileLister(config)
+
+ def matches(self, path, path_type):
+ path_type_matches = path_type in self.path_types
+ return path_type_matches and self._path_matches(path)
+
+ def _extend_base_dict(self, **kwds):
+ base_dict = dict(
+ action=self.action_type,
+ path_types=",".join(self.path_types),
+ match_type=self.match_type
+ )
+ base_dict.update(self.file_lister.to_dict())
+ base_dict.update(self.action_kwds)
+ base_dict.update(**kwds)
+ return base_dict
+
+
+class PrefixPathMapper(BasePathMapper):
+ match_type = 'prefix'
+
+ def __init__(self, config):
+ super(PrefixPathMapper, self).__init__(config)
+ self.prefix_path = abspath(config['path'])
+
+ def _path_matches(self, path):
+ return path.startswith(self.prefix_path)
+
+ def to_pattern(self):
+ pattern_str = "(%s%s[^\s,\"\']+)" % (escape(self.prefix_path), escape(sep))
+ return compile(pattern_str)
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.prefix_path)
+
+
+class GlobPathMapper(BasePathMapper):
+ match_type = 'glob'
+
+ def __init__(self, config):
+ super(GlobPathMapper, self).__init__(config)
+ self.glob_path = config['path']
+
+ def _path_matches(self, path):
+ return fnmatch.fnmatch(path, self.glob_path)
+
+ def to_pattern(self):
+ return compile(fnmatch.translate(self.glob_path))
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.glob_path)
+
+
+class RegexPathMapper(BasePathMapper):
+ match_type = 'regex'
+
+ def __init__(self, config):
+ super(RegexPathMapper, self).__init__(config)
+ self.pattern_raw = config['path']
+ self.pattern = compile(self.pattern_raw)
+
+ def _path_matches(self, path):
+ return self.pattern.match(path) is not None
+
+ def to_pattern(self):
+ return self.pattern
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.pattern_raw)
+
+MAPPER_CLASSES = [PrefixPathMapper, GlobPathMapper, RegexPathMapper]
+MAPPER_CLASS_DICT = dict(map(lambda c: (c.match_type, c), MAPPER_CLASSES))
+
+
+def mappers_from_dicts(mapper_def_list):
+ return map(lambda m: __mappper_from_dict(m), mapper_def_list)
+
+
+def __mappper_from_dict(mapper_dict):
+ map_type = mapper_dict.get('match_type', DEFAULT_PATH_MAPPER_TYPE)
+ return MAPPER_CLASS_DICT[map_type](mapper_dict)
+
+
+class FileLister(object):
+
+ def __init__(self, config):
+ self.depth = int(config.get("depth", "0"))
+
+ def to_dict(self):
+ return dict(
+ depth=self.depth
+ )
+
+ def unstructured_map(self, path):
+ depth = self.depth
+ if self.depth == 0:
+ return {path: basename(path)}
+ else:
+ while depth > 0:
+ path = dirname(path)
+ depth -= 1
+ return dict([(join(path, f), f) for f in directory_files(path)])
+
+DEFAULT_FILE_LISTER = FileLister(dict(depth=0))
+
+ACTION_CLASSES = [
+ NoneAction,
+ RewriteAction,
+ TransferAction,
+ CopyAction,
+ RemoteCopyAction,
+ RemoteTransferAction,
+]
+actions = dict([(clazz.action_type, clazz) for clazz in ACTION_CLASSES])
+
+
+__all__ = [
+ FileActionMapper,
+ path_type,
+ from_dict,
+ MessageAction,
+ RemoteTransferAction, # For testing
+]
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/pulsar/client/amqp_exchange.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange.py
@@ -0,0 +1,139 @@
+try:
+ import kombu
+ from kombu import pools
+except ImportError:
+ kombu = None
+
+import socket
+import logging
+import threading
+from time import sleep
+log = logging.getLogger(__name__)
+
+
+KOMBU_UNAVAILABLE = "Attempting to bind to AMQP message queue, but kombu dependency unavailable"
+
+DEFAULT_EXCHANGE_NAME = "pulsar"
+DEFAULT_EXCHANGE_TYPE = "direct"
+# Set timeout to periodically give up looking and check if polling should end.
+DEFAULT_TIMEOUT = 0.2
+DEFAULT_HEARTBEAT = 580
+
+DEFAULT_RECONNECT_CONSUMER_WAIT = 1
+DEFAULT_HEARTBEAT_WAIT = 1
+
+
+class PulsarExchange(object):
+ """ Utility for publishing and consuming structured Pulsar queues using kombu.
+ This is shared between the server and client - an exchange should be setup
+ for each manager (or in the case of the client, each manager one wished to
+ communicate with.)
+
+ Each Pulsar manager is defined solely by name in the scheme, so only one Pulsar
+ should target each AMQP endpoint or care should be taken that unique
+ manager names are used across Pulsar servers targetting same AMQP endpoint -
+ and in particular only one such Pulsar should define an default manager with
+ name _default_.
+ """
+
+ def __init__(
+ self,
+ url,
+ manager_name,
+ connect_ssl=None,
+ timeout=DEFAULT_TIMEOUT,
+ publish_kwds={},
+ ):
+ """
+ """
+ if not kombu:
+ raise Exception(KOMBU_UNAVAILABLE)
+ self.__url = url
+ self.__manager_name = manager_name
+ self.__connect_ssl = connect_ssl
+ self.__exchange = kombu.Exchange(DEFAULT_EXCHANGE_NAME, DEFAULT_EXCHANGE_TYPE)
+ self.__timeout = timeout
+ # Be sure to log message publishing failures.
+ if publish_kwds.get("retry", False):
+ if "retry_policy" not in publish_kwds:
+ publish_kwds["retry_policy"] = {}
+ if "errback" not in publish_kwds["retry_policy"]:
+ publish_kwds["retry_policy"]["errback"] = self.__publish_errback
+ self.__publish_kwds = publish_kwds
+
+ @property
+ def url(self):
+ return self.__url
+
+ def consume(self, queue_name, callback, check=True, connection_kwargs={}):
+ queue = self.__queue(queue_name)
+ log.debug("Consuming queue '%s'", queue)
+ while check:
+ heartbeat_thread = None
+ try:
+ with self.connection(self.__url, heartbeat=DEFAULT_HEARTBEAT, **connection_kwargs) as connection:
+ with kombu.Consumer(connection, queues=[queue], callbacks=[callback], accept=['json']):
+ heartbeat_thread = self.__start_heartbeat(queue_name, connection)
+ while check and connection.connected:
+ try:
+ connection.drain_events(timeout=self.__timeout)
+ except socket.timeout:
+ pass
+ except (IOError, socket.error), exc:
+ # In testing, errno is None
+ log.warning('Got %s, will retry: %s', exc.__class__.__name__, exc)
+ if heartbeat_thread:
+ heartbeat_thread.join()
+ sleep(DEFAULT_RECONNECT_CONSUMER_WAIT)
+
+ def heartbeat(self, connection):
+ log.debug('AMQP heartbeat thread alive')
+ while connection.connected:
+ connection.heartbeat_check()
+ sleep(DEFAULT_HEARTBEAT_WAIT)
+ log.debug('AMQP heartbeat thread exiting')
+
+ def publish(self, name, payload):
+ with self.connection(self.__url) as connection:
+ with pools.producers[connection].acquire() as producer:
+ key = self.__queue_name(name)
+ producer.publish(
+ payload,
+ serializer='json',
+ exchange=self.__exchange,
+ declare=[self.__exchange],
+ routing_key=key,
+ **self.__publish_kwds
+ )
+
+ def __publish_errback(self, exc, interval):
+ log.error("Connection error while publishing: %r", exc, exc_info=1)
+ log.info("Retrying in %s seconds", interval)
+
+ def connection(self, connection_string, **kwargs):
+ if "ssl" not in kwargs:
+ kwargs["ssl"] = self.__connect_ssl
+ return kombu.Connection(connection_string, **kwargs)
+
+ def __queue(self, name):
+ queue_name = self.__queue_name(name)
+ queue = kombu.Queue(queue_name, self.__exchange, routing_key=queue_name)
+ return queue
+
+ def __queue_name(self, name):
+ key_prefix = self.__key_prefix()
+ queue_name = '%s_%s' % (key_prefix, name)
+ return queue_name
+
+ def __key_prefix(self):
+ if self.__manager_name == "_default_":
+ key_prefix = "pulsar_"
+ else:
+ key_prefix = "pulsar_%s_" % self.__manager_name
+ return key_prefix
+
+ def __start_heartbeat(self, queue_name, connection):
+ thread_name = "consume-heartbeat-%s" % (self.__queue_name(queue_name))
+ thread = threading.Thread(name=thread_name, target=self.heartbeat, args=(connection,))
+ thread.start()
+ return thread
diff -r cfa24d46767a41afa9e83cbf703eef837b47f1e2 -r 8c569cffa9670f765492c8ddc11fb54d9a2ab2f1 lib/pulsar/client/amqp_exchange_factory.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange_factory.py
@@ -0,0 +1,41 @@
+from .amqp_exchange import PulsarExchange
+from .util import filter_destination_params
+
+
+def get_exchange(url, manager_name, params):
+ connect_ssl = parse_amqp_connect_ssl_params(params)
+ exchange_kwds = dict(
+ manager_name=manager_name,
+ connect_ssl=connect_ssl,
+ publish_kwds=parse_amqp_publish_kwds(params)
+ )
+ timeout = params.get('amqp_consumer_timeout', False)
+ if timeout is not False:
+ exchange_kwds['timeout'] = timeout
+ exchange = PulsarExchange(url, **exchange_kwds)
+ return exchange
+
+
+def parse_amqp_connect_ssl_params(params):
+ ssl_params = filter_destination_params(params, "amqp_connect_ssl_")
+ if not ssl_params:
+ return
+
+ ssl = __import__('ssl')
+ if 'cert_reqs' in ssl_params:
+ value = ssl_params['cert_reqs']
+ ssl_params['cert_reqs'] = getattr(ssl, value.upper())
+ return ssl_params
+
+
+def parse_amqp_publish_kwds(params):
+ all_publish_params = filter_destination_params(params, "amqp_publish_")
+ retry_policy_params = {}
+ for key in all_publish_params.keys():
+ if key.startswith("retry_"):
+ value = all_publish_params[key]
+ retry_policy_params[key[len("retry_"):]] = value
+ del all_publish_params[key]
+ if retry_policy_params:
+ all_publish_params["retry_policy"] = retry_policy_params
+ return all_publish_params
This diff is so big that we needed to truncate the remainder.
https://bitbucket.org/galaxy/galaxy-central/commits/566388d62374/
Changeset: 566388d62374
User: jmchilton
Date: 2014-06-24 04:27:51
Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #422)
Implement Pulsar job runners.
Affected #: 32 files
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 job_conf.xml.sample_advanced
--- a/job_conf.xml.sample_advanced
+++ b/job_conf.xml.sample_advanced
@@ -19,27 +19,30 @@
<!-- Override the $DRMAA_LIBRARY_PATH environment variable --><param id="drmaa_library_path">/sge/lib/libdrmaa.so</param></plugin>
- <plugin id="lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <!-- More information on LWR can be found at https://lwr.readthedocs.org -->
- <!-- Uncomment following line to use libcurl to perform HTTP calls (defaults to urllib) -->
+ <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
+ <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
+ <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <!-- Pulsar runners (see more at https://pulsar.readthedocs.org) -->
+ <plugin id="pulsar_rest" type="runner" load="galaxy.jobs.runners.pulsar:PulsarRESTJobRunner">
+ <!-- Allow optimized HTTP calls with libcurl (defaults to urllib) --><!-- <param id="transport">curl</param> -->
- <!-- *Experimental Caching*: Uncomment next parameters to enable
- caching and specify the number of caching threads to enable on Galaxy
- side. Likely will not work with newer features such as MQ support.
- If this is enabled be sure to specify a `file_cache_dir` in the remote
- LWR's main configuration file.
+
+ <!-- *Experimental Caching*: Next parameter enables caching.
+ Likely will not work with newer features such as MQ support.
+
+ If this is enabled be sure to specify a `file_cache_dir` in
+ the remote Pulsar's servers main configuration file.
--><!-- <param id="cache">True</param> -->
- <!-- <param id="transfer_threads">2</param> --></plugin>
- <plugin id="amqp_lwr" type="runner" load="galaxy.jobs.runners.lwr:LwrJobRunner">
- <param id="url">amqp://guest:guest@localhost:5672//</param>
- <!-- If using message queue driven LWR - the LWR will generally
- initiate file transfers so a the URL of this Galaxy instance
- must be configured. -->
+ <plugin id="pulsar_mq" type="runner" load="galaxy.jobs.runners.pulsar:PulsarMQJobRunner">
+ <!-- AMQP URL to connect to. -->
+ <param id="amqp_url">amqp://guest:guest@localhost:5672//</param>
+ <!-- URL remote Pulsar apps should transfer files to this Galaxy
+ instance to/from. --><param id="galaxy_url">http://localhost:8080</param>
- <!-- If multiple managers configured on the LWR, specify which one
- this plugin targets. -->
+ <!-- Pulsar job manager to communicate with (see Pulsar
+ docs for information on job managers). --><!-- <param id="manager">_default_</param> --><!-- The AMQP client can provide an SSL client certificate (e.g. for
validation), the following options configure that certificate
@@ -58,9 +61,17 @@
higher value (in seconds) (or `None` to use blocking connections). --><!-- <param id="amqp_consumer_timeout">None</param> --></plugin>
- <plugin id="cli" type="runner" load="galaxy.jobs.runners.cli:ShellJobRunner" />
- <plugin id="condor" type="runner" load="galaxy.jobs.runners.condor:CondorJobRunner" />
- <plugin id="slurm" type="runner" load="galaxy.jobs.runners.slurm:SlurmJobRunner" />
+ <plugin id="pulsar_legacy" type="runner" load="galaxy.jobs.runners.pulsar:PulsarLegacyJobRunner">
+ <!-- Pulsar job runner with default parameters matching those
+ of old LWR job runner. If your Pulsar server is running on a
+ Windows machine for instance this runner should still be used.
+
+ These destinations still needs to target a Pulsar server,
+ older LWR plugins and destinations still work in Galaxy can
+ target LWR servers, but this support should be considered
+ deprecated and will disappear with a future release of Galaxy.
+ -->
+ </plugin></plugins><handlers default="handlers"><!-- Additional job handlers - the id should match the name of a
@@ -125,8 +136,8 @@
$galaxy_root:ro,$tool_directory:ro,$working_directory:rw,$default_file_path:ro
- If using the LWR, defaults will be even further restricted because the
- LWR will (by default) stage all needed inputs into the job's job_directory
+ If using the Pulsar, defaults will be even further restricted because the
+ Pulsar will (by default) stage all needed inputs into the job's job_directory
(so there is not need to allow the docker container to read all the
files - let alone write over them). Defaults in this case becomes:
@@ -135,7 +146,7 @@
Python string.Template is used to expand volumes and values $defaults,
$galaxy_root, $default_file_path, $tool_directory, $working_directory,
are available to all jobs and $job_directory is also available for
- LWR jobs.
+ Pulsar jobs.
--><!-- Control memory allocatable by docker container with following option:
-->
@@ -213,87 +224,71 @@
<!-- A destination that represents a method in the dynamic runner. --><param id="function">foo</param></destination>
- <destination id="secure_lwr" runner="lwr">
- <param id="url">https://windowshost.examle.com:8913/</param>
- <!-- If set, private_token must match token remote LWR server configured with. -->
+ <destination id="secure_pulsar_rest_dest" runner="pulsar_rest">
+ <param id="url">https://examle.com:8913/</param>
+ <!-- If set, private_token must match token in remote Pulsar's
+ configuration. --><param id="private_token">123456789changeme</param><!-- Uncomment the following statement to disable file staging (e.g.
- if there is a shared file system between Galaxy and the LWR
+ if there is a shared file system between Galaxy and the Pulsar
server). Alternatively action can be set to 'copy' - to replace
http transfers with file system copies, 'remote_transfer' to cause
- the lwr to initiate HTTP transfers instead of Galaxy, or
- 'remote_copy' to cause lwr to initiate file system copies.
+ the Pulsar to initiate HTTP transfers instead of Galaxy, or
+ 'remote_copy' to cause Pulsar to initiate file system copies.
If setting this to 'remote_transfer' be sure to specify a
'galaxy_url' attribute on the runner plugin above. --><!-- <param id="default_file_action">none</param> --><!-- The above option is just the default, the transfer behavior
none|copy|http can be configured on a per path basis via the
- following file. See lib/galaxy/jobs/runners/lwr_client/action_mapper.py
- for examples of how to configure this file. This is very beta
- and nature of file will likely change.
+ following file. See Pulsar documentation for more details and
+ examples.
-->
- <!-- <param id="file_action_config">file_actions.json</param> -->
- <!-- Uncomment following option to disable Galaxy tool dependency
- resolution and utilize remote LWR's configuraiton of tool
- dependency resolution instead (same options as Galaxy for
- dependency resolution are available in LWR). At a minimum
- the remote LWR server should define a tool_dependencies_dir in
- its `server.ini` configuration. The LWR will not attempt to
- stage dependencies - so ensure the the required galaxy or tool
- shed packages are available remotely (exact same tool shed
- installed changesets are required).
+ <!-- <param id="file_action_config">file_actions.yaml</param> -->
+ <!-- The non-legacy Pulsar runners will attempt to resolve Galaxy
+ dependencies remotely - to enable this set a tool_dependency_dir
+ in Pulsar's configuration (can work with all the same dependency
+ resolutions mechanisms as Galaxy - tool Shed installs, Galaxy
+ packages, etc...). To disable this behavior, set the follow parameter
+ to none. To generate the dependency resolution command locally
+ set the following parameter local.
-->
- <!-- <param id="dependency_resolution">remote</params> -->
- <!-- Traditionally, the LWR allow Galaxy to generate a command line
- as if it were going to run the command locally and then the
- LWR client rewrites it after the fact using regular
- expressions. Setting the following value to true causes the
- LWR runner to insert itself into the command line generation
- process and generate the correct command line from the get go.
- This will likely be the default someday - but requires a newer
- LWR version and is less well tested. -->
- <!-- <param id="rewrite_parameters">true</params> -->
+ <!-- <param id="dependency_resolution">none</params> --><!-- Uncomment following option to enable setting metadata on remote
- LWR server. The 'use_remote_datatypes' option is available for
+ Pulsar server. The 'use_remote_datatypes' option is available for
determining whether to use remotely configured datatypes or local
ones (both alternatives are a little brittle). --><!-- <param id="remote_metadata">true</param> --><!-- <param id="use_remote_datatypes">false</param> --><!-- <param id="remote_property_galaxy_home">/path/to/remote/galaxy-central</param> -->
- <!-- If remote LWR server is configured to run jobs as the real user,
+ <!-- If remote Pulsar server is configured to run jobs as the real user,
uncomment the following line to pass the current Galaxy user
along. --><!-- <param id="submit_user">$__user_name__</param> -->
- <!-- Various other submission parameters can be passed along to the LWR
- whose use will depend on the remote LWR's configured job manager.
+ <!-- Various other submission parameters can be passed along to the Pulsar
+ whose use will depend on the remote Pulsar's configured job manager.
For instance:
-->
- <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- <param id="submit_native_specification">-P bignodes -R y -pe threads 8</param> -->
+ <!-- Disable parameter rewriting and rewrite generated commands
+ instead. This may be required if remote host is Windows machine
+ but probably not otherwise.
+ -->
+ <!-- <param id="rewrite_parameters">false</params> --></destination>
- <destination id="amqp_lwr_dest" runner="amqp_lwr" >
- <!-- url and private_token are not valid when using MQ driven LWR. The plugin above
- determines which queue/manager to target and the underlying MQ server should be
- used to configure security.
- -->
- <!-- Traditionally, the LWR client sends request to LWR
- server to populate various system properties. This
+ <destination id="pulsar_mq_dest" runner="amqp_pulsar" >
+ <!-- The RESTful Pulsar client sends a request to Pulsar
+ to populate various system properties. This
extra step can be disabled and these calculated here
on client by uncommenting jobs_directory and
specifying any additional remote_property_ of
interest, this is not optional when using message
queues.
-->
- <param id="jobs_directory">/path/to/remote/lwr/lwr_staging/</param>
- <!-- Default the LWR send files to and pull files from Galaxy when
- using message queues (in the more traditional mode Galaxy sends
- files to and pull files from the LWR - this is obviously less
- appropriate when using a message queue).
-
- The default_file_action currently requires pycurl be available
- to Galaxy (presumably in its virtualenv). Making this dependency
- optional is an open task.
+ <param id="jobs_directory">/path/to/remote/pulsar/files/staging/</param>
+ <!-- Otherwise MQ and Legacy pulsar destinations can be supplied
+ all the same destination parameters as the RESTful client documented
+ above (though url and private_token are ignored when using a MQ).
-->
- <param id="default_file_action">remote_transfer</param></destination><destination id="ssh_torque" runner="cli"><param id="shell_plugin">SecureShell</param>
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/pulsar.py
--- /dev/null
+++ b/lib/galaxy/jobs/runners/pulsar.py
@@ -0,0 +1,707 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+
+import logging
+
+from galaxy import model
+from galaxy.jobs.runners import AsynchronousJobState, AsynchronousJobRunner
+from galaxy.jobs import ComputeEnvironment
+from galaxy.jobs import JobDestination
+from galaxy.jobs.command_factory import build_command
+from galaxy.tools.deps import dependencies
+from galaxy.util import string_as_bool_or_none
+from galaxy.util.bunch import Bunch
+from galaxy.util import specs
+
+import errno
+from time import sleep
+import os
+
+from pulsar.client import build_client_manager
+from pulsar.client import url_to_destination_params
+from pulsar.client import finish_job as pulsar_finish_job
+from pulsar.client import submit_job as pulsar_submit_job
+from pulsar.client import ClientJobDescription
+from pulsar.client import PulsarOutputs
+from pulsar.client import ClientOutputs
+from pulsar.client import PathMapper
+
+log = logging.getLogger( __name__ )
+
+__all__ = [ 'PulsarLegacyJobRunner', 'PulsarRESTJobRunner', 'PulsarMQJobRunner' ]
+
+NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE = "Pulsar misconfiguration - Pulsar client configured to set metadata remotely, but remote Pulsar isn't properly configured with a galaxy_home directory."
+NO_REMOTE_DATATYPES_CONFIG = "Pulsar client is configured to use remote datatypes configuration when setting metadata externally, but Pulsar is not configured with this information. Defaulting to datatypes_conf.xml."
+GENERIC_REMOTE_ERROR = "Failed to communicate with remote job server."
+
+# Is there a good way to infer some default for this? Can only use
+# url_for from web threads. https://gist.github.com/jmchilton/9098762
+DEFAULT_GALAXY_URL = "http://localhost:8080"
+
+PULSAR_PARAM_SPECS = dict(
+ transport=dict(
+ map=specs.to_str_or_none,
+ valid=specs.is_in("urllib", "curl", None),
+ default=None
+ ),
+ cache=dict(
+ map=specs.to_bool_or_none,
+ default=None,
+ ),
+ amqp_url=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ galaxy_url=dict(
+ map=specs.to_str_or_none,
+ default=DEFAULT_GALAXY_URL,
+ ),
+ manager=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_consumer_timeout=dict(
+ map=lambda val: None if val == "None" else float(val),
+ default=None,
+ ),
+ amqp_connect_ssl_ca_certs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_keyfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_certfile=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ amqp_connect_ssl_cert_reqs=dict(
+ map=specs.to_str_or_none,
+ default=None,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Producer.…
+ amqp_publish_retry=dict(
+ map=specs.to_bool,
+ default=False,
+ ),
+ amqp_publish_priority=dict(
+ map=int,
+ valid=lambda x: 0 <= x and x <= 9,
+ default=0,
+ ),
+ # http://kombu.readthedocs.org/en/latest/reference/kombu.html#kombu.Exchange.…
+ amqp_publish_delivery_mode=dict(
+ map=str,
+ valid=specs.is_in("transient", "persistent"),
+ default="persistent",
+ ),
+ amqp_publish_retry_max_retries=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_start=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_step=dict(
+ map=int,
+ default=None,
+ ),
+ amqp_publish_retry_interval_max=dict(
+ map=int,
+ default=None,
+ ),
+)
+
+
+PARAMETER_SPECIFICATION_REQUIRED = object()
+PARAMETER_SPECIFICATION_IGNORED = object()
+
+
+class PulsarJobRunner( AsynchronousJobRunner ):
+ """
+ Pulsar Job Runner
+ """
+ runner_name = "PulsarJobRunner"
+
+ def __init__( self, app, nworkers, **kwds ):
+ """Start the job runner """
+ super( PulsarJobRunner, self ).__init__( app, nworkers, runner_param_specs=PULSAR_PARAM_SPECS, **kwds )
+ self._init_worker_threads()
+ galaxy_url = self.runner_params.galaxy_url
+ if galaxy_url:
+ galaxy_url = galaxy_url.rstrip("/")
+ self.galaxy_url = galaxy_url
+ self.__init_client_manager()
+ self._monitor()
+
+ def _monitor( self ):
+ # Extension point allow MQ variant to setup callback instead
+ self._init_monitor_thread()
+
+ def __init_client_manager( self ):
+ client_manager_kwargs = {}
+ for kwd in 'manager', 'cache', 'transport':
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ for kwd in self.runner_params.keys():
+ if kwd.startswith( 'amqp_' ):
+ client_manager_kwargs[ kwd ] = self.runner_params[ kwd ]
+ self.client_manager = build_client_manager(**client_manager_kwargs)
+
+ def url_to_destination( self, url ):
+ """Convert a legacy URL to a job destination"""
+ return JobDestination( runner="pulsar", params=url_to_destination_params( url ) )
+
+ def check_watched_item(self, job_state):
+ try:
+ client = self.get_client_from_state(job_state)
+ status = client.get_status()
+ except Exception:
+ # An orphaned job was put into the queue at app startup, so remote server went down
+ # either way we are done I guess.
+ self.mark_as_finished(job_state)
+ return None
+ job_state = self._update_job_state_for_status(job_state, status)
+ return job_state
+
+ def _update_job_state_for_status(self, job_state, pulsar_status):
+ if pulsar_status == "complete":
+ self.mark_as_finished(job_state)
+ return None
+ if pulsar_status == "failed":
+ self.fail_job(job_state)
+ return None
+ if pulsar_status == "running" and not job_state.running:
+ job_state.running = True
+ job_state.job_wrapper.change_state( model.Job.states.RUNNING )
+ return job_state
+
+ def queue_job(self, job_wrapper):
+ job_destination = job_wrapper.job_destination
+ self._populate_parameter_defaults( job_destination )
+
+ command_line, client, remote_job_config, compute_environment = self.__prepare_job( job_wrapper, job_destination )
+
+ if not command_line:
+ return
+
+ try:
+ dependencies_description = PulsarJobRunner.__dependencies_description( client, job_wrapper )
+ rewrite_paths = not PulsarJobRunner.__rewrite_parameters( client )
+ unstructured_path_rewrites = {}
+ if compute_environment:
+ unstructured_path_rewrites = compute_environment.unstructured_path_rewrites
+
+ client_job_description = ClientJobDescription(
+ command_line=command_line,
+ input_files=self.get_input_files(job_wrapper),
+ client_outputs=self.__client_outputs(client, job_wrapper),
+ working_directory=job_wrapper.working_directory,
+ tool=job_wrapper.tool,
+ config_files=job_wrapper.extra_filenames,
+ dependencies_description=dependencies_description,
+ env=client.env,
+ rewrite_paths=rewrite_paths,
+ arbitrary_files=unstructured_path_rewrites,
+ )
+ job_id = pulsar_submit_job(client, client_job_description, remote_job_config)
+ log.info("Pulsar job submitted with job_id %s" % job_id)
+ job_wrapper.set_job_destination( job_destination, job_id )
+ job_wrapper.change_state( model.Job.states.QUEUED )
+ except Exception:
+ job_wrapper.fail( "failure running job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+ return
+
+ pulsar_job_state = AsynchronousJobState()
+ pulsar_job_state.job_wrapper = job_wrapper
+ pulsar_job_state.job_id = job_id
+ pulsar_job_state.old_state = True
+ pulsar_job_state.running = False
+ pulsar_job_state.job_destination = job_destination
+ self.monitor_job(pulsar_job_state)
+
+ def __prepare_job(self, job_wrapper, job_destination):
+ """ Build command-line and Pulsar client for this job. """
+ command_line = None
+ client = None
+ remote_job_config = None
+ compute_environment = None
+ try:
+ client = self.get_client_from_wrapper(job_wrapper)
+ tool = job_wrapper.tool
+ remote_job_config = client.setup(tool.id, tool.version)
+ rewrite_parameters = PulsarJobRunner.__rewrite_parameters( client )
+ prepare_kwds = {}
+ if rewrite_parameters:
+ compute_environment = PulsarComputeEnvironment( client, job_wrapper, remote_job_config )
+ prepare_kwds[ 'compute_environment' ] = compute_environment
+ job_wrapper.prepare( **prepare_kwds )
+ self.__prepare_input_files_locally(job_wrapper)
+ remote_metadata = PulsarJobRunner.__remote_metadata( client )
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( client )
+ metadata_kwds = self.__build_metadata_configuration(client, job_wrapper, remote_metadata, remote_job_config)
+ remote_command_params = dict(
+ working_directory=remote_job_config['working_directory'],
+ metadata_kwds=metadata_kwds,
+ dependency_resolution=dependency_resolution,
+ )
+ remote_working_directory = remote_job_config['working_directory']
+ # TODO: Following defs work for Pulsar, always worked for Pulsar but should be
+ # calculated at some other level.
+ remote_job_directory = os.path.abspath(os.path.join(remote_working_directory, os.path.pardir))
+ remote_tool_directory = os.path.abspath(os.path.join(remote_job_directory, "tool_files"))
+ container = self._find_container(
+ job_wrapper,
+ compute_working_directory=remote_working_directory,
+ compute_tool_directory=remote_tool_directory,
+ compute_job_directory=remote_job_directory,
+ )
+ command_line = build_command(
+ self,
+ job_wrapper=job_wrapper,
+ container=container,
+ include_metadata=remote_metadata,
+ include_work_dir_outputs=False,
+ remote_command_params=remote_command_params,
+ )
+ except Exception:
+ job_wrapper.fail( "failure preparing job", exception=True )
+ log.exception("failure running job %d" % job_wrapper.job_id)
+
+ # If we were able to get a command line, run the job
+ if not command_line:
+ job_wrapper.finish( '', '' )
+
+ return command_line, client, remote_job_config, compute_environment
+
+ def __prepare_input_files_locally(self, job_wrapper):
+ """Run task splitting commands locally."""
+ prepare_input_files_cmds = getattr(job_wrapper, 'prepare_input_files_cmds', None)
+ if prepare_input_files_cmds is not None:
+ for cmd in prepare_input_files_cmds: # run the commands to stage the input files
+ if 0 != os.system(cmd):
+ raise Exception('Error running file staging command: %s' % cmd)
+ job_wrapper.prepare_input_files_cmds = None # prevent them from being used in-line
+
+ def _populate_parameter_defaults( self, job_destination ):
+ updated = False
+ params = job_destination.params
+ for key, value in self.destination_defaults.iteritems():
+ if key in params:
+ if value is PARAMETER_SPECIFICATION_IGNORED:
+ log.warn( "Pulsar runner in selected configuration ignores parameter %s" % key )
+ continue
+ #if self.runner_params.get( key, None ):
+ # # Let plugin define defaults for some parameters -
+ # # for instance that way jobs_directory can be
+ # # configured next to AMQP url (where it belongs).
+ # params[ key ] = self.runner_params[ key ]
+ # continue
+
+ if not value:
+ continue
+
+ if value is PARAMETER_SPECIFICATION_REQUIRED:
+ raise Exception( "Pulsar destination does not define required parameter %s" % key )
+ elif value is not PARAMETER_SPECIFICATION_IGNORED:
+ params[ key ] = value
+ updated = True
+ return updated
+
+ def get_output_files(self, job_wrapper):
+ output_paths = job_wrapper.get_output_fnames()
+ return [ str( o ) for o in output_paths ] # Force job_path from DatasetPath objects.
+
+ def get_input_files(self, job_wrapper):
+ input_paths = job_wrapper.get_input_paths()
+ return [ str( i ) for i in input_paths ] # Force job_path from DatasetPath objects.
+
+ def get_client_from_wrapper(self, job_wrapper):
+ job_id = job_wrapper.job_id
+ if hasattr(job_wrapper, 'task_id'):
+ job_id = "%s_%s" % (job_id, job_wrapper.task_id)
+ params = job_wrapper.job_destination.params.copy()
+ for key, value in params.iteritems():
+ if value:
+ params[key] = model.User.expand_user_properties( job_wrapper.get_job().user, value )
+
+ env = getattr( job_wrapper.job_destination, "env", [] )
+ return self.get_client( params, job_id, env )
+
+ def get_client_from_state(self, job_state):
+ job_destination_params = job_state.job_destination.params
+ job_id = job_state.job_id
+ return self.get_client( job_destination_params, job_id )
+
+ def get_client( self, job_destination_params, job_id, env=[] ):
+ # Cannot use url_for outside of web thread.
+ #files_endpoint = url_for( controller="job_files", job_id=encoded_job_id )
+
+ encoded_job_id = self.app.security.encode_id(job_id)
+ job_key = self.app.security.encode_id( job_id, kind="jobs_files" )
+ files_endpoint = "%s/api/jobs/%s/files?job_key=%s" % (
+ self.galaxy_url,
+ encoded_job_id,
+ job_key
+ )
+ get_client_kwds = dict(
+ job_id=str( job_id ),
+ files_endpoint=files_endpoint,
+ env=env
+ )
+ return self.client_manager.get_client( job_destination_params, **get_client_kwds )
+
+ def finish_job( self, job_state ):
+ stderr = stdout = ''
+ job_wrapper = job_state.job_wrapper
+ try:
+ client = self.get_client_from_state(job_state)
+ run_results = client.full_status()
+ remote_working_directory = run_results.get("working_directory", None)
+ stdout = run_results.get('stdout', '')
+ stderr = run_results.get('stderr', '')
+ exit_code = run_results.get('returncode', None)
+ pulsar_outputs = PulsarOutputs.from_status_response(run_results)
+ # Use Pulsar client code to transfer/copy files back
+ # and cleanup job if needed.
+ completed_normally = \
+ job_wrapper.get_state() not in [ model.Job.states.ERROR, model.Job.states.DELETED ]
+ cleanup_job = self.app.config.cleanup_job
+ client_outputs = self.__client_outputs(client, job_wrapper)
+ finish_args = dict( client=client,
+ job_completed_normally=completed_normally,
+ cleanup_job=cleanup_job,
+ client_outputs=client_outputs,
+ pulsar_outputs=pulsar_outputs )
+ failed = pulsar_finish_job( **finish_args )
+ if failed:
+ job_wrapper.fail("Failed to find or download one or more job outputs from remote server.", exception=True)
+ except Exception:
+ message = GENERIC_REMOTE_ERROR
+ job_wrapper.fail( message, exception=True )
+ log.exception("failure finishing job %d" % job_wrapper.job_id)
+ return
+ if not PulsarJobRunner.__remote_metadata( client ):
+ self._handle_metadata_externally( job_wrapper, resolve_requirements=True )
+ # Finish the job
+ try:
+ job_wrapper.finish(
+ stdout,
+ stderr,
+ exit_code,
+ remote_working_directory=remote_working_directory
+ )
+ except Exception:
+ log.exception("Job wrapper finish method failed")
+ job_wrapper.fail("Unable to finish job", exception=True)
+
+ def fail_job( self, job_state ):
+ """
+ Seperated out so we can use the worker threads for it.
+ """
+ self.stop_job( self.sa_session.query( self.app.model.Job ).get( job_state.job_wrapper.job_id ) )
+ job_state.job_wrapper.fail( getattr( job_state, "fail_message", GENERIC_REMOTE_ERROR ) )
+
+ def check_pid( self, pid ):
+ try:
+ os.kill( pid, 0 )
+ return True
+ except OSError, e:
+ if e.errno == errno.ESRCH:
+ log.debug( "check_pid(): PID %d is dead" % pid )
+ else:
+ log.warning( "check_pid(): Got errno %s when attempting to check PID %d: %s" % ( errno.errorcode[e.errno], pid, e.strerror ) )
+ return False
+
+ def stop_job( self, job ):
+ #if our local job has JobExternalOutputMetadata associated, then our primary job has to have already finished
+ job_ext_output_metadata = job.get_external_output_metadata()
+ if job_ext_output_metadata:
+ pid = job_ext_output_metadata[0].job_runner_external_pid # every JobExternalOutputMetadata has a pid set, we just need to take from one of them
+ if pid in [ None, '' ]:
+ log.warning( "stop_job(): %s: no PID in database for job, unable to stop" % job.id )
+ return
+ pid = int( pid )
+ if not self.check_pid( pid ):
+ log.warning( "stop_job(): %s: PID %d was already dead or can't be signaled" % ( job.id, pid ) )
+ return
+ for sig in [ 15, 9 ]:
+ try:
+ os.killpg( pid, sig )
+ except OSError, e:
+ log.warning( "stop_job(): %s: Got errno %s when attempting to signal %d to PID %d: %s" % ( job.id, errno.errorcode[e.errno], sig, pid, e.strerror ) )
+ return # give up
+ sleep( 2 )
+ if not self.check_pid( pid ):
+ log.debug( "stop_job(): %s: PID %d successfully killed with signal %d" % ( job.id, pid, sig ) )
+ return
+ else:
+ log.warning( "stop_job(): %s: PID %d refuses to die after signaling TERM/KILL" % ( job.id, pid ) )
+ else:
+ # Remote kill
+ pulsar_url = job.job_runner_name
+ job_id = job.job_runner_external_id
+ log.debug("Attempt remote Pulsar kill of job with url %s and id %s" % (pulsar_url, job_id))
+ client = self.get_client(job.destination_params, job_id)
+ client.kill()
+
+ def recover( self, job, job_wrapper ):
+ """Recovers jobs stuck in the queued/running state when Galaxy started"""
+ job_state = self._job_state( job, job_wrapper )
+ job_wrapper.command_line = job.get_command_line()
+ state = job.get_state()
+ if state in [model.Job.states.RUNNING, model.Job.states.QUEUED]:
+ log.debug( "(Pulsar/%s) is still in running state, adding to the Pulsar queue" % ( job.get_id()) )
+ job_state.old_state = True
+ job_state.running = state == model.Job.states.RUNNING
+ self.monitor_queue.put( job_state )
+
+ def shutdown( self ):
+ super( PulsarJobRunner, self ).shutdown()
+ self.client_manager.shutdown()
+
+ def _job_state( self, job, job_wrapper ):
+ job_state = AsynchronousJobState()
+ # TODO: Determine why this is set when using normal message queue updates
+ # but not CLI submitted MQ updates...
+ raw_job_id = job.get_job_runner_external_id() or job_wrapper.job_id
+ job_state.job_id = str( raw_job_id )
+ job_state.runner_url = job_wrapper.get_job_runner_url()
+ job_state.job_destination = job_wrapper.job_destination
+ job_state.job_wrapper = job_wrapper
+ return job_state
+
+ def __client_outputs( self, client, job_wrapper ):
+ work_dir_outputs = self.get_work_dir_outputs( job_wrapper )
+ output_files = self.get_output_files( job_wrapper )
+ client_outputs = ClientOutputs(
+ working_directory=job_wrapper.working_directory,
+ work_dir_outputs=work_dir_outputs,
+ output_files=output_files,
+ version_file=job_wrapper.get_version_string_path(),
+ )
+ return client_outputs
+
+ @staticmethod
+ def __dependencies_description( pulsar_client, job_wrapper ):
+ dependency_resolution = PulsarJobRunner.__dependency_resolution( pulsar_client )
+ remote_dependency_resolution = dependency_resolution == "remote"
+ if not remote_dependency_resolution:
+ return None
+ requirements = job_wrapper.tool.requirements or []
+ installed_tool_dependencies = job_wrapper.tool.installed_tool_dependencies or []
+ return dependencies.DependenciesDescription(
+ requirements=requirements,
+ installed_tool_dependencies=installed_tool_dependencies,
+ )
+
+ @staticmethod
+ def __dependency_resolution( pulsar_client ):
+ dependency_resolution = pulsar_client.destination_params.get( "dependency_resolution", "local" )
+ if dependency_resolution not in ["none", "local", "remote"]:
+ raise Exception("Unknown dependency_resolution value encountered %s" % dependency_resolution)
+ return dependency_resolution
+
+ @staticmethod
+ def __remote_metadata( pulsar_client ):
+ remote_metadata = string_as_bool_or_none( pulsar_client.destination_params.get( "remote_metadata", False ) )
+ return remote_metadata
+
+ @staticmethod
+ def __use_remote_datatypes_conf( pulsar_client ):
+ """ When setting remote metadata, use integrated datatypes from this
+ Galaxy instance or use the datatypes config configured via the remote
+ Pulsar.
+
+ Both options are broken in different ways for same reason - datatypes
+ may not match. One can push the local datatypes config to the remote
+ server - but there is no guarentee these datatypes will be defined
+ there. Alternatively, one can use the remote datatype config - but
+ there is no guarentee that it will contain all the datatypes available
+ to this Galaxy.
+ """
+ use_remote_datatypes = string_as_bool_or_none( pulsar_client.destination_params.get( "use_remote_datatypes", False ) )
+ return use_remote_datatypes
+
+ @staticmethod
+ def __rewrite_parameters( pulsar_client ):
+ return string_as_bool_or_none( pulsar_client.destination_params.get( "rewrite_parameters", False ) ) or False
+
+ def __build_metadata_configuration(self, client, job_wrapper, remote_metadata, remote_job_config):
+ metadata_kwds = {}
+ if remote_metadata:
+ remote_system_properties = remote_job_config.get("system_properties", {})
+ remote_galaxy_home = remote_system_properties.get("galaxy_home", None)
+ if not remote_galaxy_home:
+ raise Exception(NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE)
+ metadata_kwds['exec_dir'] = remote_galaxy_home
+ outputs_directory = remote_job_config['outputs_directory']
+ configs_directory = remote_job_config['configs_directory']
+ working_directory = remote_job_config['working_directory']
+ # For metadata calculation, we need to build a list of of output
+ # file objects with real path indicating location on Galaxy server
+ # and false path indicating location on compute server. Since the
+ # Pulsar disables from_work_dir copying as part of the job command
+ # line we need to take the list of output locations on the Pulsar
+ # server (produced by self.get_output_files(job_wrapper)) and for
+ # each work_dir output substitute the effective path on the Pulsar
+ # server relative to the remote working directory as the
+ # false_path to send the metadata command generation module.
+ work_dir_outputs = self.get_work_dir_outputs(job_wrapper, job_working_directory=working_directory)
+ outputs = [Bunch(false_path=os.path.join(outputs_directory, os.path.basename(path)), real_path=path) for path in self.get_output_files(job_wrapper)]
+ for output in outputs:
+ for pulsar_workdir_path, real_path in work_dir_outputs:
+ if real_path == output.real_path:
+ output.false_path = pulsar_workdir_path
+ metadata_kwds['output_fnames'] = outputs
+ metadata_kwds['compute_tmp_dir'] = working_directory
+ metadata_kwds['config_root'] = remote_galaxy_home
+ default_config_file = os.path.join(remote_galaxy_home, 'universe_wsgi.ini')
+ metadata_kwds['config_file'] = remote_system_properties.get('galaxy_config_file', default_config_file)
+ metadata_kwds['dataset_files_path'] = remote_system_properties.get('galaxy_dataset_files_path', None)
+ if PulsarJobRunner.__use_remote_datatypes_conf( client ):
+ remote_datatypes_config = remote_system_properties.get('galaxy_datatypes_config_file', None)
+ if not remote_datatypes_config:
+ log.warn(NO_REMOTE_DATATYPES_CONFIG)
+ remote_datatypes_config = os.path.join(remote_galaxy_home, 'datatypes_conf.xml')
+ metadata_kwds['datatypes_config'] = remote_datatypes_config
+ else:
+ integrates_datatypes_config = self.app.datatypes_registry.integrated_datatypes_configs
+ # Ensure this file gets pushed out to the remote config dir.
+ job_wrapper.extra_filenames.append(integrates_datatypes_config)
+
+ metadata_kwds['datatypes_config'] = os.path.join(configs_directory, os.path.basename(integrates_datatypes_config))
+ return metadata_kwds
+
+
+class PulsarLegacyJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ rewrite_parameters="false",
+ dependency_resolution="local",
+ )
+
+
+class PulsarMQJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="remote_transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ jobs_directory=PARAMETER_SPECIFICATION_REQUIRED,
+ url=PARAMETER_SPECIFICATION_IGNORED,
+ private_token=PARAMETER_SPECIFICATION_IGNORED
+ )
+
+ def _monitor( self ):
+ # This is a message queue driven runner, don't monitor
+ # just setup required callback.
+ self.client_manager.ensure_has_status_update_callback(self.__async_update)
+
+ def __async_update( self, full_status ):
+ job_id = None
+ try:
+ job_id = full_status[ "job_id" ]
+ job, job_wrapper = self.app.job_manager.job_handler.job_queue.job_pair_for_id( job_id )
+ job_state = self._job_state( job, job_wrapper )
+ self._update_job_state_for_status(job_state, full_status[ "status" ] )
+ except Exception:
+ log.exception( "Failed to update Pulsar job status for job_id %s" % job_id )
+ raise
+ # Nothing else to do? - Attempt to fail the job?
+
+
+class PulsarRESTJobRunner( PulsarJobRunner ):
+ destination_defaults = dict(
+ default_file_action="transfer",
+ rewrite_parameters="true",
+ dependency_resolution="remote",
+ url=PARAMETER_SPECIFICATION_REQUIRED,
+ )
+
+
+class PulsarComputeEnvironment( ComputeEnvironment ):
+
+ def __init__( self, pulsar_client, job_wrapper, remote_job_config ):
+ self.pulsar_client = pulsar_client
+ self.job_wrapper = job_wrapper
+ self.local_path_config = job_wrapper.default_compute_environment()
+ self.unstructured_path_rewrites = {}
+ # job_wrapper.prepare is going to expunge the job backing the following
+ # computations, so precalculate these paths.
+ self._wrapper_input_paths = self.local_path_config.input_paths()
+ self._wrapper_output_paths = self.local_path_config.output_paths()
+ self.path_mapper = PathMapper(pulsar_client, remote_job_config, self.local_path_config.working_directory())
+ self._config_directory = remote_job_config[ "configs_directory" ]
+ self._working_directory = remote_job_config[ "working_directory" ]
+ self._sep = remote_job_config[ "system_properties" ][ "separator" ]
+ self._tool_dir = remote_job_config[ "tools_directory" ]
+ version_path = self.local_path_config.version_path()
+ new_version_path = self.path_mapper.remote_version_path_rewrite(version_path)
+ if new_version_path:
+ version_path = new_version_path
+ self._version_path = version_path
+
+ def output_paths( self ):
+ local_output_paths = self._wrapper_output_paths
+
+ results = []
+ for local_output_path in local_output_paths:
+ wrapper_path = str( local_output_path )
+ remote_path = self.path_mapper.remote_output_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_output_path, remote_path ) )
+ return results
+
+ def input_paths( self ):
+ local_input_paths = self._wrapper_input_paths
+
+ results = []
+ for local_input_path in local_input_paths:
+ wrapper_path = str( local_input_path )
+ # This will over-copy in some cases. For instance in the case of task
+ # splitting, this input will be copied even though only the work dir
+ # input will actually be used.
+ remote_path = self.path_mapper.remote_input_path_rewrite( wrapper_path )
+ results.append( self._dataset_path( local_input_path, remote_path ) )
+ return results
+
+ def _dataset_path( self, local_dataset_path, remote_path ):
+ remote_extra_files_path = None
+ if remote_path:
+ remote_extra_files_path = "%s_files" % remote_path[ 0:-len( ".dat" ) ]
+ return local_dataset_path.with_path_for_job( remote_path, remote_extra_files_path )
+
+ def working_directory( self ):
+ return self._working_directory
+
+ def config_directory( self ):
+ return self._config_directory
+
+ def new_file_path( self ):
+ return self.working_directory() # Problems with doing this?
+
+ def sep( self ):
+ return self._sep
+
+ def version_path( self ):
+ return self._version_path
+
+ def rewriter( self, parameter_value ):
+ unstructured_path_rewrites = self.unstructured_path_rewrites
+ if parameter_value in unstructured_path_rewrites:
+ # Path previously mapped, use previous mapping.
+ return unstructured_path_rewrites[ parameter_value ]
+ if parameter_value in unstructured_path_rewrites.itervalues():
+ # Path is a rewritten remote path (this might never occur,
+ # consider dropping check...)
+ return parameter_value
+
+ rewrite, new_unstructured_path_rewrites = self.path_mapper.check_for_arbitrary_rewrite( parameter_value )
+ if rewrite:
+ unstructured_path_rewrites.update(new_unstructured_path_rewrites)
+ return rewrite
+ else:
+ # Did need to rewrite, use original path or value.
+ return parameter_value
+
+ def unstructured_path_rewriter( self ):
+ return self.rewriter
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/__init__.py
--- a/lib/galaxy/jobs/runners/util/__init__.py
+++ b/lib/galaxy/jobs/runners/util/__init__.py
@@ -1,7 +1,7 @@
"""
This module and its submodules contains utilities for running external
processes and interfacing with job managers. This module should contain
-functionality shared between Galaxy and the LWR.
+functionality shared between Galaxy and the Pulsar.
"""
from galaxy.util.bunch import Bunch
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/factory.py
--- a/lib/galaxy/jobs/runners/util/cli/factory.py
+++ b/lib/galaxy/jobs/runners/util/cli/factory.py
@@ -5,7 +5,7 @@
)
code_dir = 'lib'
except ImportError:
- from lwr.managers.util.cli import (
+ from pulsar.managers.util.cli import (
CliInterface,
split_params
)
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/job/slurm.py
--- a/lib/galaxy/jobs/runners/util/cli/job/slurm.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/slurm.py
@@ -5,7 +5,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/jobs/runners/util/cli/job/torque.py
--- a/lib/galaxy/jobs/runners/util/cli/job/torque.py
+++ b/lib/galaxy/jobs/runners/util/cli/job/torque.py
@@ -7,7 +7,7 @@
from galaxy.model import Job
job_states = Job.states
except ImportError:
- # Not in Galaxy, map Galaxy job states to LWR ones.
+ # Not in Galaxy, map Galaxy job states to Pulsar ones.
from galaxy.util import enum
job_states = enum(RUNNING='running', OK='complete', QUEUED='queued')
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/__init__.py
--- a/lib/galaxy/objectstore/__init__.py
+++ b/lib/galaxy/objectstore/__init__.py
@@ -623,9 +623,9 @@
elif store == 'irods':
from .rods import IRODSObjectStore
return IRODSObjectStore(config=config, config_xml=config_xml)
- elif store == 'lwr':
- from .lwr import LwrObjectStore
- return LwrObjectStore(config=config, config_xml=config_xml)
+ elif store == 'pulsar':
+ from .pulsar import PulsarObjectStore
+ return PulsarObjectStore(config=config, config_xml=config_xml)
else:
log.error("Unrecognized object store definition: {0}".format(store))
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/lwr.py
--- a/lib/galaxy/objectstore/lwr.py
+++ /dev/null
@@ -1,76 +0,0 @@
-from __future__ import absolute_import # Need to import lwr_client absolutely.
-from ..objectstore import ObjectStore
-try:
- from galaxy.jobs.runners.lwr_client.manager import ObjectStoreClientManager
-except ImportError:
- from lwr.lwr_client.manager import ObjectStoreClientManager
-
-
-class LwrObjectStore(ObjectStore):
- """
- Object store implementation that delegates to a remote LWR server.
-
- This may be more aspirational than practical for now, it would be good to
- Galaxy to a point that a handler thread could be setup that doesn't attempt
- to access the disk files returned by a (this) object store - just passing
- them along to the LWR unmodified. That modification - along with this
- implementation and LWR job destinations would then allow Galaxy to fully
- manage jobs on remote servers with completely different mount points.
-
- This implementation should be considered beta and may be dropped from
- Galaxy at some future point or significantly modified.
- """
-
- def __init__(self, config, config_xml):
- self.lwr_client = self.__build_lwr_client(config_xml)
-
- def exists(self, obj, **kwds):
- return self.lwr_client.exists(**self.__build_kwds(obj, **kwds))
-
- def file_ready(self, obj, **kwds):
- return self.lwr_client.file_ready(**self.__build_kwds(obj, **kwds))
-
- def create(self, obj, **kwds):
- return self.lwr_client.create(**self.__build_kwds(obj, **kwds))
-
- def empty(self, obj, **kwds):
- return self.lwr_client.empty(**self.__build_kwds(obj, **kwds))
-
- def size(self, obj, **kwds):
- return self.lwr_client.size(**self.__build_kwds(obj, **kwds))
-
- def delete(self, obj, **kwds):
- return self.lwr_client.delete(**self.__build_kwds(obj, **kwds))
-
- # TODO: Optimize get_data.
- def get_data(self, obj, **kwds):
- return self.lwr_client.get_data(**self.__build_kwds(obj, **kwds))
-
- def get_filename(self, obj, **kwds):
- return self.lwr_client.get_filename(**self.__build_kwds(obj, **kwds))
-
- def update_from_file(self, obj, **kwds):
- return self.lwr_client.update_from_file(**self.__build_kwds(obj, **kwds))
-
- def get_store_usage_percent(self):
- return self.lwr_client.get_store_usage_percent()
-
- def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
- return None
-
- def __build_kwds(self, obj, **kwds):
- kwds['object_id'] = obj.id
- return kwds
- pass
-
- def __build_lwr_client(self, config_xml):
- url = config_xml.get("url")
- private_token = config_xml.get("private_token", None)
- transport = config_xml.get("transport", None)
- manager_options = dict(transport=transport)
- client_options = dict(url=url, private_token=private_token)
- lwr_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
- return lwr_client
-
- def shutdown(self):
- pass
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/objectstore/pulsar.py
--- /dev/null
+++ b/lib/galaxy/objectstore/pulsar.py
@@ -0,0 +1,73 @@
+from __future__ import absolute_import # Need to import pulsar_client absolutely.
+from ..objectstore import ObjectStore
+from pulsar.client.manager import ObjectStoreClientManager
+
+
+class PulsarObjectStore(ObjectStore):
+ """
+ Object store implementation that delegates to a remote Pulsar server.
+
+ This may be more aspirational than practical for now, it would be good to
+ Galaxy to a point that a handler thread could be setup that doesn't attempt
+ to access the disk files returned by a (this) object store - just passing
+ them along to the Pulsar unmodified. That modification - along with this
+ implementation and Pulsar job destinations would then allow Galaxy to fully
+ manage jobs on remote servers with completely different mount points.
+
+ This implementation should be considered beta and may be dropped from
+ Galaxy at some future point or significantly modified.
+ """
+
+ def __init__(self, config, config_xml):
+ self.pulsar_client = self.__build_pulsar_client(config_xml)
+
+ def exists(self, obj, **kwds):
+ return self.pulsar_client.exists(**self.__build_kwds(obj, **kwds))
+
+ def file_ready(self, obj, **kwds):
+ return self.pulsar_client.file_ready(**self.__build_kwds(obj, **kwds))
+
+ def create(self, obj, **kwds):
+ return self.pulsar_client.create(**self.__build_kwds(obj, **kwds))
+
+ def empty(self, obj, **kwds):
+ return self.pulsar_client.empty(**self.__build_kwds(obj, **kwds))
+
+ def size(self, obj, **kwds):
+ return self.pulsar_client.size(**self.__build_kwds(obj, **kwds))
+
+ def delete(self, obj, **kwds):
+ return self.pulsar_client.delete(**self.__build_kwds(obj, **kwds))
+
+ # TODO: Optimize get_data.
+ def get_data(self, obj, **kwds):
+ return self.pulsar_client.get_data(**self.__build_kwds(obj, **kwds))
+
+ def get_filename(self, obj, **kwds):
+ return self.pulsar_client.get_filename(**self.__build_kwds(obj, **kwds))
+
+ def update_from_file(self, obj, **kwds):
+ return self.pulsar_client.update_from_file(**self.__build_kwds(obj, **kwds))
+
+ def get_store_usage_percent(self):
+ return self.pulsar_client.get_store_usage_percent()
+
+ def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None):
+ return None
+
+ def __build_kwds(self, obj, **kwds):
+ kwds['object_id'] = obj.id
+ return kwds
+ pass
+
+ def __build_pulsar_client(self, config_xml):
+ url = config_xml.get("url")
+ private_token = config_xml.get("private_token", None)
+ transport = config_xml.get("transport", None)
+ manager_options = dict(transport=transport)
+ client_options = dict(url=url, private_token=private_token)
+ pulsar_client = ObjectStoreClientManager(**manager_options).get_client(client_options)
+ return pulsar_client
+
+ def shutdown(self):
+ pass
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/galaxy/tools/deps/dependencies.py
--- a/lib/galaxy/tools/deps/dependencies.py
+++ b/lib/galaxy/tools/deps/dependencies.py
@@ -8,7 +8,7 @@
related context required to resolve dependencies via the
ToolShedPackageDependencyResolver.
- This is meant to enable remote resolution of dependencies, by the LWR or
+ This is meant to enable remote resolution of dependencies, by the Pulsar or
other potential remote execution mechanisms.
"""
@@ -39,7 +39,7 @@
@staticmethod
def _toolshed_install_dependency_from_dict(as_dict):
- # Rather than requiring full models in LWR, just use simple objects
+ # Rather than requiring full models in Pulsar, just use simple objects
# containing only properties and associations used to resolve
# dependencies for tool execution.
repository_object = bunch.Bunch(
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/__init__.py
--- /dev/null
+++ b/lib/pulsar/client/__init__.py
@@ -0,0 +1,62 @@
+"""
+pulsar client
+======
+
+This module contains logic for interfacing with an external Pulsar server.
+
+------------------
+Configuring Galaxy
+------------------
+
+Galaxy job runners are configured in Galaxy's ``job_conf.xml`` file. See ``job_conf.xml.sample_advanced``
+in your Galaxy code base or on
+`Bitbucket <https://bitbucket.org/galaxy/galaxy-dist/src/tip/job_conf.xml.sample_advanc…>`_
+for information on how to configure Galaxy to interact with the Pulsar.
+
+Galaxy also supports an older, less rich configuration of job runners directly
+in its main ``universe_wsgi.ini`` file. The following section describes how to
+configure Galaxy to communicate with the Pulsar in this legacy mode.
+
+Legacy
+------
+
+A Galaxy tool can be configured to be executed remotely via Pulsar by
+adding a line to the ``universe_wsgi.ini`` file under the
+``galaxy:tool_runners`` section with the format::
+
+ <tool_id> = pulsar://http://<pulsar_host>:<pulsar_port>
+
+As an example, if a host named remotehost is running the Pulsar server
+application on port ``8913``, then the tool with id ``test_tool`` can
+be configured to run remotely on remotehost by adding the following
+line to ``universe.ini``::
+
+ test_tool = pulsar://http://remotehost:8913
+
+Remember this must be added after the ``[galaxy:tool_runners]`` header
+in the ``universe.ini`` file.
+
+
+"""
+
+from .staging.down import finish_job
+from .staging.up import submit_job
+from .staging import ClientJobDescription
+from .staging import PulsarOutputs
+from .staging import ClientOutputs
+from .client import OutputNotFoundException
+from .manager import build_client_manager
+from .destination import url_to_destination_params
+from .path_mapper import PathMapper
+
+__all__ = [
+ build_client_manager,
+ OutputNotFoundException,
+ url_to_destination_params,
+ finish_job,
+ submit_job,
+ ClientJobDescription,
+ PulsarOutputs,
+ ClientOutputs,
+ PathMapper,
+]
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/action_mapper.py
--- /dev/null
+++ b/lib/pulsar/client/action_mapper.py
@@ -0,0 +1,567 @@
+from json import load
+from os import makedirs
+from os.path import exists
+from os.path import abspath
+from os.path import dirname
+from os.path import join
+from os.path import basename
+from os.path import sep
+import fnmatch
+from re import compile
+from re import escape
+import galaxy.util
+from galaxy.util.bunch import Bunch
+from .config_util import read_file
+from .util import directory_files
+from .util import unique_path_prefix
+from .transport import get_file
+from .transport import post_file
+
+
+DEFAULT_MAPPED_ACTION = 'transfer' # Not really clear to me what this should be, exception?
+DEFAULT_PATH_MAPPER_TYPE = 'prefix'
+
+STAGING_ACTION_REMOTE = "remote"
+STAGING_ACTION_LOCAL = "local"
+STAGING_ACTION_NONE = None
+STAGING_ACTION_DEFAULT = "default"
+
+# Poor man's enum.
+path_type = Bunch(
+ # Galaxy input datasets and extra files.
+ INPUT="input",
+ # Galaxy config and param files.
+ CONFIG="config",
+ # Files from tool's tool_dir (for now just wrapper if available).
+ TOOL="tool",
+ # Input work dir files - e.g. metadata files, task-split input files, etc..
+ WORKDIR="workdir",
+ # Galaxy output datasets in their final home.
+ OUTPUT="output",
+ # Galaxy from_work_dir output paths and other files (e.g. galaxy.json)
+ OUTPUT_WORKDIR="output_workdir",
+ # Other fixed tool parameter paths (likely coming from tool data, but not
+ # nessecarily). Not sure this is the best name...
+ UNSTRUCTURED="unstructured",
+)
+
+
+ACTION_DEFAULT_PATH_TYPES = [
+ path_type.INPUT,
+ path_type.CONFIG,
+ path_type.TOOL,
+ path_type.WORKDIR,
+ path_type.OUTPUT,
+ path_type.OUTPUT_WORKDIR,
+]
+ALL_PATH_TYPES = ACTION_DEFAULT_PATH_TYPES + [path_type.UNSTRUCTURED]
+
+
+class FileActionMapper(object):
+ """
+ Objects of this class define how paths are mapped to actions.
+
+ >>> json_string = r'''{"paths": [ \
+ {"path": "/opt/galaxy", "action": "none"}, \
+ {"path": "/galaxy/data", "action": "transfer"}, \
+ {"path": "/cool/bamfiles/**/*.bam", "action": "copy", "match_type": "glob"}, \
+ {"path": ".*/dataset_\\\\d+.dat", "action": "copy", "match_type": "regex"} \
+ ]}'''
+ >>> from tempfile import NamedTemporaryFile
+ >>> from os import unlink
+ >>> def mapper_for(default_action, config_contents):
+ ... f = NamedTemporaryFile(delete=False)
+ ... f.write(config_contents.encode('UTF-8'))
+ ... f.close()
+ ... mock_client = Bunch(default_file_action=default_action, action_config_path=f.name, files_endpoint=None)
+ ... mapper = FileActionMapper(mock_client)
+ ... mapper = FileActionMapper(config=mapper.to_dict()) # Serialize and deserialize it to make sure still works
+ ... unlink(f.name)
+ ... return mapper
+ >>> mapper = mapper_for(default_action='none', config_contents=json_string)
+ >>> # Test first config line above, implicit path prefix mapper
+ >>> action = mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input')
+ >>> action.action_type == u'none'
+ True
+ >>> action.staging_needed
+ False
+ >>> # Test another (2nd) mapper, this one with a different action
+ >>> action = mapper.action('/galaxy/data/files/000/dataset_1.dat', 'input')
+ >>> action.action_type == u'transfer'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Always at least copy work_dir outputs.
+ >>> action = mapper.action('/opt/galaxy/database/working_directory/45.sh', 'workdir')
+ >>> action.action_type == u'copy'
+ True
+ >>> action.staging_needed
+ True
+ >>> # Test glob mapper (matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam', 'input').action_type == u'copy'
+ True
+ >>> # Test glob mapper (non-matching test)
+ >>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam.bai', 'input').action_type == u'none'
+ True
+ >>> # Regex mapper test.
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'input').action_type == u'copy'
+ True
+ >>> # Doesn't map unstructured paths by default
+ >>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'none'
+ True
+ >>> input_only_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "input"} \
+ ] }''')
+ >>> input_only_mapper.action('/dataset_1.dat', 'input').action_type == u'transfer'
+ True
+ >>> input_only_mapper.action('/dataset_1.dat', 'output').action_type == u'none'
+ True
+ >>> unstructured_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
+ {"path": "/", "action": "transfer", "path_types": "*any*"} \
+ ] }''')
+ >>> unstructured_mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'transfer'
+ True
+ """
+
+ def __init__(self, client=None, config=None):
+ if config is None and client is None:
+ message = "FileActionMapper must be constructed from either a client or a config dictionary."
+ raise Exception(message)
+ if config is None:
+ config = self.__client_to_config(client)
+ self.default_action = config.get("default_action", "transfer")
+ self.mappers = mappers_from_dicts(config.get("paths", []))
+ self.files_endpoint = config.get("files_endpoint", None)
+
+ def action(self, path, type, mapper=None):
+ mapper = self.__find_mapper(path, type, mapper)
+ action_class = self.__action_class(path, type, mapper)
+ file_lister = DEFAULT_FILE_LISTER
+ action_kwds = {}
+ if mapper:
+ file_lister = mapper.file_lister
+ action_kwds = mapper.action_kwds
+ action = action_class(path, file_lister=file_lister, **action_kwds)
+ self.__process_action(action, type)
+ return action
+
+ def unstructured_mappers(self):
+ """ Return mappers that will map 'unstructured' files (i.e. go beyond
+ mapping inputs, outputs, and config files).
+ """
+ return filter(lambda m: path_type.UNSTRUCTURED in m.path_types, self.mappers)
+
+ def to_dict(self):
+ return dict(
+ default_action=self.default_action,
+ files_endpoint=self.files_endpoint,
+ paths=map(lambda m: m.to_dict(), self.mappers)
+ )
+
+ def __client_to_config(self, client):
+ action_config_path = client.action_config_path
+ if action_config_path:
+ config = read_file(action_config_path)
+ else:
+ config = dict()
+ config["default_action"] = client.default_file_action
+ config["files_endpoint"] = client.files_endpoint
+ return config
+
+ def __load_action_config(self, path):
+ config = load(open(path, 'rb'))
+ self.mappers = mappers_from_dicts(config.get('paths', []))
+
+ def __find_mapper(self, path, type, mapper=None):
+ if not mapper:
+ normalized_path = abspath(path)
+ for query_mapper in self.mappers:
+ if query_mapper.matches(normalized_path, type):
+ mapper = query_mapper
+ break
+ return mapper
+
+ def __action_class(self, path, type, mapper):
+ action_type = self.default_action if type in ACTION_DEFAULT_PATH_TYPES else "none"
+ if mapper:
+ action_type = mapper.action_type
+ if type in ["workdir", "output_workdir"] and action_type == "none":
+ # We are changing the working_directory relative to what
+ # Galaxy would use, these need to be copied over.
+ action_type = "copy"
+ action_class = actions.get(action_type, None)
+ if action_class is None:
+ message_template = "Unknown action_type encountered %s while trying to map path %s"
+ message_args = (action_type, path)
+ raise Exception(message_template % message_args)
+ return action_class
+
+ def __process_action(self, action, file_type):
+ """ Extension point to populate extra action information after an
+ action has been created.
+ """
+ if action.action_type == "remote_transfer":
+ url_base = self.files_endpoint
+ if not url_base:
+ raise Exception("Attempted to use remote_transfer action with defining a files_endpoint")
+ if "?" not in url_base:
+ url_base = "%s?" % url_base
+ # TODO: URL encode path.
+ url = "%s&path=%s&file_type=%s" % (url_base, action.path, file_type)
+ action.url = url
+
+REQUIRED_ACTION_KWD = object()
+
+
+class BaseAction(object):
+ action_spec = {}
+
+ def __init__(self, path, file_lister=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+
+ def unstructured_map(self, path_helper):
+ unstructured_map = self.file_lister.unstructured_map(self.path)
+ if self.staging_needed:
+ # To ensure uniqueness, prepend unique prefix to each name
+ prefix = unique_path_prefix(self.path)
+ for path, name in unstructured_map.iteritems():
+ unstructured_map[path] = join(prefix, name)
+ else:
+ path_rewrites = {}
+ for path in unstructured_map:
+ rewrite = self.path_rewrite(path_helper, path)
+ if rewrite:
+ path_rewrites[path] = rewrite
+ unstructured_map = path_rewrites
+ return unstructured_map
+
+ @property
+ def staging_needed(self):
+ return self.staging != STAGING_ACTION_NONE
+
+ @property
+ def staging_action_local(self):
+ return self.staging == STAGING_ACTION_LOCAL
+
+
+class NoneAction(BaseAction):
+ """ This action indicates the corresponding path does not require any
+ additional action. This should indicate paths that are available both on
+ the Pulsar client (i.e. Galaxy server) and remote Pulsar server with the same
+ paths. """
+ action_type = "none"
+ staging = STAGING_ACTION_NONE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return NoneAction(path=action_dict["path"])
+
+ def path_rewrite(self, path_helper, path=None):
+ return None
+
+
+class RewriteAction(BaseAction):
+ """ This actin indicates the Pulsar server should simply rewrite the path
+ to the specified file.
+ """
+ action_spec = dict(
+ source_directory=REQUIRED_ACTION_KWD,
+ destination_directory=REQUIRED_ACTION_KWD
+ )
+ action_type = "rewrite"
+ staging = STAGING_ACTION_NONE
+
+ def __init__(self, path, file_lister=None, source_directory=None, destination_directory=None):
+ self.path = path
+ self.file_lister = file_lister or DEFAULT_FILE_LISTER
+ self.source_directory = source_directory
+ self.destination_directory = destination_directory
+
+ def to_dict(self):
+ return dict(
+ path=self.path,
+ action_type=self.action_type,
+ source_directory=self.source_directory,
+ destination_directory=self.destination_directory,
+ )
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RewriteAction(
+ path=action_dict["path"],
+ source_directory=action_dict["source_directory"],
+ destination_directory=action_dict["destination_directory"],
+ )
+
+ def path_rewrite(self, path_helper, path=None):
+ if not path:
+ path = self.path
+ new_path = path_helper.from_posix_with_new_base(self.path, self.source_directory, self.destination_directory)
+ return None if new_path == self.path else new_path
+
+
+class TransferAction(BaseAction):
+ """ This actions indicates that the Pulsar client should initiate an HTTP
+ transfer of the corresponding path to the remote Pulsar server before
+ launching the job. """
+ action_type = "transfer"
+ staging = STAGING_ACTION_LOCAL
+
+
+class CopyAction(BaseAction):
+ """ This action indicates that the Pulsar client should execute a file system
+ copy of the corresponding path to the Pulsar staging directory prior to
+ launching the corresponding job. """
+ action_type = "copy"
+ staging = STAGING_ACTION_LOCAL
+
+
+class RemoteCopyAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_copy"
+ staging = STAGING_ACTION_REMOTE
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteCopyAction(path=action_dict["path"])
+
+ def write_to_path(self, path):
+ galaxy.util.copy_to_path(open(self.path, "rb"), path)
+
+ def write_from_path(self, pulsar_path):
+ destination = self.path
+ parent_directory = dirname(destination)
+ if not exists(parent_directory):
+ makedirs(parent_directory)
+ with open(pulsar_path, "rb") as f:
+ galaxy.util.copy_to_path(f, destination)
+
+
+class RemoteTransferAction(BaseAction):
+ """ This action indicates the Pulsar server should copy the file before
+ execution via direct file system copy. This is like a CopyAction, but
+ it indicates the action should occur on the Pulsar server instead of on
+ the client.
+ """
+ action_type = "remote_transfer"
+ staging = STAGING_ACTION_REMOTE
+
+ def __init__(self, path, file_lister=None, url=None):
+ super(RemoteTransferAction, self).__init__(path, file_lister=file_lister)
+ self.url = url
+
+ def to_dict(self):
+ return dict(path=self.path, action_type=self.action_type, url=self.url)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return RemoteTransferAction(path=action_dict["path"], url=action_dict["url"])
+
+ def write_to_path(self, path):
+ get_file(self.url, path)
+
+ def write_from_path(self, pulsar_path):
+ post_file(self.url, pulsar_path)
+
+
+class MessageAction(object):
+ """ Sort of pseudo action describing "files" store in memory and
+ transferred via message (HTTP, Python-call, MQ, etc...)
+ """
+ action_type = "message"
+ staging = STAGING_ACTION_DEFAULT
+
+ def __init__(self, contents, client=None):
+ self.contents = contents
+ self.client = client
+
+ @property
+ def staging_needed(self):
+ return True
+
+ @property
+ def staging_action_local(self):
+ # Ekkk, cannot be called if created through from_dict.
+ # Shouldn't be a problem the way it is used - but is an
+ # object design problem.
+ return self.client.prefer_local_staging
+
+ def to_dict(self):
+ return dict(contents=self.contents, action_type=MessageAction.action_type)
+
+ @classmethod
+ def from_dict(cls, action_dict):
+ return MessageAction(contents=action_dict["contents"])
+
+ def write_to_path(self, path):
+ open(path, "w").write(self.contents)
+
+
+DICTIFIABLE_ACTION_CLASSES = [RemoteCopyAction, RemoteTransferAction, MessageAction]
+
+
+def from_dict(action_dict):
+ action_type = action_dict.get("action_type", None)
+ target_class = None
+ for action_class in DICTIFIABLE_ACTION_CLASSES:
+ if action_type == action_class.action_type:
+ target_class = action_class
+ if not target_class:
+ message = "Failed to recover action from dictionary - invalid action type specified %s." % action_type
+ raise Exception(message)
+ return target_class.from_dict(action_dict)
+
+
+class BasePathMapper(object):
+
+ def __init__(self, config):
+ action_type = config.get('action', DEFAULT_MAPPED_ACTION)
+ action_class = actions.get(action_type, None)
+ action_kwds = action_class.action_spec.copy()
+ for key, value in action_kwds.items():
+ if key in config:
+ action_kwds[key] = config[key]
+ elif value is REQUIRED_ACTION_KWD:
+ message_template = "action_type %s requires key word argument %s"
+ message = message_template % (action_type, key)
+ raise Exception(message)
+ self.action_type = action_type
+ self.action_kwds = action_kwds
+ path_types_str = config.get('path_types', "*defaults*")
+ path_types_str = path_types_str.replace("*defaults*", ",".join(ACTION_DEFAULT_PATH_TYPES))
+ path_types_str = path_types_str.replace("*any*", ",".join(ALL_PATH_TYPES))
+ self.path_types = path_types_str.split(",")
+ self.file_lister = FileLister(config)
+
+ def matches(self, path, path_type):
+ path_type_matches = path_type in self.path_types
+ return path_type_matches and self._path_matches(path)
+
+ def _extend_base_dict(self, **kwds):
+ base_dict = dict(
+ action=self.action_type,
+ path_types=",".join(self.path_types),
+ match_type=self.match_type
+ )
+ base_dict.update(self.file_lister.to_dict())
+ base_dict.update(self.action_kwds)
+ base_dict.update(**kwds)
+ return base_dict
+
+
+class PrefixPathMapper(BasePathMapper):
+ match_type = 'prefix'
+
+ def __init__(self, config):
+ super(PrefixPathMapper, self).__init__(config)
+ self.prefix_path = abspath(config['path'])
+
+ def _path_matches(self, path):
+ return path.startswith(self.prefix_path)
+
+ def to_pattern(self):
+ pattern_str = "(%s%s[^\s,\"\']+)" % (escape(self.prefix_path), escape(sep))
+ return compile(pattern_str)
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.prefix_path)
+
+
+class GlobPathMapper(BasePathMapper):
+ match_type = 'glob'
+
+ def __init__(self, config):
+ super(GlobPathMapper, self).__init__(config)
+ self.glob_path = config['path']
+
+ def _path_matches(self, path):
+ return fnmatch.fnmatch(path, self.glob_path)
+
+ def to_pattern(self):
+ return compile(fnmatch.translate(self.glob_path))
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.glob_path)
+
+
+class RegexPathMapper(BasePathMapper):
+ match_type = 'regex'
+
+ def __init__(self, config):
+ super(RegexPathMapper, self).__init__(config)
+ self.pattern_raw = config['path']
+ self.pattern = compile(self.pattern_raw)
+
+ def _path_matches(self, path):
+ return self.pattern.match(path) is not None
+
+ def to_pattern(self):
+ return self.pattern
+
+ def to_dict(self):
+ return self._extend_base_dict(path=self.pattern_raw)
+
+MAPPER_CLASSES = [PrefixPathMapper, GlobPathMapper, RegexPathMapper]
+MAPPER_CLASS_DICT = dict(map(lambda c: (c.match_type, c), MAPPER_CLASSES))
+
+
+def mappers_from_dicts(mapper_def_list):
+ return map(lambda m: __mappper_from_dict(m), mapper_def_list)
+
+
+def __mappper_from_dict(mapper_dict):
+ map_type = mapper_dict.get('match_type', DEFAULT_PATH_MAPPER_TYPE)
+ return MAPPER_CLASS_DICT[map_type](mapper_dict)
+
+
+class FileLister(object):
+
+ def __init__(self, config):
+ self.depth = int(config.get("depth", "0"))
+
+ def to_dict(self):
+ return dict(
+ depth=self.depth
+ )
+
+ def unstructured_map(self, path):
+ depth = self.depth
+ if self.depth == 0:
+ return {path: basename(path)}
+ else:
+ while depth > 0:
+ path = dirname(path)
+ depth -= 1
+ return dict([(join(path, f), f) for f in directory_files(path)])
+
+DEFAULT_FILE_LISTER = FileLister(dict(depth=0))
+
+ACTION_CLASSES = [
+ NoneAction,
+ RewriteAction,
+ TransferAction,
+ CopyAction,
+ RemoteCopyAction,
+ RemoteTransferAction,
+]
+actions = dict([(clazz.action_type, clazz) for clazz in ACTION_CLASSES])
+
+
+__all__ = [
+ FileActionMapper,
+ path_type,
+ from_dict,
+ MessageAction,
+ RemoteTransferAction, # For testing
+]
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/amqp_exchange.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange.py
@@ -0,0 +1,139 @@
+try:
+ import kombu
+ from kombu import pools
+except ImportError:
+ kombu = None
+
+import socket
+import logging
+import threading
+from time import sleep
+log = logging.getLogger(__name__)
+
+
+KOMBU_UNAVAILABLE = "Attempting to bind to AMQP message queue, but kombu dependency unavailable"
+
+DEFAULT_EXCHANGE_NAME = "pulsar"
+DEFAULT_EXCHANGE_TYPE = "direct"
+# Set timeout to periodically give up looking and check if polling should end.
+DEFAULT_TIMEOUT = 0.2
+DEFAULT_HEARTBEAT = 580
+
+DEFAULT_RECONNECT_CONSUMER_WAIT = 1
+DEFAULT_HEARTBEAT_WAIT = 1
+
+
+class PulsarExchange(object):
+ """ Utility for publishing and consuming structured Pulsar queues using kombu.
+ This is shared between the server and client - an exchange should be setup
+ for each manager (or in the case of the client, each manager one wished to
+ communicate with.)
+
+ Each Pulsar manager is defined solely by name in the scheme, so only one Pulsar
+ should target each AMQP endpoint or care should be taken that unique
+ manager names are used across Pulsar servers targetting same AMQP endpoint -
+ and in particular only one such Pulsar should define an default manager with
+ name _default_.
+ """
+
+ def __init__(
+ self,
+ url,
+ manager_name,
+ connect_ssl=None,
+ timeout=DEFAULT_TIMEOUT,
+ publish_kwds={},
+ ):
+ """
+ """
+ if not kombu:
+ raise Exception(KOMBU_UNAVAILABLE)
+ self.__url = url
+ self.__manager_name = manager_name
+ self.__connect_ssl = connect_ssl
+ self.__exchange = kombu.Exchange(DEFAULT_EXCHANGE_NAME, DEFAULT_EXCHANGE_TYPE)
+ self.__timeout = timeout
+ # Be sure to log message publishing failures.
+ if publish_kwds.get("retry", False):
+ if "retry_policy" not in publish_kwds:
+ publish_kwds["retry_policy"] = {}
+ if "errback" not in publish_kwds["retry_policy"]:
+ publish_kwds["retry_policy"]["errback"] = self.__publish_errback
+ self.__publish_kwds = publish_kwds
+
+ @property
+ def url(self):
+ return self.__url
+
+ def consume(self, queue_name, callback, check=True, connection_kwargs={}):
+ queue = self.__queue(queue_name)
+ log.debug("Consuming queue '%s'", queue)
+ while check:
+ heartbeat_thread = None
+ try:
+ with self.connection(self.__url, heartbeat=DEFAULT_HEARTBEAT, **connection_kwargs) as connection:
+ with kombu.Consumer(connection, queues=[queue], callbacks=[callback], accept=['json']):
+ heartbeat_thread = self.__start_heartbeat(queue_name, connection)
+ while check and connection.connected:
+ try:
+ connection.drain_events(timeout=self.__timeout)
+ except socket.timeout:
+ pass
+ except (IOError, socket.error), exc:
+ # In testing, errno is None
+ log.warning('Got %s, will retry: %s', exc.__class__.__name__, exc)
+ if heartbeat_thread:
+ heartbeat_thread.join()
+ sleep(DEFAULT_RECONNECT_CONSUMER_WAIT)
+
+ def heartbeat(self, connection):
+ log.debug('AMQP heartbeat thread alive')
+ while connection.connected:
+ connection.heartbeat_check()
+ sleep(DEFAULT_HEARTBEAT_WAIT)
+ log.debug('AMQP heartbeat thread exiting')
+
+ def publish(self, name, payload):
+ with self.connection(self.__url) as connection:
+ with pools.producers[connection].acquire() as producer:
+ key = self.__queue_name(name)
+ producer.publish(
+ payload,
+ serializer='json',
+ exchange=self.__exchange,
+ declare=[self.__exchange],
+ routing_key=key,
+ **self.__publish_kwds
+ )
+
+ def __publish_errback(self, exc, interval):
+ log.error("Connection error while publishing: %r", exc, exc_info=1)
+ log.info("Retrying in %s seconds", interval)
+
+ def connection(self, connection_string, **kwargs):
+ if "ssl" not in kwargs:
+ kwargs["ssl"] = self.__connect_ssl
+ return kombu.Connection(connection_string, **kwargs)
+
+ def __queue(self, name):
+ queue_name = self.__queue_name(name)
+ queue = kombu.Queue(queue_name, self.__exchange, routing_key=queue_name)
+ return queue
+
+ def __queue_name(self, name):
+ key_prefix = self.__key_prefix()
+ queue_name = '%s_%s' % (key_prefix, name)
+ return queue_name
+
+ def __key_prefix(self):
+ if self.__manager_name == "_default_":
+ key_prefix = "pulsar_"
+ else:
+ key_prefix = "pulsar_%s_" % self.__manager_name
+ return key_prefix
+
+ def __start_heartbeat(self, queue_name, connection):
+ thread_name = "consume-heartbeat-%s" % (self.__queue_name(queue_name))
+ thread = threading.Thread(name=thread_name, target=self.heartbeat, args=(connection,))
+ thread.start()
+ return thread
diff -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee -r 566388d623749dad4259ea04cf44a5d858a56671 lib/pulsar/client/amqp_exchange_factory.py
--- /dev/null
+++ b/lib/pulsar/client/amqp_exchange_factory.py
@@ -0,0 +1,41 @@
+from .amqp_exchange import PulsarExchange
+from .util import filter_destination_params
+
+
+def get_exchange(url, manager_name, params):
+ connect_ssl = parse_amqp_connect_ssl_params(params)
+ exchange_kwds = dict(
+ manager_name=manager_name,
+ connect_ssl=connect_ssl,
+ publish_kwds=parse_amqp_publish_kwds(params)
+ )
+ timeout = params.get('amqp_consumer_timeout', False)
+ if timeout is not False:
+ exchange_kwds['timeout'] = timeout
+ exchange = PulsarExchange(url, **exchange_kwds)
+ return exchange
+
+
+def parse_amqp_connect_ssl_params(params):
+ ssl_params = filter_destination_params(params, "amqp_connect_ssl_")
+ if not ssl_params:
+ return
+
+ ssl = __import__('ssl')
+ if 'cert_reqs' in ssl_params:
+ value = ssl_params['cert_reqs']
+ ssl_params['cert_reqs'] = getattr(ssl, value.upper())
+ return ssl_params
+
+
+def parse_amqp_publish_kwds(params):
+ all_publish_params = filter_destination_params(params, "amqp_publish_")
+ retry_policy_params = {}
+ for key in all_publish_params.keys():
+ if key.startswith("retry_"):
+ value = all_publish_params[key]
+ retry_policy_params[key[len("retry_"):]] = value
+ del all_publish_params[key]
+ if retry_policy_params:
+ all_publish_params["retry_policy"] = retry_policy_params
+ return all_publish_params
This diff is so big that we needed to truncate the remainder.
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: jmchilton: Merged in jmchilton/galaxy-central-fork-1 (pull request #411)
by commits-noreply@bitbucket.org 24 Jun '14
by commits-noreply@bitbucket.org 24 Jun '14
24 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/4ef50975607e/
Changeset: 4ef50975607e
User: jmchilton
Date: 2014-06-24 04:15:44
Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #411)
Allow dynamic job destinations rules to throw `galaxy.jobs.mapper.JobNotReadyException` indicating job not ready.
Affected #: 2 files
diff -r 5eaeb25bff8f383e54c36bd32e17432e6cafadde -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -13,6 +13,7 @@
from galaxy import model
from galaxy.util.sleeper import Sleeper
from galaxy.jobs import JobWrapper, TaskWrapper, JobDestination
+from galaxy.jobs.mapper import JobNotReadyException
log = logging.getLogger( __name__ )
@@ -263,7 +264,7 @@
try:
# Check the job's dependencies, requeue if they're not done.
# Some of these states will only happen when using the in-memory job queue
- job_state = self.__check_if_ready_to_run( job )
+ job_state = self.__check_job_state( job )
if job_state == JOB_WAIT:
new_waiting_jobs.append( job.id )
elif job_state == JOB_INPUT_ERROR:
@@ -304,7 +305,7 @@
# Done with the session
self.sa_session.remove()
- def __check_if_ready_to_run( self, job ):
+ def __check_job_state( self, job ):
"""
Check if a job is ready to run by verifying that each of its input
datasets is ready (specifically in the OK state). If any input dataset
@@ -314,62 +315,97 @@
job can be dispatched. Otherwise, return JOB_WAIT indicating that input
datasets are still being prepared.
"""
- # If tracking in the database, job.state is guaranteed to be NEW and the inputs are guaranteed to be OK
if not self.track_jobs_in_database:
- if job.state == model.Job.states.DELETED:
- return JOB_DELETED
- elif job.state == model.Job.states.ERROR:
- return JOB_ADMIN_DELETED
- for dataset_assoc in job.input_datasets + job.input_library_datasets:
- idata = dataset_assoc.dataset
- if not idata:
- continue
- # don't run jobs for which the input dataset was deleted
- if idata.deleted:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
- return JOB_INPUT_DELETED
- # an error in the input data causes us to bail immediately
- elif idata.state == idata.states.ERROR:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state == idata.states.FAILED_METADATA:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
- # need to requeue
- return JOB_WAIT
+ in_memory_not_ready_state = self.__verify_in_memory_job_inputs( job )
+ if in_memory_not_ready_state:
+ return in_memory_not_ready_state
+
+ # Else, if tracking in the database, job.state is guaranteed to be NEW and
+ # the inputs are guaranteed to be OK.
+
# Create the job wrapper so that the destination can be set
- if job.id not in self.job_wrappers:
- self.job_wrappers[job.id] = self.job_wrapper( job )
- # Cause the job_destination to be set and cached by the mapper
+ job_id = job.id
+ job_wrapper = self.job_wrappers.get( job_id, None )
+ if not job_wrapper:
+ job_wrapper = self.job_wrapper( job )
+ self.job_wrappers[ job_id ] = job_wrapper
+
+ # If state == JOB_READY, assume job_destination also set - otherwise
+ # in case of various error or cancelled states do not assume
+ # destination has been set.
+ state, job_destination = self.__verify_job_ready( job, job_wrapper )
+
+ if state == JOB_READY:
+ # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
+ self.increase_running_job_count(job.user_id, job_destination.id )
+ return state
+
+ def __verify_job_ready( self, job, job_wrapper ):
+ """ Compute job destination and verify job is ready at that
+ destination by checking job limits and quota. If this method
+ return a job state of JOB_READY - it MUST also return a job
+ destination.
+ """
+ job_destination = None
try:
- self.job_wrappers[job.id].job_destination
+ # Cause the job_destination to be set and cached by the mapper
+ job_destination = job_wrapper.job_destination
+ except JobNotReadyException as e:
+ job_state = e.job_state or JOB_WAIT
+ return job_state, None
except Exception, e:
failure_message = getattr( e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE )
if failure_message == DEFAULT_JOB_PUT_FAILURE_MESSAGE:
log.exception( 'Failed to generate job destination' )
else:
log.debug( "Intentionally failing job with message (%s)" % failure_message )
- self.job_wrappers[job.id].fail( failure_message )
- return JOB_ERROR
+ job_wrapper.fail( failure_message )
+ return JOB_ERROR, job_destination
# job is ready to run, check limits
# TODO: these checks should be refactored to minimize duplication and made more modular/pluggable
- state = self.__check_destination_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_destination_jobs( job, job_wrapper )
if state == JOB_READY:
- state = self.__check_user_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_user_jobs( job, job_wrapper )
if state == JOB_READY and self.app.config.enable_quotas:
quota = self.app.quota_agent.get_quota( job.user )
if quota is not None:
try:
usage = self.app.quota_agent.get_usage( user=job.user, history=job.history )
if usage > quota:
- return JOB_USER_OVER_QUOTA
+ return JOB_USER_OVER_QUOTA, job_destination
except AssertionError, e:
pass # No history, should not happen with an anon user
- if state == JOB_READY:
- # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
- self.increase_running_job_count(job.user_id, self.job_wrappers[job.id].job_destination.id)
- return state
+ return state, job_destination
+
+ def __verify_in_memory_job_inputs( self, job ):
+ """ Perform the same checks that happen via SQL for in-memory managed
+ jobs.
+ """
+ if job.state == model.Job.states.DELETED:
+ return JOB_DELETED
+ elif job.state == model.Job.states.ERROR:
+ return JOB_ADMIN_DELETED
+ for dataset_assoc in job.input_datasets + job.input_library_datasets:
+ idata = dataset_assoc.dataset
+ if not idata:
+ continue
+ # don't run jobs for which the input dataset was deleted
+ if idata.deleted:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
+ return JOB_INPUT_DELETED
+ # an error in the input data causes us to bail immediately
+ elif idata.state == idata.states.ERROR:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state == idata.states.FAILED_METADATA:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
+ # need to requeue
+ return JOB_WAIT
+
+ # All inputs ready to go.
+ return None
def __clear_job_count( self ):
self.user_job_count = None
diff -r 5eaeb25bff8f383e54c36bd32e17432e6cafadde -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee lib/galaxy/jobs/mapper.py
--- a/lib/galaxy/jobs/mapper.py
+++ b/lib/galaxy/jobs/mapper.py
@@ -16,6 +16,13 @@
self.failure_message = failure_message
+class JobNotReadyException( Exception ):
+
+ def __init__( self, job_state=None, message=None ):
+ self.job_state = job_state
+ self.message = message
+
+
class JobRunnerMapper( object ):
"""
This class is responsible to managing the mapping of jobs
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
5 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/72a0157988f1/
Changeset: 72a0157988f1
User: jmchilton
Date: 2014-06-11 07:19:20
Summary: Refactor to simplify __check_if_ready_to_run.
Move checks for in memory managed jobs prior to common path through code into their own helper method.
Affected #: 1 file
diff -r c52cb1f827d49f0f0ee2c1c97d3626dd1b2cc348 -r 72a0157988f1cf7e9440dc1cb3dc13ca6cdc42ba lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -240,7 +240,7 @@
try:
# Check the job's dependencies, requeue if they're not done.
# Some of these states will only happen when using the in-memory job queue
- job_state = self.__check_if_ready_to_run( job )
+ job_state = self.__check_job_state( job )
if job_state == JOB_WAIT:
new_waiting_jobs.append( job.id )
elif job_state == JOB_INPUT_ERROR:
@@ -281,7 +281,7 @@
# Done with the session
self.sa_session.remove()
- def __check_if_ready_to_run( self, job ):
+ def __check_job_state( self, job ):
"""
Check if a job is ready to run by verifying that each of its input
datasets is ready (specifically in the OK state). If any input dataset
@@ -293,28 +293,12 @@
"""
# If tracking in the database, job.state is guaranteed to be NEW and the inputs are guaranteed to be OK
if not self.track_jobs_in_database:
- if job.state == model.Job.states.DELETED:
- return JOB_DELETED
- elif job.state == model.Job.states.ERROR:
- return JOB_ADMIN_DELETED
- for dataset_assoc in job.input_datasets + job.input_library_datasets:
- idata = dataset_assoc.dataset
- if not idata:
- continue
- # don't run jobs for which the input dataset was deleted
- if idata.deleted:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
- return JOB_INPUT_DELETED
- # an error in the input data causes us to bail immediately
- elif idata.state == idata.states.ERROR:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state == idata.states.FAILED_METADATA:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
- # need to requeue
- return JOB_WAIT
+ in_memory_job_state = self.__check_in_memory_job_state( job )
+ if in_memory_job_state:
+ return in_memory_job_state
+ # If no problems, all inputs ready to go, continue
+ # with same checks either way.
+
# Create the job wrapper so that the destination can be set
if job.id not in self.job_wrappers:
self.job_wrappers[job.id] = self.job_wrapper( job )
@@ -348,6 +332,33 @@
self.increase_running_job_count(job.user_id, self.job_wrappers[job.id].job_destination.id)
return state
+ def __check_in_memory_job_state( self, job ):
+ if job.state == model.Job.states.DELETED:
+ return JOB_DELETED
+ elif job.state == model.Job.states.ERROR:
+ return JOB_ADMIN_DELETED
+ for dataset_assoc in job.input_datasets + job.input_library_datasets:
+ idata = dataset_assoc.dataset
+ if not idata:
+ continue
+ # don't run jobs for which the input dataset was deleted
+ if idata.deleted:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
+ return JOB_INPUT_DELETED
+ # an error in the input data causes us to bail immediately
+ elif idata.state == idata.states.ERROR:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state == idata.states.FAILED_METADATA:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
+ # need to requeue
+ return JOB_WAIT
+
+ # All inputs ready to go.
+ return None
+
def __clear_job_count( self ):
self.user_job_count = None
self.user_job_count_per_destination = None
https://bitbucket.org/galaxy/galaxy-central/commits/519050ab95d7/
Changeset: 519050ab95d7
User: jmchilton
Date: 2014-06-11 07:19:20
Summary: Refactor __check_if_ready_to_run - less code duplication...
... in the sense that it is no longer repeatedly grabbing same values from map, from wrapper, etc.
Affected #: 1 file
diff -r 72a0157988f1cf7e9440dc1cb3dc13ca6cdc42ba -r 519050ab95d7177abdea8d55bae3b03a3a289476 lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -291,33 +291,37 @@
job can be dispatched. Otherwise, return JOB_WAIT indicating that input
datasets are still being prepared.
"""
- # If tracking in the database, job.state is guaranteed to be NEW and the inputs are guaranteed to be OK
if not self.track_jobs_in_database:
- in_memory_job_state = self.__check_in_memory_job_state( job )
- if in_memory_job_state:
- return in_memory_job_state
- # If no problems, all inputs ready to go, continue
- # with same checks either way.
+ in_memory_not_ready_state = self.__verify_in_memory_job_inputs( job )
+ if in_memory_not_ready_state:
+ return in_memory_not_ready_state
+
+ # Else, if tracking in the database, job.state is guaranteed to be NEW and
+ # the inputs are guaranteed to be OK.
# Create the job wrapper so that the destination can be set
- if job.id not in self.job_wrappers:
- self.job_wrappers[job.id] = self.job_wrapper( job )
+ job_id = job.id
+ job_wrapper = self.job_wrappers.get( job_id, None )
+ if not job_wrapper:
+ job_wrapper = self.job_wrapper( job )
+ self.job_wrappers[ job_id ] = job_wrapper
+
# Cause the job_destination to be set and cached by the mapper
try:
- self.job_wrappers[job.id].job_destination
+ job_destination = job_wrapper.job_destination
except Exception, e:
failure_message = getattr( e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE )
if failure_message == DEFAULT_JOB_PUT_FAILURE_MESSAGE:
log.exception( 'Failed to generate job destination' )
else:
log.debug( "Intentionally failing job with message (%s)" % failure_message )
- self.job_wrappers[job.id].fail( failure_message )
+ job_wrapper.fail( failure_message )
return JOB_ERROR
# job is ready to run, check limits
# TODO: these checks should be refactored to minimize duplication and made more modular/pluggable
- state = self.__check_destination_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_destination_jobs( job, job_wrapper )
if state == JOB_READY:
- state = self.__check_user_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_user_jobs( job, job_wrapper )
if state == JOB_READY and self.app.config.enable_quotas:
quota = self.app.quota_agent.get_quota( job.user )
if quota is not None:
@@ -329,10 +333,13 @@
pass # No history, should not happen with an anon user
if state == JOB_READY:
# PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
- self.increase_running_job_count(job.user_id, self.job_wrappers[job.id].job_destination.id)
+ self.increase_running_job_count(job.user_id, job_destination.id )
return state
- def __check_in_memory_job_state( self, job ):
+ def __verify_in_memory_job_inputs( self, job ):
+ """ Perform the same checks that happen via SQL for in-memory managed
+ jobs.
+ """
if job.state == model.Job.states.DELETED:
return JOB_DELETED
elif job.state == model.Job.states.ERROR:
https://bitbucket.org/galaxy/galaxy-central/commits/8bbb244d339b/
Changeset: 8bbb244d339b
User: jmchilton
Date: 2014-06-11 07:19:20
Summary: Break up __check_job_state - extract new __verify_job_ready method.
Affected #: 1 file
diff -r 519050ab95d7177abdea8d55bae3b03a3a289476 -r 8bbb244d339b396c841341faaa9353f4a1c5e5f1 lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -306,8 +306,25 @@
job_wrapper = self.job_wrapper( job )
self.job_wrappers[ job_id ] = job_wrapper
- # Cause the job_destination to be set and cached by the mapper
+ # If state == JOB_READY, assume job_destination also set - otherwise
+ # in case of various error or cancelled states do not assume
+ # destination has been set.
+ state, job_destination = self.__verify_job_ready( job, job_wrapper )
+
+ if state == JOB_READY:
+ # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
+ self.increase_running_job_count(job.user_id, job_destination.id )
+ return state
+
+ def __verify_job_ready( self, job, job_wrapper ):
+ """ Compute job destination and verify job is ready at that
+ destination by checking job limits and quota. If this method
+ return a job state of JOB_READY - it MUST also return a job
+ destination.
+ """
+ job_destination = None
try:
+ # Cause the job_destination to be set and cached by the mapper
job_destination = job_wrapper.job_destination
except Exception, e:
failure_message = getattr( e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE )
@@ -316,7 +333,7 @@
else:
log.debug( "Intentionally failing job with message (%s)" % failure_message )
job_wrapper.fail( failure_message )
- return JOB_ERROR
+ return JOB_ERROR, job_destination
# job is ready to run, check limits
# TODO: these checks should be refactored to minimize duplication and made more modular/pluggable
state = self.__check_destination_jobs( job, job_wrapper )
@@ -328,13 +345,10 @@
try:
usage = self.app.quota_agent.get_usage( user=job.user, history=job.history )
if usage > quota:
- return JOB_USER_OVER_QUOTA
+ return JOB_USER_OVER_QUOTA, job_destination
except AssertionError, e:
pass # No history, should not happen with an anon user
- if state == JOB_READY:
- # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
- self.increase_running_job_count(job.user_id, job_destination.id )
- return state
+ return state, job_destination
def __verify_in_memory_job_inputs( self, job ):
""" Perform the same checks that happen via SQL for in-memory managed
https://bitbucket.org/galaxy/galaxy-central/commits/e1c8d892be5d/
Changeset: e1c8d892be5d
User: jmchilton
Date: 2014-06-11 07:19:20
Summary: Allow dynamic job destinations to throw new JobNotReadyException to indicate delayed decision.
Perhaps wait on some deployer defined limit or resource to become available, etc...
Affected #: 2 files
diff -r 8bbb244d339b396c841341faaa9353f4a1c5e5f1 -r e1c8d892be5de20ed4564a3e467943701dccacd8 lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -13,6 +13,7 @@
from galaxy import model
from galaxy.util.sleeper import Sleeper
from galaxy.jobs import JobWrapper, TaskWrapper, JobDestination
+from galaxy.jobs.mapper import JobNotReadyException
log = logging.getLogger( __name__ )
@@ -326,6 +327,9 @@
try:
# Cause the job_destination to be set and cached by the mapper
job_destination = job_wrapper.job_destination
+ except JobNotReadyException as e:
+ job_state = e.job_state or JOB_WAIT
+ return job_state, None
except Exception, e:
failure_message = getattr( e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE )
if failure_message == DEFAULT_JOB_PUT_FAILURE_MESSAGE:
diff -r 8bbb244d339b396c841341faaa9353f4a1c5e5f1 -r e1c8d892be5de20ed4564a3e467943701dccacd8 lib/galaxy/jobs/mapper.py
--- a/lib/galaxy/jobs/mapper.py
+++ b/lib/galaxy/jobs/mapper.py
@@ -16,6 +16,13 @@
self.failure_message = failure_message
+class JobNotReadyException( Exception ):
+
+ def __init__( self, job_state=None, message=None ):
+ self.job_state = job_state
+ self.message = message
+
+
class JobRunnerMapper( object ):
"""
This class is responsible to managing the mapping of jobs
https://bitbucket.org/galaxy/galaxy-central/commits/4ef50975607e/
Changeset: 4ef50975607e
User: jmchilton
Date: 2014-06-24 04:15:44
Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #411)
Allow dynamic job destinations rules to throw `galaxy.jobs.mapper.JobNotReadyException` indicating job not ready.
Affected #: 2 files
diff -r 5eaeb25bff8f383e54c36bd32e17432e6cafadde -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee lib/galaxy/jobs/handler.py
--- a/lib/galaxy/jobs/handler.py
+++ b/lib/galaxy/jobs/handler.py
@@ -13,6 +13,7 @@
from galaxy import model
from galaxy.util.sleeper import Sleeper
from galaxy.jobs import JobWrapper, TaskWrapper, JobDestination
+from galaxy.jobs.mapper import JobNotReadyException
log = logging.getLogger( __name__ )
@@ -263,7 +264,7 @@
try:
# Check the job's dependencies, requeue if they're not done.
# Some of these states will only happen when using the in-memory job queue
- job_state = self.__check_if_ready_to_run( job )
+ job_state = self.__check_job_state( job )
if job_state == JOB_WAIT:
new_waiting_jobs.append( job.id )
elif job_state == JOB_INPUT_ERROR:
@@ -304,7 +305,7 @@
# Done with the session
self.sa_session.remove()
- def __check_if_ready_to_run( self, job ):
+ def __check_job_state( self, job ):
"""
Check if a job is ready to run by verifying that each of its input
datasets is ready (specifically in the OK state). If any input dataset
@@ -314,62 +315,97 @@
job can be dispatched. Otherwise, return JOB_WAIT indicating that input
datasets are still being prepared.
"""
- # If tracking in the database, job.state is guaranteed to be NEW and the inputs are guaranteed to be OK
if not self.track_jobs_in_database:
- if job.state == model.Job.states.DELETED:
- return JOB_DELETED
- elif job.state == model.Job.states.ERROR:
- return JOB_ADMIN_DELETED
- for dataset_assoc in job.input_datasets + job.input_library_datasets:
- idata = dataset_assoc.dataset
- if not idata:
- continue
- # don't run jobs for which the input dataset was deleted
- if idata.deleted:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
- return JOB_INPUT_DELETED
- # an error in the input data causes us to bail immediately
- elif idata.state == idata.states.ERROR:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state == idata.states.FAILED_METADATA:
- self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
- return JOB_INPUT_ERROR
- elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
- # need to requeue
- return JOB_WAIT
+ in_memory_not_ready_state = self.__verify_in_memory_job_inputs( job )
+ if in_memory_not_ready_state:
+ return in_memory_not_ready_state
+
+ # Else, if tracking in the database, job.state is guaranteed to be NEW and
+ # the inputs are guaranteed to be OK.
+
# Create the job wrapper so that the destination can be set
- if job.id not in self.job_wrappers:
- self.job_wrappers[job.id] = self.job_wrapper( job )
- # Cause the job_destination to be set and cached by the mapper
+ job_id = job.id
+ job_wrapper = self.job_wrappers.get( job_id, None )
+ if not job_wrapper:
+ job_wrapper = self.job_wrapper( job )
+ self.job_wrappers[ job_id ] = job_wrapper
+
+ # If state == JOB_READY, assume job_destination also set - otherwise
+ # in case of various error or cancelled states do not assume
+ # destination has been set.
+ state, job_destination = self.__verify_job_ready( job, job_wrapper )
+
+ if state == JOB_READY:
+ # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
+ self.increase_running_job_count(job.user_id, job_destination.id )
+ return state
+
+ def __verify_job_ready( self, job, job_wrapper ):
+ """ Compute job destination and verify job is ready at that
+ destination by checking job limits and quota. If this method
+ return a job state of JOB_READY - it MUST also return a job
+ destination.
+ """
+ job_destination = None
try:
- self.job_wrappers[job.id].job_destination
+ # Cause the job_destination to be set and cached by the mapper
+ job_destination = job_wrapper.job_destination
+ except JobNotReadyException as e:
+ job_state = e.job_state or JOB_WAIT
+ return job_state, None
except Exception, e:
failure_message = getattr( e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE )
if failure_message == DEFAULT_JOB_PUT_FAILURE_MESSAGE:
log.exception( 'Failed to generate job destination' )
else:
log.debug( "Intentionally failing job with message (%s)" % failure_message )
- self.job_wrappers[job.id].fail( failure_message )
- return JOB_ERROR
+ job_wrapper.fail( failure_message )
+ return JOB_ERROR, job_destination
# job is ready to run, check limits
# TODO: these checks should be refactored to minimize duplication and made more modular/pluggable
- state = self.__check_destination_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_destination_jobs( job, job_wrapper )
if state == JOB_READY:
- state = self.__check_user_jobs( job, self.job_wrappers[job.id] )
+ state = self.__check_user_jobs( job, job_wrapper )
if state == JOB_READY and self.app.config.enable_quotas:
quota = self.app.quota_agent.get_quota( job.user )
if quota is not None:
try:
usage = self.app.quota_agent.get_usage( user=job.user, history=job.history )
if usage > quota:
- return JOB_USER_OVER_QUOTA
+ return JOB_USER_OVER_QUOTA, job_destination
except AssertionError, e:
pass # No history, should not happen with an anon user
- if state == JOB_READY:
- # PASS. increase usage by one job (if caching) so that multiple jobs aren't dispatched on this queue iteration
- self.increase_running_job_count(job.user_id, self.job_wrappers[job.id].job_destination.id)
- return state
+ return state, job_destination
+
+ def __verify_in_memory_job_inputs( self, job ):
+ """ Perform the same checks that happen via SQL for in-memory managed
+ jobs.
+ """
+ if job.state == model.Job.states.DELETED:
+ return JOB_DELETED
+ elif job.state == model.Job.states.ERROR:
+ return JOB_ADMIN_DELETED
+ for dataset_assoc in job.input_datasets + job.input_library_datasets:
+ idata = dataset_assoc.dataset
+ if not idata:
+ continue
+ # don't run jobs for which the input dataset was deleted
+ if idata.deleted:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s (file: %s) was deleted before the job started" % ( idata.hid, idata.file_name ) )
+ return JOB_INPUT_DELETED
+ # an error in the input data causes us to bail immediately
+ elif idata.state == idata.states.ERROR:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s is in error state" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state == idata.states.FAILED_METADATA:
+ self.job_wrappers.pop(job.id, self.job_wrapper( job )).fail( "input data %s failed to properly set metadata" % ( idata.hid ) )
+ return JOB_INPUT_ERROR
+ elif idata.state != idata.states.OK and not ( idata.state == idata.states.SETTING_METADATA and job.tool_id is not None and job.tool_id == self.app.datatypes_registry.set_external_metadata_tool.id ):
+ # need to requeue
+ return JOB_WAIT
+
+ # All inputs ready to go.
+ return None
def __clear_job_count( self ):
self.user_job_count = None
diff -r 5eaeb25bff8f383e54c36bd32e17432e6cafadde -r 4ef50975607ee0d3b4490c9e7a5795d6a04802ee lib/galaxy/jobs/mapper.py
--- a/lib/galaxy/jobs/mapper.py
+++ b/lib/galaxy/jobs/mapper.py
@@ -16,6 +16,13 @@
self.failure_message = failure_message
+class JobNotReadyException( Exception ):
+
+ def __init__( self, job_state=None, message=None ):
+ self.job_state = job_state
+ self.message = message
+
+
class JobRunnerMapper( object ):
"""
This class is responsible to managing the mapping of jobs
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: jmchilton: Docfix: Delete diminutive docker doc deficiency.
by commits-noreply@bitbucket.org 23 Jun '14
by commits-noreply@bitbucket.org 23 Jun '14
23 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/5eaeb25bff8f/
Changeset: 5eaeb25bff8f
User: jmchilton
Date: 2014-06-23 19:49:05
Summary: Docfix: Delete diminutive docker doc deficiency.
Affected #: 1 file
diff -r 631127bb6c2657140e75f203301abfdf567d82e5 -r 5eaeb25bff8f383e54c36bd32e17432e6cafadde job_conf.xml.sample_advanced
--- a/job_conf.xml.sample_advanced
+++ b/job_conf.xml.sample_advanced
@@ -178,7 +178,7 @@
does trust tool's specified container - but also wants tool's not
configured to run in a container the following option can provide
a fallback. -->
- <!-- <param id="dockers_default_container_id">busybox:ubuntu-14.04</param> -->
+ <!-- <param id="docker_default_container_id">busybox:ubuntu-14.04</param> --></destination><destination id="pbs" runner="pbs" tags="mycluster"/>
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: greg: Missed committing a new __init__.py file for Tool Shed dependencies.
by commits-noreply@bitbucket.org 23 Jun '14
by commits-noreply@bitbucket.org 23 Jun '14
23 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/631127bb6c26/
Changeset: 631127bb6c26
User: greg
Date: 2014-06-23 14:58:25
Summary: Missed committing a new __init__.py file for Tool Shed dependencies.
Affected #: 1 file
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0
commit/galaxy-central: greg: A bit of repository dependency function re-factoring for Galaxy installs.
by commits-noreply@bitbucket.org 23 Jun '14
by commits-noreply@bitbucket.org 23 Jun '14
23 Jun '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/f5589d243d0f/
Changeset: f5589d243d0f
User: greg
Date: 2014-06-23 02:31:19
Summary: A bit of repository dependency function re-factoring for Galaxy installs.
Affected #: 4 files
diff -r 344e84a6554ae94604f32e8f62feebd65a6ac358 -r f5589d243d0f920cdd96c3e980762bb1a7cc061b lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -1359,9 +1359,8 @@
else:
# Entering this else block occurs only if the tool_shed_repository does not include any valid tools.
if install_repository_dependencies:
- repository_dependencies = \
- repository_dependency_util.get_repository_dependencies_for_installed_tool_shed_repository( trans.app,
- tool_shed_repository )
+ repository_dependencies = rdm.get_repository_dependencies_for_installed_tool_shed_repository( trans.app,
+ tool_shed_repository )
else:
repository_dependencies = None
if metadata:
@@ -1579,9 +1578,9 @@
raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url )
readme_files_dict = json.from_json_string( raw_text )
tool_dependencies = metadata.get( 'tool_dependencies', None )
- repository_dependencies = \
- repository_dependency_util.get_repository_dependencies_for_installed_tool_shed_repository( trans.app,
- tool_shed_repository )
+ rdm = RepositoryDependencyManager( trans.app )
+ repository_dependencies = rdm.get_repository_dependencies_for_installed_tool_shed_repository( trans.app,
+ tool_shed_repository )
repo_info_dict = \
repository_maintenance_util.create_repo_info_dict( app=trans.app,
repository_clone_url=repository_clone_url,
diff -r 344e84a6554ae94604f32e8f62feebd65a6ac358 -r f5589d243d0f920cdd96c3e980762bb1a7cc061b lib/tool_shed/galaxy_install/repair_repository_manager.py
--- a/lib/tool_shed/galaxy_install/repair_repository_manager.py
+++ b/lib/tool_shed/galaxy_install/repair_repository_manager.py
@@ -4,6 +4,7 @@
log = logging.getLogger( __name__ )
from tool_shed.galaxy_install import install_manager
+from tool_shed.galaxy_install.repository_dependencies.repository_dependency_manager import RepositoryDependencyManager
from tool_shed.util import common_util
from tool_shed.util import container_util
@@ -55,6 +56,7 @@
issues with an installed repository that has installation problems somewhere in its
dependency hierarchy.
"""
+ rdm = RepositoryDependencyManager( self.app )
tsr_ids = []
repo_info_dicts = []
tool_panel_section_keys = []
@@ -62,8 +64,8 @@
irm = install_manager.InstallRepositoryManager( self.app )
# Get a dictionary of all repositories upon which the contents of the current repository_metadata
#record depend.
- repository_dependencies_dict = \
- repository_dependency_util.get_repository_dependencies_for_installed_tool_shed_repository( self.app, repository )
+ repository_dependencies_dict = rdm.get_repository_dependencies_for_installed_tool_shed_repository( self.app,
+ repository )
if repository_dependencies_dict:
# Generate the list of installed repositories from the information contained in the
# repository_dependencies dictionary.
@@ -73,13 +75,15 @@
# repaired in the required order.
for installed_repository in installed_repositories:
tsr_ids.append( self.app.security.encode_id( installed_repository.id ) )
- repo_info_dict, tool_panel_section_key = self.get_repo_info_dict_for_repair( installed_repository )
+ repo_info_dict, tool_panel_section_key = self.get_repo_info_dict_for_repair( rdm,
+ installed_repository )
tool_panel_section_keys.append( tool_panel_section_key )
repo_info_dicts.append( repo_info_dict )
else:
# The received repository has no repository dependencies.
tsr_ids.append( self.app.security.encode_id( repository.id ) )
- repo_info_dict, tool_panel_section_key = self.get_repo_info_dict_for_repair( repository )
+ repo_info_dict, tool_panel_section_key = self.get_repo_info_dict_for_repair( rdm,
+ repository )
tool_panel_section_keys.append( tool_panel_section_key )
repo_info_dicts.append( repo_info_dict )
ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \
@@ -91,11 +95,11 @@
repair_dict[ 'ordered_tool_panel_section_keys' ] = ordered_tool_panel_section_keys
return repair_dict
- def get_repo_info_dict_for_repair( self, repository ):
+ def get_repo_info_dict_for_repair( self, rdm, repository ):
tool_panel_section_key = None
repository_clone_url = common_util.generate_clone_url_for_installed_repository( self.app, repository )
- repository_dependencies = \
- repository_dependency_util.get_repository_dependencies_for_installed_tool_shed_repository( self.app, repository )
+ repository_dependencies = rdm.get_repository_dependencies_for_installed_tool_shed_repository( self.app,
+ repository )
metadata = repository.metadata
if metadata:
tool_dependencies = metadata.get( 'tool_dependencies', None )
diff -r 344e84a6554ae94604f32e8f62feebd65a6ac358 -r f5589d243d0f920cdd96c3e980762bb1a7cc061b lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
--- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
+++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
@@ -255,6 +255,29 @@
self.build_repository_dependency_relationships( all_repo_info_dicts, all_created_or_updated_tool_shed_repositories )
return created_or_updated_tool_shed_repositories, tool_panel_section_keys, all_repo_info_dicts, filtered_repo_info_dicts
+ def get_repository_dependencies_for_installed_tool_shed_repository( self, app, repository ):
+ """
+ Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
+ for the received repository which is installed into Galaxy. This method is called only from Galaxy.
+ """
+ tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) )
+ params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ),
+ str( repository.owner ),
+ str( repository.changeset_revision ) )
+ url = common_util.url_join( tool_shed_url,
+ 'repository/get_repository_dependencies%s' % params )
+ try:
+ raw_text = common_util.tool_shed_get( app, tool_shed_url, url )
+ except Exception, e:
+ print "The URL\n%s\nraised the exception:\n%s\n" % ( url, str( e ) )
+ return ''
+ if len( raw_text ) > 2:
+ encoded_text = json.loads( raw_text )
+ text = encoding_util.tool_shed_decode( encoded_text )
+ else:
+ text = ''
+ return text
+
def get_repository_dependency_by_repository_id( self, install_model, decoded_repository_id ):
return install_model.context.query( install_model.RepositoryDependency ) \
.filter( install_model.RepositoryDependency.table.c.tool_shed_repository_id == decoded_repository_id ) \
diff -r 344e84a6554ae94604f32e8f62feebd65a6ac358 -r f5589d243d0f920cdd96c3e980762bb1a7cc061b lib/tool_shed/util/repository_dependency_util.py
--- a/lib/tool_shed/util/repository_dependency_util.py
+++ b/lib/tool_shed/util/repository_dependency_util.py
@@ -147,29 +147,6 @@
prior_installation_required,
only_if_compiling_contained_td )
-def get_repository_dependencies_for_installed_tool_shed_repository( app, repository ):
- """
- Send a request to the appropriate tool shed to retrieve the dictionary of repository dependencies defined
- for the received repository which is installed into Galaxy. This method is called only from Galaxy.
- """
- tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) )
- params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ),
- str( repository.owner ),
- str( repository.changeset_revision ) )
- url = common_util.url_join( tool_shed_url,
- 'repository/get_repository_dependencies%s' % params )
- try:
- raw_text = common_util.tool_shed_get( app, tool_shed_url, url )
- except Exception, e:
- print "The URL\n%s\nraised the exception:\n%s\n" % ( url, str( e ) )
- return ''
- if len( raw_text ) > 2:
- encoded_text = json.loads( raw_text )
- text = encoding_util.tool_shed_decode( encoded_text )
- else:
- text = ''
- return text
-
def get_repository_dependencies_for_changeset_revision( app, repository, repository_metadata, toolshed_base_url,
key_rd_dicts_to_be_processed=None, all_repository_dependencies=None,
handled_key_rd_dicts=None, circular_repository_dependencies=None ):
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
1
0