addEntryByIndex method

  1. @override
bool addEntryByIndex(
  1. int index,
  2. T? e
)
override

It's best not to use this method because it will cause the points to be unevenly distributed in x axis. the added entry's x value must be in range of Pre's x value(Pre : Entry at index - 1) and Cur's x value(Cur: Entry at index).

Implementation

@override
bool addEntryByIndex(int index, T? e) {
  // TODO : should be optional? T?e
  if (index < 0 || index > getEntryCount()) {
    return false;
  }

  List<T?>? valueDatas = values;
  if (getEntryCount() == 0) {
    return addEntry(e);
  }

  if (index == 0) {
    T cur = valueDatas![index]!;
    if (e!.x >= cur.x) {
      return false;
    }
  } else if (index == getEntryCount()) {
    T pre = valueDatas![index - 1]!;
    if (e!.x <= pre.x) {
      return false;
    }
  } else {
    T cur = valueDatas![index]!;
    var pre = valueDatas[index - 1];
    if (e!.x >= cur.x || e.x <= pre!.x) {
      return false;
    }
  }

  calcMinMax1(e);

  valueDatas.insert(index, e);

  return true;
}