riku
2024-05-06 1534aee0339dee8000cdd26c21797cf3ad391f7a
src/model/Legend.js
@@ -215,79 +215,6 @@
      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]]);
      }
    }
    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 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] + '&nbsp;~' + nextR[0] + '&nbsp;' + Util.factorUnit2[name];
      } else {
        d =
          '&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp;' +
          r[0] +
          ' &nbsp;' +
          Util.factorUnit2[name];
      }
      div3.append(d);
      div1.append(div2);
      div1.append(div3);
      legend.append(div1);
    }
    if (animation == false) {
      return;
    }
    legend.hide('fast', function () {
      setTimeout(() => {
        legend.show('fast');
      }, 500);
    });
  }
};