UNPKG

1.72 kBJavaScriptView Raw
1import { MIN_CHART_HEIGHT, MIN_CHART_WIDTH } from '../constant';
2/**
3 * get the element's bounding size
4 * @param ele dom element
5 * @returns the element width and height
6 */
7function getElementSize(ele) {
8 var style = getComputedStyle(ele);
9 return {
10 width: (ele.clientWidth || parseInt(style.width, 10)) -
11 parseInt(style.paddingLeft, 10) -
12 parseInt(style.paddingRight, 10),
13 height: (ele.clientHeight || parseInt(style.height, 10)) -
14 parseInt(style.paddingTop, 10) -
15 parseInt(style.paddingBottom, 10),
16 };
17}
18/**
19 * is value a valid number
20 * @param v the input value
21 * @returns whether it is a number
22 */
23function isNumber(v) {
24 return typeof v === 'number' && !isNaN(v);
25}
26/**
27 * @ignore
28 * calculate the chart size
29 * @param ele DOM element
30 * @param autoFit should auto fit
31 * @param width chart width which is set by user
32 * @param height chart height which is set by user
33 * @returns the chart width and height
34 */
35export function getChartSize(ele, autoFit, width, height) {
36 var w = width;
37 var h = height;
38 if (autoFit) {
39 var size = getElementSize(ele);
40 w = size.width ? size.width : w;
41 h = size.height ? size.height : h;
42 }
43 return {
44 width: Math.max(isNumber(w) ? w : MIN_CHART_WIDTH, MIN_CHART_WIDTH),
45 height: Math.max(isNumber(h) ? h : MIN_CHART_HEIGHT, MIN_CHART_HEIGHT),
46 };
47}
48/**
49 * @ignore
50 * remove html element from its parent
51 * @param dom
52 */
53export function removeDom(dom) {
54 var parent = dom.parentNode;
55 if (parent) {
56 parent.removeChild(dom);
57 }
58}
59/** @ignore */
60export { createDom, modifyCSS } from '@antv/dom-util';
61//# sourceMappingURL=dom.js.map
\No newline at end of file