Skip to content

Commit

Permalink
Remove warning on undefined/null data.
Browse files Browse the repository at this point in the history
It incorrectly issues warnings when the plot is first loaded, due to
the default accessors returning undefinded.
  • Loading branch information
Justin Lan committed Jul 29, 2014
1 parent 9aa03a0 commit 6a81f2a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
81 changes: 39 additions & 42 deletions plottable.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ var Plottable;
if (selection.node().nodeName === "text") {
var originalText = selection.text();
selection.text(s);
bb = Plottable.Util.DOM.getBBox(selection);
bb = Util.DOM.getBBox(selection);
selection.text(originalText);
return { width: bb.width, height: bb.height };
} else {
var t = selection.append("text").text(s);
bb = Plottable.Util.DOM.getBBox(t);
bb = Util.DOM.getBBox(t);
t.remove();
return { width: bb.width, height: bb.height };
}
Expand Down Expand Up @@ -582,7 +582,7 @@ var Plottable;
*/
function CachingCharacterMeasurer(g) {
var _this = this;
this.cache = new Plottable.Util.Cache(getTextMeasure(g), CANONICAL_CHR, Plottable.Util.Methods.objEq);
this.cache = new Util.Cache(getTextMeasure(g), CANONICAL_CHR, Util.Methods.objEq);
this.measure = combineWhitespace(measureByCharacter(wrapWhitespace(function (s) {
return _this.cache.get(s);
})));
Expand Down Expand Up @@ -675,11 +675,11 @@ var Plottable;
var innerG = g.append("g");
var textEl = innerG.append("text");
textEl.text(line);
var bb = Plottable.Util.DOM.getBBox(textEl);
var bb = Util.DOM.getBBox(textEl);
var h = bb.height;
var w = bb.width;
if (w > width || h > height) {
Plottable.Util.Methods.warn("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 All @@ -688,7 +688,7 @@ var Plottable;
var yOff = height * yOffsetFactor[yAlign] + h * (1 - yOffsetFactor[yAlign]);
var ems = -0.4 * (1 - yOffsetFactor[yAlign]);
textEl.attr("text-anchor", anchor).attr("y", ems + "em");
Plottable.Util.DOM.translate(innerG, xOff, yOff);
Util.DOM.translate(innerG, xOff, yOff);
return { width: w, height: h };
}
Text.writeLineHorizontally = writeLineHorizontally;
Expand Down Expand Up @@ -723,7 +723,7 @@ var Plottable;
var blockG = g.append("g");
brokenText.forEach(function (line, i) {
var innerG = blockG.append("g");
Plottable.Util.DOM.translate(innerG, 0, i * h);
Util.DOM.translate(innerG, 0, i * h);
var wh = writeLineHorizontally(line, innerG, width, h, xAlign, yAlign);
if (wh.width > maxWidth) {
maxWidth = wh.width;
Expand All @@ -732,7 +732,7 @@ var Plottable;
var usedSpace = h * brokenText.length;
var freeSpace = height - usedSpace;
var translator = { center: 0.5, top: 0, bottom: 1 };
Plottable.Util.DOM.translate(blockG, 0, freeSpace * translator[yAlign]);
Util.DOM.translate(blockG, 0, freeSpace * translator[yAlign]);
return { width: maxWidth, height: usedSpace };
}
Text.writeTextHorizontally = writeTextHorizontally;
Expand All @@ -746,7 +746,7 @@ var Plottable;
var blockG = g.append("g");
brokenText.forEach(function (line, i) {
var innerG = blockG.append("g");
Plottable.Util.DOM.translate(innerG, i * h, 0);
Util.DOM.translate(innerG, i * h, 0);
var wh = writeLineVertically(line, innerG, h, height, xAlign, yAlign, rotation);
if (wh.height > maxHeight) {
maxHeight = wh.height;
Expand All @@ -755,7 +755,7 @@ var Plottable;
var usedSpace = h * brokenText.length;
var freeSpace = width - usedSpace;
var translator = { center: 0.5, left: 0, right: 1 };
Plottable.Util.DOM.translate(blockG, freeSpace * translator[xAlign], 0);
Util.DOM.translate(blockG, freeSpace * translator[xAlign], 0);

return { width: usedSpace, height: maxHeight };
}
Expand All @@ -773,7 +773,7 @@ var Plottable;
var orientHorizontally = (horizontally != null) ? horizontally : width * 1.1 > height;
var primaryDimension = orientHorizontally ? width : height;
var secondaryDimension = orientHorizontally ? height : width;
var wrappedText = Plottable.Util.WordWrap.breakTextToFitRect(text, primaryDimension, secondaryDimension, tm);
var wrappedText = Util.WordWrap.breakTextToFitRect(text, primaryDimension, secondaryDimension, tm);

if (wrappedText.lines.length === 0) {
return { textFits: wrappedText.textFits, usedWidth: 0, usedHeight: 0 };
Expand Down Expand Up @@ -836,7 +836,7 @@ var Plottable;
lines = lines.splice(0, nLinesThatFit);
if (nLinesThatFit > 0) {
// Overwrite the last line to one that has had a ... appended to the end
lines[nLinesThatFit - 1] = Plottable.Util.Text._addEllipsesToLine(lines[nLinesThatFit - 1], width, measureText);
lines[nLinesThatFit - 1] = Util.Text._addEllipsesToLine(lines[nLinesThatFit - 1], width, measureText);
}
}
return { originalText: text, lines: lines, textFits: textFit };
Expand Down Expand Up @@ -1330,7 +1330,7 @@ var Plottable;
return formattedValue;
};
return Currency;
})(Plottable.Formatter.Fixed);
})(Formatter.Fixed);
Formatter.Currency = Currency;
})(Plottable.Formatter || (Plottable.Formatter = {}));
var Formatter = Plottable.Formatter;
Expand Down Expand Up @@ -1367,7 +1367,7 @@ var Plottable;
return formattedValue;
};
return Percentage;
})(Plottable.Formatter.Fixed);
})(Formatter.Fixed);
Formatter.Percentage = Percentage;
})(Plottable.Formatter || (Plottable.Formatter = {}));
var Formatter = Plottable.Formatter;
Expand Down Expand Up @@ -1689,9 +1689,6 @@ var Plottable;
DataSource.prototype.computeExtent = function (accessor) {
var appliedAccessor = Plottable.Util.Methods.applyAccessor(accessor, this);
var mappedData = this._data.map(appliedAccessor);
if (mappedData.indexOf(null) >= 0 || mappedData.indexOf(undefined) >= 0) {
Plottable.Util.Methods.warn("Data has contains null or undefined elements. This could mean data was not parsed correctly");
}
if (mappedData.length === 0) {
return [];
} else if (typeof (mappedData[0]) === "string") {
Expand Down Expand Up @@ -2185,7 +2182,7 @@ var Plottable;
};
Component.AUTORESIZE_BY_DEFAULT = true;
return Component;
})(Plottable.Abstract.PlottableObject);
})(Abstract.PlottableObject);
Abstract.Component = Component;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -2295,7 +2292,7 @@ var Plottable;
});
};
return ComponentContainer;
})(Plottable.Abstract.Component);
})(Abstract.Component);
Abstract.ComponentContainer = ComponentContainer;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -2904,7 +2901,7 @@ var Plottable;
return this;
};
return Scale;
})(Plottable.Abstract.PlottableObject);
})(Abstract.PlottableObject);
Abstract.Scale = Scale;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -3123,7 +3120,7 @@ var Plottable;
}
};
return Plot;
})(Plottable.Abstract.Component);
})(Abstract.Component);
Abstract.Plot = Plot;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand All @@ -3139,7 +3136,7 @@ var Plottable;
function Immediate() {
}
Immediate.prototype.render = function () {
Plottable.Core.RenderController.flush();
RenderController.flush();
};
return Immediate;
})();
Expand All @@ -3149,7 +3146,7 @@ var Plottable;
function AnimationFrame() {
}
AnimationFrame.prototype.render = function () {
Plottable.Util.DOM.requestAnimationFramePolyfill(Plottable.Core.RenderController.flush);
Plottable.Util.DOM.requestAnimationFramePolyfill(RenderController.flush);
};
return AnimationFrame;
})();
Expand All @@ -3160,7 +3157,7 @@ var Plottable;
this._timeoutMsec = Plottable.Util.DOM.POLYFILL_TIMEOUT_MSEC;
}
Timeout.prototype.render = function () {
setTimeout(Plottable.Core.RenderController.flush, this._timeoutMsec);
setTimeout(RenderController.flush, this._timeoutMsec);
};
return Timeout;
})();
Expand Down Expand Up @@ -3191,7 +3188,7 @@ var Plottable;
var _componentsNeedingRender = {};
var _componentsNeedingComputeLayout = {};
var _animationRequested = false;
RenderController._renderPolicy = new Plottable.Core.RenderController.RenderPolicy.AnimationFrame();
RenderController._renderPolicy = new RenderController.RenderPolicy.AnimationFrame();

