2021-05-25 04:58:29 +00:00
|
|
|
import opts from './opts.js';
|
|
|
|
|
import { getData } from './data.js';
|
2021-05-25 02:39:56 +00:00
|
|
|
|
2021-11-15 14:33:45 +00:00
|
|
|
export function drawData(board, idx) {
|
2021-05-25 04:58:29 +00:00
|
|
|
const ctx = board.getContext();
|
2021-11-15 14:33:45 +00:00
|
|
|
const helperCtx = board.getHelperContext();
|
2021-05-25 04:58:29 +00:00
|
|
|
const data = getData();
|
|
|
|
|
board.clear();
|
2021-11-15 14:58:20 +00:00
|
|
|
ctx.clearRect(0, 0, opts.devicePixelRatio * opts.contextWidth, opts.devicePixelRatio * opts.contextHeight);
|
|
|
|
|
helperCtx.clearRect(0, 0, opts.devicePixelRatio * opts.contextWidth, opts.devicePixelRatio * opts.contextHeight);
|
2021-11-15 14:33:45 +00:00
|
|
|
|
2021-07-14 14:05:24 +00:00
|
|
|
// ctx.setFillStyle('#ffffff');
|
|
|
|
|
// ctx.fillRect(0, 0, opts.width, opts.height);
|
2021-11-15 14:33:45 +00:00
|
|
|
|
|
|
|
|
data.elements.forEach((ele, i) => {
|
2021-05-25 04:58:29 +00:00
|
|
|
ctx.setFillStyle(ele.desc.color);
|
|
|
|
|
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
2021-11-15 14:33:45 +00:00
|
|
|
|
|
|
|
|
// helperCtx.setFillStyle('#2196f3');
|
|
|
|
|
// helperCtx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
|
|
|
|
|
|
|
|
|
if (i === idx) {
|
|
|
|
|
helperCtx.beginPath();
|
|
|
|
|
helperCtx.setLineDash([4, 4]);
|
|
|
|
|
helperCtx.setLineWidth(2);
|
|
|
|
|
helperCtx.setStrokeStyle('#2196f3');
|
|
|
|
|
helperCtx.moveTo(ele.x, ele.y);
|
|
|
|
|
helperCtx.lineTo(ele.x + ele.w, ele.y);
|
|
|
|
|
helperCtx.lineTo(ele.x + ele.w, ele.y + ele.h);
|
|
|
|
|
helperCtx.lineTo(ele.x, ele.y + ele.h);
|
|
|
|
|
helperCtx.lineTo(ele.x, ele.y);
|
|
|
|
|
helperCtx.stroke();
|
|
|
|
|
helperCtx.closePath();
|
|
|
|
|
}
|
2021-05-25 04:58:29 +00:00
|
|
|
});
|
2021-05-25 02:39:56 +00:00
|
|
|
board.draw();
|
|
|
|
|
}
|