bar.d.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import type {ChannelValueIntervalSpec, ChannelValueSpec} from "../channel.js";
  2. import type {InsetOptions} from "../inset.js";
  3. import type {Interval} from "../interval.js";
  4. import type {Data, MarkOptions, RenderableMark} from "../mark.js";
  5. import type {StackOptions} from "../transforms/stack.js";
  6. import type {RectCornerOptions} from "./rect.js";
  7. /** Options for the barX and barY marks. */
  8. interface BarOptions extends MarkOptions, InsetOptions, RectCornerOptions, StackOptions {
  9. /**
  10. * How to convert a continuous value (**x** for barX, or **y** for barY) into
  11. * an interval (**x1** and **x2** for barX, or **y1** and **y2** for barY);
  12. * one of:
  13. *
  14. * - an object that implements *floor*, *offset*, and *range* methods
  15. * - a named time interval such as *day* (for date intervals)
  16. * - a number (for number intervals), defining intervals at integer multiples of *n*
  17. *
  18. * For example, for a scatterplot showing the frequency distribution of
  19. * English letters, where the vertical extent of each bar covers a unit
  20. * percentage:
  21. *
  22. * ```js
  23. * Plot.barY(alphabet, {x: "letter", y: "frequency", interval: 0.01})
  24. * ```
  25. *
  26. * Setting this option disables the implicit stack transform (stackX for barX,
  27. * or stackY for barY).
  28. */
  29. interval?: Interval;
  30. }
  31. /** Options for the barX mark. */
  32. export interface BarXOptions extends BarOptions {
  33. /**
  34. * The horizontal position (or length/width) channel, typically bound to the
  35. * *x* scale.
  36. *
  37. * If neither **x1** nor **x2** nor **interval** is specified, an implicit
  38. * stackX transform is applied and **x** defaults to the identity function,
  39. * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. Otherwise if an **interval**
  40. * is specified, then **x1** and **x2** are derived from **x**, representing
  41. * the lower and upper bound of the containing interval, respectively.
  42. * Otherwise, if only one of **x1** or **x2** is specified, the other defaults
  43. * to **x**, which defaults to zero.
  44. */
  45. x?: ChannelValueIntervalSpec;
  46. /**
  47. * The required primary (starting, often left) horizontal position channel,
  48. * typically bound to the *x* scale. Setting this option disables the implicit
  49. * stackX transform.
  50. *
  51. * If *x* represents ordinal values, use a cell mark instead.
  52. */
  53. x1?: ChannelValueSpec;
  54. /**
  55. * The required secondary (ending, often right) horizontal position channel,
  56. * typically bound to the *x* scale. Setting this option disables the implicit
  57. * stackX transform.
  58. *
  59. * If *x* represents ordinal values, use a cell mark instead.
  60. */
  61. x2?: ChannelValueSpec;
  62. /**
  63. * The optional vertical position of the bar; a ordinal channel typically
  64. * bound to the *y* scale. If not specified, the bar spans the vertical extent
  65. * of the frame; otherwise the *y* scale must be a *band* scale.
  66. *
  67. * If *y* represents quantitative or temporal values, use a rectX mark
  68. * instead.
  69. */
  70. y?: ChannelValueSpec;
  71. }
  72. /** Options for the barY mark. */
  73. export interface BarYOptions extends BarOptions {
  74. /**
  75. * The vertical position (or length/height) channel, typically bound to the
  76. * *y* scale.
  77. *
  78. * If neither **y1** nor **y2** nor **interval** is specified, an implicit
  79. * stackY transform is applied and **y** defaults to the identity function,
  80. * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. Otherwise if an **interval**
  81. * is specified, then **y1** and **y2** are derived from **y**, representing
  82. * the lower and upper bound of the containing interval, respectively.
  83. * Otherwise, if only one of **y1** or **y2** is specified, the other defaults
  84. * to **y**, which defaults to zero.
  85. */
  86. y?: ChannelValueIntervalSpec;
  87. /**
  88. * The required primary (starting, often bottom) vertical position channel,
  89. * typically bound to the *y* scale. Setting this option disables the implicit
  90. * stackY transform.
  91. *
  92. * If *y* represents ordinal values, use a cell mark instead.
  93. */
  94. y1?: ChannelValueSpec;
  95. /**
  96. * The required secondary (ending, often top) horizontal position channel,
  97. * typically bound to the *y* scale. Setting this option disables the implicit
  98. * stackY transform.
  99. *
  100. * If *y* represents ordinal values, use a cell mark instead.
  101. */
  102. y2?: ChannelValueSpec;
  103. /**
  104. * The optional horizontal position of the bar; a ordinal channel typically
  105. * bound to the *x* scale. If not specified, the bar spans the horizontal
  106. * extent of the frame; otherwise the *x* scale must be a *band* scale.
  107. *
  108. * If *x* represents quantitative or temporal values, use a rectY mark
  109. * instead.
  110. */
  111. x?: ChannelValueSpec;
  112. }
  113. /**
  114. * Returns a new horizontal bar mark for the given *data* and *options*; the
  115. * required *x* values should be quantitative or temporal, and the optional *y*
  116. * values should be ordinal. For example, for a horizontal bar chart of English
  117. * letter frequency:
  118. *
  119. * ```js
  120. * Plot.barX(alphabet, {x: "frequency", y: "letter"})
  121. * ```
  122. *
  123. * If neither **x1** nor **x2** nor **interval** is specified, an implicit
  124. * stackX transform is applied and **x** defaults to the identity function,
  125. * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. Otherwise if an **interval** is
  126. * specified, then **x1** and **x2** are derived from **x**, representing the
  127. * lower and upper bound of the containing interval, respectively. Otherwise, if
  128. * only one of **x1** or **x2** is specified, the other defaults to **x**, which
  129. * defaults to zero.
  130. *
  131. * The optional **y** ordinal channel specifies the vertical position; it is
  132. * typically bound to the *y* scale, which must be a *band* scale. If the **y**
  133. * channel is not specified, the bar will span the vertical extent of the plot’s
  134. * frame. The barX mark is often used in conjunction with the groupY transform.
  135. * For a stacked histogram of penguins by species, colored by sex:
  136. *
  137. * ```js
  138. * Plot.barX(penguins, Plot.groupY({x: "count"}, {y: "species", fill: "sex"}))
  139. * ```
  140. *
  141. * If *y* is quantitative, use the rectX mark instead, possibly with a binY
  142. * transform. If *x* is ordinal, use the cell mark instead, possibly with a
  143. * group transform.
  144. *
  145. * If *options* is undefined, then **y** defaults to the zero-based index of
  146. * *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:
  147. *
  148. * ```js
  149. * Plot.barX([4, 9, 24, 46, 66, 7])
  150. * ```
  151. */
  152. export function barX(data?: Data, options?: BarXOptions): BarX;
  153. /**
  154. * Returns a new vertical bar mark for the given *data* and *options*; the
  155. * required *y* values should be quantitative or temporal, and the optional *x*
  156. * values should be ordinal. For example, for a vertical bar chart of English
  157. * letter frequency:
  158. *
  159. * ```js
  160. * Plot.barY(alphabet, {y: "frequency", x: "letter"})
  161. * ```
  162. *
  163. * If neither **y1** nor **y2** nor **interval** is specified, an implicit
  164. * stackY transform is applied and **y** defaults to the identity function,
  165. * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. Otherwise if an **interval** is
  166. * specified, then **y1** and **y2** are derived from **y**, representing the
  167. * lower and upper bound of the containing interval, respectively. Otherwise, if
  168. * only one of **y1** or **y2** is specified, the other defaults to **y**, which
  169. * defaults to zero.
  170. *
  171. * The optional **x** ordinal channel specifies the horizontal position; it is
  172. * typically bound to the *x* scale, which must be a *band* scale. If the **x**
  173. * channel is not specified, the bar will span the horizontal extent of the
  174. * plot’s frame. The barY mark is often used in conjunction with the groupX
  175. * transform. For a stacked histogram of penguins by species, colored by sex:
  176. *
  177. * ```js
  178. * Plot.barY(penguins, Plot.groupX({y: "count"}, {x: "species", fill: "sex"}))
  179. * ```
  180. *
  181. * If *x* is quantitative, use the rectY mark instead, possibly with a binX
  182. * transform. If *y* is ordinal, use the cell mark instead, possibly with a
  183. * group transform.
  184. *
  185. * If *options* is undefined, then **x** defaults to the zero-based index of
  186. * *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:
  187. *
  188. * ```js
  189. * Plot.barY([4, 9, 24, 46, 66, 7])
  190. * ```
  191. */
  192. export function barY(data?: Data, options?: BarYOptions): BarY;
  193. /** The barX mark. */
  194. export class BarX extends RenderableMark {}
  195. /** The barY mark. */
  196. export class BarY extends RenderableMark {}