Debian Codegraph @

dojox/charting/plot2d/_PlotEvents.js

raw symbols SCIP
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 // summary:
11 // Destroy any internal elements and event handlers.
12 this.resetEvents();
13 this.inherited(arguments);
14 },
15 plotEvent: function(o){
16 // summary:
17 // Stub function for use by specific plots.
18 // o: Object
19 // An object intended to represent event parameters.
20 },
21 raiseEvent: function(o){
22 // summary:
23 // Raises events in predefined order
24 // o: Object
25 // An object intended to represent event parameters.
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 // summary:
40 // Helper function to connect any object's method to our plotEvent.
41 // object: Object
42 // The object to connect to.
43 // method: String|Function
44 // The method to fire when our plotEvent is fired.
45 // returns: Array
46 // The handle as returned from dojo.connect (see dojo.connect).
47 this.dirty = true;
48 return hub.connect(this, "plotEvent", object, method); // Array
49 },
50 events: function(){
51 // summary:
52 // Find out if any event handlers have been connected to our plotEvent.
53 // returns: Boolean
54 // A flag indicating that there are handlers attached.
55 return !!this.plotEvent.after;
56 },
57 resetEvents: function(){
58 // summary:
59 // Reset all events attached to our plotEvent (i.e. disconnect).
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 // summary:
99 // Emulates firing an event for a given data value (specified by
100 // an index) of a given series.
101 // seriesName: String
102 // Series name.
103 // eventName: String
104 // Event name to emulate.
105 // index: Number
106 // Valid data value index used to raise an event.
107 // eventObject: Object?
108 // Optional event object. Especially useful for synthetic events.
109 // Default: null.
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 });