// version: 2017-11-25 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | RGraph is licensed under the Open Source MIT license. That means that it's | * | totally free to use and there are no restrictions on what you can do with it! | * o--------------------------------------------------------------------------------o */ /** * Initialise the various objects */ RGraph = window.RGraph || {isRGraph: true}; // Module pattern (function (win, doc, undefined) { RGraph.Sheets = function (key) { var worksheet, callback, letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 3 arguments if (arguments.length === 3) { worksheet = Number(arguments[1]); callback = arguments[2]; // 2 arguments } else { worksheet = 1; callback = arguments[1]; } var url = 'https://spreadsheets.google.com/feeds/cells/[KEY]/[WORKSHEET]/public/full?alt=json-in-script&callback=__rgraph_JSONPCallback'.replace(/\[KEY\]/, key).replace(/\[WORKSHEET\]/, worksheet); /* * https://spreadsheets.google.com/feeds/cells/1q_BMjvKO_kKbAO3VjoaITSDyrLAk8f0SK5UFMmE3oRs/2/public/full?alt=json-in-script */ // // Loads the spreadsheet // this.load = function(url, userCallback) { var obj = this; // A global on purpose __rgraph_JSONPCallback = function (json) { // Save the JSON on the RGraph.Sheets object obj.json = json; // // Put the entries in the JSON feed into a grid // var grid = [], row = 0, col = 0; for (var i=0; i"); // // And without jQuery... var scriptNode = document.createElement('script'); scriptNode.src = url; document.body.appendChild(scriptNode); }; // // Fetches a row of data and returns it // // @param id number The numeric index of the column to fetch (starts at 1) // @param start number The index to start fetching/returning at. The first // character is 1 // @param opt An option object containing options // this.row = function (index, start) { var opt = {}, row; // Default for start is 1 start = start || 1; // // Parse the .trim argument // if (arguments && typeof arguments[2] === 'object' && typeof arguments[2].trim === 'boolean') { opt.trim = arguments[2].trim; } else { opt.trim = true; } row = this.data[index - 1].slice(start - 1); // Trim the array if required if (opt.trim) { row = RGraph.arrayTrim(row); } return row; }; // // Fetches a column of data and returns it // // @param id number The letter that corresponds to the column // @param start number The index to start fetching/returning at. The first // character is 1 // @param opt An option object containing options // this.col = function (index, start) { var opt = {}, col = []; // Default for start is 1 start = start || 1; if (arguments && typeof arguments[2] === 'object' && typeof arguments[2].trim === 'boolean') { opt.trim = arguments[2].trim; } else { opt.trim = true; } for (var i=0; i