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


TypeScript Text.set_value方法代碼示例

本文整理匯總了TypeScript中core/visuals.Text.set_value方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Text.set_value方法的具體用法?TypeScript Text.set_value怎麽用?TypeScript Text.set_value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在core/visuals.Text的用法示例。


在下文中一共展示了Text.set_value方法的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.set_value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。