createCustomDivides static method

List<NamedLine> createCustomDivides(
  1. List<double> custom, {
  2. NamedLine? fromStartLine,
  3. NamedLine? toEndLine,
  4. bool includeStartEnd = false,
})

创建自定义线(占首尾线区间比值 < 1)

Implementation

static List<NamedLine> createCustomDivides(List<double> custom, {
  NamedLine? fromStartLine,
  NamedLine? toEndLine,
  bool includeStartEnd = false}){
  NamedLine fromStart = fromStartLine ?? NamedLine.percent(0.0, name: NAME_START);
  NamedLine toEnd = toEndLine ?? NamedLine.percent(1.0, name: NAME_END);
  assert(custom.isNotEmpty);
  var excludeStartEnd =  custom.indexed.map<NamedLine>((indexed){
    // var stepPercent = (toEnd.percent - fromStart.percent) / count;
    percentGetter(size) => (toEnd.percentGetter(size) - fromStart.percentGetter(size)) * indexed.$2;
    return NamedLine.getter(
      percentGetter,
      name: '${indexed.$1}/$NAME_CUSTOM:(1/1)=>${percentGetter(Size.square(1.0))}',
    );
  }).toList();
  return includeStartEnd ? [
    NamedLine.rename(rename: '$NAME_CUSTOM-$NAME_START', copy: fromStart),
    ... excludeStartEnd,
    NamedLine.rename(rename: '$NAME_CUSTOM-$NAME_END', copy: toEnd),
  ]: excludeStartEnd;
}