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