forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.js
36 lines (32 loc) · 1.04 KB
/
cell.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
import {identity, indexOf, maybeColor, maybeTuple} from "../mark.js";
import {AbstractBar} from "./bar.js";
export class Cell extends AbstractBar {
constructor(data, {x, y, ...options} = {}) {
super(
data,
[
{name: "x", value: x, scale: "x", type: "band", optional: true},
{name: "y", value: y, scale: "y", type: "band", optional: true}
],
options
);
}
_transform() {
// noop
}
_positions({x: X, y: Y}) {
return [X, Y];
}
}
export function cell(data, {x, y, ...options} = {}) {
([x, y] = maybeTuple(x, y));
return new Cell(data, {...options, x, y});
}
export function cellX(data, {x = indexOf, fill, stroke, ...options} = {}) {
if (fill === undefined && maybeColor(stroke)[0] === undefined) fill = identity;
return new Cell(data, {...options, x, fill, stroke});
}
export function cellY(data, {y = indexOf, fill, stroke, ...options} = {}) {
if (fill === undefined && maybeColor(stroke)[0] === undefined) fill = identity;
return new Cell(data, {...options, y, fill, stroke});
}