function setRenderPolicy(policy) {
RenderController._renderPolicy = policy;
Expand Down Expand Up @@ -3259,7 +3256,7 @@ var Plottable;
}

// Reset resize flag regardless of queue'd components
Plottable.Core.ResizeBroadcaster.clearResizing();
Core.ResizeBroadcaster.clearResizing();
}
RenderController.flush = flush;
})(Core.RenderController || (Core.RenderController = {}));
Expand Down Expand Up @@ -3288,7 +3285,7 @@ var Plottable;

function _lazyInitialize() {
if (broadcaster === undefined) {
broadcaster = new Plottable.Core.Broadcaster(ResizeBroadcaster);
broadcaster = new Core.Broadcaster(ResizeBroadcaster);
window.addEventListener("resize", _onResize);
}
}
Expand Down Expand Up @@ -3715,7 +3712,7 @@ var Plottable;
return [0, 1];
};
return QuantitativeScale;
})(Plottable.Abstract.Scale);
})(Abstract.Scale);
Abstract.QuantitativeScale = QuantitativeScale;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -4790,7 +4787,7 @@ var Plottable;
return (Math.floor(boundingBox.left) <= Math.ceil(tickBox.left) && Math.floor(boundingBox.top) <= Math.ceil(tickBox.top) && Math.floor(tickBox.right) <= Math.ceil(boundingBox.left + _this.availableWidth) && Math.floor(tickBox.bottom) <= Math.ceil(boundingBox.top + _this.availableHeight));
};

