From 87d557cff6118bf2f4233b271401593d95a8ccb8 Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Tue, 22 Jul 2014 11:29:17 -0700 Subject: [PATCH 1/2] fix _getParsedStyle() and Label._requestedSpace --- plottable.js | 13 +++++++++++-- src/components/legend.ts | 8 ++++++++ src/utils/domUtils.ts | 7 ++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/plottable.js b/plottable.js index 86c80401f0..d86fbd5adf 100644 --- a/plottable.js +++ b/plottable.js @@ -1017,10 +1017,11 @@ var Plottable; function _getParsedStyleValue(style, prop) { var value = style.getPropertyValue(prop); - if (value == null) { + var parsedValue = parseFloat(value); + if (parsedValue != parsedValue) { return 0; } - return parseFloat(value); + return parsedValue; } // @@ -5403,6 +5404,14 @@ var Plottable; Legend.prototype._requestedSpace = function (offeredWidth, offeredY) { var textHeight = this.measureTextHeight(); + if (textHeight === 0) { + return { + width: 0, + height: 0, + wantsWidth: false, + wantsHeight: false + }; + } var totalNumRows = this.colorScale.domain().length; var rowsICanFit = Math.min(totalNumRows, Math.floor(offeredY / textHeight)); diff --git a/src/components/legend.ts b/src/components/legend.ts index 430c685c83..a70a00629c 100644 --- a/src/components/legend.ts +++ b/src/components/legend.ts @@ -140,6 +140,14 @@ export module Component { public _requestedSpace(offeredWidth: number, offeredY: number): ISpaceRequest { var textHeight = this.measureTextHeight(); + if (textHeight === 0) { + return { + width: 0, + height: 0, + wantsWidth: false, + wantsHeight: false + }; + } var totalNumRows = this.colorScale.domain().length; var rowsICanFit = Math.min(totalNumRows, Math.floor(offeredY / textHeight)); diff --git a/src/utils/domUtils.ts b/src/utils/domUtils.ts index 24fdc90e73..58a97e6964 100644 --- a/src/utils/domUtils.ts +++ b/src/utils/domUtils.ts @@ -22,10 +22,11 @@ export module Util { function _getParsedStyleValue(style: CSSStyleDeclaration, prop: string): number { var value: any = style.getPropertyValue(prop); - if (value == null){ - return 0; + var parsedValue = parseFloat(value); + if (parsedValue != parsedValue) { + return 0; } - return parseFloat(value); + return parsedValue; } // From 08c1079d00e6301486c32a6ec7a0dddf5a827f1b Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Tue, 22 Jul 2014 11:34:44 -0700 Subject: [PATCH 2/2] fixed lint bug, != instead of !== --- plottable.js | 2 +- src/utils/domUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plottable.js b/plottable.js index d86fbd5adf..2643c7217a 100644 --- a/plottable.js +++ b/plottable.js @@ -1018,7 +1018,7 @@ var Plottable; function _getParsedStyleValue(style, prop) { var value = style.getPropertyValue(prop); var parsedValue = parseFloat(value); - if (parsedValue != parsedValue) { + if (parsedValue !== parsedValue) { return 0; } return parsedValue; diff --git a/src/utils/domUtils.ts b/src/utils/domUtils.ts index 58a97e6964..151bb90957 100644 --- a/src/utils/domUtils.ts +++ b/src/utils/domUtils.ts @@ -23,7 +23,7 @@ export module Util { function _getParsedStyleValue(style: CSSStyleDeclaration, prop: string): number { var value: any = style.getPropertyValue(prop); var parsedValue = parseFloat(value); - if (parsedValue != parsedValue) { + if (parsedValue !== parsedValue) { return 0; } return parsedValue;