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


TypeScript arrayable.map函数代码示例

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


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

示例1: _map_data

 protected _map_data(): void {
   // XXX: Order is important here: size is always present (at least
   // a default), but radius is only present if a user specifies it.
   if (this._radius != null) {
     if (this.model.properties.radius.spec.units == "data") {
       const rd = this.model.properties.radius_dimension.spec.value
       switch (rd) {
         case "x": {
           this.sradius = this.sdist(this.renderer.xscale, this._x, this._radius)
           break
         }
         case "y": {
           this.sradius = this.sdist(this.renderer.yscale, this._y, this._radius)
           break
         }
         case "max": {
           const sradius_x = this.sdist(this.renderer.xscale, this._x, this._radius)
           const sradius_y = this.sdist(this.renderer.yscale, this._y, this._radius)
           this.sradius = map(sradius_x, (s, i) => Math.max(s, sradius_y[i]))
           break
         }
         case "min": {
           const sradius_x = this.sdist(this.renderer.xscale, this._x, this._radius)
           const sradius_y = this.sdist(this.renderer.yscale, this._y, this._radius)
           this.sradius = map(sradius_x, (s, i) => Math.min(s, sradius_y[i]))
           break
         }
       }
     } else {
       this.sradius = this._radius
       this.max_size = 2*this.max_radius
     }
   } else
     this.sradius = map(this._size, (s) => s/2)
 }
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:35,代码来源:circle.ts

示例2: _set_data

 protected _set_data(nvertices: number): void {
   const n = nvertices * 4;  // in bytes
   // Set buffer size
   this.vbo_x.set_size(n)
   this.vbo_y.set_size(n)
   this.vbo_a.set_size(n)
   this.vbo_s.set_size(n)
   // Upload data for x and y, apply a baked-in offset for float32 precision (issue #3795)
   // The exact value for the baked_offset does not matter, as long as it brings the data to less extreme values
   const xx = new Float64Array(this.glyph._x)
   const yy = new Float64Array(this.glyph._y)
   for (let i = 0, end = nvertices; i < end; i++) {
      xx[i] += this._baked_offset[0]
      yy[i] += this._baked_offset[1]
   }
   this.vbo_x.set_data(0, new Float32Array(xx))
   this.vbo_y.set_data(0, new Float32Array(yy))
   // Angle if available; circle does not have angle. If we don't set data, angle is default 0 in glsl
   if (this.glyph._angle != null) {
     this.vbo_a.set_data(0, new Float32Array(this.glyph._angle))
   }
   // Radius is special; some markes allow radius in data-coords instead of screen coords
   // @radius tells us that radius is in units, sradius is the pre-calculated screen radius
   if (this.glyph instanceof CircleView && this.glyph._radius != null)
     this.vbo_s.set_data(0, new Float32Array(map(this.glyph.sradius, (s) => s*2)))
   else
     this.vbo_s.set_data(0, new Float32Array(this.glyph._size))
 }
开发者ID:gully,项目名称:bokeh,代码行数:28,代码来源:markers.ts

