// o---------------------------------------------------------------------------------o // | This file is part of the RGraph package - you can learn more at: | // | | // | https://www.rgraph.net/license.html | // | | // | RGraph is dual-licensed under the Open Source GPL license. That means that it's | // | free to use and there are no restrictions on what you can use RGraph for! | // | If the GPL license does not suit you however, then there's an inexpensive | // | commercial license option available. See the URL above for more details. | // o---------------------------------------------------------------------------------o // // Initialise the various objects // RGraph = window.RGraph || {isrgraph:true,isRGraph: true,rgraph:true}; // Module pattern (function (win, doc, undefined) { RGraph.Sheets = function () { var args = RGraph.Sheets.getArgs(arguments, 'oauth,key,worksheet,callback'); // Allow three args to be given as well as four if (arguments.length === 1) { // Nothing to do here } else if (arguments.length === 3) { args.oauth = args.oauth; args.key = args.key; args.callback = args.worksheet; // Need to set this because the order of the args is wrong args.worksheet = 'Sheet1'; } else if (arguments.length === 4) { args.worksheet = args.worksheet; } var worksheet = args.worksheet, callback = args.callback, letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', key = args.key, oauth = args.oauth; var url = ('https://sheets.googleapis.com/v4/spreadsheets/[KEY]/values/[WORKSHEET]?alt=json&key=[OAUTH_KEY]') .replace(/\[KEY\]/, args.key) .replace(/\[WORKSHEET\]/, encodeURIComponent(args.worksheet)) .replace(/\[OAUTH_KEY\]/, args.oauth) // // Loads the spreadsheet // this.load = function(url, userCallback) { var obj = this; RGraph.Sheets.AJAX.getJSON(url, function (json) { var grid = json.values; var rows = grid.length; var cells = 0; // // Determine the longest row // for (var i=0; i 234 for (var i=0; i=0; i--) { if (arr[i] || content) { out.push(arr[i]); content = true; } } arr = out.reverse(); return out; }; // // This function allows both object based arguments to functions // and also regular arguments as well. // // You can call it from inside a function like this: // // args = RGraph.Sheets.getArgs(arguments, 'object,id,foo,bar'); // // So you're passing it the arguments object and a comma seperated list of names // for the arguments. // // @param array args The arguments object that you get when inside a function // @param string names A comma seperated list of desired names for the arguments // eg: 'object,color,size' // RGraph.Sheets.getArgs = function (args, names) { var ret = {}; var count = 0; names = names.trim().split(/ *, */); if ( args && args[0] && args.length === 1 && typeof args[0][names[0]] !== 'undefined') { for (var i=0; i