Statistician.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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."+o2.language, 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.fireEvent("loadLayout");
  29. this.loadStatData();
  30. },
  31. reload: function(json){
  32. if( this.stat )this.stat.destroy();
  33. this.container.empty();
  34. if(json)this.json = json;
  35. this.loadLayout();
  36. this.fireEvent("loadLayout");
  37. this.loadStatData();
  38. },
  39. loadLayout: function(){
  40. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  41. //if (this.json.isChart) this.chartAreaNode = new Element("div", {"styles": this.css.statChartAreaNode}).inject(this.node);
  42. //if (this.json.isTable) this.tableAreaNode = new Element("div", {"styles": this.css.statTableAreaNode}).inject(this.node);
  43. },
  44. createLoadding: function(){
  45. this.node.empty();
  46. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.node);
  47. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  48. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  49. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  50. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  51. loadingTextNode.set("text", "loading...");
  52. },
  53. loadStatData: function(node){
  54. this.createLoadding();
  55. MWF.Actions.get("x_query_assemble_surface").loadStat(this.json.statName, this.json.application, null, function(json){
  56. if (this.loadingAreaNode){
  57. this.loadingAreaNode.destroy();
  58. this.loadingAreaNode = null;
  59. }
  60. if (json.data.calculate.isGroup){
  61. this.stat = new MWF.xApplication.query.Query.Statistician.GroupStat(this, json.data);
  62. }else{
  63. this.stat = new MWF.xApplication.query.Query.Statistician.Stat(this, json.data);
  64. }
  65. this.fireEvent("loaded");
  66. }.bind(this));
  67. },
  68. setContentHeight: function(){
  69. if(this.resizeTimeout){
  70. window.clearTimeout(this.resizeTimeout);
  71. }
  72. this.resizeTimeout = window.setTimeout(function () {
  73. if(this.stat)this.stat.resizeChartFun();
  74. this._setContentHeight();
  75. this.resizeTimeout = null;
  76. }.bind(this), 200)
  77. },
  78. _setContentHeight: function(){
  79. if( !this.overfloatFlag ){
  80. this.node.setStyle("overflow-y", "auto");
  81. this.overfloatFlag = true;
  82. }
  83. var h = this.container.getSize().y;
  84. var paddingTop = (this.node.getStyle("padding-top") || "0").toInt();
  85. var paddingBottom = (this.node.getStyle("padding-bottom") || "0").toInt();
  86. h = h - paddingTop - paddingBottom;
  87. this.node.setStyle("height", h+"px");
  88. }
  89. });
  90. MWF.xApplication.query.Query.Statistician.Stat = new Class({
  91. initialize: function(statistician, data){
  92. //this.explorer = explorer;
  93. this.statistician = statistician;
  94. this.json = this.statistician.json;
  95. this.data = data;
  96. this.statGridData = Array.clone(this.data.calculateGrid);
  97. this.css = this.statistician.css;
  98. this.lp = this.statistician.lp;
  99. this.node = this.statistician.node;
  100. this.load();
  101. },
  102. load: function(){
  103. this.charts = this.data.calculate.chart;
  104. if( !this.charts ){
  105. this.charts = ["bar", "pie", "line"];
  106. }else if( typeOf( this.charts ) === "string" ){
  107. this.charts = [this.charts];
  108. }
  109. if (this.json.isChart) this.chartAreaNode = new Element("div", {"styles": this.css.statChartAreaNode}).inject(this.node);
  110. if( this.json.chartNodeStyles )this.chartAreaNode.setStyles(this.json.chartNodeStyles);
  111. if (this.json.isTable) this.tableAreaNode = new Element("div#tableAreaNode", {"styles": this.css.statTableAreaNode}).inject(this.node);
  112. if( this.json.tableNodeStyles )this.tableAreaNode.setStyles(this.json.tableNodeStyles);
  113. this.loadData();
  114. if (this.json.isTable) this.createTable();
  115. if (this.json.isChart) this.createChart();
  116. },
  117. loadData: function(){
  118. var entries = {};
  119. this.data.calculate.calculateList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  120. },
  121. createChart: function(){
  122. this.chartToolbarNode = new Element("div", {"styles": this.css.statChartToolbarNode}).inject(this.chartAreaNode);
  123. if( this.charts.length > 0 ){
  124. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  125. }else{
  126. this.chartAreaNode.setStyles( this.css.statChartAreaNode_noChart )
  127. }
  128. if( this.charts.length > 0 || this.data.calculate.isGroup ){
  129. this.loadChartToolbar();
  130. }else{
  131. this.chartAreaNode.hide();
  132. }
  133. //this.loadChart();
  134. if (this.statistician.app){
  135. this.resizeChartFun = this.reloadChart.bind(this);
  136. this.statistician.app.addEvent("resizeCompleted", this.resizeChartFun);
  137. this.statistician.app.addEvent("postMaxSize", this.resizeChartFun);
  138. this.statistician.app.addEvent("postRestoreSize", this.resizeChartFun);
  139. }
  140. },
  141. loadChartToolbar: function(){
  142. MWF.require("MWF.widget.Toolbar", function(){
  143. this.toolbar = new MWF.widget.Toolbar(this.chartToolbarNode, {"style": "simple"}, this);
  144. var charts = this.charts;
  145. if (charts.indexOf("bar")!==-1){
  146. var actionNode = new Element("div", {
  147. "MWFnodeid": "bar",
  148. "MWFnodetype": "MWFToolBarOnOffButton",
  149. "MWFButtonImage": this.statistician.path+""+this.statistician.options.style+"/icon/barChart.png",
  150. "title": this.lp.chart.bar,
  151. "MWFButtonAction": "changeChartBar",
  152. "MWFButtonText": this.lp.chart.bar
  153. }).inject(this.chartToolbarNode);
  154. }
  155. if (charts.indexOf("pie")!==-1){
  156. var actionNode = new Element("div", {
  157. "MWFnodeid": "pie",
  158. "MWFnodetype": "MWFToolBarOnOffButton",
  159. "MWFButtonImage": this.statistician.path+""+this.statistician.options.style+"/icon/pieChart.png",
  160. "title": this.lp.chart.pie,
  161. "MWFButtonAction": "changeChartPie",
  162. "MWFButtonText": this.lp.chart.pie
  163. }).inject(this.chartToolbarNode);
  164. }
  165. if (charts.indexOf("line")!==-1){
  166. var actionNode = new Element("div", {
  167. "MWFnodeid": "line",
  168. "MWFnodetype": "MWFToolBarOnOffButton",
  169. "MWFButtonImage": this.statistician.path+""+this.statistician.options.style+"/icon/lineChart.png",
  170. "title": this.lp.chart.line,
  171. "MWFButtonAction": "changeChartLine",
  172. "MWFButtonText": this.lp.chart.line
  173. }).inject(this.chartToolbarNode);
  174. }
  175. if (this.data.calculate.isGroup && this.json.isRowToColumn !== false ){
  176. var actionNode = new Element("div", {
  177. "MWFnodeid": "rowToColumn",
  178. "MWFnodetype": "MWFToolBarButton",
  179. "MWFButtonImage": this.statistician.path+""+this.statistician.options.style+"/icon/rowToColumn.png",
  180. "title": this.lp.chart.rowToColumn,
  181. "MWFButtonAction": "loadRowToColumn",
  182. "MWFButtonText": this.lp.chart.rowToColumn
  183. }).inject(this.chartToolbarNode);
  184. }else if( charts.length === 0 ){
  185. this.chartToolbarNode.hide();
  186. }
  187. this.toolbar.load();
  188. var defaultChart = "";
  189. if( charts.indexOf( "bar" ) !== -1 ){
  190. defaultChart = "bar"
  191. }else{
  192. defaultChart = charts[0];
  193. }
  194. if( defaultChart === "bar" ){
  195. this.changeChartBar("on", this.toolbar.items[ defaultChart ]);
  196. }else if( defaultChart === "pie" ){
  197. this.changeChartPie("on", this.toolbar.items[ defaultChart ]);
  198. }else if( defaultChart === "line" ){
  199. this.changeChartLine("on", this.toolbar.items[ defaultChart ]);
  200. }
  201. //this.reloadChart();
  202. }.bind(this));
  203. },
  204. changeChartBar: function(status, btn){
  205. if(this.toolbar.items["pie"])this.toolbar.items["pie"].off();
  206. if(this.toolbar.items["line"])this.toolbar.items["line"].off();
  207. btn.on();
  208. this.currentChart = "bar";
  209. this.reloadChart();
  210. },
  211. changeChartPie: function(status, btn){
  212. if(this.toolbar.items["bar"])this.toolbar.items["bar"].off();
  213. if(this.toolbar.items["line"])this.toolbar.items["line"].off();
  214. btn.on();
  215. this.currentChart = "pie";
  216. this.reloadChart();
  217. },
  218. changeChartLine: function(status, btn){
  219. if(this.toolbar.items["pie"])this.toolbar.items["pie"].off();
  220. if(this.toolbar.items["bar"])this.toolbar.items["bar"].off();
  221. btn.on();
  222. this.currentChart = "line";
  223. this.reloadChart();
  224. },
  225. toFloat: function(value){
  226. if (value.substr(0,1)==="¥") value = value.substr(1, value.length);
  227. value = value.replace(/,/g, "");
  228. value = value.replace(/\s/g, "");
  229. return value.toFloat()
  230. },
  231. loadChartBar: function(){
  232. MWF.require("MWF.widget.chart.Bar", function(){
  233. var maxLength = 0, marginLeft = 40;
  234. if (this.statGridData.length){
  235. this.statGridData.each(function(d){
  236. maxLength = Math.max( (d.value || "" ).length, maxLength);
  237. });
  238. if( maxLength > 6 ){
  239. marginLeft = marginLeft + (maxLength - 6) * 7;
  240. }
  241. }
  242. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.statGridData, "displayName", {"delay": 0, "style": "monthly", "marginLeft": marginLeft});
  243. //this.bar.addBar("value");
  244. this.bar.addBar(function(d){
  245. var value = d.value;
  246. if (value.substr(0,1)==="¥") value = value.substr(1, value.length);
  247. value = value.replace(/,/g, "");
  248. value = value.replace(/\s/g, "");
  249. return value.toFloat()
  250. }, function(d){
  251. return d.value;
  252. });
  253. //bar.addBar("value");
  254. this.bar.addEvents({
  255. "mouseover": function(rects, texts, d, i){
  256. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  257. var rect = rects.filter(function(data, idx){return (idx==i);});
  258. var color = rect.attr("fill");
  259. rect.node().store("color", color);
  260. rect.attr("fill", "brown");
  261. }.bind(this),
  262. "mouseout": function(rects, texts, d, i){
  263. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  264. var rect = rects.filter(function(data, idx){return (idx==i);});
  265. var color = rect.node().retrieve("color");
  266. rect.attr("fill", color);
  267. }.bind(this)
  268. });
  269. this.bar.load();
  270. this.statistician.fireEvent("loadChart");
  271. }.bind(this));
  272. },
  273. loadChartPie: function(){
  274. MWF.require("MWF.widget.chart.Pie", function(){
  275. var data = [];
  276. var total = 0;
  277. // this.data.calculateGrid.each(function(d){
  278. // total += this.toFloat(d.value);
  279. // }.bind(this));
  280. this.data.calculateGrid.each(function(d){
  281. var v = this.toFloat(d.value);
  282. // var percent = ((v/total)*10000).toInt()/100;
  283. // percent = ""+ percent +"%";
  284. data.push({"name": d.displayName, "value": v});
  285. }.bind(this));
  286. this.bar = new MWF.widget.chart.Pie(this.chartNode, data, {"textType": "percent"});
  287. this.bar.load();
  288. this.statistician.fireEvent("loadChart");
  289. }.bind(this));
  290. },
  291. loadChartLine: function(){
  292. MWF.require("MWF.widget.chart.Line", function(){
  293. var maxLength = 0, marginLeft = 40;
  294. if (this.statGridData.length){
  295. this.statGridData.each(function(d){
  296. maxLength = Math.max( (d.value || "" ).length, maxLength);
  297. });
  298. if( maxLength > 6 ){
  299. marginLeft = marginLeft + (maxLength - 6) * 7;
  300. }
  301. }
  302. this.bar = new MWF.widget.chart.Line(this.chartNode, this.statGridData, "displayName", {"delay": 0, "style": "monthly", "marginLeft": marginLeft});
  303. //this.bar.addBar("value");
  304. this.bar.addBar(function(d){
  305. var value = d.value;
  306. if (value.substr(0,1)==="¥") value = value.substr(1, value.length);
  307. value = value.replace(/,/g, "");
  308. value = value.replace(/\s/g, "");
  309. return value.toFloat()
  310. }, function(d){
  311. return d.value;
  312. });
  313. this.bar.load();
  314. this.statistician.fireEvent("loadChart");
  315. }.bind(this));
  316. },
  317. resizeChart: function(){
  318. if (this.bar) this.bar.destroy();
  319. this.bar = null;
  320. if (this.chartNode) this.chartNode.empty();
  321. this.loadChartBar();
  322. },
  323. // loadChart: function(){
  324. //
  325. // },
  326. createTable: function(){
  327. this.createTableHead();
  328. this.createTableData();
  329. },
  330. createTableHead: function(){
  331. this.table = new Element("table", {
  332. "styles": this.css.statTableNode,
  333. "width": "100%",
  334. "border": "0",
  335. "cellPadding": "0",
  336. "cellSpacing": "0"
  337. }).inject(this.tableAreaNode);
  338. this.headTr = new Element("tr").inject(this.table);
  339. this.data.calculate.calculateList.each(function(title){
  340. var th = new Element("th", {
  341. "styles": this.css.statHeadTh,
  342. "text": title.displayName
  343. }).inject(this.headTr);
  344. }.bind(this));
  345. },
  346. createTableData: function(){
  347. if (this.statGridData.length){
  348. var tr = new Element("tr").inject(this.table);
  349. this.statGridData.each(function(d){
  350. var td = new Element("td", {"styles": this.css.statContentTdNode}).inject(tr);
  351. td.set("text", d.value);
  352. }.bind(this));
  353. }
  354. },
  355. destroy: function(){
  356. if (this.bar) this.bar.destroy();
  357. if (this.statistician.app){
  358. if (this.resizeChartFun){
  359. this.statistician.app.removeEvent("resizeCompleted", this.resizeChartFun);
  360. this.statistician.app.removeEvent("postMaxSize", this.resizeChartFun);
  361. this.statistician.app.removeEvent("postRestoreSize", this.resizeChartFun);
  362. }
  363. }
  364. MWF.release(this);
  365. }
  366. });
  367. MWF.xApplication.query.Query.Statistician.GroupStat = new Class({
  368. Extends: MWF.xApplication.query.Query.Statistician.Stat,
  369. loadData: function(){
  370. var entries = {};
  371. var groupColumn = null;
  372. this.data.calculate.calculateList.each(function(entry){
  373. entries[entry.id] = entry;
  374. // if (entry.column === this.data.group.column){
  375. // groupColumn = entry;
  376. // }
  377. }.bind(this));
  378. this.statGridData.each(function(dd){
  379. // if (groupColumn){
  380. // dd.group = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": dd.group, "data": this.data}) : dd.group;
  381. // }
  382. dd.list.each(function(c){
  383. c.value = (entries[c.column].code) ? MWF.Macro.exec(entries[c.column].code, {"value": c.value, "data": this.data}) : c.value
  384. }.bind(this));
  385. }.bind(this));
  386. },
  387. createChart: function(){
  388. this.chartToolbarNode = new Element("div", {"styles": this.css.statChartToolbarNode}).inject(this.chartAreaNode);
  389. if( this.charts.length > 0 ){
  390. if (this.json.isLegend) this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartAreaNode);
  391. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  392. }else{
  393. this.chartAreaNode.setStyles( this.css.statChartAreaNode_noChart )
  394. }
  395. this.loadChartToolbar();
  396. //this.loadChartBar();
  397. if (this.statistician.app){
  398. this.resizeChartFun = this.reloadChart.bind(this);
  399. this.statistician.app.addEvent("resizeCompleted", this.resizeChartFun);
  400. this.statistician.app.addEvent("postMaxSize", this.resizeChartFun);
  401. this.statistician.app.addEvent("postRestoreSize", this.resizeChartFun);
  402. }
  403. },
  404. resizeChart: function(){
  405. if (this.bar) this.bar.destroy();
  406. this.bar = null;
  407. if (this.json.isLegend) this.chartFlagNode.empty();
  408. this.chartNode.empty();
  409. this.loadChartBar();
  410. },
  411. toFloat: function(value){
  412. if(o2.typeOf(value) === "number")return value.toFloat();
  413. if (value.substr(0,1)==="¥") value = value.substr(1, value.length);
  414. value = value.replace(/,/g, "");
  415. value = value.replace(/\s/g, "");
  416. return value.toFloat()
  417. },
  418. loadChartBar: function(){
  419. if (this.json.isLegend) if (!this.chartFlagNode) this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartNode, "before");
  420. if (!this.selectedData) this.selectedData = this.statGridData;
  421. if (!this.selectedData.length) this.selectedData = this.statGridData;
  422. MWF.require("MWF.widget.chart.Bar", function(){
  423. //this.selectedData.each()
  424. var maxLength = 0, marginLeft = 40;
  425. if (this.selectedData.length){
  426. this.selectedData.each(function(sd){
  427. (sd.list || []).each(function(d, i){
  428. maxLength = Math.max( (d.value || "" ).length, maxLength);
  429. }.bind(this));
  430. })
  431. if( maxLength > 6 ){
  432. marginLeft = marginLeft + (maxLength - 6) * 7;
  433. }
  434. }
  435. this.flag = [];
  436. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.selectedData, "group", {"delay": 0, "style": "monthly", "marginLeft": marginLeft});
  437. if (this.selectedData.length){
  438. this.selectedData[0].list.each(function(d, i){
  439. this.flag.push({"name":d.displayName, "color": this.bar.colors[i]});
  440. this.bar.addBar(function(v){
  441. return this.toFloat(v.list[i].value);
  442. }.bind(this), function(v){
  443. return v.list[i].value;
  444. });
  445. }.bind(this));
  446. }
  447. this.bar.addEvents({
  448. "mouseover": function(rects, texts, d, i){
  449. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  450. var rect = rects.filter(function(data, idx){return (idx==i);});
  451. var color = rect.attr("fill");
  452. rect.node().store("color", color);
  453. rect.attr("fill", "brown");
  454. }.bind(this),
  455. "mouseout": function(rects, texts, d, i){
  456. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  457. var rect = rects.filter(function(data, idx){return (idx==i);});
  458. var color = rect.node().retrieve("color");
  459. rect.attr("fill", color);
  460. }.bind(this)
  461. });
  462. this.bar.load();
  463. if (this.json.isLegend) this.loadFlags();
  464. this.statistician.fireEvent("loadChart");
  465. }.bind(this));
  466. },
  467. rowToColumn: function(data){
  468. var o = [];
  469. var idxs = {};
  470. data.each(function(d){
  471. var group = d.group;
  472. var column = d.column;
  473. d.list.each(function(l){
  474. if (l.column){
  475. var idx = (l.column) ? idxs[l.column] : idxs[l.displayName];
  476. if (!idx && idx!==0){
  477. o.push({ "column": l.column, "group": l.displayName, "list": [] });
  478. idx = o.length-1;
  479. idxs[l.column] = idx;
  480. }
  481. o[idx].list.push({
  482. "displayName": group,
  483. "name": group,
  484. "value": l.value
  485. });
  486. }else{
  487. var idx = (l.column) ? idxs[l.column] : idxs[l.displayName];
  488. if (!idx && idx!==0){
  489. o.push({ "group": l.displayName, "list": [] });
  490. idx = o.length-1;
  491. idxs[l.displayName] = idx;
  492. }
  493. o[idx].list.push({
  494. "column": column,
  495. "displayName": group,
  496. "name": group,
  497. "value": l.value
  498. });
  499. }
  500. }.bind(this));
  501. }.bind(this));
  502. return o;
  503. },
  504. loadChartPie: function(){
  505. if (!this.selectedData) this.selectedData = this.statGridData;
  506. if (!this.selectedData.length) this.selectedData = this.statGridData;
  507. var pieData = this.rowToColumn(this.selectedData);
  508. MWF.require("MWF.widget.chart.Pie", function(){
  509. var count = pieData.length;
  510. var size = this.chartNode.getSize();
  511. var w = size.x/count;
  512. pieData.each(function(d){
  513. var pieAreaNode = new Element("div", {
  514. "styles": {"overflow": "hidden", "height": ""+size.y+"px", "float": "left", "width": ""+w+"px"}
  515. }).inject(this.chartNode);
  516. var pieTitleNode = new Element("div", {
  517. "styles": {"text-align": "center", "line-height":"30px", "font-size":"16px", "font-weight":"bold", "overflow": "hidden", "height": "30px"},
  518. "text": d.group
  519. }).inject(pieAreaNode);
  520. var h = size.y-30;
  521. var pieNode = new Element("div", {
  522. "styles": {"overflow": "hidden", "height": ""+h+"px"}
  523. }).inject(pieAreaNode);
  524. var data = [];
  525. d.list.each(function(d){
  526. var v = this.toFloat(d.value);
  527. data.push({"name": d.displayName, "value": v, "text": d.value});
  528. }.bind(this));
  529. var pie = new MWF.widget.chart.Pie(pieNode, data, {"textType": "percent"});
  530. pie.load();
  531. }.bind(this));
  532. this.statistician.fireEvent("loadChart");
  533. }.bind(this));
  534. },
  535. loadChartLine: function(){
  536. if (this.json.isLegend) if (!this.chartFlagNode) this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartNode, "before");
  537. if (!this.selectedData) this.selectedData = this.statGridData;
  538. if (!this.selectedData.length) this.selectedData = this.statGridData;
  539. MWF.require("MWF.widget.chart.Line", function(){
  540. //this.selectedData.each()
  541. var maxLength = 0, marginLeft = 40;
  542. if (this.selectedData.length){
  543. this.selectedData.each(function(sd){
  544. (sd.list || []).each(function(d, i){
  545. maxLength = Math.max( (d.value || "" ).length, maxLength);
  546. }.bind(this));
  547. })
  548. if( maxLength > 6 ){
  549. marginLeft = marginLeft + (maxLength - 6) * 7;
  550. }
  551. }
  552. this.flag = [];
  553. this.bar = new MWF.widget.chart.Line(this.chartNode, this.selectedData, "group", {"delay": 0, "style": "monthly", "marginLeft": marginLeft});
  554. if (this.selectedData.length){
  555. this.selectedData[0].list.each(function(d, i){
  556. this.flag.push({"name":d.displayName, "color": this.bar.colors[i]});
  557. this.bar.addBar(function(v){
  558. return this.toFloat(v.list[i].value);
  559. }.bind(this), function(v){
  560. return v.list[i].value;
  561. });
  562. }.bind(this));
  563. }
  564. this.bar.addEvents({
  565. "mouseover": function(rects, texts, d, i){
  566. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  567. var rect = rects.filter(function(data, idx){return (idx==i);});
  568. var color = rect.attr("fill");
  569. rect.node().store("color", color);
  570. rect.attr("fill", "brown");
  571. }.bind(this),
  572. "mouseout": function(rects, texts, d, i){
  573. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  574. var rect = rects.filter(function(data, idx){return (idx==i);});
  575. var color = rect.node().retrieve("color");
  576. rect.attr("fill", color);
  577. }.bind(this)
  578. });
  579. this.bar.load();
  580. if (this.json.isLegend) this.loadFlags();
  581. this.statistician.fireEvent("loadChart");
  582. }.bind(this));
  583. },
  584. loadRowToColumn: function(){
  585. this.isRowToColumn = !this.isRowToColumn;
  586. if ((this.selectedRows && this.selectedRows.length) || (this.selectedCols && this.selectedCols.length)) this.selectAll();
  587. this.statGridData = this.rowToColumn(this.statGridData);
  588. this.selectedData = [];
  589. this.reloadChart();
  590. this.reloadTable();
  591. },
  592. loadFlags: function(){
  593. this.flag.each(function(f, i){
  594. this.loadFlag(f, i);
  595. }.bind(this));
  596. },
  597. loadFlag: function(f, i){
  598. var flagNode = new Element("div", {"styles": this.css.ststChartFlagNode}).inject(this.chartFlagNode);
  599. var flagColorNode = new Element("div", {"styles": this.css.ststChartFlagColorNode}).inject(flagNode);
  600. flagColorNode.setStyle("background-color", f.color);
  601. var flagNameNode = new Element("div", {"styles": this.css.ststChartFlagNameNode}).inject(flagNode);
  602. flagNameNode.set("text", f.name);
  603. flagNameNode.set("title", f.name);
  604. flagNode.store("idx", i);
  605. flagNode.store("barColor", f.color);
  606. var _self = this;
  607. flagNode.addEvents({
  608. "mouseover": function(){
  609. this.getFirst().setStyles(_self.css.ststChartFlagColorNode_over);
  610. var idx = this.retrieve("idx");
  611. switch (_self.currentChart){
  612. case "bar":
  613. _self.highlightBar(idx);
  614. break;
  615. case "line":
  616. _self.highlightLine(idx);
  617. break;
  618. }
  619. },
  620. "mouseout": function(){
  621. this.getFirst().setStyles(_self.css.ststChartFlagColorNode);
  622. var idx = this.retrieve("idx");
  623. var barColor = this.retrieve("barColor");
  624. switch (_self.currentChart){
  625. case "bar":
  626. _self.unHighlightBar(idx, barColor);
  627. break;
  628. case "line":
  629. _self.unHighlightLine(idx, barColor);
  630. break;
  631. }
  632. }
  633. });
  634. },
  635. createDefs: function(node, data){
  636. var svgNode = node.append(data.tag);
  637. Object.each(data.attrs, function(v,k){svgNode.attr(k,v);});
  638. if (data.subs) {
  639. data.subs.each(function(v){
  640. this.createDefs(svgNode, v);
  641. }.bind(this));
  642. }
  643. },
  644. createHighlightDefs: function(id){
  645. //this.defssvg = this.bar.createDefs;
  646. var node = this.bar.svg.append("defs");
  647. var data = this.bar.css["rect_over_defs"];
  648. this.createDefs(node, data);
  649. node.select(function(){ return this.getFirst(); }).attr("id", id);
  650. node.attr("id", "defs_"+id);
  651. },
  652. unHighlightBar: function(i, barColor){
  653. var id = "rect_over_defs"+i;
  654. var def = d3.select("#defs_"+id);
  655. def.remove();
  656. var rects = this.bar.rectCluster[i];
  657. rects.attr(this.bar.css["rect_over_defs"].urlAttr, null);
  658. var texts = this.bar.textCluster[i];
  659. texts.attr("display", "none");
  660. texts.attr("font-weight", "normal");
  661. },
  662. unHighlightLine: function(i, barColor){
  663. var line = this.bar.lineCluster[i];
  664. var points = this.bar.pointCluster[i];
  665. var texts = this.bar.textCluster[i];
  666. line.attr("stroke-width", "1");
  667. points.attr("r", "5").attr("stroke-width", "1");
  668. texts.attr("display", "none");
  669. texts.attr("font-weight", "normal");
  670. },
  671. highlightBar: function(i){
  672. this.bar.rectCluster[i].remove();
  673. var rects = this.recreateBars(i);
  674. var id = "rect_over_defs"+i;
  675. this.createHighlightDefs(id);
  676. rects.attr(this.bar.css["rect_over_defs"].urlAttr, "url(#"+id+")");
  677. var texts = this.bar.textCluster[i];
  678. texts.attr("display", "block");
  679. texts.attr("font-weight", "bold");
  680. },
  681. highlightLine: function(i){
  682. var line = this.bar.lineCluster[i];
  683. var points = this.bar.pointCluster[i];
  684. var texts = this.bar.textCluster[i];
  685. // debugger;
  686. // this.bar.lineGroup.selectAll("path").sort(function(a,b, i1, i2){
  687. // debugger;
  688. // });
  689. var p = this.bar.lineGroup.select(":last-child");
  690. line._groups[0][0].inject(p._groups[0][0],"after");
  691. line.attr("stroke-width", "3");
  692. points.attr("r", "6").attr("stroke-width", "3");
  693. texts.attr("display", "block");
  694. texts.attr("font-weight", "bold");
  695. },
  696. recreateBars: function(i){
  697. //var data = this.data.calculateGrid.map(function(d, idx) {
  698. var data = this.selectedData.map(function(d, idx) {
  699. return {"name": d["group"], "data": this.toFloat(d.list[i].value)};
  700. }.bind(this));
  701. this.bar.rectClass = Math.round(Math.random()*100);
  702. var barWidth = this.bar.xScale.bandwidth()/this.bar.barsData.length;
  703. var rects = this.bar.group.selectAll(".MWFBar_"+this.bar.rectClass+"_"+i)
  704. .data(data)
  705. .enter().append("rect")
  706. .attr("class", ".MWFBar_"+this.bar.rectClass+"_"+i)
  707. .attr("x", function(d) { return this.xScale(d.name)+(i*barWidth); }.bind(this.bar))
  708. .attr("width", barWidth)
  709. .attr("height", function(d) { return this.size.y - this.yScale(d.data); }.bind(this.bar))
  710. .attr("y", function(d) { return this.yScale(d.data); }.bind(this.bar))
  711. .attr("fill", this.bar.colors[i]);
  712. this.bar.rectCluster[i] = rects;
  713. this.bar.setEvents();
  714. return rects;
  715. },
  716. reloadTable: function(){
  717. if(this.tableAreaNode){
  718. this.tableAreaNode.empty();
  719. this.createTable();
  720. }
  721. },
  722. createTableHead: function(){
  723. this.selectedCols = [];
  724. this.selectedRows = [];
  725. this.table = new Element("table", {
  726. "styles": this.css.statTableNode,
  727. "width": "100%",
  728. "border": "0",
  729. "cellPadding": "0",
  730. "cellSpacing": "0"
  731. }).inject(this.tableAreaNode);
  732. var _self = this;
  733. this.headTr = this.table.insertRow();
  734. this.selectAllTd = (this.headTr.insertCell()).setStyles(this.css.statAllSelectTd).set("title", this.lp.selecteAll);
  735. this.selectAllTd.addClass("selectAllTd").addEvent("click", function(){
  736. _self.selectAll(this);
  737. });
  738. this.selectEntryTd = (this.headTr.insertCell()).setStyles(this.css.statAllColSelectTd).set("title", this.lp.selecteAllCol);
  739. this.selectEntryTd.addClass("selectAllColTd").addEvent("click", function(){
  740. _self.selectAllCol(this);
  741. });
  742. if(this.statGridData.length){
  743. this.statGridData[0].list.each(function(d){
  744. var title = d.displayName;
  745. selectTd = (this.headTr.insertCell()).setStyles(this.css.statColSelectTd);
  746. selectTd.addClass("selectColTd").addEvent("click", function(){
  747. _self.selectCol(this);
  748. });
  749. }.bind(this));
  750. }
  751. if( this.isRowToColumn && this.data.calculate.isAmount ){
  752. this.totalBlankTd = new Element("td.blankTd", {"styles": this.css.blankTd}).inject(this.headTr);
  753. }
  754. this.titleTr = this.table.insertRow();
  755. this.selectGroupTd = (this.titleTr.insertCell()).setStyles(this.css.statAllRowSelectTd).set("title", this.lp.selecteAllRow);
  756. this.selectGroupTd.addClass("selectAllRowTd").addEvent("click", this.selectAllRow.bind(this));
  757. this.categoryTitleTd = new Element("th", {
  758. "styles": this.css.statHeadTh,
  759. "text": this.data.calculate.title || this.lp.category
  760. }).inject(this.titleTr);
  761. this.categoryTitleTd.setStyle("width", "160px");
  762. if(this.statGridData.length) {
  763. this.statGridData[0].list.each(function (d) {
  764. var title = d.displayName;
  765. var th = new Element("th", {
  766. "styles": this.css.statHeadTh,
  767. "text": title
  768. }).inject(this.titleTr);
  769. }.bind(this));
  770. }
  771. if( this.isRowToColumn && this.data.calculate.isAmount ){
  772. this.totalTh = new Element("th.totalTh", {"styles": this.css.totalHeadTh, "text": this.lp.amount}).inject(this.titleTr);
  773. }
  774. },
  775. createTableData: function(){
  776. if (this.statGridData.length){
  777. var _self = this;
  778. // var groupColumn = null;
  779. // for (var c = 0; c<this.data.calculate.calculateList.length; c++){
  780. // if (this.data.calculate.calculateList[c].column === this.data.group.column){
  781. // groupColumn = this.data.calculate.calculateList[c];
  782. // break;
  783. // }
  784. // }
  785. this.statGridData.each(function(d){
  786. var tr = this.table.insertRow().addClass("dataTr");
  787. var selectTd = tr.insertCell().setStyles(this.css.statRowSelectTd).addClass("selectTd");
  788. selectTd.addClass("selectRowTd").addEvent("click", function(){
  789. _self.selectRow(this);
  790. });
  791. var text = d.group;
  792. // if (groupColumn){
  793. // text = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": d.group, "data": this.data}) : d.group;
  794. // }
  795. var categoryTh = new Element("th", {"styles": this.css.statHeadTh, "text": text}).inject(tr);
  796. var total = new Decimal(0);
  797. d.list.each(function(l, i){
  798. var td = new Element("td.dataTd", {"styles": this.css.statContentTdNode}).inject(tr);
  799. td.set("text", l.value);
  800. this.setDragEvent(td);
  801. total = total.plus( this.toFloat( l.value || "0" ) );
  802. }.bind(this));
  803. if( this.isRowToColumn && this.data.calculate.isAmount ) {
  804. var td = new Element("td.totalTd", {"styles": this.css.totalContentTdNode}).inject(tr);
  805. var t = total.toString();
  806. td.set("text", this.toString(d, t));
  807. }
  808. }.bind(this));
  809. if( !this.isRowToColumn && this.data.calculate.isAmount ){
  810. var totals = [], gridDataList = [];
  811. this.statGridData.each(function(d){
  812. d.list.each(function(l, i){
  813. var addv = this.toFloat( l.value || "0" );
  814. if( totals.length > i ){
  815. totals[i] = totals[i].plus(addv);
  816. }else{
  817. gridDataList.push( l );
  818. totals.push( new Decimal(addv) );
  819. }
  820. }.bind(this));
  821. }.bind(this));
  822. var tr = this.table.insertRow();
  823. tr.addClass("totalTr");
  824. var td = new Element("td.blankTd", {"styles": this.css.blankTd}).inject(tr);
  825. var th = new Element("th.totalTh", {"styles": this.css.totalHeadTh, "text": this.lp.amount}).inject(tr);
  826. totals.each(function(l, i) {
  827. var td = new Element("td.totalTd", {"styles": this.css.totalContentTdNode}).inject(tr);
  828. var t = l.toString();
  829. td.set("text", this.toString(gridDataList[i], t));
  830. }.bind(this));
  831. }
  832. }
  833. },
  834. toString: function(gridData, value){
  835. var calculates = this.data.calculate.calculateList.filter(function(c){
  836. return c.id === gridData.column;
  837. });
  838. if( !calculates.length )return value;
  839. var calculate = calculates[0];
  840. switch (calculate.formatType) {
  841. case "currency": //货币
  842. value = this.addZero( value );
  843. value = value.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //添加逗号
  844. value = "¥" + value;
  845. break;
  846. case "percent": //百分比
  847. value = value.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //添加逗号
  848. value = value + "%";
  849. break;
  850. }
  851. return value;
  852. },
  853. addZero: function( s ){
  854. var pointLength = 2;
  855. if( s.indexOf(".") > -1 ){
  856. var length = s.split(".")[1].length;
  857. if( length < pointLength ){
  858. s = s + "0".repeat(pointLength-length);
  859. }
  860. }else{
  861. s = s +"."+ "0".repeat(pointLength)
  862. }
  863. return s;
  864. },
  865. setDragEvent: function(td){
  866. new Drag(td, {
  867. "onStart": function(dragged, e){
  868. this.cellDragStart(dragged, e);
  869. }.bind(this),
  870. "onDrag": function(dragged, e){
  871. this.cellDrag(dragged, e);
  872. }.bind(this),
  873. "onComplete": function(dragged, e){
  874. this.completeDrag(dragged, e);
  875. }.bind(this)
  876. });
  877. var _self = this;
  878. td.addEvent("click", function(){
  879. var cellIndex = td.cellIndex-2;
  880. var rowIndex = td.getParent("tr").rowIndex-2;
  881. if (_self.checkIsSelected(cellIndex, rowIndex)){
  882. }else{
  883. if (_self.selectedCols.length || _self.selectedRows.length){
  884. _self.selectAll();
  885. }
  886. }
  887. });
  888. },
  889. cellDragStart: function(td, e){
  890. //if (_self.selectedCols.length || _self.selectedRows.length){
  891. // _self.selectAll();
  892. //}
  893. var p = td.getPosition();
  894. var size = td.getSize();
  895. td.store("start", {"x": p.x, "y": p.y});
  896. td.store("start2", {"x": p.x+size.x, "y": p.y+size.y});
  897. },
  898. getSelectedCells: function(td, start, e){
  899. var ox = e.page.x-start.x;
  900. var oy = e.page.y-start.y;
  901. var tdSize = td.getSize();
  902. var cols = (ox/tdSize.x).toInt();
  903. var rows = (oy/tdSize.y).toInt();
  904. return {"cols": cols, "rows": rows};
  905. },
  906. cellDrag: function(td, e){
  907. this.selectedRows = [];
  908. this.selectedCols = [];
  909. this.selectedData = [];
  910. var start = td.retrieve("start");
  911. var start2 = td.retrieve("start2");
  912. var c1 = this.getSelectedCells(td, start, e);
  913. var c2 = this.getSelectedCells(td, start2, e);
  914. var cols = (Math.abs(c1.cols)>Math.abs(c2.cols)) ? c1.cols : c2.cols;
  915. var rows = (Math.abs(c1.rows)>Math.abs(c2.rows)) ? c1.rows : c2.rows;
  916. var cellIndex = td.cellIndex-2;
  917. var rowIndex = td.getParent("tr").rowIndex-2;
  918. if (!cellIndex || cellIndex<0) cellIndex = 0;
  919. if (!rowIndex || rowIndex<0) rowIndex = 0;
  920. var toCellIndex = cellIndex+cols;
  921. var toRowIndex = rowIndex+rows;
  922. var statRowIndex;
  923. if( !this.isRowToColumn && this.data.calculate.isAmount ){
  924. var statRow = this.table.getElement(".totalTr");
  925. if( statRow )statRowIndex = statRow.rowIndex - 2;
  926. }
  927. if (toRowIndex>rowIndex){
  928. for (var i=rowIndex; i<=toRowIndex; i++){
  929. if( i !== statRowIndex )this.selectedRows.push(i);
  930. }
  931. }else{
  932. for (var i=toRowIndex; i<=rowIndex; i++){
  933. if( i !== statRowIndex )this.selectedRows.push(i);
  934. }
  935. }
  936. var statColIndex;
  937. if( this.isRowToColumn && this.data.calculate.isAmount ){
  938. statColIndex = (this.totalBlankTd || this.totalTh).cellIndex - 2;
  939. }
  940. if (toCellIndex>cellIndex){
  941. for (var i=cellIndex; i<=toCellIndex; i++){
  942. if( i !== statColIndex )this.selectedCols.push(i);
  943. }
  944. }else{
  945. for (var i=toCellIndex; i<=cellIndex; i++) {
  946. if( i !== statColIndex )this.selectedCols.push(i);
  947. }
  948. }
  949. this.checkSelectedCells();
  950. },
  951. completeDrag: function(td, e){
  952. //设置选中样式
  953. var trs = this.table.getElements("tr[class!='totalTr']");
  954. //取消全部选中
  955. trs.each(function (tr, i) {
  956. if( i === 0 ){
  957. tr.getElements("td").each(function (td, i) {
  958. if( i > 1 && td.hasClass("selectColTd") )td.setStyles(this.css.statTableSelectTd);
  959. }.bind(this));
  960. }else if( i > 1 ){
  961. tr.getElement("td").setStyles(this.css.statTableSelectTd);
  962. }
  963. }.bind(this))
  964. var tds = trs[0].getElements("td");
  965. this.selectedCols.each(function(i){
  966. var td = tds[i+2];
  967. if(td.hasClass("selectColTd"))td.setStyles(this.css.statTableSelectedTd);
  968. }.bind(this));
  969. this.selectedRows.each(function(i){
  970. var td = trs[i+2].getElement("td");
  971. if(td.hasClass("selectRowTd"))td.setStyles(this.css.statTableSelectedTd);
  972. }.bind(this));
  973. this.reloadChart();
  974. },
  975. selectCol: function(td){
  976. var i = td.cellIndex;
  977. var dataIndex = i-2;
  978. if (this.selectedCols.indexOf(dataIndex)!=-1){
  979. td.setStyles(this.css.statTableSelectTd);
  980. this.selectedCols.erase(dataIndex);
  981. }else{
  982. td.setStyles(this.css.statTableSelectedTd);
  983. this.selectedCols.push(dataIndex);
  984. }
  985. this.checkSelectedCells();
  986. this.reloadChart();
  987. },
  988. selectRow: function(td){
  989. var tr = td.getParent("tr");
  990. var i = tr.rowIndex;
  991. var dataIndex = i-2;
  992. if (this.selectedRows.indexOf(dataIndex)!=-1){
  993. td.setStyles(this.css.statTableSelectTd);
  994. this.selectedRows.erase(dataIndex);
  995. }else{
  996. td.setStyles(this.css.statTableSelectedTd);
  997. this.selectedRows.push(dataIndex);
  998. }
  999. this.checkSelectedCells();
  1000. this.reloadChart();
  1001. },
  1002. selectAllRow: function(){
  1003. if (this.selectedRows.length){
  1004. this.selectedRows = [];
  1005. var trs = this.table.getElements("tr[class!='totalTr']");
  1006. for (var n=2; n<trs.length; n++){
  1007. trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  1008. }
  1009. }else{
  1010. this.selectedRows = [];
  1011. var seltrs = this.table.getElements("tr[class!='totalTr']");
  1012. for (var n=2; n<seltrs.length; n++){
  1013. this.selectedRows.push(n-2);
  1014. seltrs[n].getElement("td").setStyles(this.css.statTableSelectedTd);
  1015. }
  1016. }
  1017. this.checkSelectedCells();
  1018. this.reloadChart();
  1019. },
  1020. selectAllCol: function(){
  1021. if (this.selectedCols.length){
  1022. this.selectedCols = [];
  1023. var trs = this.table.getElements("tr[class!='totalTr']");
  1024. var tds = trs[0].getElements("td");
  1025. for (var i=2; i<tds.length; i++){
  1026. tds[i].setStyles(this.css.statTableSelectTd);
  1027. }
  1028. //for (var n=2; n<trs.length; n++){
  1029. // trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  1030. //}
  1031. }else{
  1032. var seltrs = this.table.getElements("tr[class!='totalTr']");
  1033. var seltds = seltrs[0].getElements("td");
  1034. for (var n=2; n<seltds.length; n++){
  1035. this.selectedCols.push(n-2);
  1036. seltds[n].setStyles(this.css.statTableSelectedTd);
  1037. }
  1038. }
  1039. this.checkSelectedCells();
  1040. this.reloadChart();
  1041. },
  1042. selectAll: function(){
  1043. debugger;
  1044. if (this.selectedRows.length || this.selectedCols.length){
  1045. this.selectedRows = [];
  1046. this.selectedCols = [];
  1047. var trs = this.table.getElements("tr[class!='totalTr']");
  1048. var tds = trs[0].getElements("td");
  1049. for (var i=2; i<tds.length; i++){
  1050. if( tds[i].hasClass("selectColTd") )tds[i].setStyles(this.css.statTableSelectTd);
  1051. }
  1052. for (var n=2; n<trs.length; n++){
  1053. trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  1054. }
  1055. }else{
  1056. var seltrs = this.table.getElements("tr[class!='totalTr']");
  1057. var seltds = seltrs[0].getElements("td");
  1058. for (var seli=2; seli<seltds.length; seli++){
  1059. if( seltds[seli].hasClass("selectColTd") ){
  1060. this.selectedCols.push(seli-2);
  1061. seltds[seli].setStyles(this.css.statTableSelectedTd);
  1062. }
  1063. }
  1064. for (var seln=2; seln<seltrs.length; seln++){
  1065. this.selectedRows.push(seln-2);
  1066. seltrs[seln].getElement("td").setStyles(this.css.statTableSelectedTd);
  1067. }
  1068. }
  1069. this.checkSelectedCells();
  1070. this.reloadChart();
  1071. },
  1072. checkIsSelected: function(ci, ri){
  1073. if (!this.selectedCols.length && !this.selectedRows.length) return false;
  1074. var colSelect = (!this.selectedCols.length) || this.selectedCols.indexOf(ci)!=-1;
  1075. var rowSelect = (!this.selectedRows.length) || this.selectedRows.indexOf(ri)!=-1;
  1076. return (colSelect && rowSelect);
  1077. },
  1078. checkSelectedCells: function(){
  1079. this.selectedData = [];
  1080. var rows = this.table.getElements("tr[class!='totalTr']");
  1081. for (var rowIdx = 2; rowIdx<rows.length; rowIdx++){
  1082. var o = {
  1083. "group": this.statGridData[rowIdx-2].group,
  1084. "list": []
  1085. };
  1086. var cols = rows[rowIdx].getElements("td");
  1087. for (var colIdx = 1; colIdx<cols.length; colIdx++){
  1088. if ( cols[colIdx].hasClass("dataTd") && this.checkIsSelected(colIdx-1, rowIdx-2)){
  1089. cols[colIdx].setStyles(this.css.statContentTdNode_selected);
  1090. o.list.push({
  1091. "column": this.statGridData[rowIdx-2].list[colIdx-1].column,
  1092. "displayName": this.statGridData[rowIdx-2].list[colIdx-1].displayName,
  1093. "value": this.statGridData[rowIdx-2].list[colIdx-1].value
  1094. });
  1095. }else{
  1096. cols[colIdx].setStyles(this.css.statContentTdNode);
  1097. }
  1098. }
  1099. if (o.list.length) this.selectedData.push(o);
  1100. }
  1101. },
  1102. reloadChart: function(){
  1103. if (this.json.isChart && this.charts.length > 0 ){
  1104. if (this.bar) this.bar.destroy();
  1105. this.bar = null;
  1106. if (this.chartFlagNode){
  1107. this.chartFlagNode.destroy();
  1108. this.chartFlagNode = null;
  1109. }
  1110. if (this.chartNode)this.chartNode.empty();
  1111. switch (this.currentChart){
  1112. case "bar":
  1113. this.loadChartBar();
  1114. break;
  1115. case "pie":
  1116. this.loadChartPie();
  1117. break;
  1118. case "line":
  1119. this.loadChartLine();
  1120. break;
  1121. default:
  1122. this.loadChartBar();
  1123. }
  1124. }
  1125. }
  1126. });