From 5e752d836801bdd01638dac09d3cc21d88548d92 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Sat, 28 Jun 2014 18:40:43 -0400 Subject: [PATCH 1/8] Adds remove method to layer (#63). --- d3.chart.js | 145 ++++++++++++++++++++++++++++------ d3.chart.min.js | 4 +- d3.chart.min.map | 2 +- examples/scripts/bar-chart.js | 3 +- src/layer.js | 20 ++++- test/tests/layer.js | 9 +++ 6 files changed, 153 insertions(+), 30 deletions(-) diff --git a/d3.chart.js b/d3.chart.js index 3d6d1b2..aa3df78 100644 --- a/d3.chart.js +++ b/d3.chart.js @@ -1,12 +1,24 @@ /*! d3.chart - v0.2.1 * License: MIT Expat - * Date: 2014-06-24 + * Date: 2014-06-28 */ -(function(window) { +(function(global, factory) { + "use strict"; + + if (typeof global.define === "function" && global.define.amd) { + define(["d3"], function(d3) { + factory(global, d3); + }); + } else { + factory(global, global.d3); + } + +})(this, function(window, d3) { +"use strict"; + "use strict"; /*jshint unused: false */ -var d3 = window.d3; var hasOwnProp = Object.hasOwnProperty; var d3cAssert = function(test, message) { @@ -32,6 +44,7 @@ var lifecycleRe = /^(enter|update|merge|exit)(:transition)?$/; * * @private * @constructor + * @externalExample {runnable} layer * * @param {d3.selection} base The containing DOM node for the layer. */ @@ -60,11 +73,22 @@ Layer.prototype.insert = function() { d3cAssert(false, "Layers must specify an `insert` method."); }; +/** + * Invoked by {@link Layer#draw} in order to remove existing DOM nodes from + * this layer's `base`. This default implementation may be overridden by + * Layer instances. + */ +Layer.prototype.remove = function() { + this.remove(); +}; + /** * Subscribe a handler to a "lifecycle event". These events (and only these * events) are triggered when {@link Layer#draw} is invoked--see that method * for more details on lifecycle events. * + * @externalExample {runnable} layer-on + * * @param {String} eventName Identifier for the lifecycle event for which to * subscribe. * @param {Function} handler Callback function @@ -94,6 +118,8 @@ Layer.prototype.on = function(eventName, handler, options) { * Unsubscribe the specified handler from the specified event. If no handler is * supplied, remove *all* handlers from the event. * + * @externalExample {runnable} layer-off + * * @param {String} eventName Identifier for event from which to remove * unsubscribe * @param {Function} handler Callback to remove from the specified event @@ -130,9 +156,12 @@ Layer.prototype.off = function(eventName, handler) { /** * Render the layer according to the input data: Bind the data to the layer - * (according to {@link Layer#dataBind}, insert new elements (according to - * {@link Layer#insert}, make lifecycle selections, and invoke all relevant - * handlers (as attached via {@link Layer#on}) with the lifecycle selections. + * (according to {@link Layer#dataBind}), insert new elements (according to + * {@link Layer#insert}), make lifecycle selections, invoke all relevant + * handlers (as attached via {@link Layer#on}) with the lifecycle selections, + * then remove existing elements (according to {@link Layer#remove}). + * + * The lifecycle selections are: * * - update * - update:transition @@ -141,10 +170,13 @@ Layer.prototype.off = function(eventName, handler) { * - exit * - exit:transition * + * @externalExample {runnable} layer-draw + * * @param {Array} data Data to drive the rendering. */ Layer.prototype.draw = function(data) { - var bound, entering, events, selection, handlers, eventName, idx, len; + var bound, entering, events, selection, method, handlers, eventName, idx, + len; bound = this.dataBind.call(this._base, data); @@ -164,30 +196,37 @@ Layer.prototype.draw = function(data) { }, { name: "enter", - // Defer invocation of the `insert` method so that the previous - // `update` selection does not contain the new nodes. - selection: this.insert.bind(entering) + selection: entering, + method: this.insert }, { name: "merge", - // This selection will be modified when the previous selection - // is made. + // Although the `merge` lifecycle event shares its selection object + // with the `update` lifecycle event, the object's contents will be + // modified when d3.chart invokes the user-supplied `insert` method + // when triggering the `enter` event. selection: bound }, { name: "exit", - selection: bound.exit.bind(bound) + // Although the `exit` lifecycle event shares its selection object + // with the `update` and `merge` lifecycle events, the object's + // contents will be modified when d3.chart invokes + // `d3.selection.exit`. + selection: bound, + method: bound.exit } ]; for (var i = 0, l = events.length; i < l; ++i) { eventName = events[i].name; selection = events[i].selection; + method = events[i].method; - // Some lifecycle selections are expressed as functions so that - // they may be delayed. - if (typeof selection === "function") { - selection = selection(); + // Some lifecycle selections modify shared state, so they must be + // deferred until just prior to handler invocation. + if (typeof method === "function") { + selection = method.call(selection); } if (selection.empty()) { @@ -223,6 +262,8 @@ Layer.prototype.draw = function(data) { } } } + + this.remove.call(selection); }; "use strict"; @@ -334,17 +375,25 @@ var transformCascade = function(instance, data) { /** * Create a d3.chart * + * @constructor + * @externalExample {runnable} chart + * * @param {d3.selection} selection The chart's "base" DOM node. This should * contain any nodes that the chart generates. * @param {mixed} chartOptions A value for controlling how the chart should be * created. This value will be forwarded to {@link Chart#initialize}, so * charts may define additional properties for consumers to modify their - * behavior during initialization. + * behavior during initialization. The following attributes will be + * copied onto the chart instance (if present): + * + * - {Function} transform - A data transformation function unique to the + * Chart instance being created. If specified, this function will be + * invoked after all inherited implementations as part of the + * `Chart#draw` operation. * * @constructor */ var Chart = function(selection, chartOptions) { - this.base = selection; this._layers = {}; this._attached = {}; @@ -372,6 +421,8 @@ Chart.prototype.initialize = function() {}; /** * Remove a layer from the chart. * + * @externalExample chart-unlayer + * * @param {String} name The name of the layer to remove. * * @returns {Layer} The layer removed by this operation. @@ -402,6 +453,8 @@ Chart.prototype.unlayer = function(name) { * whenever this chart's {@link Chart#draw} is invoked and will receive the * data (optionally modified by the chart's {@link Chart#transform} method. * + * @externalExample chart-layer + * * @param {String} name Name of the layer to attach or retrieve. * @param {d3.selection|Layer} [selection] The layer's base or a * previously-created {@link Layer}. @@ -446,6 +499,8 @@ Chart.prototype.layer = function(name, selection, options) { * method will be invoked whenever the containing chart's `draw` method is * invoked. * + * @externalExample chart-attach + * * @param {String} attachmentName Name of the attachment * @param {Chart} [chart] d3.chart to register as a mix in of this chart. When * unspecified, this method will return the attachment previously @@ -462,10 +517,32 @@ Chart.prototype.attach = function(attachmentName, chart) { return chart; }; +/** + * A "hook" method that you may define to modify input data before it is used + * to draw the chart's layers and attachments. This method will be used by all + * sub-classes (see {@link transformCascade} for details). + * + * Note you will most likely never call this method directly, but rather + * include it as part of a chart definition, and then rely on d3.chart to + * invoke it when you draw the chart with {@link Chart#draw}. + * + * @externalExample {runnable} chart-transform + * + * @param {Array} data Input data provided to @link Chart#draw}. + * + * @returns {mixed} Data to be used in drawing the chart's layers and + * attachments. + */ +Chart.prototype.transform = function(data) { + return data; +}; + /** * Update the chart's representation in the DOM, drawing all of its layers and * any "attachment" charts (as attached via {@link Chart#attach}). * + * @externalExample chart-draw + * * @param {Object} data Data to pass to the {@link Layer#draw|draw method} of * this cart's {@link Layer|layers} (if any) and the {@link * Chart#draw|draw method} of this chart's attachments (if any). @@ -503,6 +580,8 @@ Chart.prototype.draw = function(data) { * Subscribe a callback function to an event triggered on the chart. See {@link * Chart#once} to subscribe a callback function to an event for one occurence. * + * @externalExample {runnable} chart-on + * * @param {String} name Name of the event * @param {ChartEventHandler} callback Function to be invoked when the event * occurs @@ -527,6 +606,8 @@ Chart.prototype.on = function(name, callback, context) { * unsubscribed. See {@link Chart#on} to subscribe a callback function to an * event indefinitely. * + * @externalExample {runnable} chart-once + * * @param {String} name Name of the event * @param {ChartEventHandler} callback Function to be invoked when the event * occurs @@ -553,6 +634,8 @@ Chart.prototype.once = function(name, callback, context) { * are specified (but `callback` is omitted), all events bound to the given * event with the given context will be unsubscribed. * + * @externalExample {runnable} chart-off + * * @param {String} [name] Name of the event to be unsubscribed * @param {ChartEventHandler} [callback] Function to be unsubscribed * @param {Object} [context] Contexts to be unsubscribe @@ -601,6 +684,8 @@ Chart.prototype.off = function(name, callback, context) { /** * Publish an event on this chart with the given `name`. * + * @externalExample {runnable} chart-trigger + * * @param {String} name Name of the event to publish * @param {...*} arguments Values with which to invoke the registered * callbacks. @@ -627,9 +712,10 @@ Chart.prototype.trigger = function(name) { * "overrides" for the default chart instance methods. Allows for basic * inheritance so that new chart constructors may be defined in terms of * existing chart constructors. Based on the `extend` function defined by - * {@link http://backbonejs.org/|Backbone.js}. + * [Backbone.js](http://backbonejs.org/). * * @static + * @externalExample {runnable} chart-extend * * @param {String} name Identifier for the new Chart constructor. * @param {Object} protoProps Properties to set on the new chart's prototype. @@ -674,11 +760,25 @@ Chart.extend = function(name, protoProps, staticProps) { "use strict"; +/** + * A namespace defined by [the D3.js library](http://d3js.org/). The d3.chart + * API is defined within this namespace. + * @namespace d3 + */ + +/** + * A constructor function defined by [the D3.js library](http://d3js.org/). + * @constructor d3.selection + * @memberof d3 + */ + /** * Create a new chart constructor or return a previously-created chart * constructor. * * @static + * @memberof d3 + * @externalExample {runnable} chart * * @param {String} name If no other arguments are specified, return the * previously-created chart with this name. @@ -701,7 +801,7 @@ d3.chart = function(name) { * Instantiate a chart or return the chart that the current selection belongs * to. * - * @static + * @externalExample {runnable} selection-chart * * @param {String} [chartName] The name of the chart to instantiate. If the * name is unspecified, this method will return the chart that the @@ -727,4 +827,5 @@ d3.selection.enter.prototype.chart = function() { return this._chart; }; d3.transition.prototype.chart = d3.selection.enter.prototype.chart; -})(this); \ No newline at end of file + +}); diff --git a/d3.chart.min.js b/d3.chart.min.js index b27de59..2ac2269 100644 --- a/d3.chart.min.js +++ b/d3.chart.min.js @@ -1,6 +1,6 @@ /*! d3.chart - v0.2.1 * License: MIT Expat - * Date: 2014-06-24 + * Date: 2014-06-28 */ -(function(t){"use strict";function e(t){var e,r,n,i;if(!t)return t;for(r=arguments.length,e=1;r>e;e++)if(n=arguments[e])for(i in n)t[i]=n[i];return t}var r=t.d3,n=Object.hasOwnProperty,i=function(t,e){if(!t)throw Error("[d3.chart] "+e)};i(r,"d3.js is required"),i("string"==typeof r.version&&r.version.match(/^3/),"d3.js version 3 is required");var a=/^(enter|update|merge|exit)(:transition)?$/,s=function(t){i(t,"Layers must be initialized with a base."),this._base=t,this._handlers={}};s.prototype.dataBind=function(){i(!1,"Layers must specify a `dataBind` method.")},s.prototype.insert=function(){i(!1,"Layers must specify an `insert` method.")},s.prototype.on=function(t,e,r){return r=r||{},i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#on`: '"+t+"'."),t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:e,chart:r.chart||null}),this._base},s.prototype.off=function(t,e){var r,n=this._handlers[t];if(i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#off`: '"+t+"'."),!n)return this._base;if(1===arguments.length)return n.length=0,this._base;for(r=n.length-1;r>-1;--r)n[r].callback===e&&n.splice(r,1);return this._base},s.prototype.draw=function(t){var e,n,a,s,o,h,c,l;e=this.dataBind.call(this._base,t),i(e&&e.call===r.selection.prototype.call,"Invalid selection defined by `Layer#dataBind` method."),i(e.enter,"Layer selection not properly bound."),n=e.enter(),n._chart=this._base._chart,a=[{name:"update",selection:e},{name:"enter",selection:this.insert.bind(n)},{name:"merge",selection:e},{name:"exit",selection:e.exit.bind(e)}];for(var u=0,p=a.length;p>u;++u)if(h=a[u].name,s=a[u].selection,"function"==typeof s&&(s=s()),!s.empty()){if(i(s&&s.call===r.selection.prototype.call,"Invalid selection defined for '"+h+"' lifecycle event."),o=this._handlers[h])for(c=0,l=o.length;l>c;++c)s._chart=o[c].chart||this._base._chart,s.call(o[c].callback);if(o=this._handlers[h+":transition"],o&&o.length)for(s=s.transition(),c=0,l=o.length;l>c;++c)s._chart=o[c].chart||this._base._chart,s.call(o[c].callback)}},r.selection.prototype.layer=function(t){var e,r=new s(this);if(r.dataBind=t.dataBind,r.insert=t.insert,"events"in t)for(e in t.events)r.on(e,t.events[e]);return this.on=function(){return r.on.apply(r,arguments)},this.off=function(){return r.off.apply(r,arguments)},this.draw=function(){return r.draw.apply(r,arguments)},this};var o=function(t,e){var r=this.constructor,i=r.__super__;i&&o.call(i,t,e),n.call(r.prototype,"initialize")&&this.initialize.apply(t,e)},h=function(t,e){var r=this.constructor,i=r.__super__;return this===t&&n.call(this,"transform")&&(e=this.transform(e)),n.call(r.prototype,"transform")&&(e=r.prototype.transform.call(t,e)),i&&(e=h.call(i,t,e)),e},c=function(t,e){this.base=t,this._layers={},this._attached={},this._events={},e&&e.transform&&(this.transform=e.transform),o.call(this,this,[e])};c.prototype.initialize=function(){},c.prototype.unlayer=function(t){var e=this.layer(t);return delete this._layers[t],delete e._chart,e},c.prototype.layer=function(t,e,r){var n;if(1===arguments.length)return this._layers[t];if(2===arguments.length){if("function"==typeof e.draw)return e._chart=this,this._layers[t]=e,this._layers[t];i(!1,"When reattaching a layer, the second argument must be a d3.chart layer")}return n=e.layer(r),this._layers[t]=n,e._chart=this,n},c.prototype.attach=function(t,e){return 1===arguments.length?this._attached[t]:(this._attached[t]=e,e)},c.prototype.draw=function(t){var e,r,n;t=h.call(this,this,t);for(e in this._layers)this._layers[e].draw(t);for(r in this._attached)n=this.demux?this.demux(r,t):t,this._attached[r].draw(n)},c.prototype.on=function(t,e,r){var n=this._events[t]||(this._events[t]=[]);return n.push({callback:e,context:r||this,_chart:this}),this},c.prototype.once=function(t,e,r){var n=this,i=function(){n.off(t,i),e.apply(this,arguments)};return this.on(t,i,r)},c.prototype.off=function(t,e,r){var n,i,a,s,o,h;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return a=this._events[t],a&&(a.length=0),this;for(n=t?[t]:Object.keys(this._events),o=0;n.length>o;o++)for(i=n[o],a=this._events[i],h=a.length;h--;)s=a[h],(e&&e===s.callback||r&&r===s.context)&&a.splice(h,1);return this},c.prototype.trigger=function(t){var e,r,n=Array.prototype.slice.call(arguments,1),i=this._events[t];if(void 0!==i)for(e=0;i.length>e;e++)r=i[e],r.callback.apply(r.context,n);return this},c.extend=function(t,r,i){var a,s=this;a=r&&n.call(r,"constructor")?r.constructor:function(){return s.apply(this,arguments)},e(a,s,i);var o=function(){this.constructor=a};return o.prototype=s.prototype,a.prototype=new o,r&&e(a.prototype,r),a.__super__=s.prototype,c[t]=a,a},r.chart=function(t){return 0===arguments.length?c:1===arguments.length?c[t]:c.extend.apply(c,arguments)},r.selection.prototype.chart=function(t,e){if(0===arguments.length)return this._chart;var r=c[t];return i(r,"No chart registered with name '"+t+"'"),new r(this,e)},r.selection.enter.prototype.chart=function(){return this._chart},r.transition.prototype.chart=r.selection.enter.prototype.chart})(this); +(function(t,e){"use strict";"function"==typeof t.define&&t.define.amd?define(["d3"],function(n){e(t,n)}):e(t,t.d3)})(this,function(t,e){"use strict";function n(t){var e,n,r,i;if(!t)return t;for(n=arguments.length,e=1;n>e;e++)if(r=arguments[e])for(i in r)t[i]=r[i];return t}var r=Object.hasOwnProperty,i=function(t,e){if(!t)throw Error("[d3.chart] "+e)};i(e,"d3.js is required"),i("string"==typeof e.version&&e.version.match(/^3/),"d3.js version 3 is required");var a=/^(enter|update|merge|exit)(:transition)?$/,s=function(t){i(t,"Layers must be initialized with a base."),this._base=t,this._handlers={}};s.prototype.dataBind=function(){i(!1,"Layers must specify a `dataBind` method.")},s.prototype.insert=function(){i(!1,"Layers must specify an `insert` method.")},s.prototype.remove=function(){this.remove()},s.prototype.on=function(t,e,n){return n=n||{},i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#on`: '"+t+"'."),t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:e,chart:n.chart||null}),this._base},s.prototype.off=function(t,e){var n,r=this._handlers[t];if(i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#off`: '"+t+"'."),!r)return this._base;if(1===arguments.length)return r.length=0,this._base;for(n=r.length-1;n>-1;--n)r[n].callback===e&&r.splice(n,1);return this._base},s.prototype.draw=function(t){var n,r,a,s,o,h,c,l,u;n=this.dataBind.call(this._base,t),i(n&&n.call===e.selection.prototype.call,"Invalid selection defined by `Layer#dataBind` method."),i(n.enter,"Layer selection not properly bound."),r=n.enter(),r._chart=this._base._chart,a=[{name:"update",selection:n},{name:"enter",selection:r,method:this.insert},{name:"merge",selection:n},{name:"exit",selection:n,method:n.exit}];for(var f=0,p=a.length;p>f;++f)if(c=a[f].name,s=a[f].selection,o=a[f].method,"function"==typeof o&&(s=o.call(s)),!s.empty()){if(i(s&&s.call===e.selection.prototype.call,"Invalid selection defined for '"+c+"' lifecycle event."),h=this._handlers[c])for(l=0,u=h.length;u>l;++l)s._chart=h[l].chart||this._base._chart,s.call(h[l].callback);if(h=this._handlers[c+":transition"],h&&h.length)for(s=s.transition(),l=0,u=h.length;u>l;++l)s._chart=h[l].chart||this._base._chart,s.call(h[l].callback)}this.remove.call(s)},e.selection.prototype.layer=function(t){var e,n=new s(this);if(n.dataBind=t.dataBind,n.insert=t.insert,"events"in t)for(e in t.events)n.on(e,t.events[e]);return this.on=function(){return n.on.apply(n,arguments)},this.off=function(){return n.off.apply(n,arguments)},this.draw=function(){return n.draw.apply(n,arguments)},this};var o=function(t,e){var n=this.constructor,i=n.__super__;i&&o.call(i,t,e),r.call(n.prototype,"initialize")&&this.initialize.apply(t,e)},h=function(t,e){var n=this.constructor,i=n.__super__;return this===t&&r.call(this,"transform")&&(e=this.transform(e)),r.call(n.prototype,"transform")&&(e=n.prototype.transform.call(t,e)),i&&(e=h.call(i,t,e)),e},c=function(t,e){this.base=t,this._layers={},this._attached={},this._events={},e&&e.transform&&(this.transform=e.transform),o.call(this,this,[e])};c.prototype.initialize=function(){},c.prototype.unlayer=function(t){var e=this.layer(t);return delete this._layers[t],delete e._chart,e},c.prototype.layer=function(t,e,n){var r;if(1===arguments.length)return this._layers[t];if(2===arguments.length){if("function"==typeof e.draw)return e._chart=this,this._layers[t]=e,this._layers[t];i(!1,"When reattaching a layer, the second argument must be a d3.chart layer")}return r=e.layer(n),this._layers[t]=r,e._chart=this,r},c.prototype.attach=function(t,e){return 1===arguments.length?this._attached[t]:(this._attached[t]=e,e)},c.prototype.transform=function(t){return t},c.prototype.draw=function(t){var e,n,r;t=h.call(this,this,t);for(e in this._layers)this._layers[e].draw(t);for(n in this._attached)r=this.demux?this.demux(n,t):t,this._attached[n].draw(r)},c.prototype.on=function(t,e,n){var r=this._events[t]||(this._events[t]=[]);return r.push({callback:e,context:n||this,_chart:this}),this},c.prototype.once=function(t,e,n){var r=this,i=function(){r.off(t,i),e.apply(this,arguments)};return this.on(t,i,n)},c.prototype.off=function(t,e,n){var r,i,a,s,o,h;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return a=this._events[t],a&&(a.length=0),this;for(r=t?[t]:Object.keys(this._events),o=0;r.length>o;o++)for(i=r[o],a=this._events[i],h=a.length;h--;)s=a[h],(e&&e===s.callback||n&&n===s.context)&&a.splice(h,1);return this},c.prototype.trigger=function(t){var e,n,r=Array.prototype.slice.call(arguments,1),i=this._events[t];if(void 0!==i)for(e=0;i.length>e;e++)n=i[e],n.callback.apply(n.context,r);return this},c.extend=function(t,e,i){var a,s=this;a=e&&r.call(e,"constructor")?e.constructor:function(){return s.apply(this,arguments)},n(a,s,i);var o=function(){this.constructor=a};return o.prototype=s.prototype,a.prototype=new o,e&&n(a.prototype,e),a.__super__=s.prototype,c[t]=a,a},e.chart=function(t){return 0===arguments.length?c:1===arguments.length?c[t]:c.extend.apply(c,arguments)},e.selection.prototype.chart=function(t,e){if(0===arguments.length)return this._chart;var n=c[t];return i(n,"No chart registered with name '"+t+"'"),new n(this,e)},e.selection.enter.prototype.chart=function(){return this._chart},e.transition.prototype.chart=e.selection.enter.prototype.chart}); //@ sourceMappingURL=d3.chart.min.map \ No newline at end of file diff --git a/d3.chart.min.map b/d3.chart.min.map index 3a23bf2..5ffc8e9 100644 --- a/d3.chart.min.map +++ b/d3.chart.min.map @@ -1 +1 @@ -{"version":3,"file":"d3.chart.min.js","sources":["d3.chart.js"],"names":["window","extend","object","argsIndex","argsLength","iteratee","key","arguments","length","d3","hasOwnProp","Object","hasOwnProperty","d3cAssert","test","message","Error","version","match","lifecycleRe","Layer","base","this","_base","_handlers","prototype","dataBind","insert","on","eventName","handler","options","push","callback","chart","off","idx","handlers","splice","draw","data","bound","entering","events","selection","len","call","enter","_chart","name","bind","exit","i","l","empty","transition","layer","apply","initCascade","instance","args","ctor","constructor","sup","__super__","initialize","transformCascade","transform","Chart","chartOptions","_layers","_attached","_events","unlayer","attach","attachmentName","layerName","attachmentData","demux","context","once","self","names","n","event","j","keys","trigger","ev","Array","slice","undefined","protoProps","staticProps","child","parent","Surrogate","chartName","ChartCtor"],"mappings":";;;;CAIA,SAAUA,GACV,YAoQA,SAASC,GAAOC,GACf,GAAIC,GAAWC,EAAYC,EAAUC,CACr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,MAAOiC,GAAOtC,MAAMnC,KAAMf,YAI/CN,EAAO6F,EAAOC,EAAQF,EAItB,IAAIG,GAAY,WAAY1E,KAAKwC,YAAcgC,EAa/C,OAZAE,GAAUvE,UAAYsE,EAAOtE,UAC7BqE,EAAMrE,UAAY,GAAIuE,GAIlBJ,GAAc3F,EAAO6F,EAAMrE,UAAWmE,GAI1CE,EAAM9B,UAAY+B,EAAOtE,UAEzB2C,EAAMnB,GAAQ6C,EACPA,GAkBRrF,EAAGyB,MAAQ,SAASe,GACnB,MAAyB,KAArB1C,UAAUC,OACN4D,EACwB,IAArB7D,UAAUC,OACb4D,EAAMnB,GAGPmB,EAAMnE,OAAOwD,MAAMW,EAAO7D,YAelCE,EAAGmC,UAAUnB,UAAUS,MAAQ,SAAS+D,EAAWlE,GAGlD,GAAyB,IAArBxB,UAAUC,OACb,MAAOc,MAAK0B,MAEb,IAAIkD,GAAY9B,EAAM6B,EAGtB,OAFApF,GAAUqF,EAAW,kCAAoCD,EAAY,KAE9D,GAAIC,GAAU5E,KAAMS,IAK5BtB,EAAGmC,UAAUG,MAAMtB,UAAUS,MAAQ,WACpC,MAAOZ,MAAK0B,QAEbvC,EAAG8C,WAAW9B,UAAUS,MAAQzB,EAAGmC,UAAUG,MAAMtB,UAAUS,QAC1DZ"} \ No newline at end of file +{"version":3,"file":"d3.chart.min.js","sources":["d3.chart.js"],"names":["global","factory","define","amd","d3","this","window","extend","object","argsIndex","argsLength","iteratee","key","arguments","length","hasOwnProp","Object","hasOwnProperty","d3cAssert","test","message","Error","version","match","lifecycleRe","Layer","base","_base","_handlers","prototype","dataBind","insert","remove","on","eventName","handler","options","push","callback","chart","off","idx","handlers","splice","draw","data","bound","entering","events","selection","method","len","call","enter","_chart","name","exit","i","l","empty","transition","layer","apply","initCascade","instance","args","ctor","constructor","sup","__super__","initialize","transformCascade","transform","Chart","chartOptions","_layers","_attached","_events","unlayer","attach","attachmentName","layerName","attachmentData","demux","context","once","self","names","n","event","j","keys","trigger","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,MAAKiD,QAEblD,EAAGwD,WAAW/B,UAAUU,MAAQnC,EAAG6C,UAAUI,MAAMxB,UAAUU"} \ No newline at end of file diff --git a/examples/scripts/bar-chart.js b/examples/scripts/bar-chart.js index 52e8230..f21f6ca 100644 --- a/examples/scripts/bar-chart.js +++ b/examples/scripts/bar-chart.js @@ -34,8 +34,7 @@ d3.chart("BarChart", { function onExitTrans() { this.duration(1000) - .attr("x", function(d, i) { return chart.x(i - 1) - .5; }) - .remove(); + .attr("x", function(d, i) { return chart.x(i - 1) - .5; }); } function dataBind(data) { diff --git a/src/layer.js b/src/layer.js index cfaa900..11549fe 100644 --- a/src/layer.js +++ b/src/layer.js @@ -39,6 +39,15 @@ Layer.prototype.insert = function() { d3cAssert(false, "Layers must specify an `insert` method."); }; +/** + * Invoked by {@link Layer#draw} in order to remove existing DOM nodes from + * this layer's `base`. This default implementation may be overridden by + * Layer instances. + */ +Layer.prototype.remove = function() { + this.remove(); +}; + /** * Subscribe a handler to a "lifecycle event". These events (and only these * events) are triggered when {@link Layer#draw} is invoked--see that method @@ -113,9 +122,12 @@ Layer.prototype.off = function(eventName, handler) { /** * Render the layer according to the input data: Bind the data to the layer - * (according to {@link Layer#dataBind}, insert new elements (according to - * {@link Layer#insert}, make lifecycle selections, and invoke all relevant - * handlers (as attached via {@link Layer#on}) with the lifecycle selections. + * (according to {@link Layer#dataBind}), insert new elements (according to + * {@link Layer#insert}), make lifecycle selections, invoke all relevant + * handlers (as attached via {@link Layer#on}) with the lifecycle selections, + * then remove existing elements (according to {@link Layer#remove}). + * + * The lifecycle selections are: * * - update * - update:transition @@ -216,4 +228,6 @@ Layer.prototype.draw = function(data) { } } } + + this.remove.call(selection); }; diff --git a/test/tests/layer.js b/test/tests/layer.js index f59ac19..c6f74f9 100644 --- a/test/tests/layer.js +++ b/test/tests/layer.js @@ -55,6 +55,10 @@ suite("d3.layer", function() { dataBind: dataBind, insert: insert }); + // this.layer.remove = sinon.spy(); + var remove = this.remove = sinon.spy(function() { + return this.layer.remove(); + }); }); test("invokes the provided `dataBind` method exactly once", function() { @@ -82,6 +86,11 @@ suite("d3.layer", function() { this.layer.draw([]); assert(this.insert.calledOn(this.dataBind.returnValues[0].enter.returnValues[0])); }); + test("invokes the provided `remove` method exactly once", function() { + assert.equal(this.remove.callCount, 0); + this.layer.draw([]); + assert.equal(this.remove.callCount, 1); + }); suite("event triggering", function() { test("invokes event handlers with the correct selection", function() { From d9d8aa6556e3b89a3ca1a858217eaa66b93a1f88 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Sun, 29 Jun 2014 12:46:37 -0400 Subject: [PATCH 2/8] Remove distribution files --- d3.chart.js | 145 +++++++---------------------------------------- d3.chart.min.js | 4 +- d3.chart.min.map | 2 +- 3 files changed, 25 insertions(+), 126 deletions(-) diff --git a/d3.chart.js b/d3.chart.js index aa3df78..3d6d1b2 100644 --- a/d3.chart.js +++ b/d3.chart.js @@ -1,24 +1,12 @@ /*! d3.chart - v0.2.1 * License: MIT Expat - * Date: 2014-06-28 + * Date: 2014-06-24 */ -(function(global, factory) { - "use strict"; - - if (typeof global.define === "function" && global.define.amd) { - define(["d3"], function(d3) { - factory(global, d3); - }); - } else { - factory(global, global.d3); - } - -})(this, function(window, d3) { -"use strict"; - +(function(window) { "use strict"; /*jshint unused: false */ +var d3 = window.d3; var hasOwnProp = Object.hasOwnProperty; var d3cAssert = function(test, message) { @@ -44,7 +32,6 @@ var lifecycleRe = /^(enter|update|merge|exit)(:transition)?$/; * * @private * @constructor - * @externalExample {runnable} layer * * @param {d3.selection} base The containing DOM node for the layer. */ @@ -73,22 +60,11 @@ Layer.prototype.insert = function() { d3cAssert(false, "Layers must specify an `insert` method."); }; -/** - * Invoked by {@link Layer#draw} in order to remove existing DOM nodes from - * this layer's `base`. This default implementation may be overridden by - * Layer instances. - */ -Layer.prototype.remove = function() { - this.remove(); -}; - /** * Subscribe a handler to a "lifecycle event". These events (and only these * events) are triggered when {@link Layer#draw} is invoked--see that method * for more details on lifecycle events. * - * @externalExample {runnable} layer-on - * * @param {String} eventName Identifier for the lifecycle event for which to * subscribe. * @param {Function} handler Callback function @@ -118,8 +94,6 @@ Layer.prototype.on = function(eventName, handler, options) { * Unsubscribe the specified handler from the specified event. If no handler is * supplied, remove *all* handlers from the event. * - * @externalExample {runnable} layer-off - * * @param {String} eventName Identifier for event from which to remove * unsubscribe * @param {Function} handler Callback to remove from the specified event @@ -156,12 +130,9 @@ Layer.prototype.off = function(eventName, handler) { /** * Render the layer according to the input data: Bind the data to the layer - * (according to {@link Layer#dataBind}), insert new elements (according to - * {@link Layer#insert}), make lifecycle selections, invoke all relevant - * handlers (as attached via {@link Layer#on}) with the lifecycle selections, - * then remove existing elements (according to {@link Layer#remove}). - * - * The lifecycle selections are: + * (according to {@link Layer#dataBind}, insert new elements (according to + * {@link Layer#insert}, make lifecycle selections, and invoke all relevant + * handlers (as attached via {@link Layer#on}) with the lifecycle selections. * * - update * - update:transition @@ -170,13 +141,10 @@ Layer.prototype.off = function(eventName, handler) { * - exit * - exit:transition * - * @externalExample {runnable} layer-draw - * * @param {Array} data Data to drive the rendering. */ Layer.prototype.draw = function(data) { - var bound, entering, events, selection, method, handlers, eventName, idx, - len; + var bound, entering, events, selection, handlers, eventName, idx, len; bound = this.dataBind.call(this._base, data); @@ -196,37 +164,30 @@ Layer.prototype.draw = function(data) { }, { name: "enter", - selection: entering, - method: this.insert + // Defer invocation of the `insert` method so that the previous + // `update` selection does not contain the new nodes. + selection: this.insert.bind(entering) }, { name: "merge", - // Although the `merge` lifecycle event shares its selection object - // with the `update` lifecycle event, the object's contents will be - // modified when d3.chart invokes the user-supplied `insert` method - // when triggering the `enter` event. + // This selection will be modified when the previous selection + // is made. selection: bound }, { name: "exit", - // Although the `exit` lifecycle event shares its selection object - // with the `update` and `merge` lifecycle events, the object's - // contents will be modified when d3.chart invokes - // `d3.selection.exit`. - selection: bound, - method: bound.exit + selection: bound.exit.bind(bound) } ]; for (var i = 0, l = events.length; i < l; ++i) { eventName = events[i].name; selection = events[i].selection; - method = events[i].method; - // Some lifecycle selections modify shared state, so they must be - // deferred until just prior to handler invocation. - if (typeof method === "function") { - selection = method.call(selection); + // Some lifecycle selections are expressed as functions so that + // they may be delayed. + if (typeof selection === "function") { + selection = selection(); } if (selection.empty()) { @@ -262,8 +223,6 @@ Layer.prototype.draw = function(data) { } } } - - this.remove.call(selection); }; "use strict"; @@ -375,25 +334,17 @@ var transformCascade = function(instance, data) { /** * Create a d3.chart * - * @constructor - * @externalExample {runnable} chart - * * @param {d3.selection} selection The chart's "base" DOM node. This should * contain any nodes that the chart generates. * @param {mixed} chartOptions A value for controlling how the chart should be * created. This value will be forwarded to {@link Chart#initialize}, so * charts may define additional properties for consumers to modify their - * behavior during initialization. The following attributes will be - * copied onto the chart instance (if present): - * - * - {Function} transform - A data transformation function unique to the - * Chart instance being created. If specified, this function will be - * invoked after all inherited implementations as part of the - * `Chart#draw` operation. + * behavior during initialization. * * @constructor */ var Chart = function(selection, chartOptions) { + this.base = selection; this._layers = {}; this._attached = {}; @@ -421,8 +372,6 @@ Chart.prototype.initialize = function() {}; /** * Remove a layer from the chart. * - * @externalExample chart-unlayer - * * @param {String} name The name of the layer to remove. * * @returns {Layer} The layer removed by this operation. @@ -453,8 +402,6 @@ Chart.prototype.unlayer = function(name) { * whenever this chart's {@link Chart#draw} is invoked and will receive the * data (optionally modified by the chart's {@link Chart#transform} method. * - * @externalExample chart-layer - * * @param {String} name Name of the layer to attach or retrieve. * @param {d3.selection|Layer} [selection] The layer's base or a * previously-created {@link Layer}. @@ -499,8 +446,6 @@ Chart.prototype.layer = function(name, selection, options) { * method will be invoked whenever the containing chart's `draw` method is * invoked. * - * @externalExample chart-attach - * * @param {String} attachmentName Name of the attachment * @param {Chart} [chart] d3.chart to register as a mix in of this chart. When * unspecified, this method will return the attachment previously @@ -517,32 +462,10 @@ Chart.prototype.attach = function(attachmentName, chart) { return chart; }; -/** - * A "hook" method that you may define to modify input data before it is used - * to draw the chart's layers and attachments. This method will be used by all - * sub-classes (see {@link transformCascade} for details). - * - * Note you will most likely never call this method directly, but rather - * include it as part of a chart definition, and then rely on d3.chart to - * invoke it when you draw the chart with {@link Chart#draw}. - * - * @externalExample {runnable} chart-transform - * - * @param {Array} data Input data provided to @link Chart#draw}. - * - * @returns {mixed} Data to be used in drawing the chart's layers and - * attachments. - */ -Chart.prototype.transform = function(data) { - return data; -}; - /** * Update the chart's representation in the DOM, drawing all of its layers and * any "attachment" charts (as attached via {@link Chart#attach}). * - * @externalExample chart-draw - * * @param {Object} data Data to pass to the {@link Layer#draw|draw method} of * this cart's {@link Layer|layers} (if any) and the {@link * Chart#draw|draw method} of this chart's attachments (if any). @@ -580,8 +503,6 @@ Chart.prototype.draw = function(data) { * Subscribe a callback function to an event triggered on the chart. See {@link * Chart#once} to subscribe a callback function to an event for one occurence. * - * @externalExample {runnable} chart-on - * * @param {String} name Name of the event * @param {ChartEventHandler} callback Function to be invoked when the event * occurs @@ -606,8 +527,6 @@ Chart.prototype.on = function(name, callback, context) { * unsubscribed. See {@link Chart#on} to subscribe a callback function to an * event indefinitely. * - * @externalExample {runnable} chart-once - * * @param {String} name Name of the event * @param {ChartEventHandler} callback Function to be invoked when the event * occurs @@ -634,8 +553,6 @@ Chart.prototype.once = function(name, callback, context) { * are specified (but `callback` is omitted), all events bound to the given * event with the given context will be unsubscribed. * - * @externalExample {runnable} chart-off - * * @param {String} [name] Name of the event to be unsubscribed * @param {ChartEventHandler} [callback] Function to be unsubscribed * @param {Object} [context] Contexts to be unsubscribe @@ -684,8 +601,6 @@ Chart.prototype.off = function(name, callback, context) { /** * Publish an event on this chart with the given `name`. * - * @externalExample {runnable} chart-trigger - * * @param {String} name Name of the event to publish * @param {...*} arguments Values with which to invoke the registered * callbacks. @@ -712,10 +627,9 @@ Chart.prototype.trigger = function(name) { * "overrides" for the default chart instance methods. Allows for basic * inheritance so that new chart constructors may be defined in terms of * existing chart constructors. Based on the `extend` function defined by - * [Backbone.js](http://backbonejs.org/). + * {@link http://backbonejs.org/|Backbone.js}. * * @static - * @externalExample {runnable} chart-extend * * @param {String} name Identifier for the new Chart constructor. * @param {Object} protoProps Properties to set on the new chart's prototype. @@ -760,25 +674,11 @@ Chart.extend = function(name, protoProps, staticProps) { "use strict"; -/** - * A namespace defined by [the D3.js library](http://d3js.org/). The d3.chart - * API is defined within this namespace. - * @namespace d3 - */ - -/** - * A constructor function defined by [the D3.js library](http://d3js.org/). - * @constructor d3.selection - * @memberof d3 - */ - /** * Create a new chart constructor or return a previously-created chart * constructor. * * @static - * @memberof d3 - * @externalExample {runnable} chart * * @param {String} name If no other arguments are specified, return the * previously-created chart with this name. @@ -801,7 +701,7 @@ d3.chart = function(name) { * Instantiate a chart or return the chart that the current selection belongs * to. * - * @externalExample {runnable} selection-chart + * @static * * @param {String} [chartName] The name of the chart to instantiate. If the * name is unspecified, this method will return the chart that the @@ -827,5 +727,4 @@ d3.selection.enter.prototype.chart = function() { return this._chart; }; d3.transition.prototype.chart = d3.selection.enter.prototype.chart; - -}); +})(this); \ No newline at end of file diff --git a/d3.chart.min.js b/d3.chart.min.js index 2ac2269..b27de59 100644 --- a/d3.chart.min.js +++ b/d3.chart.min.js @@ -1,6 +1,6 @@ /*! d3.chart - v0.2.1 * License: MIT Expat - * Date: 2014-06-28 + * Date: 2014-06-24 */ -(function(t,e){"use strict";"function"==typeof t.define&&t.define.amd?define(["d3"],function(n){e(t,n)}):e(t,t.d3)})(this,function(t,e){"use strict";function n(t){var e,n,r,i;if(!t)return t;for(n=arguments.length,e=1;n>e;e++)if(r=arguments[e])for(i in r)t[i]=r[i];return t}var r=Object.hasOwnProperty,i=function(t,e){if(!t)throw Error("[d3.chart] "+e)};i(e,"d3.js is required"),i("string"==typeof e.version&&e.version.match(/^3/),"d3.js version 3 is required");var a=/^(enter|update|merge|exit)(:transition)?$/,s=function(t){i(t,"Layers must be initialized with a base."),this._base=t,this._handlers={}};s.prototype.dataBind=function(){i(!1,"Layers must specify a `dataBind` method.")},s.prototype.insert=function(){i(!1,"Layers must specify an `insert` method.")},s.prototype.remove=function(){this.remove()},s.prototype.on=function(t,e,n){return n=n||{},i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#on`: '"+t+"'."),t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:e,chart:n.chart||null}),this._base},s.prototype.off=function(t,e){var n,r=this._handlers[t];if(i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#off`: '"+t+"'."),!r)return this._base;if(1===arguments.length)return r.length=0,this._base;for(n=r.length-1;n>-1;--n)r[n].callback===e&&r.splice(n,1);return this._base},s.prototype.draw=function(t){var n,r,a,s,o,h,c,l,u;n=this.dataBind.call(this._base,t),i(n&&n.call===e.selection.prototype.call,"Invalid selection defined by `Layer#dataBind` method."),i(n.enter,"Layer selection not properly bound."),r=n.enter(),r._chart=this._base._chart,a=[{name:"update",selection:n},{name:"enter",selection:r,method:this.insert},{name:"merge",selection:n},{name:"exit",selection:n,method:n.exit}];for(var f=0,p=a.length;p>f;++f)if(c=a[f].name,s=a[f].selection,o=a[f].method,"function"==typeof o&&(s=o.call(s)),!s.empty()){if(i(s&&s.call===e.selection.prototype.call,"Invalid selection defined for '"+c+"' lifecycle event."),h=this._handlers[c])for(l=0,u=h.length;u>l;++l)s._chart=h[l].chart||this._base._chart,s.call(h[l].callback);if(h=this._handlers[c+":transition"],h&&h.length)for(s=s.transition(),l=0,u=h.length;u>l;++l)s._chart=h[l].chart||this._base._chart,s.call(h[l].callback)}this.remove.call(s)},e.selection.prototype.layer=function(t){var e,n=new s(this);if(n.dataBind=t.dataBind,n.insert=t.insert,"events"in t)for(e in t.events)n.on(e,t.events[e]);return this.on=function(){return n.on.apply(n,arguments)},this.off=function(){return n.off.apply(n,arguments)},this.draw=function(){return n.draw.apply(n,arguments)},this};var o=function(t,e){var n=this.constructor,i=n.__super__;i&&o.call(i,t,e),r.call(n.prototype,"initialize")&&this.initialize.apply(t,e)},h=function(t,e){var n=this.constructor,i=n.__super__;return this===t&&r.call(this,"transform")&&(e=this.transform(e)),r.call(n.prototype,"transform")&&(e=n.prototype.transform.call(t,e)),i&&(e=h.call(i,t,e)),e},c=function(t,e){this.base=t,this._layers={},this._attached={},this._events={},e&&e.transform&&(this.transform=e.transform),o.call(this,this,[e])};c.prototype.initialize=function(){},c.prototype.unlayer=function(t){var e=this.layer(t);return delete this._layers[t],delete e._chart,e},c.prototype.layer=function(t,e,n){var r;if(1===arguments.length)return this._layers[t];if(2===arguments.length){if("function"==typeof e.draw)return e._chart=this,this._layers[t]=e,this._layers[t];i(!1,"When reattaching a layer, the second argument must be a d3.chart layer")}return r=e.layer(n),this._layers[t]=r,e._chart=this,r},c.prototype.attach=function(t,e){return 1===arguments.length?this._attached[t]:(this._attached[t]=e,e)},c.prototype.transform=function(t){return t},c.prototype.draw=function(t){var e,n,r;t=h.call(this,this,t);for(e in this._layers)this._layers[e].draw(t);for(n in this._attached)r=this.demux?this.demux(n,t):t,this._attached[n].draw(r)},c.prototype.on=function(t,e,n){var r=this._events[t]||(this._events[t]=[]);return r.push({callback:e,context:n||this,_chart:this}),this},c.prototype.once=function(t,e,n){var r=this,i=function(){r.off(t,i),e.apply(this,arguments)};return this.on(t,i,n)},c.prototype.off=function(t,e,n){var r,i,a,s,o,h;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return a=this._events[t],a&&(a.length=0),this;for(r=t?[t]:Object.keys(this._events),o=0;r.length>o;o++)for(i=r[o],a=this._events[i],h=a.length;h--;)s=a[h],(e&&e===s.callback||n&&n===s.context)&&a.splice(h,1);return this},c.prototype.trigger=function(t){var e,n,r=Array.prototype.slice.call(arguments,1),i=this._events[t];if(void 0!==i)for(e=0;i.length>e;e++)n=i[e],n.callback.apply(n.context,r);return this},c.extend=function(t,e,i){var a,s=this;a=e&&r.call(e,"constructor")?e.constructor:function(){return s.apply(this,arguments)},n(a,s,i);var o=function(){this.constructor=a};return o.prototype=s.prototype,a.prototype=new o,e&&n(a.prototype,e),a.__super__=s.prototype,c[t]=a,a},e.chart=function(t){return 0===arguments.length?c:1===arguments.length?c[t]:c.extend.apply(c,arguments)},e.selection.prototype.chart=function(t,e){if(0===arguments.length)return this._chart;var n=c[t];return i(n,"No chart registered with name '"+t+"'"),new n(this,e)},e.selection.enter.prototype.chart=function(){return this._chart},e.transition.prototype.chart=e.selection.enter.prototype.chart}); +(function(t){"use strict";function e(t){var e,r,n,i;if(!t)return t;for(r=arguments.length,e=1;r>e;e++)if(n=arguments[e])for(i in n)t[i]=n[i];return t}var r=t.d3,n=Object.hasOwnProperty,i=function(t,e){if(!t)throw Error("[d3.chart] "+e)};i(r,"d3.js is required"),i("string"==typeof r.version&&r.version.match(/^3/),"d3.js version 3 is required");var a=/^(enter|update|merge|exit)(:transition)?$/,s=function(t){i(t,"Layers must be initialized with a base."),this._base=t,this._handlers={}};s.prototype.dataBind=function(){i(!1,"Layers must specify a `dataBind` method.")},s.prototype.insert=function(){i(!1,"Layers must specify an `insert` method.")},s.prototype.on=function(t,e,r){return r=r||{},i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#on`: '"+t+"'."),t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:e,chart:r.chart||null}),this._base},s.prototype.off=function(t,e){var r,n=this._handlers[t];if(i(a.test(t),"Unrecognized lifecycle event name specified to `Layer#off`: '"+t+"'."),!n)return this._base;if(1===arguments.length)return n.length=0,this._base;for(r=n.length-1;r>-1;--r)n[r].callback===e&&n.splice(r,1);return this._base},s.prototype.draw=function(t){var e,n,a,s,o,h,c,l;e=this.dataBind.call(this._base,t),i(e&&e.call===r.selection.prototype.call,"Invalid selection defined by `Layer#dataBind` method."),i(e.enter,"Layer selection not properly bound."),n=e.enter(),n._chart=this._base._chart,a=[{name:"update",selection:e},{name:"enter",selection:this.insert.bind(n)},{name:"merge",selection:e},{name:"exit",selection:e.exit.bind(e)}];for(var u=0,p=a.length;p>u;++u)if(h=a[u].name,s=a[u].selection,"function"==typeof s&&(s=s()),!s.empty()){if(i(s&&s.call===r.selection.prototype.call,"Invalid selection defined for '"+h+"' lifecycle event."),o=this._handlers[h])for(c=0,l=o.length;l>c;++c)s._chart=o[c].chart||this._base._chart,s.call(o[c].callback);if(o=this._handlers[h+":transition"],o&&o.length)for(s=s.transition(),c=0,l=o.length;l>c;++c)s._chart=o[c].chart||this._base._chart,s.call(o[c].callback)}},r.selection.prototype.layer=function(t){var e,r=new s(this);if(r.dataBind=t.dataBind,r.insert=t.insert,"events"in t)for(e in t.events)r.on(e,t.events[e]);return this.on=function(){return r.on.apply(r,arguments)},this.off=function(){return r.off.apply(r,arguments)},this.draw=function(){return r.draw.apply(r,arguments)},this};var o=function(t,e){var r=this.constructor,i=r.__super__;i&&o.call(i,t,e),n.call(r.prototype,"initialize")&&this.initialize.apply(t,e)},h=function(t,e){var r=this.constructor,i=r.__super__;return this===t&&n.call(this,"transform")&&(e=this.transform(e)),n.call(r.prototype,"transform")&&(e=r.prototype.transform.call(t,e)),i&&(e=h.call(i,t,e)),e},c=function(t,e){this.base=t,this._layers={},this._attached={},this._events={},e&&e.transform&&(this.transform=e.transform),o.call(this,this,[e])};c.prototype.initialize=function(){},c.prototype.unlayer=function(t){var e=this.layer(t);return delete this._layers[t],delete e._chart,e},c.prototype.layer=function(t,e,r){var n;if(1===arguments.length)return this._layers[t];if(2===arguments.length){if("function"==typeof e.draw)return e._chart=this,this._layers[t]=e,this._layers[t];i(!1,"When reattaching a layer, the second argument must be a d3.chart layer")}return n=e.layer(r),this._layers[t]=n,e._chart=this,n},c.prototype.attach=function(t,e){return 1===arguments.length?this._attached[t]:(this._attached[t]=e,e)},c.prototype.draw=function(t){var e,r,n;t=h.call(this,this,t);for(e in this._layers)this._layers[e].draw(t);for(r in this._attached)n=this.demux?this.demux(r,t):t,this._attached[r].draw(n)},c.prototype.on=function(t,e,r){var n=this._events[t]||(this._events[t]=[]);return n.push({callback:e,context:r||this,_chart:this}),this},c.prototype.once=function(t,e,r){var n=this,i=function(){n.off(t,i),e.apply(this,arguments)};return this.on(t,i,r)},c.prototype.off=function(t,e,r){var n,i,a,s,o,h;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return a=this._events[t],a&&(a.length=0),this;for(n=t?[t]:Object.keys(this._events),o=0;n.length>o;o++)for(i=n[o],a=this._events[i],h=a.length;h--;)s=a[h],(e&&e===s.callback||r&&r===s.context)&&a.splice(h,1);return this},c.prototype.trigger=function(t){var e,r,n=Array.prototype.slice.call(arguments,1),i=this._events[t];if(void 0!==i)for(e=0;i.length>e;e++)r=i[e],r.callback.apply(r.context,n);return this},c.extend=function(t,r,i){var a,s=this;a=r&&n.call(r,"constructor")?r.constructor:function(){return s.apply(this,arguments)},e(a,s,i);var o=function(){this.constructor=a};return o.prototype=s.prototype,a.prototype=new o,r&&e(a.prototype,r),a.__super__=s.prototype,c[t]=a,a},r.chart=function(t){return 0===arguments.length?c:1===arguments.length?c[t]:c.extend.apply(c,arguments)},r.selection.prototype.chart=function(t,e){if(0===arguments.length)return this._chart;var r=c[t];return i(r,"No chart registered with name '"+t+"'"),new r(this,e)},r.selection.enter.prototype.chart=function(){return this._chart},r.transition.prototype.chart=r.selection.enter.prototype.chart})(this); //@ sourceMappingURL=d3.chart.min.map \ No newline at end of file diff --git a/d3.chart.min.map b/d3.chart.min.map index 5ffc8e9..3a23bf2 100644 --- a/d3.chart.min.map +++ b/d3.chart.min.map @@ -1 +1 @@ -{"version":3,"file":"d3.chart.min.js","sources":["d3.chart.js"],"names":["global","factory","define","amd","d3","this","window","extend","object","argsIndex","argsLength","iteratee","key","arguments","length","hasOwnProp","Object","hasOwnProperty","d3cAssert","test","message","Error","version","match","lifecycleRe","Layer","base","_base","_handlers","prototype","dataBind","insert","remove","on","eventName","handler","options","push","callback","chart","off","idx","handlers","splice","draw","data","bound","entering","events","selection","method","len","call","enter","_chart","name","exit","i","l","empty","transition","layer","apply","initCascade","instance","args","ctor","constructor","sup","__super__","initialize","transformCascade","transform","Chart","chartOptions","_layers","_attached","_events","unlayer","attach","attachmentName","layerName","attachmentData","demux","context","once","self","names","n","event","j","keys","trigger","ev","Array","slice","undefined","protoProps","staticProps","child","parent","Surrogate","chartName","ChartCtor"],"mappings":";;;;CAIA,SAAUA,EAAQC,GACjB,YAE6B,mBAAlBD,GAAOE,QAAyBF,EAAOE,OAAOC,IACxDD,QAAQ,MAAO,SAASE,GACvBH,EAAQD,EAAQI,KAGjBH,EAAQD,EAAQA,EAAOI,MAGtBC,KAAM,SAASC,EAAQF,GAC1B,YAkSA,SAASG,GAAOC,GACf,GAAIC,GAAWC,EAAYC,EAAUC,CACrC,KAAKJ,EACJ,MAAOA,EAGR,KADAE,EAAaG,UAAUC,OAClBL,EAAY,EAAeC,EAAZD,EAAwBA,IAE3C,GADAE,EAAWE,UAAUJ,GAEpB,IAAKG,IAAOD,GACXH,EAAOI,GAAOD,EAASC,EAI1B,OAAOJ,GA3SR,GAAIO,GAAaC,OAAOC,eAEpBC,EAAY,SAASC,EAAMC,GAC9B,IAAID,EAGJ,KAAUE,OAAM,cAAgBD,GAGjCF,GAAUd,EAAI,qBACdc,EAAgC,gBAAfd,GAAGkB,SAAwBlB,EAAGkB,QAAQC,MAAM,MAC5D,8BAID,IAAIC,GAAc,4CAcdC,EAAQ,SAASC,GACpBR,EAAUQ,EAAM,2CAChBrB,KAAKsB,MAAQD,EACbrB,KAAKuB,aASNH,GAAMI,UAAUC,SAAW,WAC1BZ,GAAU,EAAO,6CAQlBO,EAAMI,UAAUE,OAAS,WACxBb,GAAU,EAAO,4CAQlBO,EAAMI,UAAUG,OAAS,WACxB3B,KAAK2B,UAgBNP,EAAMI,UAAUI,GAAK,SAASC,EAAWC,EAASC,GAgBjD,MAfAA,GAAUA,MAEVlB,EACCM,EAAYL,KAAKe,GACjB,+DACAA,EAAY,MAGPA,IAAa7B,MAAKuB,YACvBvB,KAAKuB,UAAUM,OAEhB7B,KAAKuB,UAAUM,GAAWG,MACzBC,SAAUH,EACVI,MAAOH,EAA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lG,KAAM+B,IAK5BhC,EAAG6C,UAAUI,MAAMxB,UAAUU,MAAQ,WACpC,MAAOlC,MAAKiD,QAEblD,EAAGwD,WAAW/B,UAAUU,MAAQnC,EAAG6C,UAAUI,MAAMxB,UAAUU"} \ No newline at end of file +{"version":3,"file":"d3.chart.min.js","sources":["d3.chart.js"],"names":["window","extend","object","argsIndex","argsLength","iteratee","key","arguments","length","d3","hasOwnProp","Object","hasOwnProperty","d3cAssert","test","message","Error","version","match","lifecycleRe","Layer","base","this","_base","_handlers","prototype","dataBind","insert","on","eventName","handler","options","push","callback","chart","off","idx","handlers","splice","draw","data","bound","entering","events","selection","len","call","enter","_chart","name","bind","exit","i","l","empty","transition","layer","apply","initCascade","instance","args","ctor","constructor","sup","__super__","initialize","transformCascade","transform","Chart","chartOptions","_layers","_attached","_events","unlayer","attach","attachmentName","layerName","attachmentData","demux","context","once","self","names","n","event","j","keys","trigger","ev","Array","slice","undefined","protoProps","staticProps","child","parent","Surrogate","chartName","ChartCtor"],"mappings":";;;;CAIA,SAAUA,GACV,YAoQA,SAASC,GAAOC,GACf,GAAIC,GAAWC,EAAYC,EAAUC,CACrC,KAAKJ,EACJ,MAAOA,EAGR,KADAE,EAAaG,UAAUC,OAClBL,EAAY,EAAeC,EAAZD,EAAwBA,IAE3C,GADAE,EAAWE,UAAUJ,GAEpB,IAAKG,IAAOD,GACXH,EAAOI,GAAOD,EAASC,EAI1B,OAAOJ,GA/QR,GAAIO,GAAKT,EAAOS,GACZC,EAAaC,OAAOC,eAEpBC,EAAY,SAASC,EAAMC,GAC9B,IAAID,EAGJ,KAAUE,OAAM,cAAgBD,GAGjCF,GAAUJ,EAAI,qBACdI,EAAgC,gBAAfJ,GAAGQ,SAAwBR,EAAGQ,QAAQC,MAAM,MAC5D,8BAID,IAAIC,GAAc,4CAadC,EAAQ,SAASC,GACpBR,EAAUQ,EAAM,2CAChBC,KAAKC,MAAQF,EACbC,KAAKE,aASNJ,GAAMK,UAAUC,SAAW,WAC1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C,OACb,MAAOc,MAAK0B,MAEb,IAAIkD,GAAY9B,EAAM6B,EAGtB,OAFApF,GAAUqF,EAAW,kCAAoCD,EAAY,KAE9D,GAAIC,GAAU5E,KAAMS,IAK5BtB,EAAGmC,UAAUG,MAAMtB,UAAUS,MAAQ,WACpC,MAAOZ,MAAK0B,QAEbvC,EAAG8C,WAAW9B,UAAUS,MAAQzB,EAAGmC,UAAUG,MAAMtB,UAAUS,QAC1DZ"} \ No newline at end of file From a5a80c74c44d1cc76a1bcb7a9c3dae59d96fd4a3 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Sun, 29 Jun 2014 13:14:49 -0400 Subject: [PATCH 3/8] Typo fix --- src/layer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layer.js b/src/layer.js index 11549fe..f3b6823 100644 --- a/src/layer.js +++ b/src/layer.js @@ -40,7 +40,7 @@ Layer.prototype.insert = function() { }; /** - * Invoked by {@link Layer#draw} in order to remove existing DOM nodes from + * Invoked by {@link Layer#draw} in order to remove exiting DOM nodes from * this layer's `base`. This default implementation may be overridden by * Layer instances. */ @@ -125,7 +125,7 @@ Layer.prototype.off = function(eventName, handler) { * (according to {@link Layer#dataBind}), insert new elements (according to * {@link Layer#insert}), make lifecycle selections, invoke all relevant * handlers (as attached via {@link Layer#on}) with the lifecycle selections, - * then remove existing elements (according to {@link Layer#remove}). + * then remove exiting elements (according to {@link Layer#remove}). * * The lifecycle selections are: * From 8493b6a41c3b212b9654ba8463284183e0f1a0a1 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Sun, 29 Jun 2014 13:15:04 -0400 Subject: [PATCH 4/8] Fix remove test for layer. --- test/tests/layer.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/tests/layer.js b/test/tests/layer.js index c6f74f9..ac76541 100644 --- a/test/tests/layer.js +++ b/test/tests/layer.js @@ -55,10 +55,6 @@ suite("d3.layer", function() { dataBind: dataBind, insert: insert }); - // this.layer.remove = sinon.spy(); - var remove = this.remove = sinon.spy(function() { - return this.layer.remove(); - }); }); test("invokes the provided `dataBind` method exactly once", function() { @@ -86,10 +82,11 @@ suite("d3.layer", function() { this.layer.draw([]); assert(this.insert.calledOn(this.dataBind.returnValues[0].enter.returnValues[0])); }); - test("invokes the provided `remove` method exactly once", function() { - assert.equal(this.remove.callCount, 0); + test("invokes the provided `remove` method", function() { + this.layer.draw([1]); + assert.equal(this.layer.selectAll('g')[0].length, 1); this.layer.draw([]); - assert.equal(this.remove.callCount, 1); + assert.equal(this.layer.selectAll('g')[0].length, 0); }); suite("event triggering", function() { From 960b6df68987d4c6c6fb65ada9cb0ae2b925f5a1 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Wed, 9 Jul 2014 23:12:17 -0400 Subject: [PATCH 5/8] Uses .size in layer test --- test/tests/layer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/layer.js b/test/tests/layer.js index ac76541..87d9446 100644 --- a/test/tests/layer.js +++ b/test/tests/layer.js @@ -84,9 +84,9 @@ suite("d3.layer", function() { }); test("invokes the provided `remove` method", function() { this.layer.draw([1]); - assert.equal(this.layer.selectAll('g')[0].length, 1); + assert.equal(this.layer.selectAll('g').size(), 1); this.layer.draw([]); - assert.equal(this.layer.selectAll('g')[0].length, 0); + assert.equal(this.layer.selectAll('g').size(), 0); }); suite("event triggering", function() { From 506162d8416721b245612bd82497914e6d10f577 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Wed, 9 Jul 2014 23:21:17 -0400 Subject: [PATCH 6/8] Makes `remove` configurable --- src/layer-extensions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/layer-extensions.js b/src/layer-extensions.js index 2048f76..8c7bd0a 100644 --- a/src/layer-extensions.js +++ b/src/layer-extensions.js @@ -13,9 +13,12 @@ d3.selection.prototype.layer = function(options) { var layer = new Layer(this); var eventName; - // Set layer methods (required) + // Set layer methods (databind/insert required, remove optional) layer.dataBind = options.dataBind; layer.insert = options.insert; + if (options.remove) { + layer.remove = options.remove; + } // Bind events (optional) if ("events" in options) { From d4ddaccc3b406b86fd28446b7f95e582b06b91d7 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Mon, 21 Jul 2014 00:28:42 -0400 Subject: [PATCH 7/8] Updates layer spec with test for explicit remove function --- test/tests/layer.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/tests/layer.js b/test/tests/layer.js index 87d9446..2ffbbec 100644 --- a/test/tests/layer.js +++ b/test/tests/layer.js @@ -49,11 +49,12 @@ suite("d3.layer", function() { sinon.spy(entering, "transition"); return entering; }); + var remove = this.remove = sinon.spy(); var base = this.base = d3.select("#test").append("svg"); this.layer = base.layer({ dataBind: dataBind, - insert: insert + insert: insert, }); }); @@ -82,12 +83,22 @@ suite("d3.layer", function() { this.layer.draw([]); assert(this.insert.calledOn(this.dataBind.returnValues[0].enter.returnValues[0])); }); - test("invokes the provided `remove` method", function() { + test("by default removes exiting nodes from the DOM", function() { this.layer.draw([1]); assert.equal(this.layer.selectAll('g').size(), 1); this.layer.draw([]); assert.equal(this.layer.selectAll('g').size(), 0); }); + test("invokes the provided `remove` method", function() { + this.layer = this.base.layer({ + dataBind: this.dataBind, + insert: this.insert, + remove: this.remove + }); + + this.layer.draw([]); + assert(this.remove.called); + }); suite("event triggering", function() { test("invokes event handlers with the correct selection", function() { From 48f918f502827980950988a77e8bcc1ad2cf09a9 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Wed, 23 Jul 2014 07:00:18 -0400 Subject: [PATCH 8/8] Adds test for chart with provided remove method. --- test/tests/layer.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/tests/layer.js b/test/tests/layer.js index 2ffbbec..e0686ae 100644 --- a/test/tests/layer.js +++ b/test/tests/layer.js @@ -56,6 +56,12 @@ suite("d3.layer", function() { dataBind: dataBind, insert: insert, }); + + this.layerWithRemove = this.base.append('g').layer({ + dataBind: dataBind, + insert: insert, + remove: remove + }); }); test("invokes the provided `dataBind` method exactly once", function() { @@ -89,17 +95,18 @@ suite("d3.layer", function() { this.layer.draw([]); assert.equal(this.layer.selectAll('g').size(), 0); }); - test("invokes the provided `remove` method", function() { - this.layer = this.base.layer({ - dataBind: this.dataBind, - insert: this.insert, - remove: this.remove - }); + test("invokes the provided `remove` method in the context of the layer's bound 'exit' selection", function() { + var updating, exiting; - this.layer.draw([]); - assert(this.remove.called); + this.layerWithRemove.draw([1, 2, 3]); + this.layerWithRemove.draw([]); + + updating = this.dataBind.returnValues[1]; + exiting = updating.exit.returnValues[0]; + + assert(this.remove.calledOn(exiting)); }); - + suite("event triggering", function() { test("invokes event handlers with the correct selection", function() { var layer = this.base.append("g").layer({ @@ -154,19 +161,25 @@ suite("d3.layer", function() { }, insert: function() { return this.append("g"); - } + }, + remove: function() { + return this.remove(); + } }); var enterSpy = sinon.spy(); var updateSpy = sinon.spy(); + var exitSpy = sinon.spy(); layer.draw([1]); layer.on("enter", enterSpy); layer.on("update", updateSpy); + layer.on("exit", exitSpy); layer.draw([1]); sinon.assert.callCount(enterSpy, 0); sinon.assert.callCount(updateSpy, 1); + sinon.assert.callCount(exitSpy, 0); }); suite("Layer#off", function() {