From 7b1293cec33b47680f08756bd1f8518d3cb1a729 Mon Sep 17 00:00:00 2001 From: Riku <risaku@163.com> Date: 星期三, 01 一月 2025 22:33:32 +0800 Subject: [PATCH] 新增对比色 --- src/model/Legend.js | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/model/Legend.js b/src/model/Legend.js index 5021b16..e92ebd1 100644 --- a/src/model/Legend.js +++ b/src/model/Legend.js @@ -148,7 +148,7 @@ [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) { @@ -297,7 +297,44 @@ 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 + }; + } + + // if (data == min) { + // console.log(data); + // } + + var per = (max - min) / this._custom.length; + var i = parseInt((data - min) / per); + var range = min + i * per + if (i >= this._custom.length - 1) { + i = this._custom.length - 2; + range = min + i * per + } + + let nextIndex = i + 1; + let nextRange = min + nextIndex * per + if (nextIndex > this._custom.length - 1) { + nextIndex = this._custom.length - 1; + nextRange = min + nextIndex * per + } + + return { + color: this._custom[i], + nextColor: this._custom[nextIndex], + range, + nextRange + }; + }, }; export { Legend }; -- Gitblit v1.9.3