示例3: draw

  draw(indices: number[], mainGlyph: MarkerView | CircleView, trans: Transform): void {
    // The main glyph has the data, *this* glyph has the visuals.
    const mainGlGlyph = mainGlyph.glglyph
    const {nvertices} = mainGlGlyph

    // Upload data if we must. Only happens for main glyph.
    if (mainGlGlyph.data_changed) {
      if (!(isFinite(trans.dx) && isFinite(trans.dy))) {
        return;  // not sure why, but it happens on init sometimes (#4367)
      }
      mainGlGlyph._baked_offset = [trans.dx, trans.dy];  // float32 precision workaround; used in _set_data() and below
      mainGlGlyph._set_data(nvertices)
      mainGlGlyph.data_changed = false
    } else if (this.glyph instanceof CircleView && this.glyph._radius != null &&
               (this.last_trans == null || trans.sx != this.last_trans.sx || trans.sy != this.last_trans.sy)) {
      // Keep screen radius up-to-date for circle glyph. Only happens when a radius is given
      this.last_trans = trans
      this.vbo_s.set_data(0, new Float32Array(map(this.glyph.sradius, (s) => s*2)))
    }

    // Update visuals if we must. Can happen for all glyphs.
    if (this.visuals_changed) {
      this._set_visuals(nvertices)
      this.visuals_changed = false
    }

    // Handle transformation to device coordinates
    // Note the baked-in offset to avoid float32 precision problems
    const baked_offset = mainGlGlyph._baked_offset
    this.prog.set_uniform('u_pixel_ratio', 'float', [trans.pixel_ratio])
    this.prog.set_uniform('u_canvas_size', 'vec2', [trans.width, trans.height])
    this.prog.set_uniform('u_offset', 'vec2', [trans.dx - baked_offset[0], trans.dy - baked_offset[1]])
    this.prog.set_uniform('u_scale', 'vec2', [trans.sx, trans.sy])

    // Select buffers from main glyph
    // (which may be this glyph but maybe not if this is a (non)selection glyph)
    this.prog.set_attribute('a_x', 'float', mainGlGlyph.vbo_x)
    this.prog.set_attribute('a_y', 'float', mainGlGlyph.vbo_y)
    this.prog.set_attribute('a_size', 'float', mainGlGlyph.vbo_s)
    this.prog.set_attribute('a_angle', 'float', mainGlGlyph.vbo_a)

    // Draw directly or using indices. Do not handle indices if they do not
    // fit in a uint16; WebGL 1.0 does not support uint32.
    if (indices.length == 0)
      return
    else if (indices.length === nvertices)
      this.prog.draw(this.gl.POINTS, [0, nvertices])
    else if (nvertices < 65535) {
      // On IE the marker size is reduced to 1 px when using an index buffer
      // A MS Edge dev on Twitter said on 24-04-2014: "gl_PointSize > 1.0 works
      // in DrawArrays; gl_PointSize > 1.0 in DrawElements is coming soon in the
      // next renderer update.
      const ua = window.navigator.userAgent
      if ((ua.indexOf("MSIE ") + ua.indexOf("Trident/") + ua.indexOf("Edge/")) > 0) {
         logger.warn('WebGL warning: IE is known to produce 1px sprites whith selections.')
       }
      this.index_buffer.set_size(indices.length*2)
      this.index_buffer.set_data(0, new Uint16Array(indices))
      this.prog.draw(this.gl.POINTS, this.index_buffer)
    } else {
      // Work around the limit that the indexbuffer must be uint16. We draw in chunks.
      // First collect indices in chunks
      const chunksize = 64000;  // 65536
      const chunks: number[][] = []
      for (let i = 0, end = Math.ceil(nvertices/chunksize); i < end; i++) {
         chunks.push([])
      }
      for (let i = 0, end = indices.length; i < end; i++) {
        const uint16_index = indices[i] % chunksize
        const chunk = Math.floor(indices[i] / chunksize)
        chunks[chunk].push(uint16_index)
      }
      // Then draw each chunk
      for (let chunk = 0, end = chunks.length; chunk < end; chunk++) {
        const these_indices = new Uint16Array(chunks[chunk])
        const offset = chunk * chunksize * 4
        if (these_indices.length === 0) {
          continue
        }
        this.prog.set_attribute('a_x', 'float', mainGlGlyph.vbo_x, 0, offset)
        this.prog.set_attribute('a_y', 'float', mainGlGlyph.vbo_y, 0, offset)
        this.prog.set_attribute('a_size', 'float', mainGlGlyph.vbo_s, 0, offset)
        this.prog.set_attribute('a_angle', 'float', mainGlGlyph.vbo_a, 0, offset)
        if (this.vbo_linewidth.used) {
          this.prog.set_attribute('a_linewidth', 'float', this.vbo_linewidth, 0, offset)
        }
        if (this.vbo_fg_color.used) {
          this.prog.set_attribute('a_fg_color', 'vec4', this.vbo_fg_color, 0, offset * 4)
        }
        if (this.vbo_bg_color.used) {
          this.prog.set_attribute('a_bg_color', 'vec4', this.vbo_bg_color, 0, offset * 4)
        }
        // The actual drawing
        this.index_buffer.set_size(these_indices.length*2)
        this.index_buffer.set_data(0, these_indices)
        this.prog.draw(this.gl.POINTS, this.index_buffer)
      }
    }
  }
开发者ID:gully,项目名称:bokeh,代码行数:99,代码来源:markers.ts

示例4: v_synthetic

 // convert an array of string factors into synthetic coordinates
 v_synthetic(xs: Arrayable<number | Factor | [string] | OffsetFactor>): Arrayable<number> {
   return map(xs, (x) => this.synthetic(x))
 }
开发者ID:jsignell,项目名称:bokeh,代码行数:4,代码来源:factor_range.ts

