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


TypeScript Context2d.save方法代码示例

本文整理汇总了TypeScript中core/util/canvas.Context2d.save方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Context2d.save方法的具体用法?TypeScript Context2d.save怎么用?TypeScript Context2d.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core/util/canvas.Context2d的用法示例。


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

示例1: _draw_major_labels

  _draw_major_labels(ctx: Context2d, tick_info) {
    if (!this.visuals.major_label_text.doit) {
      return;
    }

    const [nx, ny] = this.model._normals();
    const image = this.model._computed_image_dimensions();
    const [x_offset, y_offset] = [image.width * nx, image.height * ny];
    const standoff = (this.model.label_standoff + this.model._tick_extent());
    const [x_standoff, y_standoff] = [standoff*nx, standoff*ny];

    const [sx, sy] = tick_info.coords.major;

    const formatted_labels = tick_info.labels.major;

    this.visuals.major_label_text.set_value(ctx);

    ctx.save();
    ctx.translate(x_offset + x_standoff, y_offset + y_standoff);
    for (let i = 0, end = sx.length; i < end; i++) {
      ctx.fillText(formatted_labels[i],
                   Math.round(sx[i]+(nx*this.model.label_standoff)),
                   Math.round(sy[i]+(ny*this.model.label_standoff)));
    }
    return ctx.restore();
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:26,代码来源:color_bar.ts

示例2: _paint_levels

  protected _paint_levels(ctx: Context2d, levels: string[], clip_region?: FrameBox): void {
    ctx.save()

    if (clip_region != null) {
      ctx.beginPath()
      ctx.rect.apply(ctx, clip_region)
      ctx.clip()
    }

    const indices: {[key: string]: number} = {}
    for (let i = 0; i < this.model.plot.renderers.length; i++) {
      const renderer = this.model.plot.renderers[i]
      indices[renderer.id] = i
    }

    const sortKey = (renderer_view: RendererView) => indices[renderer_view.model.id]

    for (const level of levels) {
      const renderer_views = sortBy(values(this.levels[level]), sortKey)

      for (const renderer_view of renderer_views) {
        renderer_view.render()
      }
    }

    ctx.restore()
  }
开发者ID:gully,项目名称:bokeh,代码行数:27,代码来源:plot_canvas.ts

示例3: _paint_levels

  _paint_levels(ctx: Context2d, levels, clip_region = null) {
    ctx.save();

    if ((clip_region != null) && (this.model.plot.output_backend === "canvas")) {
      ctx.beginPath();
      ctx.rect.apply(ctx, clip_region);
      ctx.clip();
    }

    const indices = {};
    for (let i = 0; i < this.model.plot.renderers.length; i++) {
      const renderer = this.model.plot.renderers[i];
      indices[renderer.id] = i;
    }

    const sortKey = renderer_view => indices[renderer_view.model.id];

    for (const level of levels) {
      const renderer_views = sortBy(values(this.levels[level]), sortKey);

      for (const renderer_view of renderer_views) {
        renderer_view.render();
      }
    }

    return ctx.restore();
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:27,代码来源:plot_canvas.ts

示例4: _canvas_text

  protected _canvas_text(ctx: Context2d, text: string, sx: number, sy: number, angle: number): void {
    this.visuals.text.set_value(ctx)
    const bbox_dims = this._calculate_bounding_box_dimensions(ctx, text)

    ctx.save()

    ctx.beginPath()
    ctx.translate(sx, sy)

    if (angle)
      ctx.rotate(angle)

    ctx.rect(bbox_dims[0], bbox_dims[1], bbox_dims[2], bbox_dims[3])

    if (this.visuals.background_fill.doit) {
      this.visuals.background_fill.set_value(ctx)
      ctx.fill()
    }

    if (this.visuals.border_line.doit) {
      this.visuals.border_line.set_value(ctx)
      ctx.stroke()
    }

    if (this.visuals.text.doit) {
      this.visuals.text.set_value(ctx)
      ctx.fillText(text, 0, 0)
    }

    ctx.restore()
  }
开发者ID:Zyell,项目名称:bokeh,代码行数:31,代码来源:text_annotation.ts

示例5: _v_canvas_text

  _v_canvas_text(ctx: Context2d, i, text, sx, sy, angle) {
    this.visuals.text.set_vectorize(ctx, i);
    const bbox_dims = this._calculate_bounding_box_dimensions(ctx, text);

    ctx.save();

    ctx.beginPath();
    ctx.translate(sx, sy);
    ctx.rotate(angle);

    ctx.rect(bbox_dims[0], bbox_dims[1], bbox_dims[2], bbox_dims[3]);

    if (this.visuals.background_fill.doit) {
      this.visuals.background_fill.set_vectorize(ctx, i);
      ctx.fill();
    }

    if (this.visuals.border_line.doit) {
      this.visuals.border_line.set_vectorize(ctx, i);
      ctx.stroke();
    }

    if (this.visuals.text.doit) {
      this.visuals.text.set_vectorize(ctx, i);
      ctx.fillText(text, 0, 0);
    }

    return ctx.restore();
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:29,代码来源:label_set.ts

示例6: _draw_title

  protected _draw_title(ctx: Context2d): void {
    if (!this.visuals.title_text.doit)
      return

    ctx.save()
    this.visuals.title_text.set_value(ctx)
    ctx.fillText(this.model.title, 0, -this.model.title_standoff)
    ctx.restore()
  }
开发者ID:jsignell,项目名称:bokeh,代码行数:9,代码来源:color_bar.ts

示例7: _draw_title

  protected _draw_title(ctx: Context2d, bbox: BBox): void {
    if (!this.visuals.title_text.doit)
      return

    ctx.save()
    ctx.translate(bbox.x0, bbox.y0 + this.title_height)
    this.visuals.title_text.set_value(ctx)
    ctx.fillText(this.model.title, this.legend_padding, this.legend_padding-this.model.title_standoff)
    ctx.restore()
  }
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:10,代码来源:legend.ts

示例8: _draw_title

  _draw_title(ctx: Context2d) {
    if (!this.visuals.title_text.doit) {
      return;
    }

    ctx.save();
    this.visuals.title_text.set_value(ctx);
    ctx.fillText(this.model.title, 0, -this.model.title_standoff);
    return ctx.restore();
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:10,代码来源:color_bar.ts

示例9: _render

  _render(ctx: Context2d, indices, {sx, sy, _x_offset, _y_offset, _angle, _text}) {
    for (const i of indices) {
      if (isNaN(sx[i]+sy[i]+_x_offset[i]+_y_offset[i]+_angle[i]) || (_text[i] == null)) {
        continue;
      }

      if (this.visuals.text.doit) {
        const text = `${_text[i]}`;

        ctx.save();
        ctx.translate(sx[i] + _x_offset[i], sy[i] + _y_offset[i]);
        ctx.rotate(_angle[i]);
        this.visuals.text.set_vectorize(ctx, i);

        if (text.indexOf("\n") === -1) {
          ctx.fillText(text, 0, 0);
        } else {
          const lines = text.split("\n");

          const font = this.visuals.text.cache_select("font", i);
          const {height} = get_text_height(font);
          const line_height = this.visuals.text.text_line_height.value()*height;
          const block_height = line_height*lines.length;

          const baseline = this.visuals.text.cache_select("text_baseline", i);
          let y;
          switch (baseline) {
            case "top": {
              y = 0;
              break;
            }
            case "middle": {
              y = (-block_height/2) + (line_height/2);
              break;
            }
            case "bottom": {
              y = -block_height + line_height;
              break;
            }
            default: {
              y = 0;
              console.warn(`'${baseline}' baseline not supported with multi line text`);
            }
          }

          for (const line of lines) {
            ctx.fillText(line, 0, y);
            y += line_height;
          }
        }

        ctx.restore();
      }
    }
  }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:55,代码来源:text.ts

示例10: _generic_line_legend

 _generic_line_legend(ctx: Context2d, x0, x1, y0, y1, index) {
   ctx.save();
   ctx.beginPath();
   ctx.moveTo(x0, (y0 + y1) /2);
   ctx.lineTo(x1, (y0 + y1) /2);
   if (this.visuals.line.doit) {
     this.visuals.line.set_vectorize(ctx, index);
     ctx.stroke();
   }
   return ctx.restore();
 }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:11,代码来源:glyph.ts


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