当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript types.isNumber函数代码示例

本文整理汇总了TypeScript中core/util/types.isNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumber函数的具体用法?TypeScript isNumber怎么用?TypeScript isNumber使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isNumber函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: compute

 compute(x: number | Factor): number {
   if (this.range instanceof FactorRange)
     return this._compute(this.range.synthetic(x))
   else if (isNumber(x))
     return this._compute(x)
   else
     throw new Error("unexpected")
 }
开发者ID:Zyell,项目名称:bokeh,代码行数:8,代码来源:jitter.ts

示例2: patch_to_column

export function patch_to_column(col: Arrayable, patch: Patch[], shapes: Shape[]): Set<number> {
  const patched: Set<number> = new Set()
  let patched_range = false

  for (const [ind, val] of patch) {

    // make the single index case look like the length-3 multi-index case
    let item: Arrayable, shape: Shape
    let index: [number, number | Slice, number | Slice]
    let value: unknown[]
    if (isArray(ind)) {
      const [i] = ind
      patched.add(i)
      shape = shapes[i]
      item = col[i]
      value = val as unknown[]

      // this is basically like NumPy's "newaxis", inserting an empty dimension
      // makes length 2 and 3 multi-index cases uniform, so that the same code
      // can handle both
      if (ind.length === 2) {
        shape = [1, shape[0]]
        index = [ind[0], 0, ind[1]]
      } else
        index = ind
    } else  {
      if (isNumber(ind)) {
        value = [val]
        patched.add(ind)
      } else {
        value = val as unknown[]
        patched_range = true
      }

      index = [0, 0, ind]
      shape = [1, col.length]
      item = col
    }

    // now this one nested loop handles all cases
    let flat_index = 0
    const [istart, istop, istep] = slice(index[1], shape[0])
    const [jstart, jstop, jstep] = slice(index[2], shape[1])

    for (let i = istart; i < istop; i += istep) {
      for (let j = jstart; j < jstop; j += jstep) {
        if (patched_range) {
          patched.add(j)
        }
        item[(i*shape[1]) + j] = value[flat_index]
        flat_index++
      }
    }
  }

  return patched
}
开发者ID:jsignell,项目名称:bokeh,代码行数:57,代码来源:column_data_source.ts

示例3: _convert_color

export function _convert_color(color: string | number): number {
  if (isNumber(color))
    return color
  if (color[0] != "#")
    color = color2hex(color)
  if (color.length != 9)
    color = color + 'ff'
  return parseInt(color.slice(1), 16)
}
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:9,代码来源:color_mapper.ts

示例4: function

 const _convert = function(value) {
   if (isNumber(value)) {
     return value;
   } else {
     if (value.length !== 9) {
       value = value + 'ff';
     }
     return parseInt(value.slice(1), 16);
   }
 };
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:10,代码来源:color_mapper.ts

示例5: function

export const patch_to_column = function(col, patch, shapes) {
  const patched = new Set()
  let patched_range = false

  for (let [ind, value] of patch) {

    // make the single index case look like the length-3 multi-index case
    let  item, shape
    if (!isArray(ind)) {
      if (isNumber(ind)) {
        value = [value]
        patched.push(ind)
      } else {
        patched_range = true
      }

      ind = [0, 0, ind]
      shape = [1, col.length]
      item = col

    } else {
      patched.push(ind[0])
      shape = shapes[ind[0]]
      item = col[ind[0]]
    }

    // this is basically like NumPy's "newaxis", inserting an empty dimension
    // makes length 2 and 3 multi-index cases uniform, so that the same code
    // can handle both
    if (ind.length === 2) {
      shape = [1, shape[0]]
      ind = [ind[0], 0, ind[1]]
    }

    // now this one nested loop handles all cases
    let flat_index = 0
    const [istart, istop, istep] = slice(ind[1], shape[0])
    const [jstart, jstop, jstep] = slice(ind[2], shape[1])

    for (let i = istart; i < istop; i += istep) {
      for (let j = jstart; j < jstop; j += jstep) {
        if (patched_range) {
          patched.push(j)
        }
        item[(i*shape[1]) + j] = value[flat_index]
        flat_index++
      }
    }
  }

  return patched
}
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:52,代码来源:column_data_source.ts

示例6: slice

export function slice(ind: number | Slice, length: number): [number, number, number] {
  let start: number, step: number, stop: number

  if (isNumber(ind)) {
    start = ind
    stop  = ind + 1
    step  = 1
  } else {
    start = ind.start != null ? ind.start : 0
    stop  = ind.stop  != null ? ind.stop  : length
    step  = ind.step  != null ? ind.step  : 1
  }

  return [start, stop, step]
}
开发者ID:jsignell,项目名称:bokeh,代码行数:15,代码来源:column_data_source.ts

示例7: loc

  get loc(): number {
    if (this.fixed_location != null) {
      if (isNumber(this.fixed_location)) {
        return this.fixed_location
      }
      const [, cross_range] = this.ranges
      if (cross_range instanceof FactorRange) {
        return cross_range.synthetic(this.fixed_location)
      }
      throw new Error("unexpected")

    }

    const [, cross_range] = this.ranges

    switch (this.panel.side) {
      case 'left':
      case 'below':
        return cross_range.start
      case 'right':
      case 'above':
        return cross_range.end
    }
  }
开发者ID:,项目名称:,代码行数:24,代码来源:

示例8: doFormat

  doFormat(ticks, _axis) {
    let labels;
    if (ticks.length === 0) {
      return [];
    }

    let zero_eps = 0;
    if (ticks.length >= 2) {
      zero_eps = Math.abs(ticks[1] - ticks[0]) / 10000;
    }

    let need_sci = false;
    if (this.use_scientific) {
      for (const tick of ticks) {
        const tick_abs = Math.abs(tick);
        if ((tick_abs > zero_eps) &&
            ((tick_abs >= this.scientific_limit_high) ||
            (tick_abs <= this.scientific_limit_low))) {
          need_sci = true;
          break;
        }
      }
    }

    const { precision } = this;

    if ((precision == null) || isNumber(precision)) {
      labels = new Array(ticks.length);
      if (need_sci) {
        for (let i = 0, end = ticks.length; i < end; i++) {
          labels[i] = ticks[i].toExponential(precision || undefined);
        }
      } else {
        for (let i = 0, end = ticks.length; i < end; i++) {
          labels[i] = ticks[i].toFixed(precision || undefined).replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, "");
        }
      }
      return labels;

    } else if (precision === 'auto') {
      labels = new Array(ticks.length);
      for (let x = this.last_precision, asc = this.last_precision <= 15; asc ? x <= 15 : x >= 15; asc ? x++ : x--) {
        let is_ok = true;
        if (need_sci) {
          for (let i = 0, end = ticks.length; i < end; i++) {
            labels[i] = ticks[i].toExponential(x);
            if (i > 0) {
              if (labels[i] === labels[i-1]) {
                is_ok = false;
                break;
              }
            }
          }
          if (is_ok) {
            break;
          }
        } else {
          for (let i = 0, end = ticks.length; i < end; i++) {
            labels[i] = ticks[i].toFixed(x).replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, "");
            if (i > 0) {
              if (labels[i] === labels[i-1]) {
                is_ok = false;
                break;
              }
            }
          }
          if (is_ok) {
            break;
          }
        }

        if (is_ok) {
          this.last_precision = x;
          return labels;
        }
      }
    }

    return labels;
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:80,代码来源:basic_tick_formatter.ts


注:本文中的core/util/types.isNumber函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。