示例5: tick_info

  tick_info(): TickInfo {
    const image_dimensions = this._computed_image_dimensions()

    let scale_length: number
    switch (this.model.orientation) {
      case "vertical": {
        scale_length = image_dimensions.height
        break
      }
      case "horizontal": {
        scale_length = image_dimensions.width
        break
      }
      default:
        throw new Error("unreachable code")
    }

    const scale = this._tick_coordinate_scale(scale_length)
    const [i, j] = this._normals()
    const [start, end] = [this.model.color_mapper.low, this.model.color_mapper.high]

    // XXX: passing null as cross_loc probably means MercatorTickers, etc
    // will not function properly in conjunction with colorbars
    const ticks = this.model.ticker.get_ticks(start, end, null, null, this.model.ticker.desired_num_ticks)

    const majors = ticks.major
    const minors = ticks.minor

    const major_coords: [number[], number[]] = [[], []]
    const minor_coords: [number[], number[]] = [[], []]

    for (let ii = 0, _end = majors.length; ii < _end; ii++) {
      if (majors[ii] < start || majors[ii] > end)
        continue

      major_coords[i].push(majors[ii])
      major_coords[j].push(0)
    }

    for (let ii = 0, _end = minors.length; ii < _end; ii++) {
      if (minors[ii] < start || minors[ii] > end)
        continue

      minor_coords[i].push(minors[ii])
      minor_coords[j].push(0)
    }

    const labels = {major: this._format_major_labels(major_coords[i], majors)}

    const coords: {major: Coords, minor: Coords} = {
      major: [[], []],
      minor: [[], []],
    }

    coords.major[i] = scale.v_compute(major_coords[i])
    coords.minor[i] = scale.v_compute(minor_coords[i])

    coords.major[j] = major_coords[j]
    coords.minor[j] = minor_coords[j]

    // Because we want the scale to be reversed
    if (this.model.orientation == 'vertical') {
      coords.major[i] = map(coords.major[i], (coord) => scale_length - coord)
      coords.minor[i] = map(coords.minor[i], (coord) => scale_length - coord)
    }

    return {coords, labels}
  }
开发者ID:jsignell,项目名称:bokeh,代码行数:68,代码来源:color_bar.ts

示例6: render

  render(): void {
    if (!this.model.visible)
      return

    const t0 = Date.now()

    const glsupport = this.has_webgl

    this.glyph.map_data()
    const dtmap = Date.now() - t0

    const tmask = Date.now()
    // all_indices is in full data space, indices is converted to subset space
    // either by mask_data (that uses the spatial index) or manually
    let indices = this.glyph.mask_data(this.all_indices)
    if (indices.length === this.all_indices.length) {
      indices = range(0, this.all_indices.length)
    }
    const dtmask = Date.now() - tmask

    const {ctx} = this.plot_view.canvas_view
    ctx.save()

    // selected is in full set space
    const {selected} = this.model.data_source
    let selected_full_indices: number[]
    if (!selected || selected.is_empty())
      selected_full_indices = []
    else {
      if (this.glyph instanceof LineView && selected.selected_glyph === this.glyph.model)
        selected_full_indices = this.model.view.convert_indices_from_subset(indices)
      else
        selected_full_indices = selected.indices
    }

    // inspected is in full set space
    const {inspected} = this.model.data_source
    let inspected_full_indices: number[]
    if (!inspected || inspected.is_empty())
      inspected_full_indices = []
    else {
      if (inspected['0d'].glyph)
        inspected_full_indices = this.model.view.convert_indices_from_subset(indices)
      else if (inspected['1d'].indices.length > 0)
        inspected_full_indices = inspected['1d'].indices
      else
        inspected_full_indices = map(Object.keys(inspected["2d"].indices), (i) => parseInt(i))
    }

    // inspected is transformed to subset space
    const inspected_subset_indices = filter(indices, (i) => includes(inspected_full_indices, this.all_indices[i]))

    const {lod_threshold} = this.plot_model
    let glyph: GlyphView
    let nonselection_glyph: GlyphView
    let selection_glyph: GlyphView
    if ((this.model.document != null ? this.model.document.interactive_duration() > 0 : false)
        && !glsupport && lod_threshold != null && this.all_indices.length > lod_threshold) {
      // Render decimated during interaction if too many elements and not using GL
      indices = this.decimated
      glyph = this.decimated_glyph
      nonselection_glyph = this.decimated_glyph
      selection_glyph = this.selection_glyph
    } else {
      glyph = this.model.muted && this.muted_glyph != null ? this.muted_glyph : this.glyph
      nonselection_glyph = this.nonselection_glyph
      selection_glyph = this.selection_glyph
    }

    if (this.hover_glyph != null && inspected_subset_indices.length)
      indices = difference(indices, inspected_subset_indices)

    // Render with no selection
    let dtselect: number | null = null
    let trender: number
    if (!(selected_full_indices.length && this.have_selection_glyphs())) {
      trender = Date.now()
      if (this.glyph instanceof LineView) {
        if (this.hover_glyph && inspected_subset_indices.length)
          this.hover_glyph.render(ctx, this.model.view.convert_indices_from_subset(inspected_subset_indices), this.glyph)
        else
          glyph.render(ctx, this.all_indices, this.glyph)
      } else {
        glyph.render(ctx, indices, this.glyph)
        if (this.hover_glyph && inspected_subset_indices.length)
          this.hover_glyph.render(ctx, inspected_subset_indices, this.glyph)
      }
    // Render with selection
    } else {
      // reset the selection mask
      const tselect = Date.now()
      const selected_mask: {[key: number]: boolean} = {}
      for (const i of selected_full_indices) {
        selected_mask[i] = true
      }

      // intersect/different selection with render mask
      const selected_subset_indices: number[] = new Array()
      const nonselected_subset_indices: number[] = new Array()

//.........这里部分代码省略.........
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:101,代码来源:glyph_renderer.ts


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