Skip to content

Commit 774191f

Browse files
committed
1d density contours with frameAnchor
1 parent b80af5b commit 774191f

File tree

5 files changed

+347
-5
lines changed

5 files changed

+347
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ If a **z**, **stroke** or **fill** channel is specified, the input points are gr
10361036
10371037
If stroke or fill is specified as *density*, a color channel is returned with values representing the density normalized between 0 and 1.
10381038
1039-
This mark requires the **x** and **y** channels to be specified.
1039+
If either of the **x** or **y** channels are not specified, the corresponding position is controlled by the **frameAnchor** option.
10401040
10411041
### Dot
10421042

src/marks/density.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,17 @@ export class Density extends Mark {
5252

5353
export function density(data, {x, y, ...options} = {}) {
5454
([x, y] = maybeTuple(x, y));
55-
if (x === undefined || y === undefined) throw new Error("x and y must be defined");
5655
return new Density(data, {...options, x, y});
5756
}
5857

5958
function densityInitializer(options, bandwidth, thresholds, f, s) {
6059
return initializer(options, function(data, facets, channels, scales, dimensions) {
61-
const X = channels.x.scale ? valueof(channels.x.value, scales[channels.x.scale]) : channels.x.value;
62-
const Y = channels.y.scale ? valueof(channels.y.value, scales[channels.y.scale]) : channels.y.value;
60+
const X = channels.x?.scale ? valueof(channels.x.value, scales[channels.x.scale]) : channels.x?.value;
61+
const Y = channels.y?.scale ? valueof(channels.y.value, scales[channels.y.scale]) : channels.y?.value;
6362
const W = channels.weight?.value;
6463
const Z = channels.z?.value;
6564
const {z} = this;
66-
const [cx, cy] = applyFrameAnchor(this, dimensions);
65+
const [cx, cy] = applyFrameAnchor(options, dimensions);
6766
const {width, height} = dimensions;
6867
const newFacets = [];
6968
const contours = [];

0 commit comments

Comments
 (0)