cell.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {identity, indexOf, maybeColorChannel, maybeTuple} from "../options.js";
  2. import {applyTransform} from "../style.js";
  3. import {AbstractBar} from "./bar.js";
  4. const defaults = {
  5. ariaLabel: "cell"
  6. };
  7. export class Cell extends AbstractBar {
  8. constructor(data, {x, y, ...options} = {}) {
  9. super(
  10. data,
  11. {
  12. x: {value: x, scale: "x", type: "band", optional: true},
  13. y: {value: y, scale: "y", type: "band", optional: true}
  14. },
  15. options,
  16. defaults
  17. );
  18. }
  19. _transform(selection, mark) {
  20. // apply dx, dy
  21. selection.call(applyTransform, mark, {}, 0, 0);
  22. }
  23. }
  24. export function cell(data, {x, y, ...options} = {}) {
  25. [x, y] = maybeTuple(x, y);
  26. return new Cell(data, {...options, x, y});
  27. }
  28. export function cellX(data, {x = indexOf, fill, stroke, ...options} = {}) {
  29. if (fill === undefined && maybeColorChannel(stroke)[0] === undefined) fill = identity;
  30. return new Cell(data, {...options, x, fill, stroke});
  31. }
  32. export function cellY(data, {y = indexOf, fill, stroke, ...options} = {}) {
  33. if (fill === undefined && maybeColorChannel(stroke)[0] === undefined) fill = identity;
  34. return new Cell(data, {...options, y, fill, stroke});
  35. }