Skip to content

Commit

Permalink
Fix previous commit, which adds warn instead of console.log.
Browse files Browse the repository at this point in the history
Now warn uses console.warn if it is available, console.log if it is not,
and does nothing otherwise.

Note that perfDiagnostics.ts was removed in the previous commit.
  • Loading branch information
teamdandelion committed Jul 18, 2014
1 parent d2e63b3 commit bef33e7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 78 deletions.
2 changes: 1 addition & 1 deletion plottable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare module Plottable {
function inRange(x: number, a: number, b: number): boolean;
/** Print a warning message to the console, if it is available.
*
* @params {any} The warnings to print
* @param {string} The warnings to print
*/
function warn(warning: string): void;
/**
Expand Down
16 changes: 10 additions & 6 deletions plottable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ var Plottable;

/** Print a warning message to the console, if it is available.
*
* @params {any} The warnings to print
* @param {string} The warnings to print
*/
function warn(warning) {
/* tslint:disable:no-console */
if (window.console) {
console.log(warning);
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 */
}
Expand Down Expand Up @@ -643,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 @@ -2556,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 @@ -3575,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])) {
Utils.Methods.warn("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])) {
Utils.Methods.warn("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) {
Utils.Methods.warn("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
6 changes: 5 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export module Util {
export function warn(warning: string) {
/* tslint:disable:no-console */
if ((<any> window).console != null) {
console.log(warning);
if ((<any> window).console.warn != null) {
console.warn(warning);
} else if ((<any> window).console.log != null) {
console.log(warning);
}
}
/* tslint:enable:no-console */
}
Expand Down
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

0 comments on commit bef33e7

Please sign in to comment.