~bac/juju-gui/1103207

« back to all changes in this revision

Viewing changes to app/assets/javascripts/d3-components.js

  • Committer: Matthew Scott
  • Date: 2013-01-09 17:23:33 UTC
  • mfrom: (307 juju-gui)
  • mto: This revision was merged to the branch mainline in revision 312.
  • Revision ID: matthew.scott@canonical.com-20130109172333-ad6ndevmn5p44dz0
Merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
 
195
195
      function _bindEvent(name, handler, container, selector, context) {
196
196
        // Adapt between d3 events and YUI delegates.
197
 
        var d3Adaptor = function(evt) {
 
197
        var d3Adapter = function(evt) {
198
198
          var selection = d3.select(evt.currentTarget.getDOMNode()),
199
199
              d = selection.data()[0];
200
200
          // This is a minor violation (extension)
201
201
          // of the interface, but suits us well.
202
202
          d3.event = evt;
 
203
          //console.debug('Handler for', name, selector, d3.event);
203
204
          return handler.call(
204
205
              evt.currentTarget.getDOMNode(), d, context);
205
206
        };
206
207
 
207
208
        subscriptions.push(
208
 
            Y.delegate(name, d3Adaptor, container, selector, context));
 
209
            Y.delegate(name, d3Adapter, container, selector, context));
209
210
      }
210
211
 
211
212
      this.unbind(modName);
252
253
                // (re)Register the event to bubble.
253
254
                self.publish(name, {emitFacade: true});
254
255
              }
255
 
              console.debug('d3 component yui event binding', target.toString(),
256
 
                            eventPhase, name);
 
256
              console.debug('yui event binding', module.name, eventPhase, name);
257
257
              subscriptions.push(
258
258
                  target[eventPhase](
259
259
                  name, callback, handler.context));
288
288
     * Specialized handling of events only found in d3.
289
289
     * This is again an internal implementation detail.
290
290
     *
291
 
     * Its worth noting that d3 events don't use a delegate pattern
 
291
     * It is worth noting that d3 events don't use a delegate pattern
292
292
     * and thus must be bound to nodes present in a selection.
293
293
     * For this reason binding d3 events happens after render cycles.
294
294
     *
313
313
        Y.each(handlers, function(handler, trigger) {
314
314
          var adapter;
315
315
          handler = self._normalizeHandler(handler, module);
316
 
          // Create an adaptor
 
316
          // Create an adapter
317
317
          adapter = function() {
318
318
            var selection = d3.select(this),
319
319
                d = selection.data()[0];
 
320
            console.debug('D3 Handler for', selector, trigger);
320
321
            return handler.callback.call(this, d, handler.context);
321
322
          };
322
323
          d3.selectAll(selector).on(trigger, adapter);
325
326
    },
326
327
 
327
328
    /**
328
 
     * Allow d3 event rebinding after rendering.
 
329
     * Allow d3 event rebinding after rendering. The component
 
330
     * can trigger this after it is sure relevant elements
 
331
     * are in the bound DOM.
329
332
     *
330
333
     **/
331
334
    bindAllD3Events: function() {