diff --git a/plottable.d.ts b/plottable.d.ts index dbea55fd0a..ad21dcd960 100644 --- a/plottable.d.ts +++ b/plottable.d.ts @@ -11,6 +11,11 @@ declare module Plottable { * @return {boolean} Whether x is in [a, b] */ function inRange(x: number, a: number, b: number): boolean; + /** Print a warning message to the console, if it is available. + * + * @param {string} The warnings to print + */ + function warn(warning: string): void; /** * Takes two arrays of numbers and adds them together * diff --git a/plottable.js b/plottable.js index a0e568c042..51daf0db0d 100644 --- a/plottable.js +++ b/plottable.js @@ -22,6 +22,23 @@ var Plottable; } Methods.inRange = inRange; + /** Print a warning message to the console, if it is available. + * + * @param {string} The warnings to print + */ + function warn(warning) { + /* tslint:disable:no-console */ + if (window.console != null) { + if (window.console.warn != null) { + console.warn(warning); + } else if (window.console.log != null) { + console.log(warning); + } + } + /* tslint:enable:no-console */ + } + Methods.warn = warn; + /** * Takes two arrays of numbers and adds them together * @@ -630,7 +647,7 @@ var Plottable; var h = bb.height; var w = bb.width; if (w > width || h > height) { - console.log("Insufficient space to fit text"); + Util.Methods.warn("Insufficient space to fit text"); return { width: 0, height: 0 }; } var anchorConverter = { left: "start", center: "middle", right: "end" }; @@ -2543,7 +2560,7 @@ var Plottable; }; if (epsilonGT(spaceRequest.width, offeredWidths[colIndex]) || epsilonGT(spaceRequest.height, offeredHeights[rowIndex])) { - console.log("Invariant Violation: Abstract.Component cannot request more space than is offered"); + Plottable.Util.Methods.warn("Invariant Violation: Abstract.Component cannot request more space than is offered"); } requestedWidths[colIndex] = Math.max(requestedWidths[colIndex], spaceRequest.width); @@ -3562,7 +3579,7 @@ var Plottable; return x !== x || x === Infinity || x === -Infinity; }; if (isNaNOrInfinity(values[0]) || isNaNOrInfinity(values[1])) { - console.log("Warning: QuantitiveScales cannot take NaN or Infinity as a domain value. Ignoring."); + Plottable.Util.Methods.warn("Warning: QuantitiveScales cannot take NaN or Infinity as a domain value. Ignoring."); return; } _super.prototype._setDomain.call(this, values); diff --git a/src/core/table.ts b/src/core/table.ts index cff6a25844..ace491eadd 100644 --- a/src/core/table.ts +++ b/src/core/table.ts @@ -218,7 +218,7 @@ export module Component { }; if (epsilonGT(spaceRequest.width, offeredWidths[colIndex]) || epsilonGT(spaceRequest.height, offeredHeights[rowIndex])) { - console.log("Invariant Violation: Abstract.Component cannot request more space than is offered"); + Util.Methods.warn("Invariant Violation: Abstract.Component cannot request more space than is offered"); } requestedWidths [colIndex] = Math.max(requestedWidths [colIndex], spaceRequest.width ); diff --git a/src/scales/quantitiveScale.ts b/src/scales/quantitiveScale.ts index 28995797d4..3c3db2b573 100644 --- a/src/scales/quantitiveScale.ts +++ b/src/scales/quantitiveScale.ts @@ -51,7 +51,7 @@ export module Abstract { public _setDomain(values: any[]) { var isNaNOrInfinity = (x: any) => x !== x || x === Infinity || x === -Infinity; if (isNaNOrInfinity(values[0]) || isNaNOrInfinity(values[1])) { - console.log("Warning: QuantitiveScales cannot take NaN or Infinity as a domain value. Ignoring."); + Util.Methods.warn("Warning: QuantitiveScales cannot take NaN or Infinity as a domain value. Ignoring."); return; } super._setDomain(values); diff --git a/src/utils/textUtils.ts b/src/utils/textUtils.ts index 63caf6fd77..7c40def485 100644 --- a/src/utils/textUtils.ts +++ b/src/utils/textUtils.ts @@ -204,7 +204,7 @@ export module Util { var h = bb.height; var w = bb.width; if (w > width || h > height) { - console.log("Insufficient space to fit text"); + Util.Methods.warn("Insufficient space to fit text"); return {width: 0, height: 0}; } var anchorConverter: {[s: string]: string} = {left: "start", center: "middle", right: "end"}; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5a47fa9efc..819d29b689 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -16,6 +16,22 @@ export module Util { return (Math.min(a,b) <= x && x <= Math.max(a,b)); } + /** Print a warning message to the console, if it is available. + * + * @param {string} The warnings to print + */ + export function warn(warning: string) { + /* tslint:disable:no-console */ + if (( window).console != null) { + if (( window).console.warn != null) { + console.warn(warning); + } else if (( window).console.log != null) { + console.log(warning); + } + } + /* tslint:enable:no-console */ + } + /** * Takes two arrays of numbers and adds them together * @@ -114,7 +130,7 @@ export module Util { * @param {any} a Object to check against b for equality. * @param {any} b Object to check against a for equality. * - * @returns {boolean} whether or not two objects share the same keys, and + * @returns {boolean} whether or not two objects share the same keys, and * values associated with those keys. Values will be compared * with ===. */ diff --git a/test/perfdiagnostics.ts b/test/perfdiagnostics.ts deleted file mode 100644 index 36094e74a4..0000000000 --- a/test/perfdiagnostics.ts +++ /dev/null @@ -1,61 +0,0 @@ - -module PerfDiagnostics { - class PerfDiagnostics { - private static diagnostics: { [measurementName: string]: PerfDiagnostics; } = {}; - private total: number; - private start: number; - private numCalls: number; - - public static toggle(measurementName: string) { - var diagnostic: PerfDiagnostics;; - if (PerfDiagnostics.diagnostics[measurementName] != null) { - diagnostic = PerfDiagnostics.diagnostics[measurementName]; - } else { - diagnostic = new PerfDiagnostics(); - PerfDiagnostics.diagnostics[measurementName] = diagnostic; - } - diagnostic.toggle(); - } - - private static getTime() { - if (false && performance.now) { // testing for existance of performance breaks on ipad - return performance.now(); - } else { - return Date.now(); - } - } - - public static logResults() { - var grandTotal = PerfDiagnostics.diagnostics["total"] ? PerfDiagnostics.diagnostics["total"].total : null; - var measurementNames: string[] = Object.keys(PerfDiagnostics.diagnostics); - measurementNames.forEach((measurementName: string) => { - var result = PerfDiagnostics.diagnostics[measurementName].total; - console.log(measurementName); - console.group(); - console.log("Time:", result); - (grandTotal && measurementName !== "total") ? console.log("% :", Math.round(result/grandTotal * 10000) / 100) : null; - console.groupEnd(); - }); - - } - - constructor() { - this.total = 0; - this.numCalls = 0; - this.start = null; - } - - public toggle() { - if (this.start == null) { - this.start = PerfDiagnostics.getTime(); - } else { - this.total += PerfDiagnostics.getTime() - this.start; - this.numCalls++; - this.start = null; - } - } - } - export function toggle(measurementName: string) {return PerfDiagnostics.toggle(measurementName);}; - export function logResults() {return PerfDiagnostics.logResults();}; -} -( window).report = PerfDiagnostics.logResults; diff --git a/test/testReference.ts b/test/testReference.ts index 123d75361a..0ebfaa203a 100644 --- a/test/testReference.ts +++ b/test/testReference.ts @@ -7,7 +7,6 @@ /// /// -/// /// /// diff --git a/test/tests.js b/test/tests.js index 6bd7de916e..47a52de082 100644 --- a/test/tests.js +++ b/test/tests.js @@ -111,72 +111,6 @@ before(function () { window.Pixel_CloseTo_Requirement = window.PHANTOMJS ? 2 : 0.5; }); -var PerfDiagnostics; -(function (_PerfDiagnostics) { - var PerfDiagnostics = (function () { - function PerfDiagnostics() { - this.total = 0; - this.numCalls = 0; - this.start = null; - } - PerfDiagnostics.toggle = function (measurementName) { - var diagnostic; - ; - if (PerfDiagnostics.diagnostics[measurementName] != null) { - diagnostic = PerfDiagnostics.diagnostics[measurementName]; - } else { - diagnostic = new PerfDiagnostics(); - PerfDiagnostics.diagnostics[measurementName] = diagnostic; - } - diagnostic.toggle(); - }; - - PerfDiagnostics.getTime = function () { - if (false && performance.now) { - return performance.now(); - } else { - return Date.now(); - } - }; - - PerfDiagnostics.logResults = function () { - var grandTotal = PerfDiagnostics.diagnostics["total"] ? PerfDiagnostics.diagnostics["total"].total : null; - var measurementNames = Object.keys(PerfDiagnostics.diagnostics); - measurementNames.forEach(function (measurementName) { - var result = PerfDiagnostics.diagnostics[measurementName].total; - console.log(measurementName); - console.group(); - console.log("Time:", result); - (grandTotal && measurementName !== "total") ? console.log("% :", Math.round(result / grandTotal * 10000) / 100) : null; - console.groupEnd(); - }); - }; - - PerfDiagnostics.prototype.toggle = function () { - if (this.start == null) { - this.start = PerfDiagnostics.getTime(); - } else { - this.total += PerfDiagnostics.getTime() - this.start; - this.numCalls++; - this.start = null; - } - }; - PerfDiagnostics.diagnostics = {}; - return PerfDiagnostics; - })(); - function toggle(measurementName) { - return PerfDiagnostics.toggle(measurementName); - } - _PerfDiagnostics.toggle = toggle; - ; - function logResults() { - return PerfDiagnostics.logResults(); - } - _PerfDiagnostics.logResults = logResults; - ; -})(PerfDiagnostics || (PerfDiagnostics = {})); -window.report = PerfDiagnostics.logResults; - /// var assert = chai.assert; diff --git a/tslint.json b/tslint.json index 9b244d402c..1795198cfe 100644 --- a/tslint.json +++ b/tslint.json @@ -12,6 +12,15 @@ "no-arg": true, "no-bitwise": true, "no-construct": true, + "no-console": [true, + "log", + "debug", + "info", + "time", + "timeEnd", + "trace", + "warn" + ], "no-duplicate-key": true, "no-duplicate-variable": true, "no-empty": true,