//时间初始化（时间戳，时间类型）
var formatDateTime = function (inputTime,type) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    //return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    if(type=="1h" || type=="2h" || type=="3h" || type=="6h" || type=="12h" || type=="1d"){
        return h+':'+minute;
    } else if (type=="3d" || type=="7d" || type=="14d" || type=="1m"){
        return h+':'+minute;
    } else if (type=="所有"){
        return y + '-' + m
    } else if (type == "outhers"){
        return m + '-' + d+'  '+h+':'+minute;
    } else if (type == "allDays"){
        return y + '-' + m + '-' + d+'  '+ h +':'+minute;
    }  else if (type == "yyddmmhms"){
        return y + '-' + m + '-' + d+'  '+h+':'+minute+':'+second;
    }
};
var tofix2 = function (num) {
    return Math.round(num * 100) / 100;
};
var tofix1 = function (num) {
    return Math.round(num * 10) / 10;
};
var msx,msy;
$(document).mousemove(function(e){
    msx = e.pageX;
    msy = e.pageY;
});
//折线图表（id,数据）
var mapChart = function (id,res,switch_num,point) {
    //console.log(res)
    $(id).parent().find(".totalTime").val(res.end_time-res.start_time);
    $(id).parent().find(".flowchartStart").val(res.start_time);
    $(id).parent().find(".flowchartEnd").val(res.end_time);

    $(id).css("height","300px");
    $(id).next().show();
    var arrKeyIn = [],arrKeyOut = [],xLine=[],yLine1=[],yLine2=[];
    var all_line = [],in_95_line = [],out_95_line = [];
    var actionTime = $(id).parent().find(".link-action.selected").html();

    for (var key in res.in) {
        arrKeyIn.push([parseInt(key),res.in[key]]);
        xLine.push(parseInt(key));
        yLine1.push(res.in[key]);
        all_line.push([parseInt(key),res.all_line]);
        in_95_line.push([parseInt(key),res.in_95_line]);
        out_95_line.push([parseInt(key),res.out_95_line])
    }
    for (var key in res.out) {
        arrKeyOut.push([parseInt(key),res.out[key]]);
        yLine2.push(res.out[key])
    }
    $(id).parent().find(".thisStart").val(arrKeyIn[0][0]);
    $(id).parent().find(".thisEnd").val(arrKeyIn[arrKeyIn.length-1][0]);
    if(!point){
        point = arrKeyIn[arrKeyIn.length-1][0] - arrKeyIn[0][0];
    } 
    var sum = 0 , sum2 = 0;
    for(var i=0;i<yLine1.length;i++){
        sum+=yLine1[i];
    }
    for(var i=0;i<yLine2.length;i++){
        sum2+=yLine2[i];
    }
    var y_unit = res.y_unit;
    var unit = res.in_info.unit;
    //下方注释
    $(id).next().find(".rrd_flowchart_img_info_inCurrent").html(tofix2(yLine1[yLine1.length-1])+" "+unit);
    $(id).next().find(".rrd_flowchart_img_info_outCurrent").html(tofix2(yLine2[yLine2.length-1])+" "+unit);
    $(id).next().find(".rrd_flowchart_img_info_inAVERAGE").html(tofix2(sum/yLine1.length)+" "+unit);
    $(id).next().find(".rrd_flowchart_img_info_outAVERAGE").html(tofix2(sum2/yLine2.length)+" "+unit);
    $(id).next().find(".rrd_flowchart_img_info_inMaximum").html(tofix2(res.in_info.max)+" "+unit);
    $(id).next().find(".rrd_flowchart_img_info_outMaximum").html(tofix2(res.out_info.max)+" "+unit);
    //换算注释单位
    var in_95_line_unite = 'bps',
        out_95_line_unite = 'bps',
        all_line_unite = 'bps',
        in_95_line_now = res.in_95_line,
        out_95_line_now = res.out_95_line,
        all_line_now = res.all_line;
    if(unit=="Kbps"){
        if(res.in_95_line<0.01){
            in_95_line_now = res.in_95_line*1024;
            in_95_line_unite = "bps"
        } else {
            in_95_line_now = res.in_95_line;
            in_95_line_unite = "kbps"
        }
        if(res.out_95_line<0.01){
            out_95_line_now = res.out_95_line*1024;
            out_95_line_unite = "bps"
        } else {
            out_95_line_now = res.out_95_line;
            out_95_line_unite = "kbps"
        }
        if(res.all_line<0.01){
            all_line_now = res.all_line*1024;
            all_line_unite = "bps"
        } else {
            all_line_now = res.all_line;
            all_line_unite = "Kbps"
        }
    } else if(unit=="Mbps"){
        if(res.in_95_line<0.00001){
            in_95_line_now = res.in_95_line*1024*1024;
            in_95_line_unite = "bps"
        } else if(res.in_95_line<0.01){
            in_95_line_now = res.in_95_line*1024;
            in_95_line_unite = "Kbps"
        } else {
            in_95_line_now = res.in_95_line;
            in_95_line_unite = "Mbps"
        }
        if(res.out_95_line<0.00001){
            out_95_line_now = res.out_95_line*1024*1024;
            out_95_line_unite = "bps"
        } else if(res.out_95_line<0.01){
            out_95_line_now = res.out_95_line*1024;
            out_95_line_unite = "Kbps"
        } else {
            out_95_line_now = res.out_95_line;
            out_95_line_unite = "Mbps"
        }
        if(res.all_line<0.00001){
            all_line_now = res.all_line*1024*1024;
            all_line_unite = "bps"
        } else if(res.all_line<0.01){
            all_line_now = res.all_line*1024;
            all_line_unite = "Kbps"
        } else {
            all_line_now = res.all_line;
            all_line_unite = "Mbps"
        }
    } else if(unit=="Gbps"){
        if(res.in_95_line<0.00000001){
            in_95_line_now = res.in_95_line*1024*1024*1024;
            in_95_line_unite = "bps"
        } else if(res.in_95_line<0.00001){
            in_95_line_now = res.in_95_line*1024*1024;
            in_95_line_unite = "Kbps"
        } else if(res.in_95_line<0.01){
            in_95_line_now = res.in_95_line*1024;
            in_95_line_unite = "Mbps"
        } else {
            in_95_line_now = res.in_95_line;
            in_95_line_unite = "Gbps"
        }
        if(res.out_95_line<0.00000001){
            out_95_line_now = res.out_95_line*1024*1024*1024;
            out_95_line_unite = "bps"
        } else if(res.out_95_line<0.00001){
            out_95_line_now = res.out_95_line*1024*1024;
            out_95_line_unite = "Kbps"
        } else if(res.out_95_line<0.01){
            out_95_line_now = res.out_95_line*1024;
            out_95_line_unite = "Mbps"
        } else {
            out_95_line_now = res.out_95_line;
            out_95_line_unite = "Gbps"
        }
        if(res.all_line<0.00000001){
            all_line_now = res.all_line*1024*1024*1024;
            all_line_unite = "bps"
        } else if(res.all_line<0.00001){
            all_line_now = res.all_line*1024*1024;
            all_line_unite = "Kbps"
        } else if(res.out_95_line<0.01){
            out_95_line_now = res.all_line*1024;
            out_95_line_unite = "Mbps"
        } else {
            all_line_now = res.all_line;
            all_line_unite = "Gbps"
        }
    } else if(unit=="Tbps"){
        if(res.in_95_line<0.00000000001){
            in_95_line_now = res.in_95_line*1024*1024*1024*1024;
            in_95_line_unite = "bps"
        } else if(res.in_95_line<0.00000001){
            in_95_line_now = res.in_95_line*1024*1024*1024;
            in_95_line_unite = "Kbps"
        } else if(res.in_95_line<0.00001){
            in_95_line_now = res.in_95_line*1024*1024;
            in_95_line_unite = "Mbps"
        } else if(res.in_95_line<0.01){
            in_95_line_now = res.in_95_line*1024;
            in_95_line_unite = "Gbps"
        } else {
            in_95_line_now = res.in_95_line;
            in_95_line_unite = "Tbps"
        }
        if(res.out_95_line<0.00000000001){
            out_95_line_now = res.out_95_line*1024*1024*1024*1024;
            out_95_line_unite = "bps"
        } else if(res.out_95_line<0.00000001){
            out_95_line_now = res.out_95_line*1024*1024*1024;
            out_95_line_unite = "Kbps"
        } else if(res.out_95_line<0.00001){
            out_95_line_now = res.out_95_line*1024*1024;
            out_95_line_unite = "Mbps"
        } else if(res.out_95_line<0.01){
            out_95_line_now = res.out_95_line*1024;
            out_95_line_unite = "Gbps"
        } else {
            out_95_line_now = res.out_95_line;
            out_95_line_unite = "Tbps"
        }
        if(res.all_line<0.00000000001){
            all_line_now = res.all_line*1024*1024*1024*1024;
            all_line_unite = "bps"
        } else if(res.all_line<0.00000001){
            all_line_now = res.all_line*1024*1024*1024;
            all_line_unite = "Kbps"
        } else if(res.all_line<0.00001){
            all_line_now = res.all_line*1024*1024;
            all_line_unite = "Mbps"
        } else if(res.all_line<0.01){
            all_line_now = res.all_line*1024;
            all_line_unite = "Gbps"
        } else {
            all_line_now = res.all_line;
            all_line_unite = "Tbps"
        }
    }
    $(id).next().find(".in_95_line span").html(tofix2(in_95_line_now)+" "+in_95_line_unite);
    $(id).next().find(".out_95_line span").html(tofix2(out_95_line_now)+" "+out_95_line_unite);
    $(id).next().find(".all_line span").html(tofix2(all_line_now)+" "+all_line_unite);
    //x轴
    var xPoint,xPointMin,xPointMax,interval,intervalMin,intervalMax;
    //间隔处理
    if(point !=null){
        if(point<=60*60000){//1h
            intervalMin = 60000*2;
            intervalMax = 60000;
            xPointMin = point/60000*2;
            xPointMax = point/60000;
        } else if(point<=180*60000 && point>60*60000){//1h-3h
            intervalMin = 120000*2;
            intervalMax = 120000;
            xPointMin = point/(120000*2);
            xPointMax = point/120000;
        } else if(point<=360*60000 && point>180*60000){//3h-6h
            intervalMin = 300000*2;
            intervalMax = 300000;
            xPointMin = point/(300000*2);
            xPointMax = point/300000;
        } else if(point<=12*60*60000 && point>6*60*60000){//6h-12h
            intervalMin = 15*60000*2;
            intervalMax = 15*60000;
            xPointMin = point/(15*60000*2);
            xPointMax = point/(15*60000);
        } else if(point<=24*60*60000 && point>12*60*60000){//12h-1d
            intervalMin = 30*60000*2;
            intervalMax = 30*60000;
            xPointMin = point/(30*60000*2);
            xPointMax = point/(30*60000);
        } else if(point<=5*24*60*60000 && point>24*60*60000){//1d-5d
            intervalMin = 60*60000*2;
            intervalMax = 60*60000;
            xPointMin = point/(60*60000*2);
            xPointMax = point/(60*60000);
        } else if(point<=7*24*60*60000 && point>5*24*60*60000){//5d-7d
            intervalMin = 3*60*60000*2;
            intervalMax = 3*60*60000;
            xPointMin = point/(3*60*60000*2);
            xPointMax = point/(3*60*60000);
        } else if(point<=13*24*60*60000 && point>7*24*60*60000){//7d-13d
            intervalMin = 6*60*60000*2;
            intervalMax = 6*60*60000;
            xPointMin = point/(6*60*60000*2);
            xPointMax = point/(6*60*60000);
        } else if(point<=25*24*60*60000 && point>13*24*60*60000){//13d-25d
            intervalMin = 12*60*60000*2;
            intervalMax = 12*60*60000;
            xPointMin = point/(12*60*60000*2);
            xPointMax = point/(12*60*60000);
        } else if(point<=129*24*60*60000 && point>25*24*60*60000){//25d-4m9d
            intervalMin = 24*60*60000*2;
            intervalMax = 24*60*60000;
            xPointMin = point/(24*60*60000*2);
            xPointMax = point/(24*60*60000);
        } else if(point>129*24*60*60000){//25d-4m9d
            intervalMin = 7*24*60*60000*2;
            intervalMax = 7*24*60*60000;
            xPointMin = point/(7*24*60*60000*2);
            xPointMax = point/(7*24*60*60000);
        }
    } else {
        if(actionTime == "1h"){
            intervalMin = 120000;
            intervalMax = 60000;
            xPointMin = 30;
            xPointMax = 60;
        } else if(actionTime == "2h") {
            intervalMin = 300000;
            intervalMax = 120000;
            xPointMin = 24;
            xPointMax = 59;
        } else if(actionTime == "3h") {
            intervalMin = 300000;
            intervalMax = 120000;
            xPointMin = 36;
            xPointMax = 89;
        } else if(actionTime == "6h") {
            intervalMin = 900000;
            intervalMax = 300000;
            xPointMin = 24;
            xPointMax = 71;
        } else if(actionTime == "12h") {
            intervalMin = 1800000;
            intervalMax = 900000;
            xPointMin = 24;
            xPointMax = 47;
        } else if(actionTime == "1d") {
            intervalMin = 3600000;
            intervalMax = 1800000;
            xPointMin = 24;
            xPointMax = 47;
        } else if(actionTime == "3d") {
            intervalMin = 10800000;
            intervalMax = 3600000;
            xPointMin = 24;
            xPointMax = 71;
        } else if(actionTime == "7d") {
            intervalMin = 21600000;
            intervalMax = 10800000;
            xPointMin = 28;
            xPointMax = 55;
        } else if(actionTime == "14d") {
            intervalMin = 43200000;
            intervalMax = 21600000;
            xPointMin = 28;
            xPointMax = 55;
        } else if(actionTime == "1m") {
            intervalMin = 86400000;
            intervalMax = 43200000;
            xPointMin = 30;
            xPointMax = 59;
        } else if(actionTime == "所有") {
            intervalMin = 2592000000;
            intervalMax = 2592000000;
            xPointMin = 24;
            xPointMax = 24;
        }
    }
    var winWidth;
    if (window.innerWidth)
        winWidth = window.innerWidth;
    else if ((document.body) && (document.body.clientWidth))
        winWidth = document.body.clientWidth;

    if(winWidth<1366){
        xPoint = xPointMin;
        interval = intervalMin;
    } else {
        xPoint = xPointMax;
        interval = intervalMax;
    }
    var xLineMin=xLine[0];
    var xLineLine=[];
    var xLineMax=xLine[xLine.length-1];
    var deviation = 0,deviation2;
    deviation2 = formatDateTime(xLineMax,"3d");
    if(point != null){
        if(point<=5*24*60*60000 && point>24*60*60000 && winWidth>=1366){//1d-5d
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%60 != 0){
                deviation = 60000*(-(parseInt(deviation)%60));
            }
        } else if(point<=5*24*60*60000 && point>24*60*60000 && winWidth<1366){//1d-5d
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%120 != 0){
                deviation = 60000*(-(parseInt(deviation)%120));
            }
        } else if(point<=7*24*60*60000 && point>5*24*60*60000 && winWidth>=1366){//5d-7d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%3 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%3*60));
            }
        } else if(point<=7*24*60*60000 && point>5*24*60*60000 && winWidth<1366){//5d-7d

            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%6 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%6*60));
            }
        } else if(point<=13*24*60*60000 && point>7*24*60*60000 && winWidth>=1366){//7d-13d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%6 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%6*60));
            }
        } else if(point<=13*24*60*60000 && point>7*24*60*60000 && winWidth<1366){//7d-13d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%12 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%12*60));
            }
        } else if(point<=25*24*60*60000 && point>13*24*60*60000 && winWidth>=1366){//13d-25d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%12 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%12*60));
            }
        } else if(point<=25*24*60*60000 && point>13*24*60*60000 && winWidth<1366){//13d-25d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%24 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%24*60));
            }
        } else if(point<=129*24*60*60000 && point>25*24*60*60000 && winWidth>=1366){//25d-129d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%24 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%24*60));
            }
        } else if(point<=129*24*60*60000 && point>25*24*60*60000 && winWidth<1366){//25d-129d
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%24 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%24*60));
            }
        } else if(point>129*24*60*60000 && winWidth>=1366){//129d+
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%24 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%24*60));
            }
        } else if(point>129*24*60*60000 && winWidth<1366){//129d+
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%24 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%24*60));
            }
        }
    } else {
        if((actionTime == "2h" && winWidth>=1366) || (actionTime == "1h" && winWidth<1366) || (actionTime == "3h" && winWidth>=1366)){
            deviation = parseInt(deviation2.substr(deviation2.length-1));
            if(deviation%2 != 0){
                deviation = 60000;
            }
        } else if((actionTime == "2h" && winWidth < 1366) || (actionTime == "3h" && winWidth<1366) || (actionTime == "6h" && winWidth>=1366)){
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%5 != 0){
                deviation = 60000*(-(parseInt(deviation)%5));
            }
        } else if((actionTime == "6h" && winWidth < 1366) || (actionTime == "12h" && winWidth>=1366)){
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%15 != 0){
                deviation = 60000*(-(parseInt(deviation)%15));
            }
        } else if((actionTime == "12h" && winWidth < 1366) || (actionTime == "1d" && winWidth>=1366)){
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%30 != 0){
                deviation = 60000*(-(parseInt(deviation)%30));
            }
        } else if((actionTime == "1d" && winWidth < 1366) || (actionTime == "3d" && winWidth>=1366)){
            deviation = parseInt(deviation2.substr(deviation2.length-2));
            if(parseInt(deviation)%60 != 0){
                deviation = 60000*(-(parseInt(deviation)%60));
            }
        } else if((actionTime == "3d" && winWidth < 1366) || (actionTime == "7d" && winWidth>=1366)){
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%3 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%3*60));
            }
        } else if((actionTime == "7d" && winWidth < 1366) || (actionTime == "14d" && winWidth>=1366)){
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%6 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%6*60));
            }
        } else if((actionTime == "14d" && winWidth < 1366) || actionTime == "1m"){
            deviation = deviation2.substr(deviation2.length-5);
            var deviationLeft = deviation.split(":")[0]
            var deviationRight = deviation.split(":")[1]
            if(parseInt(deviationRight)%60 != 0 || parseInt(deviationLeft)%12 != 0){
                deviation = -60000*((parseInt(deviationRight)%60)+ (parseInt(deviationLeft)%12*60));
            }
        }
    }

    $(id).parent().find(".jeindiv2").html(formatDateTime(xLineMax,"yyddmmhms"));
    $(id).parent().find(".jeindiv1").html(formatDateTime(xLine[0],"yyddmmhms"));

    for(var i=0;i<=xPoint;i++){
        if(actionTime != "outhers"){
            if(i==0){
                xLineLine.push([xLineMax-(i*interval),formatDateTime(xLineMax-(i*interval),"outhers")]);
            } else if( i == xPoint){
                xLineLine.push([xLineMin,formatDateTime(xLineMin,"outhers")]);
            } else {
                if(formatDateTime(xLineMax+deviation-(i*interval),actionTime)=="00:00"){
                    xLineLine.push([xLineMax+deviation-(i*interval),formatDateTime(xLineMax+deviation-(i*interval),"outhers")]);
                } else {
                    xLineLine.push([xLineMax+deviation-(i*interval),formatDateTime(xLineMax+deviation-(i*interval),actionTime)]);
                }
            }
        } else{
            xLineLine.push([xLineMax+deviation-(i*interval),formatDateTime(xLineMax+deviation-(i*interval),actionTime)]);
        }
    }
    var tickets = [];
    tickets.push([0]);
    /*y轴间隔处理*/
    if(res.y_max <= 2){
        for(var i = 0;i<=res.y_max;i+=0.2){
            tickets.push([tofix1(i)]);
        }
    } else if (res.y_max <= 5 && 2 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=0.5){
            tickets.push([i]);
        }
    } else if (res.y_max <= 10 && 5 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=1){
            tickets.push([tofix1(i)]);
        }
    } else if (res.y_max <= 20 && 10 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=2){
            tickets.push([i]);
        }
    } else if (res.y_max <= 50 && 20 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=5){
            tickets.push([i]);
        }
    } else if (res.y_max <= 100 && 50 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=10){
            tickets.push([i]);
        }
    } else if (res.y_max <= 200 && 100 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=20){
            tickets.push([i]);
        }
    } else if (res.y_max <= 500 && 200 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=50){
            tickets.push([i]);
        }
    } else if (res.y_max <= 1000 && 500 < res.y_max){
        for(var i = 0;i<=res.y_max;i+=100){
            tickets.push([i]);
        }
    }

    var options = {
        series: {
            shadowSize: 0,
            lines: {
                show: true
            },
            points: {
                show: false
            }
        },
        crosshair: { mode: "x" ,color:"rgba(244,7,3,0.3)",lineWidth: 1},
        yaxis: { min: 0, max: res.y_max ,
            ticks: tickets,
            tickFormatter: function (v) {
                return v + y_unit;
            }
        }, // Y 轴的最大值最小值
        xaxis: {
            ticks: xLineLine
        },
        grid:{//线的颜色
            show: true,
            aboveData: false,
            color: "#d0dcf6",
            borderColor: "#d0dcf6",
            hoverable: true,
            clickable: false
        }
    };
    var dataset = [
        {  data:  arrKeyIn , color:"#00aa00",lines: {show: true, lineWidth: 1.2, fill: 0.15, fillColor: { colors: ["rgba(0,170,0,.3)", "#00aa00"]}}, radius: 4},
        { data:  arrKeyOut , color: "#4b4bff",lines: {show: true, lineWidth: 1.2, fill: 0.15, fillColor: { colors: ["rgba(75,75,225,0.3)", "#4b4bff"]}}, radius: 4 },
        {  data:  all_line , color: "#f74f22", lines:{lineWidth: 1}},
        {  data:  in_95_line , color: "#00aa00", lines:{lineWidth: 1}},
        {  data:  out_95_line , color: "#4b4bff", lines:{lineWidth: 1}}
    ];
    $.plot(id, dataset, options);
    //鼠标滑过显示注释
    $("<div id='tooltip'></div>").css({
        position: "absolute",
        display: "none",
        "background-color": "#fff",
        color:"#1f2c33",
        border:"1px solid #ccd5d9",
        "-webkit-box-shadow":"0 4px 20px 0 rgba(118, 141, 153, 0.5)",
        "-moz-box-shadow":"0 4px 20px 0 rgba(118, 141, 153, 0.5)",
        "box-shadow":"0 4px 20px 0 rgba(118, 141, 153, 0.5)",
        "line-height":"18px",
        "font-size":"10px",
        padding:"15px 10px 10px 10px"
    }).appendTo("body");
    $(id).bind("plothover", function (event, pos, item) {
        if (item) {
            $("#tooltip").children().remove();
            var xmodel = item.datapoint[0],
                y = item.datapoint[1].toFixed(2);
            $("#tooltip").append("<div>Time：<span>"+formatDateTime(xmodel,"allDays")+"</span></div>");
            for (key in  arrKeyIn){
                if(arrKeyIn[key][0] == xmodel){
                    var arrKeyInValue ="Traffic Inbound：" + tofix2(arrKeyIn[key][1]) + unit;
                    $("#tooltip").append("<div><i style=\"display: inline-block;width: 10px;height: 10px;background:#01ab01;margin-right: 5px;\"></i>"+arrKeyInValue+"</div>");
                }
            }
            for (key in  arrKeyOut){
                if(arrKeyOut[key][0] == xmodel){
                    var arrKeyOutValue ="Traffic Outbound：" + tofix2(arrKeyOut[key][1]) + unit;
                    $("#tooltip").append("<div><i style=\"display: inline-block;width: 10px;height: 10px;background:#3437fb;margin-right: 5px;\"></i>"+arrKeyOutValue+"</div>");
                }
            }

            $("#tooltip").css({top: item.pageY+10, left: item.pageX+10}).fadeIn(200);
        } else {
            var div = $('#rrd_flowchart_img');
            if(div.length == 0){
                div = $('.rrd_traffic');
            }
            var y1 = div.offset().top;
            var y2 = y1 + div.height();
            var x1 = div.offset().left;
            var x2 = x1 + div.width();
            if( msx < x1+10 || msx > x2-10 || msy < y1+5 || msy > y2-20){
                $("#tooltip").hide()
            }
        }
    });
    //获取select
    if(typeof switch_num == 'undefined'){
        $(id).next().find(".OutgoingGigabitEthernet").html("Aggregate Interface");
        $(id).next().find(".IncomingGigabitEthernet").html("Aggregate Interface");
    } else {
        $(id).next().find(".IncomingGigabitEthernet").html(switch_num);
        $(id).next().find(".OutgoingGigabitEthernet").html(switch_num);
    }

    //不显示的数据
    if(res.all_line == undefined){
        $(".all_line").hide();
    } else{
        $(".all_line").show();
    }
    if(res.in_95_line == undefined){
        $(".in_95_line").hide();
    } else {
        $(".in_95_line").show();
    }
    if(res.out_95_line == undefined){
        $(".out_95_line").hide();
    } else {
        $(".out_95_line").show();
    }
    //数据红色显示
    setTimeout(function(){
        for(var i=0 ; i<$(".xAxis >.tickLabel").length;i++ ){
            $(".xAxis >.tickLabel").eq(0).css("color","red");
            $(".xAxis >.tickLabel").eq($(".xAxis >.tickLabel").length-1).css("color","red");
            var str = $(".xAxis >.tickLabel").eq(i).html();

            if(point !=null){
                if(str.length == 12 && !(actionTime == "1m" && winWidth<1366)){
                    $(".xAxis >.tickLabel").eq(i).css("color","red")
                }
            } else {
                if(point<25*24*60*60000){
                    if(str.length == 12){
                        $(".xAxis >.tickLabel").eq(i).css("color","red")
                    }
                }
            }

            str = str.substr(str.length-3);
            if(point !=null){
            } else {
                if(actionTime == "1h" || actionTime == "2h" || actionTime == "3h" || actionTime == "6h" || actionTime == "12h" || (actionTime == "1d" && winWidth>=1366) ){
                    str = str.substr(str.length-3);
                    if(str == ":00"){
                        $(".xAxis >.tickLabel").eq(i).css("color","red")
                    }
                }
                if(winWidth<1366){
                    if(actionTime == "1d"){
                        str = str.substr(str.length-3);
                        if(str == ":00"){
                            $(this).css("color","red")
                        }
                    }
                } else {
                }
            }


        }
    },100)
}
function sliderReset(id){
    var axis_all = $("#"+id).parent().find(".slider-outer").width();
    var slider = $("#"+id).parent().find(".slider-content-center").width()
    $("#"+id).parent().find(".slider-outer").css("width",axis_all);
    $("#"+id).parent().find(".slider-content-prev").css("left",axis_all - slider-32-35);
    $("#"+id).parent().find(".slider-content-center").css("left",axis_all - slider-16-35);
    $("#"+id).parent().find(".slider-content-next").css("left",axis_all -16-35);
}

