Skip to content

Commit

Permalink
Radial line and area.
Browse files Browse the repository at this point in the history
Fixes #25. Fixes #26.
  • Loading branch information
mbostock committed Dec 4, 2015
1 parent b3cdcea commit 0633d65
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 131 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -19,6 +19,7 @@ export {default as line} from "./src/line";
export {default as monotone} from "./src/curve/monotone";
export {default as natural} from "./src/curve/natural";
export {default as pie} from "./src/pie";
export {default as radialArea} from "./src/radialArea";
export {default as radialLine} from "./src/radialLine";
export {default as square} from "./src/symbol/square";
export {default as stepAfter} from "./src/curve/stepAfter";
Expand Down
3 changes: 1 addition & 2 deletions src/area.js
Expand Up @@ -81,8 +81,7 @@ export default function() {
};

area.curve = function(_) {
var n = arguments.length;
return n ? (curve = n > 1 ? curveBind(_, arguments) : _, context != null && (output = curve(context)), area) : curve;
return arguments.length ? (curve = curveBind(_, arguments), context != null && (output = curve(context)), area) : curve;
};

area.context = function(_) {
Expand Down
8 changes: 3 additions & 5 deletions src/curve/basis.js
Expand Up @@ -9,10 +9,6 @@ export function point(that, x, y) {
);
};

function basis(context) {
return new Basis(context);
}

function Basis(context) {
this._context = context;
}
Expand Down Expand Up @@ -50,4 +46,6 @@ Basis.prototype = {
}
};

export default basis;
export default function(context) {
return new Basis(context);
};
8 changes: 3 additions & 5 deletions src/curve/basisClosed.js
@@ -1,9 +1,5 @@
import {point} from "./basis";

function basisClosed(context) {
return new BasisClosed(context);
}

function BasisClosed(context) {
this._context = context;
}
Expand Down Expand Up @@ -48,4 +44,6 @@ BasisClosed.prototype = {
}
};

export default basisClosed;
export default function(context) {
return new BasisClosed(context);
};
8 changes: 3 additions & 5 deletions src/curve/basisOpen.js
@@ -1,9 +1,5 @@
import {point} from "./basis";

function basisOpen(context) {
return new BasisOpen(context);
}

function BasisOpen(context) {
this._context = context;
}
Expand Down Expand Up @@ -38,4 +34,6 @@ BasisOpen.prototype = {
}
};

export default basisOpen;
export default function(context) {
return new BasisOpen(context);
};
5 changes: 3 additions & 2 deletions src/curve/bind.js
@@ -1,10 +1,11 @@
var slice = Array.prototype.slice;

export default function(interpolate, args) {
export default function(curve, args) {
if (args.length < 2) return curve;
args = slice.call(args);
args[0] = null;
return function(context) {
args[0] = context;
return interpolate.apply(null, args);
return curve.apply(null, args);
};
};
12 changes: 5 additions & 7 deletions src/curve/bundle.js
@@ -1,11 +1,5 @@
import basis from "./basis";

function bundle(context, beta) {
return beta == null ? new Bundle(context, 0.85)
: (beta = +beta) === 1 ? basis(context)
: new Bundle(context, beta);
}

function Bundle(context, beta) {
this._basis = basis(context);
this._beta = beta;
Expand Down Expand Up @@ -48,4 +42,8 @@ Bundle.prototype = {
}
};

export default bundle;
export default function(context, beta) {
return beta == null ? new Bundle(context, 0.85)
: (beta = +beta) === 1 ? basis(context)
: new Bundle(context, beta);
};
8 changes: 3 additions & 5 deletions src/curve/cardinal.js
Expand Up @@ -9,10 +9,6 @@ export function point(that, x, y) {
);
};

function cardinal(context, tension) {
return new Cardinal(context, (tension == null ? 1 : 1 - tension) / 6);
}

function Cardinal(context, k) {
this._context = context;
this._k = k;
Expand Down Expand Up @@ -51,4 +47,6 @@ Cardinal.prototype = {
}
};

export default cardinal;
export default function(context, tension) {
return new Cardinal(context, (tension == null ? 1 : 1 - tension) / 6);
};
8 changes: 3 additions & 5 deletions src/curve/cardinalClosed.js
@@ -1,9 +1,5 @@
import {point} from "./cardinal";

function cardinalClosed(context, tension) {
return new CardinalClosed(context, (tension == null ? 1 : 1 - tension) / 6);
}

function CardinalClosed(context, k) {
this._context = context;
this._k = k;
Expand Down Expand Up @@ -48,4 +44,6 @@ CardinalClosed.prototype = {
}
};

export default cardinalClosed;
export default function(context, tension) {
return new CardinalClosed(context, (tension == null ? 1 : 1 - tension) / 6);
};
8 changes: 3 additions & 5 deletions src/curve/cardinalOpen.js
@@ -1,9 +1,5 @@
import {point} from "./cardinal";

function cardinalOpen(context, tension) {
return new CardinalOpen(context, (tension == null ? 1 : 1 - tension) / 6);
}

function CardinalOpen(context, k) {
this._context = context;
this._k = k;
Expand Down Expand Up @@ -39,4 +35,6 @@ CardinalOpen.prototype = {
}
};

export default cardinalOpen;
export default function(context, tension) {
return new CardinalOpen(context, (tension == null ? 1 : 1 - tension) / 6);
};
12 changes: 5 additions & 7 deletions src/curve/catmullRom.js
Expand Up @@ -25,12 +25,6 @@ export function point(that, x, y) {
that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
};

function catmullRom(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRom(context, alpha)
: cardinal(context, 0);
}

