
//根据等级获取对应的颜色
function getColorByLevel(level) {
    if(level==="特质"){
        return "#2E8B56";
    }else if(level==="优质"){
        return "#5E9346";
    }else if(level==="优良"){
        return "#919B38";
    }else if(level==="良好"){
        return "#C1A128";
    }else if(level==="轻度污染"){
        return "#D39320";
    }else if(level==="中度污染"){
        return "#C37024";
    }else if(level==="重度污染"){
        return "#B54C26";
    }else if(level==="极度污染"){
        return "#A52A2A";
    }else if(level.indexOf("暂无数据")>0){
        return "#808080";
    }else if(level.indexOf("/")>0){
        return "#CCC";
    }
}

//综合评分
function getColorByLevelAllData(level) {
    if(level==="优质"){
        return "#2E8B56";
    }else if(level==="良好"){
        return "#919B38";
    }else if(level==="合格"){
        return "#D39320";
    }else if(level==="较差"){
        return "#B54C26";
    }else if(level==="极差"){
        return "#A52A2A";
    }else if(level.indexOf("暂无数据")>0){
        return "#808080";
    }else if(level.indexOf("/")>0){
        return "#CCC";
    }
}


//点击ul切换页面表格数据
$("#qualifiedTab a").on('click',function () {
    var html=$(this).html();
    parent.$("#target").text(html);
    //执行查询操作并画图
    var urlPart=$(this).prop("id");
    if(urlPart==="vuDev"){
        if (powerQualityData===null){
            initMap(null,html,17.5,2.5,'(%)',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.vuDevs==null?0:powerQualityData.vuDevs.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.vuDevs, html, 17.5, 2.5, '(%)',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.vuDevs, html, 17.5, 2.5, '(%)',lineFeed,barRouteZero)
            }
        }
    }else if (urlPart==="frequencyDeviation"){
        if (powerQualityData===null){
            initMap(null,html,0.35,0.05,'(Hz)',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.freqDev==null?0:powerQualityData.freqDev.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.freqDev, html, 0.35, 0.05, '(Hz)',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.freqDev, html, 0.35, 0.05, '(Hz)',lineFeed,barRouteZero)
            }
        }
    }else if (urlPart==="vthd"){
        if (powerQualityData===null){
            initMap(null,html,3.5,0.5,'(%)',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.vThdCp95==null?0:powerQualityData.vThdCp95.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.vThdCp95, html, 3.5, 0.5, '(%)',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.vThdCp95, html, 3.5, 0.5, '(%)',lineFeed,barRouteZero)
            }
        }
    }else if (urlPart==="vplt"){
        if (powerQualityData===null){
            initMap(null,html,1.05,0.15,'',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.dataPlt==null?0:powerQualityData.dataPlt.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.dataPlt, html, 1.2, 0.15, '',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.dataPlt, html, 1.2, 0.15, '',lineFeed,barRouteZero)
            }
        }
    }else if (urlPart==="vUnbalance"){
        if (powerQualityData===null){
            initMap(null,html,3.5,0.5,'(%)',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.vunbalanceCp95==null?0:powerQualityData.vunbalanceCp95.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.vunbalanceCp95, html, 3.5, 0.5, '(%)',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.vunbalanceCp95, html, 3.5, 0.5, '(%)',lineFeed,barRouteZero)
            }
        }
    }else if(urlPart==="allData"){
        if (powerQualityData===null){
            initMap(null,'综合评估',5,1,'',lineFeed,barRouteZero)
        }else{
            var powerLength=powerQualityData.synData==null?0:powerQualityData.synData.length;
            if(parseInt(powerLength)>parseInt(barUpperLimit6)) {
                initMap(powerQualityData.synData, '综合评估', 5, 1, '',noLineFeed,barRouteIncline)
            }else {
                initMap(powerQualityData.synData, '综合评估', 5, 1, '',lineFeed,barRouteZero)
            }
        }
    }
})

//绘制地图的数据
function drawMap(d,name) {
    if (name ==="电压偏差"){
        renderMapEvent(d,0,2.5,5,7.5,10,12.5,15,17.5);
    }else if (name ==="频率偏差"){
        renderMapEvent(d,0,0.05,0.1,0.15,0.2,0.25,0.30,0.35);
    }else if (name ==="谐波含量"){
        renderMapEvent(d,0,0.5,1,1.5,2,2.5,3,3.5);
    }else if (name ==="电压闪变"){
        renderMapEvent(d,0,0.15,0.3,0.45,0.6,0.75,0.90,1.05);
    }else if (name ==="三相电压不平衡度"){
        renderMapEvent(d,0,0.5,1,1.5,2,2.5,3,3.5);
    }else if(name==="综合评估"){
        renderMapEventAll(d,0,2,3,4,4.5,5);
    }
}

//获取柱状图的最大值
function getMaxValue(max,quentityData,temp) {
    for(var i=0;i<quentityData.length;i++){
        if(quentityData[i].data!==3.1415&quentityData[i].data!==3.14159){
            if (quentityData[i].data>=max){
                max = quentityData[i].data+temp;
            }
        }
    }
    return max.toFixed(2);
}

