Skip to content

Commit af3fc09

Browse files
committed
frame
1 parent 146069e commit af3fc09

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export {BarX, BarY, barX, barY} from "./marks/bar.js";
55
export {bin, binX, binY} from "./marks/bin.js";
66
export {Cell, cell, cellX, cellY} from "./marks/cell.js";
77
export {Dot, dot, dotX, dotY} from "./marks/dot.js";
8+
export {Frame, frame} from "./marks/frame.js";
89
export {group, groupX, groupY} from "./marks/group.js";
910
export {Line, line, lineX, lineY} from "./marks/line.js";
1011
export {Link, link} from "./marks/link.js";

src/marks/frame.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {create} from "d3-selection";
2+
import {Mark} from "../mark.js";
3+
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
4+
5+
export class Frame extends Mark {
6+
constructor({
7+
fill = "none",
8+
stroke = "currentColor",
9+
...style
10+
} = {}) {
11+
super();
12+
Style(this, {fill, stroke, ...style});
13+
}
14+
render(
15+
index,
16+
scales,
17+
channels,
18+
{marginTop, marginRight, marginBottom, marginLeft, width, height}
19+
) {
20+
return create("svg:rect")
21+
.call(applyIndirectStyles, this)
22+
.call(applyDirectStyles, this)
23+
.attr("x", marginLeft)
24+
.attr("y", marginTop)
25+
.attr("width", width - marginLeft - marginRight)
26+
.attr("height", height - marginTop - marginBottom)
27+
.node();
28+
}
29+
}
30+
31+
export function frame(options) {
32+
return new Frame(options);
33+
}

test/plots/penguin-culmen.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default async function() {
1313
marginRight: 80
1414
},
1515
marks: [
16+
Plot.frame(),
1617
Plot.dot(data.slice(), {
1718
x: "culmen_depth_mm",
1819
y: "culmen_length_mm",

0 commit comments

Comments
 (0)