From 20df9b7d919c485e3e616c83434f0666afc99e23 Mon Sep 17 00:00:00 2001 From: Daniel Mane Date: Thu, 27 Mar 2014 15:23:08 -0700 Subject: [PATCH] Make and use a setter for rAccessor --- examples/main-page/commit-chart.js | 6 +++--- src/circleRenderer.ts | 13 ++++++++++--- src/squareRenderer.ts | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/main-page/commit-chart.js b/examples/main-page/commit-chart.js index fe273e460e..be39eabedd 100644 --- a/examples/main-page/commit-chart.js +++ b/examples/main-page/commit-chart.js @@ -13,7 +13,6 @@ function commitChart(svg, dataset) { .domain(["danmane", "jlan", "aramaswamy", "derekcicerone"]) .range(["#ff7f0e", "#1f77b4", "#2ca02c", "#d62728"]); - function dateAccessor(d) { return d.date; } function radiusAccessor(d) { return rScale.scale(linesAddedAccessor(d)); } function colorAccessor(d) { return colorScale.scale(d.name); } @@ -23,8 +22,9 @@ function commitChart(svg, dataset) { } - var renderer = new Plottable.CircleRenderer(dataset, xScale, yScale, dateAccessor, hourAccessor, radiusAccessor) - .colorAccessor(colorAccessor); + var renderer = new Plottable.CircleRenderer(dataset, xScale, yScale) + .xAccessor("date").yAccessor(hourAccessor) + .rAccessor(radiusAccessor).colorAccessor(colorAccessor); var legend = new Plottable.Legend(colorScale).colMinimum(160).xOffset(-15).yOffset(10); var gridlines = new Plottable.Gridlines(xScale, yScale); diff --git a/src/circleRenderer.ts b/src/circleRenderer.ts index 812e73fc9e..3cfdd17691 100644 --- a/src/circleRenderer.ts +++ b/src/circleRenderer.ts @@ -2,7 +2,7 @@ module Plottable { export class CircleRenderer extends XYRenderer { - private rAccessor: any; + private _rAccessor: any; private static defaultRAccessor = 3; /** @@ -19,15 +19,22 @@ module Plottable { constructor(dataset: IDataset, xScale: QuantitiveScale, yScale: QuantitiveScale, xAccessor?: any, yAccessor?: any, rAccessor?: any) { super(dataset, xScale, yScale, xAccessor, yAccessor); - this.rAccessor = (rAccessor != null) ? rAccessor : CircleRenderer.defaultRAccessor; + this._rAccessor = (rAccessor != null) ? rAccessor : CircleRenderer.defaultRAccessor; this.classed("circle-renderer", true); } + public rAccessor(a: any) { + this._rAccessor = a; + this._requireRerender = true; + this._rerenderUpdateSelection = true; + return this; + } + public _paint() { super._paint(); var cx = (d: any, i: number) => this.xScale.scale(this._getAppliedAccessor(this._xAccessor)(d, i)); var cy = (d: any, i: number) => this.yScale.scale(this._getAppliedAccessor(this._yAccessor)(d, i)); - var r = this._getAppliedAccessor(this.rAccessor); + var r = this._getAppliedAccessor(this._rAccessor); var color = this._getAppliedAccessor(this._colorAccessor); this.dataSelection = this.renderArea.selectAll("circle").data(this._data); this.dataSelection.enter().append("circle"); diff --git a/src/squareRenderer.ts b/src/squareRenderer.ts index 1219e7fb01..433e42eb7a 100644 --- a/src/squareRenderer.ts +++ b/src/squareRenderer.ts @@ -2,8 +2,8 @@ module Plottable { export class SquareRenderer extends XYRenderer { - private rAccessor: IAccessor; - private static defaultRAccessor = (d: any) => 3; + private _rAccessor: any; + private static defaultRAccessor = 3; /** * Creates a SquareRenderer. @@ -19,15 +19,23 @@ module Plottable { constructor(dataset: IDataset, xScale: QuantitiveScale, yScale: QuantitiveScale, xAccessor?: IAccessor, yAccessor?: IAccessor, rAccessor?: IAccessor) { super(dataset, xScale, yScale, xAccessor, yAccessor); - this.rAccessor = (rAccessor != null) ? rAccessor : SquareRenderer.defaultRAccessor; + this._rAccessor = (rAccessor != null) ? rAccessor : SquareRenderer.defaultRAccessor; this.classed("square-renderer", true); } + + public rAccessor(a: any) { + this._rAccessor = a; + this._requireRerender = true; + this._rerenderUpdateSelection = true; + return this; + } + public _paint() { super._paint(); var xA = this._getAppliedAccessor(this._xAccessor); var yA = this._getAppliedAccessor(this._yAccessor); - var rA = this._getAppliedAccessor(this.rAccessor); + var rA = this._getAppliedAccessor(this._rAccessor); var cA = this._getAppliedAccessor(this._colorAccessor); var xFn = (d: any, i: number) => this.xScale.scale(xA(d, i)) - rA(d, i);