Skip to content

Commit

Permalink
Merge pull request #724 from palantir/warn
Browse files Browse the repository at this point in the history
Switch from console.log to Utils.Methods.warn
  • Loading branch information
teamdandelion committed Jul 18, 2014
2 parents 2f12fa8 + bef33e7 commit b72ea40
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 135 deletions.
5 changes: 5 additions & 0 deletions plottable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
23 changes: 20 additions & 3 deletions plottable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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" };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/scales/quantitiveScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/textUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down
18 changes: 17 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((<any> window).console != null) {
if ((<any> window).console.warn != null) {
console.warn(warning);
} else if ((<any> window).console.log != null) {
console.log(warning);
}
}
/* tslint:enable:no-console */
}

/**
* Takes two arrays of numbers and adds them together
*
Expand Down Expand Up @@ -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 ===.
*/
Expand Down
61 changes: 0 additions & 61 deletions test/perfdiagnostics.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/testReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
///<reference path="../build/plottable.d.ts" />

///<reference path="globalInitialization.ts" />
///<reference path="perfdiagnostics.ts" />

///<reference path="components/baseAxisTests.ts" />
///<reference path="components/numericAxisTests.ts" />
Expand Down
66 changes: 0 additions & 66 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

///<reference path="../testReference.ts" />
var assert = chai.assert;

Expand Down
9 changes: 9 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b72ea40

Please sign in to comment.