| 1 |
define(["dojo/_base/lang", "dojo/_base/array", "dojo/_base/declare", "dojo/_base/connect"], |
| 2 |
function(lang, arr, declare, hub){ |
| 3 |
|
| 4 |
return declare("dojox.charting.plot2d._PlotEvents", null, { |
| 5 |
constructor: function(){ |
| 6 |
this._shapeEvents = []; |
| 7 |
this._eventSeries = {}; |
| 8 |
}, |
| 9 |
destroy: function(){ |
| 10 |
|
| 11 |
|
| 12 |
this.resetEvents(); |
| 13 |
this.inherited(arguments); |
| 14 |
}, |
| 15 |
plotEvent: function(o){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
}, |
| 21 |
raiseEvent: function(o){ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
this.plotEvent(o); |
| 27 |
var t = lang.delegate(o); |
| 28 |
t.originalEvent = o.type; |
| 29 |
t.originalPlot = o.plot; |
| 30 |
t.type = "onindirect"; |
| 31 |
arr.forEach(this.chart.stack, function(plot){ |
| 32 |
if(plot !== this && plot.plotEvent){ |
| 33 |
t.plot = plot; |
| 34 |
plot.plotEvent(t); |
| 35 |
} |
| 36 |
}, this); |
| 37 |
}, |
| 38 |
connect: function(object, method){ |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
this.dirty = true; |
| 48 |
return hub.connect(this, "plotEvent", object, method); |
| 49 |
}, |
| 50 |
events: function(){ |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
return !!this.plotEvent.after; |
| 56 |
}, |
| 57 |
resetEvents: function(){ |
| 58 |
|
| 59 |
|
| 60 |
if(this._shapeEvents.length){ |
| 61 |
arr.forEach(this._shapeEvents, function(item){ |
| 62 |
item.shape.disconnect(item.handle); |
| 63 |
}); |
| 64 |
this._shapeEvents = []; |
| 65 |
} |
| 66 |
this.raiseEvent({type: "onplotreset", plot: this}); |
| 67 |
}, |
| 68 |
_connectSingleEvent: function(o, eventName){ |
| 69 |
this._shapeEvents.push({ |
| 70 |
shape: o.eventMask, |
| 71 |
handle: o.eventMask.connect(eventName, this, function(e){ |
| 72 |
o.type = eventName; |
| 73 |
o.event = e; |
| 74 |
this.raiseEvent(o); |
| 75 |
o.event = null; |
| 76 |
}) |
| 77 |
}); |
| 78 |
}, |
| 79 |
_connectEvents: function(o){ |
| 80 |
if(o){ |
| 81 |
o.chart = this.chart; |
| 82 |
o.plot = this; |
| 83 |
o.hAxis = this.hAxis || null; |
| 84 |
o.vAxis = this.vAxis || null; |
| 85 |
o.eventMask = o.eventMask || o.shape; |
| 86 |
this._connectSingleEvent(o, "onmouseover"); |
| 87 |
this._connectSingleEvent(o, "onmouseout"); |
| 88 |
this._connectSingleEvent(o, "onclick"); |
| 89 |
} |
| 90 |
}, |
| 91 |
_reconnectEvents: function(seriesName){ |
| 92 |
var a = this._eventSeries[seriesName]; |
| 93 |
if(a){ |
| 94 |
arr.forEach(a, this._connectEvents, this); |
| 95 |
} |
| 96 |
}, |
| 97 |
fireEvent: function(seriesName, eventName, index, eventObject){ |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
var s = this._eventSeries[seriesName]; |
| 111 |
if(s && s.length && index < s.length){ |
| 112 |
var o = s[index]; |
| 113 |
o.type = eventName; |
| 114 |
o.event = eventObject || null; |
| 115 |
this.raiseEvent(o); |
| 116 |
o.event = null; |
| 117 |
} |
| 118 |
} |
| 119 |
}); |
| 120 |
}); |