Statistician.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("MWF.xScript.Macro", null, false);
  5. MWF.xDesktop.requireApp("query.Query", "lp.zh-cn", null, false);
  6. MWF.xApplication.query.Query.Statistician = MWF.QStatistician = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "resizeNode": true
  12. },
  13. initialize: function(app, container, json, options){
  14. this.setOptions(options);
  15. this.path = "/x_component_query_Query/$Statistician/";
  16. this.cssPath = "/x_component_query_Query/$Statistician/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.lp = MWF.xApplication.query.Query.LP;
  19. this.app = app;
  20. this.container = $(container);
  21. this.json = json;
  22. this.statJson = null;
  23. this.gridJson = null;
  24. this.load();
  25. },
  26. load: function(){
  27. this.loadLayout();
  28. this.loadStatData();
  29. },
  30. loadLayout: function(){
  31. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  32. //if (this.json.isChart) this.chartAreaNode = new Element("div", {"styles": this.css.statChartAreaNode}).inject(this.node);
  33. //if (this.json.isTable) this.tableAreaNode = new Element("div", {"styles": this.css.statTableAreaNode}).inject(this.node);
  34. },
  35. createLoadding: function(){
  36. this.node.empty();
  37. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.node);
  38. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  39. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  40. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  41. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  42. loadingTextNode.set("text", "loading...");
  43. },
  44. loadStatData: function(node){
  45. debugger;
  46. this.createLoadding();
  47. MWF.Actions.get("x_query_assemble_surface").loadStat(this.json.statName, this.json.application, null, function(json){
  48. if (this.loadingAreaNode){
  49. this.loadingAreaNode.destroy();
  50. this.loadingAreaNode = null;
  51. }
  52. if (json.data.calculate.isGroup){
  53. this.stat = new MWF.xApplication.query.Query.Statistician.GroupStat(this, json.data);
  54. }else{
  55. this.stat = new MWF.xApplication.query.Query.Statistician.Stat(this, json.data);
  56. }
  57. this.fireEvent("loaded");
  58. }.bind(this));
  59. }
  60. });
  61. MWF.xApplication.query.Query.Statistician.Stat = new Class({
  62. initialize: function(statistician, data){
  63. //this.explorer = explorer;
  64. this.statistician = statistician;
  65. this.json = this.statistician.json;
  66. this.data = data;
  67. this.css = this.statistician.css;
  68. this.lp = this.statistician.lp;
  69. this.node = this.statistician.node;
  70. this.load();
  71. },
  72. load: function(){
  73. if (this.json.isChart) this.chartAreaNode = new Element("div", {"styles": this.css.statChartAreaNode}).inject(this.node);
  74. if (this.json.isTable) this.tableAreaNode = new Element("div", {"styles": this.css.statTableAreaNode}).inject(this.node);
  75. this.loadData();
  76. if (this.json.isTable) this.createTable();
  77. if (this.json.isChart) this.createChart();
  78. },
  79. loadData: function(){
  80. var entries = {};
  81. this.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  82. },
  83. createChart: function(){
  84. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  85. this.loadChart();
  86. if (this.statistician.app){
  87. this.resizeChartFun = this.resizeChart.bind(this);
  88. this.statistician.app.addEvent("resizeCompleted", this.resizeChartFun);
  89. this.statistician.app.addEvent("postMaxSize", this.resizeChartFun);
  90. this.statistician.app.addEvent("postRestoreSize", this.resizeChartFun);
  91. }
  92. },
  93. resizeChart: function(){
  94. if (this.bar) this.bar.destroy();
  95. this.bar = null;
  96. if (this.chartNode) this.chartNode.empty();
  97. this.loadChart();
  98. },
  99. loadChart: function(){
  100. MWF.require("MWF.widget.chart.Bar", function(){
  101. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.data.calculateGrid, "displayName", {"delay": 0, "style": "monthly"});
  102. this.bar.addBar("value");
  103. //bar.addBar("value");
  104. this.bar.addEvents({
  105. "mouseover": function(rects, texts, d, i){
  106. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  107. var rect = rects.filter(function(data, idx){return (idx==i);});
  108. var color = rect.attr("fill");
  109. rect.node().store("color", color);
  110. rect.attr("fill", "brown");
  111. }.bind(this),
  112. "mouseout": function(rects, texts, d, i){
  113. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  114. var rect = rects.filter(function(data, idx){return (idx==i);});
  115. var color = rect.node().retrieve("color");
  116. rect.attr("fill", color);
  117. }.bind(this)
  118. });
  119. this.bar.load();
  120. }.bind(this));
  121. },
  122. createTable: function(){
  123. this.createTableHead();
  124. this.createTableData();
  125. },
  126. createTableHead: function(){
  127. this.table = new Element("table", {
  128. "styles": this.css.statTableNode,
  129. "width": "100%",
  130. "border": "0",
  131. "cellPadding": "0",
  132. "cellSpacing": "0"
  133. }).inject(this.node);
  134. this.headTr = new Element("tr").inject(this.table);
  135. this.data.calculate.calculateList.each(function(title){
  136. var th = new Element("th", {
  137. "styles": this.css.statHeadTh,
  138. "text": title.displayName
  139. }).inject(this.headTr);
  140. }.bind(this));
  141. },
  142. createTableData: function(){
  143. if (this.data.calculateGrid.length){
  144. var tr = new Element("tr").inject(this.table);
  145. this.data.calculateGrid.each(function(d){
  146. var td = new Element("td", {"styles": this.css.statContentTdNode}).inject(tr);
  147. td.set("text", d.value);
  148. }.bind(this));
  149. }
  150. },
  151. destroy: function(){
  152. if (this.bar) this.bar.destroy();
  153. if (this.statistician.app){
  154. if (this.resizeChartFun){
  155. this.resizeChartFun.app.removeEvent("resizeCompleted", this.resizeChartFun);
  156. this.resizeChartFun.app.removeEvent("postMaxSize", this.resizeChartFun);
  157. this.resizeChartFun.app.removeEvent("postRestoreSize", this.resizeChartFun);
  158. }
  159. }
  160. MWF.release(this);
  161. }
  162. });
  163. MWF.xApplication.query.Query.Statistician.GroupStat = new Class({
  164. Extends: MWF.xApplication.query.Query.Statistician.Stat,
  165. loadData: function(){
  166. var entries = {};
  167. var groupColumn = null;
  168. this.data.selectList.each(function(entry){
  169. entries[entry.column] = entry;
  170. if (entry.column === this.data.group.column){
  171. groupColumn = entry;
  172. }
  173. }.bind(this));
  174. this.data.calculateGrid.each(function(dd){
  175. if (groupColumn){
  176. dd.group = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": dd.group, "data": this.data}) : dd.group;
  177. }
  178. dd.list.each(function(c){
  179. c.value = (entries[c.column].code) ? MWF.Macro.exec(entries[c.column].code, {"value": c.value, "data": this.data}) : c.value
  180. }.bind(this));
  181. }.bind(this));
  182. },
  183. createChart: function(){
  184. if (this.json.isLegend) this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartAreaNode);
  185. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  186. this.loadChart();
  187. if (this.statistician.app){
  188. this.resizeChartFun = this.resizeChart.bind(this);
  189. this.statistician.app.addEvent("resizeCompleted", this.resizeChartFun);
  190. this.statistician.app.addEvent("postMaxSize", this.resizeChartFun);
  191. this.statistician.app.addEvent("postRestoreSize", this.resizeChartFun);
  192. }
  193. },
  194. resizeChart: function(){
  195. if (this.bar) this.bar.destroy();
  196. this.bar = null;
  197. if (this.json.isLegend) this.chartFlagNode.empty();
  198. this.chartNode.empty();
  199. this.loadChart();
  200. },
  201. loadChart: function(){
  202. if (!this.selectedData) this.selectedData = this.data.calculateGrid;
  203. if (!this.selectedData.length) this.selectedData = this.data.calculateGrid;
  204. MWF.require("MWF.widget.chart.Bar", function(){
  205. this.flag = [];
  206. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.selectedData, "group", {"delay": 0, "style": "monthly"});
  207. if (this.selectedData.length){
  208. this.selectedData[0].list.each(function(d, i){
  209. this.flag.push({"name":d.displayName, "color": this.bar.colors[i]});
  210. this.bar.addBar(function(v){return v.list[i].value});
  211. }.bind(this));
  212. }
  213. this.bar.addEvents({
  214. "mouseover": function(rects, texts, d, i){
  215. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  216. var rect = rects.filter(function(data, idx){return (idx==i);});
  217. var color = rect.attr("fill");
  218. rect.node().store("color", color);
  219. rect.attr("fill", "brown");
  220. }.bind(this),
  221. "mouseout": function(rects, texts, d, i){
  222. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  223. var rect = rects.filter(function(data, idx){return (idx==i);});
  224. var color = rect.node().retrieve("color");
  225. rect.attr("fill", color);
  226. }.bind(this)
  227. });
  228. this.bar.load();
  229. if (this.json.isLegend) this.loadFlags();
  230. }.bind(this));
  231. },
  232. loadFlags: function(){
  233. this.flag.each(function(f, i){
  234. this.loadFlag(f, i);
  235. }.bind(this));
  236. },
  237. loadFlag: function(f, i){
  238. var flagNode = new Element("div", {"styles": this.css.ststChartFlagNode}).inject(this.chartFlagNode);
  239. var flagColorNode = new Element("div", {"styles": this.css.ststChartFlagColorNode}).inject(flagNode);
  240. flagColorNode.setStyle("background-color", f.color);
  241. var flagNameNode = new Element("div", {"styles": this.css.ststChartFlagNameNode}).inject(flagNode);
  242. flagNameNode.set("text", f.name);
  243. flagNameNode.set("title", f.name);
  244. flagNode.store("idx", i);
  245. flagNode.store("barColor", f.color);
  246. var _self = this;
  247. flagNode.addEvents({
  248. "mouseover": function(){
  249. this.getFirst().setStyles(_self.css.ststChartFlagColorNode_over);
  250. var idx = this.retrieve("idx");
  251. _self.highlightBar(idx);
  252. },
  253. "mouseout": function(){
  254. this.getFirst().setStyles(_self.css.ststChartFlagColorNode);
  255. var idx = this.retrieve("idx");
  256. var barColor = this.retrieve("barColor");
  257. _self.unHighlightBar(idx, barColor);
  258. }
  259. });
  260. },
  261. createDefs: function(node, data){
  262. var svgNode = node.append(data.tag);
  263. Object.each(data.attrs, function(v,k){svgNode.attr(k,v);});
  264. if (data.subs) {
  265. data.subs.each(function(v){
  266. this.createDefs(svgNode, v);
  267. }.bind(this));
  268. }
  269. },
  270. createHighlightDefs: function(id){
  271. //this.defssvg = this.bar.createDefs;
  272. var node = this.bar.svg.append("defs");
  273. var data = this.bar.css["rect_over_defs"];
  274. this.createDefs(node, data);
  275. node.select(function(){ return this.getFirst(); }).attr("id", id);
  276. node.attr("id", "defs_"+id);
  277. },
  278. unHighlightBar: function(i, barColor){
  279. var id = "rect_over_defs"+i;
  280. var def = d3.select("#defs_"+id);
  281. def.remove();
  282. var rects = this.bar.rectCluster[i];
  283. rects.attr(this.bar.css["rect_over_defs"].urlAttr, null);
  284. var texts = this.bar.textCluster[i];
  285. texts.attr("display", "none");
  286. texts.attr("font-weight", "normal");
  287. },
  288. highlightBar: function(i){
  289. this.bar.rectCluster[i].remove();
  290. var rects = this.recreateBars(i);
  291. var id = "rect_over_defs"+i;
  292. this.createHighlightDefs(id);
  293. rects.attr(this.bar.css["rect_over_defs"].urlAttr, "url(#"+id+")");
  294. var texts = this.bar.textCluster[i];
  295. texts.attr("display", "block");
  296. texts.attr("font-weight", "bold");
  297. },
  298. recreateBars: function(i){
  299. var data = this.data.calculateGrid.map(function(d, idx) {
  300. return {"name": d["group"], "data": d.list[i].value};
  301. }.bind(this));
  302. this.bar.rectClass = Math.round(Math.random()*100);
  303. var barWidth = this.bar.xScale.bandwidth()/this.bar.barsData.length;
  304. var rects = this.bar.group.selectAll(".MWFBar_"+this.bar.rectClass+"_"+i)
  305. .data(data)
  306. .enter().append("rect")
  307. .attr("class", ".MWFBar_"+this.bar.rectClass+"_"+i)
  308. .attr("x", function(d) { return this.xScale(d.name)+(i*barWidth); }.bind(this.bar))
  309. .attr("width", barWidth)
  310. .attr("height", function(d) { return this.size.y - this.yScale(d.data); }.bind(this.bar))
  311. .attr("y", function(d) { return this.yScale(d.data); }.bind(this.bar))
  312. .attr("fill", this.bar.colors[i]);
  313. this.bar.rectCluster[i] = rects;
  314. this.bar.setEvents();
  315. return rects;
  316. },
  317. createTableHead: function(){
  318. this.selectedCols = [];
  319. this.selectedRows = [];
  320. this.table = new Element("table", {
  321. "styles": this.css.statTableNode,
  322. "width": "100%",
  323. "border": "0",
  324. "cellPadding": "0",
  325. "cellSpacing": "0"
  326. }).inject(this.node);
  327. _self = this;
  328. this.headTr = this.table.insertRow();
  329. this.selectAllTd = (this.headTr.insertCell()).setStyles(this.css.statAllSelectTd).set("title", this.lp.selecteAll);
  330. this.selectAllTd.addEvent("click", function(){
  331. _self.selectAll(this);
  332. });
  333. this.selectEntryTd = (this.headTr.insertCell()).setStyles(this.css.statAllColSelectTd).set("title", this.lp.selecteAllCol);
  334. this.selectEntryTd.addEvent("click", function(){
  335. _self.selectAllCol(this);
  336. });
  337. this.data.calculate.calculateList.each(function(title){
  338. selectTd = (this.headTr.insertCell()).setStyles(this.css.statColSelectTd);
  339. selectTd.addEvent("click", function(){
  340. _self.selectCol(this);
  341. });
  342. }.bind(this));
  343. this.titleTr = this.table.insertRow();
  344. this.selectGroupTd = (this.titleTr.insertCell()).setStyles(this.css.statAllRowSelectTd).set("title", this.lp.selecteAllRow);
  345. this.categoryTitleTd = new Element("th", {
  346. "styles": this.css.statHeadTh,
  347. "text": this.data.calculate.title || this.lp.category
  348. }).inject(this.titleTr);
  349. this.categoryTitleTd.setStyle("width", "160px");
  350. this.data.calculate.calculateList.each(function(title){
  351. var th = new Element("th", {
  352. "styles": this.css.statHeadTh,
  353. "text": title.displayName
  354. }).inject(this.titleTr);
  355. }.bind(this));
  356. },
  357. createTableData: function(){
  358. if (this.data.calculateGrid.length){
  359. var _self = this;
  360. var groupColumn = null;
  361. for (var c = 0; c<this.data.selectList.length; c++){
  362. if (this.data.selectList[c].column === this.data.group.column){
  363. groupColumn = this.data.selectList[c];
  364. break;
  365. }
  366. }
  367. this.data.calculateGrid.each(function(d){
  368. var tr = this.table.insertRow();
  369. var selectTd = tr.insertCell().setStyles(this.css.statRowSelectTd);
  370. selectTd.addEvent("click", function(){
  371. _self.selectRow(this);
  372. });
  373. var text = d.group;
  374. if (groupColumn){
  375. text = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": d.group, "data": this.data}) : d.group;
  376. }
  377. var categoryTh = new Element("th", {"styles": this.css.statHeadTh, "text": text}).inject(tr);
  378. d.list.each(function(l){
  379. var td = new Element("td", {"styles": this.css.statContentTdNode}).inject(tr);
  380. td.set("text", l.value);
  381. this.setDragEvent(td);
  382. }.bind(this));
  383. }.bind(this));
  384. }
  385. },
  386. setDragEvent: function(td){
  387. new Drag(td, {
  388. "onStart": function(dragged, e){
  389. this.cellDragStart(dragged, e);
  390. }.bind(this),
  391. "onDrag": function(dragged, e){
  392. this.cellDrag(dragged, e);
  393. }.bind(this),
  394. "onComplete": function(dragged, e){
  395. this.completeDrag(dragged, e);
  396. }.bind(this)
  397. });
  398. var _self = this;
  399. td.addEvent("click", function(){
  400. var cellIndex = td.cellIndex-2;
  401. var rowIndex = td.getParent("tr").rowIndex-2;
  402. if (_self.checkIsSelected(cellIndex, rowIndex)){
  403. }else{
  404. debugger;
  405. if (_self.selectedCols.length || _self.selectedRows.length){
  406. _self.selectAll();
  407. }
  408. }
  409. });
  410. },
  411. cellDragStart: function(td, e){
  412. //if (_self.selectedCols.length || _self.selectedRows.length){
  413. // _self.selectAll();
  414. //}
  415. var p = td.getPosition();
  416. var size = td.getSize();
  417. td.store("start", {"x": p.x, "y": p.y});
  418. td.store("start2", {"x": p.x+size.x, "y": p.y+size.y});
  419. },
  420. getSelectedCells: function(td, start, e){
  421. var ox = e.page.x-start.x;
  422. var oy = e.page.y-start.y;
  423. var tdSize = td.getSize();
  424. var cols = (ox/tdSize.x).toInt();
  425. var rows = (oy/tdSize.y).toInt();
  426. return {"cols": cols, "rows": rows};
  427. },
  428. cellDrag: function(td, e){
  429. this.selectedRows = [];
  430. this.selectedCols = [];
  431. this.selectedData = [];
  432. var start = td.retrieve("start");
  433. var start2 = td.retrieve("start2");
  434. var c1 = this.getSelectedCells(td, start, e);
  435. var c2 = this.getSelectedCells(td, start2, e);
  436. var cols = (Math.abs(c1.cols)>Math.abs(c2.cols)) ? c1.cols : c2.cols;
  437. var rows = (Math.abs(c1.rows)>Math.abs(c2.rows)) ? c1.rows : c2.rows;
  438. var cellIndex = td.cellIndex-2;
  439. var rowIndex = td.getParent("tr").rowIndex-2;
  440. if (!cellIndex || cellIndex<0) cellIndex = 0;
  441. if (!rowIndex || rowIndex<0) rowIndex = 0;
  442. var toCellIndex = cellIndex+cols;
  443. var toRowIndex = rowIndex+rows;
  444. if (toRowIndex>rowIndex){
  445. for (var i=rowIndex; i<=toRowIndex; i++) this.selectedRows.push(i);
  446. }else{
  447. for (var i=toRowIndex; i<=rowIndex; i++) this.selectedRows.push(i);
  448. }
  449. if (toCellIndex>cellIndex){
  450. for (var i=cellIndex; i<=toCellIndex; i++) this.selectedCols.push(i);
  451. }else{
  452. for (var i=toCellIndex; i<=cellIndex; i++) this.selectedCols.push(i);
  453. }
  454. this.checkSelectedCells();
  455. },
  456. completeDrag: function(td, e){
  457. var trs = this.table.getElements("tr");
  458. var tds = trs[0].getElements("td");
  459. this.selectedCols.each(function(i){
  460. tds[i+2].setStyles(this.css.statTableSelectedTd);
  461. }.bind(this));
  462. this.selectedRows.each(function(i){
  463. trs[i+2].getElement("td").setStyles(this.css.statTableSelectedTd);
  464. }.bind(this));
  465. this.reloadChart();
  466. },
  467. selectCol: function(td){
  468. var i = td.cellIndex;
  469. var dataIndex = i-2;
  470. if (this.selectedCols.indexOf(dataIndex)!=-1){
  471. td.setStyles(this.css.statTableSelectTd);
  472. this.selectedCols.erase(dataIndex);
  473. }else{
  474. td.setStyles(this.css.statTableSelectedTd);
  475. this.selectedCols.push(dataIndex);
  476. }
  477. this.checkSelectedCells();
  478. this.reloadChart();
  479. },
  480. selectRow: function(td){
  481. var tr = td.getParent("tr");
  482. var i = tr.rowIndex;
  483. var dataIndex = i-2;
  484. if (this.selectedRows.indexOf(dataIndex)!=-1){
  485. td.setStyles(this.css.statTableSelectTd);
  486. this.selectedRows.erase(dataIndex);
  487. }else{
  488. td.setStyles(this.css.statTableSelectedTd);
  489. this.selectedRows.push(dataIndex);
  490. }
  491. this.checkSelectedCells();
  492. this.reloadChart();
  493. },
  494. selectAllCol: function(){
  495. if (this.selectedCols.length){
  496. this.selectedCols = [];
  497. var trs = this.table.getElements("tr");
  498. var tds = trs[0].getElements("td");
  499. for (var i=2; i<tds.length; i++){
  500. tds[i].setStyles(this.css.statTableSelectTd);
  501. }
  502. //for (var n=2; n<trs.length; n++){
  503. // trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  504. //}
  505. }else{
  506. var seltrs = this.table.getElements("tr");
  507. var seltds = seltrs[0].getElements("td");
  508. for (var n=2; n<seltds.length; n++){
  509. this.selectedCols.push(n-2);
  510. seltds[n].setStyles(this.css.statTableSelectedTd);
  511. }
  512. }
  513. this.checkSelectedCells();
  514. this.reloadChart();
  515. },
  516. selectAll: function(){
  517. if (this.selectedRows.length || this.selectedCols.length){
  518. this.selectedRows = [];
  519. this.selectedCols = [];
  520. var trs = this.table.getElements("tr");
  521. var tds = trs[0].getElements("td");
  522. for (var i=2; i<tds.length; i++){
  523. tds[i].setStyles(this.css.statTableSelectTd);
  524. }
  525. for (var n=2; n<trs.length; n++){
  526. trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  527. }
  528. }else{
  529. var seltrs = this.table.getElements("tr");
  530. var seltds = seltrs[0].getElements("td");
  531. for (var seli=2; seli<seltds.length; seli++){
  532. this.selectedCols.push(seli-2);
  533. seltds[seli].setStyles(this.css.statTableSelectedTd);
  534. }
  535. for (var seln=2; seln<seltrs.length; seln++){
  536. this.selectedRows.push(seln-2);
  537. seltrs[seln].getElement("td").setStyles(this.css.statTableSelectedTd);
  538. }
  539. }
  540. this.checkSelectedCells();
  541. this.reloadChart();
  542. },
  543. checkIsSelected: function(ci, ri){
  544. if (!this.selectedCols.length && !this.selectedRows.length) return false;
  545. var colSelect = (!this.selectedCols.length) || this.selectedCols.indexOf(ci)!=-1;
  546. var rowSelect = (!this.selectedRows.length) || this.selectedRows.indexOf(ri)!=-1;
  547. return (colSelect && rowSelect);
  548. },
  549. checkSelectedCells: function(){
  550. this.selectedData = [];
  551. var rows = this.table.getElements("tr");
  552. for (var rowIdx = 2; rowIdx<rows.length; rowIdx++){
  553. var o = {
  554. "group": this.data.calculateGrid[rowIdx-2].group,
  555. "list": []
  556. };
  557. var cols = rows[rowIdx].getElements("td");
  558. for (var colIdx = 1; colIdx<cols.length; colIdx++){
  559. if (this.checkIsSelected(colIdx-1, rowIdx-2)){
  560. cols[colIdx].setStyles(this.css.statContentTdNode_selected);
  561. o.list.push({
  562. "column": this.data.calculateGrid[rowIdx-2].list[colIdx-1].column,
  563. "displayName": this.data.calculateGrid[rowIdx-2].list[colIdx-1].displayName,
  564. "value": this.data.calculateGrid[rowIdx-2].list[colIdx-1].value
  565. });
  566. }else{
  567. cols[colIdx].setStyles(this.css.statContentTdNode);
  568. }
  569. }
  570. if (o.list.length) this.selectedData.push(o);
  571. }
  572. },
  573. reloadChart: function(){
  574. if (this.json.isChart){
  575. if (this.bar) this.bar.destroy();
  576. this.bar = null;
  577. if (this.chartFlagNode)this.chartFlagNode.empty();
  578. if (this.chartNode)this.chartNode.empty();
  579. this.loadChart();
  580. }
  581. }
  582. });