本文整理汇总了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
}
示例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)
}
}