function CatmullRom(context, alpha) {
this._context = context;
this._alpha = alpha;
Expand Down Expand Up @@ -81,4 +75,8 @@ CatmullRom.prototype = {
}
};

export default catmullRom;
export default function(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRom(context, alpha)
: cardinal(context, 0);
};
12 changes: 5 additions & 7 deletions src/curve/catmullRomClosed.js
@@ -1,12 +1,6 @@
import cardinalClosed from "./cardinalClosed";
import {point} from "./catmullRom";

function catmullRomClosed(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRomClosed(context, alpha)
: cardinalClosed(context, 0);
}

function CatmullRomClosed(context, alpha) {
this._context = context;
this._alpha = alpha;
Expand Down Expand Up @@ -63,4 +57,8 @@ CatmullRomClosed.prototype = {
}
};

export default catmullRomClosed;
export default function(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRomClosed(context, alpha)
: cardinalClosed(context, 0);
};
12 changes: 5 additions & 7 deletions src/curve/catmullRomOpen.js
@@ -1,12 +1,6 @@
import cardinalOpen from "./cardinalOpen";
import {point} from "./catmullRom";

function catmullRomOpen(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRomOpen(context, alpha)
: cardinalOpen(context, 0);
}

function CatmullRomOpen(context, alpha) {
this._context = context;
this._alpha = alpha;
Expand Down Expand Up @@ -54,4 +48,8 @@ CatmullRomOpen.prototype = {
}
};

export default catmullRomOpen;
export default function(context, alpha) {
return (alpha = alpha == null ? 0.5 : +alpha)
? new CatmullRomOpen(context, alpha)
: cardinalOpen(context, 0);
};
8 changes: 3 additions & 5 deletions src/curve/linear.js
@@ -1,7 +1,3 @@
function linear(context) {
return new Linear(context);
}

function Linear(context) {
this._context = context;
}
Expand Down Expand Up @@ -30,4 +26,6 @@ Linear.prototype = {
}
};

export default linear;
export default function(context) {
return new Linear(context);
};
8 changes: 3 additions & 5 deletions src/curve/linearClosed.js
@@ -1,7 +1,3 @@
function linearClosed(context) {
return new LinearClosed(context);
}

function LinearClosed(context) {
this._context = context;
}
Expand All @@ -20,4 +16,6 @@ LinearClosed.prototype = {
}
};

export default linearClosed;
export default function(context) {
return new LinearClosed(context);
};
8 changes: 3 additions & 5 deletions src/curve/monotone.js
Expand Up @@ -33,10 +33,6 @@ function point(that, t0, t1) {
that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
}

function monotone(context) {
return new Monotone(context);
}

function Monotone(context) {
this._context = context;
}
Expand Down Expand Up @@ -80,4 +76,6 @@ Monotone.prototype = {
}
}

export default monotone;
export default function(context) {
return new Monotone(context);
};
8 changes: 3 additions & 5 deletions src/curve/natural.js
@@ -1,7 +1,3 @@
function natural(context) {
return new Natural(context);
}

function Natural(context) {
this._context = context;
}
Expand Down Expand Up @@ -64,4 +60,6 @@ function controlPoints(x) {
return [a, b];
}

export default natural;
export default function(context) {
return new Natural(context);
};
36 changes: 36 additions & 0 deletions src/curve/radial.js
@@ -0,0 +1,36 @@
import bind from "./bind";
import {halfPi} from "../math";

function Radial(curve) {
this._curve = curve;
}

Radial.prototype = {
areaStart: function() {
this._curve.areaStart();
},
areaEnd: function() {
this._curve.areaEnd();
},
lineStart: function() {
this._curve.lineStart();
},
lineEnd: function() {
this._curve.lineEnd();
},
point: function(r, a) {
a -= halfPi, this._curve.point(r * Math.cos(a), r * Math.sin(a));
}
};

export default function(curve, args) {
curve = bind(curve, args);

function radial(context) {
return new Radial(curve(context));
}

radial._curve = curve;

return radial;
};
8 changes: 3 additions & 5 deletions src/curve/step.js
@@ -1,7 +1,3 @@
function step(context) {
return new Step(context);
}

function Step(context) {
this._context = context;
}
Expand Down Expand Up @@ -38,4 +34,6 @@ Step.prototype = {
}
};

export default step;
export default function(context) {
return new Step(context);
};
8 changes: 3 additions & 5 deletions src/curve/stepAfter.js
@@ -1,7 +1,3 @@
function stepAfter(context) {
return new StepAfter(context);
}

function StepAfter(context) {
this._context = context;
}
Expand Down Expand Up @@ -36,4 +32,6 @@ StepAfter.prototype = {
}
};

export default stepAfter;
export default function(context) {
return new StepAfter(context);
};
8 changes: 3 additions & 5 deletions src/curve/stepBefore.js
@@ -1,7 +1,3 @@
function stepBefore(context) {
return new StepBefore(context);
}

function StepBefore(context) {
this._context = context;
}
Expand Down Expand Up @@ -36,4 +32,6 @@ StepBefore.prototype = {
}
};

export default stepBefore;
export default function(context) {
return new StepBefore(context);
};
3 changes: 1 addition & 2 deletions src/line.js
Expand Up @@ -45,8 +45,7 @@ export default function() {
};

line.curve = function(_) {
var n = arguments.length;
return n ? (curve = n > 1 ? curveBind(_, arguments) : _, context != null && (output = curve(context)), line) : curve;
return arguments.length ? (curve = curveBind(_, arguments), context != null && (output = curve(context)), line) : curve;
};

line.context = function(_) {
Expand Down

0 comments on commit 0633d65

Please sign in to comment.