Skip to content

Commit 1d4da1f

Browse files
authored
Plot.frame rounded corners (#951)
closes #942
1 parent bc6a831 commit 1d4da1f

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ Decorations are static marks that do not represent data. Currently this includes
15001500
15011501
[Source](./src/marks/frame.js) · [Examples](https://observablehq.com/@observablehq/plot-frame) · Draws a simple frame around the entire plot (or facet).
15021502
1503-
The frame mark supports the [standard mark options](#marks), but does not accept any data or support channels. The default **stroke** is currentColor, and the default **fill** is none.
1503+
The frame mark supports the [standard mark options](#marks), and the **rx** and **ry** options to set the [*x* radius](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx) and [*y* radius](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry) for rounded corners. It does not accept any data or support channels. The default **stroke** is currentColor, and the default **fill** is none.
15041504
15051505
#### Plot.frame(*options*)
15061506

src/marks/frame.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ export class Frame extends Mark {
1616
insetTop = inset,
1717
insetRight = inset,
1818
insetBottom = inset,
19-
insetLeft = inset
19+
insetLeft = inset,
20+
rx,
21+
ry
2022
} = options;
2123
super(undefined, undefined, options, defaults);
2224
this.insetTop = number(insetTop);
2325
this.insetRight = number(insetRight);
2426
this.insetBottom = number(insetBottom);
2527
this.insetLeft = number(insetLeft);
28+
this.rx = number(rx);
29+
this.ry = number(ry);
2630
}
2731
render(index, scales, channels, dimensions) {
2832
const {marginTop, marginRight, marginBottom, marginLeft, width, height} = dimensions;
29-
const {insetTop, insetRight, insetBottom, insetLeft} = this;
33+
const {insetTop, insetRight, insetBottom, insetLeft, rx, ry} = this;
3034
return create("svg:rect")
3135
.call(applyIndirectStyles, this, scales, dimensions)
3236
.call(applyDirectStyles, this)
@@ -35,7 +39,9 @@ export class Frame extends Mark {
3539
.attr("y", marginTop + insetTop)
3640
.attr("width", width - marginLeft - marginRight - insetLeft - insetRight)
3741
.attr("height", height - marginTop - marginBottom - insetTop - insetBottom)
38-
.node();
42+
.attr("rx", rx)
43+
.attr("ry", ry)
44+
.node();
3945
}
4046
}
4147

test/output/frameCorners.svg

Lines changed: 17 additions & 0 deletions
Loading

test/plots/frame-corners.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export default async function() {
4+
return Plot.frame({rx: 16, ry: 10}).plot();
5+
}

test/plots/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export {default as flareCluster} from "./flare-cluster.js";
6969
export {default as flareIndent} from "./flare-indent.js";
7070
export {default as flareTree} from "./flare-tree.js";
7171
export {default as footballCoverage} from "./football-coverage.js";
72+
export {default as frameCorners} from "./frame-corners.js";
7273
export {default as fruitSales} from "./fruit-sales.js";
7374
export {default as fruitSalesDate} from "./fruit-sales-date.js";
7475
export {default as gistempAnomaly} from "./gistemp-anomaly.js";

0 commit comments

Comments
 (0)