Built files from Bizgaze WebServer
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  1. (function() {
  2. var callWithJQuery,
  3. indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
  4. slice = [].slice,
  5. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  6. hasProp = {}.hasOwnProperty;
  7. callWithJQuery = function(pivotModule) {
  8. if (typeof exports === "object" && typeof module === "object") {
  9. return pivotModule(require("jquery"));
  10. } else if (typeof define === "function" && define.amd) {
  11. return define(["jquery"], pivotModule);
  12. } else {
  13. return pivotModule(jQuery);
  14. }
  15. };
  16. callWithJQuery(function($) {
  17. /*
  18. Utilities
  19. */
  20. var PivotData, addSeparators, aggregatorTemplates, aggregators, dayNamesEn, derivers, getSort, locales, mthNamesEn, naturalSort, numberFormat, pivotTableRenderer, rd, renderers, rx, rz, sortAs, usFmt, usFmtInt, usFmtPct, zeroPad;
  21. addSeparators = function(nStr, thousandsSep, decimalSep) {
  22. var rgx, x, x1, x2;
  23. nStr += '';
  24. x = nStr.split('.');
  25. x1 = x[0];
  26. x2 = x.length > 1 ? decimalSep + x[1] : '';
  27. rgx = /(\d+)(\d{3})/;
  28. while (rgx.test(x1)) {
  29. x1 = x1.replace(rgx, '$1' + thousandsSep + '$2');
  30. }
  31. return x1 + x2;
  32. };
  33. numberFormat = function(opts) {
  34. var defaults;
  35. defaults = {
  36. digitsAfterDecimal: 2,
  37. scaler: 1,
  38. thousandsSep: ",",
  39. decimalSep: ".",
  40. prefix: "",
  41. suffix: ""
  42. };
  43. opts = $.extend({}, defaults, opts);
  44. return function(x) {
  45. var result;
  46. if (isNaN(x) || !isFinite(x)) {
  47. return "";
  48. }
  49. result = addSeparators((opts.scaler * x).toFixed(opts.digitsAfterDecimal), opts.thousandsSep, opts.decimalSep);
  50. return "" + opts.prefix + result + opts.suffix;
  51. };
  52. };
  53. usFmt = numberFormat();
  54. usFmtInt = numberFormat({
  55. digitsAfterDecimal: 0
  56. });
  57. usFmtPct = numberFormat({
  58. digitsAfterDecimal: 1,
  59. scaler: 100,
  60. suffix: "%"
  61. });
  62. aggregatorTemplates = {
  63. count: function(formatter) {
  64. if (formatter == null) {
  65. formatter = usFmtInt;
  66. }
  67. return function() {
  68. return function(data, rowKey, colKey) {
  69. return {
  70. count: 0,
  71. push: function() {
  72. return this.count++;
  73. },
  74. value: function() {
  75. return this.count;
  76. },
  77. format: formatter
  78. };
  79. };
  80. };
  81. },
  82. uniques: function(fn, formatter) {
  83. if (formatter == null) {
  84. formatter = usFmtInt;
  85. }
  86. return function(arg) {
  87. var attr;
  88. attr = arg[0];
  89. return function(data, rowKey, colKey) {
  90. return {
  91. uniq: [],
  92. push: function(record) {
  93. var ref;
  94. if (ref = record[attr], indexOf.call(this.uniq, ref) < 0) {
  95. return this.uniq.push(record[attr]);
  96. }
  97. },
  98. value: function() {
  99. return fn(this.uniq);
  100. },
  101. format: formatter,
  102. numInputs: attr != null ? 0 : 1
  103. };
  104. };
  105. };
  106. },
  107. sum: function(formatter) {
  108. if (formatter == null) {
  109. formatter = usFmt;
  110. }
  111. return function(arg) {
  112. var attr;
  113. attr = arg[0];
  114. return function(data, rowKey, colKey) {
  115. return {
  116. sum: 0,
  117. push: function(record) {
  118. if (!isNaN(parseFloat(record[attr]))) {
  119. return this.sum += parseFloat(record[attr]);
  120. }
  121. },
  122. value: function() {
  123. return this.sum;
  124. },
  125. format: formatter,
  126. numInputs: attr != null ? 0 : 1
  127. };
  128. };
  129. };
  130. },
  131. extremes: function(mode, formatter) {
  132. if (formatter == null) {
  133. formatter = usFmt;
  134. }
  135. return function(arg) {
  136. var attr;
  137. attr = arg[0];
  138. return function(data, rowKey, colKey) {
  139. return {
  140. val: null,
  141. sorter: getSort(data != null ? data.sorters : void 0, attr),
  142. push: function(record) {
  143. var ref, ref1, ref2, x;
  144. x = record[attr];
  145. if (mode === "min" || mode === "max") {
  146. x = parseFloat(x);
  147. if (!isNaN(x)) {
  148. this.val = Math[mode](x, (ref = this.val) != null ? ref : x);
  149. }
  150. }
  151. if (mode === "first") {
  152. if (this.sorter(x, (ref1 = this.val) != null ? ref1 : x) <= 0) {
  153. this.val = x;
  154. }
  155. }
  156. if (mode === "last") {
  157. if (this.sorter(x, (ref2 = this.val) != null ? ref2 : x) >= 0) {
  158. return this.val = x;
  159. }
  160. }
  161. },
  162. value: function() {
  163. return this.val;
  164. },
  165. format: function(x) {
  166. if (isNaN(x)) {
  167. return x;
  168. } else {
  169. return formatter(x);
  170. }
  171. },
  172. numInputs: attr != null ? 0 : 1
  173. };
  174. };
  175. };
  176. },
  177. quantile: function(q, formatter) {
  178. if (formatter == null) {
  179. formatter = usFmt;
  180. }
  181. return function(arg) {
  182. var attr;
  183. attr = arg[0];
  184. return function(data, rowKey, colKey) {
  185. return {
  186. vals: [],
  187. push: function(record) {
  188. var x;
  189. x = parseFloat(record[attr]);
  190. if (!isNaN(x)) {
  191. return this.vals.push(x);
  192. }
  193. },
  194. value: function() {
  195. var i;
  196. if (this.vals.length === 0) {
  197. return null;
  198. }
  199. this.vals.sort(function(a, b) {
  200. return a - b;
  201. });
  202. i = (this.vals.length - 1) * q;
  203. return (this.vals[Math.floor(i)] + this.vals[Math.ceil(i)]) / 2.0;
  204. },
  205. format: formatter,
  206. numInputs: attr != null ? 0 : 1
  207. };
  208. };
  209. };
  210. },
  211. runningStat: function(mode, ddof, formatter) {
  212. if (mode == null) {
  213. mode = "mean";
  214. }
  215. if (ddof == null) {
  216. ddof = 1;
  217. }
  218. if (formatter == null) {
  219. formatter = usFmt;
  220. }
  221. return function(arg) {
  222. var attr;
  223. attr = arg[0];
  224. return function(data, rowKey, colKey) {
  225. return {
  226. n: 0.0,
  227. m: 0.0,
  228. s: 0.0,
  229. push: function(record) {
  230. var m_new, x;
  231. x = parseFloat(record[attr]);
  232. if (isNaN(x)) {
  233. return;
  234. }
  235. this.n += 1.0;
  236. if (this.n === 1.0) {
  237. return this.m = x;
  238. } else {
  239. m_new = this.m + (x - this.m) / this.n;
  240. this.s = this.s + (x - this.m) * (x - m_new);
  241. return this.m = m_new;
  242. }
  243. },
  244. value: function() {
  245. if (mode === "mean") {
  246. if (this.n === 0) {
  247. return 0 / 0;
  248. } else {
  249. return this.m;
  250. }
  251. }
  252. if (this.n <= ddof) {
  253. return 0;
  254. }
  255. switch (mode) {
  256. case "var":
  257. return this.s / (this.n - ddof);
  258. case "stdev":
  259. return Math.sqrt(this.s / (this.n - ddof));
  260. }
  261. },
  262. format: formatter,
  263. numInputs: attr != null ? 0 : 1
  264. };
  265. };
  266. };
  267. },
  268. sumOverSum: function(formatter) {
  269. if (formatter == null) {
  270. formatter = usFmt;
  271. }
  272. return function(arg) {
  273. var denom, num;
  274. num = arg[0], denom = arg[1];
  275. return function(data, rowKey, colKey) {
  276. return {
  277. sumNum: 0,
  278. sumDenom: 0,
  279. push: function(record) {
  280. if (!isNaN(parseFloat(record[num]))) {
  281. this.sumNum += parseFloat(record[num]);
  282. }
  283. if (!isNaN(parseFloat(record[denom]))) {
  284. return this.sumDenom += parseFloat(record[denom]);
  285. }
  286. },
  287. value: function() {
  288. return this.sumNum / this.sumDenom;
  289. },
  290. format: formatter,
  291. numInputs: (num != null) && (denom != null) ? 0 : 2
  292. };
  293. };
  294. };
  295. },
  296. sumOverSumBound80: function(upper, formatter) {
  297. if (upper == null) {
  298. upper = true;
  299. }
  300. if (formatter == null) {
  301. formatter = usFmt;
  302. }
  303. return function(arg) {
  304. var denom, num;
  305. num = arg[0], denom = arg[1];
  306. return function(data, rowKey, colKey) {
  307. return {
  308. sumNum: 0,
  309. sumDenom: 0,
  310. push: function(record) {
  311. if (!isNaN(parseFloat(record[num]))) {
  312. this.sumNum += parseFloat(record[num]);
  313. }
  314. if (!isNaN(parseFloat(record[denom]))) {
  315. return this.sumDenom += parseFloat(record[denom]);
  316. }
  317. },
  318. value: function() {
  319. var sign;
  320. sign = upper ? 1 : -1;
  321. return (0.821187207574908 / this.sumDenom + this.sumNum / this.sumDenom + 1.2815515655446004 * sign * Math.sqrt(0.410593603787454 / (this.sumDenom * this.sumDenom) + (this.sumNum * (1 - this.sumNum / this.sumDenom)) / (this.sumDenom * this.sumDenom))) / (1 + 1.642374415149816 / this.sumDenom);
  322. },
  323. format: formatter,
  324. numInputs: (num != null) && (denom != null) ? 0 : 2
  325. };
  326. };
  327. };
  328. },
  329. fractionOf: function(wrapped, type, formatter) {
  330. if (type == null) {
  331. type = "total";
  332. }
  333. if (formatter == null) {
  334. formatter = usFmtPct;
  335. }
  336. return function() {
  337. var x;
  338. x = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  339. return function(data, rowKey, colKey) {
  340. return {
  341. selector: {
  342. total: [[], []],
  343. row: [rowKey, []],
  344. col: [[], colKey]
  345. }[type],
  346. inner: wrapped.apply(null, x)(data, rowKey, colKey),
  347. push: function(record) {
  348. return this.inner.push(record);
  349. },
  350. format: formatter,
  351. value: function() {
  352. return this.inner.value() / data.getAggregator.apply(data, this.selector).inner.value();
  353. },
  354. numInputs: wrapped.apply(null, x)().numInputs
  355. };
  356. };
  357. };
  358. }
  359. };
  360. aggregatorTemplates.countUnique = function(f) {
  361. return aggregatorTemplates.uniques((function(x) {
  362. return x.length;
  363. }), f);
  364. };
  365. aggregatorTemplates.listUnique = function(s) {
  366. return aggregatorTemplates.uniques((function(x) {
  367. return x.sort(naturalSort).join(s);
  368. }), (function(x) {
  369. return x;
  370. }));
  371. };
  372. aggregatorTemplates.max = function(f) {
  373. return aggregatorTemplates.extremes('max', f);
  374. };
  375. aggregatorTemplates.min = function(f) {
  376. return aggregatorTemplates.extremes('min', f);
  377. };
  378. aggregatorTemplates.first = function(f) {
  379. return aggregatorTemplates.extremes('first', f);
  380. };
  381. aggregatorTemplates.last = function(f) {
  382. return aggregatorTemplates.extremes('last', f);
  383. };
  384. aggregatorTemplates.median = function(f) {
  385. return aggregatorTemplates.quantile(0.5, f);
  386. };
  387. aggregatorTemplates.average = function(f) {
  388. return aggregatorTemplates.runningStat("mean", 1, f);
  389. };
  390. aggregatorTemplates["var"] = function(ddof, f) {
  391. return aggregatorTemplates.runningStat("var", ddof, f);
  392. };
  393. aggregatorTemplates.stdev = function(ddof, f) {
  394. return aggregatorTemplates.runningStat("stdev", ddof, f);
  395. };
  396. aggregators = (function(tpl) {
  397. return {
  398. "Count": tpl.count(usFmtInt),
  399. "Count Unique Values": tpl.countUnique(usFmtInt),
  400. "List Unique Values": tpl.listUnique(", "),
  401. "Sum": tpl.sum(usFmt),
  402. "Integer Sum": tpl.sum(usFmtInt),
  403. "Average": tpl.average(usFmt),
  404. "Median": tpl.median(usFmt),
  405. "Sample Variance": tpl["var"](1, usFmt),
  406. "Sample Standard Deviation": tpl.stdev(1, usFmt),
  407. "Minimum": tpl.min(usFmt),
  408. "Maximum": tpl.max(usFmt),
  409. "First": tpl.first(usFmt),
  410. "Last": tpl.last(usFmt),
  411. "Sum over Sum": tpl.sumOverSum(usFmt),
  412. "80% Upper Bound": tpl.sumOverSumBound80(true, usFmt),
  413. "80% Lower Bound": tpl.sumOverSumBound80(false, usFmt),
  414. "Sum as Fraction of Total": tpl.fractionOf(tpl.sum(), "total", usFmtPct),
  415. "Sum as Fraction of Rows": tpl.fractionOf(tpl.sum(), "row", usFmtPct),
  416. "Sum as Fraction of Columns": tpl.fractionOf(tpl.sum(), "col", usFmtPct),
  417. "Count as Fraction of Total": tpl.fractionOf(tpl.count(), "total", usFmtPct),
  418. "Count as Fraction of Rows": tpl.fractionOf(tpl.count(), "row", usFmtPct),
  419. "Count as Fraction of Columns": tpl.fractionOf(tpl.count(), "col", usFmtPct)
  420. };
  421. })(aggregatorTemplates);
  422. renderers = {
  423. "Table": function(data, opts) {
  424. return pivotTableRenderer(data, opts);
  425. },
  426. "Table Barchart": function(data, opts) {
  427. return $(pivotTableRenderer(data, opts)).barchart();
  428. },
  429. "Heatmap": function(data, opts) {
  430. return $(pivotTableRenderer(data, opts)).heatmap("heatmap", opts);
  431. },
  432. "Row Heatmap": function(data, opts) {
  433. return $(pivotTableRenderer(data, opts)).heatmap("rowheatmap", opts);
  434. },
  435. "Col Heatmap": function(data, opts) {
  436. return $(pivotTableRenderer(data, opts)).heatmap("colheatmap", opts);
  437. }
  438. };
  439. locales = {
  440. en: {
  441. aggregators: aggregators,
  442. renderers: renderers,
  443. localeStrings: {
  444. renderError: "An error occurred rendering the PivotTable results.",
  445. computeError: "An error occurred computing the PivotTable results.",
  446. uiRenderError: "An error occurred rendering the PivotTable UI.",
  447. selectAll: "Select All",
  448. selectNone: "Select None",
  449. tooMany: "(too many to list)",
  450. filterResults: "Filter values",
  451. apply: "Apply",
  452. cancel: "Cancel",
  453. totals: "Totals",
  454. vs: "vs",
  455. by: "by"
  456. }
  457. }
  458. };
  459. mthNamesEn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  460. dayNamesEn = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  461. zeroPad = function(number) {
  462. return ("0" + number).substr(-2, 2);
  463. };
  464. derivers = {
  465. bin: function(col, binWidth) {
  466. return function(record) {
  467. return record[col] - record[col] % binWidth;
  468. };
  469. },
  470. dateFormat: function(col, formatString, utcOutput, mthNames, dayNames) {
  471. var utc;
  472. if (utcOutput == null) {
  473. utcOutput = false;
  474. }
  475. if (mthNames == null) {
  476. mthNames = mthNamesEn;
  477. }
  478. if (dayNames == null) {
  479. dayNames = dayNamesEn;
  480. }
  481. utc = utcOutput ? "UTC" : "";
  482. return function(record) {
  483. var date;
  484. date = new Date(Date.parse(record[col]));
  485. if (isNaN(date)) {
  486. return "";
  487. }
  488. return formatString.replace(/%(.)/g, function(m, p) {
  489. switch (p) {
  490. case "y":
  491. return date["get" + utc + "FullYear"]();
  492. case "m":
  493. return zeroPad(date["get" + utc + "Month"]() + 1);
  494. case "n":
  495. return mthNames[date["get" + utc + "Month"]()];
  496. case "d":
  497. return zeroPad(date["get" + utc + "Date"]());
  498. case "w":
  499. return dayNames[date["get" + utc + "Day"]()];
  500. case "x":
  501. return date["get" + utc + "Day"]();
  502. case "H":
  503. return zeroPad(date["get" + utc + "Hours"]());
  504. case "M":
  505. return zeroPad(date["get" + utc + "Minutes"]());
  506. case "S":
  507. return zeroPad(date["get" + utc + "Seconds"]());
  508. default:
  509. return "%" + p;
  510. }
  511. });
  512. };
  513. }
  514. };
  515. rx = /(\d+)|(\D+)/g;
  516. rd = /\d/;
  517. rz = /^0/;
  518. naturalSort = (function(_this) {
  519. return function(as, bs) {
  520. var a, a1, b, b1, nas, nbs;
  521. if ((bs != null) && (as == null)) {
  522. return -1;
  523. }
  524. if ((as != null) && (bs == null)) {
  525. return 1;
  526. }
  527. if (typeof as === "number" && isNaN(as)) {
  528. return -1;
  529. }
  530. if (typeof bs === "number" && isNaN(bs)) {
  531. return 1;
  532. }
  533. nas = +as;
  534. nbs = +bs;
  535. if (nas < nbs) {
  536. return -1;
  537. }
  538. if (nas > nbs) {
  539. return 1;
  540. }
  541. if (typeof as === "number" && typeof bs !== "number") {
  542. return -1;
  543. }
  544. if (typeof bs === "number" && typeof as !== "number") {
  545. return 1;
  546. }
  547. if (typeof as === "number" && typeof bs === "number") {
  548. return 0;
  549. }
  550. if (isNaN(nbs) && !isNaN(nas)) {
  551. return -1;
  552. }
  553. if (isNaN(nas) && !isNaN(nbs)) {
  554. return 1;
  555. }
  556. a = String(as);
  557. b = String(bs);
  558. if (a === b) {
  559. return 0;
  560. }
  561. if (!(rd.test(a) && rd.test(b))) {
  562. return (a > b ? 1 : -1);
  563. }
  564. a = a.match(rx);
  565. b = b.match(rx);
  566. while (a.length && b.length) {
  567. a1 = a.shift();
  568. b1 = b.shift();
  569. if (a1 !== b1) {
  570. if (rd.test(a1) && rd.test(b1)) {
  571. return a1.replace(rz, ".0") - b1.replace(rz, ".0");
  572. } else {
  573. return (a1 > b1 ? 1 : -1);
  574. }
  575. }
  576. }
  577. return a.length - b.length;
  578. };
  579. })(this);
  580. sortAs = function(order) {
  581. var i, l_mapping, mapping, x;
  582. mapping = {};
  583. l_mapping = {};
  584. for (i in order) {
  585. x = order[i];
  586. mapping[x] = i;
  587. if (typeof x === "string") {
  588. l_mapping[x.toLowerCase()] = i;
  589. }
  590. }
  591. return function(a, b) {
  592. if ((mapping[a] != null) && (mapping[b] != null)) {
  593. return mapping[a] - mapping[b];
  594. } else if (mapping[a] != null) {
  595. return -1;
  596. } else if (mapping[b] != null) {
  597. return 1;
  598. } else if ((l_mapping[a] != null) && (l_mapping[b] != null)) {
  599. return l_mapping[a] - l_mapping[b];
  600. } else if (l_mapping[a] != null) {
  601. return -1;
  602. } else if (l_mapping[b] != null) {
  603. return 1;
  604. } else {
  605. return naturalSort(a, b);
  606. }
  607. };
  608. };
  609. getSort = function(sorters, attr) {
  610. var sort;
  611. if (sorters != null) {
  612. if ($.isFunction(sorters)) {
  613. sort = sorters(attr);
  614. if ($.isFunction(sort)) {
  615. return sort;
  616. }
  617. } else if (sorters[attr] != null) {
  618. return sorters[attr];
  619. }
  620. }
  621. return naturalSort;
  622. };
  623. /*
  624. Data Model class
  625. */
  626. PivotData = (function() {
  627. function PivotData(input, opts) {
  628. var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9;
  629. if (opts == null) {
  630. opts = {};
  631. }
  632. this.getAggregator = bind(this.getAggregator, this);
  633. this.getRowKeys = bind(this.getRowKeys, this);
  634. this.getColKeys = bind(this.getColKeys, this);
  635. this.sortKeys = bind(this.sortKeys, this);
  636. this.arrSort = bind(this.arrSort, this);
  637. this.input = input;
  638. this.aggregator = (ref = opts.aggregator) != null ? ref : aggregatorTemplates.count()();
  639. this.aggregatorName = (ref1 = opts.aggregatorName) != null ? ref1 : "Count";
  640. this.colAttrs = (ref2 = opts.cols) != null ? ref2 : [];
  641. this.rowAttrs = (ref3 = opts.rows) != null ? ref3 : [];
  642. this.valAttrs = (ref4 = opts.vals) != null ? ref4 : [];
  643. this.sorters = (ref5 = opts.sorters) != null ? ref5 : {};
  644. this.rowOrder = (ref6 = opts.rowOrder) != null ? ref6 : "key_a_to_z";
  645. this.colOrder = (ref7 = opts.colOrder) != null ? ref7 : "key_a_to_z";
  646. this.derivedAttributes = (ref8 = opts.derivedAttributes) != null ? ref8 : {};
  647. this.filter = (ref9 = opts.filter) != null ? ref9 : (function() {
  648. return true;
  649. });
  650. this.tree = {};
  651. this.rowKeys = [];
  652. this.colKeys = [];
  653. this.rowTotals = {};
  654. this.colTotals = {};
  655. this.allTotal = this.aggregator(this, [], []);
  656. this.sorted = false;
  657. PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
  658. return function(record) {
  659. if (_this.filter(record)) {
  660. return _this.processRecord(record);
  661. }
  662. };
  663. })(this));
  664. }
  665. PivotData.forEachRecord = function(input, derivedAttributes, f) {
  666. var addRecord, compactRecord, i, j, k, l, len1, record, ref, results, results1, tblCols;
  667. if ($.isEmptyObject(derivedAttributes)) {
  668. addRecord = f;
  669. } else {
  670. addRecord = function(record) {
  671. var k, ref, v;
  672. for (k in derivedAttributes) {
  673. v = derivedAttributes[k];
  674. record[k] = (ref = v(record)) != null ? ref : record[k];
  675. }
  676. return f(record);
  677. };
  678. }
  679. if ($.isFunction(input)) {
  680. return input(addRecord);
  681. } else if ($.isArray(input)) {
  682. if ($.isArray(input[0])) {
  683. results = [];
  684. for (i in input) {
  685. if (!hasProp.call(input, i)) continue;
  686. compactRecord = input[i];
  687. if (!(i > 0)) {
  688. continue;
  689. }
  690. record = {};
  691. ref = input[0];
  692. for (j in ref) {
  693. if (!hasProp.call(ref, j)) continue;
  694. k = ref[j];
  695. record[k] = compactRecord[j];
  696. }
  697. results.push(addRecord(record));
  698. }
  699. return results;
  700. } else {
  701. results1 = [];
  702. for (l = 0, len1 = input.length; l < len1; l++) {
  703. record = input[l];
  704. results1.push(addRecord(record));
  705. }
  706. return results1;
  707. }
  708. } else if (input instanceof $) {
  709. tblCols = [];
  710. $("thead > tr > th", input).each(function(i) {
  711. return tblCols.push($(this).text());
  712. });
  713. return $("tbody > tr", input).each(function(i) {
  714. record = {};
  715. $("td", this).each(function(j) {
  716. return record[tblCols[j]] = $(this).text();
  717. });
  718. return addRecord(record);
  719. });
  720. } else {
  721. throw new Error("unknown input format");
  722. }
  723. };
  724. PivotData.prototype.forEachMatchingRecord = function(criteria, callback) {
  725. return PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
  726. return function(record) {
  727. var k, ref, v;
  728. if (!_this.filter(record)) {
  729. return;
  730. }
  731. for (k in criteria) {
  732. v = criteria[k];
  733. if (v !== ((ref = record[k]) != null ? ref : "null")) {
  734. return;
  735. }
  736. }
  737. return callback(record);
  738. };
  739. })(this));
  740. };
  741. PivotData.prototype.arrSort = function(attrs) {
  742. var a, sortersArr;
  743. sortersArr = (function() {
  744. var l, len1, results;
  745. results = [];
  746. for (l = 0, len1 = attrs.length; l < len1; l++) {
  747. a = attrs[l];
  748. results.push(getSort(this.sorters, a));
  749. }
  750. return results;
  751. }).call(this);
  752. return function(a, b) {
  753. var comparison, i, sorter;
  754. for (i in sortersArr) {
  755. if (!hasProp.call(sortersArr, i)) continue;
  756. sorter = sortersArr[i];
  757. comparison = sorter(a[i], b[i]);
  758. if (comparison !== 0) {
  759. return comparison;
  760. }
  761. }
  762. return 0;
  763. };
  764. };
  765. PivotData.prototype.sortKeys = function() {
  766. var v;
  767. if (!this.sorted) {
  768. this.sorted = true;
  769. v = (function(_this) {
  770. return function(r, c) {
  771. return _this.getAggregator(r, c).value();
  772. };
  773. })(this);
  774. switch (this.rowOrder) {
  775. case "value_a_to_z":
  776. this.rowKeys.sort((function(_this) {
  777. return function(a, b) {
  778. return naturalSort(v(a, []), v(b, []));
  779. };
  780. })(this));
  781. break;
  782. case "value_z_to_a":
  783. this.rowKeys.sort((function(_this) {
  784. return function(a, b) {
  785. return -naturalSort(v(a, []), v(b, []));
  786. };
  787. })(this));
  788. break;
  789. default:
  790. this.rowKeys.sort(this.arrSort(this.rowAttrs));
  791. }
  792. switch (this.colOrder) {
  793. case "value_a_to_z":
  794. return this.colKeys.sort((function(_this) {
  795. return function(a, b) {
  796. return naturalSort(v([], a), v([], b));
  797. };
  798. })(this));
  799. case "value_z_to_a":
  800. return this.colKeys.sort((function(_this) {
  801. return function(a, b) {
  802. return -naturalSort(v([], a), v([], b));
  803. };
  804. })(this));
  805. default:
  806. return this.colKeys.sort(this.arrSort(this.colAttrs));
  807. }
  808. }
  809. };
  810. PivotData.prototype.getColKeys = function() {
  811. this.sortKeys();
  812. return this.colKeys;
  813. };
  814. PivotData.prototype.getRowKeys = function() {
  815. this.sortKeys();
  816. return this.rowKeys;
  817. };
  818. PivotData.prototype.processRecord = function(record) {
  819. var colKey, flatColKey, flatRowKey, l, len1, len2, n, ref, ref1, ref2, ref3, rowKey, x;
  820. colKey = [];
  821. rowKey = [];
  822. ref = this.colAttrs;
  823. for (l = 0, len1 = ref.length; l < len1; l++) {
  824. x = ref[l];
  825. colKey.push((ref1 = record[x]) != null ? ref1 : "null");
  826. }
  827. ref2 = this.rowAttrs;
  828. for (n = 0, len2 = ref2.length; n < len2; n++) {
  829. x = ref2[n];
  830. rowKey.push((ref3 = record[x]) != null ? ref3 : "null");
  831. }
  832. flatRowKey = rowKey.join(String.fromCharCode(0));
  833. flatColKey = colKey.join(String.fromCharCode(0));
  834. this.allTotal.push(record);
  835. if (rowKey.length !== 0) {
  836. if (!this.rowTotals[flatRowKey]) {
  837. this.rowKeys.push(rowKey);
  838. this.rowTotals[flatRowKey] = this.aggregator(this, rowKey, []);
  839. }
  840. this.rowTotals[flatRowKey].push(record);
  841. }
  842. if (colKey.length !== 0) {
  843. if (!this.colTotals[flatColKey]) {
  844. this.colKeys.push(colKey);
  845. this.colTotals[flatColKey] = this.aggregator(this, [], colKey);
  846. }
  847. this.colTotals[flatColKey].push(record);
  848. }
  849. if (colKey.length !== 0 && rowKey.length !== 0) {
  850. if (!this.tree[flatRowKey]) {
  851. this.tree[flatRowKey] = {};
  852. }
  853. if (!this.tree[flatRowKey][flatColKey]) {
  854. this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
  855. }
  856. return this.tree[flatRowKey][flatColKey].push(record);
  857. }
  858. };
  859. PivotData.prototype.getAggregator = function(rowKey, colKey) {
  860. var agg, flatColKey, flatRowKey;
  861. flatRowKey = rowKey.join(String.fromCharCode(0));
  862. flatColKey = colKey.join(String.fromCharCode(0));
  863. if (rowKey.length === 0 && colKey.length === 0) {
  864. agg = this.allTotal;
  865. } else if (rowKey.length === 0) {
  866. agg = this.colTotals[flatColKey];
  867. } else if (colKey.length === 0) {
  868. agg = this.rowTotals[flatRowKey];
  869. } else {
  870. agg = this.tree[flatRowKey][flatColKey];
  871. }
  872. return agg != null ? agg : {
  873. value: (function() {
  874. return null;
  875. }),
  876. format: function() {
  877. return "";
  878. }
  879. };
  880. };
  881. return PivotData;
  882. })();
  883. $.pivotUtilities = {
  884. aggregatorTemplates: aggregatorTemplates,
  885. aggregators: aggregators,
  886. renderers: renderers,
  887. derivers: derivers,
  888. locales: locales,
  889. naturalSort: naturalSort,
  890. numberFormat: numberFormat,
  891. sortAs: sortAs,
  892. PivotData: PivotData
  893. };
  894. /*
  895. Default Renderer for hierarchical table layout
  896. */
  897. pivotTableRenderer = function(pivotData, opts) {
  898. var aggregator, c, colAttrs, colKey, colKeys, defaults, getClickHandler, i, j, r, result, rowAttrs, rowKey, rowKeys, spanSize, tbody, td, th, thead, totalAggregator, tr, txt, val, x;
  899. defaults = {
  900. table: {
  901. clickCallback: null,
  902. rowTotals: true,
  903. colTotals: true
  904. },
  905. localeStrings: {
  906. totals: "Totals"
  907. }
  908. };
  909. opts = $.extend(true, {}, defaults, opts);
  910. colAttrs = pivotData.colAttrs;
  911. rowAttrs = pivotData.rowAttrs;
  912. rowKeys = pivotData.getRowKeys();
  913. colKeys = pivotData.getColKeys();
  914. if (opts.table.clickCallback) {
  915. getClickHandler = function(value, rowValues, colValues) {
  916. var attr, filters, i;
  917. filters = {};
  918. for (i in colAttrs) {
  919. if (!hasProp.call(colAttrs, i)) continue;
  920. attr = colAttrs[i];
  921. if (colValues[i] != null) {
  922. filters[attr] = colValues[i];
  923. }
  924. }
  925. for (i in rowAttrs) {
  926. if (!hasProp.call(rowAttrs, i)) continue;
  927. attr = rowAttrs[i];
  928. if (rowValues[i] != null) {
  929. filters[attr] = rowValues[i];
  930. }
  931. }
  932. return function(e) {
  933. return opts.table.clickCallback(e, value, filters, pivotData);
  934. };
  935. };
  936. }
  937. result = document.createElement("table");
  938. result.className = "pvtTable";
  939. spanSize = function(arr, i, j) {
  940. var l, len, n, noDraw, ref, ref1, stop, x;
  941. if (i !== 0) {
  942. noDraw = true;
  943. for (x = l = 0, ref = j; 0 <= ref ? l <= ref : l >= ref; x = 0 <= ref ? ++l : --l) {
  944. if (arr[i - 1][x] !== arr[i][x]) {
  945. noDraw = false;
  946. }
  947. }
  948. if (noDraw) {
  949. return -1;
  950. }
  951. }
  952. len = 0;
  953. while (i + len < arr.length) {
  954. stop = false;
  955. for (x = n = 0, ref1 = j; 0 <= ref1 ? n <= ref1 : n >= ref1; x = 0 <= ref1 ? ++n : --n) {
  956. if (arr[i][x] !== arr[i + len][x]) {
  957. stop = true;
  958. }
  959. }
  960. if (stop) {
  961. break;
  962. }
  963. len++;
  964. }
  965. return len;
  966. };
  967. thead = document.createElement("thead");
  968. for (j in colAttrs) {
  969. if (!hasProp.call(colAttrs, j)) continue;
  970. c = colAttrs[j];
  971. tr = document.createElement("tr");
  972. if (parseInt(j) === 0 && rowAttrs.length !== 0) {
  973. th = document.createElement("th");
  974. th.setAttribute("colspan", rowAttrs.length);
  975. th.setAttribute("rowspan", colAttrs.length);
  976. tr.appendChild(th);
  977. }
  978. th = document.createElement("th");
  979. th.className = "pvtAxisLabel";
  980. th.textContent = c;
  981. tr.appendChild(th);
  982. for (i in colKeys) {
  983. if (!hasProp.call(colKeys, i)) continue;
  984. colKey = colKeys[i];
  985. x = spanSize(colKeys, parseInt(i), parseInt(j));
  986. if (x !== -1) {
  987. th = document.createElement("th");
  988. th.className = "pvtColLabel";
  989. th.textContent = colKey[j];
  990. th.setAttribute("colspan", x);
  991. if (parseInt(j) === colAttrs.length - 1 && rowAttrs.length !== 0) {
  992. th.setAttribute("rowspan", 2);
  993. }
  994. tr.appendChild(th);
  995. }
  996. }
  997. if (parseInt(j) === 0 && opts.table.rowTotals) {
  998. th = document.createElement("th");
  999. th.className = "pvtTotalLabel pvtRowTotalLabel";
  1000. th.innerHTML = opts.localeStrings.totals;
  1001. th.setAttribute("rowspan", colAttrs.length + (rowAttrs.length === 0 ? 0 : 1));
  1002. tr.appendChild(th);
  1003. }
  1004. thead.appendChild(tr);
  1005. }
  1006. if (rowAttrs.length !== 0) {
  1007. tr = document.createElement("tr");
  1008. for (i in rowAttrs) {
  1009. if (!hasProp.call(rowAttrs, i)) continue;
  1010. r = rowAttrs[i];
  1011. th = document.createElement("th");
  1012. th.className = "pvtAxisLabel";
  1013. th.textContent = r;
  1014. tr.appendChild(th);
  1015. }
  1016. th = document.createElement("th");
  1017. if (colAttrs.length === 0) {
  1018. th.className = "pvtTotalLabel pvtRowTotalLabel";
  1019. th.innerHTML = opts.localeStrings.totals;
  1020. }
  1021. tr.appendChild(th);
  1022. thead.appendChild(tr);
  1023. }
  1024. result.appendChild(thead);
  1025. tbody = document.createElement("tbody");
  1026. for (i in rowKeys) {
  1027. if (!hasProp.call(rowKeys, i)) continue;
  1028. rowKey = rowKeys[i];
  1029. tr = document.createElement("tr");
  1030. for (j in rowKey) {
  1031. if (!hasProp.call(rowKey, j)) continue;
  1032. txt = rowKey[j];
  1033. x = spanSize(rowKeys, parseInt(i), parseInt(j));
  1034. if (x !== -1) {
  1035. th = document.createElement("th");
  1036. th.className = "pvtRowLabel";
  1037. th.textContent = txt;
  1038. th.setAttribute("rowspan", x);
  1039. if (parseInt(j) === rowAttrs.length - 1 && colAttrs.length !== 0) {
  1040. th.setAttribute("colspan", 2);
  1041. }
  1042. tr.appendChild(th);
  1043. }
  1044. }
  1045. for (j in colKeys) {
  1046. if (!hasProp.call(colKeys, j)) continue;
  1047. colKey = colKeys[j];
  1048. aggregator = pivotData.getAggregator(rowKey, colKey);
  1049. val = aggregator.value();
  1050. td = document.createElement("td");
  1051. td.className = "pvtVal row" + i + " col" + j;
  1052. td.textContent = aggregator.format(val);
  1053. td.setAttribute("data-value", val);
  1054. if (getClickHandler != null) {
  1055. td.onclick = getClickHandler(val, rowKey, colKey);
  1056. }
  1057. tr.appendChild(td);
  1058. }
  1059. if (opts.table.rowTotals || colAttrs.length === 0) {
  1060. totalAggregator = pivotData.getAggregator(rowKey, []);
  1061. val = totalAggregator.value();
  1062. td = document.createElement("td");
  1063. td.className = "pvtTotal rowTotal";
  1064. td.textContent = totalAggregator.format(val);
  1065. td.setAttribute("data-value", val);
  1066. if (getClickHandler != null) {
  1067. td.onclick = getClickHandler(val, rowKey, []);
  1068. }
  1069. td.setAttribute("data-for", "row" + i);
  1070. tr.appendChild(td);
  1071. }
  1072. tbody.appendChild(tr);
  1073. }
  1074. if (opts.table.colTotals || rowAttrs.length === 0) {
  1075. tr = document.createElement("tr");
  1076. if (opts.table.colTotals || rowAttrs.length === 0) {
  1077. th = document.createElement("th");
  1078. th.className = "pvtTotalLabel pvtColTotalLabel";
  1079. th.innerHTML = opts.localeStrings.totals;
  1080. th.setAttribute("colspan", rowAttrs.length + (colAttrs.length === 0 ? 0 : 1));
  1081. tr.appendChild(th);
  1082. }
  1083. for (j in colKeys) {
  1084. if (!hasProp.call(colKeys, j)) continue;
  1085. colKey = colKeys[j];
  1086. totalAggregator = pivotData.getAggregator([], colKey);
  1087. val = totalAggregator.value();
  1088. td = document.createElement("td");
  1089. td.className = "pvtTotal colTotal";
  1090. td.textContent = totalAggregator.format(val);
  1091. td.setAttribute("data-value", val);
  1092. if (getClickHandler != null) {
  1093. td.onclick = getClickHandler(val, [], colKey);
  1094. }
  1095. td.setAttribute("data-for", "col" + j);
  1096. tr.appendChild(td);
  1097. }
  1098. if (opts.table.rowTotals || colAttrs.length === 0) {
  1099. totalAggregator = pivotData.getAggregator([], []);
  1100. val = totalAggregator.value();
  1101. td = document.createElement("td");
  1102. td.className = "pvtGrandTotal";
  1103. td.textContent = totalAggregator.format(val);
  1104. td.setAttribute("data-value", val);
  1105. if (getClickHandler != null) {
  1106. td.onclick = getClickHandler(val, [], []);
  1107. }
  1108. tr.appendChild(td);
  1109. }
  1110. tbody.appendChild(tr);
  1111. }
  1112. result.appendChild(tbody);
  1113. result.setAttribute("data-numrows", rowKeys.length);
  1114. result.setAttribute("data-numcols", colKeys.length);
  1115. return result;
  1116. };
  1117. /*
  1118. Pivot Table core: create PivotData object and call Renderer on it
  1119. */
  1120. $.fn.pivot = function(input, inputOpts, locale) {
  1121. var defaults, e, localeDefaults, localeStrings, opts, pivotData, result, x;
  1122. if (locale == null) {
  1123. locale = "en";
  1124. }
  1125. if (locales[locale] == null) {
  1126. locale = "en";
  1127. }
  1128. defaults = {
  1129. cols: [],
  1130. rows: [],
  1131. vals: [],
  1132. rowOrder: "key_a_to_z",
  1133. colOrder: "key_a_to_z",
  1134. dataClass: PivotData,
  1135. filter: function() {
  1136. return true;
  1137. },
  1138. aggregator: aggregatorTemplates.count()(),
  1139. aggregatorName: "Count",
  1140. sorters: {},
  1141. derivedAttributes: {},
  1142. renderer: pivotTableRenderer
  1143. };
  1144. localeStrings = $.extend(true, {}, locales.en.localeStrings, locales[locale].localeStrings);
  1145. localeDefaults = {
  1146. rendererOptions: {
  1147. localeStrings: localeStrings
  1148. },
  1149. localeStrings: localeStrings
  1150. };
  1151. opts = $.extend(true, {}, localeDefaults, $.extend({}, defaults, inputOpts));
  1152. result = null;
  1153. try {
  1154. pivotData = new opts.dataClass(input, opts);
  1155. try {
  1156. result = opts.renderer(pivotData, opts.rendererOptions);
  1157. } catch (error) {
  1158. e = error;
  1159. if (typeof console !== "undefined" && console !== null) {
  1160. console.error(e.stack);
  1161. }
  1162. result = $("<span>").html(opts.localeStrings.renderError);
  1163. }
  1164. } catch (error) {
  1165. e = error;
  1166. if (typeof console !== "undefined" && console !== null) {
  1167. console.error(e.stack);
  1168. }
  1169. result = $("<span>").html(opts.localeStrings.computeError);
  1170. }
  1171. x = this[0];
  1172. while (x.hasChildNodes()) {
  1173. x.removeChild(x.lastChild);
  1174. }
  1175. return this.append(result);
  1176. };
  1177. /*
  1178. Pivot Table UI: calls Pivot Table core above with options set by user
  1179. */
  1180. $.fn.pivotUI = function(input, inputOpts, overwrite, locale) {
  1181. var a, aggregator, attr, attrLength, attrValues, c, colOrderArrow, defaults, e, existingOpts, fn1, i, initialRender, l, len1, len2, len3, localeDefaults, localeStrings, materializedInput, n, o, opts, ordering, pivotTable, recordsProcessed, ref, ref1, ref2, ref3, refresh, refreshDelayed, renderer, rendererControl, rowOrderArrow, shownAttributes, shownInAggregators, shownInDragDrop, tr1, tr2, uiTable, unused, unusedAttrsVerticalAutoCutoff, unusedAttrsVerticalAutoOverride, x;
  1182. if (overwrite == null) {
  1183. overwrite = false;
  1184. }
  1185. if (locale == null) {
  1186. locale = "en";
  1187. }
  1188. if (locales[locale] == null) {
  1189. locale = "en";
  1190. }
  1191. defaults = {
  1192. derivedAttributes: {},
  1193. aggregators: locales[locale].aggregators,
  1194. renderers: locales[locale].renderers,
  1195. hiddenAttributes: [],
  1196. hiddenFromAggregators: [],
  1197. hiddenFromDragDrop: [],
  1198. menuLimit: 500,
  1199. cols: [],
  1200. rows: [],
  1201. vals: [],
  1202. rowOrder: "key_a_to_z",
  1203. colOrder: "key_a_to_z",
  1204. dataClass: PivotData,
  1205. exclusions: {},
  1206. inclusions: {},
  1207. unusedAttrsVertical: 85,
  1208. autoSortUnusedAttrs: false,
  1209. onRefresh: null,
  1210. showUI: true,
  1211. filter: function() {
  1212. return true;
  1213. },
  1214. sorters: {}
  1215. };
  1216. localeStrings = $.extend(true, {}, locales.en.localeStrings, locales[locale].localeStrings);
  1217. localeDefaults = {
  1218. rendererOptions: {
  1219. localeStrings: localeStrings
  1220. },
  1221. localeStrings: localeStrings
  1222. };
  1223. existingOpts = this.data("pivotUIOptions");
  1224. if ((existingOpts == null) || overwrite) {
  1225. opts = $.extend(true, {}, localeDefaults, $.extend({}, defaults, inputOpts));
  1226. } else {
  1227. opts = existingOpts;
  1228. }
  1229. try {
  1230. attrValues = {};
  1231. materializedInput = [];
  1232. recordsProcessed = 0;
  1233. PivotData.forEachRecord(input, opts.derivedAttributes, function(record) {
  1234. var attr, base, ref, value;
  1235. if (!opts.filter(record)) {
  1236. return;
  1237. }
  1238. materializedInput.push(record);
  1239. for (attr in record) {
  1240. if (!hasProp.call(record, attr)) continue;
  1241. if (attrValues[attr] == null) {
  1242. attrValues[attr] = {};
  1243. if (recordsProcessed > 0) {
  1244. attrValues[attr]["null"] = recordsProcessed;
  1245. }
  1246. }
  1247. }
  1248. for (attr in attrValues) {
  1249. value = (ref = record[attr]) != null ? ref : "null";
  1250. if ((base = attrValues[attr])[value] == null) {
  1251. base[value] = 0;
  1252. }
  1253. attrValues[attr][value]++;
  1254. }
  1255. return recordsProcessed++;
  1256. });
  1257. uiTable = $("<table>", {
  1258. "class": "pvtUi"
  1259. }).attr("cellpadding", 5);
  1260. rendererControl = $("<td>").addClass("pvtUiCell");
  1261. renderer = $("<select>").addClass('pvtRenderer').appendTo(rendererControl).bind("change", function() {
  1262. return refresh();
  1263. });
  1264. ref = opts.renderers;
  1265. for (x in ref) {
  1266. if (!hasProp.call(ref, x)) continue;
  1267. $("<option>").val(x).html(x).appendTo(renderer);
  1268. }
  1269. unused = $("<td>").addClass('pvtAxisContainer pvtUnused pvtUiCell');
  1270. shownAttributes = (function() {
  1271. var results;
  1272. results = [];
  1273. for (a in attrValues) {
  1274. if (indexOf.call(opts.hiddenAttributes, a) < 0) {
  1275. results.push(a);
  1276. }
  1277. }
  1278. return results;
  1279. })();
  1280. shownInAggregators = (function() {
  1281. var l, len1, results;
  1282. results = [];
  1283. for (l = 0, len1 = shownAttributes.length; l < len1; l++) {
  1284. c = shownAttributes[l];
  1285. if (indexOf.call(opts.hiddenFromAggregators, c) < 0) {
  1286. results.push(c);
  1287. }
  1288. }
  1289. return results;
  1290. })();
  1291. shownInDragDrop = (function() {
  1292. var l, len1, results;
  1293. results = [];
  1294. for (l = 0, len1 = shownAttributes.length; l < len1; l++) {
  1295. c = shownAttributes[l];
  1296. if (indexOf.call(opts.hiddenFromDragDrop, c) < 0) {
  1297. results.push(c);
  1298. }
  1299. }
  1300. return results;
  1301. })();
  1302. unusedAttrsVerticalAutoOverride = false;
  1303. if (opts.unusedAttrsVertical === "auto") {
  1304. unusedAttrsVerticalAutoCutoff = 120;
  1305. } else {
  1306. unusedAttrsVerticalAutoCutoff = parseInt(opts.unusedAttrsVertical);
  1307. }
  1308. if (!isNaN(unusedAttrsVerticalAutoCutoff)) {
  1309. attrLength = 0;
  1310. for (l = 0, len1 = shownInDragDrop.length; l < len1; l++) {
  1311. a = shownInDragDrop[l];
  1312. attrLength += a.length;
  1313. }
  1314. unusedAttrsVerticalAutoOverride = attrLength > unusedAttrsVerticalAutoCutoff;
  1315. }
  1316. if (opts.unusedAttrsVertical === true || unusedAttrsVerticalAutoOverride) {
  1317. unused.addClass('pvtVertList');
  1318. } else {
  1319. unused.addClass('pvtHorizList');
  1320. }
  1321. fn1 = function(attr) {
  1322. var attrElem, checkContainer, closeFilterBox, controls, filterItem, filterItemExcluded, finalButtons, hasExcludedItem, len2, n, placeholder, ref1, sorter, triangleLink, v, value, valueCount, valueList, values;
  1323. values = (function() {
  1324. var results;
  1325. results = [];
  1326. for (v in attrValues[attr]) {
  1327. results.push(v);
  1328. }
  1329. return results;
  1330. })();
  1331. hasExcludedItem = false;
  1332. valueList = $("<div>").addClass('pvtFilterBox').hide();
  1333. valueList.append($("<h4>").append($("<span>").text(attr), $("<span>").addClass("count").text("(" + values.length + ")")));
  1334. if (values.length > opts.menuLimit) {
  1335. valueList.append($("<p>").html(opts.localeStrings.tooMany));
  1336. } else {
  1337. if (values.length > 5) {
  1338. controls = $("<p>").appendTo(valueList);
  1339. sorter = getSort(opts.sorters, attr);
  1340. placeholder = opts.localeStrings.filterResults;
  1341. $("<input>", {
  1342. type: "text"
  1343. }).appendTo(controls).attr({
  1344. placeholder: placeholder,
  1345. "class": "pvtSearch"
  1346. }).bind("keyup", function() {
  1347. var accept, accept_gen, filter;
  1348. filter = $(this).val().toLowerCase().trim();
  1349. accept_gen = function(prefix, accepted) {
  1350. return function(v) {
  1351. var real_filter, ref1;
  1352. real_filter = filter.substring(prefix.length).trim();
  1353. if (real_filter.length === 0) {
  1354. return true;
  1355. }
  1356. return ref1 = Math.sign(sorter(v.toLowerCase(), real_filter)), indexOf.call(accepted, ref1) >= 0;
  1357. };
  1358. };
  1359. accept = filter.indexOf(">=") === 0 ? accept_gen(">=", [1, 0]) : filter.indexOf("<=") === 0 ? accept_gen("<=", [-1, 0]) : filter.indexOf(">") === 0 ? accept_gen(">", [1]) : filter.indexOf("<") === 0 ? accept_gen("<", [-1]) : filter.indexOf("~") === 0 ? function(v) {
  1360. if (filter.substring(1).trim().length === 0) {
  1361. return true;
  1362. }
  1363. return v.toLowerCase().match(filter.substring(1));
  1364. } : function(v) {
  1365. return v.toLowerCase().indexOf(filter) !== -1;
  1366. };
  1367. return valueList.find('.pvtCheckContainer p label span.value').each(function() {
  1368. if (accept($(this).text())) {
  1369. return $(this).parent().parent().show();
  1370. } else {
  1371. return $(this).parent().parent().hide();
  1372. }
  1373. });
  1374. });
  1375. controls.append($("<br>"));
  1376. $("<button>", {
  1377. type: "button"
  1378. }).appendTo(controls).html(opts.localeStrings.selectAll).bind("click", function() {
  1379. valueList.find("input:visible:not(:checked)").prop("checked", true).toggleClass("changed");
  1380. return false;
  1381. });
  1382. $("<button>", {
  1383. type: "button"
  1384. }).appendTo(controls).html(opts.localeStrings.selectNone).bind("click", function() {
  1385. valueList.find("input:visible:checked").prop("checked", false).toggleClass("changed");
  1386. return false;
  1387. });
  1388. }
  1389. checkContainer = $("<div>").addClass("pvtCheckContainer").appendTo(valueList);
  1390. ref1 = values.sort(getSort(opts.sorters, attr));
  1391. for (n = 0, len2 = ref1.length; n < len2; n++) {
  1392. value = ref1[n];
  1393. valueCount = attrValues[attr][value];
  1394. filterItem = $("<label>");
  1395. filterItemExcluded = false;
  1396. if (opts.inclusions[attr]) {
  1397. filterItemExcluded = (indexOf.call(opts.inclusions[attr], value) < 0);
  1398. } else if (opts.exclusions[attr]) {
  1399. filterItemExcluded = (indexOf.call(opts.exclusions[attr], value) >= 0);
  1400. }
  1401. hasExcludedItem || (hasExcludedItem = filterItemExcluded);
  1402. $("<input>").attr("type", "checkbox").addClass('pvtFilter').attr("checked", !filterItemExcluded).data("filter", [attr, value]).appendTo(filterItem).bind("change", function() {
  1403. return $(this).toggleClass("changed");
  1404. });
  1405. filterItem.append($("<span>").addClass("value").text(value));
  1406. filterItem.append($("<span>").addClass("count").text("(" + valueCount + ")"));
  1407. checkContainer.append($("<p>").append(filterItem));
  1408. }
  1409. }
  1410. closeFilterBox = function() {
  1411. if (valueList.find("[type='checkbox']").length > valueList.find("[type='checkbox']:checked").length) {
  1412. attrElem.addClass("pvtFilteredAttribute");
  1413. } else {
  1414. attrElem.removeClass("pvtFilteredAttribute");
  1415. }
  1416. valueList.find('.pvtSearch').val('');
  1417. valueList.find('.pvtCheckContainer p').show();
  1418. return valueList.hide();
  1419. };
  1420. finalButtons = $("<p>").appendTo(valueList);
  1421. if (values.length <= opts.menuLimit) {
  1422. $("<button>", {
  1423. type: "button"
  1424. }).text(opts.localeStrings.apply).appendTo(finalButtons).bind("click", function() {
  1425. if (valueList.find(".changed").removeClass("changed").length) {
  1426. refresh();
  1427. }
  1428. return closeFilterBox();
  1429. });
  1430. }
  1431. $("<button>", {
  1432. type: "button"
  1433. }).text(opts.localeStrings.cancel).appendTo(finalButtons).bind("click", function() {
  1434. valueList.find(".changed:checked").removeClass("changed").prop("checked", false);
  1435. valueList.find(".changed:not(:checked)").removeClass("changed").prop("checked", true);
  1436. return closeFilterBox();
  1437. });
  1438. triangleLink = $("<span>").addClass('pvtTriangle').html(" &#x25BE;").bind("click", function(e) {
  1439. var left, ref2, top;
  1440. ref2 = $(e.currentTarget).position(), left = ref2.left, top = ref2.top;
  1441. return valueList.css({
  1442. left: left + 10,
  1443. top: top + 10
  1444. }).show();
  1445. });
  1446. attrElem = $("<li>").addClass("axis_" + i).append($("<span>").addClass('pvtAttr').text(attr).data("attrName", attr).append(triangleLink));
  1447. if (hasExcludedItem) {
  1448. attrElem.addClass('pvtFilteredAttribute');
  1449. }
  1450. return unused.append(attrElem).append(valueList);
  1451. };
  1452. for (i in shownInDragDrop) {
  1453. if (!hasProp.call(shownInDragDrop, i)) continue;
  1454. attr = shownInDragDrop[i];
  1455. fn1(attr);
  1456. }
  1457. tr1 = $("<tr>").appendTo(uiTable);
  1458. aggregator = $("<select>").addClass('pvtAggregator').bind("change", function() {
  1459. return refresh();
  1460. });
  1461. ref1 = opts.aggregators;
  1462. for (x in ref1) {
  1463. if (!hasProp.call(ref1, x)) continue;
  1464. aggregator.append($("<option>").val(x).html(x));
  1465. }
  1466. ordering = {
  1467. key_a_to_z: {
  1468. rowSymbol: "&varr;",
  1469. colSymbol: "&harr;",
  1470. next: "value_a_to_z"
  1471. },
  1472. value_a_to_z: {
  1473. rowSymbol: "&darr;",
  1474. colSymbol: "&rarr;",
  1475. next: "value_z_to_a"
  1476. },
  1477. value_z_to_a: {
  1478. rowSymbol: "&uarr;",
  1479. colSymbol: "&larr;",
  1480. next: "key_a_to_z"
  1481. }
  1482. };
  1483. rowOrderArrow = $("<a>", {
  1484. role: "button"
  1485. }).addClass("pvtRowOrder").data("order", opts.rowOrder).html(ordering[opts.rowOrder].rowSymbol).bind("click", function() {
  1486. $(this).data("order", ordering[$(this).data("order")].next);
  1487. $(this).html(ordering[$(this).data("order")].rowSymbol);
  1488. return refresh();
  1489. });
  1490. colOrderArrow = $("<a>", {
  1491. role: "button"
  1492. }).addClass("pvtColOrder").data("order", opts.colOrder).html(ordering[opts.colOrder].colSymbol).bind("click", function() {
  1493. $(this).data("order", ordering[$(this).data("order")].next);
  1494. $(this).html(ordering[$(this).data("order")].colSymbol);
  1495. return refresh();
  1496. });
  1497. $("<td>").addClass('pvtVals pvtUiCell').appendTo(tr1).append(aggregator).append(rowOrderArrow).append(colOrderArrow).append($("<br>"));
  1498. $("<td>").addClass('pvtAxisContainer pvtHorizList pvtCols pvtUiCell').appendTo(tr1);
  1499. tr2 = $("<tr>").appendTo(uiTable);
  1500. tr2.append($("<td>").addClass('pvtAxisContainer pvtRows pvtUiCell').attr("valign", "top"));
  1501. pivotTable = $("<td>").attr("valign", "top").addClass('pvtRendererArea').appendTo(tr2);
  1502. if (opts.unusedAttrsVertical === true || unusedAttrsVerticalAutoOverride) {
  1503. uiTable.find('tr:nth-child(1)').prepend(rendererControl);
  1504. uiTable.find('tr:nth-child(2)').prepend(unused);
  1505. } else {
  1506. uiTable.prepend($("<tr>").append(rendererControl).append(unused));
  1507. }
  1508. this.html(uiTable);
  1509. ref2 = opts.cols;
  1510. for (n = 0, len2 = ref2.length; n < len2; n++) {
  1511. x = ref2[n];
  1512. this.find(".pvtCols").append(this.find(".axis_" + ($.inArray(x, shownInDragDrop))));
  1513. }
  1514. ref3 = opts.rows;
  1515. for (o = 0, len3 = ref3.length; o < len3; o++) {
  1516. x = ref3[o];
  1517. this.find(".pvtRows").append(this.find(".axis_" + ($.inArray(x, shownInDragDrop))));
  1518. }
  1519. if (opts.aggregatorName != null) {
  1520. this.find(".pvtAggregator").val(opts.aggregatorName);
  1521. }
  1522. if (opts.rendererName != null) {
  1523. this.find(".pvtRenderer").val(opts.rendererName);
  1524. }
  1525. if (!opts.showUI) {
  1526. this.find(".pvtUiCell").hide();
  1527. }
  1528. initialRender = true;
  1529. refreshDelayed = (function(_this) {
  1530. return function() {
  1531. var exclusions, inclusions, len4, newDropdown, numInputsToProcess, pivotUIOptions, pvtVals, ref4, ref5, subopts, t, u, unusedAttrsContainer, vals;
  1532. subopts = {
  1533. derivedAttributes: opts.derivedAttributes,
  1534. localeStrings: opts.localeStrings,
  1535. rendererOptions: opts.rendererOptions,
  1536. sorters: opts.sorters,
  1537. cols: [],
  1538. rows: [],
  1539. dataClass: opts.dataClass
  1540. };
  1541. numInputsToProcess = (ref4 = opts.aggregators[aggregator.val()]([])().numInputs) != null ? ref4 : 0;
  1542. vals = [];
  1543. _this.find(".pvtRows li span.pvtAttr").each(function() {
  1544. return subopts.rows.push($(this).data("attrName"));
  1545. });
  1546. _this.find(".pvtCols li span.pvtAttr").each(function() {
  1547. return subopts.cols.push($(this).data("attrName"));
  1548. });
  1549. _this.find(".pvtVals select.pvtAttrDropdown").each(function() {
  1550. if (numInputsToProcess === 0) {
  1551. return $(this).remove();
  1552. } else {
  1553. numInputsToProcess--;
  1554. if ($(this).val() !== "") {
  1555. return vals.push($(this).val());
  1556. }
  1557. }
  1558. });
  1559. if (numInputsToProcess !== 0) {
  1560. pvtVals = _this.find(".pvtVals");
  1561. for (x = t = 0, ref5 = numInputsToProcess; 0 <= ref5 ? t < ref5 : t > ref5; x = 0 <= ref5 ? ++t : --t) {
  1562. newDropdown = $("<select>").addClass('pvtAttrDropdown').append($("<option>")).bind("change", function() {
  1563. return refresh();
  1564. });
  1565. for (u = 0, len4 = shownInAggregators.length; u < len4; u++) {
  1566. attr = shownInAggregators[u];
  1567. newDropdown.append($("<option>").val(attr).text(attr));
  1568. }
  1569. pvtVals.append(newDropdown);
  1570. }
  1571. }
  1572. if (initialRender) {
  1573. vals = opts.vals;
  1574. i = 0;
  1575. _this.find(".pvtVals select.pvtAttrDropdown").each(function() {
  1576. $(this).val(vals[i]);
  1577. return i++;
  1578. });
  1579. initialRender = false;
  1580. }
  1581. subopts.aggregatorName = aggregator.val();
  1582. subopts.vals = vals;
  1583. subopts.aggregator = opts.aggregators[aggregator.val()](vals);
  1584. subopts.renderer = opts.renderers[renderer.val()];
  1585. subopts.rowOrder = rowOrderArrow.data("order");
  1586. subopts.colOrder = colOrderArrow.data("order");
  1587. exclusions = {};
  1588. _this.find('input.pvtFilter').not(':checked').each(function() {
  1589. var filter;
  1590. filter = $(this).data("filter");
  1591. if (exclusions[filter[0]] != null) {
  1592. return exclusions[filter[0]].push(filter[1]);
  1593. } else {
  1594. return exclusions[filter[0]] = [filter[1]];
  1595. }
  1596. });
  1597. inclusions = {};
  1598. _this.find('input.pvtFilter:checked').each(function() {
  1599. var filter;
  1600. filter = $(this).data("filter");
  1601. if (exclusions[filter[0]] != null) {
  1602. if (inclusions[filter[0]] != null) {
  1603. return inclusions[filter[0]].push(filter[1]);
  1604. } else {
  1605. return inclusions[filter[0]] = [filter[1]];
  1606. }
  1607. }
  1608. });
  1609. subopts.filter = function(record) {
  1610. var excludedItems, k, ref6, ref7;
  1611. if (!opts.filter(record)) {
  1612. return false;
  1613. }
  1614. for (k in exclusions) {
  1615. excludedItems = exclusions[k];
  1616. if (ref6 = "" + ((ref7 = record[k]) != null ? ref7 : 'null'), indexOf.call(excludedItems, ref6) >= 0) {
  1617. return false;
  1618. }
  1619. }
  1620. return true;
  1621. };
  1622. pivotTable.pivot(materializedInput, subopts);
  1623. pivotUIOptions = $.extend({}, opts, {
  1624. cols: subopts.cols,
  1625. rows: subopts.rows,
  1626. colOrder: subopts.colOrder,
  1627. rowOrder: subopts.rowOrder,
  1628. vals: vals,
  1629. exclusions: exclusions,
  1630. inclusions: inclusions,
  1631. inclusionsInfo: inclusions,
  1632. aggregatorName: aggregator.val(),
  1633. rendererName: renderer.val()
  1634. });
  1635. _this.data("pivotUIOptions", pivotUIOptions);
  1636. if (opts.autoSortUnusedAttrs) {
  1637. unusedAttrsContainer = _this.find("td.pvtUnused.pvtAxisContainer");
  1638. $(unusedAttrsContainer).children("li").sort(function(a, b) {
  1639. return naturalSort($(a).text(), $(b).text());
  1640. }).appendTo(unusedAttrsContainer);
  1641. }
  1642. pivotTable.css("opacity", 1);
  1643. if (opts.onRefresh != null) {
  1644. return opts.onRefresh(pivotUIOptions);
  1645. }
  1646. };
  1647. })(this);
  1648. refresh = (function(_this) {
  1649. return function() {
  1650. pivotTable.css("opacity", 0.5);
  1651. return setTimeout(refreshDelayed, 10);
  1652. };
  1653. })(this);
  1654. refresh();
  1655. this.find(".pvtAxisContainer").sortable({
  1656. update: function(e, ui) {
  1657. if (ui.sender == null) {
  1658. return refresh();
  1659. }
  1660. },
  1661. connectWith: this.find(".pvtAxisContainer"),
  1662. items: 'li',
  1663. placeholder: 'pvtPlaceholder'
  1664. });
  1665. } catch (error) {
  1666. e = error;
  1667. if (typeof console !== "undefined" && console !== null) {
  1668. console.error(e.stack);
  1669. }
  1670. this.html(opts.localeStrings.uiRenderError);
  1671. }
  1672. return this;
  1673. };
  1674. /*
  1675. Heatmap post-processing
  1676. */
  1677. $.fn.heatmap = function(scope, opts) {
  1678. var colorScaleGenerator, heatmapper, i, j, l, n, numCols, numRows, ref, ref1, ref2;
  1679. if (scope == null) {
  1680. scope = "heatmap";
  1681. }
  1682. numRows = this.data("numrows");
  1683. numCols = this.data("numcols");
  1684. colorScaleGenerator = opts != null ? (ref = opts.heatmap) != null ? ref.colorScaleGenerator : void 0 : void 0;
  1685. if (colorScaleGenerator == null) {
  1686. colorScaleGenerator = function(values) {
  1687. var max, min;
  1688. min = Math.min.apply(Math, values);
  1689. max = Math.max.apply(Math, values);
  1690. return function(x) {
  1691. var nonRed;
  1692. nonRed = 255 - Math.round(255 * (x - min) / (max - min));
  1693. return "rgb(255," + nonRed + "," + nonRed + ")";
  1694. };
  1695. };
  1696. }
  1697. heatmapper = (function(_this) {
  1698. return function(scope) {
  1699. var colorScale, forEachCell, values;
  1700. forEachCell = function(f) {
  1701. return _this.find(scope).each(function() {
  1702. var x;
  1703. x = $(this).data("value");
  1704. if ((x != null) && isFinite(x)) {
  1705. return f(x, $(this));
  1706. }
  1707. });
  1708. };
  1709. values = [];
  1710. forEachCell(function(x) {
  1711. return values.push(x);
  1712. });
  1713. colorScale = colorScaleGenerator(values);
  1714. return forEachCell(function(x, elem) {
  1715. return elem.css("background-color", colorScale(x));
  1716. });
  1717. };
  1718. })(this);
  1719. switch (scope) {
  1720. case "heatmap":
  1721. heatmapper(".pvtVal");
  1722. break;
  1723. case "rowheatmap":
  1724. for (i = l = 0, ref1 = numRows; 0 <= ref1 ? l < ref1 : l > ref1; i = 0 <= ref1 ? ++l : --l) {
  1725. heatmapper(".pvtVal.row" + i);
  1726. }
  1727. break;
  1728. case "colheatmap":
  1729. for (j = n = 0, ref2 = numCols; 0 <= ref2 ? n < ref2 : n > ref2; j = 0 <= ref2 ? ++n : --n) {
  1730. heatmapper(".pvtVal.col" + j);
  1731. }
  1732. }
  1733. heatmapper(".pvtTotal.rowTotal");
  1734. heatmapper(".pvtTotal.colTotal");
  1735. return this;
  1736. };
  1737. /*
  1738. Barchart post-processing
  1739. */
  1740. return $.fn.barchart = function(opts) {
  1741. var barcharter, i, l, numCols, numRows, ref;
  1742. numRows = this.data("numrows");
  1743. numCols = this.data("numcols");
  1744. barcharter = (function(_this) {
  1745. return function(scope) {
  1746. var forEachCell, max, min, range, scaler, values;
  1747. forEachCell = function(f) {
  1748. return _this.find(scope).each(function() {
  1749. var x;
  1750. x = $(this).data("value");
  1751. if ((x != null) && isFinite(x)) {
  1752. return f(x, $(this));
  1753. }
  1754. });
  1755. };
  1756. values = [];
  1757. forEachCell(function(x) {
  1758. return values.push(x);
  1759. });
  1760. max = Math.max.apply(Math, values);
  1761. if (max < 0) {
  1762. max = 0;
  1763. }
  1764. range = max;
  1765. min = Math.min.apply(Math, values);
  1766. if (min < 0) {
  1767. range = max - min;
  1768. }
  1769. scaler = function(x) {
  1770. return 100 * x / (1.4 * range);
  1771. };
  1772. return forEachCell(function(x, elem) {
  1773. var bBase, bgColor, text, wrapper;
  1774. text = elem.text();
  1775. wrapper = $("<div>").css({
  1776. "position": "relative",
  1777. "height": "55px"
  1778. });
  1779. bgColor = "gray";
  1780. bBase = 0;
  1781. if (min < 0) {
  1782. bBase = scaler(-min);
  1783. }
  1784. if (x < 0) {
  1785. bBase += scaler(x);
  1786. bgColor = "darkred";
  1787. x = -x;
  1788. }
  1789. wrapper.append($("<div>").css({
  1790. "position": "absolute",
  1791. "bottom": bBase + "%",
  1792. "left": 0,
  1793. "right": 0,
  1794. "height": scaler(x) + "%",
  1795. "background-color": bgColor
  1796. }));
  1797. wrapper.append($("<div>").text(text).css({
  1798. "position": "relative",
  1799. "padding-left": "5px",
  1800. "padding-right": "5px"
  1801. }));
  1802. return elem.css({
  1803. "padding": 0,
  1804. "padding-top": "5px",
  1805. "text-align": "center"
  1806. }).html(wrapper);
  1807. });
  1808. };
  1809. })(this);
  1810. for (i = l = 0, ref = numRows; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
  1811. barcharter(".pvtVal.row" + i);
  1812. }
  1813. barcharter(".pvtTotal.colTotal");
  1814. return this;
  1815. };
  1816. });
  1817. }).call(this);