-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
500 lines (390 loc) · 17.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Rectangle = exports.Circle = exports.PolyLine = exports.SteppedLine = exports.Line = void 0;
var _react = _interopRequireWildcard(require("react"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var baseStyle = {
position: 'absolute',
zIndex: 10,
backgroundColor: '#000000'
};
function drawLine(from, to, lineWeight, componentStyle) {
var m = (to[1] - from[1]) / (to[0] - from[0]);
var line = [];
if (from[0] < to[0]) {
for (var x = from[0]; x <= to[0]; x += 0.1) {
var y = m * (x - to[0]) + to[1];
var pixel = _objectSpread({}, componentStyle, {
left: "".concat(x, "px"),
top: "".concat(y, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
line.push(_react["default"].createElement("div", {
style: pixel
}));
}
} else if (from[0] > to[0]) {
for (var _x = from[0]; _x >= to[0]; _x -= 0.1) {
var _y = m * (_x - to[0]) + to[1];
var _pixel = _objectSpread({}, componentStyle, {
left: "".concat(_x, "px"),
top: "".concat(_y, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
line.push(_react["default"].createElement("div", {
style: _pixel
}));
}
} else {
if (from[1] < to[1]) {
for (var _y2 = from[1]; _y2 <= to[1]; _y2 += 0.1) {
var _x2 = from[0];
var _pixel2 = _objectSpread({}, componentStyle, {
left: "".concat(_x2, "px"),
top: "".concat(_y2, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
line.push(_react["default"].createElement("div", {
style: _pixel2
}));
}
} else if (from[1] > to[1]) {
for (var _y3 = from[1]; _y3 >= to[1]; _y3 -= 0.1) {
var _x3 = from[0];
var _pixel3 = _objectSpread({}, componentStyle, {
left: "".concat(_x3, "px"),
top: "".concat(_y3, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
line.push(_react["default"].createElement("div", {
style: _pixel3
}));
}
} else {
var _x4 = from[0];
var _y4 = from[1];
var _pixel4 = _objectSpread({}, componentStyle, {
left: "".concat(_x4, "px"),
top: "".concat(_y4, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
line.push(_react["default"].createElement("div", {
style: _pixel4
}));
}
}
return line;
}
var Line =
/*#__PURE__*/
function (_Component) {
_inherits(Line, _Component);
function Line() {
_classCallCheck(this, Line);
return _possibleConstructorReturn(this, _getPrototypeOf(Line).apply(this, arguments));
}
_createClass(Line, [{
key: "render",
value: function render() {
var componentStyle = _objectSpread({}, baseStyle);
if (this.props.position === 'fixed') {
componentStyle.position = this.props.position;
}
var from;
this.props.from ? from = this.props.from : from = [0, 0];
var to;
this.props.to ? to = this.props.to : to = [0, 0];
var lineWeight;
this.props.lineWeight ? lineWeight = this.props.lineWeight : lineWeight = 3;
if (this.props.color) {
componentStyle.backgroundColor = this.props.color;
}
if (this.props.zIndex) {
componentStyle.zIndex = this.props.zIndex;
}
var line = drawLine(from, to, lineWeight, componentStyle);
return _react["default"].createElement("div", null, line);
}
}]);
return Line;
}(_react.Component);
exports.Line = Line;
var SteppedLine =
/*#__PURE__*/
function (_Component2) {
_inherits(SteppedLine, _Component2);
function SteppedLine() {
_classCallCheck(this, SteppedLine);
return _possibleConstructorReturn(this, _getPrototypeOf(SteppedLine).apply(this, arguments));
}
_createClass(SteppedLine, [{
key: "render",
value: function render() {
var componentStyle = _objectSpread({}, baseStyle);
if (this.props.position === 'fixed') {
componentStyle.position = this.props.position;
}
var from;
this.props.from ? from = this.props.from : from = [0, 0];
var to;
this.props.to ? to = this.props.to : to = [0, 0];
var lineWeight;
this.props.lineWeight ? lineWeight = this.props.lineWeight : lineWeight = 3;
if (this.props.color) {
componentStyle.backgroundColor = this.props.color;
}
if (this.props.zIndex) {
componentStyle.zIndex = this.props.zIndex;
}
var _from = from,
_from2 = _slicedToArray(_from, 2),
x1 = _from2[0],
y1 = _from2[1];
var _to = to,
_to2 = _slicedToArray(_to, 2),
x2 = _to2[0],
y2 = _to2[1];
var midx = x1 + (x2 - x1) / 2;
var line1 = _objectSpread({}, componentStyle, {
left: "".concat(midx >= x1 ? x1 : midx, "px"),
top: "".concat(y1, "px"),
width: "".concat(Math.abs((x2 - x1) / 2), "px"),
height: "".concat(lineWeight, "px")
});
var line2 = _objectSpread({}, componentStyle, {
left: "".concat(midx, "px"),
top: "".concat(y2 >= y1 ? y1 : y2, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(y2 - y1 === 0 ? 0 : Math.abs(y2 - y1) + lineWeight, "px")
});
var line3 = _objectSpread({}, componentStyle, {
left: "".concat(x2 >= midx ? midx : x2, "px"),
top: "".concat(y2, "px"),
width: "".concat(Math.abs((x2 - x1) / 2), "px"),
height: "".concat(lineWeight, "px")
});
return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement("div", {
style: line1
}), _react["default"].createElement("div", {
style: line2
}), _react["default"].createElement("div", {
style: line3
}));
}
}]);
return SteppedLine;
}(_react.Component);
exports.SteppedLine = SteppedLine;
var PolyLine =
/*#__PURE__*/
function (_Component3) {
_inherits(PolyLine, _Component3);
function PolyLine() {
_classCallCheck(this, PolyLine);
return _possibleConstructorReturn(this, _getPrototypeOf(PolyLine).apply(this, arguments));
}
_createClass(PolyLine, [{
key: "render",
value: function render() {
var componentStyle = _objectSpread({}, baseStyle);
if (this.props.position === 'fixed') {
componentStyle.position = this.props.position;
}
var lines = [];
var points;
if (this.props.points) {
var from = this.props.points.slice(0, -1);
var to = this.props.points.slice(1);
points = from.map(function (_, i) {
return [from[i], to[i]];
});
} else {
points = [[0, 0], [0, 0]];
}
var lineWeight;
this.props.lineWeight ? lineWeight = this.props.lineWeight : lineWeight = 3;
if (this.props.color) {
componentStyle.backgroundColor = this.props.color;
}
if (this.props.zIndex) {
componentStyle.zIndex = this.props.zIndex;
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = points[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
_from3 = _step$value[0],
_to3 = _step$value[1];
lines.push.apply(lines, _toConsumableArray(drawLine(_from3, _to3, lineWeight, componentStyle)));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return _react["default"].createElement("div", null, lines);
}
}]);
return PolyLine;
}(_react.Component);
exports.PolyLine = PolyLine;
var Circle =
/*#__PURE__*/
function (_Component4) {
_inherits(Circle, _Component4);
function Circle() {
_classCallCheck(this, Circle);
return _possibleConstructorReturn(this, _getPrototypeOf(Circle).apply(this, arguments));
}
_createClass(Circle, [{
key: "render",
value: function render() {
var componentStyle = _objectSpread({}, baseStyle);
if (this.props.position === 'fixed') {
componentStyle.position = this.props.position;
}
var circle = [];
var center;
this.props.center ? center = this.props.center : center = [0, 0];
var radius;
this.props.radius ? radius = this.props.radius : radius = 1;
var lineWeight;
this.props.lineWeight ? lineWeight = this.props.lineWeight : lineWeight = 3;
if (this.props.color) {
componentStyle.backgroundColor = this.props.color;
}
if (this.props.zIndex) {
componentStyle.zIndex = this.props.zIndex;
}
for (var x = center[0] - radius; x <= center[0] + radius; x += 0.01) {
var yb = center[1] + Math.sqrt(Math.pow(radius, 2) - Math.pow(x - center[0], 2));
var yt = center[1] - Math.sqrt(Math.pow(radius, 2) - Math.pow(x - center[0], 2));
var pixelB = _objectSpread({}, componentStyle, {
left: "".concat(x, "px"),
top: "".concat(yb, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
var pixelT = _objectSpread({}, componentStyle, {
left: "".concat(x, "px"),
top: "".concat(yt, "px"),
width: "".concat(lineWeight, "px"),
height: "".concat(lineWeight, "px")
});
circle.push(_react["default"].createElement("div", {
style: pixelB
}));
circle.push(_react["default"].createElement("div", {
style: pixelT
}));
}
return _react["default"].createElement("div", null, circle);
}
}]);
return Circle;
}(_react.Component);
exports.Circle = Circle;
var Rectangle =
/*#__PURE__*/
function (_Component5) {
_inherits(Rectangle, _Component5);
function Rectangle() {
_classCallCheck(this, Rectangle);
return _possibleConstructorReturn(this, _getPrototypeOf(Rectangle).apply(this, arguments));
}
_createClass(Rectangle, [{
key: "render",
value: function render() {
var componentStyle = _objectSpread({}, baseStyle);
if (this.props.position === 'fixed') {
componentStyle.position = this.props.position;
}
var rectangle = [];
var corner;
this.props.corner ? corner = this.props.corner : corner = [0, 0];
var height;
this.props.height ? height = this.props.height : height = 1;
var width;
this.props.width ? width = this.props.width : width = 1;
var lineWeight;
this.props.lineWeight ? lineWeight = this.props.lineWeight : lineWeight = 3;
if (this.props.color) {
componentStyle.backgroundColor = this.props.color;
}
if (this.props.zIndex) {
componentStyle.zIndex = this.props.zIndex;
}
var corners = [[corner[0], corner[1]], [corner[0] + width, corner[1]], [corner[0] + width, corner[1] + height], [corner[0], corner[1] + height], [corner[0], corner[1]]];
var from = corners.slice(0, -1);
var to = corners.slice(1);
var points = from.map(function (_, i) {
return [from[i], to[i]];
});
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = points[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
_from4 = _step2$value[0],
_to4 = _step2$value[1];
rectangle.push.apply(rectangle, _toConsumableArray(drawLine(_from4, _to4, lineWeight, componentStyle)));
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
_iterator2["return"]();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return _react["default"].createElement("div", null, rectangle);
}
}]);
return Rectangle;
}(_react.Component);
exports.Rectangle = Rectangle;