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