-PlotKit.CanvasRenderer.prototype._initialiseEvents = function() {
- var connect = MochiKit.Signal.connect;
- var bind = MochiKit.Base.bind;
- //MochiKit.Signal.registerSignals(this, ['onmouseover', 'onclick', 'onmouseout', 'onmousemove']);
- //connect(this.element, 'onmouseover', bind(this.onmouseover, this));
- //connect(this.element, 'onmouseout', bind(this.onmouseout, this));
- //connect(this.element, 'onmousemove', bind(this.onmousemove, this));
- connect(this.element, 'onclick', bind(this.onclick, this));
-};
-
-PlotKit.CanvasRenderer.prototype._resolveObject = function(e) {
- // does not work in firefox
- //var x = (e.event().offsetX - this.area.x) / this.area.w;
- //var y = (e.event().offsetY - this.area.y) / this.area.h;
-
- var x = (e.mouse().page.x - PlotKit.Base.findPosX(this.element) - this.area.x) / this.area.w;
- var y = (e.mouse().page.y - PlotKit.Base.findPosY(this.element) - this.area.y) / this.area.h;
-
- //log(x, y);
-
- var isHit = this.layout.hitTest(x, y);
- if (isHit)
- return isHit;
- return null;
-};
-
-PlotKit.CanvasRenderer.prototype._createEventObject = function(layoutObj, e) {
- if (layoutObj == null) {
- return null;
- }
-
- e.chart = layoutObj
- return e;
-};
-
-
-PlotKit.CanvasRenderer.prototype.onclick = function(e) {
- var layoutObject = this._resolveObject(e);
- var eventObject = this._createEventObject(layoutObject, e);
- if (eventObject != null)
- MochiKit.Signal.signal(this, "onclick", eventObject);
-};
-
-PlotKit.CanvasRenderer.prototype.onmouseover = function(e) {
- var layoutObject = this._resolveObject(e);
- var eventObject = this._createEventObject(layoutObject, e);
- if (eventObject != null)
- signal(this, "onmouseover", eventObject);
-};
-
-PlotKit.CanvasRenderer.prototype.onmouseout = function(e) {
- var layoutObject = this._resolveObject(e);
- var eventObject = this._createEventObject(layoutObject, e);
- if (eventObject == null)
- signal(this, "onmouseout", e);
- else
- signal(this, "onmouseout", eventObject);
-
-};
-
-PlotKit.CanvasRenderer.prototype.onmousemove = function(e) {
- var layoutObject = this._resolveObject(e);
- var eventObject = this._createEventObject(layoutObject, e);
-
- if ((layoutObject == null) && (this.event_isinside == null)) {
- // TODO: should we emit an event anyway?
- return;
- }
-
- if ((layoutObject != null) && (this.event_isinside == null))
- signal(this, "onmouseover", eventObject);
-
- if ((layoutObject == null) && (this.event_isinside != null))
- signal(this, "onmouseout", eventObject);
-
- if ((layoutObject != null) && (this.event_isinside != null))
- signal(this, "onmousemove", eventObject);
-
- this.event_isinside = layoutObject;
- //log("move", x, y);
-};