function resizeDocument(){
    var main = $(window.parent.document).find("#flowchart_traffic_iframe");
    var mainheight = $(document).height();
    main.height(mainheight);
}

$(function(){
    if($('.rrd_traffic').length>0){
        $('.rrd_traffic').each(function(){
            var id = $(this).data('id');
            $(this).find("#"+id).html('<span>图片加载中…</span>');
            var url = $(this).find('.links').data('url');
            var type = $(this).find('.links').data('type');
            var diff_time = $(this).find('.zoom').find('.selected').attr('zoom');
            var switch_num = $(this).find('.links').data('port');
            var end = new Date().getTime();
            var start = +(end - diff_time * 1000);
            var _this = $(this)
            $.getJSON(location.href+url+'&switch_num='+switch_num+'&start='+start+'&end='+end+'&traffic=true&get_traffic=1&t='+Math.random(), {}, function(res){
                if(typeof res.status != 'undefined' && res.status == 'success'){
                    sliderReset(id);
                    $("#"+id).parent().find("input.flowchart").val(id);
                    $("#"+id).parent().find("input.flowchartUrl").val(url);
                    $("#"+id).parent().find("input.flowchartSwitch").val(switch_num);
                    $("#"+id).parent().find(".selectTime").html($("#"+id).parent().find(".zoom").find(".link-action.selected").html())
                    mapChart("#"+id,res,switch_num)
                    resizeDocument()
                }else if(res.status == 'nosupport'){
                    _this.parent().parent().parent().remove();
                }else{
                    var content = '没有流量数据';
                    // if(/^\d+$/i.test(switch_num)){
                    //     content = language.pleaseRefreshSwitchSNMPInfo
                    // }
                    $("#"+id).html("<div style='text-align: center;color:#999;'>"+ content +"</div>");
                    $("#"+id).css("height","50px !important;")
                    $("#"+id).next().hide()
                }
            })
        })
    }
})

