waffle.d.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type {Data, RenderableMark} from "../mark.js";
  2. import type {BarXOptions, BarYOptions} from "./bar.js";
  3. /** Options for the waffleX and waffleY mark. */
  4. interface WaffleOptions {
  5. /** The number of cells per row or column; defaults to undefined for automatic. */
  6. multiple?: number;
  7. /** The quantity each cell represents; defaults to 1. */
  8. unit?: number;
  9. /** The gap in pixels between cells; defaults to 1. */
  10. gap?: number;
  11. /** If true, round to integers to avoid partial cells. */
  12. round?: boolean | ((value: number) => number);
  13. }
  14. /** Options for the waffleX mark. */
  15. export interface WaffleXOptions extends BarXOptions, WaffleOptions {}
  16. /** Options for the waffleY mark. */
  17. export interface WaffleYOptions extends BarYOptions, WaffleOptions {}
  18. /**
  19. * Returns a new vertical waffle mark for the given *data* and *options*; the
  20. * required *y* values should be quantitative, and the optional *x* values
  21. * should be ordinal. For example, for a vertical waffle chart of Olympic
  22. * athletes by sport:
  23. *
  24. * ```js
  25. * Plot.waffleY(olympians, Plot.groupX({y: "count"}, {x: "sport"}))
  26. * ```
  27. *
  28. * If neither **y1** nor **y2** nor **interval** is specified, an implicit
  29. * stackY transform is applied and **y** defaults to the identity function,
  30. * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. Otherwise if an **interval** is
  31. * specified, then **y1** and **y2** are derived from **y**, representing the
  32. * lower and upper bound of the containing interval, respectively. Otherwise, if
  33. * only one of **y1** or **y2** is specified, the other defaults to **y**, which
  34. * defaults to zero.
  35. *
  36. * The optional **x** ordinal channel specifies the horizontal position; it is
  37. * typically bound to the *x* scale, which must be a *band* scale. If the **x**
  38. * channel is not specified, the waffle will span the horizontal extent of the
  39. * plot’s frame. Because a waffle represents a discrete number of square cells,
  40. * it may not use all of the available bandwidth.
  41. *
  42. * If *options* is undefined, then **x** defaults to the zero-based index of
  43. * *data* [0, 1, 2, …], allowing a quick waffle chart from an array of numbers:
  44. *
  45. * ```js
  46. * Plot.waffleY([4, 9, 24, 46, 66, 7])
  47. * ```
  48. */
  49. export function waffleY(data?: Data, options?: WaffleYOptions): WaffleY;
  50. /**
  51. * Returns a new horizonta waffle mark for the given *data* and *options*; the
  52. * required *x* values should be quantitative, and the optional *y* values
  53. * should be ordinal. For example, for a horizontal waffle chart of Olympic
  54. * athletes by sport:
  55. *
  56. * ```js
  57. * Plot.waffleX(olympians, Plot.groupY({x: "count"}, {y: "sport"}))
  58. * ```
  59. *
  60. * If neither **x1** nor **x2** nor **interval** is specified, an implicit
  61. * stackX transform is applied and **x** defaults to the identity function,
  62. * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. Otherwise if an **interval** is
  63. * specified, then **x1** and **x2** are derived from **x**, representing the
  64. * lower and upper bound of the containing interval, respectively. Otherwise, if
  65. * only one of **x1** or **x2** is specified, the other defaults to **x**, which
  66. * defaults to zero.
  67. *
  68. * The optional **y** ordinal channel specifies the vertical position; it is
  69. * typically bound to the *y* scale, which must be a *band* scale. If the **y**
  70. * channel is not specified, the waffle will span the vertical extent of the
  71. * plot’s frame. Because a waffle represents a discrete number of square cells,
  72. * it may not use all of the available bandwidth.
  73. *
  74. * If *options* is undefined, then **y** defaults to the zero-based index of
  75. * *data* [0, 1, 2, …], allowing a quick waffle chart from an array of numbers:
  76. *
  77. * ```js
  78. * Plot.waffleX([4, 9, 24, 46, 66, 7])
  79. * ```
  80. */
  81. export function waffleX(data?: Data, options?: WaffleXOptions): WaffleX;
  82. /** The waffleX mark. */
  83. export class WaffleX extends RenderableMark {}
  84. /** The waffleY mark. */
  85. export class WaffleY extends RenderableMark {}