reportCtrl-2.js 65 KB

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