1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528 |
- 'use strict';
- 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) {
- // api_reportservice.reportGroup("excutePerson").then(function(response) {
- // if (response.state == 200) {
- // } else {
- // SweetAlert.swal({
- // title: "系统错误",
- // text: "请稍后再试!",
- // type: "error"
- // });
- // }
- // });
- var ROWS = "ROWS";
- var COLUMNS = "COLUMNS";
- $scope.treeshow = true;
- $scope.searchstate = "";
- $scope.headers = "请选择事件树形列表!";
- api_report.getLicenseKey().then(function(response) {
- $cookieStore.put('Auth-Token', response.token);
- $scope.try_async_load();
- });
- var apple_selected, tree, treedata_avm, treedata_geography;
- var workspace = {};
- $scope.parameters = {};
- // $scope.starttimes = {};
- // $scope.endtimes = {};
- $scope.category = {};
- $scope.reportName = "报表";
- $scope.allheight = 100;
- $scope.isMaskground = false;
- // var starttime, endtime
- // $scope.starttimes = moment().startOf('month').format('YYYYMMDD');
- // $scope.endtimes = moment().format('YYYYMMDD');
- $scope.starttimes = moment(new Date().getTime() - 86400000 * 7).format('YYYYMMDD');
- $scope.endtimes = moment(new Date().getTime() - 86400000).format('YYYYMMDD');
- $scope.changeForm = function(paramDateFrom) {
- $scope.starttimes = moment(paramDateFrom).format('YYYYMMDD');
- }
- $scope.changeTo = function(paramDateTo) {
- $scope.endtimes = moment(paramDateTo).format('YYYYMMDD');
- }
- $scope.week = function() {
- $scope.searchstate = "week";
- var weeks = new Date().getDay();
- $scope.starttimes = moment(new Date().getTime() - 86400000 * (weeks + 6)).format('YYYYMMDD');
- $scope.endtimes = moment(new Date().getTime() - 86400000 * (weeks)).format('YYYYMMDD');
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- $scope.parameters = parseDateParameter($scope.parameters);
- $scope.mdxquery();
- }
- $scope.month = function() {
- $scope.searchstate = "month";
- $scope.starttimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth() - 1)).format('YYYYMMDD');
- $scope.endtimes = moment((new Date(moment().startOf('month'))).setMonth((new Date()).getMonth()) - 86400000).format('YYYYMMDD');
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- $scope.parameters = parseDateParameter($scope.parameters);
- $scope.mdxquery();
- }
- $scope.year = function() {
- $scope.searchstate = "year";
- $scope.starttimes = moment().startOf('year').format('YYYYMMDD');
- $scope.endtimes = moment().format('YYYYMMDD');
- $scope.parameters.paramDateFrom = $scope.starttimes;
- $scope.parameters.paramDateTo = $scope.endtimes;
- $scope.parameters = parseDateParameter($scope.parameters);
- $scope.mdxquery();
- }
- $scope.my_tree_handler = function(branch) {
- $scope.isMaskground = true;
- $scope.treeshow = false;
- if (branch.type == 'FILE') {
- console.log(branch);
- $scope.reportName = branch.label;
- var path = $scope.mdxpath = branch.path;
- queryUUID = genUUID();
- api_report.getMdx(path, queryUUID).then(function(response) {
- var mdxquery = Restangular.stripRestangular(response);
- workspace.query = mdxquery;
- $scope.shows = false;
- $scope.isMaskground = false;
- workspace.query.parameters.paramDateFrom = $scope.starttimes;
- workspace.query.parameters.paramDateTo = $scope.endtimes;
- $scope.parameters = parseDateParameter(workspace.query.parameters);
- if (workspace.query.parameters.reportUUID) {
- $scope.rptUUID = workspace.query.parameters.reportUUID;
- delete workspace.query.parameters.reportUUID;
- $scope.parameters = parseDateParameter(workspace.query.parameters);
- api_statistic.query(workspace.query.parameters, $scope.rptUUID).then(function(data) {
- $scope.rheaders = [];
- $scope.rRows = [];
- var reportData = Restangular.stripRestangular(data);
- if (reportData.cellset.length < 2) {
- reportData.cellset = null;
- $scope.shows = true;
- $scope.empty = "数据为空!"
- }
- var tableContent = render(reportData);
- })
- } else {
- $scope.rptUUID = undefined;
- api_report.execute(mdxquery).then(function(data) {
- $scope.rheaders = [];
- $scope.rRows = [];
- var reportData = Restangular.stripRestangular(data);
- // if($scope.reportName=="事件工作回顾"&&reportData.cellset.length<4){
- // reportData.cellset=null;
- // }
- // if($scope.reportName=="事件解决率统计"&&reportData.cellset.length<4){
- // reportData.cellset=null;
- // }
- if (reportData.cellset == null || reportData.cellset.length == 0) {
- $scope.shows = true;
- $scope.empty = "数据为空!"
- }
- //console.log(reportData);
- var tableContent = render(reportData);
- renderChart(reportData);
- //console.log(tableContent);
- //console.log($scope.rheaders);
- })
- }
- //http://localhost:9008/api/statistic/unidimensional/d75e22c1-7f60-4e22-affd-23742a475407
- });
- }
- }
- $scope.my_data = [];
- $scope.my_tree = tree = {};
- $scope.try_async_load = function() {
- $scope.my_data = [];
- $scope.select_treedata = [];
- api_report.list().then(function(response) {
- var dataList = Restangular.stripRestangular(response);
- getRepoRoot(dataList, '/homes/home:admin/ITSM报表');
- $scope.repoRoot.name = "模块选择"
- convertRepoObject($scope.repoRoot);
- $scope.my_data.push($scope.repoRoot);
- });
- };
- $scope.repoRoot = null;
- function getRepoRoot(repo, path) {
- angular.forEach(repo, function(value, key) {
- if (value.path == path) {
- $scope.repoRoot = value;
- } else {
- if ($scope.repoRoot == null && angular.isDefined(value.repoObjects)) {
- getRepoRoot(value.repoObjects, path);
- } else {
- }
- }
- });
- }
- function convertRepoObject(repo) {
- if (angular.isArray(repo)) {
- angular.forEach(repo, function(value, key) {
- convertRepoObject(value);
- })
- } else {
- if (angular.isDefined(repo.name)) {
- if (repo.name.indexOf(".") >= 0) {
- repo.label = repo.name.substr(0, repo.name.lastIndexOf("."));
- } else {
- repo.label = repo.name;
- }
- //delete repo.name;
- }
- if (angular.isDefined(repo.repoObjects)) {
- repo.children = [];
- repo.children = repo.repoObjects;
- delete repo.repoObjects;
- convertRepoObject(repo.children);
- }
- }
- }
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- var parentNode = null;
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- if (typeof datum.parent === "undefined" || datum.parent == null) {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent.id];
- //We don't need this property, so let's delete it.
- delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function(item) {
- list.push(item);
- });
- return list;
- }
- function parseDateParameter(parameters) {
- var result = undefined;
- if (angular.isArray(parameters)) {
- // angular.forEach(parmeters,function(param){
- // param.
- // })
- } else {
- result = {};
- for (var k in parameters) {
- if (k.indexOf("Date") > 0) {
- if (angular.isString(parameters[k])) {
- result[k] = moment(parameters[k], "YYYYMMDD").format("YYYY-MM-DD");
- //result[k] = ''+parameters[k]+'';//= moment(parameters[k], "YYYYMMDD").toDate();
- }
- }
- }
- }
- return result;
- }
- function ConvertDateParameter(parameters) {
- var result = undefined;
- if (angular.isArray(parameters)) {
- //
- } else {
- result = {};
- for (var k in parameters) {
- if (k.indexOf("Date") > 0) {
- if (angular.isDate(parameters[k])) {
- result[k] = moment(parameters[k]).format("YYYYMMDD");
- } else if (angular.isString(parameters[k])) {
- result[k] = parameters[k];
- }
- }
- }
- }
- return result;
- }
- $scope.open = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.opened = !$scope.opened;
- };
- $scope.endOpen = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.startOpened = false;
- $scope.endOpened = !$scope.endOpened;
- };
- $scope.startOpen = function($event) {
- $event.preventDefault();
- $event.stopPropagation();
- $scope.endOpened = false;
- $scope.startOpened = !$scope.startOpened;
- };
- $scope.mdxquery = function(key) {
- $scope.isMaskground = true;
- if (key && key == 'all') {
- $scope.searchstate = "";
- }
- $scope.shows = false;
- if (angular.isDefined(workspace.query)) {
- if ($scope.rptUUID) {
- workspace.query.parameters = ConvertDateParameter($scope.parameters);
- workspace.query.parameters.paramDateFrom = workspace.query.parameters.paramDateFrom.replace(/-/g, "");
- workspace.query.parameters.paramDateTo = workspace.query.parameters.paramDateTo.replace(/-/g, "");
- $scope.starttimes = workspace.query.parameters.paramDateFrom;
- $scope.endtimes = workspace.query.parameters.paramDateTo;
- api_statistic.query(workspace.query.parameters, $scope.rptUUID).then(function(data) {
- $scope.rheaders = [];
- $scope.rRows = [];
- $scope.isMaskground = false;
- var reportData = Restangular.stripRestangular(data);
- if (reportData.cellset.length < 2) {
- reportData.cellset = null;
- $scope.shows = true;
- $scope.empty = "数据为空!"
- }
- var tableContent = render(reportData);
- })
- } else {
- $scope.rptUUID = undefined;
- workspace.query.parameters = ConvertDateParameter($scope.parameters);
- if (angular.isDefined($scope.parameters.paramDateFrom) && angular.isDefined($scope.parameters.paramDateTo)) {
- workspace.query.parameters.paramDateFrom = workspace.query.parameters.paramDateFrom.replace(/-/g, "");
- workspace.query.parameters.paramDateTo = workspace.query.parameters.paramDateTo.replace(/-/g, "");
- // workspace.query.parameters=ConvertDateParameter($scope.parameters);
- // workspace.query.parameters.categorys=categorys;
- $scope.starttimes = workspace.query.parameters.paramDateFrom;
- $scope.endtimes = workspace.query.parameters.paramDateTo;
- api_report.execute(workspace.query).then(function(data) {
- $scope.isMaskground = false;
- $scope.rheaders = [];
- $scope.rRows = [];
- var reportData = Restangular.stripRestangular(data);
- if (reportData.cellset == null || reportData.cellset.length == 0) {
- $scope.shows = true;
- $scope.empty = "数据为空!"
- }
- console.log(reportData);
- var tableContent =
- render(reportData);
- renderChart(reportData);
- console.log($scope.rheaders);
- })
- }
- }
- }
- }
- $scope.execute = function() {
- api_report.list($scope.token).then(function(response) {
- $scope.select_treedata = $scope.my_data = response;
- });
- }
- $scope.searchOptions = function() {
- if (angular.isDefined(workspace.query)) {
- var queryParameters = workspace.query.parameters;
- for (var parm in queryParameters) {
- if (parm == 'Week') {
- } else {
- }
- }
- }
- }
- $scope.activeParentGroup = false;
- $scope.disabledParentGroup = false;
- $scope.toggleParentGroup = function() {
- if (workspace.query) {
- // if($scope.activeParentGroup){
- // workspace.query.properties['saiku.olap.result.formatter']='flat';
- // $scope.activeParentGroup=!$scope.activeParentGroup;
- // }else{
- workspace.query.properties['saiku.olap.result.formatter'] = 'flattened';
- // $scope.activeParentGroup=!$scope.activeParentGroup;
- // }
- //console.log(workspace.query);
- executeQuery(workspace.query);
- }
- }
- var process_data_tree = function(args, flat, setdata) {
- var self = this;
- var data = {};
- if (flat) {
- data.resultset = [];
- data.metadata = [];
- data.height = 0;
- data.width = 0;
- }
- var currentDataPos = data;
- if (typeof args == "undefined" || typeof args.data == "undefined") {
- return;
- }
- if (args.data !== null && args.data.error !== null) {
- return;
- }
- // Check to see if there is data
- if (args.data === null || (args.data.cellset && args.data.cellset.length === 0)) {
- return;
- }
- var cellset = args.data.cellset;
- if (cellset && cellset.length > 0) {
- var lowest_level = 0;
- var data_start = 0;
- var hasStart = false;
- var row,
- rowLen,
- labelCol,
- reduceFunction = function(memo, num) {
- return memo + num;
- };
- for (row = 0, rowLen = cellset.length; data_start === 0 && row < rowLen; row++) {
- for (var field = 0, fieldLen = cellset[row].length; field < fieldLen; field++) {
- if (!hasStart) {
- while (cellset[row][field].type == "COLUMN_HEADER" && cellset[row][field].value == "null") {
- row++;
- }
- }
- hasStart = true;
- if (cellset[row][field].type == "ROW_HEADER_HEADER") {
- while (cellset[row][field].type == "ROW_HEADER_HEADER") {
- if (flat) {
- data.metadata.push({
- colIndex: field,
- colType: "String",
- colName: cellset[row][field].value
- });
- }
- field++;
- }
- lowest_level = field - 1;
- }
- if (cellset[row][field].type == "COLUMN_HEADER") {
- var lowest_col_header = 0;
- var colheader = [];
- while (lowest_col_header <= row) {
- if (cellset[lowest_col_header][field].value !== "null") {
- colheader.push(cellset[lowest_col_header][field].value);
- }
- lowest_col_header++;
- }
- if (flat) {
- data.metadata.push({
- colIndex: field,
- colType: "Numeric",
- colName: colheader.join(' ~ ')
- });
- }
- data_start = row + 1;
- }
- }
- }
- var labelsSet = {};
- var rowlabels = [];
- for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
- rowlabels.push(null);
- }
- for (row = data_start, rowLen = cellset.length; row < rowLen; row++) {
- if (cellset[row][0].value !== "") {
- var record = [];
- var flatrecord = [];
- var parent = null;
- var rv = null;
- for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
- if (cellset[row] && cellset[row][labelCol].value === 'null') {
- currentDataPos = data;
- var prevLabel = 0;
- for (; prevLabel < lowest_level && cellset[row][prevLabel].value === 'null'; prevLabel++) {
- currentDataPos = currentDataPos[rowlabels[prevLabel]];
- }
- if (prevLabel > labelCol) {
- labelCol = prevLabel;
- }
- }
- if (cellset[row] && cellset[row][labelCol].value !== 'null') {
- if (labelCol === 0) {
- for (var xx = 0; xx <= lowest_level; xx++) {
- rowlabels[xx] = null;
- }
- }
- if (typeof currentDataPos == "number") {
- parent[rv] = {};
- currentDataPos = parent[rv];
- }
- rv = cellset[row][labelCol].value;
- rowlabels[labelCol] = rv;
- if (!currentDataPos.hasOwnProperty(rv)) {
- currentDataPos[rv] = {};
- }
- parent = currentDataPos;
- currentDataPos = currentDataPos[rv];
- }
- }
- flatrecord = _.clone(rowlabels);
- for (var col = lowest_level + 1, colLen = cellset[row].length; col < colLen; col++) {
- var cell = cellset[row][col];
- var value = cell.value || 0;
- var maybePercentage = (value !== 0);
- // check if the resultset contains the raw value, if not try to parse the given value
- var raw = cell.properties.raw;
- if (raw && raw !== "null") {
- value = parseFloat(raw);
- } else if (typeof(cell.value) !== "number" && parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''))) {
- value = parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''));
- maybePercentage = false;
- }
- if (value > 0 && maybePercentage) {
- value = cell.value && cell.value.indexOf('%') >= 0 ? value * 100 : value;
- }
- record.push(value);
- flatrecord.push({ f: cell.value, v: value });
- }
- if (flat) data.resultset.push(flatrecord);
- var sum = _.reduce(record, reduceFunction, 0);
- rv = (rv === null ? "null" : rv);
- parent[rv] = sum;
- currentDataPos = data;
- }
- }
- if (setdata) {
- self.rawdata = args.data;
- self.data = data;
- self.hasProcessed = true;
- self.data.height = self.data.resultset.length;
- }
- return data;
- } else {
- //no result
- //$(self.el).find('.canvas_wrapper').text("No results").show();
- }
- };
- //图
- function randColor() {
- tmpHSV = randomHSV(tmpHSV);
- return colorToHex(HSVToRGB(tmpHSV.h, tmpHSV.s, tmpHSV.v));
- // console.log()
- };
- function highlightColor() {
- var highlight = {
- h: tmpHSV.h + 5.5,
- s: 0.55,
- v: 0.5
- };
- return colorToHex(HSVToRGB(highlight.h, highlight.s, highlight.v));
- }
- var renderChart = function(reportData) {
- var data = process_data_tree({ data: reportData });
- var _ = window._;
- var dataChart = undefined;
- $scope.chartData = [];
- // tmpHSV=undefined;
- if (workspace.query) {
- if (workspace.query.properties['saiku.ui.render.type'] == "sunburst") {
- $scope.chartType = "pie";
- dataChart = [];
- var total = 0;
- var i = 0;
- _.forIn(data, function(value, key) {
- total += value;
- i++;
- dataChart.push({
- label: key,
- value: value,
- color: randColor()
- });
- });
- // function randColor(){
- // if(i%4==1){return '#01A2D9'}
- // else if(i%4==2){return '#71BBDE'}
- // else if(i%4==3){return '#FF9122'}
- // else if(i%4==0){return '#F8B705'}
- // }
- // console.log(total);
- // for(var i=0;i<dataChart.length;i++){
- // dataChart[i].value=dataChart[i].value*100/total
- // dataChart[i].value=dataChart[i].value.toFixed(2);
- // }
- $scope.chartData = dataChart;
- $scope.chartOptions = {
- // responsive: true,
- // //Boolean - Whether we should show a stroke on each segment
- segmentShowStroke: true,
- // //String - The colour of each segment stroke
- // segmentStrokeColor : '#fff',
- // //Number - The width of each segment stroke
- segmentStrokeWidth: 2,
- // //Number - The percentage of the chart that we cut out of the middle
- // percentageInnerCutout : 0, // This is 0 for Pie charts
- // //Number - Amount of animation steps
- // animationSteps : 100,
- // //String - Animation easing effect
- // animationEasing : 'easeOutBounce',
- // //Boolean - Whether we animate the rotation of the Doughnut
- // animateRotate : true,
- // //Boolean - Whether we animate scaling the Doughnut from the centre
- // animateScale : false,
- // //String - A legend template
- 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>',
- //showTooltips:false,
- //tooltipEvents:[],
- onAnimationComplete: function() {
- this.showTooltip(this.segments, true);
- console.log(this.segments)
- }
- };
- } else if (workspace.query.properties['saiku.ui.render.type'] == "stackedBar") {
- // $scope.chartType="bar";
- // dataChart = {};
- // var labels=[];
- // var barData =[];
- // _.forIn(data, function(value, key) {
- // labels.push(key);
- // barData.push(value);
- // });
- // dataChart={
- // labels:labels,
- // datasets:[]
- // };
- // dataChart.datasets.push({
- // //label:'事件数',
- // fillColor: '#0E7EC5',
- // strokeColor: 'rgba(220,220,220,0.8)',
- // highlightFill: 'rgba(220,220,220,0.75)',
- // highlightStroke: 'rgba(220,220,220,1)',
- // data:barData
- // });
- // $scope.chartData = dataChart;
- // $scope.chartOptions = {};
- // }else if(workspace.query.properties['saiku.ui.render.type']=="pie"){
- // $scope.chartType="doughnut";
- // $scope.series=[];
- // dataChart = [];
- // var i=0;
- // var chart=[];
- // // $scope.firstchart=false;
- // // $scope.secondchart=false;
- // var chartcanvas=function(canvansdata){
- // _.forIn(canvansdata, function(value, key) {
- // var sum = 0;
- // if(typeof(value)=='object'){
- // _.forIn(value, function(date, item) {
- // sum += date;
- // });
- // }else{
- // sum = value;
- // }
- // dataChart.push({
- // indexLabel:key,
- // y:sum,
- // color:randColor() ,
- // highlight: highlightColor(),
- // });
- // });
- // // $scope.chartData = dataChart;
- // chart = new CanvasJS.Chart("chartContainer"+[i],{
- // theme: "theme2",
- // title:{
- // text: $scope.reportName
- // },
- // data: [{
- // type: "pie",
- // showInLegend: true,
- // toolTipContent: "{indexLabel} - #percent %",
- // yValueFormatString: "",
- // legendText: "{indexLabel}",
- // dataPoints: dataChart
- // }],
- // plotOptions: {
- // series: {
- // cursor: 'pointer',
- // events: {
- // click: function(e) {
- // _.forIn(canvansdata, function(value, key) {
- // if(key==e.dataPoint.indexLabel&&typeof(value)=='object'){
- // dataChart=[];
- // i++;
- // chartcanvas(value);
- // }
- // });
- // }
- // }
- // }
- // },
- // });
- // chart.render();
- // // i++;
- // }
- // chartcanvas(data);
- }
- //"line"
- //"bar"
- //"radar"
- //"polararea"
- //"pie"
- //"doughnut"
- }
- }
- var queryUUID;
- function genUUID() {
- var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
- function(c) {
- var r = Math.random() * 16 | 0,
- v = c == 'x' ? r : (r & 0x3 | 0x8);
- return v.toString(16);
- }).toUpperCase();
- return uuid;
- }
- function exportMdxBefore(path, uuid, callback) {
- var rdata = 'file=' + path + '&formatter=flattened&language=zh';
- $http({
- url: api_report.queryMdxUri(uuid).getRequestedUrl(),
- method: 'POST',
- data: rdata,
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'X-Auth-Token': $cookieStore.get('Auth-Token') || null
- }
- }).success(function(data, status, headers, config) {
- if (status == 200) {
- if (callback) {
- callback(data.name, path);
- }
- }
- //console.log(status);
- //console.log(data);
- });
- }
- $scope.getRelativePosition = function(eve) {
- console.log(eve)
- }
- $scope.getPointPosition = function(eve) {
- console.log("31231")
- }
- $scope.exportData = function(uuid) {
- //var url=api_report.exportData($scope.mdxpath).getRequestedUrl();
- if (!uuid && queryUUID) {
- uuid = queryUUID;
- }
- var name = $scope.mdxpath;
- // if(workspace.query.name!=undefined){
- // exportMdxBefore(name,uuid, function(queryName,path){
- // var filename = path.substring(path.lastIndexOf('/')+1).slice(0, -5);
- // $http({
- // url : api_report.exportData('flat', queryName, encodeURIComponent(filename)).getRequestedUrl(),
- // method : 'GET',
- // params : {},
- // headers : {
- // //'Content-type' : 'application/xls',
- // 'Accept': 'application/vnd.ms-excel',
- // 'X-Auth-Token' : $cookieStore.get('Auth-Token')||null
- // },
- // responseType : 'arraybuffer'
- // }).success(function(data, status, headers, config) {
- // var file = new Blob([ data ], {
- // type : 'application/vnd.ms-excel'
- // });
- // //trick to download store a file having its URL
- // var fileURL = URL.createObjectURL(file);
- // var a = document.createElement('a');
- // a.href = fileURL;
- // a.target = '_blank';
- // a.download = filename+"xls";
- // document.body.appendChild(a);
- // a.click();
- // }).error(function(data, status, headers, config) {
- // console.log(data);
- // });
- // });
- // }
- // return;
- //return url;
- if (workspace.query.name != undefined) {
- var filename = name.substring(name.lastIndexOf('/') + 1).slice(0, -5);
- // if(filename=="事件详细资料."){
- // // api_statistic.unidimensionalExport(workspace.query.parameters,$scope.rptUUID).then(function(data){
- // // var file = new Blob([ data ], {
- // // type : 'application/vnd.ms-excel;charset=utf-8;'
- // // });
- // // //trick to download store a file having its URL
- // // var fileURL = URL.createObjectURL(file);
- // // var a = document.createElement('a');
- // // a.href = fileURL;
- // // a.target = '_blank';
- // // a.download = filename+"xls";
- // // document.body.appendChild(a);
- // // a.click();
- // // })
- // $http({
- // url : api_statistic.unidimensionalExport($scope.rptUUID).getRequestedUrl(),
- // method : 'POST',
- // data : workspace.query.parameters,
- // headers : {
- // //'Content-type' : 'application/xls',
- // 'Accept': '*/*'
- // },
- // responseType : 'arraybuffer'
- // }).success(function(data, status, headers, config) {
- // var file = new Blob([ data ], {
- // type : 'application/vnd.ms-excel'
- // });
- // //trick to download store a file having its URL
- // var fileURL = URL.createObjectURL(file);
- // var a = document.createElement('a');
- // a.href = fileURL;
- // a.target = '_blank';
- // a.download = filename+"xls";
- // document.body.appendChild(a);
- // a.click();
- // }).error(function(data, status, headers, config) {
- // console.log(data);
- // });
- // }else{
- $http({
- url: api_report.exportData('flat', uuid, encodeURIComponent(filename)).getRequestedUrl(),
- method: 'POST',
- data: workspace.query,
- headers: {
- //'Content-type' : 'application/xls',
- 'Accept': 'application/vnd.ms-excel',
- 'X-Auth-Token': $cookieStore.get('Auth-Token') || null
- },
- responseType: 'arraybuffer'
- }).success(function(data, status, headers, config) {
- var file = new Blob([data], {
- type: 'application/vnd.ms-excel'
- });
- //trick to download store a file having its URL
- var fileURL = URL.createObjectURL(file);
- var a = document.createElement('a');
- a.href = fileURL;
- a.target = '_blank';
- a.download = filename + "xls";
- document.body.appendChild(a);
- a.click();
- }).error(function(data, status, headers, config) {
- console.log(data);
- });
- }
- // }
- /*
- if(workspace.query.name!=undefined){
- var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
- window.location=api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl();
- }*/
- // if(workspace.query.name!=undefined){
- // var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
- // //var win = window.open('_blank');
- // downFile(api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl(), function(blob){
- // var url = URL.createObjectURL(blob);
- // window.location = url;
- // });
- // }
- }
- function downFile(url, success) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.setRequestHeader("X-Auth-Token", $cookieStore.get('Auth-Token'))
- xhr.responseType = "blob";
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- if (success) success(xhr.response);
- }
- }
- }
- $scope.rheaders = [];
- $scope.rRows = [];
- function executeQuery(mdxquery) {
- api_report.execute(mdxquery).then(function(data) {
- $scope.rheaders = [];
- $scope.rRows = [];
- var reportData = Restangular.stripRestangular(data);
- //console.log(reportData);
- var tableContent = render(reportData);
- //console.log(tableContent);
- //console.log($scope.rheaders);
- })
- }
- function render(data) {
- return internalRenderTable(data);
- }
- function internalRenderTable(allData) {
- var tableContent = "";
- var rowContent = "";
- var data = allData.cellset;
- var table = data ? data : [];
- var colSpan;
- var colValue;
- var isHeaderLowestLvl;
- var isBody = false;
- var firstColumn;
- var isLastColumn, isLastRow;
- var nextHeader;
- var nextrow;
- var processedRowHeader = false;
- var lowestRowLvl = 0;
- var rowGroups = [];
- var batchSize = null;
- var batchStarted = false;
- var isColHeader = false,
- isColHeaderDone = false;
- var resultRows = [];
- var wrapContent = true;
- var colHeaders = [];
- var rowHeaders = [];
- var rowDatas = [];
- var allDatas = [];
- // if (options) {
- // batchSize = options.hasOwnProperty('batchSize') ? options.batchSize : null;
- // wrapContent = options.hasOwnProperty('wrapContent') ? options.wrapContent : true;
- // }
- var totalsLists = {};
- totalsLists[COLUMNS] = allData.rowTotalsLists;
- totalsLists[ROWS] = allData.colTotalsLists;
- var scanSums = {};
- var scanIndexes = {};
- var dirs = [ROWS, COLUMNS];
- for (var i = 0; i < dirs.length; i++) {
- scanSums[dirs[i]] = new Array();
- scanIndexes[dirs[i]] = new Array();
- }
- if (totalsLists[COLUMNS])
- for (var i = 0; i < totalsLists[COLUMNS].length; i++) {
- scanIndexes[COLUMNS][i] = 0;
- scanSums[COLUMNS][i] = totalsLists[COLUMNS][i][scanIndexes[COLUMNS][i]].width;
- }
- var i = 0;
- for (var row = 0, rowLen = table.length; row < rowLen; row++) {
- var rowShifted = row - allData.topOffset;
- nextrow = 1;
- colSpan = 1;
- colValue = "";
- isHeaderLowestLvl = false;
- isLastColumn = false;
- isLastRow = false;
- isColHeader = false;
- var headerSame = false;
- if (totalsLists[ROWS])
- for (var i = 0; i < totalsLists[ROWS].length; i++) {
- scanIndexes[ROWS][i] = 0;
- scanSums[ROWS][i] = totalsLists[ROWS][i][scanIndexes[ROWS][i]].width;
- }
- rowContent = "<tr>";
- if (row === 0) {
- rowContent = "<thead>" + rowContent;
- }
- for (var col = 0, colLen = table[row].length; col < colLen; col++) {
- var colShifted = col - allData.leftOffset;
- var header = data[row][col];
- if (header.type === "COLUMN_HEADER") {
- isColHeader = true;
- }
- if (header.type === "ROW_HEADER" && data[row][0]) {
- }
- // If the cell is a column header and is null (top left of table)
- if (header.type === "COLUMN_HEADER" && header.value === "null" && (firstColumn == null || col < firstColumn)) {
- rowContent += '<th class="all_null"> </th>';
- var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0' };
- colHeaders.push(headerObject);
- } // If the cell is a column header and isn't null (column header of table)
- else if (header.type === "COLUMN_HEADER") {
- if (firstColumn == null) {
- firstColumn = col;
- }
- if (table[row].length == col + 1)
- isLastColumn = true;
- else
- nextHeader = data[row][col + 1];
- // if (table.length == row+1)
- // isLastRow = true;
- // else
- // nextrows = data[row+1][col];
- if (isLastColumn) {
- // Last column in a row...
- if (header.value == "null") {
- rowContent += '<th class="col_null"> </th>';
- var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0' };
- colHeaders.push(headerObject);
- } else {
- if (totalsLists[ROWS])
- colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
- rowContent += '<th class="col" style="text-align: center;" colspan="' + colSpan + '" title="' + header.value + '">' +
- (wrapContent ? '<div rel="' + row + ":" + col + '">' + header.value + '</div>' : header.value) +
- '</th>';
- var headerObject = { thclass: 'col', colspan: '' + colSpan + '', title: header.value };
- if (wrapContent) {
- headerObject.value = { rel: row + ":" + col, value: header.value };
- } else {
- headerObject.value = header.value;
- }
- colHeaders.push(headerObject);
- }
- } else {
- // All the rest...
- var groupChange = (col > 1 && row > 1 && !isHeaderLowestLvl && col > firstColumn) ?
- data[row - 1][col + 1].value != data[row - 1][col].value || data[row - 1][col + 1].properties.uniquename != data[row - 1][col].properties.uniquename :
- false;
- var maxColspan = colSpan > 999 ? true : false;
- // if (header.value != nextHeader.value || nextParentsDiffer(data, row, col) || isHeaderLowestLvl || groupChange || maxColspan) {
- // if (header.value == "null") {
- // rowContent += '<th class="col_null" colspan="' + colSpan + '"> </th>';
- // var headerObject = { thclass: 'col_null', colspan: colSpan, value: " " };
- // colHeaders.push(headerObject);
- // } else {
- // if (totalsLists[ROWS])
- // colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
- // rowContent += '<th class="col" style="text-align: center;" colspan="' + (colSpan == 0 ? 1 : colSpan) + '" title="' + header.value + '">' +
- // (wrapContent ? '<div rel="' + row + ":" + col + '">' + header.value + '</div>' : header.value) +
- // '</th>';
- // var headerObject = { thclass: 'col', colspan: (colSpan == 0 ? 1 : colSpan), title: header.value };
- // if (wrapContent) {
- // headerObject.value = { rel: row + ":" + col, value: header.value };
- // } else {
- // headerObject.value = header.value;
- // }
- // colHeaders.push(headerObject);
- // }
- // colSpan = 1;
- // } else {
- // colSpan++;
- // }
- }
- data[row][3] = {};
- if (totalsLists[ROWS])
- rowContent += genTotalHeaderCells(col - allData.leftOffset + 1, row + 1, scanSums[ROWS], scanIndexes[ROWS], totalsLists[ROWS], wrapContent);
- //TODO
- } // If the cell is a row header and is null (grouped row header)
- else if (header.type === "ROW_HEADER" && header.value === "null") {
- rowContent += '<th class="row_null"> </th>';
- var headerObject = { thclass: 'row_null', value: header.value };
- colHeaders.push();
- } // If the cell is a row header and isn't null (last row header)
- else if (header.type === "ROW_HEADER") {
- if (lowestRowLvl == col)
- isHeaderLowestLvl = true;
- else
- nextHeader = data[row][col + 1];
- if (table.length == row + 1)
- isLastRow = true;
- else
- nextrow = data[row + 1][col];
- var previousRow = data[row - 1];
- var headerObject = {};
- var same = !headerSame && !isHeaderLowestLvl && (col == 0) && header.value === previousRow[col].value;
- headerSame = !same;
- var value = (same ? "<div> </div>" : '<div rel="' + row + ":" + col + '">' + header.value + '</div>');
- if (same) {
- // data[row][3]+=parseInt(data[row][2].value);
- // data[row][3]=String(data[row][3])
- headerObject.value = {
- value: '\u00A0\u00A0'
- }
- } else {
- headerObject.value = {
- value: header.value,
- rel: row + ":" + col
- }
- }
- if (!wrapContent) {
- value = (same ? " " : header.value);
- if (same) {
- headerObject.value = '\u00A0/\u00A0';
- } else {
- headerObject.value = header.value;
- }
- }
- var tipsy = "";
- var cssclass;
- // if(same==true){
- // console.log(header.value)
- // cssclass='row_null';
- // }else if(same==false){
- // cssclass='row';
- // }
- var cssclass = (same ? "row_null" : "row");
- var colspan = 0;
- var rowspan = 0;
- if (!isHeaderLowestLvl && (typeof nextHeader == "undefined" || nextHeader.value === "null")) {
- colspan = 1;
- var group = header.properties.dimension;
- var level = header.properties.level;
- var groupWidth = (group in rowGroups ? rowGroups[group].length - rowGroups[group].indexOf(level) : 1);
- for (var k = col + 1; colspan < groupWidth && k <= (lowestRowLvl + 1) && data[row][k] !== "null"; k++) {
- colspan = k - col;
- // headerObject.colspan=colspan;
- }
- col = col + colspan;
- }
- if (!isLastRow && (data[row + 1][col].value == data[row][col].value)) {
- // rowspan = 1;
- // for (var t = row + 1; rowspan < row && k <= (row+1) && data[t][col] !== "null"; t++) {
- // rowspan = t - row;
- // }
- // row = row + rowspan ;
- // rowspan=rowspan+1;
- // headerObject.rowspan=rowspan;
- }
- rowContent += '<th class="' + cssclass + '" ' + (colspan > 0 ? ' colspan="' + colspan + '"' : "") + (rowspan > 0 ? ' rowspan="' + rowspan + '"' : "") + tipsy + '>' + value + '</th>';
- headerObject.thclass = cssclass;
- if (colspan > 0) {
- // console.log("colspan:" + colspan);
- headerObject.colspan = colspan;
- }
- // console.log("-----");
- // console.log(headerObject);
- rowDatas.push(headerObject);
- } else if (header.type === "ROW_HEADER_HEADER") {
- rowContent += '<th class="row_header">' + (wrapContent ? '<div>' + header.value + '</div>' : header.value) + '</th>';
- var headerObject = { thclass: 'row_header', value: header.value };
- if (wrapContent) {
- headerObject.value = {
- value: header.value
- }
- } else {
- headerObject.value = header.value;
- }
- colHeaders.push(headerObject);
- isHeaderLowestLvl = true;
- processedRowHeader = true;
- lowestRowLvl = col;
- if (header.properties.hasOwnProperty("dimension")) {
- var group = header.properties.dimension;
- if (!(group in rowGroups)) {
- rowGroups[group] = [];
- }
- rowGroups[group].push(header.properties.level);
- }
- } // If the cell is a normal data cell
- else if (header.type === "DATA_CELL") {
- if (header.value == null || header.value == "") {
- header.value = "0";
- }
- batchStarted = true;
- var color = "";
- var val = header.value;
- var arrow = "";
- var rowEntity = {};
- if (header.properties) {
- if (header.properties.hasOwnProperty('image')) {
- var img_height = header.properties.hasOwnProperty('image_height') ? " height='" + header.properties.image_height + "'" : "";
- var img_width = header.properties.hasOwnProperty('image_width') ? " width='" + header.properties.image_width + "'" : "";
- val = "<img " + img_height + " " + img_width + " style='padding-left: 5px' src='" + header.properties.image + "' border='0'>";
- }
- if (header.properties.hasOwnProperty('style')) {
- color = " style='background-color: " + header.properties.style + "' ";
- rowEntity.rowStyle = { 'background-color': header.properties.style };
- }
- if (header.properties.hasOwnProperty('link')) {
- val = "<a target='__blank' href='" + header.properties.link + "'>" + val + "</a>";
- //rowEntity.value=
- }
- if (header.properties.hasOwnProperty('arrow')) {
- arrow = "<img height='10' width='10' style='padding-left: 5px' src='./images/arrow-" + header.properties.arrow + ".gif' border='0'>";
- //rowEntity.arrow=
- }
- } else {
- header.properties = {};
- }
- rowContent += '<td class="data" ' + color + '>' +
- (wrapContent ? '<div class="datadiv" alt="' + header.properties.raw + '" rel="' + header.properties.position + '">' : "") +
- val + arrow +
- (wrapContent ? '</div>' : '') + '</td>';
- if (wrapContent) {
- rowEntity.value = {
- alt: header.properties.raw,
- rel: header.properties.position,
- value: val
- }
- } else {
- rowEntity.value = val;
- }
- rowDatas.push(rowEntity);
- if (totalsLists[ROWS])
- rowContent += genTotalDataCells(colShifted + 1, rowShifted, scanSums[ROWS], scanIndexes[ROWS], totalsLists, wrapContent);
- }
- }
- // console.log(i);
- rowContent += "</tr>";
- // if(colHeaders.length!=0&&colHeaders[0].value.value=="(All)"){colHeaders=colHeaders.splice(1,6)}
- $scope.rheaders.push(colHeaders);
- // $scope.rheaders=$scope.rheaders[0].splice(1,1)
- colHeaders = [];
- if (rowDatas.length > 1) {
- // for(var i=0;i<rowDatas.length;i++){
- // if(rowDatas[i].thclass=="row_null"){
- // rowDatas=rowDatas.splice(1,1)
- // }
- // }
- if ($scope.reportName == "接听率") {
- if (rowDatas.length > 2) {
- i = i + parseInt(rowDatas[rowDatas.length - 1].value.value, 10) + parseInt(rowDatas[rowDatas.length - 2].value.alt, 10);
- } else {
- i = i + parseInt(rowDatas[rowDatas.length - 1].value.value, 10);
- }
- } else {
- i = i + parseInt((rowDatas[rowDatas.length - 1].value.value).replace(",", ""), 10);
- }
- $scope.rRows.push(rowDatas);
- rowDatas = [];
- }
- // console.log($scope.rRows);
- var totals = "";
- if (totalsLists[COLUMNS] && rowShifted >= 0) {
- totals += genTotalHeaderRowCells(rowShifted + 1, scanSums, scanIndexes, totalsLists, wrapContent);
- }
- if (batchStarted && batchSize) {
- if (row <= batchSize) {
- if (!isColHeader && !isColHeaderDone) {
- tableContent += "</thead><tbody>";
- isColHeaderDone = true;
- }
- tableContent += rowContent;
- if (totals.length > 0) {
- tableContent += totals;
- }
- } else {
- resultRows.push(rowContent);
- if (totals.length > 0) {
- resultRows.push(totals);
- }
- }
- } else {
- if (!isColHeader && !isColHeaderDone) {
- tableContent += "</thead><tbody>";
- isColHeaderDone = true;
- }
- tableContent += rowContent;
- if (totals.length > 0) {
- tableContent += totals;
- }
- }
- }
- //增加事件占比
- var addrowdata = [];
- var addrowdatas = [];
- var sumdata = [];
- addrowdata[0] = { thclass: "row", value: { rel: "1:0", value: "合计" } }
- var c = 0;
- var b = 0;
- for (var j = 0; j < $scope.rRows.length; j++) {
- if ($scope.reportName == "区域地点统计") {
- if ($scope.rRows[j][0].thclass == "row") {
- // $scope.rRows[j][4]
- c = parseInt($scope.rRows[j][2].value.alt);
- if (!$scope.rRows[j + 1]) {
- $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c), alt: String(c) } }])
- }
- if ($scope.rRows[j + 1] && $scope.rRows[j + 1][0].thclass == "row") {
- $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c), alt: String(c) } }])
- }
- } else if ($scope.rRows[j][0].thclass == "row_null") {
- c += parseInt($scope.rRows[j][2].value.alt);
- if ($scope.rRows[j + 1] && $scope.rRows[j + 1][0].thclass != "row_null") {
- // $scope.rRows[j].push({value:{value:String(c)}});
- // $scope.rRows.push($scope.rRows)
- $scope.rRows.splice(j + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c), alt: String(c) } }]);
- b++;
- } else if (!$scope.rRows[j + 1] && $scope.rRows[j][0].thclass != "row_null") {
- $scope.rRows.splice(j + b + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c), alt: String(c) } }])
- } else if (!$scope.rRows[j + 1] && $scope.rRows[j][0].thclass == "row_null") {
- $scope.rRows.splice(j + b + 1, 0, [{ thclass: "rows", colspan: "2", value: { rel: "1:0", value: "区域合计" } }, { value: { value: String(c), alt: String(c) } }])
- } else {
- }
- }
- }
- if ($scope.reportName == "接听率") {
- if ($scope.rheaders[0].length > 2) {
- $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))) } });
- } else {
- $scope.rRows[j].push({ value: { value: String((parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value))) } });
- }
- // i = parseInt($scope.rRows[j][$scope.rRows[j].length - 1].value.value);
- // if (rowDatas.length > 1) {
- // i = i + parseInt(rowDatas[rowDatas.length - 1].value.value, 10);
- // $scope.rRows.push(rowDatas);
- // rowDatas = [];
- // }
- }
- if (i != 0) {
- $scope.rRows[j].push({ value: { value: String((parseInt(($scope.rRows[j][$scope.rRows[j].length - 1].value.value).replace(",", "")) * 100 / i).toFixed(2)) + '%' } })
- } else {
- $scope.rRows[j].push({ value: { value: String((0).toFixed(2)) + '%' } });
- }
- // $scope.rRows[j].push({value:{value:String((parseInt($scope.rRows[j][$scope.rRows[j].length-1].value.value)*100/i).toFixed(2))+'%'}})
- for (var index = 0; index < $scope.rRows[j].length; index++) {
- var match = /^[+-]?\d*\.?\d*$/.test($scope.rRows[j][index].value.value)
- if (match) {
- if (angular.isUndefined(sumdata[index])) {
- sumdata[index] = parseInt(($scope.rRows[j][index].value.value).replace(",", ""))
- } else {
- sumdata[index] = sumdata[index] + parseInt(($scope.rRows[j][index].value.value).replace(",", ""))
- }
- addrowdata[index] = { value: { value: String(sumdata[index]) } };
- }
- }
- }
- addrowdata.push({ value: { value: "100%" } });
- angular.forEach(addrowdata, function(item) {
- if (item) {
- addrowdatas.push(item);
- }
- })
- if ($scope.reportName == "区域地点统计") {
- addrowdatas.splice(2, 1)
- }
- if ($scope.reportName == "接听率") {
- $scope.rheaders[0].push({ colspan: "1", thclass: "col", title: "合计", value: { rel: "0:1", value: "合计" } })
- }
- addrowdatas[0] = { thclass: "row", colspan: addrowdata.length - addrowdatas.length + 1, value: { rel: "1:0", value: "总合计" } };
- $scope.rheaders[0].push({ colspan: "1", thclass: "col", title: "占比", value: { rel: "0:1", value: "占比(%)" } })
- // if($scope.reportName=="区域地点统计"){
- // $scope.rheaders[0].push({colspan:"1",thclass:"col",title:"一级事件总数",value:{rel:"0:1",value:"一级事件总数"}})
- // }
- // var addrowdata=[];
- // var addrowdata=[{thclass:"row",value:{rel:"1:0",value:"合计"}},{value:{alt:String(parseFloat(i)),value:String(i),proption:'100%'}}]
- $scope.rRows.push(addrowdatas);
- var hmainCol = 35 * $scope.rRows.length;
- $scope.allheight = hmainCol + 570;
- return "<table>" + tableContent + "</tbody></table>";
- }
- // $scope.rheaders=$scope.rheaders.splice(1,1)
- function nextParentsDiffer(data, row, col) {
- while (row-- > 0) {
- if (data[row][col].properties.uniquename != data[row][col + 1].properties.uniquename)
- return true;
- }
- return false;
- }
- // $scope.chartType="doughnut";
- // //chart view
- // $scope.chartData = [
- // { value : 50, color : "#F7464A" },
- // { value : 90, color : "#E2EAE9" },
- // { value : 75, color : "#D4CCC5" },
- // { value : 30, color : "#949FB1"}
- // ];
- // $scope.chartOptions = {
- // // Chart.js options can go here.
- // };
- $scope.onChartClick = function(event) {
- console.log(event);
- // _.forIn(data, function(value, key) {
- // var sum = 0;
- // _.forIn(value, function(date, item) {
- // total+=date;
- // sum += date;
- // i++;
- // // dataChart.push({
- // // label:key,
- // // value:sum,
- // // color:randColor() ,
- // // highlight: highlightColor(),
- // // });
- // });
- // dataChart.push({
- // label:key,
- // value:sum,
- // color:randColor() ,
- // highlight: highlightColor(),
- // });
- // });
- };
- var tmpHSV = undefined;
- function randomHSV(hsv) {
- if (angular.isUndefined(hsv)) {
- return {
- h: 0,
- s: 0.75,
- v: 0.8
- };
- } else {
- return {
- h: hsv.h + 51.5,
- s: 0.75,
- v: 0.8
- }
- }
- }
- function HSVToRGB(h, s, v) {
- var i;
- var f, p, q, t;
- var r, g, b;
- if (s == 0) {
- v = Math.floor(v * 255);
- return {
- r: v,
- g: v,
- b: v
- };
- }
- h /= 60;
- i = Math.floor(h);
- f = h - i;
- p = v * (1 - s);
- q = v * (1 - s * f);
- t = v * (1 - s * (1 - f));
- switch (i) {
- case 0:
- r = v;
- g = t;
- b = p;
- break;
- case 1:
- r = q;
- g = v;
- b = p;
- break;
- case 2:
- r = p;
- g = v;
- b = t;
- break;
- case 3:
- r = p;
- g = q;
- b = v;
- break;
- case 4:
- r = t;
- g = p;
- b = v;
- break;
- default:
- r = v;
- g = p;
- b = q;
- break;
- }
- return {
- r: r * 255,
- g: g * 255,
- b: b * 255
- };
- };
- function colorToHex(color) {
- var red = color.r;
- var green = color.g;
- var blue = color.b;
- var rgb = blue | (green << 8) | (red << 16);
- return '#' + rgb.toString(16);
- };
- }]);
|