var tickLabels = this._tickLabelContainer.selectAll("." + Plottable.Abstract.Axis.TICK_LABEL_CLASS);
var tickLabels = this._tickLabelContainer.selectAll("." + Abstract.Axis.TICK_LABEL_CLASS);
if (tickLabels[0].length === 0) {
return;
}
Expand All @@ -4805,7 +4802,7 @@ var Plottable;
};

Axis.prototype._hideOverlappingTickLabels = function () {
var visibleTickLabels = this._tickLabelContainer.selectAll("." + Plottable.Abstract.Axis.TICK_LABEL_CLASS).filter(function (d, i) {
var visibleTickLabels = this._tickLabelContainer.selectAll("." + Abstract.Axis.TICK_LABEL_CLASS).filter(function (d, i) {
return d3.select(this).style("visibility") === "visible";
});
var lastLabelClientRect;
Expand All @@ -4824,7 +4821,7 @@ var Plottable;
Axis.TICK_MARK_CLASS = "tick-mark";
Axis.TICK_LABEL_CLASS = "tick-label";
return Axis;
})(Plottable.Abstract.Component);
})(Abstract.Component);
Abstract.Axis = Axis;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -6065,7 +6062,7 @@ var Plottable;
};

XYPlot.prototype._updateXDomainer = function () {
if (this.xScale instanceof Plottable.Abstract.QuantitativeScale) {
if (this.xScale instanceof Abstract.QuantitativeScale) {
var scale = this.xScale;
if (!scale._userSetDomainer) {
scale.domainer().pad().nice();
Expand All @@ -6075,7 +6072,7 @@ var Plottable;
};

XYPlot.prototype._updateYDomainer = function () {
if (this.yScale instanceof Plottable.Abstract.QuantitativeScale) {
if (this.yScale instanceof Abstract.QuantitativeScale) {
var scale = this.yScale;
if (!scale._userSetDomainer) {
scale.domainer().pad().nice();
Expand All @@ -6084,7 +6081,7 @@ var Plottable;
return this;
};
return XYPlot;
})(Plottable.Abstract.Plot);
})(Abstract.Plot);
Abstract.XYPlot = XYPlot;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -6406,7 +6403,7 @@ var Plottable;
};

BarPlot.prototype._updateDomainer = function (scale) {
if (scale instanceof Plottable.Abstract.QuantitativeScale) {
if (scale instanceof Abstract.QuantitativeScale) {
var qscale = scale;
if (!qscale._userSetDomainer) {
if (this._baselineValue != null) {
Expand Down Expand Up @@ -6473,7 +6470,7 @@ var Plottable;

BarPlot._BarAlignmentToFactor = {};
return BarPlot;
})(Plottable.Abstract.XYPlot);
})(Abstract.XYPlot);
Abstract.BarPlot = BarPlot;
})(Plottable.Abstract || (Plottable.Abstract = {}));
var Abstract = Plottable.Abstract;
Expand Down Expand Up @@ -6751,7 +6748,7 @@ var Plottable;
this._applyAnimatedAttributes(this.areaPath, "area", attrToProjector);
};
return Area;
})(Plottable.Plot.Line);
})(Plot.Line);
Plot.Area = Area;
})(Plottable.Plot || (Plottable.Plot = {}));
var Plot = Plottable.Plot;
Expand Down Expand Up @@ -6857,7 +6854,7 @@ var Plottable;
}).attr(attrToProjector);
};
return IterativeDelay;
})(Plottable.Animator.Default);
})(Animator.Default);
Animator.IterativeDelay = IterativeDelay;
})(Plottable.Animator || (Plottable.Animator = {}));
var Animator = Plottable.Animator;
Expand Down Expand Up @@ -7361,7 +7358,7 @@ var Plottable;
};
DragBox.CLASS_DRAG_BOX = "drag-box";
return DragBox;
})(Plottable.Interaction.Drag);
})(Interaction.Drag);
Interaction.DragBox = DragBox;
})(Plottable.Interaction || (Plottable.Interaction = {}));
var Interaction = Plottable.Interaction;
Expand Down Expand Up @@ -7402,7 +7399,7 @@ var Plottable;
return this;
};
return XDragBox;
})(Plottable.Interaction.DragBox);
})(Interaction.DragBox);
Interaction.XDragBox = XDragBox;
})(Plottable.Interaction || (Plottable.Interaction = {}));
var Interaction = Plottable.Interaction;
Expand Down Expand Up @@ -7440,7 +7437,7 @@ var Plottable;
this.callbackToCall(pixelArea);
};
return XYDragBox;
})(Plottable.Interaction.DragBox);
})(Interaction.DragBox);
Interaction.XYDragBox = XYDragBox;
})(Plottable.Interaction || (Plottable.Interaction = {}));
var Interaction = Plottable.Interaction;
Expand Down Expand Up @@ -7481,7 +7478,7 @@ var Plottable;
return this;
};
return YDragBox;
})(Plottable.Interaction.DragBox);
})(Interaction.DragBox);
Interaction.YDragBox = YDragBox;
})(Plottable.Interaction || (Plottable.Interaction = {}));
var Interaction = Plottable.Interaction;
Expand Down
3 changes: 0 additions & 3 deletions src/core/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ module Plottable {
private computeExtent(accessor: IAccessor): any[] {
var appliedAccessor = Util.Methods.applyAccessor(accessor, this);
var mappedData = this._data.map(appliedAccessor);
if (mappedData.indexOf(null) >= 0 || mappedData.indexOf(undefined) >= 0) {
Util.Methods.warn("Data has contains null or undefined elements. This could mean data was not parsed correctly");
}
if (mappedData.length === 0){
return [];
} else if (typeof(mappedData[0]) === "string") {
Expand Down

0 comments on commit 6a81f2a

Please sign in to comment.