source: node_modules/victory-vendor/lib-vendor/d3-shape/src/curve/bump.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.bumpRadial = bumpRadial;
7exports.bumpX = bumpX;
8exports.bumpY = bumpY;
9var _pointRadial = _interopRequireDefault(require("../pointRadial.js"));
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11class Bump {
12 constructor(context, x) {
13 this._context = context;
14 this._x = x;
15 }
16 areaStart() {
17 this._line = 0;
18 }
19 areaEnd() {
20 this._line = NaN;
21 }
22 lineStart() {
23 this._point = 0;
24 }
25 lineEnd() {
26 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
27 this._line = 1 - this._line;
28 }
29 point(x, y) {
30 x = +x, y = +y;
31 switch (this._point) {
32 case 0:
33 {
34 this._point = 1;
35 if (this._line) this._context.lineTo(x, y);else this._context.moveTo(x, y);
36 break;
37 }
38 case 1:
39 this._point = 2;
40 // falls through
41 default:
42 {
43 if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
44 break;
45 }
46 }
47 this._x0 = x, this._y0 = y;
48 }
49}
50class BumpRadial {
51 constructor(context) {
52 this._context = context;
53 }
54 lineStart() {
55 this._point = 0;
56 }
57 lineEnd() {}
58 point(x, y) {
59 x = +x, y = +y;
60 if (this._point++ === 0) {
61 this._x0 = x, this._y0 = y;
62 } else {
63 const p0 = (0, _pointRadial.default)(this._x0, this._y0);
64 const p1 = (0, _pointRadial.default)(this._x0, this._y0 = (this._y0 + y) / 2);
65 const p2 = (0, _pointRadial.default)(x, this._y0);
66 const p3 = (0, _pointRadial.default)(x, y);
67 this._context.moveTo(...p0);
68 this._context.bezierCurveTo(...p1, ...p2, ...p3);
69 }
70 }
71}
72function bumpX(context) {
73 return new Bump(context, true);
74}
75function bumpY(context) {
76 return new Bump(context, false);
77}
78function bumpRadial(context) {
79 return new BumpRadial(context);
80}
Note: See TracBrowser for help on using the repository browser.