Skip to content

Commit

Permalink
util 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 7, 2017
1 parent e066c50 commit b3a5116
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 deletions.
29 changes: 20 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
var Canvas = require('./src/canvas')
var G = require('./src/g/index')
Canvas.G = G
Canvas.Group = G.Group
Canvas.Shape = {}
Canvas.Shape.Marker = G.Marker
Canvas.Util = require('./src/util/index')
Canvas.Matrix = require('@ali/g-matrix')
module.exports = Canvas
import {toArray, toString, toCurve, toAbsolute, catmullRomToBezier} from '@ali/g-path-util';

var Canvas = require('./src/canvas');
var G = require('./src/g/index');
Canvas.G = G;
Canvas.Group = G.Group;
Canvas.Shape = {};
Canvas.Shape.Marker = G.Marker;
Canvas.PathUtil = {
parsePathString: toArray,
parsePathArray: toString, // Util.path2string
path2curve: toCurve,
pathToAbsolute: toAbsolute, // Util.path2Absolute
catmullRom2bezier: catmullRomToBezier,
};
Canvas.MatrixUtil = require('./src/util/matrix-util');
Canvas.DomUtil = require('./src/util/dom-util');
Canvas.Matrix = require('@ali/g-matrix');

module.exports = Canvas;
43 changes: 43 additions & 0 deletions src/util/dom-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,49 @@ module.exports = {
container.innerHTML = '' + str;
return container.childNodes[0];
},
/**
* 获取屏幕像素比
*/
getRatio() {
return window.devicePixelRatio ? window.devicePixelRatio : 2;
},
/**
* 获取宽度
* @param {HTMLElement} el dom节点
* @return {Number} 宽度
*/
getWidth(el) {
let width = Util.getStyle(el, 'width');
if (width === 'auto') {
width = el.offsetWidth;
}
return parseFloat(width);
},
/**
* 获取高度
* @param {HTMLElement} el dom节点
* @return {Number} 高度
*/
getHeight(el) {
let height = Util.getStyle(el, 'height');
if (height === 'auto') {
height = el.offsetHeight;
}
return parseFloat(height);
},
/**
* 获取外层高度
* @param {HTMLElement} el dom节点
* @return {Number} 高度
*/
getOuterHeight(el) {
const height = Util.getHeight(el);
const bTop = parseFloat(Util.getStyle(el, 'borderTopWidth')) || 0;
const pTop = parseFloat(Util.getStyle(el, 'paddingTop'));
const pBottom = parseFloat(Util.getStyle(el, 'paddingBottom'));
const bBottom = parseFloat(Util.getStyle(el, 'borderBottomWidth')) || 0;
return height + bTop + bBottom + pTop + pBottom;
},
/**
* TODO: 应该移除的
* 添加时间监听器
Expand Down
54 changes: 1 addition & 53 deletions src/util/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import CommonUtil from './common-util';
import DomUtil from './dom-util';
import MatrixUtil from './matrix-util';
import {toArray, toString, toCurve, toAbsolute, catmullRomToBezier} from '@ali/g-path-util';
import {merge} from 'lodash';

const Util = {};

merge(Util, CommonUtil, DomUtil, {
CommonUtil.merge(Util, CommonUtil, DomUtil, {
/**
* 混合方法 适用CFG模式
* @param {Array} arr 数组
Expand All @@ -28,55 +25,6 @@ merge(Util, CommonUtil, DomUtil, {
c[Param] = Util.merge(temp, c[Param]);
}
},
/**
* 获取屏幕像素比
*/
getRatio() {
return window.devicePixelRatio ? window.devicePixelRatio : 2;
},
/**
* 获取宽度
* @param {HTMLElement} el dom节点
* @return {Number} 宽度
*/
getWidth(el) {
let width = Util.getStyle(el, 'width');
if (width === 'auto') {
width = el.offsetWidth;
}
return parseFloat(width);
},
/**
* 获取高度
* @param {HTMLElement} el dom节点
* @return {Number} 高度
*/
getHeight(el) {
let height = Util.getStyle(el, 'height');
if (height === 'auto') {
height = el.offsetHeight;
}
return parseFloat(height);
},
/**
* 获取外层高度
* @param {HTMLElement} el dom节点
* @return {Number} 高度
*/
getOuterHeight(el) {
const height = Util.getHeight(el);
const bTop = parseFloat(Util.getStyle(el, 'borderTopWidth')) || 0;
const pTop = parseFloat(Util.getStyle(el, 'paddingTop'));
const pBottom = parseFloat(Util.getStyle(el, 'paddingBottom'));
const bBottom = parseFloat(Util.getStyle(el, 'borderBottomWidth')) || 0;
return height + bTop + bBottom + pTop + pBottom;
},
parsePathString: toArray,
parsePathArray: toString, // Util.path2string
path2curve: toCurve,
pathToAbsolute: toAbsolute, // Util.path2Absolute
catmullRom2bezier: catmullRomToBezier,
MatrixUtil: MatrixUtil,
});

module.exports = Util;

0 comments on commit b3a5116

Please sign in to comment.