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