core.scale.d.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. export default class Scale extends Element<import("../types/basic.js").AnyObject, import("../types/basic.js").AnyObject> {
  2. constructor(cfg: any);
  3. /** @type {string} */
  4. id: string;
  5. /** @type {string} */
  6. type: string;
  7. /** @type {any} */
  8. options: any;
  9. /** @type {CanvasRenderingContext2D} */
  10. ctx: CanvasRenderingContext2D;
  11. /** @type {Chart} */
  12. chart: Chart;
  13. /** @type {number} */
  14. top: number;
  15. /** @type {number} */
  16. bottom: number;
  17. /** @type {number} */
  18. left: number;
  19. /** @type {number} */
  20. right: number;
  21. /** @type {number} */
  22. width: number;
  23. /** @type {number} */
  24. height: number;
  25. _margins: {
  26. left: number;
  27. right: number;
  28. top: number;
  29. bottom: number;
  30. };
  31. /** @type {number} */
  32. maxWidth: number;
  33. /** @type {number} */
  34. maxHeight: number;
  35. /** @type {number} */
  36. paddingTop: number;
  37. /** @type {number} */
  38. paddingBottom: number;
  39. /** @type {number} */
  40. paddingLeft: number;
  41. /** @type {number} */
  42. paddingRight: number;
  43. /** @type {string=} */
  44. axis: string | undefined;
  45. /** @type {number=} */
  46. labelRotation: number | undefined;
  47. min: any;
  48. max: any;
  49. _range: {
  50. min: number;
  51. max: number;
  52. };
  53. /** @type {Tick[]} */
  54. ticks: Tick[];
  55. /** @type {object[]|null} */
  56. _gridLineItems: object[] | null;
  57. /** @type {object[]|null} */
  58. _labelItems: object[] | null;
  59. /** @type {object|null} */
  60. _labelSizes: object | null;
  61. _length: number;
  62. _maxLength: number;
  63. _longestTextCache: {};
  64. /** @type {number} */
  65. _startPixel: number;
  66. /** @type {number} */
  67. _endPixel: number;
  68. _reversePixels: boolean;
  69. _userMax: any;
  70. _userMin: any;
  71. _suggestedMax: any;
  72. _suggestedMin: any;
  73. _ticksLength: number;
  74. _borderValue: number;
  75. _cache: {};
  76. _dataLimitsCached: boolean;
  77. $context: any;
  78. /**
  79. * @param {any} options
  80. * @since 3.0
  81. */
  82. init(options: any): void;
  83. /**
  84. * Parse a supported input value to internal representation.
  85. * @param {*} raw
  86. * @param {number} [index]
  87. * @since 3.0
  88. */
  89. parse(raw: any, index?: number): any;
  90. /**
  91. * @return {{min: number, max: number, minDefined: boolean, maxDefined: boolean}}
  92. * @protected
  93. * @since 3.0
  94. */
  95. protected getUserBounds(): {
  96. min: number;
  97. max: number;
  98. minDefined: boolean;
  99. maxDefined: boolean;
  100. };
  101. /**
  102. * @param {boolean} canStack
  103. * @return {{min: number, max: number}}
  104. * @protected
  105. * @since 3.0
  106. */
  107. protected getMinMax(canStack: boolean): {
  108. min: number;
  109. max: number;
  110. };
  111. /**
  112. * Get the padding needed for the scale
  113. * @return {{top: number, left: number, bottom: number, right: number}} the necessary padding
  114. * @private
  115. */
  116. private getPadding;
  117. /**
  118. * Returns the scale tick objects
  119. * @return {Tick[]}
  120. * @since 2.7
  121. */
  122. getTicks(): Tick[];
  123. /**
  124. * @return {string[]}
  125. */
  126. getLabels(): string[];
  127. /**
  128. * @return {import('../types.js').LabelItem[]}
  129. */
  130. getLabelItems(chartArea?: import("../types.js").ChartArea): import('../types.js').LabelItem[];
  131. beforeLayout(): void;
  132. beforeUpdate(): void;
  133. /**
  134. * @param {number} maxWidth - the max width in pixels
  135. * @param {number} maxHeight - the max height in pixels
  136. * @param {{top: number, left: number, bottom: number, right: number}} margins - the space between the edge of the other scales and edge of the chart
  137. * This space comes from two sources:
  138. * - padding - space that's required to show the labels at the edges of the scale
  139. * - thickness of scales or legends in another orientation
  140. */
  141. update(maxWidth: number, maxHeight: number, margins: {
  142. top: number;
  143. left: number;
  144. bottom: number;
  145. right: number;
  146. }): void;
  147. /**
  148. * @protected
  149. */
  150. protected configure(): void;
  151. _alignToPixels: any;
  152. afterUpdate(): void;
  153. beforeSetDimensions(): void;
  154. setDimensions(): void;
  155. afterSetDimensions(): void;
  156. _callHooks(name: any): void;
  157. beforeDataLimits(): void;
  158. determineDataLimits(): void;
  159. afterDataLimits(): void;
  160. beforeBuildTicks(): void;
  161. /**
  162. * @return {object[]} the ticks
  163. */
  164. buildTicks(): object[];
  165. afterBuildTicks(): void;
  166. beforeTickToLabelConversion(): void;
  167. /**
  168. * Convert ticks to label strings
  169. * @param {Tick[]} ticks
  170. */
  171. generateTickLabels(ticks: Tick[]): void;
  172. afterTickToLabelConversion(): void;
  173. beforeCalculateLabelRotation(): void;
  174. calculateLabelRotation(): void;
  175. afterCalculateLabelRotation(): void;
  176. afterAutoSkip(): void;
  177. beforeFit(): void;
  178. fit(): void;
  179. _calculatePadding(first: any, last: any, sin: any, cos: any): void;
  180. /**
  181. * Handle margins and padding interactions
  182. * @private
  183. */
  184. private _handleMargins;
  185. afterFit(): void;
  186. /**
  187. * @return {boolean}
  188. */
  189. isHorizontal(): boolean;
  190. /**
  191. * @return {boolean}
  192. */
  193. isFullSize(): boolean;
  194. /**
  195. * @param {Tick[]} ticks
  196. * @private
  197. */
  198. private _convertTicksToLabels;
  199. /**
  200. * @return {{ first: object, last: object, widest: object, highest: object, widths: Array, heights: array }}
  201. * @private
  202. */
  203. private _getLabelSizes;
  204. /**
  205. * Returns {width, height, offset} objects for the first, last, widest, highest tick
  206. * labels where offset indicates the anchor point offset from the top in pixels.
  207. * @return {{ first: object, last: object, widest: object, highest: object, widths: Array, heights: array }}
  208. * @private
  209. */
  210. private _computeLabelSizes;
  211. /**
  212. * Used to get the label to display in the tooltip for the given value
  213. * @param {*} value
  214. * @return {string}
  215. */
  216. getLabelForValue(value: any): string;
  217. /**
  218. * Returns the location of the given data point. Value can either be an index or a numerical value
  219. * The coordinate (0, 0) is at the upper-left corner of the canvas
  220. * @param {*} value
  221. * @param {number} [index]
  222. * @return {number}
  223. */
  224. getPixelForValue(value: any, index?: number): number;
  225. /**
  226. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  227. * The coordinate (0, 0) is at the upper-left corner of the canvas
  228. * @param {number} pixel
  229. * @return {*}
  230. */
  231. getValueForPixel(pixel: number): any;
  232. /**
  233. * Returns the location of the tick at the given index
  234. * The coordinate (0, 0) is at the upper-left corner of the canvas
  235. * @param {number} index
  236. * @return {number}
  237. */
  238. getPixelForTick(index: number): number;
  239. /**
  240. * Utility for getting the pixel location of a percentage of scale
  241. * The coordinate (0, 0) is at the upper-left corner of the canvas
  242. * @param {number} decimal
  243. * @return {number}
  244. */
  245. getPixelForDecimal(decimal: number): number;
  246. /**
  247. * @param {number} pixel
  248. * @return {number}
  249. */
  250. getDecimalForPixel(pixel: number): number;
  251. /**
  252. * Returns the pixel for the minimum chart value
  253. * The coordinate (0, 0) is at the upper-left corner of the canvas
  254. * @return {number}
  255. */
  256. getBasePixel(): number;
  257. /**
  258. * @return {number}
  259. */
  260. getBaseValue(): number;
  261. /**
  262. * @protected
  263. */
  264. protected getContext(index: any): any;
  265. /**
  266. * @return {number}
  267. * @private
  268. */
  269. private _tickSize;
  270. /**
  271. * @return {boolean}
  272. * @private
  273. */
  274. private _isVisible;
  275. /**
  276. * @private
  277. */
  278. private _computeGridLineItems;
  279. /**
  280. * @private
  281. */
  282. private _computeLabelItems;
  283. _getXAxisLabelAlignment(): string;
  284. _getYAxisLabelAlignment(tl: any): {
  285. textAlign: string;
  286. x: any;
  287. };
  288. /**
  289. * @private
  290. */
  291. private _computeLabelArea;
  292. /**
  293. * @protected
  294. */
  295. protected drawBackground(): void;
  296. getLineWidthForValue(value: any): any;
  297. /**
  298. * @protected
  299. */
  300. protected drawGrid(chartArea: any): void;
  301. /**
  302. * @protected
  303. */
  304. protected drawBorder(): void;
  305. /**
  306. * @protected
  307. */
  308. protected drawLabels(chartArea: any): void;
  309. /**
  310. * @protected
  311. */
  312. protected drawTitle(): void;
  313. draw(chartArea: any): void;
  314. /**
  315. * @return {object[]}
  316. * @private
  317. */
  318. private _layers;
  319. /**
  320. * Returns visible dataset metas that are attached to this scale
  321. * @param {string} [type] - if specified, also filter by dataset type
  322. * @return {object[]}
  323. */
  324. getMatchingVisibleMetas(type?: string): object[];
  325. /**
  326. * @param {number} index
  327. * @return {object}
  328. * @protected
  329. */
  330. protected _resolveTickFontOptions(index: number): object;
  331. /**
  332. * @protected
  333. */
  334. protected _maxDigits(): number;
  335. }
  336. export type Chart = import('../types/index.js').Chart;
  337. export type Tick = {
  338. value: number | string;
  339. label?: string;
  340. major?: boolean;
  341. $context?: any;
  342. };
  343. import Element from "./core.element.js";