Skip to content

Commit 78c019d

Browse files
committed
add setStepOfAllObjects
1 parent f3d61ac commit 78c019d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "./drawGraphicsToCanvas"
88
import { translateGraphics } from "./translateGraphics"
99
import { mergeGraphics } from "./mergeGraphics"
10+
import { setStepOfAllObjects } from "./setStepOfAllObjects"
1011
import {
1112
stackGraphicsHorizontally,
1213
stackGraphicsVertically,
@@ -35,6 +36,7 @@ export {
3536
} from "./drawGraphicsToCanvas"
3637
export { translateGraphics } from "./translateGraphics"
3738
export { mergeGraphics } from "./mergeGraphics"
39+
export { setStepOfAllObjects } from "./setStepOfAllObjects"
3840
export {
3941
stackGraphicsHorizontally,
4042
stackGraphicsVertically,

lib/setStepOfAllObjects.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { GraphicsObject } from "./types"
2+
3+
export function setStepOfAllObjects(
4+
graphics: GraphicsObject,
5+
step: number,
6+
): GraphicsObject {
7+
return {
8+
...graphics,
9+
points: graphics.points?.map((p) => ({
10+
...p,
11+
step,
12+
})),
13+
lines: graphics.lines?.map((line) => ({
14+
...line,
15+
step,
16+
})),
17+
rects: graphics.rects?.map((rect) => ({
18+
...rect,
19+
step,
20+
})),
21+
circles: graphics.circles?.map((circle) => ({
22+
...circle,
23+
step,
24+
})),
25+
texts: graphics.texts?.map((text) => ({
26+
...text,
27+
step,
28+
})),
29+
}
30+
}

0 commit comments

Comments
 (0)