From 23d04090ec96a7619131dfe0a317eeb1222fad86 Mon Sep 17 00:00:00 2001 From: Daniel Mane Date: Mon, 17 Mar 2014 18:00:54 -0700 Subject: [PATCH] Update plottable.js and plottable.d.ts --- plottable.d.ts | 42 ---------------- plottable.js | 130 ++++++++++++++++++++++++------------------------- 2 files changed, 65 insertions(+), 107 deletions(-) diff --git a/plottable.d.ts b/plottable.d.ts index a8f6e8aa84..3aa42e794f 100644 --- a/plottable.d.ts +++ b/plottable.d.ts @@ -91,7 +91,6 @@ declare module Plottable { * @param {D3.Selection} element A D3 selection consisting of the element to anchor to. * @returns {Component} The calling component. */ - public _anchor(element: D3.Selection): Component; /** * Computes the size, position, and alignment from the specified values. * If no parameters are supplied and the component is a root node, @@ -103,13 +102,11 @@ declare module Plottable { * @param {number} availableHeight * @returns {Component} The calling Component. */ - public _computeLayout(xOrigin?: number, yOrigin?: number, availableWidth?: number, availableHeight?: number): Component; /** * Renders the component. * * @returns {Component} The calling Component. */ - public _render(): Component; public renderTo(element: D3.Selection): Component; /** * Sets the x alignment of the Component. @@ -341,7 +338,6 @@ declare module Plottable { * @param {Component} componentToListenTo The component to listen for interactions on. */ constructor(componentToListenTo: Component); - public _anchor(hitBox: D3.Selection): void; /** * Registers the Interaction on the Component it's listening to. * This needs to be called to activate the interaction. @@ -364,7 +360,6 @@ declare module Plottable { * @param {QuantitiveScale} yScale The Y scale to update on panning/zooming. */ constructor(componentToListenTo: Component, xScale: QuantitiveScale, yScale: QuantitiveScale); - public _anchor(hitBox: D3.Selection): void; } class AreaInteraction extends Interaction { /** @@ -386,7 +381,6 @@ declare module Plottable { * @returns {AreaInteraction} The calling AreaInteraction. */ public clearBox(): AreaInteraction; - public _anchor(hitBox: D3.Selection): AreaInteraction; } class ZoomCallbackGenerator { /** @@ -416,12 +410,10 @@ declare module Plottable { } class MousemoveInteraction extends Interaction { constructor(componentToListenTo: Component); - public _anchor(hitBox: D3.Selection): void; public mousemove(x: number, y: number): void; } class CrosshairsInteraction extends MousemoveInteraction { constructor(renderer: XYRenderer); - public _anchor(hitBox: D3.Selection): void; public mousemove(x: number, y: number): void; } } @@ -435,7 +427,6 @@ declare module Plottable { * @param {string} [orientation] The orientation of the Label (horizontal/vertical-left/vertical-right). */ constructor(text?: string, orientation?: string); - public _anchor(element: D3.Selection): Label; /** * Sets the text on the Label. * @@ -443,7 +434,6 @@ declare module Plottable { * @returns {Label} The calling Label. */ public setText(text: string): Label; - public _computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): Label; } class TitleLabel extends Label { constructor(text?: string, orientation?: string); @@ -473,9 +463,7 @@ declare module Plottable { public dataset(dataset: IDataset): Renderer; public metadata(metadata: IMetadata): Renderer; public data(data: any[]): Renderer; - public _render(): Renderer; public colorAccessor(a: IAccessor): Renderer; - public _anchor(element: D3.Selection): Renderer; } class XYRenderer extends Renderer { public dataSelection: D3.UpdateSelection; @@ -494,7 +482,6 @@ declare module Plottable { * @param {IAccessor} [yAccessor] A function for extracting y values from the data. */ constructor(dataset: IDataset, xScale: QuantitiveScale, yScale: QuantitiveScale, xAccessor?: IAccessor, yAccessor?: IAccessor); - public _computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): XYRenderer; /** * Converts a SelectionArea with pixel ranges to one with data ranges. * @@ -529,7 +516,6 @@ declare module Plottable { * @param {IAccessor} [yAccessor] A function for extracting y values from the data. */ constructor(dataset: IDataset, xScale: QuantitiveScale, yScale: QuantitiveScale, xAccessor?: IAccessor, yAccessor?: IAccessor); - public _anchor(element: D3.Selection): LineRenderer; } class CircleRenderer extends XYRenderer { public size: number; @@ -581,9 +567,6 @@ declare module Plottable { * @param {Component} component The Component to be added. */ public addComponent(row: number, col: number, component: Component): Table; - public _anchor(element: D3.Selection): Table; - public _computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): Table; - public _render(): Table; /** * Sets the row and column padding on the Table. * @@ -648,7 +631,6 @@ declare module Plottable { public scale(scale: ColorScale): Legend; public rowMinimum(): number; public rowMinimum(newVal: number): Legend; - public _render(): Legend; } } declare module Plottable { @@ -665,8 +647,6 @@ declare module Plottable { * @param {any} [formatter] a D3 formatter */ constructor(axisScale: Scale, orientation: string, formatter?: any); - public _anchor(element: D3.Selection): Axis; - public _render(): Axis; public scale(): Scale; public scale(newScale: Scale): Axis; /** @@ -706,7 +686,6 @@ declare module Plottable { * @param {any} [formatter] a D3 formatter */ constructor(scale: Scale, orientation: string, formatter?: any); - public _anchor(element: D3.Selection): XAxis; /** * Sets or gets the tick label position relative to the tick marks. * @@ -715,7 +694,6 @@ declare module Plottable { */ public tickLabelPosition(): string; public tickLabelPosition(position: string): XAxis; - public _render(): XAxis; } class YAxis extends Axis { /** @@ -727,7 +705,6 @@ declare module Plottable { * @param {any} [formatter] a D3 formatter */ constructor(scale: Scale, orientation: string, formatter?: any); - public _anchor(element: D3.Selection): YAxis; /** * Sets or gets the tick label position relative to the tick marks. * @@ -736,7 +713,6 @@ declare module Plottable { */ public tickLabelPosition(): string; public tickLabelPosition(position: string): YAxis; - public _render(): YAxis; } } declare module Plottable { @@ -748,23 +724,7 @@ declare module Plottable { * @param {Component[]} [components] The Components in the ComponentGroup. */ constructor(components?: Component[]); -<<<<<<< HEAD - /** - * Adds a Component to the ComponentGroup. - * - * @param {Component} c The Component to add. - * @returns {ComponentGroup} The calling ComponentGroup. - */ - public addComponent(c: Component): ComponentGroup; - public _anchor(element: D3.Selection): ComponentGroup; - public _computeLayout(xOrigin?: number, yOrigin?: number, availableWidth?: number, availableHeight?: number): ComponentGroup; - public _render(): ComponentGroup; -======= public merge(c: Component): ComponentGroup; - public anchor(element: D3.Selection): ComponentGroup; - public computeLayout(xOrigin?: number, yOrigin?: number, availableWidth?: number, availableHeight?: number): ComponentGroup; - public render(): ComponentGroup; ->>>>>>> master public isFixedWidth(): boolean; public isFixedHeight(): boolean; } @@ -779,8 +739,6 @@ declare module Plottable { * @param {QuantitiveScale} yScale The scale to base the y gridlines on. Pass null if no gridlines are desired. */ constructor(xScale: QuantitiveScale, yScale: QuantitiveScale); - public anchor(element: D3.Selection): Gridlines; - public render(): Gridlines; } } declare module Plottable { diff --git a/plottable.js b/plottable.js index 93e883e439..a92baf9624 100644 --- a/plottable.js +++ b/plottable.js @@ -133,7 +133,7 @@ var Plottable; * @param {D3.Selection} element A D3 selection consisting of the element to anchor to. * @returns {Component} The calling component. */ - Component.prototype.anchor = function (element) { + Component.prototype._anchor = function (element) { var _this = this; if (element.node().childNodes.length > 0) { throw new Error("Can't anchor to a non-empty element"); @@ -183,7 +183,7 @@ var Plottable; * @param {number} availableHeight * @returns {Component} The calling Component. */ - Component.prototype.computeLayout = function (xOrigin, yOrigin, availableWidth, availableHeight) { + Component.prototype._computeLayout = function (xOrigin, yOrigin, availableWidth, availableHeight) { var _this = this; if (xOrigin == null || yOrigin == null || availableWidth == null || availableHeight == null) { if (this.element == null) { @@ -195,7 +195,7 @@ var Plottable; availableWidth = parseFloat(this.rootSVG.attr("width")); availableHeight = parseFloat(this.rootSVG.attr("height")); } else { - throw new Error("null arguments cannot be passed to computeLayout() on a non-root node"); + throw new Error("null arguments cannot be passed to _computeLayout() on a non-root node"); } } this.xOrigin = xOrigin; @@ -232,16 +232,16 @@ var Plottable; * * @returns {Component} The calling Component. */ - Component.prototype.render = function () { + Component.prototype._render = function () { return this; }; Component.prototype.renderTo = function (element) { - // When called on top-level-component, a shortcut for component.anchor(svg).computeLayout().render() + // When called on top-level-component, a shortcut for component._anchor(svg)._computeLayout()._render() if (this.element == null) { - this.anchor(element); + this._anchor(element); } - this.computeLayout().render(); + this._computeLayout()._render(); return this; }; @@ -345,7 +345,7 @@ var Plottable; this.hitBox = this.addBox("hit-box"); this.hitBox.style("fill", "#ffffff").style("opacity", 0); // We need to set these so Chrome will register events } - interaction.anchor(this.hitBox); + interaction._anchor(this.hitBox); } else { this.interactionsToRegister.push(interaction); } @@ -691,7 +691,7 @@ var Plottable; function Interaction(componentToListenTo) { this.componentToListenTo = componentToListenTo; } - Interaction.prototype.anchor = function (hitBox) { + Interaction.prototype._anchor = function (hitBox) { this.hitBox = hitBox; }; @@ -729,8 +729,8 @@ var Plottable; return _this.rerenderZoomed(); }); } - PanZoomInteraction.prototype.anchor = function (hitBox) { - _super.prototype.anchor.call(this, hitBox); + PanZoomInteraction.prototype._anchor = function (hitBox) { + _super.prototype._anchor.call(this, hitBox); this.zoom(hitBox); }; @@ -838,8 +838,8 @@ var Plottable; return this; }; - AreaInteraction.prototype.anchor = function (hitBox) { - _super.prototype.anchor.call(this, hitBox); + AreaInteraction.prototype._anchor = function (hitBox) { + _super.prototype._anchor.call(this, hitBox); var cname = AreaInteraction.CLASS_DRAG_BOX; var background = this.componentToListenTo.backgroundContainer; this.dragBox = background.append("rect").classed(cname, true).attr("x", 0).attr("y", 0); @@ -923,9 +923,9 @@ var Plottable; function MousemoveInteraction(componentToListenTo) { _super.call(this, componentToListenTo); } - MousemoveInteraction.prototype.anchor = function (hitBox) { + MousemoveInteraction.prototype._anchor = function (hitBox) { var _this = this; - _super.prototype.anchor.call(this, hitBox); + _super.prototype._anchor.call(this, hitBox); hitBox.on("mousemove", function () { var xy = d3.mouse(hitBox.node()); var x = xy[0]; @@ -947,8 +947,8 @@ var Plottable; _super.call(this, renderer); this.renderer = renderer; } - CrosshairsInteraction.prototype.anchor = function (hitBox) { - _super.prototype.anchor.call(this, hitBox); + CrosshairsInteraction.prototype._anchor = function (hitBox) { + _super.prototype._anchor.call(this, hitBox); var container = this.renderer.foregroundContainer.append("g").classed("crosshairs", true); this.circle = container.append("circle").classed("centerpoint", true); this.xLine = container.append("path").classed("x-line", true); @@ -1008,8 +1008,8 @@ var Plottable; } this.xAlign("CENTER").yAlign("CENTER"); // the defaults } - Label.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + Label.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.textElement = this.content.append("text"); this.setText(this.text); return this; @@ -1047,8 +1047,8 @@ var Plottable; this.measureAndSetTextSize(); }; - Label.prototype.computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { - _super.prototype.computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); + Label.prototype._computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { + _super.prototype._computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); this.textElement.attr("dy", 0); // Reset this so we maintain idempotence var bbox = Plottable.Utils.getBBox(this.textElement); @@ -1161,7 +1161,7 @@ var Plottable; return this; }; - Renderer.prototype.render = function () { + Renderer.prototype._render = function () { this._paint(); this._requireRerender = false; this._rerenderUpdateSelection = false; @@ -1179,8 +1179,8 @@ var Plottable; // no-op }; - Renderer.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + Renderer.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.renderArea = this.content.append("g").classed("render-area", true); return this; }; @@ -1235,8 +1235,8 @@ var Plottable; return _this.rescale(); }); } - XYRenderer.prototype.computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { - _super.prototype.computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); + XYRenderer.prototype._computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { + _super.prototype._computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); this.xScale.range([0, this.availableWidth]); this.yScale.range([this.availableHeight, 0]); return this; @@ -1297,7 +1297,7 @@ var Plottable; XYRenderer.prototype.rescale = function () { if (this.element != null) { - this.render(); + this._render(); } }; XYRenderer.defaultXAccessor = function (d) { @@ -1326,8 +1326,8 @@ var Plottable; _super.call(this, dataset, xScale, yScale, xAccessor, yAccessor); this.classed("line-renderer", true); } - LineRenderer.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + LineRenderer.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.path = this.renderArea.append("path"); return this; }; @@ -1532,22 +1532,22 @@ var Plottable; return this; }; - Table.prototype.anchor = function (element) { + Table.prototype._anchor = function (element) { var _this = this; - _super.prototype.anchor.call(this, element); + _super.prototype._anchor.call(this, element); // recursively anchor children this.rows.forEach(function (row, rowIndex) { row.forEach(function (component, colIndex) { - component.anchor(_this.content.append("g")); + component._anchor(_this.content.append("g")); }); }); return this; }; - Table.prototype.computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { + Table.prototype._computeLayout = function (xOffset, yOffset, availableWidth, availableHeight) { var _this = this; - _super.prototype.computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); + _super.prototype._computeLayout.call(this, xOffset, yOffset, availableWidth, availableHeight); // calculate the amount of free space by recursive col-/row- Minimum() calls var freeWidth = this.availableWidth - this.colMinimum(); @@ -1579,7 +1579,7 @@ var Plottable; var childXOffset = 0; row.forEach(function (component, colIndex) { // recursively compute layout - component.computeLayout(childXOffset, childYOffset, colWidths[colIndex], rowHeights[rowIndex]); + component._computeLayout(childXOffset, childYOffset, colWidths[colIndex], rowHeights[rowIndex]); childXOffset += colWidths[colIndex] + _this.colPadding; }); childYOffset += rowHeights[rowIndex] + _this.rowPadding; @@ -1587,11 +1587,11 @@ var Plottable; return this; }; - Table.prototype.render = function () { + Table.prototype._render = function () { // recursively render children this.rows.forEach(function (row, rowIndex) { row.forEach(function (component, colIndex) { - component.render(); + component._render(); }); }); return this; @@ -1826,8 +1826,8 @@ var Plottable; return textHeight; }; - Legend.prototype.render = function () { - _super.prototype.render.call(this); + Legend.prototype._render = function () { + _super.prototype._render.call(this); var domain = this.colorScale.domain(); var textHeight = this.measureTextHeight(); var availableWidth = this.colMinimum() - textHeight - Legend.MARGIN; @@ -1894,13 +1894,13 @@ var Plottable; return _this.rescale(); }); } - Axis.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + Axis.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.axisElement = this.content.append("g").classed("axis", true); return this; }; - Axis.prototype.render = function () { + Axis.prototype._render = function () { if (this.orient() === "left") { this.axisElement.attr("transform", "translate(" + Axis.yWidth + ", 0)"); } @@ -1963,7 +1963,7 @@ var Plottable; }; Axis.prototype.rescale = function () { - return (this.element != null) ? this.render() : null; + return (this.element != null) ? this._render() : null; // short circuit, we don't care about perf. }; @@ -2095,8 +2095,8 @@ var Plottable; this.fixedWidthVal = false; this.tickLabelPosition("center"); } - XAxis.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + XAxis.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.axisElement.classed("x-axis", true); return this; }; @@ -2117,8 +2117,8 @@ var Plottable; } }; - XAxis.prototype.render = function () { - _super.prototype.render.call(this); + XAxis.prototype._render = function () { + _super.prototype._render.call(this); if (this.tickLabelPosition() !== "center") { var tickTextLabels = this.axisElement.selectAll("text"); tickTextLabels.attr("y", "0px"); @@ -2163,8 +2163,8 @@ var Plottable; this.fixedHeightVal = false; this.tickLabelPosition("MIDDLE"); } - YAxis.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + YAxis.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.axisElement.classed("y-axis", true); return this; }; @@ -2185,8 +2185,8 @@ var Plottable; } }; - YAxis.prototype.render = function () { - _super.prototype.render.call(this); + YAxis.prototype._render = function () { + _super.prototype._render.call(this); if (this.tickLabelPosition() !== "middle") { var tickTextLabels = this.axisElement.selectAll("text"); tickTextLabels.attr("x", "0px"); @@ -2235,7 +2235,7 @@ var Plottable; this.components.push(c); } if (this.element != null) { - c.anchor(this.content.append("g")); + c._anchor(this.content.append("g")); } return this; }; @@ -2250,28 +2250,28 @@ var Plottable; } }; - ComponentGroup.prototype.anchor = function (element) { + ComponentGroup.prototype._anchor = function (element) { var _this = this; - _super.prototype.anchor.call(this, element); + _super.prototype._anchor.call(this, element); this.components.forEach(function (c) { - return c.anchor(_this.content.append("g")); + return c._anchor(_this.content.append("g")); }); return this; }; - ComponentGroup.prototype.computeLayout = function (xOrigin, yOrigin, availableWidth, availableHeight) { + ComponentGroup.prototype._computeLayout = function (xOrigin, yOrigin, availableWidth, availableHeight) { var _this = this; - _super.prototype.computeLayout.call(this, xOrigin, yOrigin, availableWidth, availableHeight); + _super.prototype._computeLayout.call(this, xOrigin, yOrigin, availableWidth, availableHeight); this.components.forEach(function (c) { - c.computeLayout(0, 0, _this.availableWidth, _this.availableHeight); + c._computeLayout(0, 0, _this.availableWidth, _this.availableHeight); }); return this; }; - ComponentGroup.prototype.render = function () { - _super.prototype.render.call(this); + ComponentGroup.prototype._render = function () { + _super.prototype._render.call(this); this.components.forEach(function (c) { - return c.render(); + return c._render(); }); return this; }; @@ -2320,15 +2320,15 @@ var Plottable; }); } } - Gridlines.prototype.anchor = function (element) { - _super.prototype.anchor.call(this, element); + Gridlines.prototype._anchor = function (element) { + _super.prototype._anchor.call(this, element); this.xLinesContainer = this.content.append("g").classed("x-gridlines", true); this.yLinesContainer = this.content.append("g").classed("y-gridlines", true); return this; }; - Gridlines.prototype.render = function () { - _super.prototype.render.call(this); + Gridlines.prototype._render = function () { + _super.prototype._render.call(this); this.redrawXLines(); this.redrawYLines(); return this;