forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe.js
43 lines (41 loc) · 1.28 KB
/
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
36
37
38
39
40
41
42
43
import {create} from "d3";
import {Mark, number} from "../mark.js";
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";
export class Frame extends Mark {
constructor({
fill = "none",
stroke = fill === null || fill === "none" ? "currentColor" : "none",
inset = 0,
insetTop = inset,
insetRight = inset,
insetBottom = inset,
insetLeft = inset,
...style
} = {}) {
super();
Style(this, {fill, stroke, ...style});
this.insetTop = number(insetTop);
this.insetRight = number(insetRight);
this.insetBottom = number(insetBottom);
this.insetLeft = number(insetLeft);
}
render(
index,
scales,
channels,
{marginTop, marginRight, marginBottom, marginLeft, width, height}
) {
return create("svg:rect")
.call(applyIndirectStyles, this)
.call(applyDirectStyles, this)
.call(applyTransform, null, null, 0.5, 0.5)
.attr("x", marginLeft + this.insetLeft)
.attr("y", marginTop + this.insetTop)
.attr("width", width - marginLeft - marginRight - this.insetLeft - this.insetRight)
.attr("height", height - marginTop - marginBottom - this.insetTop - this.insetBottom)
.node();
}
}
export function frame(options) {
return new Frame(options);
}