source: node_modules/d3-shape/src/curve/bump.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.7 KB
RevLine 
[e4c61dd]1import pointRadial from "../pointRadial.js";
2
3class Bump {
4 constructor(context, x) {
5 this._context = context;
6 this._x = x;
7 }
8 areaStart() {
9 this._line = 0;
10 }
11 areaEnd() {
12 this._line = NaN;
13 }
14 lineStart() {
15 this._point = 0;
16 }
17 lineEnd() {
18 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
19 this._line = 1 - this._line;
20 }
21 point(x, y) {
22 x = +x, y = +y;
23 switch (this._point) {
24 case 0: {
25 this._point = 1;
26 if (this._line) this._context.lineTo(x, y);
27 else this._context.moveTo(x, y);
28 break;
29 }
30 case 1: this._point = 2; // falls through
31 default: {
32 if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
33 else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
34 break;
35 }
36 }
37 this._x0 = x, this._y0 = y;
38 }
39}
40
41class BumpRadial {
42 constructor(context) {
43 this._context = context;
44 }
45 lineStart() {
46 this._point = 0;
47 }
48 lineEnd() {}
49 point(x, y) {
50 x = +x, y = +y;
51 if (this._point === 0) {
52 this._point = 1;
53 } else {
54 const p0 = pointRadial(this._x0, this._y0);
55 const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
56 const p2 = pointRadial(x, this._y0);
57 const p3 = pointRadial(x, y);
58 this._context.moveTo(...p0);
59 this._context.bezierCurveTo(...p1, ...p2, ...p3);
60 }
61 this._x0 = x, this._y0 = y;
62 }
63}
64
65export function bumpX(context) {
66 return new Bump(context, true);
67}
68
69export function bumpY(context) {
70 return new Bump(context, false);
71}
72
73export function bumpRadial(context) {
74 return new BumpRadial(context);
75}
Note: See TracBrowser for help on using the repository browser.