-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathframe.js
35 lines (33 loc) · 933 Bytes
/
frame.js
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
import {create} from "d3-selection";
import {Mark} from "../mark.js";
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
export class Frame extends Mark {
constructor({
fill = "none",
stroke = "currentColor",
...style
} = {}) {
super();
Style(this, {fill, stroke, ...style});
}
render(
index,
scales,
channels,
{marginTop, marginRight, marginBottom, marginLeft, width, height}
) {
const {stroke} = this;
const offset = stroke === "none" ? 0 : 0.5; // crisp edges
return create("svg:rect")
.call(applyIndirectStyles, this)
.call(applyDirectStyles, this)
.attr("x", marginLeft + offset)
.attr("y", marginTop + offset)
.attr("width", width - marginLeft - marginRight)
.attr("height", height - marginTop - marginBottom)
.node();
}
}
export function frame(options) {
return new Frame(options);
}