forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.js
46 lines (41 loc) · 1.35 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
37
38
39
40
41
42
43
44
45
46
import {identity, indexOf, maybeColorChannel, maybeTuple} from "../options.js";
import {applyTransform} from "../style.js";
import {AbstractBar} from "./bar.js";
const defaults = {
ariaLabel: "cell"
};
export class Cell extends AbstractBar {
constructor(data, {x, y, ...options} = {}) {
super(
data,
{
x: {value: x, scale: "x", type: "band", optional: true},
y: {value: y, scale: "y", type: "band", optional: true}
},
options,
defaults
);
}
_transform(selection, mark) {
// apply dx, dy
selection.call(applyTransform, mark, {}, 0, 0);
}
}
/** @jsdoc cell */
export function cell(data, options = {}) {
let {x, y, ...remainingOptions} = options;
[x, y] = maybeTuple(x, y);
return new Cell(data, {...remainingOptions, x, y});
}
/** @jsdoc cellX */
export function cellX(data, options = {}) {
let {x = indexOf, fill, stroke, ...remainingOptions} = options;
if (fill === undefined && maybeColorChannel(stroke)[0] === undefined) fill = identity;
return new Cell(data, {...remainingOptions, x, fill, stroke});
}
/** @jsdoc cellY */
export function cellY(data, options = {}) {
let {y = indexOf, fill, stroke, ...remainingOptions} = options;
if (fill === undefined && maybeColorChannel(stroke)[0] === undefined) fill = identity;
return new Cell(data, {...remainingOptions, y, fill, stroke});
}