riku
2025-03-14 8372d022614a1897120802cf1bac90d61651177f
src/model/Legend.js
@@ -292,7 +292,7 @@
  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;
    }
@@ -309,24 +309,16 @@
      };
    }
    // if (data == min) {
    //   console.log(data);
    // }
    var per = (max - min) / this._custom.length;
    // 将数据按照颜色数量分隔,求出每一段的数据偏移量
    var per = (max - min) / (this._custom.length - 1);
    // 计算当前数据所在的分段范围
    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
    }
    // 如果是最大值,同样分割到最后一段
    if (i == this._custom.length - 1) i--;
    var 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
    }
    let nextRange = min + nextIndex * per;
    return {
      color: this._custom[i],
@@ -334,7 +326,7 @@
      range,
      nextRange
    };
  },
  }
};
export { Legend };