| | |
| | | |
| | | //各监测因子数据分级(标准) |
| | | _legend_r: { |
| | | NO: [0, 100, 200, 700, 1200, 2340], |
| | | NO2: [0, 100, 200, 700, 1200, 2340], |
| | | CO: [0, 5, 10, 35, 60, 90], |
| | | CO: [0, 5000, 10000, 35000, 60000, 90000], |
| | | H2S: [0, 150, 500, 650, 800, 1600], |
| | | SO2: [0, 150, 500, 650, 800, 1600], |
| | | O3: [0, 160, 200, 300, 400, 800], |
| | |
| | | |
| | | //各监测因子数据分级(标准)对应颜色 |
| | | _legend_c: { |
| | | NO: [ |
| | | [0, 0.89, 0, 0.75], |
| | | [1, 1, 0, 0.75], |
| | | [1, 0.49, 0, 0.75], |
| | | [1, 0, 0, 0.75], |
| | | [0.6, 0, 0.3, 0.75], |
| | | [0.49, 0, 0.14, 0.75] |
| | | ], |
| | | NO2: [ |
| | | [0, 0.89, 0, 0.75], |
| | | [1, 1, 0, 0.75], |
| | |
| | | [0.87, 0.92, 0.03, 0.75], |
| | | [0.8, 0.67, 0.04, 0.75], |
| | | [0.92, 0.28, 0.07, 0.75], |
| | | [0.6, 0.05, 0.05, 0.75] |
| | | [0.96, 0.05, 0.05, 0.75] |
| | | ], |
| | | |
| | | getStandardRange: function (name) { |
| | |
| | | // } |
| | | // max = parseInt(key) |
| | | // } |
| | | if (name == 'CO') { |
| | | min *= 1000; |
| | | max *= 1000; |
| | | } |
| | | |
| | | return [min, max]; |
| | | }, |
| | | |
| | | getColor: function (name, type, data, min, max) { |
| | | if (!data) { |
| | | return [0, 0, 0, 0]; |
| | | } |
| | | if (type == this.S_TYPE) { |
| | | return this.getStandardColor(name, data); |
| | | } else { |
| | |
| | | }, |
| | | |
| | | /** |
| | | * 获取当前颜色上一个等级的颜色 |
| | | * @param {*} name |
| | | * @param {*} type |
| | | * @param {*} color |
| | | */ |
| | | getPreviousColor(name, type, color) { |
| | | let colors; |
| | | if (type == this.S_TYPE) { |
| | | colors = this._legend_c[name]; |
| | | } else { |
| | | colors = this._custom; |
| | | } |
| | | if (colors == undefined) { |
| | | colors = this._legend_c['PM25']; |
| | | } |
| | | let index = colors.indexOf(color); |
| | | index--; |
| | | if (index < 0) index = 0; |
| | | return colors[index]; |
| | | }, |
| | | |
| | | /** |
| | | * 获取监测因子当前浓度对应的颜色 |
| | | * @param name 监测因子名称 |
| | | * @param data 监测因子浓度 |
| | | */ |
| | | getStandardColor: function (name, data) { |
| | | var range = this._legend_r[name]; |
| | | var colors = this._legend_c[name]; |
| | | let range = this._legend_r[name]; |
| | | let colors = this._legend_c[name]; |
| | | if (range == undefined) { |
| | | range = this._legend_r['PM25']; |
| | | colors = this._legend_c['PM25']; |
| | | } |
| | | // return colors[0] |
| | | |
| | | var selected = undefined; |
| | | let selected = undefined; |
| | | for (let i = 0; i < range.length; i++) { |
| | | const d = range[i]; |
| | | var d1 = d; |
| | | if (name == 'CO') { |
| | | d1 *= 1000; |
| | | } |
| | | let d1 = d; |
| | | if (data >= d1) { |
| | | selected = i; |
| | | } else { |
| | |
| | | return colors[selected]; |
| | | }, |
| | | |
| | | getStandardColorAndNext: function (name, data) { |
| | | if (!data) { |
| | | return { |
| | | color: [0, 0, 0, 0], |
| | | nextColor: [0, 0, 0, 0], |
| | | range: 0, |
| | | nextRange: 0 |
| | | }; |
| | | } |
| | | let range = this._legend_r[name]; |
| | | let colors = this._legend_c[name]; |
| | | if (range == undefined) { |
| | | range = this._legend_r['PM25']; |
| | | colors = this._legend_c['PM25']; |
| | | } |
| | | |
| | | let selected = undefined; |
| | | for (let i = 0; i < range.length; i++) { |
| | | const d = range[i]; |
| | | let d1 = d; |
| | | if (data >= d1) { |
| | | selected = i; |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 避免下标越界 |
| | | if (selected >= colors.length) { |
| | | selected = colors.length - 1; |
| | | } |
| | | |
| | | let nextIndex = selected + 1; |
| | | if (nextIndex >= colors.length) { |
| | | nextIndex = colors.length - 1; |
| | | } |
| | | |
| | | return { |
| | | color: colors[selected], |
| | | nextColor: colors[nextIndex], |
| | | range: range[selected], |
| | | nextRange: range[nextIndex] |
| | | }; |
| | | }, |
| | | |
| | | getCustomColor: function (data, min, max) { |
| | | var per = (max - min) / this._custom.length; |
| | | var i = parseInt(data / per); |
| | | var i = parseInt((data - min) / per); |
| | | if (i >= this._custom.length) { |
| | | i = this._custom.length - 1; |
| | | } |
| | | return this._custom[i]; |
| | | }, |
| | | |
| | | /** |
| | | * 获取分析图例 |
| | | */ |
| | | refreshLegend: function (eId, name, animation, type, min, max) { |
| | | var legend = $('#' + eId); |
| | | legend.empty(); |
| | | |
| | | var r = this._legend_r[name]; |
| | | var c = this._legend_c[name]; |
| | | // 没有找到标准图例的因子,默认使用自定义范围图例 |
| | | if (r == undefined) { |
| | | type = this.C_TYPE; |
| | | } |
| | | var range = []; |
| | | if (type != this.S_TYPE && min != undefined && max != undefined) { |
| | | var count = this._custom.length; |
| | | var per = (max - min) / count; |
| | | for (let i = 0; i < count; i++) { |
| | | range.push([(min + per * i).toFixed(1), this._custom[i]]); |
| | | } |
| | | } else { |
| | | for (let i = 0; i < r.length; i++) { |
| | | range.push([r[i], c[i]]); |
| | | } |
| | | getCustomColorAndNext: function (data, min, max) { |
| | | if (!data) { |
| | | return { |
| | | color: [0, 0, 0, 0], |
| | | nextColor: [0, 0, 0, 0], |
| | | range: 0, |
| | | nextRange: 0 |
| | | }; |
| | | } |
| | | |
| | | for (let i = 0; i < range.length; i++) { |
| | | const r = range[i]; |
| | | const nextR = range[i + 1]; |
| | | var div1 = $('<div></div>'); |
| | | div1.addClass('flexbox align-items margin-top'); |
| | | var div2 = $('<div></div>'); |
| | | div2.addClass('rectangle'); |
| | | // 将数据按照颜色数量分隔,求出每一段的数据偏移量 |
| | | var per = (max - min) / (this._custom.length - 1); |
| | | // 计算当前数据所在的分段范围 |
| | | var i = parseInt((data - min) / per); |
| | | // 如果是最大值,同样分割到最后一段 |
| | | if (i == this._custom.length - 1) i--; |
| | | var range = min + i * per; |
| | | |
| | | var color = r[1]; |
| | | var bgcolor = |
| | | 'rgba(' + |
| | | color[0] * 255 + |
| | | ', ' + |
| | | color[1] * 255 + |
| | | ', ' + |
| | | color[2] * 255 + |
| | | ', ' + |
| | | color[3] + |
| | | ')'; |
| | | div2.css('background-color', bgcolor); |
| | | var div3 = $('<div></div>'); |
| | | var d; |
| | | if (nextR != undefined) { |
| | | d = r[0] + ' ~' + nextR[0] + ' ' + Util.factorUnit2[name]; |
| | | } else { |
| | | d = |
| | | ' > ' + |
| | | r[0] + |
| | | ' ' + |
| | | Util.factorUnit2[name]; |
| | | } |
| | | div3.append(d); |
| | | div1.append(div2); |
| | | div1.append(div3); |
| | | legend.append(div1); |
| | | } |
| | | let nextIndex = i + 1; |
| | | let nextRange = min + nextIndex * per; |
| | | |
| | | if (animation == false) { |
| | | return; |
| | | } |
| | | legend.hide('fast', function () { |
| | | setTimeout(() => { |
| | | legend.show('fast'); |
| | | }, 500); |
| | | }); |
| | | return { |
| | | color: this._custom[i], |
| | | nextColor: this._custom[nextIndex], |
| | | range, |
| | | nextRange |
| | | }; |
| | | } |
| | | }; |
| | | |