source: node_modules/d3-shape/src/curve/basis.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.4 KB
Line 
1export function point(that, x, y) {
2 that._context.bezierCurveTo(
3 (2 * that._x0 + that._x1) / 3,
4 (2 * that._y0 + that._y1) / 3,
5 (that._x0 + 2 * that._x1) / 3,
6 (that._y0 + 2 * that._y1) / 3,
7 (that._x0 + 4 * that._x1 + x) / 6,
8 (that._y0 + 4 * that._y1 + y) / 6
9 );
10}
11
12export function Basis(context) {
13 this._context = context;
14}
15
16Basis.prototype = {
17 areaStart: function() {
18 this._line = 0;
19 },
20 areaEnd: function() {
21 this._line = NaN;
22 },
23 lineStart: function() {
24 this._x0 = this._x1 =
25 this._y0 = this._y1 = NaN;
26 this._point = 0;
27 },
28 lineEnd: function() {
29 switch (this._point) {
30 case 3: point(this, this._x1, this._y1); // falls through
31 case 2: this._context.lineTo(this._x1, this._y1); break;
32 }
33 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
34 this._line = 1 - this._line;
35 },
36 point: function(x, y) {
37 x = +x, y = +y;
38 switch (this._point) {
39 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
40 case 1: this._point = 2; break;
41 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
42 default: point(this, x, y); break;
43 }
44 this._x0 = this._x1, this._x1 = x;
45 this._y0 = this._y1, this._y1 = y;
46 }
47};
48
49export default function(context) {
50 return new Basis(context);
51}
Note: See TracBrowser for help on using the repository browser.