You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.2 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. import { Point } from './helpers.canvas.js';
  2. import type { ChartArea, FontSpec } from '../types/index.js';
  3. import type { TRBL, TRBLCorners } from '../types/geometric.js';
  4. /**
  5. * @alias Chart.helpers.options
  6. * @namespace
  7. */
  8. /**
  9. * Converts the given line height `value` in pixels for a specific font `size`.
  10. * @param value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  11. * @param size - The font size (in pixels) used to resolve relative `value`.
  12. * @returns The effective line height in pixels (size * 1.2 if value is invalid).
  13. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  14. * @since 2.7.0
  15. */
  16. export declare function toLineHeight(value: number | string, size: number): number;
  17. /**
  18. * @param value
  19. * @param props
  20. */
  21. export declare function _readValueToProps<K extends string>(value: number | Record<K, number>, props: K[]): Record<K, number>;
  22. export declare function _readValueToProps<K extends string, T extends string>(value: number | Record<K & T, number>, props: Record<T, K>): Record<T, number>;
  23. /**
  24. * Converts the given value into a TRBL object.
  25. * @param value - If a number, set the value to all TRBL component,
  26. * else, if an object, use defined properties and sets undefined ones to 0.
  27. * x / y are shorthands for same value for left/right and top/bottom.
  28. * @returns The padding values (top, right, bottom, left)
  29. * @since 3.0.0
  30. */
  31. export declare function toTRBL(value: number | TRBL | Point): Record<"left" | "top" | "bottom" | "right", number>;
  32. /**
  33. * Converts the given value into a TRBL corners object (similar with css border-radius).
  34. * @param value - If a number, set the value to all TRBL corner components,
  35. * else, if an object, use defined properties and sets undefined ones to 0.
  36. * @returns The TRBL corner values (topLeft, topRight, bottomLeft, bottomRight)
  37. * @since 3.0.0
  38. */
  39. export declare function toTRBLCorners(value: number | TRBLCorners): Record<"topLeft" | "topRight" | "bottomLeft" | "bottomRight", number>;
  40. /**
  41. * Converts the given value into a padding object with pre-computed width/height.
  42. * @param value - If a number, set the value to all TRBL component,
  43. * else, if an object, use defined properties and sets undefined ones to 0.
  44. * x / y are shorthands for same value for left/right and top/bottom.
  45. * @returns The padding values (top, right, bottom, left, width, height)
  46. * @since 2.7.0
  47. */
  48. export declare function toPadding(value?: number | TRBL): ChartArea;
  49. export interface CanvasFontSpec extends FontSpec {
  50. string: string;
  51. }
  52. /**
  53. * Parses font options and returns the font object.
  54. * @param options - A object that contains font options to be parsed.
  55. * @param fallback - A object that contains fallback font options.
  56. * @return The font object.
  57. * @private
  58. */
  59. export declare function toFont(options: Partial<FontSpec>, fallback?: Partial<FontSpec>): {
  60. family: string;
  61. lineHeight: number;
  62. size: number;
  63. style: "normal" | "inherit" | "italic" | "oblique" | "initial";
  64. weight: string;
  65. string: string;
  66. };
  67. /**
  68. * Evaluates the given `inputs` sequentially and returns the first defined value.
  69. * @param inputs - An array of values, falling back to the last value.
  70. * @param context - If defined and the current value is a function, the value
  71. * is called with `context` as first argument and the result becomes the new input.
  72. * @param index - If defined and the current value is an array, the value
  73. * at `index` become the new input.
  74. * @param info - object to return information about resolution in
  75. * @param info.cacheable - Will be set to `false` if option is not cacheable.
  76. * @since 2.7.0
  77. */
  78. export declare function resolve(inputs: Array<unknown>, context?: object, index?: number, info?: {
  79. cacheable: boolean;
  80. }): unknown;
  81. /**
  82. * @param minmax
  83. * @param grace
  84. * @param beginAtZero
  85. * @private
  86. */
  87. export declare function _addGrace(minmax: {
  88. min: number;
  89. max: number;
  90. }, grace: number | string, beginAtZero: boolean): {
  91. min: number;
  92. max: number;
  93. };
  94. /**
  95. * Create a context inheriting parentContext
  96. * @param parentContext
  97. * @param context
  98. * @returns
  99. */
  100. export declare function createContext<T extends object>(parentContext: null, context: T): T;
  101. export declare function createContext<T extends object, P extends T>(parentContext: P, context: T): P & T;