Comparing version 3.3.5 to 3.4.0-beta.1
var Util = require('./util/index'); | ||
var Event = require('./event'); | ||
var Event = require('./core/event'); | ||
@@ -79,3 +79,3 @@ var Group = require('./core/group'); | ||
Util.extend(Canvas, Group); | ||
Util.augment(Canvas, { | ||
Util.augment(Canvas, Event, { | ||
init: function init() { | ||
@@ -93,105 +93,5 @@ Canvas.superclass.init.call(this); | ||
if (this.get('eventEnable')) { | ||
this._registEvents(); | ||
this.registerEvent(this); | ||
} | ||
}, | ||
getEmitter: function getEmitter(element, event) { | ||
if (element) { | ||
if (Util.isEmpty(element._getEvents())) { | ||
var parent = element.get('parent'); | ||
if (parent && !event.propagationStopped) { | ||
return this.getEmitter(parent, event); | ||
} | ||
} else { | ||
return element; | ||
} | ||
} | ||
}, | ||
_getEventObj: function _getEventObj(type, e, point, target) { | ||
var event = new Event(type, e, true, true); | ||
event.x = point.x; | ||
event.y = point.y; | ||
event.clientX = e.clientX; | ||
event.clientY = e.clientY; | ||
event.currentTarget = target; | ||
event.target = target; | ||
return event; | ||
}, | ||
_triggerEvent: function _triggerEvent(type, e) { | ||
var point = this.getPointByClient(e.clientX, e.clientY); | ||
var shape = this.getShape(point.x, point.y, e); | ||
var el = this.get('el'); | ||
var emitObj; | ||
if (type === 'mousemove') { | ||
var preShape = this.get('preShape'); | ||
if (preShape && preShape !== shape) { | ||
var mouseleave = this._getEventObj('mouseleave', e, point, preShape); | ||
emitObj = this.getEmitter(preShape, e); | ||
emitObj && emitObj.emit('mouseleave', mouseleave); | ||
el.style.cursor = 'default'; | ||
} | ||
if (shape) { | ||
var mousemove = this._getEventObj('mousemove', e, point, shape); | ||
emitObj = this.getEmitter(shape, e); | ||
emitObj && emitObj.emit('mousemove', mousemove); | ||
if (preShape !== shape) { | ||
var mouseenter = this._getEventObj('mouseenter', e, point, shape); | ||
emitObj && emitObj.emit('mouseenter', mouseenter, e); | ||
} | ||
} else { | ||
var canvasmousemove = this._getEventObj('mousemove', e, point, this); | ||
this.emit('mousemove', canvasmousemove); | ||
} | ||
this.set('preShape', shape); | ||
} else { | ||
var event = this._getEventObj(type, e, point, shape || this); | ||
emitObj = this.getEmitter(shape, e); | ||
if (emitObj && emitObj !== this) { | ||
emitObj.emit(type, event); | ||
} | ||
this.emit(type, event); | ||
} | ||
if (shape && !shape.get('destroyed')) { | ||
el.style.cursor = shape.attr('cursor') || 'default'; | ||
} | ||
}, | ||
_registEvents: function _registEvents() { | ||
var self = this; | ||
var el = self.get('el'); | ||
var events = ['mouseout', 'mouseover', 'mousemove', 'mousedown', 'mouseleave', 'mouseup', 'click', 'dblclick']; | ||
Util.each(events, function (event) { | ||
el.addEventListener(event, function (e) { | ||
self._triggerEvent(event, e); | ||
}, false); | ||
}); // special cases | ||
el.addEventListener('touchstart', function (e) { | ||
if (!Util.isEmpty(e.touches)) { | ||
self._triggerEvent('touchstart', e.touches[0]); | ||
} | ||
}, false); | ||
el.addEventListener('touchmove', function (e) { | ||
if (!Util.isEmpty(e.touches)) { | ||
self._triggerEvent('touchmove', e.touches[0]); | ||
} | ||
}, false); | ||
el.addEventListener('touchend', function (e) { | ||
if (!Util.isEmpty(e.changedTouches)) { | ||
self._triggerEvent('touchend', e.changedTouches[0]); | ||
} | ||
}, false); | ||
}, | ||
_scale: function _scale() { | ||
@@ -198,0 +98,0 @@ if (this._cfg.renderType !== 'svg') { |
@@ -9,3 +9,3 @@ var Util = require('../util/index'); | ||
var EventEmitter = require('wolfy87-eventemitter'); | ||
var EventEmitter = require('./mixin/event'); | ||
@@ -17,3 +17,4 @@ var Element = function Element(cfg) { | ||
visible: true, | ||
destroyed: false | ||
destroyed: false, | ||
_events: {} | ||
}; // 配置存放地 | ||
@@ -20,0 +21,0 @@ |
@@ -479,2 +479,6 @@ var Util = require('../util/index'); | ||
clear: function clear(delayRemove) { | ||
if (this.get('destroyed')) { | ||
return; | ||
} | ||
var children = this._cfg.children; | ||
@@ -481,0 +485,0 @@ |
@@ -22,3 +22,3 @@ module.exports = { | ||
// version, etc. | ||
version: '3.3.5' | ||
version: '3.4.0-beta.1' | ||
}; |
@@ -51,6 +51,5 @@ var Util = require('../../util'); | ||
console.warn(ev); | ||
} finally { | ||
self.toDraw = false; | ||
} | ||
self.toDraw = false; | ||
} | ||
@@ -57,0 +56,0 @@ |
@@ -113,6 +113,5 @@ var Util = require('../../util'); | ||
console.warn(ev); | ||
} finally { | ||
self.toDraw = false; | ||
} | ||
self.toDraw = false; | ||
} | ||
@@ -390,3 +389,2 @@ | ||
var parent = model._cfg.parent; | ||
var parentNode = parent._cfg.el; | ||
@@ -398,5 +396,12 @@ if (!type) { | ||
var shape = document.createElementNS('http://www.w3.org/2000/svg', type); | ||
if (model._cfg.id) { | ||
shape.id = model._cfg.id; | ||
} | ||
model._cfg.el = shape; | ||
if (parent) { | ||
var parentNode = parent._cfg.el; | ||
if (typeof index === 'undefined') { | ||
@@ -403,0 +408,0 @@ parentNode.appendChild(shape); |
{ | ||
"name": "@antv/g", | ||
"version": "3.3.5", | ||
"version": "3.4.0-beta.1", | ||
"description": "A canvas library which providing 2d draw for G2.", | ||
@@ -76,5 +76,4 @@ "keywords": [ | ||
"d3-interpolate": "~1.1.5", | ||
"d3-timer": "~1.0.6", | ||
"wolfy87-eventemitter": "~5.1.0" | ||
"d3-timer": "~1.0.6" | ||
} | ||
} |
const Util = require('./util/index'); | ||
const Event = require('./event'); | ||
const Event = require('./core/event'); | ||
const Group = require('./core/group'); | ||
@@ -67,3 +67,3 @@ const Timeline = require('./core/mixin/timeline'); | ||
Util.augment(Canvas, { | ||
Util.augment(Canvas, Event, { | ||
init() { | ||
@@ -76,106 +76,5 @@ Canvas.superclass.init.call(this); | ||
if (this.get('eventEnable')) { | ||
this._registEvents(); | ||
this.registerEvent(this); | ||
} | ||
}, | ||
getEmitter(element, event) { | ||
if (element) { | ||
if (Util.isEmpty(element._getEvents())) { | ||
const parent = element.get('parent'); | ||
if (parent && !event.propagationStopped) { | ||
return this.getEmitter(parent, event); | ||
} | ||
} else { | ||
return element; | ||
} | ||
} | ||
}, | ||
_getEventObj(type, e, point, target) { | ||
const event = new Event(type, e, true, true); | ||
event.x = point.x; | ||
event.y = point.y; | ||
event.clientX = e.clientX; | ||
event.clientY = e.clientY; | ||
event.currentTarget = target; | ||
event.target = target; | ||
return event; | ||
}, | ||
_triggerEvent(type, e) { | ||
const point = this.getPointByClient(e.clientX, e.clientY); | ||
const shape = this.getShape(point.x, point.y, e); | ||
const el = this.get('el'); | ||
let emitObj; | ||
if (type === 'mousemove') { | ||
const preShape = this.get('preShape'); | ||
if (preShape && preShape !== shape) { | ||
const mouseleave = this._getEventObj('mouseleave', e, point, preShape); | ||
emitObj = this.getEmitter(preShape, e); | ||
emitObj && emitObj.emit('mouseleave', mouseleave); | ||
el.style.cursor = 'default'; | ||
} | ||
if (shape) { | ||
const mousemove = this._getEventObj('mousemove', e, point, shape); | ||
emitObj = this.getEmitter(shape, e); | ||
emitObj && emitObj.emit('mousemove', mousemove); | ||
if (preShape !== shape) { | ||
const mouseenter = this._getEventObj('mouseenter', e, point, shape); | ||
emitObj && emitObj.emit('mouseenter', mouseenter, e); | ||
} | ||
} else { | ||
const canvasmousemove = this._getEventObj('mousemove', e, point, this); | ||
this.emit('mousemove', canvasmousemove); | ||
} | ||
this.set('preShape', shape); | ||
} else { | ||
const event = this._getEventObj(type, e, point, shape || this); | ||
emitObj = this.getEmitter(shape, e); | ||
if (emitObj && emitObj !== this) { | ||
emitObj.emit(type, event); | ||
} | ||
this.emit(type, event); | ||
} | ||
if (shape && !shape.get('destroyed')) { | ||
el.style.cursor = shape.attr('cursor') || 'default'; | ||
} | ||
}, | ||
_registEvents() { | ||
const self = this; | ||
const el = self.get('el'); | ||
const events = [ | ||
'mouseout', | ||
'mouseover', | ||
'mousemove', | ||
'mousedown', | ||
'mouseleave', | ||
'mouseup', | ||
'click', | ||
'dblclick' | ||
]; | ||
Util.each(events, event => { | ||
el.addEventListener(event, e => { | ||
self._triggerEvent(event, e); | ||
}, false); | ||
}); | ||
// special cases | ||
el.addEventListener('touchstart', e => { | ||
if (!Util.isEmpty(e.touches)) { | ||
self._triggerEvent('touchstart', e.touches[0]); | ||
} | ||
}, false); | ||
el.addEventListener('touchmove', e => { | ||
if (!Util.isEmpty(e.touches)) { | ||
self._triggerEvent('touchmove', e.touches[0]); | ||
} | ||
}, false); | ||
el.addEventListener('touchend', e => { | ||
if (!Util.isEmpty(e.changedTouches)) { | ||
self._triggerEvent('touchend', e.changedTouches[0]); | ||
} | ||
}, false); | ||
}, | ||
_scale() { | ||
@@ -182,0 +81,0 @@ if (this._cfg.renderType !== 'svg') { |
@@ -5,3 +5,3 @@ const Util = require('../util/index'); | ||
const Animate = require('./mixin/animation'); | ||
const EventEmitter = require('wolfy87-eventemitter'); | ||
const EventEmitter = require('./mixin/event'); | ||
@@ -13,3 +13,4 @@ const Element = function(cfg) { | ||
visible: true, | ||
destroyed: false | ||
destroyed: false, | ||
_events: {} | ||
}; // 配置存放地 | ||
@@ -16,0 +17,0 @@ |
@@ -431,2 +431,5 @@ const Util = require('../util/index'); | ||
clear(delayRemove) { | ||
if (this.get('destroyed')) { | ||
return; | ||
} | ||
const children = this._cfg.children; | ||
@@ -433,0 +436,0 @@ for (let i = children.length - 1; i >= 0; i--) { |
@@ -22,3 +22,3 @@ module.exports = { | ||
// version, etc. | ||
version: '3.3.5' | ||
version: '3.4.0-beta.1' | ||
}; |
@@ -56,5 +56,5 @@ const Util = require('../../util'); | ||
console.warn(ev); | ||
} finally { | ||
self.toDraw = false; | ||
} | ||
self.toDraw = false; | ||
} | ||
@@ -61,0 +61,0 @@ if (self.animateHandler) { |
@@ -103,5 +103,5 @@ const Util = require('../../util'); | ||
console.warn(ev); | ||
} finally { | ||
self.toDraw = false; | ||
} | ||
self.toDraw = false; | ||
} | ||
@@ -325,3 +325,2 @@ if (self.animateHandler) { | ||
const parent = model._cfg.parent; | ||
const parentNode = parent._cfg.el; | ||
if (!type) { | ||
@@ -331,4 +330,8 @@ throw new Error('the type' + model.type + 'is not supported by svg'); | ||
const shape = document.createElementNS('http://www.w3.org/2000/svg', type); | ||
if (model._cfg.id) { | ||
shape.id = model._cfg.id; | ||
} | ||
model._cfg.el = shape; | ||
if (parent) { | ||
const parentNode = parent._cfg.el; | ||
if (typeof index === 'undefined') { | ||
@@ -335,0 +338,0 @@ parentNode.appendChild(shape); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
130
27663
1036025
1
- Removedwolfy87-eventemitter@~5.1.0
- Removedwolfy87-eventemitter@5.1.0(transitive)