@pie-lib/plot 2.1.9 → 2.1.10-next.351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -222
- package/lib/draggable.js +20 -14
- package/lib/draggable.js.map +1 -1
- package/lib/graph-props.js +2 -4
- package/lib/graph-props.js.map +1 -1
- package/lib/grid-draggable.js +32 -22
- package/lib/grid-draggable.js.map +1 -1
- package/lib/index.js +14 -10
- package/lib/index.js.map +1 -1
- package/lib/root.js +40 -34
- package/lib/root.js.map +1 -1
- package/lib/trig.js +1 -1
- package/lib/trig.js.map +1 -1
- package/lib/types.js +1 -1
- package/lib/utils.js +8 -5
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/graph-props.js +3 -6
- package/src/root.jsx +18 -15
- package/src/utils.js +3 -3
package/lib/grid-draggable.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -23,11 +25,13 @@ var _invariant = _interopRequireDefault(require("invariant"));
|
|
|
23
25
|
|
|
24
26
|
var _d3Selection = require("d3-selection");
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
var _excluded = ["disabled", "onClick"];
|
|
27
29
|
|
|
28
|
-
function
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
31
|
|
|
30
|
-
function
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
35
|
|
|
32
36
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
33
37
|
|
|
@@ -35,11 +39,15 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
35
39
|
|
|
36
40
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
37
41
|
|
|
38
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
42
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
39
43
|
|
|
40
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
44
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
41
45
|
|
|
42
|
-
function
|
|
46
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
47
|
+
|
|
48
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
49
|
+
|
|
50
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
|
|
43
51
|
|
|
44
52
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
45
53
|
|
|
@@ -47,17 +55,21 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
47
55
|
|
|
48
56
|
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); } }
|
|
49
57
|
|
|
50
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
58
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
51
59
|
|
|
52
|
-
function
|
|
60
|
+
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
53
61
|
|
|
54
|
-
function
|
|
62
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
63
|
+
|
|
64
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
65
|
+
|
|
66
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
55
67
|
|
|
56
68
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
57
69
|
|
|
58
|
-
function
|
|
70
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
59
71
|
|
|
60
|
-
function
|
|
72
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
61
73
|
|
|
62
74
|
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; }
|
|
63
75
|
|
|
@@ -80,17 +92,15 @@ exports.deltaFn = deltaFn;
|
|
|
80
92
|
|
|
81
93
|
var gridDraggable = function gridDraggable(opts) {
|
|
82
94
|
return function (Comp) {
|
|
83
|
-
var _class
|
|
95
|
+
var _class;
|
|
84
96
|
|
|
85
97
|
(0, _invariant["default"])(!!opts && (0, _isFunction["default"])(opts.fromDelta) && (0, _isFunction["default"])(opts.bounds) && (0, _isFunction["default"])(opts.anchorPoint), 'You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }');
|
|
86
|
-
return
|
|
87
|
-
/*#__PURE__*/
|
|
88
|
-
function (_React$Component) {
|
|
98
|
+
return _class = /*#__PURE__*/function (_React$Component) {
|
|
89
99
|
_inherits(GridDraggable, _React$Component);
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
var _getPrototypeOf2;
|
|
101
|
+
var _super = _createSuper(GridDraggable);
|
|
93
102
|
|
|
103
|
+
function GridDraggable() {
|
|
94
104
|
var _this;
|
|
95
105
|
|
|
96
106
|
_classCallCheck(this, GridDraggable);
|
|
@@ -99,7 +109,7 @@ var gridDraggable = function gridDraggable(opts) {
|
|
|
99
109
|
args[_key] = arguments[_key];
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
_this =
|
|
112
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
103
113
|
|
|
104
114
|
_defineProperty(_assertThisInitialized(_this), "grid", function () {
|
|
105
115
|
var graphProps = _this.props.graphProps;
|
|
@@ -315,7 +325,7 @@ var gridDraggable = function gridDraggable(opts) {
|
|
|
315
325
|
var _this$props3 = this.props,
|
|
316
326
|
disabled = _this$props3.disabled,
|
|
317
327
|
onClick = _this$props3.onClick,
|
|
318
|
-
rest = _objectWithoutProperties(_this$props3,
|
|
328
|
+
rest = _objectWithoutProperties(_this$props3, _excluded);
|
|
319
329
|
/* eslint-enable no-unused-vars */
|
|
320
330
|
|
|
321
331
|
|
|
@@ -331,7 +341,7 @@ var gridDraggable = function gridDraggable(opts) {
|
|
|
331
341
|
|
|
332
342
|
|
|
333
343
|
var isDragging = this.state ? !!this.state.startX : false;
|
|
334
|
-
return _react["default"].createElement(_draggable.DraggableCore, {
|
|
344
|
+
return /*#__PURE__*/_react["default"].createElement(_draggable.DraggableCore, {
|
|
335
345
|
disabled: disabled,
|
|
336
346
|
onMouseDown: onMouseDown,
|
|
337
347
|
onStart: this.onStart,
|
|
@@ -339,7 +349,7 @@ var gridDraggable = function gridDraggable(opts) {
|
|
|
339
349
|
onStop: this.onStop,
|
|
340
350
|
axis: opts.axis || 'both',
|
|
341
351
|
grid: [grid.x, grid.y]
|
|
342
|
-
}, _react["default"].createElement(Comp, _extends({}, rest, {
|
|
352
|
+
}, /*#__PURE__*/_react["default"].createElement(Comp, _extends({}, rest, {
|
|
343
353
|
disabled: disabled,
|
|
344
354
|
isDragging: isDragging
|
|
345
355
|
})));
|
|
@@ -355,7 +365,7 @@ var gridDraggable = function gridDraggable(opts) {
|
|
|
355
365
|
onClick: _propTypes["default"].func,
|
|
356
366
|
onMove: _propTypes["default"].func,
|
|
357
367
|
graphProps: _types.GraphPropsType.isRequired
|
|
358
|
-
}),
|
|
368
|
+
}), _class;
|
|
359
369
|
};
|
|
360
370
|
};
|
|
361
371
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/grid-draggable.jsx"],"names":["log","deltaFn","scale","snap","val","delta","normalized","inverted","invert","gridDraggable","opts","Comp","fromDelta","bounds","anchorPoint","graphProps","props","domain","range","x","step","y","e","onDragStart","document","activeElement","blur","setState","startX","clientX","startY","clientY","key","event","K","toUpperCase","end","start","state","Math","abs","out","grid","scaled","left","interval","right","top","bottom","dd","rootNode","getRootNode","rawX","rawY","xOutside","deltaX","min","max","yOutside","deltaY","onDrag","getScaledBounds","skipDragOutsideOfBounds","dragArg","applyDelta","undefined","point","pos","position","p","utils","getDelta","onDragStop","onClick","lastX","lastY","isClick","tiny","target","disabled","rest","onMouseDown","nativeEvent","preventDefault","isDragging","onStart","onStop","axis","React","Component","PropTypes","bool","func","onMove","GraphPropsType","isRequired"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AACO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,KAAD,EAAQC,IAAR,EAAcC,GAAd;AAAA,SAAsB,UAAAC,KAAK,EAAI;AACpD,QAAMC,UAAU,GAAGD,KAAK,GAAGH,KAAK,CAAC,CAAD,CAAhC;AACA,QAAMK,QAAQ,GAAGL,KAAK,CAACM,MAAN,CAAaF,UAAb,CAAjB;AACA,WAAOH,IAAI,CAACC,GAAG,GAAGG,QAAP,CAAX;AACD,GAJsB;AAAA,CAAhB;AAKP;;;;;;;;AAIO,IAAME,aAAa,GAAG,SAAhBA,aAAgB,CAAAC,IAAI;AAAA,SAAI,UAAAC,IAAI,EAAI;AAAA;;AAC3C,+BACE,CAAC,CAACD,IAAF,IAAU,4BAAWA,IAAI,CAACE,SAAhB,CAAV,IAAwC,4BAAWF,IAAI,CAACG,MAAhB,CAAxC,IAAmE,4BAAWH,IAAI,CAACI,WAAhB,CADrE,EAEE,kGAFF;AAIA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA,+DAUS,YAAM;AAAA,cACHC,UADG,GACY,MAAKC,KADj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AC,wBAAD;AACE,YAAA,QAAQ,EAAEmD,QADZ;AAEE,YAAA,WAAW,EAAEE,WAFf;AAGE,YAAA,OAAO,EAAE,KAAKI,OAHhB;AAIE,YAAA,MAAM,EAAE,KAAKzB,MAJf;AAKE,YAAA,MAAM,EAAE,KAAK0B,MALf;AAME,YAAA,IAAI,EAAE5E,IAAI,CAAC6E,IAAL,IAAa,MANrB;AAOE,YAAA,IAAI,EAAE,CAAC7C,IAAI,CAACvB,CAAN,EAASuB,IAAI,CAACrB,CAAd;AAPR,aASE,gCAAC,IAAD,eAAU2D,IAAV;AAAgB,YAAA,QAAQ,EAAED,QAA1B;AAAoC,YAAA,UAAU,EAAEK;AAAhD,aATF,CADF;AAaD;AAlMH;;AAAA;AAAA,MAAmCI,kBAAMC,SAAzC,wCACqB;AACjBV,MAAAA,QAAQ,EAAEW,sBAAUC,IADH;AAEjBpE,MAAAA,WAAW,EAAEmE,sBAAUE,IAFN;AAGjBhC,MAAAA,MAAM,EAAE8B,sBAAUE,IAHD;AAIjBpB,MAAAA,UAAU,EAAEkB,sBAAUE,IAJL;AAKjBnB,MAAAA,OAAO,EAAEiB,sBAAUE,IALF;AAMjBC,MAAAA,MAAM,EAAEH,sBAAUE,IAND;AAOjB7E,MAAAA,UAAU,EAAE+E,sBAAeC;AAPV,KADrB;AAoMD,GAzMgC;AAAA,CAA1B","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { DraggableCore } from './draggable';\nimport debug from 'debug';\nimport * as utils from './utils';\nimport isFunction from 'lodash/isFunction';\nimport invariant from 'invariant';\nimport { clientPoint } from 'd3-selection';\nconst log = debug('pie-lib:plot:grid-draggable');\nexport const deltaFn = (scale, snap, val) => delta => {\n const normalized = delta + scale(0);\n const inverted = scale.invert(normalized);\n return snap(val + inverted);\n};\n/**\n * Creates a Component that is draggable, within a bounded grid.\n * @param {*} opts\n */\nexport const gridDraggable = opts => Comp => {\n invariant(\n !!opts && isFunction(opts.fromDelta) && isFunction(opts.bounds) && isFunction(opts.anchorPoint),\n 'You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }'\n );\n return class GridDraggable extends React.Component {\n static propTypes = {\n disabled: PropTypes.bool,\n onDragStart: PropTypes.func,\n onDrag: PropTypes.func,\n onDragStop: PropTypes.func,\n onClick: PropTypes.func,\n onMove: PropTypes.func,\n graphProps: GraphPropsType.isRequired\n };\n grid = () => {\n const { graphProps } = this.props;\n const { scale, domain, range } = graphProps;\n return {\n x: scale.x(domain.step) - scale.x(0),\n y: scale.y(range.step) - scale.y(0)\n };\n };\n onStart = e => {\n const { onDragStart } = this.props;\n if (document.activeElement) {\n document.activeElement.blur();\n }\n this.setState({ startX: e.clientX, startY: e.clientY });\n if (onDragStart) {\n onDragStart();\n }\n };\n position = () => {\n const { x, y } = opts.anchorPoint(this.props);\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n return {\n anchorPoint: {\n x,\n y\n },\n x: deltaFn(scale.x, snap.x, x),\n y: deltaFn(scale.y, snap.y, y)\n };\n };\n\n tiny = (key, event) => {\n const K = key.toUpperCase();\n const end = event[`client${K}`];\n const start = this.state[`start${K}`];\n const delta = Math.abs(end - start);\n const out = delta < Math.abs(this.grid()[key]) / 10;\n log('[tiny] key: ', key, 'delta: ', delta, 'out: ', out);\n return out;\n };\n\n getScaledBounds = () => {\n const bounds = opts.bounds(this.props, this.props.graphProps);\n log('bounds: ', bounds);\n const grid = this.grid();\n\n const scaled = {\n left: (bounds.left / grid.interval) * grid.x,\n right: (bounds.right / grid.interval) * grid.x,\n top: (bounds.top / grid.interval) * grid.y,\n bottom: (bounds.bottom / grid.interval) * grid.y\n };\n log('[getScaledBounds]: ', scaled);\n return scaled;\n };\n\n skipDragOutsideOfBounds = (dd, e, graphProps) => {\n // ignore drag movement outside of the domain and range.\n const rootNode = graphProps.getRootNode();\n const [rawX, rawY] = clientPoint(rootNode, e);\n const { scale, domain, range } = graphProps;\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n\n const xOutside = (dd.deltaX > 0 && x < domain.min) || (dd.deltaX < 0 && x > domain.max);\n const yOutside = (dd.deltaY > 0 && y > range.max) || (dd.deltaY < 0 && y < range.min);\n return xOutside || yOutside;\n };\n\n onDrag = (e, dd) => {\n const { onDrag, graphProps } = this.props;\n\n if (!onDrag) {\n return;\n }\n\n const bounds = this.getScaledBounds();\n\n if (dd.deltaX < 0 && dd.deltaX < bounds.left) {\n return;\n }\n\n if (dd.deltaX > 0 && dd.deltaX > bounds.right) {\n return;\n }\n\n if (dd.deltaY < 0 && dd.deltaY < bounds.top) {\n return;\n }\n\n if (dd.deltaY > 0 && dd.deltaY > bounds.bottom) {\n return;\n }\n\n if (this.skipDragOutsideOfBounds(dd, e, graphProps)) {\n return;\n }\n\n const dragArg = this.applyDelta({ x: dd.deltaX, y: dd.deltaY });\n\n if (dragArg !== undefined || dragArg !== null) {\n onDrag(dragArg);\n }\n };\n\n getDelta = point => {\n const pos = this.position();\n\n const p = {\n x: pos.x(point.x),\n y: pos.y(point.y)\n };\n\n return utils.getDelta(pos.anchorPoint, p);\n };\n\n applyDelta = point => {\n const delta = this.getDelta(point);\n log('[applyDelta] delta:', delta);\n return opts.fromDelta(this.props, delta);\n };\n\n onStop = (e, dd) => {\n log('[onStop] dd:', dd);\n const { onDragStop, onClick } = this.props;\n\n if (onDragStop) {\n onDragStop();\n }\n\n log('[onStop] lastX/Y: ', dd.lastX, dd.lastY);\n const isClick = this.tiny('x', e) && this.tiny('y', e);\n\n if (isClick) {\n if (onClick) {\n log('call onClick');\n this.setState({ startX: null });\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n const [rawX, rawY] = clientPoint(e.target, e);\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n x = snap.x(x);\n y = snap.y(y);\n onClick({ x, y });\n return false;\n }\n }\n\n this.setState({ startX: null, startY: null });\n // return false to prevent state updates in the underlying draggable - a move will have triggered an update already.\n return false;\n };\n\n render() {\n /* eslint-disable no-unused-vars */\n //Note: we pull onClick out so that it's not in ...rest.\n const { disabled, onClick, ...rest } = this.props;\n /* eslint-enable no-unused-vars */\n\n const grid = this.grid();\n //prevent the text select icon from rendering.\n const onMouseDown = e => e.nativeEvent.preventDefault();\n\n /**\n * TODO: This shouldnt be necessary, we should be able to use the r-d classnames.\n * But they aren't being unset. If we continue with this lib, we'll have to fix this.\n */\n const isDragging = this.state ? !!this.state.startX : false;\n\n return (\n <DraggableCore\n disabled={disabled}\n onMouseDown={onMouseDown}\n onStart={this.onStart}\n onDrag={this.onDrag}\n onStop={this.onStop}\n axis={opts.axis || 'both'}\n grid={[grid.x, grid.y]}\n >\n <Comp {...rest} disabled={disabled} isDragging={isDragging} />\n </DraggableCore>\n );\n }\n };\n};\n"],"file":"grid-draggable.js"}
|
|
1
|
+
{"version":3,"sources":["../src/grid-draggable.jsx"],"names":["log","deltaFn","scale","snap","val","delta","normalized","inverted","invert","gridDraggable","opts","Comp","fromDelta","bounds","anchorPoint","graphProps","props","domain","range","x","step","y","e","onDragStart","document","activeElement","blur","setState","startX","clientX","startY","clientY","key","event","K","toUpperCase","end","start","state","Math","abs","out","grid","scaled","left","interval","right","top","bottom","dd","rootNode","getRootNode","rawX","rawY","xOutside","deltaX","min","max","yOutside","deltaY","onDrag","getScaledBounds","skipDragOutsideOfBounds","dragArg","applyDelta","undefined","point","pos","position","p","utils","getDelta","onDragStop","onClick","lastX","lastY","isClick","tiny","target","disabled","rest","onMouseDown","nativeEvent","preventDefault","isDragging","onStart","onStop","axis","React","Component","PropTypes","bool","func","onMove","GraphPropsType","isRequired"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AACO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,KAAD,EAAQ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AAEW,sBAAUC,IADH;AAEjBpE,MAAAA,WAAW,EAAEmE,sBAAUE,IAFN;AAGjBhC,MAAAA,MAAM,EAAE8B,sBAAUE,IAHD;AAIjBpB,MAAAA,UAAU,EAAEkB,sBAAUE,IAJL;AAKjBnB,MAAAA,OAAO,EAAEiB,sBAAUE,IALF;AAMjBC,MAAAA,MAAM,EAAEH,sBAAUE,IAND;AAOjB7E,MAAAA,UAAU,EAAE+E,sBAAeC;AAPV,KADrB;AAoMD,GAzMgC;AAAA,CAA1B","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { DraggableCore } from './draggable';\nimport debug from 'debug';\nimport * as utils from './utils';\nimport isFunction from 'lodash/isFunction';\nimport invariant from 'invariant';\nimport { clientPoint } from 'd3-selection';\nconst log = debug('pie-lib:plot:grid-draggable');\nexport const deltaFn = (scale, snap, val) => delta => {\n const normalized = delta + scale(0);\n const inverted = scale.invert(normalized);\n return snap(val + inverted);\n};\n/**\n * Creates a Component that is draggable, within a bounded grid.\n * @param {*} opts\n */\nexport const gridDraggable = opts => Comp => {\n invariant(\n !!opts && isFunction(opts.fromDelta) && isFunction(opts.bounds) && isFunction(opts.anchorPoint),\n 'You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }'\n );\n return class GridDraggable extends React.Component {\n static propTypes = {\n disabled: PropTypes.bool,\n onDragStart: PropTypes.func,\n onDrag: PropTypes.func,\n onDragStop: PropTypes.func,\n onClick: PropTypes.func,\n onMove: PropTypes.func,\n graphProps: GraphPropsType.isRequired\n };\n grid = () => {\n const { graphProps } = this.props;\n const { scale, domain, range } = graphProps;\n return {\n x: scale.x(domain.step) - scale.x(0),\n y: scale.y(range.step) - scale.y(0)\n };\n };\n onStart = e => {\n const { onDragStart } = this.props;\n if (document.activeElement) {\n document.activeElement.blur();\n }\n this.setState({ startX: e.clientX, startY: e.clientY });\n if (onDragStart) {\n onDragStart();\n }\n };\n position = () => {\n const { x, y } = opts.anchorPoint(this.props);\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n return {\n anchorPoint: {\n x,\n y\n },\n x: deltaFn(scale.x, snap.x, x),\n y: deltaFn(scale.y, snap.y, y)\n };\n };\n\n tiny = (key, event) => {\n const K = key.toUpperCase();\n const end = event[`client${K}`];\n const start = this.state[`start${K}`];\n const delta = Math.abs(end - start);\n const out = delta < Math.abs(this.grid()[key]) / 10;\n log('[tiny] key: ', key, 'delta: ', delta, 'out: ', out);\n return out;\n };\n\n getScaledBounds = () => {\n const bounds = opts.bounds(this.props, this.props.graphProps);\n log('bounds: ', bounds);\n const grid = this.grid();\n\n const scaled = {\n left: (bounds.left / grid.interval) * grid.x,\n right: (bounds.right / grid.interval) * grid.x,\n top: (bounds.top / grid.interval) * grid.y,\n bottom: (bounds.bottom / grid.interval) * grid.y\n };\n log('[getScaledBounds]: ', scaled);\n return scaled;\n };\n\n skipDragOutsideOfBounds = (dd, e, graphProps) => {\n // ignore drag movement outside of the domain and range.\n const rootNode = graphProps.getRootNode();\n const [rawX, rawY] = clientPoint(rootNode, e);\n const { scale, domain, range } = graphProps;\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n\n const xOutside = (dd.deltaX > 0 && x < domain.min) || (dd.deltaX < 0 && x > domain.max);\n const yOutside = (dd.deltaY > 0 && y > range.max) || (dd.deltaY < 0 && y < range.min);\n return xOutside || yOutside;\n };\n\n onDrag = (e, dd) => {\n const { onDrag, graphProps } = this.props;\n\n if (!onDrag) {\n return;\n }\n\n const bounds = this.getScaledBounds();\n\n if (dd.deltaX < 0 && dd.deltaX < bounds.left) {\n return;\n }\n\n if (dd.deltaX > 0 && dd.deltaX > bounds.right) {\n return;\n }\n\n if (dd.deltaY < 0 && dd.deltaY < bounds.top) {\n return;\n }\n\n if (dd.deltaY > 0 && dd.deltaY > bounds.bottom) {\n return;\n }\n\n if (this.skipDragOutsideOfBounds(dd, e, graphProps)) {\n return;\n }\n\n const dragArg = this.applyDelta({ x: dd.deltaX, y: dd.deltaY });\n\n if (dragArg !== undefined || dragArg !== null) {\n onDrag(dragArg);\n }\n };\n\n getDelta = point => {\n const pos = this.position();\n\n const p = {\n x: pos.x(point.x),\n y: pos.y(point.y)\n };\n\n return utils.getDelta(pos.anchorPoint, p);\n };\n\n applyDelta = point => {\n const delta = this.getDelta(point);\n log('[applyDelta] delta:', delta);\n return opts.fromDelta(this.props, delta);\n };\n\n onStop = (e, dd) => {\n log('[onStop] dd:', dd);\n const { onDragStop, onClick } = this.props;\n\n if (onDragStop) {\n onDragStop();\n }\n\n log('[onStop] lastX/Y: ', dd.lastX, dd.lastY);\n const isClick = this.tiny('x', e) && this.tiny('y', e);\n\n if (isClick) {\n if (onClick) {\n log('call onClick');\n this.setState({ startX: null });\n const { graphProps } = this.props;\n const { scale, snap } = graphProps;\n const [rawX, rawY] = clientPoint(e.target, e);\n let x = scale.x.invert(rawX);\n let y = scale.y.invert(rawY);\n x = snap.x(x);\n y = snap.y(y);\n onClick({ x, y });\n return false;\n }\n }\n\n this.setState({ startX: null, startY: null });\n // return false to prevent state updates in the underlying draggable - a move will have triggered an update already.\n return false;\n };\n\n render() {\n /* eslint-disable no-unused-vars */\n //Note: we pull onClick out so that it's not in ...rest.\n const { disabled, onClick, ...rest } = this.props;\n /* eslint-enable no-unused-vars */\n\n const grid = this.grid();\n //prevent the text select icon from rendering.\n const onMouseDown = e => e.nativeEvent.preventDefault();\n\n /**\n * TODO: This shouldnt be necessary, we should be able to use the r-d classnames.\n * But they aren't being unset. If we continue with this lib, we'll have to fix this.\n */\n const isDragging = this.state ? !!this.state.startX : false;\n\n return (\n <DraggableCore\n disabled={disabled}\n onMouseDown={onMouseDown}\n onStart={this.onStart}\n onDrag={this.onDrag}\n onStop={this.onStop}\n axis={opts.axis || 'both'}\n grid={[grid.x, grid.y]}\n >\n <Comp {...rest} disabled={disabled} isDragging={isDragging} />\n </DraggableCore>\n );\n }\n };\n};\n"],"file":"grid-draggable.js"}
|
package/lib/index.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
Object.defineProperty(exports, "Root", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _root["default"];
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
8
|
Object.defineProperty(exports, "Draggable", {
|
|
13
9
|
enumerable: true,
|
|
14
10
|
get: function get() {
|
|
15
11
|
return _draggable["default"];
|
|
16
12
|
}
|
|
17
13
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
14
|
+
Object.defineProperty(exports, "Root", {
|
|
19
15
|
enumerable: true,
|
|
20
16
|
get: function get() {
|
|
21
|
-
return
|
|
17
|
+
return _root["default"];
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
20
|
Object.defineProperty(exports, "createGraphProps", {
|
|
@@ -27,7 +23,13 @@ Object.defineProperty(exports, "createGraphProps", {
|
|
|
27
23
|
return _graphProps.create;
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
|
-
|
|
26
|
+
Object.defineProperty(exports, "gridDraggable", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _gridDraggable.gridDraggable;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.utils = exports.types = exports.trig = void 0;
|
|
31
33
|
|
|
32
34
|
var _root = _interopRequireDefault(require("./root"));
|
|
33
35
|
|
|
@@ -49,7 +51,9 @@ exports.types = types;
|
|
|
49
51
|
|
|
50
52
|
var _graphProps = require("./graph-props");
|
|
51
53
|
|
|
52
|
-
function
|
|
54
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
55
|
+
|
|
56
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
53
57
|
|
|
54
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
55
59
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AACA;;;;AACA;;;;AACA","sourcesContent":["import Root from './root';\nimport Draggable from './draggable';\nimport { gridDraggable } from './grid-draggable';\nimport * as utils from './utils';\nimport * as trig from './trig';\nimport * as types from './types';\nimport { create as createGraphProps } from './graph-props';\n\nexport { Root, Draggable, gridDraggable, utils, trig, types, createGraphProps };\n"],"file":"index.js"}
|
package/lib/root.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -19,27 +21,27 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
19
21
|
|
|
20
22
|
var _renderUi = require("@pie-lib/render-ui");
|
|
21
23
|
|
|
22
|
-
var _utils = require("./utils");
|
|
23
|
-
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
25
|
|
|
26
|
-
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); }
|
|
27
|
-
|
|
28
26
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
29
27
|
|
|
30
28
|
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); } }
|
|
31
29
|
|
|
32
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
30
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
33
31
|
|
|
34
|
-
function
|
|
32
|
+
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
35
33
|
|
|
36
|
-
function
|
|
34
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
+
|
|
36
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
|
+
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
37
39
|
|
|
38
40
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
41
|
|
|
40
|
-
function
|
|
42
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
43
|
|
|
42
|
-
function
|
|
44
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
45
|
|
|
44
46
|
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; }
|
|
45
47
|
|
|
@@ -55,22 +57,23 @@ var GraphTitle = (0, _styles.withStyles)(function (theme) {
|
|
|
55
57
|
})(function (_ref) {
|
|
56
58
|
var value = _ref.value,
|
|
57
59
|
classes = _ref.classes;
|
|
58
|
-
return _react["default"].createElement(_Typography["default"], {
|
|
60
|
+
return /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
59
61
|
className: classes.title,
|
|
62
|
+
color: "primary",
|
|
60
63
|
variant: "h5",
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
dangerouslySetInnerHTML: {
|
|
65
|
+
__html: value
|
|
66
|
+
}
|
|
67
|
+
});
|
|
63
68
|
});
|
|
64
69
|
exports.GraphTitle = GraphTitle;
|
|
65
70
|
|
|
66
|
-
var Root =
|
|
67
|
-
/*#__PURE__*/
|
|
68
|
-
function (_React$Component) {
|
|
71
|
+
var Root = /*#__PURE__*/function (_React$Component) {
|
|
69
72
|
_inherits(Root, _React$Component);
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
var _getPrototypeOf2;
|
|
74
|
+
var _super = _createSuper(Root);
|
|
73
75
|
|
|
76
|
+
function Root() {
|
|
74
77
|
var _this;
|
|
75
78
|
|
|
76
79
|
_classCallCheck(this, Root);
|
|
@@ -79,7 +82,7 @@ function (_React$Component) {
|
|
|
79
82
|
args[_key] = arguments[_key];
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
_this =
|
|
85
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
83
86
|
|
|
84
87
|
_defineProperty(_assertThisInitialized(_this), "mouseMove", function (g) {
|
|
85
88
|
var _this$props = _this.props,
|
|
@@ -127,24 +130,28 @@ function (_React$Component) {
|
|
|
127
130
|
children = _this$props2.children,
|
|
128
131
|
classes = _this$props2.classes,
|
|
129
132
|
title = _this$props2.title,
|
|
130
|
-
rootRef = _this$props2.rootRef
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var
|
|
139
|
-
|
|
133
|
+
rootRef = _this$props2.rootRef;
|
|
134
|
+
var _graphProps$size = graphProps.size,
|
|
135
|
+
_graphProps$size$widt = _graphProps$size.width,
|
|
136
|
+
width = _graphProps$size$widt === void 0 ? 500 : _graphProps$size$widt,
|
|
137
|
+
_graphProps$size$heig = _graphProps$size.height,
|
|
138
|
+
height = _graphProps$size$heig === void 0 ? 500 : _graphProps$size$heig,
|
|
139
|
+
domain = graphProps.domain,
|
|
140
|
+
range = graphProps.range;
|
|
141
|
+
var topPadding = 50;
|
|
142
|
+
var leftPadding = topPadding + 10; // left side requires an extra padding of 10
|
|
143
|
+
|
|
144
|
+
var finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;
|
|
145
|
+
var finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;
|
|
146
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
140
147
|
className: classes.root
|
|
141
|
-
}, title && _react["default"].createElement(GraphTitle, {
|
|
148
|
+
}, title && /*#__PURE__*/_react["default"].createElement(GraphTitle, {
|
|
142
149
|
value: title
|
|
143
|
-
}), _react["default"].createElement("svg", {
|
|
150
|
+
}), /*#__PURE__*/_react["default"].createElement("svg", {
|
|
144
151
|
width: finalWidth,
|
|
145
152
|
height: finalHeight,
|
|
146
153
|
className: classes.svg
|
|
147
|
-
}, _react["default"].createElement("g", {
|
|
154
|
+
}, /*#__PURE__*/_react["default"].createElement("g", {
|
|
148
155
|
ref: function ref(r) {
|
|
149
156
|
_this2.g = r;
|
|
150
157
|
|
|
@@ -153,7 +160,7 @@ function (_React$Component) {
|
|
|
153
160
|
}
|
|
154
161
|
},
|
|
155
162
|
className: classes.graphBox,
|
|
156
|
-
transform: "translate(".concat(
|
|
163
|
+
transform: "translate(".concat(leftPadding, ", ").concat(topPadding, ")")
|
|
157
164
|
}, children)));
|
|
158
165
|
}
|
|
159
166
|
}]);
|
|
@@ -169,8 +176,7 @@ _defineProperty(Root, "propTypes", {
|
|
|
169
176
|
graphProps: _types.GraphPropsType.isRequired,
|
|
170
177
|
onMouseMove: _propTypes["default"].func,
|
|
171
178
|
classes: _propTypes["default"].object.isRequired,
|
|
172
|
-
rootRef: _propTypes["default"].func
|
|
173
|
-
paddingLeft: _propTypes["default"].number
|
|
179
|
+
rootRef: _propTypes["default"].func
|
|
174
180
|
});
|
|
175
181
|
|
|
176
182
|
var styles = function styles() {
|
package/lib/root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/root.jsx"],"names":["GraphTitle","theme","title","color","text","textAlign","paddingTop","spacing","unit","fontSize","typography","value","classes","Root","g","props","graphProps","onMouseMove","scale","snap","coords","_groups","x","invert","y","snapped","on","mouseMove","bind","children","rootRef","
|
|
1
|
+
{"version":3,"sources":["../src/root.jsx"],"names":["GraphTitle","theme","title","color","text","textAlign","paddingTop","spacing","unit","fontSize","typography","value","classes","__html","Root","g","props","graphProps","onMouseMove","scale","snap","coords","_groups","x","invert","y","snapped","on","mouseMove","bind","children","rootRef","size","width","height","domain","range","topPadding","leftPadding","finalWidth","padding","finalHeight","root","svg","r","graphBox","React","Component","PropTypes","string","ChildrenType","GraphPropsType","isRequired","func","object","styles","border","primaryLight","backgroundColor","background","cursor","userSelect"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAMA,UAAU,GAAG,wBAAW,UAAAC,KAAK;AAAA,SAAK;AAC7CC,IAAAA,KAAK,EAAE;AACLC,MAAAA,KAAK,EAAEA,gBAAMC,IAAN,EADF;AAELC,MAAAA,SAAS,EAAE,QAFN;AAGLC,MAAAA,UAAU,EAAEL,KAAK,CAACM,OAAN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AAK,EAAEqC,UAAZ;AAAwB,QAAA,MAAM,EAAEE,WAAhC;AAA6C,QAAA,SAAS,EAAE7B,OAAO,CAAC+B;AAAhE,sBACE;AACE,QAAA,GAAG,EAAE,aAAAC,CAAC,EAAI;AACR,UAAA,MAAI,CAAC7B,CAAL,GAAS6B,CAAT;;AACA,cAAIb,OAAJ,EAAa;AACXA,YAAAA,OAAO,CAACa,CAAD,CAAP;AACD;AACF,SANH;AAOE,QAAA,SAAS,EAAEhC,OAAO,CAACiC,QAPrB;AAQE,QAAA,SAAS,sBAAeP,WAAf,eAA+BD,UAA/B;AARX,SAUGP,QAVH,CADF,CAFF,CADF;AAmBD;;;;EAvEuBgB,kBAAMC,S;;;;gBAAnBjC,I,eACQ;AACjBZ,EAAAA,KAAK,EAAE8C,sBAAUC,MADA;AAEjBnB,EAAAA,QAAQ,EAAEoB,mBAFO;AAGjBjC,EAAAA,UAAU,EAAEkC,sBAAeC,UAHV;AAIjBlC,EAAAA,WAAW,EAAE8B,sBAAUK,IAJN;AAKjBzC,EAAAA,OAAO,EAAEoC,sBAAUM,MAAV,CAAiBF,UALT;AAMjBrB,EAAAA,OAAO,EAAEiB,sBAAUK;AANF,C;;AAwErB,IAAME,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO;AACpBb,IAAAA,IAAI,EAAE;AACJc,MAAAA,MAAM,sBAAerD,gBAAMsD,YAAN,EAAf,CADF;AAEJtD,MAAAA,KAAK,EAAEA,gBAAMC,IAAN,EAFH;AAGJsD,MAAAA,eAAe,EAAEvD,gBAAMwD,UAAN;AAHb,KADc;AAMpBhB,IAAAA,GAAG,EAAE,EANe;AAOpBE,IAAAA,QAAQ,EAAE;AACRe,MAAAA,MAAM,EAAE,SADA;AAERC,MAAAA,UAAU,EAAE;AAFJ;AAPU,GAAP;AAAA,CAAf;;eAae,wBAAWN,MAAX,EAAmBzC,IAAnB,C","sourcesContent":["import React from 'react';\nimport { ChildrenType } from './types';\nimport { withStyles } from '@material-ui/core/styles';\nimport Typography from '@material-ui/core/Typography';\nimport { select, mouse } from 'd3-selection';\nimport PropTypes from 'prop-types';\nimport { GraphPropsType } from './types';\nimport { color } from '@pie-lib/render-ui';\n\nexport const GraphTitle = withStyles(theme => ({\n title: {\n color: color.text(),\n textAlign: 'center',\n paddingTop: theme.spacing.unit * 2,\n fontSize: theme.typography.fontSize + 6\n }\n}))(({ value, classes }) => (\n <Typography\n className={classes.title}\n color=\"primary\"\n variant=\"h5\"\n dangerouslySetInnerHTML={{ __html: value }}\n />\n));\n\nexport class Root extends React.Component {\n static propTypes = {\n title: PropTypes.string,\n children: ChildrenType,\n graphProps: GraphPropsType.isRequired,\n onMouseMove: PropTypes.func,\n classes: PropTypes.object.isRequired,\n rootRef: PropTypes.func\n };\n\n mouseMove = g => {\n const { graphProps, onMouseMove } = this.props;\n\n if (!onMouseMove) {\n return;\n }\n\n const { scale, snap } = graphProps;\n const coords = mouse(g._groups[0][0]);\n const x = scale.x.invert(coords[0]);\n const y = scale.y.invert(coords[1]);\n\n const snapped = {\n x: snap.x(x),\n y: snap.y(y)\n };\n\n onMouseMove(snapped);\n };\n\n componentDidMount() {\n const g = select(this.g);\n g.on('mousemove', this.mouseMove.bind(this, g));\n }\n\n componentWillUnmount() {\n const g = select(this.g);\n g.on('mousemove', null);\n }\n\n render() {\n const { graphProps, children, classes, title, rootRef } = this.props;\n const {\n size: { width = 500, height = 500 },\n domain,\n range\n } = graphProps;\n const topPadding = 50;\n const leftPadding = topPadding + 10; // left side requires an extra padding of 10\n const finalWidth = width + leftPadding * 2 + (domain.padding || 0) * 2;\n const finalHeight = height + topPadding * 2 + (range.padding || 0) * 2;\n\n return (\n <div className={classes.root}>\n {title && <GraphTitle value={title} />}\n <svg width={finalWidth} height={finalHeight} className={classes.svg}>\n <g\n ref={r => {\n this.g = r;\n if (rootRef) {\n rootRef(r);\n }\n }}\n className={classes.graphBox}\n transform={`translate(${leftPadding}, ${topPadding})`}\n >\n {children}\n </g>\n </svg>\n </div>\n );\n }\n}\nconst styles = () => ({\n root: {\n border: `solid 1px ${color.primaryLight()}`,\n color: color.text(),\n backgroundColor: color.background()\n },\n svg: {},\n graphBox: {\n cursor: 'pointer',\n userSelect: 'none'\n }\n});\n\nexport default withStyles(styles)(Root);\n"],"file":"root.js"}
|
package/lib/trig.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.toRadians = exports.toDegrees = exports.hypotenuse = exports.getOpposingSide = exports.edges = exports.diffEdge = exports.angle = exports.acuteYAngle = exports.acuteXAngle = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("../lib/utils");
|
|
9
9
|
|
package/lib/trig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/trig.js"],"names":["log","toDegrees","radians","Math","PI","toRadians","degrees","angle","a","b","vd","y","hd","x","atan2","NINETY","ONE_EIGHTY","TWO_SEVENTY","acuteXAngle","abs","acuteYAngle","hypotenuse","alpha","out","sin","edges","domain","range","destX","max","min","destY","aToB","diffEdge","dX","dY","bToA","getOpposingSide","hyp","getShortestSide","xh","yh","Number","isFinite","isNaN","Infinity","console","warn","bounds","l","enabled","bind","xRadians","yRadians","xSide","xH","ySide","yH","side","Error","point","Point","multiplier","multByPoint","normalized","add"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,mBAAN,CAAZ;;AAEO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,OAAO;AAAA,SAAIA,OAAO,IAAI,MAAMC,IAAI,CAACC,EAAf,CAAX;AAAA,CAAzB;;;;AACA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,OAAO;AAAA,SAAIA,OAAO,IAAIH,IAAI,CAACC,EAAL,GAAU,GAAd,CAAX;AAAA,CAAzB;AACP;;;;;;;;;;;;AAQO,I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D;;AACD,MAAMC,KAAK,GACTF,IAAI,KAAK,GAAT,GACI,IAAIG,yBAAJ,CAAUP,KAAV,EAAiBjB,eAAe,CAACkB,EAAD,EAAKH,QAAL,CAAhC,CADJ,GAEI,IAAIS,yBAAJ,CAAUxB,eAAe,CAACoB,EAAD,EAAKJ,QAAL,CAAzB,EAAyCG,KAAzC,CAHN;AAKAP,EAAAA,CAAC,CAAC,QAAD,EAAWW,KAAX,CAAD;AACA,MAAME,UAAU,GAAG,IAAID,yBAAJ,CAAUpD,CAAC,CAACI,CAAF,GAAML,CAAC,CAACK,CAAR,GAAY,CAAC,CAAb,GAAiB,CAA3B,EAA8BJ,CAAC,CAACE,CAAF,GAAMH,CAAC,CAACG,CAAR,GAAY,CAAC,CAAb,GAAiB,CAA/C,CAAnB;AACAsC,EAAAA,CAAC,CAAC,aAAD,EAAgBa,UAAhB,CAAD;AACA,MAAMvC,GAAG,GAAGqC,KAAK,CAACG,WAAN,CAAkBD,UAAlB,CAAZ;AACAb,EAAAA,CAAC,CAAC,MAAD,EAAS1B,GAAT,CAAD;AACA,MAAMyC,UAAU,GAAGzC,GAAG,CAAC0C,GAAJ,CAAQ,IAAIJ,yBAAJ,CAAUrD,CAAC,CAACK,CAAZ,EAAeL,CAAC,CAACG,CAAjB,CAAR,CAAnB;AACAsC,EAAAA,CAAC,CAAC,aAAD,EAAgBe,UAAhB,CAAD;AACA,SAAOA,UAAP;AACD,CAxCM","sourcesContent":["import { xy } from '../lib/utils';\nimport Point from '@mapbox/point-geometry';\nimport debug from 'debug';\nconst log = debug('pie-lib:plot:trig');\n\nexport const toDegrees = radians => radians * (180 / Math.PI);\nexport const toRadians = degrees => degrees * (Math.PI / 180);\n/**\n * return angle in radians between 2 points using counting degrees counter clockwise\n *\n * 0,0 + 1,1 = 45 in radians\n * 1,1 + 0,0 = 45?\n * @param {Point} a\n * @param {Point} b\n */\nexport const angle = (a, b) => {\n const vd = b.y - a.y;\n const hd = b.x - a.x;\n log(a, b, 'vd: ', vd, 'hd: ', hd);\n const radians = Math.atan2(vd, hd);\n return radians < 0 ? radians + Math.PI * 2 : radians;\n};\n\nconst NINETY = Math.PI / 2;\nconst ONE_EIGHTY = Math.PI;\nconst TWO_SEVENTY = ONE_EIGHTY + NINETY;\n\nexport const acuteXAngle = a => {\n log(toDegrees(a));\n\n if (a < NINETY) {\n return a;\n }\n\n if (a < ONE_EIGHTY) {\n return Math.abs(ONE_EIGHTY - a);\n }\n\n if (a < TWO_SEVENTY) {\n return Math.abs(ONE_EIGHTY - a);\n }\n\n return Math.abs(Math.PI * 2 - a);\n};\n\nexport const acuteYAngle = a => NINETY - acuteXAngle(a);\n\nexport const hypotenuse = (a, alpha) => {\n const out = Math.abs(a / Math.sin(alpha));\n\n return out;\n};\n\n/**\n * return 2 edge points for a,b within domain + range.\n * - one edge is from following a -> b to the bounds\n * - one edge is from following b -> a to the bounds\n * @param {{min: number, max: number}} domain\n * @param {{min: number, max: number}} range\n * @param {{x: number, y: number}} a\n * @param {{x: number, y: number}} b\n * @returns [{x: number, y: number}, {x: number, y: number}]\n */\nexport const edges = (domain, range) => (a, b) => {\n // const xDest =\n const destX = a.x < b.x ? domain.max : domain.min;\n const destY = a.y < b.y ? range.max : range.min;\n const aToB = diffEdge(xy(destX, destY), a, b);\n\n const dX = b.x < a.x ? domain.max : domain.min;\n const dY = b.y < a.y ? range.max : range.min;\n const bToA = diffEdge(xy(dX, dY), b, a);\n return [aToB, bToA];\n};\n\n/** get length of side A of a triangle from H and angle Alpha */\nexport const getOpposingSide = (hyp, angle) => {\n log('[getOpposingSide] hyp: ', hyp, 'angle:', angle);\n return Math.abs(hyp * Math.sin(angle));\n};\n\nconst getShortestSide = (xh, yh) => {\n if (Number.isFinite(xh) && Number.isFinite(yh)) {\n if (xh === 0 && yh > 0) {\n return 'y';\n }\n if (yh === 0 && xh > 0) {\n return 'x';\n }\n return xh < yh ? 'x' : 'y';\n }\n if (isNaN(xh) && !isNaN(yh)) {\n return 'y';\n }\n if (!isNaN(xh) && isNaN(yh)) {\n return 'x';\n }\n if (xh === Infinity) {\n return 'y';\n }\n if (yh === Infinity) {\n return 'x';\n }\n\n // eslint-disable-next-line no-console\n console.warn('hypotenuse - which is shorter? x:', xh, 'y:', yh);\n};\n/**\n * return the difference between bounds and a as a Point\n * @param {*} bounds\n */\nexport const diffEdge = (bounds, a, b) => {\n let l = log.enabled ? log.bind(log, `diffEdge: [${a.x},${a.y} -> ${b.x},${b.y}]`) : () => {};\n const xRadians = angle(a, b);\n l('x angle', toDegrees(xRadians));\n const yRadians = Math.abs(xRadians - toRadians(90));\n l('y angle', toDegrees(yRadians));\n const xSide = Math.abs(a.x - bounds.x);\n\n /**\n * Draw 2 triangles:\n * 1 with a horizontal line from a to the graph x edge\n * 1 with a vertical line from a to the graph y edge\n * Calculate the hypotenuse for both, whichever is shorter\n * indicates that we should use that triangle to get the edge point.\n */\n const xH = hypotenuse(xSide, yRadians);\n\n const ySide = Math.abs(a.y - bounds.y);\n const yH = hypotenuse(ySide, xRadians);\n\n l('x: side', xSide, 'h:', xH);\n l('y: side', ySide, 'h:', yH);\n const side = getShortestSide(xH, yH);\n\n if (side !== 'x' && side !== 'y') {\n throw new Error('Cant decide which hypotenuse to use');\n }\n const point =\n side === 'x'\n ? new Point(xSide, getOpposingSide(xH, xRadians))\n : new Point(getOpposingSide(yH, yRadians), ySide);\n\n l('point:', point);\n const multiplier = new Point(b.x < a.x ? -1 : 1, b.y < a.y ? -1 : 1);\n l('multiplier:', multiplier);\n const out = point.multByPoint(multiplier);\n l('out:', out);\n const normalized = out.add(new Point(a.x, a.y));\n l('normalized:', normalized);\n return normalized;\n};\n"],"file":"trig.js"}
|
|
1
|
+
{"version":3,"sources":["../src/trig.js"],"names":["log","toDegrees","radians","Math","PI","toRadians","degrees","angle","a","b","vd","y","hd","x","atan2","NINETY","ONE_EIGHTY","TWO_SEVENTY","acuteXAngle","abs","acuteYAngle","hypotenuse","alpha","out","sin","edges","domain","range","destX","max","min","destY","aToB","diffEdge","dX","dY","bToA","getOpposingSide","hyp","getShortestSide","xh","yh","Number","isFinite","isNaN","Infinity","console","warn","bounds","l","enabled","bind","xRadians","yRadians","xSide","xH","ySide","yH","side","Error","point","Point","multiplier","multByPoint","normalized","add"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,mBAAN,CAAZ;;AAEO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,OAAO;AAAA,SAAIA,OAAO,IAAI,MAAMC,IAAI,CAACC,EAAf,CAAX;AAAA,CAAzB;;;;AACA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,OAAO;AAAA,SAAIA,OAAO,IAAIH,IAAI,CAACC,EAAL,GAAU,GAAd,CAAX;AAAA,CAAzB;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMG,KAAK,GAAG,SAARA,KAAQ,CAACC,CAAD,EAAIC,CAAJ,EAAU;AAC7B,MAAMC,EAAE,GAAGD,CAAC,CAACE,CAAF,GAAMH,CAAC,CAACG,CAAnB;AACA,MAAMC,EAAE,GAAGH,CAAC,CAACI,CAAF,GAAML,CAAC,CAACK,CAAnB;AACAb,EAAAA,GAAG,CAACQ,CAAD,EAAIC,CAAJ,EAAO,MAAP,EAAeC,EAAf,EAAmB,MAAnB,EAA2BE,EAA3B,CAAH;AACA,MAAMV,OAAO,GAAGC,IAAI,CAACW,KAAL,CAAWJ,EAAX,EAAeE,EAAf,CAAhB;AACA,SAAOV,OAAO,GAAG,CAAV,GAAcA,OAAO,GAAGC,IAAI,CAACC,EAAL,GAAU,CAAlC,GAAsCF,OAA7C;AACD,CANM;;;AAQP,IAAMa,MAAM,GAAGZ,IAAI,CAACC,EAAL,GAAU,CAAzB;AACA,IAAMY,UAAU,GAAGb,IAAI,CAACC,EAAxB;AACA,IAAMa,WAAW,GAAGD,UAAU,GAAGD,MAAjC;;AAEO,IAAMG,WAAW,GAAG,SAAdA,WAAc,CA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AC,CAAC,MAAD,EAAS1B,GAAT,CAAD;AACA,MAAMyC,UAAU,GAAGzC,GAAG,CAAC0C,GAAJ,CAAQ,IAAIJ,yBAAJ,CAAUrD,CAAC,CAACK,CAAZ,EAAeL,CAAC,CAACG,CAAjB,CAAR,CAAnB;AACAsC,EAAAA,CAAC,CAAC,aAAD,EAAgBe,UAAhB,CAAD;AACA,SAAOA,UAAP;AACD,CAxCM","sourcesContent":["import { xy } from '../lib/utils';\nimport Point from '@mapbox/point-geometry';\nimport debug from 'debug';\nconst log = debug('pie-lib:plot:trig');\n\nexport const toDegrees = radians => radians * (180 / Math.PI);\nexport const toRadians = degrees => degrees * (Math.PI / 180);\n/**\n * return angle in radians between 2 points using counting degrees counter clockwise\n *\n * 0,0 + 1,1 = 45 in radians\n * 1,1 + 0,0 = 45?\n * @param {Point} a\n * @param {Point} b\n */\nexport const angle = (a, b) => {\n const vd = b.y - a.y;\n const hd = b.x - a.x;\n log(a, b, 'vd: ', vd, 'hd: ', hd);\n const radians = Math.atan2(vd, hd);\n return radians < 0 ? radians + Math.PI * 2 : radians;\n};\n\nconst NINETY = Math.PI / 2;\nconst ONE_EIGHTY = Math.PI;\nconst TWO_SEVENTY = ONE_EIGHTY + NINETY;\n\nexport const acuteXAngle = a => {\n log(toDegrees(a));\n\n if (a < NINETY) {\n return a;\n }\n\n if (a < ONE_EIGHTY) {\n return Math.abs(ONE_EIGHTY - a);\n }\n\n if (a < TWO_SEVENTY) {\n return Math.abs(ONE_EIGHTY - a);\n }\n\n return Math.abs(Math.PI * 2 - a);\n};\n\nexport const acuteYAngle = a => NINETY - acuteXAngle(a);\n\nexport const hypotenuse = (a, alpha) => {\n const out = Math.abs(a / Math.sin(alpha));\n\n return out;\n};\n\n/**\n * return 2 edge points for a,b within domain + range.\n * - one edge is from following a -> b to the bounds\n * - one edge is from following b -> a to the bounds\n * @param {{min: number, max: number}} domain\n * @param {{min: number, max: number}} range\n * @param {{x: number, y: number}} a\n * @param {{x: number, y: number}} b\n * @returns [{x: number, y: number}, {x: number, y: number}]\n */\nexport const edges = (domain, range) => (a, b) => {\n // const xDest =\n const destX = a.x < b.x ? domain.max : domain.min;\n const destY = a.y < b.y ? range.max : range.min;\n const aToB = diffEdge(xy(destX, destY), a, b);\n\n const dX = b.x < a.x ? domain.max : domain.min;\n const dY = b.y < a.y ? range.max : range.min;\n const bToA = diffEdge(xy(dX, dY), b, a);\n return [aToB, bToA];\n};\n\n/** get length of side A of a triangle from H and angle Alpha */\nexport const getOpposingSide = (hyp, angle) => {\n log('[getOpposingSide] hyp: ', hyp, 'angle:', angle);\n return Math.abs(hyp * Math.sin(angle));\n};\n\nconst getShortestSide = (xh, yh) => {\n if (Number.isFinite(xh) && Number.isFinite(yh)) {\n if (xh === 0 && yh > 0) {\n return 'y';\n }\n if (yh === 0 && xh > 0) {\n return 'x';\n }\n return xh < yh ? 'x' : 'y';\n }\n if (isNaN(xh) && !isNaN(yh)) {\n return 'y';\n }\n if (!isNaN(xh) && isNaN(yh)) {\n return 'x';\n }\n if (xh === Infinity) {\n return 'y';\n }\n if (yh === Infinity) {\n return 'x';\n }\n\n // eslint-disable-next-line no-console\n console.warn('hypotenuse - which is shorter? x:', xh, 'y:', yh);\n};\n/**\n * return the difference between bounds and a as a Point\n * @param {*} bounds\n */\nexport const diffEdge = (bounds, a, b) => {\n let l = log.enabled ? log.bind(log, `diffEdge: [${a.x},${a.y} -> ${b.x},${b.y}]`) : () => {};\n const xRadians = angle(a, b);\n l('x angle', toDegrees(xRadians));\n const yRadians = Math.abs(xRadians - toRadians(90));\n l('y angle', toDegrees(yRadians));\n const xSide = Math.abs(a.x - bounds.x);\n\n /**\n * Draw 2 triangles:\n * 1 with a horizontal line from a to the graph x edge\n * 1 with a vertical line from a to the graph y edge\n * Calculate the hypotenuse for both, whichever is shorter\n * indicates that we should use that triangle to get the edge point.\n */\n const xH = hypotenuse(xSide, yRadians);\n\n const ySide = Math.abs(a.y - bounds.y);\n const yH = hypotenuse(ySide, xRadians);\n\n l('x: side', xSide, 'h:', xH);\n l('y: side', ySide, 'h:', yH);\n const side = getShortestSide(xH, yH);\n\n if (side !== 'x' && side !== 'y') {\n throw new Error('Cant decide which hypotenuse to use');\n }\n const point =\n side === 'x'\n ? new Point(xSide, getOpposingSide(xH, xRadians))\n : new Point(getOpposingSide(yH, yRadians), ySide);\n\n l('point:', point);\n const multiplier = new Point(b.x < a.x ? -1 : 1, b.y < a.y ? -1 : 1);\n l('multiplier:', multiplier);\n const out = point.multByPoint(multiplier);\n l('out:', out);\n const normalized = out.add(new Point(a.x, a.y));\n l('normalized:', normalized);\n return normalized;\n};\n"],"file":"trig.js"}
|
package/lib/types.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.SnapType = exports.SizeType = exports.ScaleType = exports.RangeType = exports.PointType = exports.GraphPropsType = exports.DomainType = exports.ChildrenType = exports.BaseDomainRangeType = void 0;
|
|
7
7
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
|