File Manager
Back to List
|
Up to Parent Directory
| Current Directory: ~/graph\html\js
Editing: graph/html/js/utils.js
Full path: C:\ict\ICT\graph\html\js\utils.js
Permissions: rwx
Write test: File appears not directly writable
Current process identity: IIS APPPOOL\DefaultAppPool
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ 'use strict'; window.chartColors = { red: '#ed1c24', redLight: '#f7941d', orange: 'rgb(255, 159, 64)', yellow: 'rgb(255, 205, 86)', green: '#17fb52', greenLight: '#1df789', blue: 'rgb(54, 162, 235)', purple: 'rgb(153, 102, 255)', grey: 'rgb(201, 203, 207)' }; (function (global) { var MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var COLORS = [ '#4dc9f6', '#f67019', '#f53794', '#537bc4', '#acc236', '#166a8f', '#00a950', '#58595b', '#8549ba' ]; var Samples = global.Samples || (global.Samples = {}); var Color = global.Color; Samples.utils = { // Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ srand: function (seed) { this._seed = seed; }, rand: function (min, max) { var seed = this._seed; min = min === undefined ? 0 : min; max = max === undefined ? 1 : max; this._seed = (seed * 9301 + 49297) % 233280; return min + (this._seed / 233280) * (max - min); }, numbers: function (config) { var cfg = config || {}; var min = cfg.min || 0; var max = cfg.max || 1; var from = cfg.from || []; var count = cfg.count || 8; var decimals = cfg.decimals || 8; var continuity = cfg.continuity || 1; var dfactor = Math.pow(10, decimals) || 0; var data = []; var i, value; for (i = 0; i < count; ++i) { value = (from[i] || 0) + this.rand(min, max); if (this.rand() <= continuity) { data.push(Math.round(dfactor * value) / dfactor); } else { data.push(null); } } return data; }, labels: function (config) { var cfg = config || {}; var min = cfg.min || 0; var max = cfg.max || 100; var count = cfg.count || 8; var step = (max - min) / count; var decimals = cfg.decimals || 8; var dfactor = Math.pow(10, decimals) || 0; var prefix = cfg.prefix || ''; var values = []; var i; for (i = min; i < max; i += step) { values.push(prefix + Math.round(dfactor * i) / dfactor); } return values; }, months: function (config) { var cfg = config || {}; var count = cfg.count || 12; var section = cfg.section; var values = []; var i, value; for (i = 0; i < count; ++i) { value = MONTHS[Math.ceil(i) % 12]; values.push(value.substring(0, section)); } return values; }, color: function (index) { return COLORS[index % COLORS.length]; }, transparentize: function (color, opacity) { var alpha = opacity === undefined ? 0.5 : 1 - opacity; return Color(color).alpha(alpha).rgbString(); } }; // DEPRECATED window.randomScalingFactor = function () { return Math.round(Samples.utils.rand(-100, 100)); }; // INITIALIZATION Samples.utils.srand(Date.now()); // Google Analytics /* eslint-disable */ if (document.location.hostname.match(/^(www\.)?chartjs\.org$/)) { (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m) })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); ga('create', 'UA-28909194-3', 'auto'); ga('send', 'pageview'); } /* eslint-enable */ }(this)); function CSVToArray(strData, strDelimiter) { // Check to see if the delimiter is defined. If not, // then default to comma. strDelimiter = (strDelimiter || ","); // Create a regular expression to parse the CSV values. var objPattern = new RegExp( ( // Delimiters. "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" + // Quoted fields. "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + // Standard fields. "([^\"\\" + strDelimiter + "\\r\\n]*))" ), "gi" ); // Create an array to hold our data. Give the array // a default empty first row. var arrData = [[]]; // Create an array to hold our individual pattern // matching groups. var arrMatches = null; // Keep looping over the regular expression matches // until we can no longer find a match. while (arrMatches = objPattern.exec(strData)) { // Get the delimiter that was found. var strMatchedDelimiter = arrMatches[ 1 ]; // Check to see if the given delimiter has a length // (is not the start of string) and if it matches // field delimiter. If id does not, then we know // that this delimiter is a row delimiter. if ( strMatchedDelimiter.length && strMatchedDelimiter !== strDelimiter ) { // Since we have reached a new row of data, // add an empty row to our data array. arrData.push([]); } var strMatchedValue; // Now that we have our delimiter out of the way, // let's check to see which kind of value we // captured (quoted or unquoted). if (arrMatches[ 2 ]) { // We found a quoted value. When we capture // this value, unescape any double quotes. strMatchedValue = arrMatches[ 2 ].replace( new RegExp("\"\"", "g"), "\"" ); } else { // We found a non-quoted value. strMatchedValue = arrMatches[ 3 ]; } // Now that we have our value string, let's add // it to the data array. arrData[ arrData.length - 1 ].push(strMatchedValue); } // Return the parsed data. return(arrData); } function formatNumber(x) { if (parseInt(x) >= 1000) { return x.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); } else { return x; } } function sanitise(x) { if (isNaN(x)) { return 0; } return x; }