當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript array.min函數代碼示例

本文整理匯總了TypeScript中core/util/array.min函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript min函數的具體用法?TypeScript min怎麽用?TypeScript min使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了min函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _index_data

  protected _index_data(): SpatialIndex {
    const points = []
    for (let i = 0, end = this._xs.length; i < end; i++) {
      if (this._xs[i] == null || this._xs[i].length === 0)
        continue

      const _xsi = this._xs[i]
      const xs: number[] = []
      for (let j = 0, n = _xsi.length; j < n; j++) {
        const x = _xsi[j]
        if (!isStrictNaN(x))
          xs.push(x)
      }

      const _ysi = this._ys[i]
      const ys: number[] = []
      for (let j = 0, n = _ysi.length; j < n; j++) {
        const y = _ysi[j]
        if (!isStrictNaN(y))
          ys.push(y)
      }

      const [minX, maxX] = [min(xs), max(xs)]
      const [minY, maxY] = [min(ys), max(ys)]

      points.push({minX, minY, maxX, maxY, i})
    }

    return new SpatialIndex(points)
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:30,代碼來源:multi_line.ts

示例2: _index_hole_data

  protected _index_hole_data(): SpatialIndex {
    // need advice on how to use this sure if this could be more useful
    const points = []
    for (let i = 0, end = this._xs.length; i < end; i++) {
      for (let j = 0, endj = this._xs[i].length; j < endj; j++) {
        if (this._xs[i][j].length > 1 ) {
          for (let k = 1, endk = this._xs[i][j].length; k < endk; k++) {
            const xs = this._xs[i][j][k]  // only use holes
            const ys = this._ys[i][j][k]  // only use holes

            if (xs.length == 0)
              continue

            points.push({
              minX: min(xs),
              minY: min(ys),
              maxX: max(xs),
              maxY: max(ys),
              i,
            })
          }
        }
      }
    }
    return new SpatialIndex(points)
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:26,代碼來源:multi_polygons.ts

示例3: _index_data

  protected _index_data(): SpatialIndex {
    const xss = this._build_discontinuous_object(this._xs as any) // XXX
    const yss = this._build_discontinuous_object(this._ys as any) // XXX

    const points = []
    for (let i = 0, end = this._xs.length; i < end; i++) {
      for (let j = 0, endj = xss[i].length; j < endj; j++) {
        const xs = xss[i][j]
        const ys = yss[i][j]

        if (xs.length == 0)
          continue

        points.push({
          minX: min(xs),
          minY: min(ys),
          maxX: max(xs),
          maxY: max(ys),
          i,
        })
      }
    }

    return new SpatialIndex(points)
  }
開發者ID:gully,項目名稱:bokeh,代碼行數:25,代碼來源:patches.ts

示例4: compute

  compute(x: number): number {
    this.sort(false)

    if (this.clip) {
      if (x < this._x_sorted[0] || x > this._x_sorted[this._x_sorted.length-1])
        return NaN
    } else {
      if (x < this._x_sorted[0])
        return this._y_sorted[0]
      if (x > this._x_sorted[this._x_sorted.length-1])
        return this._y_sorted[this._y_sorted.length-1]
    }

    let ind: number
    switch (this.mode) {
      case "after": {
        ind = find_last_index(this._x_sorted, num => x >= num)
        break
      }
      case "before": {
        ind = find_index(this._x_sorted, num => x <= num)
        break
      }
      case "center": {
        const diffs = this._x_sorted.map((tx) => Math.abs(tx - x))
        const mdiff = min(diffs)
        ind = find_index(diffs, num => mdiff === num)
        break
      }
      default:
        throw new Error(`unknown mode: ${this.mode}`)
    }

    return ind != -1 ? this._y_sorted[ind] : NaN
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:35,代碼來源:step_interpolator.ts

示例5: _get_values

  _get_values(data: number[], palette: number[], image_glyph: boolean = false): number[] {
    const n = palette.length;
    const low = this.low != null ? this.low : min(data);
    const high = this.high != null ? this.high : max(data);
    const scale = n / (log1p(high) - log1p(low));  // subtract the low offset
    const max_key = palette.length - 1;
    const values = [];

    const nan_color = image_glyph ? this._nan_color : this.nan_color;
    const high_color = image_glyph ? this._high_color : this.high_color;
    const low_color = image_glyph ? this._low_color : this.low_color;

    for (const d of data) {
      // Check NaN
      if (isNaN(d)) {
        values.push(nan_color);
        continue;
      }

      if (d > high) {
        if (this.high_color != null) {
          values.push(high_color);
        } else {
          values.push(palette[max_key]);
        }
        continue;
      }

      // This handles the edge case where d == high, since the code below maps
      // values exactly equal to high to palette.length, which is greater than
      // max_key
      if (d === high) {
        values.push(palette[max_key]);
        continue;
      }

      if (d < low) {
        if (this.low_color != null) {
          values.push(low_color);
        } else {
          values.push(palette[0]);
        }
        continue;
      }

      // Get the key
      const log = log1p(d) - log1p(low);  // subtract the low offset
      let key = Math.floor(log * scale);

      // Deal with upper bound
      if (key > max_key) {
        key = max_key;
      }

      values.push(palette[key]);
    }
    return values;
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:58,代碼來源:log_color_mapper.ts

示例6: _get_dim_limits

  // utility function to get limits along both dimensions, given
  // optional dimensional constraints
  _get_dim_limits([sx0, sy0]: [number, number], [sx1, sy1]: [number, number],
      frame: CartesianFrame, dims: Dimensions): [[number, number], [number, number]] {

    const hr = frame.bbox.h_range
    let sxlim: [number, number]
    if (dims == 'width' || dims == 'both') {
      sxlim = [min([sx0, sx1]),           max([sx0, sx1])]
      sxlim = [max([sxlim[0], hr.start]), min([sxlim[1], hr.end])]
    } else
      sxlim = [hr.start, hr.end]

    const vr = frame.bbox.v_range
    let sylim: [number, number]
    if (dims == 'height' || dims == 'both') {
      sylim = [min([sy0, sy1]),           max([sy0, sy1])]
      sylim = [max([sylim[0], vr.start]), min([sylim[1], vr.end])]
    } else
      sylim = [vr.start, vr.end]

    return [sxlim, sylim]
  }
開發者ID:Zyell,項目名稱:bokeh,代碼行數:23,代碼來源:tool.ts

示例7: _index_data

  protected _index_data(): SpatialIndex {
    const points = []
    for (let i = 0, end = this._xs.length; i < end; i++) {
      for (let j = 0, endj = this._xs[i].length; j < endj; j++) {
        const xs = this._xs[i][j][0]  // do not use holes
        const ys = this._ys[i][j][0]  // do not use holes

        if (xs.length == 0)
          continue

        points.push({
          minX: min(xs),
          minY: min(ys),
          maxX: max(xs),
          maxY: max(ys),
          i,
        })
      }
    }
    this.hole_index = this._index_hole_data()  // should this be set here?
    return new SpatialIndex(points)
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:22,代碼來源:multi_polygons.ts

示例8: _index_data

  _index_data() {
    const xss = this._build_discontinuous_object(this._xs);
    const yss = this._build_discontinuous_object(this._ys);

    const points = [];
    for (let i = 0, end = this._xs.length; i < end; i++) {
      for (let j = 0, endj = xss[i].length; j < endj; j++) {
        const xs = xss[i][j];
        const ys = yss[i][j];
        if (xs.length === 0) {
          continue;
        }
        points.push({
          minX: min(xs),
          minY: min(ys),
          maxX: max(xs),
          maxY: max(ys),
          i,
        });
      }
    }

    return new RBush(points);
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:24,代碼來源:patches.ts

示例9: _get_values

  _get_values(data: number[], palette: number[], image_glyph: boolean = false): number[] {
    const low = this.low != null ? this.low : min(data);
    const high = this.high != null ? this.high : max(data);
    const max_key = palette.length - 1;
    const values = [];

    const nan_color = image_glyph ? this._nan_color : this.nan_color;
    const low_color = image_glyph ? this._low_color : this.low_color;
    const high_color = image_glyph ? this._high_color : this.high_color;

    const norm_factor = 1 / (high - low);
    const normed_interval = 1 / palette.length;

    for (const d of data) {
      if (isNaN(d)) {
        values.push(nan_color);
        continue;
      }

      // This handles the edge case where d == high, since the code below maps
      // values exactly equal to high to palette.length, which is greater than
      // max_key
      if (d === high) {
        values.push(palette[max_key]);
        continue;
      }

      const normed_d = (d - low) * norm_factor;
      const key = Math.floor(normed_d / normed_interval);
      if (key < 0) {
        if (this.low_color != null) {
          values.push(low_color);
        } else {
          values.push(palette[0]);
        }
      } else if (key > max_key) {
        if (this.high_color != null) {
          values.push(high_color);
        } else {
          values.push(palette[max_key]);
        }
      } else {
        values.push(palette[key]);
      }
    }
    return values;
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:47,代碼來源:linear_color_mapper.ts

示例10: compute

  compute(x) {
    // Apply the transform to a single value
    let descending, ret;
    this.sort(descending = false);

    if (this.clip === true) {
      if ((x < this._x_sorted[0]) || (x > this._x_sorted[this._x_sorted.length-1])) {
        return(null);
      }
    } else {
      if (x < this._x_sorted[0]) {
        return this._y_sorted[0];
      }
      if (x > this._x_sorted[this._x_sorted.length-1]) {
        return this._y_sorted[this._y_sorted.length-1];
      }
    }

    let ind = -1;
    if (this.mode === "after") {
      ind = findLastIndex(this._x_sorted, num => x >= num);
    }

    if (this.mode === "before") {
      ind = findIndex(this._x_sorted, num => x <= num);
    }

    if (this.mode === "center") {
      const diffs = (this._x_sorted.map((tx) => Math.abs(tx - x)));
      const mdiff = min(diffs);
      ind = findIndex(diffs, num => mdiff === num);
    }

    if (ind !== -1) {
      ret = this._y_sorted[ind];
    } else {
      ret = null;
    }

    return(ret);
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:41,代碼來源:step_interpolator.ts


注:本文中的core/util/array.min函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。