56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { BaseMathDrawService } from './baseMathDraw';
|
|
import { drawNumberColorContent } from './numberColorContentDraw';
|
|
|
|
/**
|
|
* 按数字涂颜色绘制服务
|
|
* 组合使用基础绘制服务和内容区域绘制服务
|
|
*/
|
|
class NumberColorDraw extends BaseMathDrawService {
|
|
colorData: {
|
|
numbers: number[];
|
|
} | null;
|
|
|
|
constructor(
|
|
canvas: Canvas,
|
|
ctx: RenderingContext,
|
|
options?: Record<string, any>,
|
|
) {
|
|
super(canvas, ctx, options);
|
|
this.colorData = null;
|
|
}
|
|
|
|
async draw(
|
|
colorData: { numbers: number[] },
|
|
patternType: string = 'circle', // 'circle' 或 'caterpillar'
|
|
) {
|
|
if (!colorData || !colorData.numbers) {
|
|
return;
|
|
}
|
|
|
|
this.setPrintConfig();
|
|
this.colorData = colorData;
|
|
this.clear();
|
|
this.setPaper();
|
|
|
|
// 绘制Header
|
|
if (this.headerType !== 'minimal') {
|
|
await this.drawHeader();
|
|
} else {
|
|
this.drawMiniHeader();
|
|
}
|
|
|
|
// 绘制内容区域(按数字涂颜色)
|
|
this.drawDivider();
|
|
await drawNumberColorContent({
|
|
canvas: this.canvas,
|
|
ctx: this.ctx,
|
|
colorData: this.colorData,
|
|
canvasWidth: this.canvasWidth,
|
|
startY: this.currentY,
|
|
patternType,
|
|
});
|
|
}
|
|
}
|
|
|
|
export default NumberColorDraw;
|