Skip to content

Commit

Permalink
Merge pull request #2836 from palantir/r-1.14.0
Browse files Browse the repository at this point in the history
Release version 1.14.0
  • Loading branch information
bluong committed Oct 2, 2015
2 parents ff431f5 + 9c2c4b3 commit d8d7325
Show file tree
Hide file tree
Showing 24 changed files with 897 additions and 391 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plottable",
"description": "A modular charting library built on D3",
"version": "1.13.0",
"version": "1.14.0",
"main": ["plottable.js", "plottable.css"],
"typescript": {
"definition": "plottable.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plottable.js",
"description": "A modular charting library built on D3",
"version": "1.13.0",
"version": "1.14.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
19 changes: 15 additions & 4 deletions plottable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3356,10 +3356,7 @@ declare module Plottable {
*/
protected _getBarPixelWidth(): number;
entities(datasets?: Dataset[]): PlotEntity[];
protected _pixelPoint(datum: any, index: number, dataset: Dataset): {
x: any;
y: any;
};
protected _pixelPoint(datum: any, index: number, dataset: Dataset): Point;
protected _uninstallScaleForKey(scale: Scale<any, number>, key: string): void;
protected _getDataToDraw(): Utils.Map<Dataset, any[]>;
}
Expand Down Expand Up @@ -3421,6 +3418,18 @@ declare module Plottable {
interpolator(interpolator: "cardinal-open"): Line<X>;
interpolator(interpolator: "cardinal-closed"): Line<X>;
interpolator(interpolator: "monotone"): Line<X>;
/**
* Gets if croppedRendering is enabled
*
* When croppedRendering is enabled, lines that will not be visible in the viewport will not be drawn.
*/
croppedRenderingEnabled(): boolean;
/**
* Sets if croppedRendering is enabled
*
* @returns {Plots.Line} The calling Plots.Line
*/
croppedRenderingEnabled(croppedRendering: boolean): Plots.Line<X>;
protected _createDrawer(dataset: Dataset): Drawer;
protected _extentsForProperty(property: string): any[];
protected _getResetYFunction(): (d: any, i: number, dataset: Dataset) => number;
Expand Down Expand Up @@ -4020,6 +4029,7 @@ declare module Plottable {
* @return {Dispatchers.Mouse} The calling Mouse Dispatcher.
*/
offDblClick(callback: MouseCallback): Dispatchers.Mouse;
eventInsideSVG(event: MouseEvent): boolean;
/**
* Returns the last computed mouse position in <svg> coordinate space.
*
Expand Down Expand Up @@ -4108,6 +4118,7 @@ declare module Plottable {
* @return {Dispatchers.Touch} The calling Touch Dispatcher.
*/
offTouchCancel(callback: TouchCallback): Dispatchers.Touch;
eventInsideSVG(event: TouchEvent): boolean;
}
}
}
Expand Down
132 changes: 94 additions & 38 deletions plottable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Plottable 1.13.0 (https://github.com/palantir/plottable)
Plottable 1.14.0 (https://github.com/palantir/plottable)
Copyright 2014-2015 Palantir Technologies
Licensed under MIT (https://github.com/palantir/plottable/blob/master/LICENSE)
*/
Expand Down Expand Up @@ -908,7 +908,7 @@ var Plottable;
///<reference path="../reference.ts" />
var Plottable;
(function (Plottable) {
Plottable.version = "1.13.0";
Plottable.version = "1.14.0";
})(Plottable || (Plottable = {}));

///<reference path="../reference.ts" />
Expand Down Expand Up @@ -4443,13 +4443,15 @@ var Plottable;
tickMarks.attr(attr);
if (this.orientation() === "bottom") {
attr["y1"] = offset;
attr["y2"] = offset + this._tierHeights[index];
attr["y2"] = offset + (this._tierLabelPositions[index] === "center" ? this.endTickLength() : this._tierHeights[index]);
}
else {
attr["y1"] = this.height() - offset;
attr["y2"] = this.height() - (offset + this._tierHeights[index]);
attr["y2"] = this.height() - (offset + (this._tierLabelPositions[index] === "center" ?
this.endTickLength() : this._tierHeights[index]));
}
d3.select(tickMarks[0][0]).attr(attr);
d3.select(tickMarks[0][tickMarks.size() - 1]).attr(attr);
// Add end-tick classes to first and last tick for CSS customization purposes
d3.select(tickMarks[0][0]).classed(Plottable.Axis.END_TICK_MARK_CLASS, true);
d3.select(tickMarks[0][tickMarks.size() - 1]).classed(Plottable.Axis.END_TICK_MARK_CLASS, true);
Expand Down Expand Up @@ -8912,29 +8914,11 @@ var Plottable;
this._barPixelWidth = this._getBarPixelWidth();
};
Bar.prototype.entities = function (datasets) {
var _this = this;
if (datasets === void 0) { datasets = this.datasets(); }
if (!this._projectorsReady()) {
return [];
}
var entities = _super.prototype.entities.call(this, datasets);
var scaledBaseline = (this._isVertical ? this.y().scale : this.x().scale).scale(this.baselineValue());
entities.forEach(function (entity) {
var bar = entity.selection;
// Using floored pixel values to account for pixel accuracy inconsistencies across browsers
if (_this._isVertical && Math.floor(+bar.attr("y")) >= Math.floor(scaledBaseline)) {
entity.position.y += +bar.attr("height");
}
else if (!_this._isVertical && Math.floor(+bar.attr("x")) < Math.floor(scaledBaseline)) {
entity.position.x -= +bar.attr("width");
}
if (_this._isVertical) {
entity.position.x = +bar.attr("x") + +bar.attr("width") / 2;
}
else {
entity.position.y = +bar.attr("y") + +bar.attr("height") / 2;
}
});
return entities;
};
Bar.prototype._pixelPoint = function (datum, index, dataset) {
Expand All @@ -8943,8 +8927,18 @@ var Plottable;
var rectY = attrToProjector["y"](datum, index, dataset);
var rectWidth = attrToProjector["width"](datum, index, dataset);
var rectHeight = attrToProjector["height"](datum, index, dataset);
var x = this._isVertical ? rectX + rectWidth / 2 : rectX + rectWidth;
var y = this._isVertical ? rectY : rectY + rectHeight / 2;
var x;
var y;
var originalPosition = (this._isVertical ? Plottable.Plot._scaledAccessor(this.y()) : Plottable.Plot._scaledAccessor(this.x()))(datum, index, dataset);
var scaledBaseline = (this._isVertical ? this.y().scale : this.x().scale).scale(this.baselineValue());
if (this._isVertical) {
x = rectX + rectWidth / 2;
y = originalPosition <= scaledBaseline ? rectY : rectY + rectHeight;
}
else {
x = originalPosition >= scaledBaseline ? rectX + rectWidth : rectX;
y = rectY + rectHeight / 2;
}
return { x: x, y: y };
};
Bar.prototype._uninstallScaleForKey = function (scale, key) {
Expand Down Expand Up @@ -8998,6 +8992,7 @@ var Plottable;
_super.call(this);
this._interpolator = "linear";
this._autorangeSmooth = false;
this._croppedRenderingEnabled = true;
this.addClass("line-plot");
var animator = new Plottable.Animators.Easing();
animator.stepDuration(Plottable.Plot._ANIMATION_MAX_DURATION);
Expand Down Expand Up @@ -9064,6 +9059,14 @@ var Plottable;
this.render();
return this;
};
Line.prototype.croppedRenderingEnabled = function (croppedRendering) {
if (croppedRendering == null) {
return this._croppedRenderingEnabled;
}
this._croppedRenderingEnabled = croppedRendering;
this.render();
return this;
};
Line.prototype._createDrawer = function (dataset) {
return new Plottable.Drawers.Line(dataset);
};
Expand Down Expand Up @@ -9249,10 +9252,50 @@ var Plottable;
};
};
Line.prototype._getDataToDraw = function () {
var _this = this;
var dataToDraw = new Plottable.Utils.Map();
this.datasets().forEach(function (dataset) { return dataToDraw.set(dataset, [dataset.data()]); });
this.datasets().forEach(function (dataset) {
var data = dataset.data();
if (!_this._croppedRenderingEnabled) {
dataToDraw.set(dataset, [data]);
return;
}
var filteredDataIndices = data.map(function (d, i) { return i; });
filteredDataIndices = _this._filterCroppedRendering(dataset, filteredDataIndices);
dataToDraw.set(dataset, [filteredDataIndices.map(function (d, i) { return data[d]; })]);
});
return dataToDraw;
};
Line.prototype._filterCroppedRendering = function (dataset, indices) {
var _this = this;
var xProjector = Plottable.Plot._scaledAccessor(this.x());
var yProjector = Plottable.Plot._scaledAccessor(this.y());
var data = dataset.data();
var filteredDataIndices = [];
var pointInViewport = function (x, y) {
return Plottable.Utils.Math.inRange(x, 0, _this.width()) &&
Plottable.Utils.Math.inRange(y, 0, _this.height());
};
for (var i = 0; i < indices.length; i++) {
var currXPoint = xProjector(data[indices[i]], indices[i], dataset);
var currYPoint = yProjector(data[indices[i]], indices[i], dataset);
var shouldShow = pointInViewport(currXPoint, currYPoint);
if (!shouldShow && indices[i - 1] != null && data[indices[i - 1]] != null) {
var prevXPoint = xProjector(data[indices[i - 1]], indices[i - 1], dataset);
var prevYPoint = yProjector(data[indices[i - 1]], indices[i - 1], dataset);
shouldShow = shouldShow || pointInViewport(prevXPoint, prevYPoint);
}
if (!shouldShow && indices[i + 1] != null && data[indices[i + 1]] != null) {
var nextXPoint = xProjector(data[indices[i + 1]], indices[i + 1], dataset);
var nextYPoint = yProjector(data[indices[i + 1]], indices[i + 1], dataset);
shouldShow = shouldShow || pointInViewport(nextXPoint, nextYPoint);
}
if (shouldShow) {
filteredDataIndices.push(indices[i]);
}
}
return filteredDataIndices;
};
return Line;
})(Plottable.XYPlot);
Plots.Line = Line;
Expand Down Expand Up @@ -10678,14 +10721,17 @@ var Plottable;
if (scope !== "page" && scope !== "element") {
throw new Error("Invalid scope '" + scope + "', must be 'element' or 'page'");
}
if (scope === "page" || this._translator.insideSVG(event)) {
if (scope === "page" || this.eventInsideSVG(event)) {
var newMousePosition = this._translator.computePosition(event.clientX, event.clientY);
if (newMousePosition != null) {
this._lastMousePosition = newMousePosition;
callbackSet.callCallbacks(this.lastMousePosition(), event);
}
}
};
Mouse.prototype.eventInsideSVG = function (event) {
return this._translator.insideSVG(event);
};
/**
* Returns the last computed mouse position in <svg> coordinate space.
*
Expand Down Expand Up @@ -10728,7 +10774,7 @@ var Plottable;
this._endCallbacks = new Plottable.Utils.CallbackSet();
this._cancelCallbacks = new Plottable.Utils.CallbackSet();
this._callbacks = [this._moveCallbacks, this._startCallbacks, this._endCallbacks, this._cancelCallbacks];
this._eventToCallback["touchstart"] = function (e) { return _this._measureAndDispatch(e, _this._startCallbacks); };
this._eventToCallback["touchstart"] = function (e) { return _this._measureAndDispatch(e, _this._startCallbacks, "page"); };
this._eventToCallback["touchmove"] = function (e) { return _this._measureAndDispatch(e, _this._moveCallbacks, "page"); };
this._eventToCallback["touchend"] = function (e) { return _this._measureAndDispatch(e, _this._endCallbacks, "page"); };
this._eventToCallback["touchcancel"] = function (e) { return _this._measureAndDispatch(e, _this._cancelCallbacks, "page"); };
Expand Down Expand Up @@ -10838,7 +10884,7 @@ var Plottable;
if (scope !== "page" && scope !== "element") {
throw new Error("Invalid scope '" + scope + "', must be 'element' or 'page'");
}
if (scope === "element" && !this._translator.insideSVG(event)) {
if (scope === "element" && !this.eventInsideSVG(event)) {
return;
}
var touches = event.changedTouches;
Expand All @@ -10858,6 +10904,9 @@ var Plottable;
callbackSet.callCallbacks(touchIdentifiers, touchPositions, event);
}
};
Touch.prototype.eventInsideSVG = function (event) {
return this._translator.insideSVG(event);
};
Touch._DISPATCHER_KEY = "__Plottable_Dispatcher_Touch";
return Touch;
})(Plottable.Dispatcher);
Expand Down Expand Up @@ -11381,12 +11430,12 @@ var Plottable;
function Pointer() {
var _this = this;
_super.apply(this, arguments);
this._overComponent = false;
this._insideComponent = false;
this._pointerEnterCallbacks = new Plottable.Utils.CallbackSet();
this._pointerMoveCallbacks = new Plottable.Utils.CallbackSet();
this._pointerExitCallbacks = new Plottable.Utils.CallbackSet();
this._mouseMoveCallback = function (p) { return _this._handlePointerEvent(p); };
this._touchStartCallback = function (ids, idToPoint) { return _this._handlePointerEvent(idToPoint[ids[0]]); };
this._mouseMoveCallback = function (p, e) { return _this._handleMouseEvent(p, e); };
this._touchStartCallback = function (ids, idToPoint, e) { return _this._handleTouchEvent(idToPoint[ids[0]], e); };
}
Pointer.prototype._anchor = function (component) {
_super.prototype._anchor.call(this, component);
Expand All @@ -11402,20 +11451,27 @@ var Plottable;
this._touchDispatcher.offTouchStart(this._touchStartCallback);
this._touchDispatcher = null;
};
Pointer.prototype._handlePointerEvent = function (p) {
Pointer.prototype._handleMouseEvent = function (p, e) {
var insideSVG = this._mouseDispatcher.eventInsideSVG(e);
this._handlePointerEvent(p, insideSVG);
};
Pointer.prototype._handleTouchEvent = function (p, e) {
var insideSVG = this._touchDispatcher.eventInsideSVG(e);
this._handlePointerEvent(p, insideSVG);
};
Pointer.prototype._handlePointerEvent = function (p, insideSVG) {
var translatedP = this._translateToComponentSpace(p);
if (this._isInsideComponent(translatedP)) {
var wasOverComponent = this._overComponent;
this._overComponent = true;
if (!wasOverComponent) {
var overComponent = this._isInsideComponent(translatedP);
if (overComponent && insideSVG) {
if (!this._insideComponent) {
this._pointerEnterCallbacks.callCallbacks(translatedP);
}
this._pointerMoveCallbacks.callCallbacks(translatedP);
}
else if (this._overComponent) {
this._overComponent = false;
else if (this._insideComponent) {
this._pointerExitCallbacks.callCallbacks(translatedP);
}
this._insideComponent = overComponent && insideSVG;
};
/**
* Adds a callback to be called when the pointer enters the Component.
Expand Down
14 changes: 7 additions & 7 deletions plottable.min.js

Large diffs are not rendered by default.

Binary file modified plottable.zip
Binary file not shown.
12 changes: 11 additions & 1 deletion quicktests/overlaying/overlaying.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ select, input:not([type=checkbox]) {
}

.sidebar-quicktest{
padding-left: 10px;
padding-left: 10px;
list-style-type: none;
font-size: 13px;
}
Expand All @@ -170,3 +170,13 @@ ol{
padding: 0px;
margin: 0px;
}

.plottable .guide-line-layer.red line.guide-line {
stroke: #F00;
stroke-width: 1px;
}

.plottable .guide-line-layer.green line.guide-line {
stroke: #0F0;
stroke-width: 1px;
}
Loading

0 comments on commit d8d7325

Please sign in to comment.