var View = require('ampersand-view');
var dc = require('dc');

module.exports = View.extend({

    initialize: function () {
        // register with DC to receive filter events
        dc.registerChart(this);

        this.once('remove', function() {

            // remove listener when widget is removed
            dc.deregisterChart(this);

            if(this._chart) {

                // remove filter
                this._chart.filterAll();

                // remove chart
                delete this._chart;

                // re-render other plots
                // NOTE: dc.renderAll() makes other widgets using the same crossfilter misbehave
                dc.redrawAll();
            }
        });
    },

    // Call-back for dc on filter events
    // Use this to update the widget
    redraw: function () {
    },

    // 
    cleanup: function () {
    },

    // First rendering pass: add responsive widget to the DOM
    // The template and CSS can use relative sizes, be responsive, etc.
    render: function () {
        if(this.template) {
            this.renderWithTemplate(this);
        }

        return this;
    },

    // Second rendering pass: add fixed-width elements to the DOM
    // Things like SVG canvas, OpenLayers Maps
    // Should call renderContent on each subwidget (if any)

    // NOTE: it is passed the view instead of using 'this' as calls from outside of ampersand
    // can set 'this' to some other object.
    renderContent: function (view) {
    },

    // Used by DC when (de)registering
    anchorName: function () {
        return this.cid;
    }
});


@@ -56,16 +56,140 @@
 'dc');%0A%0A
+// DC charts should be added to the view as view._chart%0A// the base widget then takes care of chart and filter life cycles%0A%0A
 module.e
@@ -808,16 +808,17 @@
 wAll();%0A
+%0A
         
@@ -822,16 +822,45 @@
        %7D
+%0A%0A            this.cleanup();
 %0A       
@@ -889,16 +889,124 @@
 ll-back 
+on view remove%0A    // Override to do extra cleanup here%0A    cleanup: function () %7B%0A    %7D,%0A%0A    // Call-back 
 for dc o
@@ -1072,51 +1072,8 @@
 draw
-: function () %7B%0A    %7D,%0A%0A    // %0A    cleanup
 : fu

Add a cleanup call back for widget-content