src/VegaWrapper.js
function VegaWrapper(wrapperOpts) {
    var self = this;
    // Copy all options into this object
    self.objExtender = wrapperOpts.datalib.extend;
    self.objExtender(self, wrapperOpts);
    self.validators = {};

    self.datalib.load.loader = function (opt, callback) {
        var error = callback || function (e) { throw e; }, url;

        try {
            url = self.sanitizeUrl(opt); // enable override
        } catch (err) {
            error(err);
            return;
        }

        // Process data response
        var cb = function (error, data) {
            return self.dataParser(error, data, opt, callback);
        };

        if (self.useXhr) {
            return self.datalib.load.xhr(url, opt, cb);
        } else {
            return self.datalib.load.http(url, opt, cb);
        }
    };

    self.datalib.load.sanitizeUrl = self.sanitizeUrl.bind(self);

    // Prevent accidental use
    self.datalib.load.file = alwaysFail;
    if (self.useXhr) {
        self.datalib.load.http = alwaysFail;
    } else {
        self.datalib.load.xhr = alwaysFail;
    }
}
function VegaWrapper(wrapperOpts) {
    var self = this;
    // Copy all options into this object
    self.objExtender = wrapperOpts.datalib.extend;
    self.objExtender(self, wrapperOpts);
    self.validators = {};

    self.datalib.load.loader = function (opt, callback) {
        var error = callback || function (e) { throw e; }, url;

        try {
            url = self.sanitizeUrl(opt); // enable override
        } catch (err) {
            error(err);
            return;
        }

        // Process data response
        var cb = function (error, data) {
            return self.dataParser(error, data, opt, callback);
        };

        if (self.useXhr) {
            return self.datalib.load.xhr(url, opt, cb);
        } else {
            return self.datalib.load.http(url, opt, cb);
        }
    };

    self.datalib.load.sanitizeUrl = self.sanitizeUrl.bind(self);

    // Prevent accidental use
    self.datalib.load.file = alwaysFail;
    if (self.useXhr) {
        self.datalib.load.http = alwaysFail;
    } else {
        self.datalib.load.xhr = alwaysFail;
    }
}
function VegaWrapper ( wrapperOpts ) { var self = this ; // Copy all options into this object self . objExtender = wrapperOpts . datalib . extend ; self . objExtender ( self , wrapperOpts ) ; self . validators = { } ; self . datalib . load . loader = function ( opt , callback ) { var error = callback || function ( e ) { throw e ; } , url ; try { url = self . sanitizeUrl ( opt ) ; // enable override } catch ( err ) { error ( err ) ; return ; } // Process data response var cb = function ( error , data ) { return self . dataParser ( error , data , opt , callback ) ; } ; if ( self . useXhr ) { return self . datalib . load . xhr ( url , opt , cb ) ; } else { return self . datalib . load . http ( url , opt , cb ) ; } } ; self . datalib . load . sanitizeUrl = self . sanitizeUrl . bind ( self ) ; // Prevent accidental use self . datalib . load . file = alwaysFail ; if ( self . useXhr ) { self . datalib . load . http = alwaysFail ; } else { self . datalib . load . xhr = alwaysFail ; } }
Shared library to wrap around vega code
@param {Object} wrapperOpts Configuration options
@param {Object} wrapperOpts.datalib Vega's datalib object
@param {Object} wrapperOpts.datalib.load Vega's data loader
@param {Function} wrapperOpts.datalib.load.loader Vega's data loader function
@param {Function} wrapperOpts.datalib.extend similar to jquery's extend()
@param {boolean} wrapperOpts.useXhr true if we should use XHR, false for node.js http loading
@param {boolean} wrapperOpts.isTrusted true if the graph spec can be trusted
@param {Object} wrapperOpts.domains allowed protocols and a list of their domains
@param {Object} wrapperOpts.domainMap domain remapping
@param {Function} wrapperOpts.logger
@param {Function} wrapperOpts.parseUrl
@param {Function} wrapperOpts.formatUrl
@param {string} [wrapperOpts.languageCode]
@constructor
Shared library to wrap around vega code