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


TypeScript arrayable.max函數代碼示例

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


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

示例1: _hit_point

  protected _hit_point(geometry: PointGeometry): Selection {
    let {sx, sy} = geometry

    const x = this.renderer.xscale.invert(sx)
    const y = this.renderer.yscale.invert(sy)

    const scenter_x = []
    for (let i = 0, end = this.sx0.length; i < end; i++) {
      scenter_x.push(this.sx0[i] + this.sw[i]/2)
    }

    const scenter_y = []
    for (let i = 0, end = this.sy1.length; i < end; i++) {
      scenter_y.push(this.sy1[i] + this.sh[i]/2)
    }

    const max_x2_ddist = max(this._ddist(0, scenter_x, this.ssemi_diag))
    const max_y2_ddist = max(this._ddist(1, scenter_y, this.ssemi_diag))

    const x0 = x - max_x2_ddist
    const x1 = x + max_x2_ddist
    const y0 = y - max_y2_ddist
    const y1 = y + max_y2_ddist

    const hits = []

    const bbox = hittest.validate_bbox_coords([x0, x1], [y0, y1])
    for (const i of this.index.indices(bbox)) {
      let height_in: boolean, width_in: boolean
      if (this._angle[i]) {
        const s = Math.sin(-this._angle[i])
        const c = Math.cos(-this._angle[i])
        const px = c*(sx - this.sx[i]) - s*(sy - this.sy[i]) + this.sx[i]
        const py = s*(sx - this.sx[i]) + c*(sy - this.sy[i]) + this.sy[i]
        sx = px
        sy = py
        width_in = Math.abs(this.sx[i] - sx) <= this.sw[i]/2
        height_in = Math.abs(this.sy[i] - sy) <= this.sh[i]/2
      } else {
        width_in = (sx - this.sx0[i] <= this.sw[i]) && (sx - this.sx0[i] >= 0)
        height_in = (sy - this.sy1[i] <= this.sh[i]) && (sy - this.sy1[i] >= 0)
      }

      if (height_in && width_in)
        hits.push(i)
    }

    const result = hittest.create_empty_hit_test_result()
    result.indices = hits
    return result
  }
開發者ID:Zyell,項目名稱:bokeh,代碼行數:51,代碼來源:rect.ts

示例2: min

  protected _v_compute<T>(data: Arrayable<number>, values: Arrayable<T>,
      palette: Arrayable<T>, colors: {nan_color: T, low_color?: T, high_color?: T}): void {
    const {nan_color, low_color, high_color} = colors

    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

    for (let i = 0, end = data.length; i < end; i++) {
      const d = data[i]

      // Check NaN
      if (isNaN(d)) {
        values[i] = nan_color
        continue
      }

      if (d > high) {
        values[i] = high_color != null ? high_color : 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[i] = palette[max_key]
        continue
      }

      if (d < low) {
        values[i] = low_color != null ? low_color : 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[i] = palette[key]
    }
  }
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:48,代碼來源:log_color_mapper.ts

示例3: min

  protected _v_compute<T>(data: Arrayable<number>, values: Arrayable<T>,
      palette: Arrayable<T>, colors: {nan_color: T, low_color?: T, high_color?: T}): void {
    const {nan_color, low_color, high_color} = colors

    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 norm_factor = 1 / (high - low)
    const normed_interval = 1 / palette.length

    for (let i = 0, end = data.length; i < end; i++) {
      const d = data[i]

      if (isNaN(d)) {
        values[i] = 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[i] = palette[max_key]
        continue
      }

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


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