config/Options/common/main.ts

  1. /**
  2. * Copyright (c) 2017 ~ present NAVER Corp.
  3. * billboard.js project is licensed under the MIT license
  4. */
  5. import type {RegionOptions} from "../../../../types/options";
  6. /**
  7. * main config options
  8. */
  9. export default {
  10. /**
  11. * Specify the CSS selector or the element which the chart will be set to. D3 selection object can be specified also.<br>
  12. * If other chart is set already, it will be replaced with the new one (only one chart can be set in one element).
  13. * - **NOTE:** In case of element doesn't exist or not specified, will add a `<div>` element to the body.
  14. * @name bindto
  15. * @memberof Options
  16. * @property {string|HTMLElement|d3.selection|object} [bindto="#chart"] Specify the element where chart will be drawn.
  17. * @property {string|HTMLElement|d3.selection} bindto.element="#chart" Specify the element where chart will be drawn.
  18. * @property {string} [bindto.classname=bb] Specify the class name of bind element.<br>
  19. * **NOTE:** When class name isn't `bb`, then you also need to update the default CSS to be rendered correctly.
  20. * @default #chart
  21. * @example
  22. * bindto: "#myContainer"
  23. *
  24. * // or HTMLElement
  25. * bindto: document.getElementById("myContainer")
  26. *
  27. * // or D3 selection object
  28. * bindto: d3.select("#myContainer")
  29. *
  30. * // or to change default classname
  31. * bindto: {
  32. * element: "#chart",
  33. * classname: "bill-board" // ex) <div id='chart' class='bill-board'>
  34. * }
  35. */
  36. bindto: <string | {element: string, classname?: string}>"#chart",
  37. /**
  38. * Set chart background.
  39. * @name background
  40. * @memberof Options
  41. * @property {object} background background object
  42. * @property {string} background.class Specify the class name for background element.
  43. * @property {string} background.color Specify the fill color for background element.<br>**NOTE:** Will be ignored if `imgUrl` option is set.
  44. * @property {string} background.imgUrl Specify the image url string for background.
  45. * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.Background)
  46. * @example
  47. * background: {
  48. * class: "myClass",
  49. * color: "red",
  50. *
  51. * // Set image url for background.
  52. * // If specified, 'color' option will be ignored.
  53. * imgUrl: "https://naver.github.io/billboard.js/img/logo/billboard.js.svg",
  54. * }
  55. */
  56. background: <{class?: string, color?: string, imgUrl?: string}>{},
  57. /**
  58. * Set 'clip-path' attribute for chart element
  59. * - **NOTE:**
  60. * > When is false, chart node element is positioned after the axis node in DOM tree hierarchy.
  61. * > Is to make chart element positioned over axis element.
  62. * @name clipPath
  63. * @memberof Options
  64. * @type {boolean}
  65. * @default true
  66. * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.clipPath)
  67. * @example
  68. * // don't set 'clip-path' attribute
  69. * clipPath: false
  70. */
  71. clipPath: true,
  72. /**
  73. * Set svg element's class name
  74. * @name svg
  75. * @memberof Options
  76. * @type {object}
  77. * @property {object} [svg] svg object
  78. * @property {string} [svg.classname] class name for svg element
  79. * @example
  80. * svg: {
  81. * classname: "test_class"
  82. * }
  83. */
  84. svg_classname: <string | undefined>undefined,
  85. /**
  86. * The desired size of the chart element.
  87. * If value is not specified, the width of the chart will be calculated by the size of the parent element it's appended to.
  88. * @name size
  89. * @memberof Options
  90. * @type {object}
  91. * @property {object} [size] size object
  92. * @property {number} [size.width] width of the chart element
  93. * @property {number} [size.height] height of the chart element
  94. * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.ChartSize)
  95. * @example
  96. * size: {
  97. * width: 640,
  98. * height: 480
  99. * }
  100. */
  101. size_width: <number | undefined>undefined,
  102. size_height: <number | undefined>undefined,
  103. /**
  104. * The padding of the chart element.
  105. * - **NOTE:** for more information, see the "[`Understanding padding`](https://github.com/naver/billboard.js/wiki/Understanding-padding)"" wiki documentaion.
  106. * @name padding
  107. * @memberof Options
  108. * @type {object}
  109. * @property {object|boolean} [padding=true] Set padding of chart, and accepts object or boolean type.
  110. * - `Object`: Specify each side's padding.
  111. * - `false`: Remove padding completely and make shape to fully occupy the container element.
  112. * - In this case, axes and subchart will be hidden.
  113. * - To adjust some padding from this state, use `axis.[x|y].padding` option.
  114. * @property {string} [padding.mode] padding mode
  115. * - `"fit"`: Reduce padding as much as possible to make chart fit to the container element for chart types w/axis.<br>When specified, all padding values will be relative from fitted value.
  116. * @property {number} [padding.top] padding on the top of chart
  117. * @property {number} [padding.right] padding on the right of chart
  118. * @property {number} [padding.bottom] padding on the bottom of chart
  119. * @property {number} [padding.left] padding on the left of chart
  120. * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.Padding)
  121. * @see [Demo: Fit padding](https://naver.github.io/billboard.js/demo/#ChartOptions.FitPadding)
  122. * @example
  123. * // remove padding completely.
  124. * padding: false,
  125. *
  126. * padding: {
  127. * // specifying mode value, will reduce padding and make fit to the container element.
  128. * mode: "fit"
  129. *
  130. * // when mode is "fit", all padding values will be relative from fitted value.
  131. * // so, 0 will be initial fitted value.
  132. * top: 20,
  133. * right: 20,
  134. * bottom: 20,
  135. * left: 20
  136. * }
  137. *
  138. * // or specify padding value for each side
  139. * padding: {
  140. * top: 20,
  141. * right: 20,
  142. * bottom: 20,
  143. * left: 20
  144. * }
  145. */
  146. padding: true,
  147. padding_mode: <"fit" | undefined>undefined,
  148. padding_left: <number | undefined>undefined,
  149. padding_right: <number | undefined>undefined,
  150. padding_top: <number | undefined>undefined,
  151. padding_bottom: <number | undefined>undefined,
  152. /**
  153. * Set chart resize options
  154. * @name resize
  155. * @memberof Options
  156. * @type {object}
  157. * @property {object} [resize] resize object
  158. * @property {boolean|string} [resize.auto=true] Set chart resize automatically on viewport changes.
  159. * - **NOTE:** Available options
  160. * - true: Enables automatic resize.
  161. * - false: Disables automatic resize.
  162. * - "parent": Enables automatic resize when the parent node is resized.
  163. * - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
  164. * @property {boolean|number} [resize.timer=true] Set resize timer option.
  165. * - **NOTE:** Available options
  166. * - The resize function will be called using:
  167. * - true: `setTimeout()`
  168. * - false: `requestIdleCallback()`
  169. * - Given number(delay in ms) value, resize function will be triggered using `setTimeout()` with given delay.
  170. * @see [Demo: resize "parent"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeParent)
  171. * @see [Demo: resize "viewBox"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeViewBox)
  172. * @example
  173. * resize: {
  174. * auto: false,
  175. *
  176. * // set resize based on parent node width value
  177. * auto: "parent",
  178. *
  179. * // set resize based on viewBox value
  180. * auto: "viewBox",
  181. *
  182. * // set resize function will be triggered using `setTimeout()`
  183. * timer: true,
  184. *
  185. * // set resize function will be triggered using `requestIdleCallback()`
  186. * timer: false,
  187. *
  188. * // set resize function will be triggered using `setTimeout()` with a delay of `100ms`.
  189. * timer: 100
  190. * }
  191. */
  192. resize_auto: <boolean | "parent" | "viewBox">true,
  193. resize_timer: true,
  194. /**
  195. * Set a callback to execute when the chart is clicked.
  196. * @name onclick
  197. * @memberof Options
  198. * @type {Function}
  199. * @default undefined
  200. * @example
  201. * onclick: function(event) {
  202. * this; // chart instance itself
  203. * event; // native event object
  204. * ...
  205. * }
  206. */
  207. onclick: <(() => void) | undefined>undefined,
  208. /**
  209. * Set a callback to execute when mouse/touch enters the chart.
  210. * @name onover
  211. * @memberof Options
  212. * @type {Function}
  213. * @default undefined
  214. * @example
  215. * onover: function(event) {
  216. * this; // chart instance itself
  217. * event; // native event object
  218. * ...
  219. * }
  220. */
  221. onover: <(() => void) | undefined>undefined,
  222. /**
  223. * Set a callback to execute when mouse/touch leaves the chart.
  224. * @name onout
  225. * @memberof Options
  226. * @type {Function}
  227. * @default undefined
  228. * @example
  229. * onout: function(event) {
  230. * this; // chart instance itself
  231. * event; // native event object
  232. * ...
  233. * }
  234. */
  235. onout: <(() => void) | undefined>undefined,
  236. /**
  237. * Set a callback to execute when user resizes the screen.
  238. * @name onresize
  239. * @memberof Options
  240. * @type {Function}
  241. * @default undefined
  242. * @example
  243. * onresize: function() {
  244. * this; // chart instance itself
  245. * ...
  246. * }
  247. */
  248. onresize: <(() => void) | undefined>undefined,
  249. /**
  250. * Set a callback to execute when screen resize finished.
  251. * @name onresized
  252. * @memberof Options
  253. * @type {Function}
  254. * @default undefined
  255. * @example
  256. * onresized: function() {
  257. * this; // chart instance itself
  258. * ...
  259. * }
  260. */
  261. onresized: <(() => void) | undefined>undefined,
  262. /**
  263. * Set a callback to execute before the chart is initialized
  264. * @name onbeforeinit
  265. * @memberof Options
  266. * @type {Function}
  267. * @default undefined
  268. * @example
  269. * onbeforeinit: function() {
  270. * this; // chart instance itself
  271. * ...
  272. * }
  273. */
  274. onbeforeinit: <(() => void) | undefined>undefined,
  275. /**
  276. * Set a callback to execute when the chart is initialized.
  277. * @name oninit
  278. * @memberof Options
  279. * @type {Function}
  280. * @default undefined
  281. * @example
  282. * oninit: function() {
  283. * this; // chart instance itself
  284. * ...
  285. * }
  286. */
  287. oninit: <(() => void) | undefined>undefined,
  288. /**
  289. * Set a callback to execute after the chart is initialized
  290. * @name onafterinit
  291. * @memberof Options
  292. * @type {Function}
  293. * @default undefined
  294. * @example
  295. * onafterinit: function() {
  296. * this; // chart instance itself
  297. * ...
  298. * }
  299. */
  300. onafterinit: <(() => void) | undefined>undefined,
  301. /**
  302. * Set a callback which is executed when the chart is rendered. Basically, this callback will be called in each time when the chart is redrawed.
  303. * @name onrendered
  304. * @memberof Options
  305. * @type {Function}
  306. * @default undefined
  307. * @example
  308. * onrendered: function() {
  309. * this; // chart instance itself
  310. * ...
  311. * }
  312. */
  313. onrendered: <(() => void) | undefined>undefined,
  314. /**
  315. * Set duration of transition (in milliseconds) for chart animation.<br><br>
  316. * - **NOTE:** If `0 `or `null` set, transition will be skipped. So, this makes initial rendering faster especially in case you have a lot of data.
  317. * @name transition
  318. * @memberof Options
  319. * @type {object}
  320. * @property {object} [transition] transition object
  321. * @property {number} [transition.duration=350] duration in milliseconds
  322. * @example
  323. * transition: {
  324. * duration: 500
  325. * }
  326. */
  327. transition_duration: 250,
  328. /**
  329. * Set plugins
  330. * @name plugins
  331. * @memberof Options
  332. * @type {Array}
  333. * @example
  334. * plugins: [
  335. * new bb.plugin.stanford({ ... }),
  336. * new PluginA(),
  337. * ...
  338. * ]
  339. */
  340. plugins: [],
  341. /**
  342. * Control the render timing
  343. * @name render
  344. * @memberof Options
  345. * @type {object}
  346. * @property {object} [render] render object
  347. * @property {boolean} [render.lazy=true] Make to not render at initialization.
  348. * - **NOTE**:
  349. * - Enabled by default when bind element's visibility is hidden.
  350. * - When set to `false`, will initialize the chart regardless the bind element's visibility state, but in this case chart can't be guaranteed to be rendered properly.
  351. * @property {boolean} [render.observe=true] Observe bind element's visibility(`display` or `visiblity` inline css property or class value) & render when is visible automatically (for IEs, only works IE11+). When set to **false**, call [`.flush()`](./Chart.html#flush) to render.
  352. * @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.LazyRender)
  353. * @example
  354. * render: {
  355. * lazy: true,
  356. * observe: true
  357. * }
  358. *
  359. * @example
  360. * // <!-- render.lazy will detect visibility defined -->
  361. * // (a) <div id='chart' class='hide'></div>
  362. * // (b) <div id='chart' style='display:none'></div>
  363. *
  364. * // render.lazy enabled by default when element is hidden
  365. * var chart = bb.generate({ ... });
  366. *
  367. * // chart will be rendered automatically when element's visibility changes
  368. * // Note: works only for inlined css property or class attribute changes
  369. * document.getElementById('chart').classList.remove('hide') // (a)
  370. * document.getElementById('chart').style.display = 'block'; // (b)
  371. *
  372. * @example
  373. * // chart won't be rendered and not observing bind element's visiblity changes
  374. * var chart = bb.generate({
  375. * render: {
  376. * lazy: true,
  377. * observe: false
  378. * }
  379. * });
  380. *
  381. * // call at any point when you want to render
  382. * chart.flush();
  383. */
  384. render: <{lazy?: boolean, observe?: boolean}>{},
  385. /**
  386. * Show rectangles inside the chart.<br><br>
  387. * - **NOTE:**<br>
  388. * - axis must be x, y or y2. start and end should be the value where regions start and end.
  389. * - If not specified, the edge values will be used.
  390. * - If timeseries x axis, date string, Date object and unixtime integer can be used.
  391. * - If category x axis, category name can be used for start and end.
  392. * - If class is set, the region element will have it as class.
  393. *
  394. * This option accept array of object with below values:
  395. * - `axis {string}`: 'x', 'y', or 'y2'
  396. * - `[start] {number|Date|string}`: Start position of the region. If not set, the start will be the edge of the chart.
  397. * - `[end] {number|Date|string}`: End position of the region. If not set, the end will be the edge of the chart.
  398. * - `[class] {string}`: Class value to apply to the region.
  399. * - `[label] {object}` Lable text option.
  400. * - `text {string}`: Text value.
  401. * - `x {number}`: x Position.
  402. * - `y {number}`: y Position.
  403. * - `center {string}`: Align label at the center. Allowed values are 'x', 'y', 'xy'.
  404. * - `color {string}`: Color string.
  405. * - `rotated (boolean)`: Whether rotate label or not.
  406. * @name regions
  407. * @memberof Options
  408. * @type {Array}
  409. * @default []
  410. * @see [Demo: Regions](https://naver.github.io/billboard.js/demo/#Region.Region)
  411. * @see [Demo: Regions Timeseries](https://naver.github.io/billboard.js/demo/#Region.RegionWithTimeseries)
  412. * @see [Demo: Regions Label](https://naver.github.io/billboard.js/demo/#Region.RegionLabel)
  413. * @example
  414. * regions: [
  415. * {
  416. * axis: "x",
  417. * start: 1,
  418. * end: 4,
  419. * class: "region-1-4",
  420. * label: {
  421. * text: "Region Text",
  422. * x: 5, // position relative of the initial x coordinate
  423. * y: 5, // position relative of the initial y coordinate
  424. * center: "xy", // center text label in both direction.
  425. * color: "red", // color string
  426. * rotated: true // make text to show in vertical or horizontal
  427. * }
  428. * }
  429. * ]
  430. */
  431. regions: <RegionOptions[]>[]
  432. };