Skip to content

Commit

Permalink
refactor(hiccup-svg): update points(), extract buildShape()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 21, 2019
1 parent 9cc6849 commit e01fae3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/hiccup-svg/src/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@ export const points = (
const group = ["g", fattribs({ ...attribs })];
let href: string;
if (!shape || shape[0] !== "#") {
const r = ff(size);
href = "_" + ((Math.random() * 1e6) | 0).toString(36);
group.push([
"g",
{ opacity: 0 },
shape === "circle"
? ["circle", { id: href, cx: 0, cy: 0, r: r }]
: [
"rect",
{ id: href, x: -r / 2, y: -r / 2, width: r, height: r }
]
]);
group.push(["g", { opacity: 0 }, buildShape(shape, href, size)]);
href = "#" + href;
} else {
href = shape;
Expand All @@ -43,3 +33,12 @@ export const points = (
}
return group;
};

const buildShape = (shape: string, id: string, r: number) => {
const rf = ff(r);
if (shape === "circle") {
return ["circle", { id, cx: 0, cy: 0, r: rf }];
}
const rf2 = ff(-r / 2);
return ["rect", { id, x: rf2, y: rf2, width: rf, height: rf }];
};

0 comments on commit e01fae3

Please sign in to comment.