Spaces:
Configuration error
Configuration error
File size: 1,222 Bytes
a7060a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import { Component } from "react";
import { observer } from "mobx-react";
import { Layer, Rect } from "react-konva";
/**
* Create grid for Image Canvas
* @param {number} width
* @param {number} height
* @param {number} nodeSize
*/
const createGrid = (width, height, nodeSize) => {
return [...Array(width)]
.map((_, col) =>
[...Array(height)].map((_, row) => ({
col,
row,
x: col * nodeSize,
y: row * nodeSize,
fill: "#fff",
})),
)
.reduce((p, c) => [...p, ...c]);
};
export default observer(
class ImageGrid extends Component {
render() {
const { item } = this.props;
const grid = createGrid(
Math.ceil(item.stageWidth / item.gridsize),
Math.ceil(item.stageHeight / item.gridsize),
item.gridsize,
);
return (
<Layer opacity={0.15} name="ruler">
{Object.values(grid).map((n, i) => (
<Rect
key={i}
x={n.x}
y={n.y}
width={item.gridsize}
height={item.gridsize}
stroke={item.gridcolor}
strokeWidth={1}
/>
))}
</Layer>
);
}
},
);
|