本文整理汇总了TypeScript中core/util/canvas.Context2d类的典型用法代码示例。如果您正苦于以下问题:TypeScript Context2d类的具体用法?TypeScript Context2d怎么用?TypeScript Context2d使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context2d类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _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();
}
示例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()
}
示例3: _one_diamond
function _one_diamond(ctx: Context2d, r: number): void {
ctx.moveTo(0, r)
ctx.lineTo(r/1.5, 0)
ctx.lineTo(0, -r)
ctx.lineTo(-r/1.5, 0)
ctx.closePath()
}
示例4: function
const _one_diamond = function(ctx: Context2d, r) {
ctx.moveTo(0, r);
ctx.lineTo(r/1.5, 0);
ctx.lineTo(0, -r);
ctx.lineTo(-r/1.5, 0);
return ctx.closePath();
};
示例5: _render
protected _render(ctx: Context2d, indices: number[], {sxs, sys}: MultiPolygonsData): void {
if (this.visuals.fill.doit || this.visuals.line.doit) {
for (const i of indices) {
const [sx, sy] = [sxs[i], sys[i]]
if (this.visuals.fill.doit) {
this.visuals.fill.set_vectorize(ctx, i)
this._inner_loop(ctx, sx, sy)
ctx.fill("evenodd")
}
this.visuals.hatch.doit2(ctx, i, () => {
this._inner_loop(ctx, sx, sy)
ctx.fill("evenodd")
}, () => this.renderer.request_render())
if (this.visuals.line.doit) {
this.visuals.line.set_vectorize(ctx, i)
this._inner_loop(ctx, sx, sy)
ctx.stroke()
}
}
}
}
示例6: _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();
}
示例7: _render
_render(ctx: Context2d, indices, {image_data, sx, sy, sw, sh}) {
const old_smoothing = ctx.getImageSmoothingEnabled();
ctx.setImageSmoothingEnabled(false);
for (const i of indices) {
if ((image_data[i] == null)) {
continue;
}
if (isNaN(sx[i]+sy[i]+sw[i]+sh[i])) {
continue;
}
const y_offset = sy[i];
ctx.translate(0, y_offset);
ctx.scale(1, -1);
ctx.translate(0, -y_offset);
ctx.drawImage(image_data[i], sx[i]|0, sy[i]|0, sw[i], sh[i]);
ctx.translate(0, y_offset);
ctx.scale(1, -1);
ctx.translate(0, -y_offset);
}
return ctx.setImageSmoothingEnabled(old_smoothing);
}
示例8: _normal
_normal(ctx: Context2d, _i: number): void {
ctx.beginPath()
ctx.moveTo(0.5*this.size, this.size)
ctx.lineTo(0, 0)
ctx.lineTo(-0.5*this.size, this.size)
ctx.closePath()
}
示例9: _draw_ticks
protected _draw_ticks(ctx: Context2d, coords: Coords, tin: number, tout: number, visuals: Line): void {
if (!visuals.doit)
return
const [x, y] = coords
const [sxs, sys] = this.plot_view.map_to_screen(x, y, this.model.x_range_name, this.model.y_range_name)
const [nx, ny] = this.model.normals
const [xoff, yoff] = this.model.offsets
const [nxin, nyin] = [nx * (xoff-tin), ny * (yoff-tin)]
const [nxout, nyout] = [nx * (xoff+tout), ny * (yoff+tout)]
visuals.set_value(ctx)
for (let i = 0; i < sxs.length; i++) {
const sx0 = Math.round(sxs[i] + nxout)
const sy0 = Math.round(sys[i] + nyout)
const sx1 = Math.round(sxs[i] + nxin)
const sy1 = Math.round(sys[i] + nyin)
ctx.beginPath()
ctx.moveTo(sx0, sy0)
ctx.lineTo(sx1, sy1)
ctx.stroke()
}
}
示例10: _render
protected _render(ctx: Context2d, indices: number[], {image_data, sx, sy, sw, sh}: _ImageData): void {
const old_smoothing = ctx.getImageSmoothingEnabled()
ctx.setImageSmoothingEnabled(false)
ctx.globalAlpha = this.model.global_alpha
for (const i of indices) {
if (image_data[i] == null)
continue
if (isNaN(sx[i] + sy[i] + sw[i] + sh[i]))
continue
const y_offset = sy[i]
ctx.translate(0, y_offset)
ctx.scale(1, -1)
ctx.translate(0, -y_offset)
ctx.drawImage(image_data[i], sx[i]|0, sy[i]|0, sw[i], sh[i])
ctx.translate(0, y_offset)
ctx.scale(1, -1)
ctx.translate(0, -y_offset)
}
ctx.setImageSmoothingEnabled(old_smoothing)
}