config/Options/axis/axis.ts

  1. /**
  2. * Copyright (c) 2017 ~ present NAVER Corp.
  3. * billboard.js project is licensed under the MIT license
  4. */
  5. import x from "./x";
  6. import y from "./y";
  7. import y2 from "./y2";
  8. /**
  9. * y Axis config options
  10. */
  11. export default {
  12. /**
  13. * Setup the way to evaluate tick text size.
  14. * - **NOTE:**
  15. * - Setting `false` or custom evaluator, highly recommended to memoize evaluated text dimension value to not degrade performance.
  16. * @name axis․evalTextSize
  17. * @memberof Options
  18. * @type {boolean|Function}
  19. * @default true
  20. * @example
  21. * axis: {
  22. * // will evaluate getting text size every time.
  23. * evalTextSize: false.
  24. *
  25. * // set a custom evaluator
  26. * evalTextSize: function(textElement) {
  27. * // set some character to be evaluated
  28. * text.textContent = "0";
  29. *
  30. * // get the size
  31. * const box = text.getBBox();
  32. *
  33. * // clear text
  34. * text.textContent = "";
  35. *
  36. * return { w: 7, h: 12};
  37. * }
  38. * }
  39. */
  40. axis_evalTextSize: <boolean | ((text: SVGTextElement) => {w: number, h: number})>true,
  41. /**
  42. * Switch x and y axis position.
  43. * @name axis․rotated
  44. * @memberof Options
  45. * @type {boolean}
  46. * @default false
  47. * @example
  48. * axis: {
  49. * rotated: true
  50. * }
  51. */
  52. axis_rotated: false,
  53. /**
  54. * Set axis tooltip.
  55. * - **NOTE:**
  56. * - When enabled, will disable default focus grid line.
  57. * - For `timeseries` x Axis, tootlip will be formatted using x Axis' tick format.
  58. * - For `category` x Axis, tootlip will be displaying scales' value text.
  59. * @name axis․tooltip
  60. * @memberof Options
  61. * @type {boolean}
  62. * @default false
  63. * @property {object} axis Axis object
  64. * @property {boolean} [axis.tooltip=false] Show tooltip or not.
  65. * @property {string|object} [axis.tooltip.backgroundColor] Set axis tooltip text background colors.
  66. * @see [Demo](https://naver.github.io/billboard.js/demo/#Axis.AxisTooltip)
  67. * @example
  68. * axis: {
  69. * tooltip: true, // default background color is
  70. *
  71. * // set backgound color for axis tooltip texts
  72. * tooltip: {
  73. * backgroundColor: "red",
  74. *
  75. * // set differenct backround colors per axes
  76. * // NOTE: In this case, only specified axes tooltip will appear.
  77. * backgroundColor: {
  78. * x: "green",
  79. * y: "yellow",
  80. * y2: "red"
  81. * }
  82. * }
  83. * }
  84. */
  85. axis_tooltip: <boolean | {
  86. backgroundColor?: string | {x?: string, y?: string, y2?: string}
  87. }>false,
  88. ...x,
  89. ...y,
  90. ...y2
  91. };