Files
woocommerce-subscriptions/assets/js/admin/jquery.flot.orderBars.min.js
Prospress Inc 69c6993fcf 2.3.4
2018-08-14 10:18:40 +02:00

23 lines
2.3 KiB
JavaScript

/*
* Flot plugin to order bars side by side.
*
* Released under the MIT license by Benjamin BUFFET, 20-Sep-2010.
* Modifications made by Steven Hall <github.com/emmerich>, 01-May-2013.
*
* This plugin is an alpha version.
*
* To activate the plugin you must specify the parameter "order" for the specific serie :
*
* $.plot($("#placeholder"), [{ data: [ ... ], bars :{ order = null or integer }])
*
* If 2 series have the same order param, they are ordered by the position in the array;
*
* The plugin adjust the point by adding a value depanding of the barwidth
* Exemple for 3 series (barwidth : 0.1) :
*
* first bar décalage : -0.15
* second bar décalage : -0.05
* third bar décalage : 0.05
*
*/
!function(r){function n(r){function n(r,n,a){var i=null;if(t(n)&&(f(n),e(r),o(r),u(n),g>=2)){var s=l(n),v=0,W=d();"undefined"==typeof D[n.bars.order]&&(h(s)?D[n.bars.order]=-1*b(p,s-1,Math.floor(g/2)-1)-W:D[n.bars.order]=b(p,Math.ceil(g/2),s-2)+W+2*y),v=D[n.bars.order],i=c(a,n,v),a.points=i}return i}function t(r){return null!=r.bars&&r.bars.show&&null!=r.bars.order}function e(r){var n=w?r.getPlaceholder().innerHeight():r.getPlaceholder().innerWidth(),t=w?a(r.getData(),1):a(r.getData(),0),e=t[1]-t[0];W=e/n}function a(r,n){for(var t=new Array,e=0;e<r.length;e++)t[0]=r[e].data[0][n],t[1]=r[e].data[r[e].data.length-1][n];return t}function o(r){p=i(r.getData()),g=p.length}function i(r){for(var n=new Array,t=[],e=0;e<r.length;e++)null!=r[e].bars.order&&r[e].bars.show&&t.indexOf(r[e].bars.order)<0&&(t.push(r[e].bars.order),n.push(r[e]));return n.sort(s)}function s(r,n){var t=r.bars.order,e=n.bars.order;return e>t?-1:t>e?1:0}function u(r){v="undefined"!=typeof r.bars.lineWidth?r.bars.lineWidth:2,y=v*W}function f(r){r.bars.horizontal&&(w=!0)}function l(r){for(var n=0,t=0;t<p.length;++t)if(r==p[t]){n=t;break}return n+1}function d(){var r=0;return g%2!=0&&(r=p[Math.ceil(g/2)].bars.barWidth/2),r}function h(r){return r<=Math.ceil(g/2)}function b(r,n,t){for(var e=0,a=n;t>=a;a++)e+=r[a].bars.barWidth+2*y;return e}function c(r,n,t){for(var e=r.pointsize,a=r.points,o=0,i=w?1:0;i<a.length;i+=e)a[i]+=t,n.data[o][3]=a[i],o++;return a}var p,g,v,y,W=1,w=!1,D={};r.hooks.processDatapoints.push(n)}var t={series:{bars:{order:null}}};r.plot.plugins.push({init:n,options:t,name:"orderBars",version:"0.2"})}(jQuery);