Skip to content

Commit

Permalink
纠正命名规则
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 8, 2017
1 parent b3a5116 commit eeb4cc3
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 208 deletions.
8 changes: 0 additions & 8 deletions atool-test.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Canvas.PathUtil = {
pathToAbsolute: toAbsolute, // Util.path2Absolute
catmullRom2bezier: catmullRomToBezier,
};
Canvas.MatrixUtil = require('./src/util/matrix-util');
Canvas.DomUtil = require('./src/util/dom-util');
Canvas.MatrixUtil = require('./src/util/matrix');
Canvas.DomUtil = require('./src/util/dom');
Canvas.Matrix = require('@ali/g-matrix');

module.exports = Canvas;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
"index": "./index"
},
"dependencies": {
"@ali/g-interpolation": "~0.0.0",
"@ali/g-matrix": "~0.0.0",
"@ali/g-math": "~1.0.0",
"@ali/g-color": "~0.0.7",
"@ali/g-event": "~0.0.0",
"@ali/g-interpolation": "~0.0.0",
"@ali/g-matrix": "~0.0.0",
"@ali/g-path-util": "~1.0.0",
"@ali/g-tween": "~0.3.1-beta.1",
"@ali/g-path-util": "~1.0.0"
"gl-matrix": "^2.3.2"
},
"pre-commit": {
"run": [
Expand Down
50 changes: 5 additions & 45 deletions src/canvas.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict';
import Util from './util/index';
import MouseEvent from './mouse-event';
import G from './g/index';

var Util = require('./util/index');
var MouseEvent = require('./event/mouse-event');
var G = require('./g/index');

var Canvas = function(cfg) {
const Canvas = function(cfg) {
Canvas.superclass.constructor.call(this, cfg);
};

Canvas.CFG = {

eventEnable: true,
/**
* 像素宽度
Expand Down Expand Up @@ -181,24 +178,7 @@ Util.augment(Canvas, {
* 设置初始画布参数
*/
_setInitSize: function() {
if (this.get('widthStyle')) {
this.changeSizeByCss(this.get('widthStyle'), this.get('heightStyle'));
} else if (this.get('width')) {
this.changeSize(this.get('width'), this.get('height'));
}
},
/**
* 获取像素长度
*/
_getPx: function(edge, value) {
var canvasDOM = this.get('canvasDOM');
canvasDOM.style[edge] = value;
var clientRect = Util.getBoundingClientRect(canvasDOM);
if (edge === 'width') {
return clientRect.right - clientRect.left;
} else if (edge === 'height') {
return clientRect.bottom - clientRect.top;
}
this.changeSize(this.get('width'), this.get('height'));
},
/**
* 重设画布尺寸
Expand Down Expand Up @@ -231,26 +211,6 @@ Util.augment(Canvas, {
var height = this.get('height');
return height * pixelRatio;
},
/**
* 通过css设置画布尺寸
* @param {String} CSS width
* @param {String} CSS height
*/
changeSizeByCss: function(width, height) {
var pixelRatio = this.get('pixelRatio');
width = this._getPx('width', width);
height = this._getPx('height', height);
var widthCanvas = width * pixelRatio;
var heightCanvas = height * pixelRatio;

this.set('widthStyle', width);
this.set('heightStyle', height);
this.set('widthCanvas', widthCanvas);
this.set('heightCanvas', heightCanvas);
this.set('width', width);
this.set('height', height);
this._reSize();
},
/**
* 设置画布尺寸
* @param {Number} Canvas width
Expand Down
42 changes: 0 additions & 42 deletions src/event/event.js

This file was deleted.

5 changes: 2 additions & 3 deletions src/g/core/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ var Util = require('../../util/index');
var Attributes = require('./mixin/attributes');
var Transform = require('./mixin/transform');
var Animate = require('./mixin/animate');
var EventDispatcher = require('./mixin/event-dispatcher');
var Format = require('../format');
// var Vector3 = require('@ali/g-matrix').Vector3;
var EventDispatcher = require('../../event/eventDispatcher');

var SHAPE_ATTRS = [
'fillStyle',
Expand Down Expand Up @@ -252,7 +251,7 @@ Util.augment(Element, Attributes, EventDispatcher, Transform, Animate, {
},
__setZIndex: function(zIndex) {
this.__cfg.zIndex = zIndex;
if (!Util.isNull(this.get('parent'))) {
if (!Util.isNil(this.get('parent'))) {
this.get('parent').sort();
}
return zIndex;
Expand Down
1 change: 1 addition & 0 deletions src/g/core/group.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Util = require('../../util/index');
var Vector3 = require('@ali/g-matrix').Vector3;
// import {vec3} from 'gl-matrix';
var Element = require('./element');
var Shape = require('../shape/index');
var SHAPE_MAP = {}; // 缓存图形类型
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Util = require('../util/index');
var Event = require('./event');
const Util = require('../../../util/index');
const Event = require('@ali/g-event');

module.exports = {
/**
Expand All @@ -15,9 +15,9 @@ module.exports = {
* @return {Object} this
*/
on: function(type, listener) {
var listeners = this.__listeners;
const listeners = this.__listeners;

if (Util.isNull(listeners[type])) {
if (Util.isNil(listeners[type])) {
listeners[type] = [];
}

Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = {
var listeners = self.__listeners;
var listenersArray = listeners[event.type];
event.target = self;
if (!Util.isNull(listenersArray)) {
if (!Util.isNil(listenersArray)) {
listenersArray.forEach(function(listener) {
listener.call(self, event);
});
Expand Down
4 changes: 2 additions & 2 deletions src/g/core/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Util.augment(Shape, {
var originOpacity = context.globalAlpha;
if (self.hasFill()) {
var fillOpacity = attrs.fillOpacity;
if (!Util.isNull(fillOpacity) && fillOpacity !== 1) {
if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
context.globalAlpha = fillOpacity;
context.fill();
context.globalAlpha = originOpacity;
Expand All @@ -33,7 +33,7 @@ Util.augment(Shape, {
var lineWidth = self.__attrs.lineWidth;
if (lineWidth > 0) {
var strokeOpacity = attrs.strokeOpacity;
if (!Util.isNull(strokeOpacity) && strokeOpacity !== 1) {
if (!Util.isNil(strokeOpacity) && strokeOpacity !== 1) {
context.globalAlpha = strokeOpacity;
}
context.stroke();
Expand Down
5 changes: 2 additions & 3 deletions src/g/format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Util = require('../util/index');
var GMath = require('@ali/g-math');
var GColor = require('@ali/g-color');

var regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/ig;
Expand Down Expand Up @@ -35,7 +34,7 @@ function addStop(steps, gradient, opacity) {

function parseLineGradient(color, self, opacity) {
var arr = regexLG.exec(color);
var angle = GMath.mod(GMath.degreeToRad(parseFloat(arr[1])), Math.PI * 2);
var angle = Util.mod(Util.toRadian(parseFloat(arr[1])), Math.PI * 2);
var steps = arr[2];
var box = self.getBBox();
var start;
Expand Down Expand Up @@ -169,7 +168,7 @@ module.exports = {
return parsePattern(color, self);
}
}
if (Util.isNull(opacity)) {
if (Util.isNil(opacity)) {
return color;
}
return multiplyOpacity(color, opacity);
Expand Down
16 changes: 8 additions & 8 deletions src/g/shape/cubic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Util.augment(Cubic, {
var l;

if (
Util.isNull(p1) ||
Util.isNull(p2) ||
Util.isNull(p3) ||
Util.isNull(p4)
Util.isNil(p1) ||
Util.isNil(p2) ||
Util.isNil(p3) ||
Util.isNil(p4)
) {
return null;
}
Expand Down Expand Up @@ -96,10 +96,10 @@ Util.augment(Cubic, {
var arrow = attrs.arrow;
context = context || self.get('context');
if (
Util.isNull(p1) ||
Util.isNull(p2) ||
Util.isNull(p3) ||
Util.isNull(p4)
Util.isNil(p1) ||
Util.isNil(p2) ||
Util.isNil(p3) ||
Util.isNil(p4)
) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions src/g/shape/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
var Util = require('../../util/index');
var Shape = require('../core/shape');
var Inside = require('./util/inside');
var gMath = require('@ali/g-math');
var ArcMath = require('./math/arc');
var Matrix = require('@ali/g-matrix');
var Vector2 = Matrix.Vector2;
Expand Down Expand Up @@ -102,7 +101,7 @@ Util.augment(Fan, {

var angle1 = ArcMath.nearAngle(angle, startAngle, endAngle, clockwise);

if (gMath.equal(angle, angle1)) {
if (Util.isNumberEqual(angle, angle1)) {
var ls = subv.lengthSq();
if (rs * rs <= ls && ls <= re * re) {
return true;
Expand Down
16 changes: 8 additions & 8 deletions src/g/shape/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ Util.augment(CImage, {

if (img instanceof Image || (img instanceof HTMLElement && Util.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS')) {
if (
Util.isNull(sx) ||
Util.isNull(sy) ||
Util.isNull(swidth) ||
Util.isNull(sheight)
Util.isNil(sx) ||
Util.isNil(sy) ||
Util.isNil(swidth) ||
Util.isNil(sheight)
) {
context.drawImage(img, x, y, width, height);
return;
}
if (
!Util.isNull(sx) &&
!Util.isNull(sy) &&
!Util.isNull(swidth) &&
!Util.isNull(sheight)
!Util.isNil(sx) &&
!Util.isNil(sy) &&
!Util.isNil(swidth) &&
!Util.isNil(sheight)
) {
context.drawImage(img, sx, sy, swidth, sheight, x, y, width, height);
return;
Expand Down
7 changes: 3 additions & 4 deletions src/g/shape/math/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @ignore
*/
var Vector2 = require('@ali/g-matrix').Vector2;
var GMath = require('@ali/g-math');
var Util = require('../../../util/index');

function circlePoint(cx, cy, r, angle) {
Expand Down Expand Up @@ -38,9 +37,9 @@ function nearAngle(angle, startAngle, endAngle, clockwise) {
if (endAngle - startAngle >= Math.PI * 2) {
plus = Math.PI * 2;
}
startAngle = GMath.mod(startAngle, Math.PI * 2);
endAngle = GMath.mod(endAngle, Math.PI * 2) + plus;
angle = GMath.mod(angle, Math.PI * 2);
startAngle = Util.mod(startAngle, Math.PI * 2);
endAngle = Util.mod(endAngle, Math.PI * 2) + plus;
angle = Util.mod(angle, Math.PI * 2);
if (clockwise) {
if (startAngle >= endAngle) {
if (angle > endAngle && angle < startAngle) {
Expand Down
9 changes: 4 additions & 5 deletions src/g/shape/math/cubic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @ignore
*/
var Vector2 = require('@ali/g-matrix').Vector2;
var GMath = require('@ali/g-math');
var Util = require('../../../util/index');

function cubicAt(p0, p1, p2, p3, t) {
Expand Down Expand Up @@ -101,16 +100,16 @@ function cubicExtrema(p0, p1, p2, p3) {
var t2;
var discSqrt;

if (GMath.equal(a, 0)) {
if (!GMath.equal(b, 0)) {
if (Util.isNumberEqual(a, 0)) {
if (!Util.isNumberEqual(b, 0)) {
t1 = -c / b;
if (t1 >= 0 && t1 <= 1) {
extrema.push(t1);
}
}
} else {
var disc = b * b - 4 * a * c;
if (GMath.equal(disc, 0)) {
if (Util.isNumberEqual(disc, 0)) {
extrema.push(-b / (2 * a));
} else if (disc > 0) {
discSqrt = Math.sqrt(disc);
Expand All @@ -134,7 +133,7 @@ function base3(t, p1, p2, p3, p4) {
}

function cubiclLen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
if (Util.isNull(z)) {
if (Util.isNil(z)) {
z = 1;
}
z = z > 1 ? 1 : z < 0 ? 0 : z;
Expand Down
Loading

0 comments on commit eeb4cc3

Please sign in to comment.