src/lib/charts/table.js
function(element, options) {
    _.extend(this, Backbone.Events);

    var defaults = require('../utils/default-options')();
    // set to be an object in case
    // it's undefined
    options = options || {};

    // extend the defaults
    options = _.extend(defaults, options);

    this.options = options;

    this._currentColumns = [];

    this.container = element;

    this.innerContainer = document.createElement('div');
    this.innerContainer.classList.add('inner-container');
    this.innerContainer.classList.add('hide-overflow');

    this.el = document.createElement('table');
    this.el.classList.add('table');
    this.el.classList.add('table-striped');
    this.container.classList.add('table-sink-container');
    this.innerContainer.appendChild(this.el);
    this.container.appendChild(this.innerContainer);

    this.innerContainer.style.maxHeight = options.height + 'px';

    this.resize();

    // create some scaffolding
    this.table = d3.select(this.el);
    this.thead = this.table.append('thead');
    this.tbody = this.table.append('tbody');

    // set if we should append to the existing table data
    // and not reset on batch_end
    this._append = options._append;

    this._markdownFields = this.options.markdownFields || [];

    this._bindScrollBlocker();

    // We don't need a fully-fledged data target here,
    // so we just add functions as per feedback from @demmer
    var self = this;
    this.dataTarget = {
        _data: [],
        push: function(data) {
            // clear the table if we've done batch_end / stream_end before
            if (this._data.length === 0) {
                self.clearTable();
            }

            // limit the data to avoid crashing the browser. If limit
            // is zero, then it is ignored. If the limit has been reached,
            // we return early and don't display the new data

            // check that we aren't already over the limit
            if (this._data.length >= self.options.limit) {

                // display the message and don't do anything else
                self._sendRowLimitReachedMessage();
                return;

            // check that the new data won't make us go over the limit
            } else if ((this._data.length + data.length) > self.options.limit) {

                self._sendRowLimitReachedMessage();

                // just add from new data until we get to the limit
                var i = 0;
                while (this._data.length < self.options.limit) {
                    this._data.push(data[i++]);
                }
            }
            // we're fine.
            else {
                self._clearRowLimitReachedMessage();
                this._data = this._data.concat(data);
            }

            // if you got here, draw the table
            self.onData(this._data);

        },
        batch_end: function() {
            if (self.options.update === 'replace') {
                this._data = [];
            }
        },
        stream_end: function() {
        }
    };

}
function(element, options) {
    _.extend(this, Backbone.Events);

    var defaults = require('../utils/default-options')();
    // set to be an object in case
    // it's undefined
    options = options || {};

    // extend the defaults
    options = _.extend(defaults, options);

    this.options = options;

    this._currentColumns = [];

    this.container = element;

    this.innerContainer = document.createElement('div');
    this.innerContainer.classList.add('inner-container');
    this.innerContainer.classList.add('hide-overflow');

    this.el = document.createElement('table');
    this.el.classList.add('table');
    this.el.classList.add('table-striped');
    this.container.classList.add('table-sink-container');
    this.innerContainer.appendChild(this.el);
    this.container.appendChild(this.innerContainer);

    this.innerContainer.style.maxHeight = options.height + 'px';

    this.resize();

    // create some scaffolding
    this.table = d3.select(this.el);
    this.thead = this.table.append('thead');
    this.tbody = this.table.append('tbody');

    // set if we should append to the existing table data
    // and not reset on batch_end
    this._append = options._append;

    this._markdownFields = this.options.markdownFields || [];

    this._bindScrollBlocker();

    // We don't need a fully-fledged data target here,
    // so we just add functions as per feedback from @demmer
    var self = this;
    this.dataTarget = {
        _data: [],
        push: function(data) {
            // clear the table if we've done batch_end / stream_end before
            if (this._data.length === 0) {
                self.clearTable();
            }

            // limit the data to avoid crashing the browser. If limit
            // is zero, then it is ignored. If the limit has been reached,
            // we return early and don't display the new data

            // check that we aren't already over the limit
            if (this._data.length >= self.options.limit) {

                // display the message and don't do anything else
                self._sendRowLimitReachedMessage();
                return;

            // check that the new data won't make us go over the limit
            } else if ((this._data.length + data.length) > self.options.limit) {

                self._sendRowLimitReachedMessage();

                // just add from new data until we get to the limit
                var i = 0;
                while (this._data.length < self.options.limit) {
                    this._data.push(data[i++]);
                }
            }
            // we're fine.
            else {
                self._clearRowLimitReachedMessage();
                this._data = this._data.concat(data);
            }

            // if you got here, draw the table
            self.onData(this._data);

        },
        batch_end: function() {
            if (self.options.update === 'replace') {
                this._data = [];
            }
        },
        stream_end: function() {
        }
    };

}
function ( element , options ) { _ . extend ( this , Backbone . Events ) ; var defaults = require ( '../utils/default-options' ) ( ) ; // set to be an object in case // it's undefined options = options || { } ; // extend the defaults options = _ . extend ( defaults , options ) ; this . options = options ; this . _currentColumns = [ ] ; this . container = element ; this . innerContainer = document . createElement ( 'div' ) ; this . innerContainer . classList . add ( 'inner-container' ) ; this . innerContainer . classList . add ( 'hide-overflow' ) ; this . el = document . createElement ( 'table' ) ; this . el . classList . add ( 'table' ) ; this . el . classList . add ( 'table-striped' ) ; this . container . classList . add ( 'table-sink-container' ) ; this . innerContainer . appendChild ( this . el ) ; this . container . appendChild ( this . innerContainer ) ; this . innerContainer . style . maxHeight = options . height + 'px' ; this . resize ( ) ; // create some scaffolding this . table = d3 . select ( this . el ) ; this . thead = this . table . append ( 'thead' ) ; this . tbody = this . table . append ( 'tbody' ) ; // set if we should append to the existing table data // and not reset on batch_end this . _append = options . _append ; this . _markdownFields = this . options . markdownFields || [ ] ; this . _bindScrollBlocker ( ) ; // We don't need a fully-fledged data target here, // so we just add functions as per feedback from @demmer var self = this ; this . dataTarget = { _data : [ ] , push : function ( data ) { // clear the table if we've done batch_end / stream_end before if ( this . _data . length === 0 ) { self . clearTable ( ) ; } // limit the data to avoid crashing the browser. If limit // is zero, then it is ignored. If the limit has been reached, // we return early and don't display the new data // check that we aren't already over the limit if ( this . _data . length >= self . options . limit ) { // display the message and don't do anything else self . _sendRowLimitReachedMessage ( ) ; return ; // check that the new data won't make us go over the limit } else if ( ( this . _data . length + data . length ) > self . options . limit ) { self . _sendRowLimitReachedMessage ( ) ; // just add from new data until we get to the limit var i = 0 ; while ( this . _data . length < self . options . limit ) { this . _data . push ( data [ i ++ ] ) ; } } // we're fine. else { self . _clearRowLimitReachedMessage ( ) ; this . _data = this . _data . concat ( data ) ; } // if you got here, draw the table self . onData ( this . _data ) ; } , batch_end : function ( ) { if ( self . options . update === 'replace' ) { this . _data = [ ] ; } } , stream_end : function ( ) { } } ; }
initialise the table and create some scaffolding
initialise the table and create some scaffolding