riku
2025-01-03 68ba3376731aa7a5760ba5fce1dc6ba0c80982b4
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,6 +297,35 @@
      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
    };
  }
};