$(document).on('click', '.rrd_traffic .zoom .link-action', function(){
    $(this).parent().parent().parent().find("#rrd_flowchart_img").html('<span>图片加载中…</span>')
    $(this).siblings().removeClass('selected');
    $(this).addClass('selected');
    var id =  $(this).parent().parent().parent().data('id')
    var diff_time = $(this).attr('zoom');
    var url = $(this).parent().data('url');
    var type = $(this).parent().data('type');
    var switch_num = $(this).parent().data('port');
    var end = new Date().getTime();
    var start = +(end - diff_time * 1000);
    $.getJSON(location.href+url+'&switch_num='+switch_num+'&start='+start+'&end='+end+'&traffic=true&get_traffic=1&t='+Math.random(), {}, function(res){
        if(typeof res.status != 'undefined' && res.status == 'success'){
            sliderReset(id);
            $("#"+id).parent().find(".selectTime").html($("#"+id).parent().find(".zoom").find(".link-action.selected").html())
            mapChart("#"+id, res,switch_num)
            resizeDocument()
        }else{
            var content = '没有流量数据';
            // if(/^\d+$/i.test(switch_num)){
            //     content = '请修改交换机获取新的端口信息'
            // }
            $("#"+id).html("<div style='text-align: center;color:#999;'>"+ content +"</div>");
            $("#"+id).css("height","50px !important;")
            $("#"+id).next().hide()
        }
    })
})
