source: node_modules/d3-shape/src/curve/bundle.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[e4c61dd]1import {Basis} from "./basis.js";
2
3function Bundle(context, beta) {
4 this._basis = new Basis(context);
5 this._beta = beta;
6}
7
8Bundle.prototype = {
9 lineStart: function() {
10 this._x = [];
11 this._y = [];
12 this._basis.lineStart();
13 },
14 lineEnd: function() {
15 var x = this._x,
16 y = this._y,
17 j = x.length - 1;
18
19 if (j > 0) {
20 var x0 = x[0],
21 y0 = y[0],
22 dx = x[j] - x0,
23 dy = y[j] - y0,
24 i = -1,
25 t;
26
27 while (++i <= j) {
28 t = i / j;
29 this._basis.point(
30 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
31 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
32 );
33 }
34 }
35
36 this._x = this._y = null;
37 this._basis.lineEnd();
38 },
39 point: function(x, y) {
40 this._x.push(+x);
41 this._y.push(+y);
42 }
43};
44
45export default (function custom(beta) {
46
47 function bundle(context) {
48 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
49 }
50
51 bundle.beta = function(beta) {
52 return custom(+beta);
53 };
54
55 return bundle;
56})(0.85);
Note: See TracBrowser for help on using the repository browser.