| | |
| | | [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) { |
| | |
| | | }, |
| | | |
| | | 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; |
| | | let d1 = d; |
| | | if (name == 'CO') { |
| | | d1 *= 1000; |
| | | } |
| | |
| | | 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 (name == 'CO') { |
| | | d1 *= 1000; |
| | | } |
| | | 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]; |
| | | }, |
| | | |
| | | getCustomColorAndNext: function (data, min, max) { |
| | | if (!data) { |
| | | return { |
| | | color: [0, 0, 0, 0], |
| | | nextColor: [0, 0, 0, 0], |
| | | range: 0, |
| | | nextRange: 0 |
| | | }; |
| | | } |
| | | |
| | | // 将数据按照颜色数量分隔,求出每一段的数据偏移量 |
| | | 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; |
| | | |
| | | let nextIndex = i + 1; |
| | | let nextRange = min + nextIndex * per; |
| | | |
| | | return { |
| | | color: this._custom[i], |
| | | nextColor: this._custom[nextIndex], |
| | | range, |
| | | nextRange |
| | | }; |
| | | } |
| | | }; |
| | | |