rule.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 {MarkerOptions} from "../marker.js";
  6. /** Options for the ruleX and ruleY marks. */
  7. interface RuleOptions extends MarkOptions, MarkerOptions {
  8. /**
  9. * How to convert a continuous value (**y** for ruleX, or **x** for ruleY)
  10. * into an interval (**y1** and **y2** for ruleX, or **x1** and **x2** for
  11. * ruleY); one of:
  12. *
  13. * - an object that implements *floor*, *offset*, and *range* methods
  14. * - a named time interval such as *day* (for date intervals)
  15. * - a number (for number intervals), defining intervals at integer multiples of *n*
  16. *
  17. * For example, to bin Apple’s daily stock price by month, plotting a sequence
  18. * of barcodes showing monthly distributions:
  19. *
  20. * ```js
  21. * Plot.ruleY(aapl, {x: "Date", y: "Close", interval: "month"})
  22. * ```
  23. */
  24. interval?: Interval;
  25. }
  26. /** Options for the ruleX mark. */
  27. export interface RuleXOptions extends RuleOptions, Omit<InsetOptions, "insetLeft" | "insetRight"> {
  28. /**
  29. * The horizontal position of the tick; an optional channel bound to the *x*
  30. * scale. If not specified, the rule will be horizontally centered in the
  31. * plot’s frame.
  32. */
  33. x?: ChannelValueSpec;
  34. /**
  35. * Shorthand for specifying both the primary and secondary vertical position
  36. * of the tick as the bounds of the containing interval; can only be used in
  37. * conjunction with the **interval** option.
  38. */
  39. y?: ChannelValueIntervalSpec;
  40. /**
  41. * The primary (starting, often bottom) vertical position of the tick; a
  42. * channel bound to the *y* scale.
  43. *
  44. * If *y* represents ordinal values, use a tickX mark instead.
  45. */
  46. y1?: ChannelValueSpec;
  47. /**
  48. * The secondary (ending, often top) vertical position of the tick; a channel
  49. * bound to the *y* scale.
  50. *
  51. * If *y* represents ordinal values, use a tickX mark instead.
  52. */
  53. y2?: ChannelValueSpec;
  54. }
  55. /** Options for the ruleY mark. */
  56. export interface RuleYOptions extends RuleOptions, Omit<InsetOptions, "insetTop" | "insetBottom"> {
  57. /**
  58. * Shorthand for specifying both the primary and secondary horizontal position
  59. * of the tick as the bounds of the containing interval; can only be used in
  60. * conjunction with the **interval** option.
  61. */
  62. x?: ChannelValueIntervalSpec;
  63. /**
  64. * The primary (starting, often left) horizontal position of the tick; a
  65. * channel bound to the *x* scale.
  66. *
  67. * If *x* represents ordinal values, use a tickY mark instead.
  68. */
  69. x1?: ChannelValueSpec;
  70. /**
  71. * The secondary (ending, often right) horizontal position of the tick; a
  72. * channel bound to the *x* scale.
  73. *
  74. * If *x* represents ordinal values, use a tickY mark instead.
  75. */
  76. x2?: ChannelValueSpec;
  77. /**
  78. * The vertical position of the tick; an optional channel bound to the *y*
  79. * scale. If not specified, the rule will be vertically centered in the plot’s
  80. * frame.
  81. */
  82. y?: ChannelValueSpec;
  83. }
  84. /**
  85. * Returns a new horizontally-positioned ruleX mark (a vertical line, |) for the
  86. * given *data* and *options*. The **x** channel specifies the rule’s horizontal
  87. * position and defaults to identity, assuming that *data* = [*x₀*, *x₁*, *x₂*,
  88. * …]; the optional **y1** and **y2** channels specify its vertical extent. For
  89. * example, for a candlestick chart of Apple’s daily stock price:
  90. *
  91. * ```js
  92. * Plot.ruleX(aapl, {x: "Date", y1: "Open", y2: "Close"})
  93. * ```
  94. *
  95. * The ruleX mark is often used to highlight specific *x* values. For example,
  96. * to draw a rule at *x* = 0:
  97. *
  98. * ```js
  99. * Plot.ruleX([0])
  100. * ```
  101. *
  102. * If *y* represents ordinal values, use a tickX mark instead.
  103. */
  104. export function ruleX(data?: Data, options?: RuleXOptions): RuleX;
  105. /**
  106. * Returns a new vertically-positioned ruleY mark (a horizontal line, —) for the
  107. * given *data* and *options*. The **y** channel specifies the vertical position
  108. * of the rule and defaults to identity, assuming that *data* = [*y₀*, *y₁*,
  109. * *y₂*, …]; the optional **x1** and **x2** channels specify its horizontal
  110. * extent. For example, to bin Apple’s daily stock price by month, plotting a
  111. * sequence of barcodes showing monthly distributions:
  112. *
  113. * ```js
  114. * Plot.ruleY(aapl, {x: "Date", y: "Close", interval: "month"})
  115. * ```
  116. *
  117. * The ruleY mark is often used to highlight specific *y* values. For example,
  118. * to draw a rule at *y* = 0:
  119. *
  120. * ```js
  121. * Plot.ruleY([0])
  122. * ```
  123. *
  124. * If *x* represents ordinal values, use a tickY mark instead.
  125. */
  126. export function ruleY(data?: Data, options?: RuleYOptions): RuleY;
  127. /** The ruleX mark. */
  128. export class RuleX extends RenderableMark {}
  129. /** The ruleY mark. */
  130. export class RuleY extends RenderableMark {}