reportCtrl.js 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. 'use strict';
  2. app.controller('reportCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "moment", "SweetAlert", "Restangular", "api_report", "api_statistic", function($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, moment, SweetAlert, Restangular, api_report, api_statistic) {
  3. var ROWS = "ROWS";
  4. var COLUMNS = "COLUMNS";
  5. $scope.treeshow = true;
  6. $scope.searchstate = "";
  7. $scope.headers = "请选择事件树形列表!";
  8. api_report.getLicenseKey().then(function(response) {
  9. $cookieStore.put('Auth-Token', response.token);
  10. $scope.try_async_load();
  11. });
  12. var apple_selected, tree, treedata_avm, treedata_geography;
  13. var workspace = {};
  14. $scope.parameters = {};
  15. // $scope.starttimes = {};
  16. // $scope.endtimes = {};
  17. $scope.category = {};
  18. $scope.reportName = "报表";
  19. $scope.allheight = 100;
  20. $scope.isMaskground = false;
  21. // var starttime, endtime
  22. // $scope.starttimes = moment().startOf('month').format('YYYYMMDD');
  23. // $scope.endtimes = moment().format('YYYYMMDD');
  24. $scope.starttimes = moment(new Date().getTime() - 86400000 * 7).format('YYYYMMDD');
  25. $scope.endtimes = moment(new Date().getTime() - 86400000).format('YYYYMMDD');
  26. $scope.changeForm = function(paramDateFrom) {
  27. $scope.starttimes = moment(paramDateFrom).format('YYYYMMDD');
  28. }
  29. $scope.changeTo = function(paramDateTo) {
  30. $scope.endtimes = moment(paramDateTo).format('YYYYMMDD');
  31. }
  32. $scope.week = function() {
  33. $scope.searchstate = "week";
  34. var weeks = new Date().getDay();
  35. $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYYMMDD');
  36. $scope.endtimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYYMMDD');
  37. $scope.parameters.paramDateFrom = $scope.starttimes;
  38. $scope.parameters.paramDateTo = $scope.endtimes;
  39. $scope.parameters = parseDateParameter($scope.parameters);
  40. $scope.mdxquery();
  41. }
  42. $scope.month = function() {
  43. $scope.searchstate = "month";
  44. $scope.starttimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth() - 1)).format('YYYYMMDD');
  45. $scope.endtimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth()) - 86400000).format('YYYYMMDD');
  46. $scope.parameters.paramDateFrom = $scope.starttimes;
  47. $scope.parameters.paramDateTo = $scope.endtimes;
  48. $scope.parameters = parseDateParameter($scope.parameters);
  49. $scope.mdxquery();
  50. }
  51. $scope.year = function() {
  52. $scope.searchstate = "year";
  53. $scope.starttimes = moment().startOf('year').format('YYYYMMDD');
  54. $scope.endtimes = moment().format('YYYYMMDD');
  55. $scope.parameters.paramDateFrom = $scope.starttimes;
  56. $scope.parameters.paramDateTo = $scope.endtimes;
  57. $scope.parameters = parseDateParameter($scope.parameters);
  58. $scope.mdxquery();
  59. }
  60. $scope.my_tree_handler = function(branch) {
  61. $scope.isMaskground = true;
  62. $scope.treeshow = false;
  63. if (branch.type == 'FILE') {
  64. console.log(branch);
  65. $scope.reportName = branch.label;
  66. var path = $scope.mdxpath = branch.path;
  67. queryUUID = genUUID();
  68. api_report.getMdx(path, queryUUID).then(function(response) {
  69. var mdxquery = Restangular.stripRestangular(response);
  70. workspace.query = mdxquery;
  71. $scope.shows = false;
  72. $scope.isMaskground = false;
  73. workspace.query.parameters.paramDateFrom = $scope.starttimes;
  74. workspace.query.parameters.paramDateTo = $scope.endtimes;
  75. $scope.parameters = parseDateParameter(workspace.query.parameters);
  76. if (workspace.query.parameters.reportUUID) {
  77. $scope.rptUUID = workspace.query.parameters.reportUUID;
  78. delete workspace.query.parameters.reportUUID;
  79. $scope.parameters = parseDateParameter(workspace.query.parameters);
  80. api_statistic.query(workspace.query.parameters, $scope.rptUUID).then(function(data) {
  81. $scope.rheaders = [];
  82. $scope.rRows = [];
  83. var reportData = Restangular.stripRestangular(data);
  84. if (reportData.cellset.length < 2) {
  85. reportData.cellset = null;
  86. $scope.shows = true;
  87. $scope.empty = "数据为空!"
  88. }
  89. var tableContent = render(reportData);
  90. })
  91. } else {
  92. $scope.rptUUID = undefined;
  93. api_report.execute(mdxquery).then(function(data) {
  94. $scope.rheaders = [];
  95. $scope.rRows = [];
  96. var reportData = Restangular.stripRestangular(data);
  97. // if($scope.reportName=="事件工作回顾"&&reportData.cellset.length<4){
  98. // reportData.cellset=null;
  99. // }
  100. // if($scope.reportName=="事件解决率统计"&&reportData.cellset.length<4){
  101. // reportData.cellset=null;
  102. // }
  103. if (reportData.cellset == null || reportData.cellset.length == 0) {
  104. $scope.shows = true;
  105. $scope.empty = "数据为空!"
  106. }
  107. //console.log(reportData);
  108. var tableContent = render(reportData);
  109. renderChart(reportData);
  110. //console.log(tableContent);
  111. //console.log($scope.rheaders);
  112. })
  113. }
  114. //http://localhost:9008/api/statistic/unidimensional/d75e22c1-7f60-4e22-affd-23742a475407
  115. });
  116. }
  117. }
  118. $scope.my_data = [];
  119. $scope.my_tree = tree = {};
  120. $scope.try_async_load = function() {
  121. $scope.my_data = [];
  122. $scope.select_treedata = [];
  123. api_report.list().then(function(response) {
  124. var dataList = Restangular.stripRestangular(response);
  125. getRepoRoot(dataList, '/homes/home:admin/ITSM报表');
  126. $scope.repoRoot.name = "模块选择"
  127. convertRepoObject($scope.repoRoot);
  128. $scope.my_data.push($scope.repoRoot);
  129. });
  130. };
  131. $scope.repoRoot = null;
  132. function getRepoRoot(repo, path) {
  133. angular.forEach(repo, function(value, key) {
  134. if (value.path == path) {
  135. $scope.repoRoot = value;
  136. } else {
  137. if ($scope.repoRoot == null && angular.isDefined(value.repoObjects)) {
  138. getRepoRoot(value.repoObjects, path);
  139. } else {
  140. }
  141. }
  142. });
  143. }
  144. function convertRepoObject(repo) {
  145. if (angular.isArray(repo)) {
  146. angular.forEach(repo, function(value, key) {
  147. convertRepoObject(value);
  148. })
  149. } else {
  150. if (angular.isDefined(repo.name)) {
  151. if (repo.name.indexOf(".") >= 0) {
  152. repo.label = repo.name.substr(0, repo.name.lastIndexOf("."));
  153. } else {
  154. repo.label = repo.name;
  155. }
  156. //delete repo.name;
  157. }
  158. if (angular.isDefined(repo.repoObjects)) {
  159. repo.children = [];
  160. repo.children = repo.repoObjects;
  161. delete repo.repoObjects;
  162. convertRepoObject(repo.children);
  163. }
  164. }
  165. }
  166. function convertListToTree(data, treeMap) {
  167. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  168. var root = null; //Initially set our loop to null
  169. var parentNode = null;
  170. //loop over data
  171. for (var i = 0; i < data.length; i++) {
  172. var datum = data[i];
  173. //each node will have children, so let's give it a "children" poperty
  174. datum.children = [];
  175. //add an entry for this node to the map so that any future children can
  176. //lookup the parent
  177. idToNodeMap[datum.id] = datum;
  178. //Does this node have a parent?
  179. if (typeof datum.parent === "undefined" || datum.parent == null) {
  180. //Doesn't look like it, so this node is the root of the tree
  181. root = datum;
  182. treeMap[datum.id] = root;
  183. } else {
  184. //This node has a parent, so let's look it up using the id
  185. parentNode = idToNodeMap[datum.parent.id];
  186. //We don't need this property, so let's delete it.
  187. delete datum.parent;
  188. //Let's add the current node as a child of the parent node.
  189. parentNode.children.push(datum);
  190. }
  191. }
  192. return root;
  193. }
  194. function convertParentToChildList(data) {
  195. var treeMap = {};
  196. var list = [];
  197. convertListToTree(data, treeMap);
  198. angular.forEach(treeMap, function(item) {
  199. list.push(item);
  200. });
  201. return list;
  202. }
  203. function parseDateParameter(parameters) {
  204. var result = undefined;
  205. if (angular.isArray(parameters)) {
  206. // angular.forEach(parmeters,function(param){
  207. // param.
  208. // })
  209. } else {
  210. result = {};
  211. for (var k in parameters) {
  212. if (k.indexOf("Date") > 0) {
  213. if (angular.isString(parameters[k])) {
  214. result[k] = moment(parameters[k], "YYYYMMDD").format("YYYY-MM-DD");
  215. //result[k] = ''+parameters[k]+'';//= moment(parameters[k], "YYYYMMDD").toDate();
  216. }
  217. }
  218. }
  219. }
  220. return result;
  221. }
  222. function ConvertDateParameter(parameters) {
  223. var result = undefined;
  224. if (angular.isArray(parameters)) {
  225. //
  226. } else {
  227. result = {};
  228. for (var k in parameters) {
  229. if (k.indexOf("Date") > 0) {
  230. if (angular.isDate(parameters[k])) {
  231. result[k] = moment(parameters[k]).format("YYYYMMDD");
  232. } else if (angular.isString(parameters[k])) {
  233. result[k] = parameters[k];
  234. }
  235. }
  236. }
  237. }
  238. return result;
  239. }
  240. $scope.open = function($event) {
  241. $event.preventDefault();
  242. $event.stopPropagation();
  243. $scope.opened = !$scope.opened;
  244. };
  245. $scope.endOpen = function($event) {
  246. $event.preventDefault();
  247. $event.stopPropagation();
  248. $scope.startOpened = false;
  249. $scope.endOpened = !$scope.endOpened;
  250. };
  251. $scope.startOpen = function($event) {
  252. $event.preventDefault();
  253. $event.stopPropagation();
  254. $scope.endOpened = false;
  255. $scope.startOpened = !$scope.startOpened;
  256. };
  257. $scope.mdxquery = function(key) {
  258. $scope.isMaskground = true;
  259. if (key && key == 'all') {
  260. $scope.searchstate = "";
  261. }
  262. $scope.shows = false;
  263. if (angular.isDefined(workspace.query)) {
  264. if ($scope.rptUUID) {
  265. workspace.query.parameters = ConvertDateParameter($scope.parameters);
  266. workspace.query.parameters.paramDateFrom = workspace.query.parameters.paramDateFrom.replace(/-/g, "");
  267. workspace.query.parameters.paramDateTo = workspace.query.parameters.paramDateTo.replace(/-/g, "");
  268. $scope.starttimes = workspace.query.parameters.paramDateFrom;
  269. $scope.endtimes = workspace.query.parameters.paramDateTo;
  270. api_statistic.query(workspace.query.parameters, $scope.rptUUID).then(function(data) {
  271. $scope.rheaders = [];
  272. $scope.rRows = [];
  273. $scope.isMaskground = false;
  274. var reportData = Restangular.stripRestangular(data);
  275. if (reportData.cellset.length < 2) {
  276. reportData.cellset = null;
  277. $scope.shows = true;
  278. $scope.empty = "数据为空!"
  279. }
  280. var tableContent = render(reportData);
  281. })
  282. } else {
  283. $scope.rptUUID = undefined;
  284. workspace.query.parameters = ConvertDateParameter($scope.parameters);
  285. if (angular.isDefined($scope.parameters.paramDateFrom) && angular.isDefined($scope.parameters.paramDateTo)) {
  286. workspace.query.parameters.paramDateFrom = workspace.query.parameters.paramDateFrom.replace(/-/g, "");
  287. workspace.query.parameters.paramDateTo = workspace.query.parameters.paramDateTo.replace(/-/g, "");
  288. // workspace.query.parameters=ConvertDateParameter($scope.parameters);
  289. // workspace.query.parameters.categorys=categorys;
  290. $scope.starttimes = workspace.query.parameters.paramDateFrom;
  291. $scope.endtimes = workspace.query.parameters.paramDateTo;
  292. api_report.execute(workspace.query).then(function(data) {
  293. $scope.isMaskground = false;
  294. $scope.rheaders = [];
  295. $scope.rRows = [];
  296. var reportData = Restangular.stripRestangular(data);
  297. if (reportData.cellset == null || reportData.cellset.length == 0) {
  298. $scope.shows = true;
  299. $scope.empty = "数据为空!"
  300. }
  301. console.log(reportData);
  302. var tableContent =
  303. render(reportData);
  304. renderChart(reportData);
  305. console.log($scope.rheaders);
  306. })
  307. }
  308. }
  309. }
  310. }
  311. $scope.execute = function() {
  312. api_report.list($scope.token).then(function(response) {
  313. $scope.select_treedata = $scope.my_data = response;
  314. });
  315. }
  316. $scope.searchOptions = function() {
  317. if (angular.isDefined(workspace.query)) {
  318. var queryParameters = workspace.query.parameters;
  319. for (var parm in queryParameters) {
  320. if (parm == 'Week') {
  321. } else {
  322. }
  323. }
  324. }
  325. }
  326. $scope.activeParentGroup = false;
  327. $scope.disabledParentGroup = false;
  328. $scope.toggleParentGroup = function() {
  329. if (workspace.query) {
  330. // if($scope.activeParentGroup){
  331. // workspace.query.properties['saiku.olap.result.formatter']='flat';
  332. // $scope.activeParentGroup=!$scope.activeParentGroup;
  333. // }else{
  334. workspace.query.properties['saiku.olap.result.formatter'] = 'flattened';
  335. // $scope.activeParentGroup=!$scope.activeParentGroup;
  336. // }
  337. //console.log(workspace.query);
  338. executeQuery(workspace.query);
  339. }
  340. }
  341. var process_data_tree = function(args, flat, setdata) {
  342. var self = this;
  343. var data = {};
  344. if (flat) {
  345. data.resultset = [];
  346. data.metadata = [];
  347. data.height = 0;
  348. data.width = 0;
  349. }
  350. var currentDataPos = data;
  351. if (typeof args == "undefined" || typeof args.data == "undefined") {
  352. return;
  353. }
  354. if (args.data !== null && args.data.error !== null) {
  355. return;
  356. }
  357. // Check to see if there is data
  358. if (args.data === null || (args.data.cellset && args.data.cellset.length === 0)) {
  359. return;
  360. }
  361. var cellset = args.data.cellset;
  362. if (cellset && cellset.length > 0) {
  363. var lowest_level = 0;
  364. var data_start = 0;
  365. var hasStart = false;
  366. var row,
  367. rowLen,
  368. labelCol,
  369. reduceFunction = function(memo, num) {
  370. return memo + num;
  371. };
  372. for (row = 0, rowLen = cellset.length; data_start === 0 && row < rowLen; row++) {
  373. for (var field = 0, fieldLen = cellset[row].length; field < fieldLen; field++) {
  374. if (!hasStart) {
  375. while (cellset[row][field].type == "COLUMN_HEADER" && cellset[row][field].value == "null") {
  376. row++;
  377. }
  378. }
  379. hasStart = true;
  380. if (cellset[row][field].type == "ROW_HEADER_HEADER") {
  381. while (cellset[row][field].type == "ROW_HEADER_HEADER") {
  382. if (flat) {
  383. data.metadata.push({
  384. colIndex: field,
  385. colType: "String",
  386. colName: cellset[row][field].value
  387. });
  388. }
  389. field++;
  390. }
  391. lowest_level = field - 1;
  392. }
  393. if (cellset[row][field].type == "COLUMN_HEADER") {
  394. var lowest_col_header = 0;
  395. var colheader = [];
  396. while (lowest_col_header <= row) {
  397. if (cellset[lowest_col_header][field].value !== "null") {
  398. colheader.push(cellset[lowest_col_header][field].value);
  399. }
  400. lowest_col_header++;
  401. }
  402. if (flat) {
  403. data.metadata.push({
  404. colIndex: field,
  405. colType: "Numeric",
  406. colName: colheader.join(' ~ ')
  407. });
  408. }
  409. data_start = row + 1;
  410. }
  411. }
  412. }
  413. var labelsSet = {};
  414. var rowlabels = [];
  415. for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
  416. rowlabels.push(null);
  417. }
  418. for (row = data_start, rowLen = cellset.length; row < rowLen; row++) {
  419. if (cellset[row][0].value !== "") {
  420. var record = [];
  421. var flatrecord = [];
  422. var parent = null;
  423. var rv = null;
  424. for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
  425. if (cellset[row] && cellset[row][labelCol].value === 'null') {
  426. currentDataPos = data;
  427. var prevLabel = 0;
  428. for (; prevLabel < lowest_level && cellset[row][prevLabel].value === 'null'; prevLabel++) {
  429. currentDataPos = currentDataPos[rowlabels[prevLabel]];
  430. }
  431. if (prevLabel > labelCol) {
  432. labelCol = prevLabel;
  433. }
  434. }
  435. if (cellset[row] && cellset[row][labelCol].value !== 'null') {
  436. if (labelCol === 0) {
  437. for (var xx = 0; xx <= lowest_level; xx++) {
  438. rowlabels[xx] = null;
  439. }
  440. }
  441. if (typeof currentDataPos == "number") {
  442. parent[rv] = {};
  443. currentDataPos = parent[rv];
  444. }
  445. rv = cellset[row][labelCol].value;
  446. rowlabels[labelCol] = rv;
  447. if (!currentDataPos.hasOwnProperty(rv)) {
  448. currentDataPos[rv] = {};
  449. }
  450. parent = currentDataPos;
  451. currentDataPos = currentDataPos[rv];
  452. }
  453. }
  454. flatrecord = _.clone(rowlabels);
  455. for (var col = lowest_level + 1, colLen = cellset[row].length; col < colLen; col++) {
  456. var cell = cellset[row][col];
  457. var value = cell.value || 0;
  458. var maybePercentage = (value !== 0);
  459. // check if the resultset contains the raw value, if not try to parse the given value
  460. var raw = cell.properties.raw;
  461. if (raw && raw !== "null") {
  462. value = parseFloat(raw);
  463. } else if (typeof(cell.value) !== "number" && parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''))) {
  464. value = parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''));
  465. maybePercentage = false;
  466. }
  467. if (value > 0 && maybePercentage) {
  468. value = cell.value && cell.value.indexOf('%') >= 0 ? value * 100 : value;
  469. }
  470. record.push(value);
  471. flatrecord.push({ f: cell.value, v: value });
  472. }
  473. if (flat) data.resultset.push(flatrecord);
  474. var sum = _.reduce(record, reduceFunction, 0);
  475. rv = (rv === null ? "null" : rv);
  476. parent[rv] = sum;
  477. currentDataPos = data;
  478. }
  479. }
  480. if (setdata) {
  481. self.rawdata = args.data;
  482. self.data = data;
  483. self.hasProcessed = true;
  484. self.data.height = self.data.resultset.length;
  485. }
  486. return data;
  487. } else {
  488. //no result
  489. //$(self.el).find('.canvas_wrapper').text("No results").show();
  490. }
  491. };
  492. //图
  493. function randColor() {
  494. tmpHSV = randomHSV(tmpHSV);
  495. return colorToHex(HSVToRGB(tmpHSV.h, tmpHSV.s, tmpHSV.v));
  496. // console.log()
  497. };
  498. function highlightColor() {
  499. var highlight = {
  500. h: tmpHSV.h + 5.5,
  501. s: 0.55,
  502. v: 0.5
  503. };
  504. return colorToHex(HSVToRGB(highlight.h, highlight.s, highlight.v));
  505. }
  506. var renderChart = function(reportData) {
  507. var data = process_data_tree({ data: reportData });
  508. var _ = window._;
  509. var dataChart = undefined;
  510. $scope.chartData = [];
  511. // tmpHSV=undefined;
  512. if (workspace.query) {
  513. if (workspace.query.properties['saiku.ui.render.type'] == "sunburst") {
  514. $scope.chartType = "pie";
  515. dataChart = [];
  516. var total = 0;
  517. var i = 0;
  518. _.forIn(data, function(value, key) {
  519. total += value;
  520. i++;
  521. dataChart.push({
  522. label: key,
  523. value: value,
  524. color: randColor()
  525. });
  526. });
  527. // function randColor(){
  528. // if(i%4==1){return '#01A2D9'}
  529. // else if(i%4==2){return '#71BBDE'}
  530. // else if(i%4==3){return '#FF9122'}
  531. // else if(i%4==0){return '#F8B705'}
  532. // }
  533. // console.log(total);
  534. // for(var i=0;i<dataChart.length;i++){
  535. // dataChart[i].value=dataChart[i].value*100/total
  536. // dataChart[i].value=dataChart[i].value.toFixed(2);
  537. // }
  538. $scope.chartData = dataChart;
  539. $scope.chartOptions = {
  540. // responsive: true,
  541. // //Boolean - Whether we should show a stroke on each segment
  542. segmentShowStroke: true,
  543. // //String - The colour of each segment stroke
  544. // segmentStrokeColor : '#fff',
  545. // //Number - The width of each segment stroke
  546. segmentStrokeWidth: 2,
  547. // //Number - The percentage of the chart that we cut out of the middle
  548. // percentageInnerCutout : 0, // This is 0 for Pie charts
  549. // //Number - Amount of animation steps
  550. // animationSteps : 100,
  551. // //String - Animation easing effect
  552. // animationEasing : 'easeOutBounce',
  553. // //Boolean - Whether we animate the rotation of the Doughnut
  554. // animateRotate : true,
  555. // //Boolean - Whether we animate scaling the Doughnut from the centre
  556. // animateScale : false,
  557. // //String - A legend template
  558. legendTemplate: '<ul class="tc-chart-js-legend col-md-2.5 " style="float:right;margin-top:-250px;z-index: 999;"><% for (var i=0; i<Math.min(segments.length,5); i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
  559. //showTooltips:false,
  560. //tooltipEvents:[],
  561. onAnimationComplete: function() {
  562. this.showTooltip(this.segments, true);
  563. console.log(this.segments)
  564. }
  565. };
  566. } else if (workspace.query.properties['saiku.ui.render.type'] == "stackedBar") {
  567. // $scope.chartType="bar";
  568. // dataChart = {};
  569. // var labels=[];
  570. // var barData =[];
  571. // _.forIn(data, function(value, key) {
  572. // labels.push(key);
  573. // barData.push(value);
  574. // });
  575. // dataChart={
  576. // labels:labels,
  577. // datasets:[]
  578. // };
  579. // dataChart.datasets.push({
  580. // //label:'事件数',
  581. // fillColor: '#0E7EC5',
  582. // strokeColor: 'rgba(220,220,220,0.8)',
  583. // highlightFill: 'rgba(220,220,220,0.75)',
  584. // highlightStroke: 'rgba(220,220,220,1)',
  585. // data:barData
  586. // });
  587. // $scope.chartData = dataChart;
  588. // $scope.chartOptions = {};
  589. // }else if(workspace.query.properties['saiku.ui.render.type']=="pie"){
  590. // $scope.chartType="doughnut";
  591. // $scope.series=[];
  592. // dataChart = [];
  593. // var i=0;
  594. // var chart=[];
  595. // // $scope.firstchart=false;
  596. // // $scope.secondchart=false;
  597. // var chartcanvas=function(canvansdata){
  598. // _.forIn(canvansdata, function(value, key) {
  599. // var sum = 0;
  600. // if(typeof(value)=='object'){
  601. // _.forIn(value, function(date, item) {
  602. // sum += date;
  603. // });
  604. // }else{
  605. // sum = value;
  606. // }
  607. // dataChart.push({
  608. // indexLabel:key,
  609. // y:sum,
  610. // color:randColor() ,
  611. // highlight: highlightColor(),
  612. // });
  613. // });
  614. // // $scope.chartData = dataChart;
  615. // chart = new CanvasJS.Chart("chartContainer"+[i],{
  616. // theme: "theme2",
  617. // title:{
  618. // text: $scope.reportName
  619. // },
  620. // data: [{
  621. // type: "pie",
  622. // showInLegend: true,
  623. // toolTipContent: "{indexLabel} - #percent %",
  624. // yValueFormatString: "",
  625. // legendText: "{indexLabel}",
  626. // dataPoints: dataChart
  627. // }],
  628. // plotOptions: {
  629. // series: {
  630. // cursor: 'pointer',
  631. // events: {
  632. // click: function(e) {
  633. // _.forIn(canvansdata, function(value, key) {
  634. // if(key==e.dataPoint.indexLabel&&typeof(value)=='object'){
  635. // dataChart=[];
  636. // i++;
  637. // chartcanvas(value);
  638. // }
  639. // });
  640. // }
  641. // }
  642. // }
  643. // },
  644. // });
  645. // chart.render();
  646. // // i++;
  647. // }
  648. // chartcanvas(data);
  649. }
  650. //"line"
  651. //"bar"
  652. //"radar"
  653. //"polararea"
  654. //"pie"
  655. //"doughnut"
  656. }
  657. }
  658. var queryUUID;
  659. function genUUID() {
  660. var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
  661. function(c) {
  662. var r = Math.random() * 16 | 0,
  663. v = c == 'x' ? r : (r & 0x3 | 0x8);
  664. return v.toString(16);
  665. }).toUpperCase();
  666. return uuid;
  667. }
  668. function exportMdxBefore(path, uuid, callback) {
  669. var rdata = 'file=' + path + '&formatter=flattened&language=zh';
  670. $http({
  671. url: api_report.queryMdxUri(uuid).getRequestedUrl(),
  672. method: 'POST',
  673. data: rdata,
  674. headers: {
  675. 'Content-Type': 'application/x-www-form-urlencoded',
  676. 'X-Auth-Token': $cookieStore.get('Auth-Token') || null
  677. }
  678. }).success(function(data, status, headers, config) {
  679. if (status == 200) {
  680. if (callback) {
  681. callback(data.name, path);
  682. }
  683. }
  684. //console.log(status);
  685. //console.log(data);
  686. });
  687. }
  688. $scope.getRelativePosition = function(eve) {
  689. console.log(eve)
  690. }
  691. $scope.getPointPosition = function(eve) {
  692. console.log("31231")
  693. }
  694. $scope.exportData = function(uuid) {
  695. //var url=api_report.exportData($scope.mdxpath).getRequestedUrl();
  696. if (!uuid && queryUUID) {
  697. uuid = queryUUID;
  698. }
  699. var name = $scope.mdxpath;
  700. // if(workspace.query.name!=undefined){
  701. // exportMdxBefore(name,uuid, function(queryName,path){
  702. // var filename = path.substring(path.lastIndexOf('/')+1).slice(0, -5);
  703. // $http({
  704. // url : api_report.exportData('flat', queryName, encodeURIComponent(filename)).getRequestedUrl(),
  705. // method : 'GET',
  706. // params : {},
  707. // headers : {
  708. // //'Content-type' : 'application/xls',
  709. // 'Accept': 'application/vnd.ms-excel',
  710. // 'X-Auth-Token' : $cookieStore.get('Auth-Token')||null
  711. // },
  712. // responseType : 'arraybuffer'
  713. // }).success(function(data, status, headers, config) {
  714. // var file = new Blob([ data ], {
  715. // type : 'application/vnd.ms-excel'
  716. // });
  717. // //trick to download store a file having its URL
  718. // var fileURL = URL.createObjectURL(file);
  719. // var a = document.createElement('a');
  720. // a.href = fileURL;
  721. // a.target = '_blank';
  722. // a.download = filename+"xls";
  723. // document.body.appendChild(a);
  724. // a.click();
  725. // }).error(function(data, status, headers, config) {
  726. // console.log(data);
  727. // });
  728. // });
  729. // }
  730. // return;
  731. //return url;
  732. if (workspace.query.name != undefined) {
  733. var filename = name.substring(name.lastIndexOf('/') + 1).slice(0, -5);
  734. // if(filename=="事件详细资料."){
  735. // // api_statistic.unidimensionalExport(workspace.query.parameters,$scope.rptUUID).then(function(data){
  736. // // var file = new Blob([ data ], {
  737. // // type : 'application/vnd.ms-excel;charset=utf-8;'
  738. // // });
  739. // // //trick to download store a file having its URL
  740. // // var fileURL = URL.createObjectURL(file);
  741. // // var a = document.createElement('a');
  742. // // a.href = fileURL;
  743. // // a.target = '_blank';
  744. // // a.download = filename+"xls";
  745. // // document.body.appendChild(a);
  746. // // a.click();
  747. // // })
  748. // $http({
  749. // url : api_statistic.unidimensionalExport($scope.rptUUID).getRequestedUrl(),
  750. // method : 'POST',
  751. // data : workspace.query.parameters,
  752. // headers : {
  753. // //'Content-type' : 'application/xls',
  754. // 'Accept': '*/*'
  755. // },
  756. // responseType : 'arraybuffer'
  757. // }).success(function(data, status, headers, config) {
  758. // var file = new Blob([ data ], {
  759. // type : 'application/vnd.ms-excel'
  760. // });
  761. // //trick to download store a file having its URL
  762. // var fileURL = URL.createObjectURL(file);
  763. // var a = document.createElement('a');
  764. // a.href = fileURL;
  765. // a.target = '_blank';
  766. // a.download = filename+"xls";
  767. // document.body.appendChild(a);
  768. // a.click();
  769. // }).error(function(data, status, headers, config) {
  770. // console.log(data);
  771. // });
  772. // }else{
  773. $http({
  774. url: api_report.exportData('flat', uuid, encodeURIComponent(filename)).getRequestedUrl(),
  775. method: 'POST',
  776. data: workspace.query,
  777. headers: {
  778. //'Content-type' : 'application/xls',
  779. 'Accept': 'application/vnd.ms-excel',
  780. 'X-Auth-Token': $cookieStore.get('Auth-Token') || null
  781. },
  782. responseType: 'arraybuffer'
  783. }).success(function(data, status, headers, config) {
  784. var file = new Blob([data], {
  785. type: 'application/vnd.ms-excel'
  786. });
  787. //trick to download store a file having its URL
  788. var fileURL = URL.createObjectURL(file);
  789. var a = document.createElement('a');
  790. a.href = fileURL;
  791. a.target = '_blank';
  792. a.download = filename + "xls";
  793. document.body.appendChild(a);
  794. a.click();
  795. }).error(function(data, status, headers, config) {
  796. console.log(data);
  797. });
  798. }
  799. // }
  800. /*
  801. if(workspace.query.name!=undefined){
  802. var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
  803. window.location=api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl();
  804. }*/
  805. // if(workspace.query.name!=undefined){
  806. // var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
  807. // //var win = window.open('_blank');
  808. // downFile(api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl(), function(blob){
  809. // var url = URL.createObjectURL(blob);
  810. // window.location = url;
  811. // });
  812. // }
  813. }
  814. function downFile(url, success) {
  815. var xhr = new XMLHttpRequest();
  816. xhr.open('GET', url, true);
  817. xhr.setRequestHeader("X-Auth-Token", $cookieStore.get('Auth-Token'))
  818. xhr.responseType = "blob";
  819. xhr.onreadystatechange = function() {
  820. if (xhr.readyState == 4) {
  821. if (success) success(xhr.response);
  822. }
  823. }
  824. }
  825. $scope.rheaders = [];
  826. $scope.rRows = [];
  827. function executeQuery(mdxquery) {
  828. api_report.execute(mdxquery).then(function(data) {
  829. $scope.rheaders = [];
  830. $scope.rRows = [];
  831. var reportData = Restangular.stripRestangular(data);
  832. //console.log(reportData);
  833. var tableContent = render(reportData);
  834. //console.log(tableContent);
  835. //console.log($scope.rheaders);
  836. })
  837. }
  838. function render(data) {
  839. return internalRenderTable(data);
  840. }
  841. function internalRenderTable(allData) {
  842. var tableContent = "";
  843. var rowContent = "";
  844. var data = allData.cellset;
  845. var table = data ? data : [];
  846. var colSpan;
  847. var colValue;
  848. var isHeaderLowestLvl;
  849. var isBody = false;
  850. var firstColumn;
  851. var isLastColumn, isLastRow;
  852. var nextHeader;
  853. var nextrow;
  854. var processedRowHeader = false;
  855. var lowestRowLvl = 0;
  856. var rowGroups = [];
  857. var batchSize = null;
  858. var batchStarted = false;
  859. var isColHeader = false,
  860. isColHeaderDone = false;
  861. var resultRows = [];
  862. var wrapContent = true;
  863. var colHeaders = [];
  864. var rowHeaders = [];
  865. var rowDatas = [];
  866. var allDatas = [];
  867. // if (options) {
  868. // batchSize = options.hasOwnProperty('batchSize') ? options.batchSize : null;
  869. // wrapContent = options.hasOwnProperty('wrapContent') ? options.wrapContent : true;
  870. // }
  871. var totalsLists = {};
  872. totalsLists[COLUMNS] = allData.rowTotalsLists;
  873. totalsLists[ROWS] = allData.colTotalsLists;
  874. var scanSums = {};
  875. var scanIndexes = {};
  876. var dirs = [ROWS, COLUMNS];
  877. for (var i = 0; i < dirs.length; i++) {
  878. scanSums[dirs[i]] = new Array();
  879. scanIndexes[dirs[i]] = new Array();
  880. }
  881. if (totalsLists[COLUMNS])
  882. for (var i = 0; i < totalsLists[COLUMNS].length; i++) {
  883. scanIndexes[COLUMNS][i] = 0;
  884. scanSums[COLUMNS][i] = totalsLists[COLUMNS][i][scanIndexes[COLUMNS][i]].width;
  885. }
  886. var i = 0;
  887. for (var row = 0, rowLen = table.length; row < rowLen; row++) {
  888. var rowShifted = row - allData.topOffset;
  889. nextrow = 1;
  890. colSpan = 1;
  891. colValue = "";
  892. isHeaderLowestLvl = false;
  893. isLastColumn = false;
  894. isLastRow = false;
  895. isColHeader = false;
  896. var headerSame = false;
  897. if (totalsLists[ROWS])
  898. for (var i = 0; i < totalsLists[ROWS].length; i++) {
  899. scanIndexes[ROWS][i] = 0;
  900. scanSums[ROWS][i] = totalsLists[ROWS][i][scanIndexes[ROWS][i]].width;
  901. }
  902. rowContent = "<tr>";
  903. if (row === 0) {
  904. rowContent = "<thead>" + rowContent;
  905. }
  906. for (var col = 0, colLen = table[row].length; col < colLen; col++) {
  907. var colShifted = col - allData.leftOffset;
  908. var header = data[row][col];
  909. if (header.type === "COLUMN_HEADER") {
  910. isColHeader = true;
  911. }
  912. if (header.type === "ROW_HEADER" && data[row][0]) {
  913. }
  914. // If the cell is a column header and is null (top left of table)
  915. if (header.type === "COLUMN_HEADER" && header.value === "null" && (firstColumn == null || col < firstColumn)) {
  916. rowContent += '<th class="all_null">&nbsp;</th>';
  917. var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0' };
  918. colHeaders.push(headerObject);
  919. } // If the cell is a column header and isn't null (column header of table)
  920. else if (header.type === "COLUMN_HEADER") {
  921. if (firstColumn == null) {
  922. firstColumn = col;
  923. }
  924. if (table[row].length == col + 1)
  925. isLastColumn = true;
  926. else
  927. nextHeader = data[row][col + 1];
  928. // if (table.length == row+1)
  929. // isLastRow = true;
  930. // else
  931. // nextrows = data[row+1][col];
  932. if (isLastColumn) {
  933. // Last column in a row...
  934. if (header.value == "null") {
  935. rowContent += '<th class="col_null">&nbsp;</th>';
  936. var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0' };
  937. colHeaders.push(headerObject);
  938. } else {
  939. if (totalsLists[ROWS])
  940. colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
  941. rowContent += '<th class="col" style="text-align: center;" colspan="' + colSpan + '" title="' + header.value + '">' +
  942. (wrapContent ? '<div rel="' + row + ":" + col + '">' + header.value + '</div>' : header.value) +
  943. '</th>';
  944. var headerObject = { thclass: 'col', colspan: '' + colSpan + '', title: header.value };
  945. if (wrapContent) {
  946. headerObject.value = { rel: row + ":" + col, value: header.value };
  947. } else {
  948. headerObject.value = header.value;
  949. }
  950. colHeaders.push(headerObject);
  951. }
  952. } else {
  953. // All the rest...
  954. var groupChange = (col > 1 && row > 1 && !isHeaderLowestLvl && col > firstColumn) ?
  955. data[row - 1][col + 1].value != data[row - 1][col].value || data[row - 1][col + 1].properties.uniquename != data[row - 1][col].properties.uniquename :
  956. false;
  957. var maxColspan = colSpan > 999 ? true : false;
  958. if (header.value != nextHeader.value || nextParentsDiffer(data, row, col) || isHeaderLowestLvl || groupChange || maxColspan) {
  959. if (header.value == "null") {
  960. rowContent += '<th class="col_null" colspan="' + colSpan + '">&nbsp;</th>';
  961. var headerObject = { thclass: 'col_null', colspan: colSpan, value: "&nbsp;" };
  962. colHeaders.push(headerObject);
  963. } else {
  964. if (totalsLists[ROWS])
  965. colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
  966. rowContent += '<th class="col" style="text-align: center;" colspan="' + (colSpan == 0 ? 1 : colSpan) + '" title="' + header.value + '">' +
  967. (wrapContent ? '<div rel="' + row + ":" + col + '">' + header.value + '</div>' : header.value) +
  968. '</th>';
  969. var headerObject = { thclass: 'col', colspan: (colSpan == 0 ? 1 : colSpan), title: header.value };
  970. if (wrapContent) {
  971. headerObject.value = { rel: row + ":" + col, value: header.value };
  972. } else {
  973. headerObject.value = header.value;
  974. }
  975. colHeaders.push(headerObject);
  976. }
  977. colSpan = 1;
  978. } else {
  979. colSpan++;
  980. }
  981. }
  982. // data[row][3] = {};
  983. if (totalsLists[ROWS])
  984. rowContent += genTotalHeaderCells(col - allData.leftOffset + 1, row + 1, scanSums[ROWS], scanIndexes[ROWS], totalsLists[ROWS], wrapContent);
  985. //TODO
  986. } // If the cell is a row header and is null (grouped row header)
  987. else if (header.type === "ROW_HEADER" && header.value === "null") {
  988. rowContent += '<th class="row_null">&nbsp;</th>';
  989. var headerObject = { thclass: 'row_null', value: header.value };
  990. colHeaders.push();
  991. } // If the cell is a row header and isn't null (last row header)
  992. else if (header.type === "ROW_HEADER") {
  993. if (lowestRowLvl == col)
  994. isHeaderLowestLvl = true;
  995. else
  996. nextHeader = data[row][col + 1];
  997. if (table.length == row + 1)
  998. isLastRow = true;
  999. else
  1000. nextrow = data[row + 1][col];
  1001. var previousRow = data[row - 1];
  1002. var headerObject = {};
  1003. var same = !headerSame && !isHeaderLowestLvl && (col == 0) && header.value === previousRow[col].value;
  1004. headerSame = !same;
  1005. var value = (same ? "<div>&nbsp;</div>" : '<div rel="' + row + ":" + col + '">' + header.value + '</div>');
  1006. if (same) {
  1007. // data[row][3]+=parseInt(data[row][2].value);
  1008. // data[row][3]=String(data[row][3])
  1009. headerObject.value = {
  1010. value: '\u00A0\u00A0'
  1011. }
  1012. } else {
  1013. headerObject.value = {
  1014. value: header.value,
  1015. rel: row + ":" + col
  1016. }
  1017. }
  1018. if (!wrapContent) {
  1019. value = (same ? "&nbsp;" : header.value);
  1020. if (same) {
  1021. headerObject.value = '\u00A0/\u00A0';
  1022. } else {
  1023. headerObject.value = header.value;
  1024. }
  1025. }
  1026. var tipsy = "";
  1027. var cssclass;
  1028. // if(same==true){
  1029. // console.log(header.value)
  1030. // cssclass='row_null';
  1031. // }else if(same==false){
  1032. // cssclass='row';
  1033. // }
  1034. var cssclass = (same ? "row_null" : "row");
  1035. var colspan = 0;
  1036. var rowspan = 0;
  1037. if (!isHeaderLowestLvl && (typeof nextHeader == "undefined" || nextHeader.value === "null")) {
  1038. colspan = 1;
  1039. var group = header.properties.dimension;
  1040. var level = header.properties.level;
  1041. var groupWidth = (group in rowGroups ? rowGroups[group].length - rowGroups[group].indexOf(level) : 1);
  1042. for (var k = col + 1; colspan < groupWidth && k <= (lowestRowLvl + 1) && data[row][k] !== "null"; k++) {
  1043. colspan = k - col;
  1044. // headerObject.colspan=colspan;
  1045. }
  1046. col = col + colspan;
  1047. }
  1048. if (!isLastRow && (data[row + 1][col].value == data[row][col].value)) {
  1049. // rowspan = 1;
  1050. // for (var t = row + 1; rowspan < row && k <= (row+1) && data[t][col] !== "null"; t++) {
  1051. // rowspan = t - row;
  1052. // }
  1053. // row = row + rowspan ;
  1054. // rowspan=rowspan+1;
  1055. // headerObject.rowspan=rowspan;
  1056. }
  1057. rowContent += '<th class="' + cssclass + '" ' + (colspan > 0 ? ' colspan="' + colspan + '"' : "") + (rowspan > 0 ? ' rowspan="' + rowspan + '"' : "") + tipsy + '>' + value + '</th>';
  1058. headerObject.thclass = cssclass;
  1059. if (colspan > 0) {
  1060. // console.log("colspan:" + colspan);
  1061. headerObject.colspan = colspan;
  1062. }
  1063. // console.log("-----");
  1064. // console.log(headerObject);
  1065. rowDatas.push(headerObject);
  1066. } else if (header.type === "ROW_HEADER_HEADER") {
  1067. rowContent += '<th class="row_header">' + (wrapContent ? '<div>' + header.value + '</div>' : header.value) + '</th>';
  1068. var headerObject = { thclass: 'row_header', value: header.value };
  1069. if (wrapContent) {
  1070. headerObject.value = {
  1071. value: header.value
  1072. }
  1073. } else {
  1074. headerObject.value = header.value;
  1075. }
  1076. colHeaders.push(headerObject);
  1077. isHeaderLowestLvl = true;
  1078. processedRowHeader = true;
  1079. lowestRowLvl = col;
  1080. if (header.properties.hasOwnProperty("dimension")) {
  1081. var group = header.properties.dimension;
  1082. if (!(group in rowGroups)) {
  1083. rowGroups[group] = [];
  1084. }
  1085. rowGroups[group].push(header.properties.level);
  1086. }
  1087. } // If the cell is a normal data cell
  1088. else if (header.type === "DATA_CELL") {
  1089. if (header.value == null || header.value == "") {
  1090. header.value = "0";
  1091. }
  1092. batchStarted = true;
  1093. var color = "";
  1094. var val = header.value;
  1095. var arrow = "";
  1096. var rowEntity = {};
  1097. if (header.properties) {
  1098. if (header.properties.hasOwnProperty('image')) {
  1099. var img_height = header.properties.hasOwnProperty('image_height') ? " height='" + header.properties.image_height + "'" : "";
  1100. var img_width = header.properties.hasOwnProperty('image_width') ? " width='" + header.properties.image_width + "'" : "";
  1101. val = "<img " + img_height + " " + img_width + " style='padding-left: 5px' src='" + header.properties.image + "' border='0'>";
  1102. }
  1103. if (header.properties.hasOwnProperty('style')) {
  1104. color = " style='background-color: " + header.properties.style + "' ";
  1105. rowEntity.rowStyle = { 'background-color': header.properties.style };
  1106. }
  1107. if (header.properties.hasOwnProperty('link')) {
  1108. val = "<a target='__blank' href='" + header.properties.link + "'>" + val + "</a>";
  1109. //rowEntity.value=
  1110. }
  1111. if (header.properties.hasOwnProperty('arrow')) {
  1112. arrow = "<img height='10' width='10' style='padding-left: 5px' src='./images/arrow-" + header.properties.arrow + ".gif' border='0'>";
  1113. //rowEntity.arrow=
  1114. }
  1115. } else {
  1116. header.properties = {};
  1117. }
  1118. rowContent += '<td class="data" ' + color + '>' +
  1119. (wrapContent ? '<div class="datadiv" alt="' + header.properties.raw + '" rel="' + header.properties.position + '">' : "") +
  1120. val + arrow +
  1121. (wrapContent ? '</div>' : '') + '</td>';
  1122. if (wrapContent) {
  1123. rowEntity.value = {
  1124. alt: header.properties.raw,
  1125. rel: header.properties.position,
  1126. value: val
  1127. }
  1128. } else {
  1129. rowEntity.value = val;
  1130. }
  1131. rowDatas.push(rowEntity);
  1132. if (totalsLists[ROWS])
  1133. rowContent += genTotalDataCells(colShifted + 1, rowShifted, scanSums[ROWS], scanIndexes[ROWS], totalsLists, wrapContent);
  1134. }
  1135. }
  1136. // console.log(i);
  1137. rowContent += "</tr>";
  1138. // if(colHeaders.length!=0&&colHeaders[0].value.value=="(All)"){colHeaders=colHeaders.splice(1,6)}
  1139. $scope.rheaders.push(colHeaders);
  1140. // $scope.rheaders=$scope.rheaders[0].splice(1,1)
  1141. colHeaders = [];
  1142. if (rowDatas.length > 1) {
  1143. // for(var i=0;i<rowDatas.length;i++){
  1144. // if(rowDatas[i].thclass=="row_null"){
  1145. // rowDatas=rowDatas.splice(1,1)
  1146. // }
  1147. // }
  1148. // if ($scope.reportName == "接听率") {
  1149. // if (rowDatas.length > 2) {
  1150. // i = i + parseInt((rowDatas[rowDatas.length - 1].value.value).replace(",", ""), 10) + parseInt((rowDatas[rowDatas.length - 2].value.value).replace(",", ""), 10);
  1151. // } else {
  1152. // i = i + parseInt((rowDatas[rowDatas.length - 1].value.value).replace(",", ""), 10);
  1153. // }
  1154. // } else {
  1155. i = i + parseInt((rowDatas[rowDatas.length - 1].value.value).replace(",", ""), 10);
  1156. // }
  1157. $scope.rRows.push(rowDatas);
  1158. rowDatas = [];
  1159. }
  1160. // console.log($scope.rRows);
  1161. var totals = "";
  1162. if (totalsLists[COLUMNS] && rowShifted >= 0) {
  1163. totals += genTotalHeaderRowCells(rowShifted + 1, scanSums, scanIndexes, totalsLists, wrapContent);
  1164. }
  1165. if (batchStarted && batchSize) {
  1166. if (row <= batchSize) {
  1167. if (!isColHeader && !isColHeaderDone) {
  1168. tableContent += "</thead><tbody>";
  1169. isColHeaderDone = true;
  1170. }
  1171. tableContent += rowContent;
  1172. if (totals.length > 0) {
  1173. tableContent += totals;
  1174. }
  1175. } else {
  1176. resultRows.push(rowContent);
  1177. if (totals.length > 0) {
  1178. resultRows.push(totals);
  1179. }
  1180. }
  1181. } else {
  1182. if (!isColHeader && !isColHeaderDone) {
  1183. tableContent += "</thead><tbody>";
  1184. isColHeaderDone = true;
  1185. }
  1186. tableContent += rowContent;
  1187. if (totals.length > 0) {
  1188. tableContent += totals;
  1189. }
  1190. }
  1191. }
  1192. //增加事件占比
  1193. var addrowdata = [];
  1194. var addrowdatas = [];
  1195. var sumdata = [];
  1196. addrowdata[0] = { thclass: "row", value: { rel: "1:0", value: "合计" } }
  1197. var c = 0;
  1198. var b = 0;
  1199. for (var j = 0; j < $scope.rRows.length; j++) {
  1200. if ($scope.reportName == "区域地点统计") {
  1201. if ($scope.rRows[j][0].thclass == "row") {
  1202. // $scope.rRows[j][4]
  1203. c = parseInt($scope.rRows[j][2].value.value);
  1204. if (!$scope.rRows[j + 1]) {
  1205. $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c) } }])
  1206. }
  1207. if ($scope.rRows[j + 1] && $scope.rRows[j + 1][0].thclass == "row") {
  1208. $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c) } }])
  1209. }
  1210. } else if ($scope.rRows[j][0].thclass == "row_null") {
  1211. c += parseInt($scope.rRows[j][2].value.value);
  1212. if ($scope.rRows[j + 1] && $scope.rRows[j + 1][0].thclass != "row_null") {
  1213. // $scope.rRows[j].push({value:{value:String(c)}});
  1214. // $scope.rRows.push($scope.rRows)
  1215. $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c) } }]);
  1216. b++;
  1217. } else if (!$scope.rRows[j + 1] && $scope.rRows[j][0].thclass != "row_null") {
  1218. $scope.rRows.splice(j + b + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c) } }])
  1219. } else if (!$scope.rRows[j + 1] && $scope.rRows[j][0].thclass == "row_null") {
  1220. $scope.rRows.splice(j + b + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c) } }])
  1221. } else {
  1222. }
  1223. }
  1224. }
  1225. // if ($scope.reportName == "接听率") {
  1226. // if (rowDatas.length > 1) {
  1227. // i = i + parseInt(rowDatas[rowDatas.length - 1].value.value, 10);
  1228. // }
  1229. // }
  1230. // if ($scope.reportName == "接听率") {
  1231. // if ($scope.rheaders[0].length > 2) {
  1232. // $scope.rRows[j].push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value) + parseInt($scope.rRows[j][$scope.rRows[j].length - 2].value.value))) } });
  1233. // } else {
  1234. // $scope.rRows[j].push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value))) } });
  1235. // }
  1236. // }
  1237. if ($scope.reportName == "报障统计" || $scope.reportName == "录单率统计" || $scope.reportName == "录单率统计") {
  1238. } else if ($scope.reportName == "接听率") {
  1239. $scope.rRows[j].push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value) / parseInt($scope.rRows[j][$scope.rRows[j].length - 2].value.value) * 100).toFixed(2)) + '%' } });
  1240. } else {
  1241. if (i != 0) {
  1242. $scope.rRows[j].push({ value: { value: String((parseInt(($scope.rRows[j][$scope.rRows[j].length - 1].value.value).replace(",", "")) * 100 / i).toFixed(2)) + '%' } })
  1243. } else {
  1244. $scope.rRows[j].push({ value: { value: String((0).toFixed(2)) + '%' } });
  1245. }
  1246. }
  1247. // $scope.rRows[j].push({value:{value:String((parseInt($scope.rRows[j][$scope.rRows[j].length-1].value.value)*100/i).toFixed(2))+'%'}})
  1248. for (var index = 0; index < $scope.rRows[j].length; index++) {
  1249. var match = /^[+-]?\d*\.?\d*$/.test($scope.rRows[j][index].value.value)
  1250. if (match) {
  1251. if (angular.isUndefined(sumdata[index])) {
  1252. sumdata[index] = parseInt(($scope.rRows[j][index].value.value).replace(",", ""))
  1253. } else {
  1254. sumdata[index] = sumdata[index] + parseInt(($scope.rRows[j][index].value.value).replace(",", ""))
  1255. }
  1256. addrowdata[index] = { value: { value: String(sumdata[index]) } };
  1257. }
  1258. }
  1259. }
  1260. if ($scope.reportName == "报障统计" || $scope.reportName == "录单率统计" || $scope.reportName == "录单率统计" || $scope.reportName == "服务台解决率" || $scope.reportName == "接听率") {
  1261. } else {
  1262. addrowdata.push({ value: { value: "100%" } });
  1263. angular.forEach(addrowdata, function(item) {
  1264. if (item) {
  1265. addrowdatas.push(item);
  1266. }
  1267. })
  1268. // if ($scope.reportName == "接听率") {
  1269. // addrowdata.push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value) / parseInt($scope.rRows[j][$scope.rRows[j].length - 2].value.value) * 100).toFixed(2)) + '%' } });
  1270. // angular.forEach(addrowdata, function(item) {
  1271. // if (item) {
  1272. // addrowdatas.push(item);
  1273. // }
  1274. // })
  1275. // }
  1276. }
  1277. if ($scope.reportName == "区域地点统计") {
  1278. addrowdatas.splice(2, 1)
  1279. }
  1280. // if ($scope.reportName == "接听率") {
  1281. // $scope.rheaders[0].push({ colspan: "1", thclass: "col", title: "合计", value: { rel: "0:1", value: "合计" } })
  1282. // }
  1283. if ($scope.reportName == "报障统计" || $scope.reportName == "录单率统计" || $scope.reportName == "录单率统计" || $scope.reportName == "接听率") {
  1284. } else {
  1285. addrowdatas[0] = { thclass: "row", colspan: addrowdata.length - addrowdatas.length + 1, value: { rel: "1:0", value: "总合计" } };
  1286. $scope.rheaders[0].push({ colspan: "1", thclass: "col", title: "占比", value: { rel: "0:1", value: "占比(%)" } })
  1287. }
  1288. // if ($scope.reportName == "接听率") {
  1289. // addrowdata.push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value) / parseInt($scope.rRows[j][$scope.rRows[j].length - 2].value.value) * 100).toFixed(2)) + '%' } });
  1290. // angular.forEach(addrowdata, function(item) {
  1291. // if (item) {
  1292. // addrowdatas.push(item);
  1293. // }
  1294. // })
  1295. // }
  1296. // if($scope.reportName=="区域地点统计"){
  1297. // $scope.rheaders[0].push({colspan:"1",thclass:"col",title:"一级事件总数",value:{rel:"0:1",value:"一级事件总数"}})
  1298. // }
  1299. // var addrowdata=[];
  1300. // var addrowdata=[{thclass:"row",value:{rel:"1:0",value:"合计"}},{value:{alt:String(parseFloat(i)),value:String(i),proption:'100%'}}]
  1301. $scope.rRows.push(addrowdatas);
  1302. var hmainCol = 35 * $scope.rRows.length;
  1303. $scope.allheight = hmainCol + 570;
  1304. return "<table>" + tableContent + "</tbody></table>";
  1305. }
  1306. // $scope.rheaders=$scope.rheaders.splice(1,1)
  1307. function nextParentsDiffer(data, row, col) {
  1308. while (row-- > 0) {
  1309. if (data[row][col].properties.uniquename != data[row][col + 1].properties.uniquename)
  1310. return true;
  1311. }
  1312. return false;
  1313. }
  1314. // $scope.chartType="doughnut";
  1315. // //chart view
  1316. // $scope.chartData = [
  1317. // { value : 50, color : "#F7464A" },
  1318. // { value : 90, color : "#E2EAE9" },
  1319. // { value : 75, color : "#D4CCC5" },
  1320. // { value : 30, color : "#949FB1"}
  1321. // ];
  1322. // $scope.chartOptions = {
  1323. // // Chart.js options can go here.
  1324. // };
  1325. $scope.onChartClick = function(event) {
  1326. console.log(event);
  1327. // _.forIn(data, function(value, key) {
  1328. // var sum = 0;
  1329. // _.forIn(value, function(date, item) {
  1330. // total+=date;
  1331. // sum += date;
  1332. // i++;
  1333. // // dataChart.push({
  1334. // // label:key,
  1335. // // value:sum,
  1336. // // color:randColor() ,
  1337. // // highlight: highlightColor(),
  1338. // // });
  1339. // });
  1340. // dataChart.push({
  1341. // label:key,
  1342. // value:sum,
  1343. // color:randColor() ,
  1344. // highlight: highlightColor(),
  1345. // });
  1346. // });
  1347. };
  1348. var tmpHSV = undefined;
  1349. function randomHSV(hsv) {
  1350. if (angular.isUndefined(hsv)) {
  1351. return {
  1352. h: 0,
  1353. s: 0.75,
  1354. v: 0.8
  1355. };
  1356. } else {
  1357. return {
  1358. h: hsv.h + 51.5,
  1359. s: 0.75,
  1360. v: 0.8
  1361. }
  1362. }
  1363. }
  1364. function HSVToRGB(h, s, v) {
  1365. var i;
  1366. var f, p, q, t;
  1367. var r, g, b;
  1368. if (s == 0) {
  1369. v = Math.floor(v * 255);
  1370. return {
  1371. r: v,
  1372. g: v,
  1373. b: v
  1374. };
  1375. }
  1376. h /= 60;
  1377. i = Math.floor(h);
  1378. f = h - i;
  1379. p = v * (1 - s);
  1380. q = v * (1 - s * f);
  1381. t = v * (1 - s * (1 - f));
  1382. switch (i) {
  1383. case 0:
  1384. r = v;
  1385. g = t;
  1386. b = p;
  1387. break;
  1388. case 1:
  1389. r = q;
  1390. g = v;
  1391. b = p;
  1392. break;
  1393. case 2:
  1394. r = p;
  1395. g = v;
  1396. b = t;
  1397. break;
  1398. case 3:
  1399. r = p;
  1400. g = q;
  1401. b = v;
  1402. break;
  1403. case 4:
  1404. r = t;
  1405. g = p;
  1406. b = v;
  1407. break;
  1408. default:
  1409. r = v;
  1410. g = p;
  1411. b = q;
  1412. break;
  1413. }
  1414. return {
  1415. r: r * 255,
  1416. g: g * 255,
  1417. b: b * 255
  1418. };
  1419. };
  1420. function colorToHex(color) {
  1421. var red = color.r;
  1422. var green = color.g;
  1423. var blue = color.b;
  1424. var rgb = blue | (green << 8) | (red << 16);
  1425. return '#' + rgb.toString(16);
  1426. };
  1427. }]);