Skip to content

Commit

Permalink
Merge pull request #202 from palantir/protect-anchor-computelayout-re…
Browse files Browse the repository at this point in the history
…nder

Make anchor, computeLayout, and render protected methods (via _conventio...
  • Loading branch information
teamdandelion committed Mar 18, 2014
2 parents ac56d7b + d7988c6 commit 420e7c0
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 183 deletions.
2 changes: 1 addition & 1 deletion examples/chartWithLabels/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function makeChartWithLabels() {
var renderAreaD1 = new Plottable.CircleRenderer(dataseries, xScale, yScale);
var basicTable = new Plottable.Table([[yAxisTable, renderAreaD1],
[null, xAxisTable]]);
basicTable.anchor(svg).computeLayout().render();
basicTable.renderTo(svg);
};

window.onload = makeChartWithLabels;
2 changes: 1 addition & 1 deletion examples/chartWithSubplots/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function makeChartWithSubplots() {
var basicTable = new Plottable.Table([[yAxis1, renderAreaD1, null],
[null, renderAreaD2, yAxis2],
[null, xAxis, null]]);
basicTable.anchor(svg).computeLayout().render();
basicTable.renderTo(svg);
};

window.onload = makeChartWithSubplots;
38 changes: 19 additions & 19 deletions examples/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module Demo {
var data = makeRandomData(30);
var renderAreaD1 = new Plottable.CircleRenderer(data, xScale, yScale);
var basicTable = new Plottable.Table([[renderAreaD1, yAxis], [xAxis, null]])
basicTable.anchor(svg1);
basicTable.computeLayout();
basicTable.render();
basicTable._anchor(svg1);
basicTable._computeLayout();
basicTable._render();
var pzi = new Plottable.PanZoomInteraction(renderAreaD1, xScale, yScale);
pzi.registerWithComponent();

Expand All @@ -40,9 +40,9 @@ module Demo {
var metaTable = new Plottable.Table([[t1, t2], [t3, t4]]);
metaTable.padding(5, 5);
svg2.attr("width", 800).attr("height", 600);
metaTable.anchor(svg2);
metaTable.computeLayout();
metaTable.render();
metaTable._anchor(svg2);
metaTable._computeLayout();
metaTable._render();

// make a chart with two axes
function makeMultiAxisChart() {
Expand All @@ -61,9 +61,9 @@ module Demo {
var svg3 = d3.select("#svg3");
var multiaxischart = makeMultiAxisChart();
svg3.attr("width", 400).attr("height",400);
multiaxischart.anchor(svg3);
multiaxischart.computeLayout();
multiaxischart.render();
multiaxischart._anchor(svg3);
multiaxischart._computeLayout();
multiaxischart._render();

// make a table with 2 charts and sparkline
function makeSparklineMultichart() {
Expand Down Expand Up @@ -103,11 +103,11 @@ module Demo {
var svg4 = d3.select("#svg4");
var multichart = makeSparklineMultichart();
svg4.attr("width",800).attr("height",600);
multichart.anchor(svg4);
multichart.computeLayout();
multichart.render();
multichart._anchor(svg4);
multichart._computeLayout();
multichart._render();
// svg4.selectAll("g").remove()
// multichart.render(svg4, 800, 600);
// multichart._render(svg4, 800, 600);

// function makeChartWithGivenNumAxes(left=1, right=0, top=0, bottom=1){
// var xScale = new Plottable.LinearScale();
Expand Down Expand Up @@ -137,9 +137,9 @@ module Demo {
var basicTable = new Plottable.Table([[yAxisLeftTable, renderArea, yAxisRightTable], [null, xAxis, null]]);
var title = new Plottable.TitleLabel("bpIqd");
var outerTable = new Plottable.Table([[title], [basicTable]]);
outerTable.anchor(svg5);
outerTable.computeLayout();
outerTable.render();
outerTable._anchor(svg5);
outerTable._computeLayout();
outerTable._render();


// bar renderer test
Expand All @@ -156,7 +156,7 @@ module Demo {

var BarRenderArea = new Plottable.BarRenderer(bucketData, xScale, yScale);
var basicTable = new Plottable.Table([[yAxis, BarRenderArea], [null, xAxis]])
basicTable.anchor(svg6);
basicTable.computeLayout();
basicTable.render();
basicTable._anchor(svg6);
basicTable._computeLayout();
basicTable._render();
}
10 changes: 5 additions & 5 deletions examples/demoDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ module DemoDay {
chart.c.yBins = yBins;
histogram.renderer1.dataset({metadata: {cssClass: "xBins"}, data: xBins})
histogram.renderer2.dataset({metadata: {cssClass: "yBins"}, data: yBins})
histogram.renderer1.render();
histogram.renderer2.render();
histogram.renderer1._render();
histogram.renderer2._render();
};

var firstCallback = (area: Plottable.SelectionArea) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ module DemoDay {
coordinator(chartSH, dataset);

var svg = d3.select("#table");
chartSH.table.anchor(svg);
chartSH.table.computeLayout();
chartSH.table.render();
chartSH.table._anchor(svg);
chartSH.table._computeLayout();
chartSH.table._render();
}
2 changes: 1 addition & 1 deletion examples/selectionDemo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function makeChartWithAreaInteraction() {
};
areaInteraction.callback(selectPoints); // add selectPoints as a callback when a selection is made

basicTable.anchor(svg).computeLayout().render();
basicTable.renderTo(svg);
};

window.onload = makeChartWithAreaInteraction;
2 changes: 1 addition & 1 deletion examples/simpleChart/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function makeSimpleChart() {
.addComponent(0, 1, renderAreaD1)
.addComponent(1, 1, xAxis);

basicTable.anchor(svg).computeLayout().render();
basicTable.renderTo(svg);
};

window.onload = makeSimpleChart;
6 changes: 3 additions & 3 deletions examples/sparklineDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module SparklineDemo {
// var areaInteraction = new Plottable.AreaInteraction(renderer);

var svg = d3.select("#table");
chart.anchor(svg);
chart.computeLayout();
chart.render();
chart._anchor(svg);
chart._computeLayout();
chart._render();
}
2 changes: 1 addition & 1 deletion examples/tscDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ module TSCDemo {
.addComponent(2, 1, xAxis)
.addComponent(0, 1, xAxis2);

basicTable.anchor(svg).computeLayout().render();
basicTable._anchor(svg)._computeLayout()._render();

}
61 changes: 37 additions & 24 deletions plottable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ 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;
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,
Expand All @@ -103,13 +103,13 @@ declare module Plottable {
* @param {number} availableHeight
* @returns {Component} The calling Component.
*/
public computeLayout(xOrigin?: number, yOrigin?: number, availableWidth?: number, availableHeight?: number): Component;
public _computeLayout(xOrigin?: number, yOrigin?: number, availableWidth?: number, availableHeight?: number): Component;
/**
* Renders the component.
*
* @returns {Component} The calling Component.
*/
public render(): Component;
public _render(): Component;
public renderTo(element: D3.Selection): Component;
/**
* Sets the x alignment of the Component.
Expand Down Expand Up @@ -341,7 +341,7 @@ declare module Plottable {
* @param {Component} componentToListenTo The component to listen for interactions on.
*/
constructor(componentToListenTo: Component);
public anchor(hitBox: D3.Selection): void;
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.
Expand All @@ -364,7 +364,7 @@ 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;
public _anchor(hitBox: D3.Selection): void;
}
class AreaInteraction extends Interaction {
/**
Expand All @@ -386,7 +386,7 @@ declare module Plottable {
* @returns {AreaInteraction} The calling AreaInteraction.
*/
public clearBox(): AreaInteraction;
public anchor(hitBox: D3.Selection): AreaInteraction;
public _anchor(hitBox: D3.Selection): AreaInteraction;
}
class ZoomCallbackGenerator {
/**
Expand Down Expand Up @@ -416,12 +416,12 @@ declare module Plottable {
}
class MousemoveInteraction extends Interaction {
constructor(componentToListenTo: Component);
public anchor(hitBox: D3.Selection): void;
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 _anchor(hitBox: D3.Selection): void;
public mousemove(x: number, y: number): void;
}
}
Expand All @@ -435,15 +435,15 @@ 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;
public _anchor(element: D3.Selection): Label;
/**
* Sets the text on the Label.
*
* @param {string} text The new text for the Label.
* @returns {Label} The calling Label.
*/
public setText(text: string): Label;
public computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): Label;
public _computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): Label;
}
class TitleLabel extends Label {
constructor(text?: string, orientation?: string);
Expand Down Expand Up @@ -473,9 +473,9 @@ declare module Plottable {
public dataset(dataset: IDataset): Renderer;
public metadata(metadata: IMetadata): Renderer;
public data(data: any[]): Renderer;
public render(): Renderer;
public _render(): Renderer;
public colorAccessor(a: IAccessor): Renderer;
public anchor(element: D3.Selection): Renderer;
public _anchor(element: D3.Selection): Renderer;
}
class XYRenderer extends Renderer {
public dataSelection: D3.UpdateSelection;
Expand All @@ -494,7 +494,7 @@ 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;
public _computeLayout(xOffset?: number, yOffset?: number, availableWidth?: number, availableHeight?: number): XYRenderer;
/**
* Converts a SelectionArea with pixel ranges to one with data ranges.
*
Expand Down Expand Up @@ -529,7 +529,7 @@ 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;
public _anchor(element: D3.Selection): LineRenderer;
}
class CircleRenderer extends XYRenderer {
public size: number;
Expand Down Expand Up @@ -581,9 +581,9 @@ 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;
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.
*
Expand Down Expand Up @@ -648,7 +648,7 @@ declare module Plottable {
public scale(scale: ColorScale): Legend;
public rowMinimum(): number;
public rowMinimum(newVal: number): Legend;
public render(): Legend;
public _render(): Legend;
}
}
declare module Plottable {
Expand All @@ -665,8 +665,8 @@ 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 _anchor(element: D3.Selection): Axis;
public _render(): Axis;
public scale(): Scale;
public scale(newScale: Scale): Axis;
/**
Expand Down Expand Up @@ -706,7 +706,7 @@ declare module Plottable {
* @param {any} [formatter] a D3 formatter
*/
constructor(scale: Scale, orientation: string, formatter?: any);
public anchor(element: D3.Selection): XAxis;
public _anchor(element: D3.Selection): XAxis;
/**
* Sets or gets the tick label position relative to the tick marks.
*
Expand All @@ -715,7 +715,7 @@ declare module Plottable {
*/
public tickLabelPosition(): string;
public tickLabelPosition(position: string): XAxis;
public render(): XAxis;
public _render(): XAxis;
}
class YAxis extends Axis {
/**
Expand All @@ -727,7 +727,7 @@ declare module Plottable {
* @param {any} [formatter] a D3 formatter
*/
constructor(scale: Scale, orientation: string, formatter?: any);
public anchor(element: D3.Selection): YAxis;
public _anchor(element: D3.Selection): YAxis;
/**
* Sets or gets the tick label position relative to the tick marks.
*
Expand All @@ -736,7 +736,7 @@ declare module Plottable {
*/
public tickLabelPosition(): string;
public tickLabelPosition(position: string): YAxis;
public render(): YAxis;
public _render(): YAxis;
}
}
declare module Plottable {
Expand All @@ -748,10 +748,23 @@ 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;
}
Expand Down
Loading

0 comments on commit 420e7c0

Please sign in to comment.