Skip to content

Commit

Permalink
Make and use a setter for rAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
teamdandelion committed Mar 27, 2014
1 parent 1507bf3 commit 20df9b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/main-page/commit-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand All @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions src/circleRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Plottable {
export class CircleRenderer extends XYRenderer {
private rAccessor: any;
private _rAccessor: any;
private static defaultRAccessor = 3;

/**
Expand All @@ -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");
Expand Down
16 changes: 12 additions & 4 deletions src/squareRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 20df9b7

Please sign in to comment.