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


TypeScript visuals.Text类代码示例

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


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

示例1: _oriented_labels_extent

  protected _oriented_labels_extent(labels: string[], orient: Orient | number,
                                    side: Side, standoff: number, visuals: Text): number {
    if (labels.length == 0)
      return 0

    const ctx = this.plot_view.canvas_view.ctx
    visuals.set_value(ctx)

    let hscale: number
    let angle: number

    if (isString(orient)) {
      hscale = 1
      angle = this.model.panel.get_label_angle_heuristic(orient)
    } else {
      hscale = 2
      angle = -orient
    }
    angle = Math.abs(angle)

    const c = Math.cos(angle)
    const s = Math.sin(angle)

    let extent = 0

    for (let i = 0; i < labels.length; i++) {
      const w = ctx.measureText(labels[i]).width * 1.1
      const h = ctx.measureText(labels[i]).ascent * 0.9

      let val: number

      if (side == "above" || side == "below")
        val = w*s + (h/hscale)*c
      else
        val = w*c + (h/hscale)*s

      // update extent if current value is larger
      if (val > extent)
        extent = val
    }

    // only apply the standoff if we already have non-zero extent
    if (extent > 0)
      extent += standoff

    return extent
  }
开发者ID:Zyell,项目名称:bokeh,代码行数:47,代码来源:axis.ts

示例2: _draw_oriented_labels

  protected _draw_oriented_labels(ctx: Context2d, labels: string[], coords: Coords,
                                  orient: Orient | number, _side: Side, standoff: number,
                                  visuals: Text, units: SpatialUnits = "data"): void {
    if (!visuals.doit || labels.length == 0)
      return

    let sxs, sys: Arrayable<number>
    let xoff, yoff: number

    if (units == "screen") {
      [sxs, sys] = coords;
      [xoff, yoff] = [0, 0];
    } else {
      const [dxs, dys] = coords;
      [sxs, sys] = this.plot_view.map_to_screen(dxs, dys, this.model.x_range_name, this.model.y_range_name);
      [xoff, yoff] = this.model.offsets;
    }

    const [nx, ny] = this.model.normals

    const nxd = nx * (xoff + standoff)
    const nyd = ny * (yoff + standoff)

    visuals.set_value(ctx)
    this.model.panel.apply_label_text_heuristics(ctx, orient)

    let angle: number
    if (isString(orient))
      angle = this.model.panel.get_label_angle_heuristic(orient)
    else
      angle = -orient

    for (let i = 0; i < sxs.length; i++) {
      const sx = Math.round(sxs[i] + nxd)
      const sy = Math.round(sys[i] + nyd)

      ctx.translate(sx, sy)
      ctx.rotate(angle)
      ctx.fillText(labels[i], 0, 0)
      ctx.rotate(-angle)
      ctx.translate(-sx, -sy)
    }
  }
开发者ID:Zyell,项目名称:bokeh,代码行数:43,代码来源:axis.ts


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