// 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}; RGraph.SVG = RGraph.SVG || {}; // // This function has been taken out of the RGraph.svg.common.ajax.js file to // enable the CSV reader to work standalone. // if (!RGraph.SVG.AJAX) RGraph.SVG.AJAX = function (url, callback) { // Mozilla, Safari, ... if (window.XMLHttpRequest) { var httpRequest = new XMLHttpRequest(); // MSIE } else if (window.ActiveXObject) { var httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } httpRequest.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { this.__user_callback__ = callback; this.__user_callback__(this.responseText); } } httpRequest.open('GET', url, true); httpRequest.send(); }; // // Use the AJAX function above to fetch a string // if (!RGraph.SVG.getString) RGraph.SVG.AJAX.getString = function (url, callback) { RGraph.SVG.AJAX(url, function () { var str = String(this.responseText); callback(str); }); }; // This function simply creates UID. Formerly the function in // RGraph.common.core.js was being used - but now the CSV code // is now standalone, hence this function if (!RGraph.SVG.createUID) RGraph.SVG.createUID = function () { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); }; RGraph.SVG.CSV = RGraph.CSV = function (url, func) { // // Some default values // this.url = url; this.ready = func; this.data = null; this.numrows = null; this.numcols = null; this.seperator = arguments[2] || ','; this.endofline = arguments[3] || /\r?\n/; // // A Custom split function // // @param string str The CSV string to split // @param mixed char The character to split on - or it can also be an object like this: // { // preserve: false, // Whether to preserve whitespace // char: ',' // The character to split on // } // this.splitCSV = function (str, split) { // Defaults var arr = []; var field = ''; var inDoubleQuotes = false; var inSingleQuotes = false; var preserve = (typeof split === 'object' && split.preserve) ? true : false; // The character to split the CSV string on if (typeof split === 'object') { if (typeof split.char === 'string') { split = split.char; } else { split = ','; } } // If not an object just leave the char as it's supplied for (var i=0,len=str.length; i 0) { row = row.slice(0, length) // Negative length } else if (typeof length === 'number' && length < 0) { for (var i=0; i= 0) { for (var i=start; i 0) { col = col.slice(0, length) // Negative length } else if (typeof length === 'number' && length < 0) { for (var i=0; i